Search in sources :

Example 11 with ProjectJdkTable

use of com.intellij.openapi.projectRoots.ProjectJdkTable in project android by JetBrains.

the class AndroidSdks method create.

@Nullable
public Sdk create(@NotNull IAndroidTarget target, @NotNull File sdkPath, @NotNull String sdkName, @NotNull Sdk jdk, boolean addRoots) {
    if (!target.getAdditionalLibraries().isEmpty()) {
        // Do not create an IntelliJ SDK for add-ons. Add-ons should be handled as module-level library dependencies.
        return null;
    }
    ProjectJdkTable table = ProjectJdkTable.getInstance();
    String tempName = createUniqueSdkName(SDK_NAME, Arrays.asList(table.getAllJdks()));
    Sdk sdk = table.createSdk(tempName, AndroidSdkType.getInstance());
    SdkModificator sdkModificator = sdk.getSdkModificator();
    sdkModificator.setHomePath(sdkPath.getPath());
    setUpSdk(sdk, sdkModificator, target, sdkName, Arrays.asList(table.getAllJdks()), jdk, addRoots);
    sdkModificator.commitChanges();
    ApplicationManager.getApplication().runWriteAction(() -> ProjectJdkTable.getInstance().addJdk(sdk));
    return sdk;
}
Also used : ProjectJdkTable(com.intellij.openapi.projectRoots.ProjectJdkTable) Sdk(com.intellij.openapi.projectRoots.Sdk) SdkModificator(com.intellij.openapi.projectRoots.SdkModificator) Nullable(org.jetbrains.annotations.Nullable)

Example 12 with ProjectJdkTable

use of com.intellij.openapi.projectRoots.ProjectJdkTable in project intellij-plugins by JetBrains.

the class AppTestBase method doSetupFlexSdk.

private void doSetupFlexSdk(final Module module, final String flexSdkRootPath, final TargetPlatform targetPlatform, final String sdkVersion) {
    final String sdkName = generateSdkName(sdkVersion);
    Sdk sdk = ProjectJdkTable.getInstance().findJdk(sdkName);
    if (sdk == null) {
        ApplicationManager.getApplication().runWriteAction(() -> {
            FlexSdkType2 sdkType = FlexSdkType2.getInstance();
            Sdk sdk1 = new ProjectJdkImpl(sdkName, sdkType, flexSdkRootPath, "");
            ProjectJdkTable.getInstance().addJdk(sdk1);
            Disposer.register(getSdkParentDisposable(), new Disposable() {

                @Override
                public void dispose() {
                    ApplicationManager.getApplication().runWriteAction(() -> {
                        ProjectJdkTable sdkTable = ProjectJdkTable.getInstance();
                        sdkTable.removeJdk(sdkTable.findJdk(sdkName));
                    });
                }
            });
            final SdkModificator modificator = sdk1.getSdkModificator();
            modificator.setVersionString(FlexSdkType2.getInstance().getVersionString(sdk1.getHomePath()));
            modifySdk(sdk1, modificator);
            modificator.commitChanges();
        });
    }
    FlexTestUtils.modifyBuildConfiguration(module, bc -> {
        bc.setNature(new BuildConfigurationNature(targetPlatform, false, getOutputType()));
        bc.getDependencies().setSdkEntry(Factory.createSdkEntry(sdkName));
    });
}
Also used : Disposable(com.intellij.openapi.Disposable) BuildConfigurationNature(com.intellij.flex.model.bc.BuildConfigurationNature) ProjectJdkTable(com.intellij.openapi.projectRoots.ProjectJdkTable) ProjectJdkImpl(com.intellij.openapi.projectRoots.impl.ProjectJdkImpl) Sdk(com.intellij.openapi.projectRoots.Sdk) FlexSdkType2(com.intellij.lang.javascript.flex.sdk.FlexSdkType2) SdkModificator(com.intellij.openapi.projectRoots.SdkModificator)

Example 13 with ProjectJdkTable

use of com.intellij.openapi.projectRoots.ProjectJdkTable in project intellij-plugins by JetBrains.

the class ConversionParams method convertFlexSdks.

// keep old Flex SDKs for now, after IDEA 11.1 release we may decide to delete them
public static void convertFlexSdks() {
    final ProjectJdkTable sdkTable = ProjectJdkTable.getInstance();
    final Sdk[] allSdks = sdkTable.getAllJdks();
    final FlexSdkType2 newSdkType = FlexSdkType2.getInstance();
    Map<String, Sdk> homePathToNewSdk = new HashMap<>();
    Collection<Sdk> sdksToAdd = new ArrayList<>();
    for (Sdk sdk : allSdks) {
        if (sdk.getSdkType() == newSdkType && sdk.getHomePath() != null) {
            homePathToNewSdk.put(sdk.getHomePath(), sdk);
        }
    }
    for (Sdk sdk : allSdks) {
        if (!ArrayUtil.contains(sdk.getSdkType().getName(), OLD_SDKS_TYPES)) {
            continue;
        }
        final String version = sdk.getVersionString();
        if (version == null || (!version.startsWith("3.") && !version.startsWith("4."))) {
            // ignore corrupt SDK
            continue;
        }
        final String homePath = sdk.getHomePath();
        if (homePath == null) {
            continue;
        }
        if (homePathToNewSdk.containsKey(homePath)) {
            continue;
        }
        String newSdkName = SdkConfigurationUtil.createUniqueSdkName(newSdkType, homePath, Arrays.asList(allSdks));
        Sdk newSdk = new ProjectJdkImpl(newSdkName, newSdkType, homePath, "");
        newSdkType.setupSdkPaths(newSdk);
        sdksToAdd.add(newSdk);
        homePathToNewSdk.put(homePath, newSdk);
    }
    WriteAction.run(() -> {
        for (Sdk sdk : sdksToAdd) {
            sdkTable.addJdk(sdk);
        }
    });
}
Also used : ProjectJdkTable(com.intellij.openapi.projectRoots.ProjectJdkTable) ProjectJdkImpl(com.intellij.openapi.projectRoots.impl.ProjectJdkImpl) Sdk(com.intellij.openapi.projectRoots.Sdk) FlexSdkType2(com.intellij.lang.javascript.flex.sdk.FlexSdkType2)

Example 14 with ProjectJdkTable

use of com.intellij.openapi.projectRoots.ProjectJdkTable in project android by JetBrains.

the class AndroidSdksTest method tearDown.

@Override
protected void tearDown() throws Exception {
    ProjectJdkTable sdkTable = ProjectJdkTable.getInstance();
    List<Sdk> sdks = sdkTable.getSdksOfType(AndroidSdkType.getInstance());
    try {
        ApplicationManager.getApplication().runWriteAction(() -> {
            for (Sdk sdk : sdks) {
                sdkTable.removeJdk(sdk);
            }
            sdkTable.removeJdk(myJdk);
        });
    } finally {
        super.tearDown();
    }
}
Also used : ProjectJdkTable(com.intellij.openapi.projectRoots.ProjectJdkTable) Sdk(com.intellij.openapi.projectRoots.Sdk)

Example 15 with ProjectJdkTable

use of com.intellij.openapi.projectRoots.ProjectJdkTable in project intellij-plugins by JetBrains.

the class FlexTestUtils method createSdk.

public static Sdk createSdk(final String flexSdkRootPath, @Nullable String sdkVersion, final boolean removeExisting) {
    Sdk sdk = WriteCommandAction.runWriteCommandAction(null, (Computable<Sdk>) () -> {
        final ProjectJdkTable projectJdkTable = ProjectJdkTable.getInstance();
        if (removeExisting) {
            final List<Sdk> existingFlexSdks = projectJdkTable.getSdksOfType(FlexSdkType2.getInstance());
            for (Sdk existingFlexSdk : existingFlexSdks) {
                projectJdkTable.removeJdk(existingFlexSdk);
            }
        }
        final FlexSdkType2 sdkType = FlexSdkType2.getInstance();
        final Sdk sdk1 = new ProjectJdkImpl(sdkType.suggestSdkName(null, flexSdkRootPath), sdkType, flexSdkRootPath, "");
        sdkType.setupSdkPaths(sdk1);
        projectJdkTable.addJdk(sdk1);
        return sdk1;
    });
    final SdkModificator modificator = sdk.getSdkModificator();
    if (sdkVersion != null) {
        modificator.setVersionString(sdkVersion);
    }
    if (sdk.getHomeDirectory() == null) {
        throw new IllegalArgumentException("Could not find a Flex SDK at " + flexSdkRootPath);
    }
    modificator.addRoot(sdk.getHomeDirectory(), OrderRootType.CLASSES);
    modificator.commitChanges();
    return sdk;
}
Also used : ProjectJdkTable(com.intellij.openapi.projectRoots.ProjectJdkTable) ProjectJdkImpl(com.intellij.openapi.projectRoots.impl.ProjectJdkImpl) List(java.util.List) Sdk(com.intellij.openapi.projectRoots.Sdk) FlexSdkType2(com.intellij.lang.javascript.flex.sdk.FlexSdkType2) SdkModificator(com.intellij.openapi.projectRoots.SdkModificator)

Aggregations

ProjectJdkTable (com.intellij.openapi.projectRoots.ProjectJdkTable)17 Sdk (com.intellij.openapi.projectRoots.Sdk)17 ProjectJdkImpl (com.intellij.openapi.projectRoots.impl.ProjectJdkImpl)5 Nullable (org.jetbrains.annotations.Nullable)5 SdkModificator (com.intellij.openapi.projectRoots.SdkModificator)4 FlexSdkType2 (com.intellij.lang.javascript.flex.sdk.FlexSdkType2)3 BuildConfigurationNature (com.intellij.flex.model.bc.BuildConfigurationNature)2 Disposable (com.intellij.openapi.Disposable)2 VirtualFile (com.intellij.openapi.vfs.VirtualFile)2 Container (aQute.bnd.build.Container)1 Project (aQute.bnd.build.Project)1 Workspace (aQute.bnd.build.Workspace)1 Attrs (aQute.bnd.header.Attrs)1 Refreshable (aQute.bnd.service.Refreshable)1 RepositoryPlugin (aQute.bnd.service.RepositoryPlugin)1 GoSdkType (com.goide.sdk.GoSdkType)1 CompilerConfiguration (com.intellij.compiler.CompilerConfiguration)1 JavacConfiguration (com.intellij.compiler.impl.javaCompiler.javac.JavacConfiguration)1 FacetUtil (com.intellij.facet.impl.FacetUtil)1 ModuleFileType (com.intellij.ide.highlighter.ModuleFileType)1