Search in sources :

Example 1 with GoBuildTargetSettings

use of com.goide.project.GoBuildTargetSettings in project go-lang-idea-plugin by go-lang-plugin-org.

the class GoPackageUtilTest method testInvalidateCacheOnChangingBuildTags.

public void testInvalidateCacheOnChangingBuildTags() {
    myFixture.configureByText("foo.go", "// +build ignored\n\npackage ignored");
    myFixture.configureByText("bar.go", "package not_ignored");
    assertSameElements(GoPackageUtil.getAllPackagesInDirectory(myFixture.getFile().getContainingDirectory(), null, true), "not_ignored");
    GoBuildTargetSettings newSettings = new GoBuildTargetSettings();
    newSettings.customFlags = new String[] { "ignored" };
    GoModuleSettings.getInstance(myFixture.getModule()).setBuildTargetSettings(newSettings);
    assertSameElements(GoPackageUtil.getAllPackagesInDirectory(myFixture.getFile().getContainingDirectory(), null, true), "not_ignored", "ignored");
}
Also used : GoBuildTargetSettings(com.goide.project.GoBuildTargetSettings)

Example 2 with GoBuildTargetSettings

use of com.goide.project.GoBuildTargetSettings in project go-lang-idea-plugin by go-lang-plugin-org.

the class GoBuildTagsSettingsConverterProvider method createConverter.

@NotNull
@Override
public ProjectConverter createConverter(@NotNull ConversionContext context) {
    return new ProjectConverter() {

        private GoBuildTargetSettings newSettings;

        @NotNull
        private File getGoBuildFlagsFile() {
            return new File(context.getSettingsBaseDir(), "goBuildFlags.xml");
        }

        @Nullable
        @Override
        public ConversionProcessor<ProjectSettings> createProjectFileConverter() {
            return new ConversionProcessor<ProjectSettings>() {

                @Override
                public boolean isConversionNeeded(@NotNull ProjectSettings settings) {
                    Element oldSettings = JDomSerializationUtil.findComponent(settings.getRootElement(), "GoBuildFlags");
                    return oldSettings != null;
                }

                @Override
                public void process(@NotNull ProjectSettings settings) throws CannotConvertException {
                    Element oldSettings = JDomSerializationUtil.findComponent(settings.getRootElement(), "GoBuildFlags");
                    if (oldSettings != null) {
                        newSettings = XmlSerializer.deserialize(oldSettings, GoBuildTargetSettings.class);
                        oldSettings.detach();
                    }
                }
            };
        }

        @Override
        public Collection<File> getAdditionalAffectedFiles() {
            return Collections.singletonList(getGoBuildFlagsFile());
        }

        @Override
        public boolean isConversionNeeded() {
            return getGoBuildFlagsFile().exists();
        }

        @Override
        public void preProcessingFinished() throws CannotConvertException {
            File oldSettingsFile = getGoBuildFlagsFile();
            if (oldSettingsFile.exists()) {
                Element oldSettingsRoot = JDomConvertingUtil.loadDocument(oldSettingsFile).getRootElement();
                Element buildFlagsSettings = JDomSerializationUtil.findComponent(oldSettingsRoot, "GoBuildFlags");
                if (buildFlagsSettings != null) {
                    newSettings = XmlSerializer.deserialize(buildFlagsSettings, GoBuildTargetSettings.class);
                    buildFlagsSettings.detach();
                    //noinspection ResultOfMethodCallIgnored
                    oldSettingsFile.delete();
                }
            }
        }

        @Nullable
        @Override
        public ConversionProcessor<ModuleSettings> createModuleFileConverter() {
            return new ConversionProcessor<ModuleSettings>() {

                @Override
                public boolean isConversionNeeded(@NotNull ModuleSettings settings) {
                    return getGoBuildFlagsFile().exists();
                }

                @Override
                public void process(@NotNull ModuleSettings settings) throws CannotConvertException {
                    Element rootElement = settings.getRootElement();
                    Element goComponent = JDomSerializationUtil.findOrCreateComponentElement(rootElement, GoConstants.GO_MODULE_SESTTINGS_SERVICE_NAME);
                    Element buildTags = XmlSerializer.serialize(newSettings);
                    Element existingBuildTags = goComponent.getChild(buildTags.getName());
                    if (existingBuildTags != null) {
                        existingBuildTags.detach();
                    }
                    goComponent.addContent(buildTags);
                }
            };
        }
    };
}
Also used : Element(org.jdom.Element) GoBuildTargetSettings(com.goide.project.GoBuildTargetSettings) File(java.io.File) NotNull(org.jetbrains.annotations.NotNull) NotNull(org.jetbrains.annotations.NotNull)

Example 3 with GoBuildTargetSettings

use of com.goide.project.GoBuildTargetSettings in project go-lang-idea-plugin by go-lang-plugin-org.

the class GoModuleSettingsUI method apply.

@Override
public void apply(@NotNull GoModuleSettings settings) throws ConfigurationException {
    myVendoringUI.apply(settings);
    GoBuildTargetSettings newBuildTargetSettings = new GoBuildTargetSettings();
    myBuildTagsUI.apply(newBuildTargetSettings);
    settings.setBuildTargetSettings(newBuildTargetSettings);
}
Also used : GoBuildTargetSettings(com.goide.project.GoBuildTargetSettings)

Example 4 with GoBuildTargetSettings

use of com.goide.project.GoBuildTargetSettings in project go-lang-idea-plugin by go-lang-plugin-org.

the class GoTargetSystem method forModule.

@NotNull
public static GoTargetSystem forModule(@NotNull Module module) {
    return CachedValuesManager.getManager(module.getProject()).getCachedValue(module, () -> {
        GoBuildTargetSettings settings = GoModuleSettings.getInstance(module).getBuildTargetSettings();
        String os = realValue(settings.os, GoUtil.systemOS());
        String arch = realValue(settings.arch, GoUtil.systemArch());
        ThreeState cgo = settings.cgo == ThreeState.UNSURE ? GoUtil.systemCgo(os, arch) : settings.cgo;
        String moduleSdkVersion = GoSdkService.getInstance(module.getProject()).getSdkVersion(module);
        String[] customFlags = GoSdkService.getInstance(module.getProject()).isAppEngineSdk(module) ? ArrayUtil.prepend(GAE_BUILD_FLAG, settings.customFlags) : settings.customFlags;
        String compiler = GoBuildTargetSettings.ANY_COMPILER.equals(settings.compiler) ? null : settings.compiler;
        GoTargetSystem result = new GoTargetSystem(os, arch, realValue(settings.goVersion, moduleSdkVersion), compiler, cgo, customFlags);
        return CachedValueProvider.Result.create(result, settings);
    });
}
Also used : ThreeState(com.intellij.util.ThreeState) GoBuildTargetSettings(com.goide.project.GoBuildTargetSettings) NotNull(org.jetbrains.annotations.NotNull)

Example 5 with GoBuildTargetSettings

use of com.goide.project.GoBuildTargetSettings in project go-lang-idea-plugin by go-lang-plugin-org.

the class GoPackageUtil method getAllPackagesInDirectory.

@NotNull
public static Collection<String> getAllPackagesInDirectory(@Nullable PsiDirectory dir, @Nullable Module contextModule, boolean trimTestSuffices) {
    if (dir == null)
        return Collections.emptyList();
    if (contextModule != null) {
        return getAllPackagesInDirectoryInner(dir, contextModule, trimTestSuffices);
    }
    Key<CachedValue<Collection<String>>> key = trimTestSuffices ? PACKAGES_TEST_TRIMMED_CACHE : PACKAGES_CACHE;
    return CachedValuesManager.getManager(dir.getProject()).getCachedValue(dir, key, () -> {
        Module module = ModuleUtilCore.findModuleForPsiElement(dir);
        GoBuildTargetSettings buildTargetSettings = module != null ? GoModuleSettings.getInstance(module).getBuildTargetSettings() : null;
        // todo[zolotov]: implement package modification tracker
        return buildTargetSettings != null ? CachedValueProvider.Result.create(getAllPackagesInDirectoryInner(dir, module, trimTestSuffices), dir, buildTargetSettings) : CachedValueProvider.Result.create(getAllPackagesInDirectoryInner(dir, null, trimTestSuffices), dir);
    }, false);
}
Also used : GoBuildTargetSettings(com.goide.project.GoBuildTargetSettings) CachedValue(com.intellij.psi.util.CachedValue) Module(com.intellij.openapi.module.Module) NotNull(org.jetbrains.annotations.NotNull)

Aggregations

GoBuildTargetSettings (com.goide.project.GoBuildTargetSettings)8 NotNull (org.jetbrains.annotations.NotNull)3 Module (com.intellij.openapi.module.Module)1 CachedValue (com.intellij.psi.util.CachedValue)1 ThreeState (com.intellij.util.ThreeState)1 File (java.io.File)1 Element (org.jdom.Element)1