Search in sources :

Example 31 with SdkModificator

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

the class AndroidModuleConverter1 method process.

@Override
public void process(ModuleSettings moduleSettings) throws CannotConvertException {
    Element confElement = AndroidConversionUtil.findAndroidFacetConfigurationElement(moduleSettings);
    assert confElement != null;
    Element platformNameElement = AndroidConversionUtil.getOptionElement(confElement, PLATFORM_NAME_ATTRIBUTE);
    String platformName = platformNameElement != null ? platformNameElement.getAttributeValue(AndroidConversionUtil.OPTION_VALUE_ATTRIBUTE) : null;
    if (platformName == null)
        return;
    removeOldDependencies(moduleSettings, platformName);
    confElement.removeContent(platformNameElement);
    Library androidLibrary = LibraryTablesRegistrar.getInstance().getLibraryTable().getLibraryByName(platformName);
    if (androidLibrary != null) {
        AndroidPlatform androidPlatform = AndroidPlatform.parse(androidLibrary, null, null);
        if (androidPlatform != null) {
            IAndroidTarget target = androidPlatform.getTarget();
            Sdk androidSdk = AndroidSdkUtils.findAppropriateAndroidPlatform(target, androidPlatform.getSdkData(), false);
            if (androidSdk == null) {
                androidSdk = AndroidSdks.getInstance().create(target, androidPlatform.getSdkData().getLocation(), false);
                if (androidSdk != null) {
                    final SdkModificator modificator = androidSdk.getSdkModificator();
                    for (OrderRootType type : OrderRootType.getAllTypes()) {
                        for (VirtualFile root : androidLibrary.getFiles(type)) {
                            modificator.addRoot(root, type);
                        }
                    }
                    modificator.commitChanges();
                }
            }
            if (androidSdk != null) {
                addNewDependency(moduleSettings, androidSdk.getName());
            }
        }
    }
}
Also used : VirtualFile(com.intellij.openapi.vfs.VirtualFile) OrderRootType(com.intellij.openapi.roots.OrderRootType) Element(org.jdom.Element) AndroidPlatform(org.jetbrains.android.sdk.AndroidPlatform) Library(com.intellij.openapi.roots.libraries.Library) IAndroidTarget(com.android.sdklib.IAndroidTarget) Sdk(com.intellij.openapi.projectRoots.Sdk) SdkModificator(com.intellij.openapi.projectRoots.SdkModificator)

Example 32 with SdkModificator

use of com.intellij.openapi.projectRoots.SdkModificator 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 33 with SdkModificator

use of com.intellij.openapi.projectRoots.SdkModificator 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)

Example 34 with SdkModificator

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

the class FlexTestUtils method addASDocToSdk.

public static void addASDocToSdk(final Module module, final Class clazz, final String testName) {
    WriteAction.run(() -> {
        final Sdk flexSdk = FlexUtils.getSdkForActiveBC(module);
        final SdkModificator sdkModificator = flexSdk.getSdkModificator();
        VirtualFile docRoot = LocalFileSystem.getInstance().findFileByPath(getPathToMockFlex(clazz, testName) + "/asdoc");
        sdkModificator.addRoot(docRoot, JavadocOrderRootType.getInstance());
        sdkModificator.commitChanges();
    });
}
Also used : Sdk(com.intellij.openapi.projectRoots.Sdk) SdkModificator(com.intellij.openapi.projectRoots.SdkModificator)

Example 35 with SdkModificator

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

the class FlexNavigationTest method testMonkeyPatching.

@JSTestOptions({ JSTestOption.WithFlexSdk })
public void testMonkeyPatching() throws Exception {
    final String testName = getTestName(false);
    myAfterCommitRunnable = () -> {
        final VirtualFile sdkSrc = LocalFileSystem.getInstance().findFileByPath(getTestDataPath() + BASE_PATH + testName + "_sdk_src");
        final SdkModificator sdkModificator = FlexTestUtils.getFlexSdkModificator(myModule);
        sdkModificator.addRoot(sdkSrc, OrderRootType.SOURCES);
        sdkModificator.commitChanges();
    };
    configureByFiles(BASE_PATH + testName, BASE_PATH + testName + "/" + testName + ".as", BASE_PATH + testName + "/mx/events/FlexEvent.as");
    final VirtualFile expectedFile = LocalFileSystem.getInstance().findFileByPath(ModuleRootManager.getInstance(myModule).getSourceRoots()[0].getPath() + "/mx/events/FlexEvent.as");
    assert expectedFile != null;
    final PsiReference reference = TargetElementUtil.findReference(myEditor);
    assertNotNull(reference);
    final Collection<PsiElement> candidates = TargetElementUtil.getInstance().getTargetCandidates(reference);
    assertEquals(1, candidates.size());
    doCheck(candidates.iterator().next(), expectedFile, expectedFile, null);
}
Also used : VirtualFile(com.intellij.openapi.vfs.VirtualFile) SdkModificator(com.intellij.openapi.projectRoots.SdkModificator) JSTestOptions(com.intellij.lang.javascript.JSTestOptions)

Aggregations

SdkModificator (com.intellij.openapi.projectRoots.SdkModificator)51 Sdk (com.intellij.openapi.projectRoots.Sdk)32 VirtualFile (com.intellij.openapi.vfs.VirtualFile)30 File (java.io.File)8 Module (com.intellij.openapi.module.Module)7 IAndroidTarget (com.android.sdklib.IAndroidTarget)6 AndroidSdkAdditionalData (org.jetbrains.android.sdk.AndroidSdkAdditionalData)5 NotNull (org.jetbrains.annotations.NotNull)5 ProjectJdkTable (com.intellij.openapi.projectRoots.ProjectJdkTable)4 Library (com.intellij.openapi.roots.libraries.Library)4 Nullable (org.jetbrains.annotations.Nullable)4 JSTestOptions (com.intellij.lang.javascript.JSTestOptions)3 Project (com.intellij.openapi.project.Project)3 ProjectJdkImpl (com.intellij.openapi.projectRoots.impl.ProjectJdkImpl)3 FirstRunWizardMode (com.android.tools.idea.welcome.config.FirstRunWizardMode)2 FlexSdkType2 (com.intellij.lang.javascript.flex.sdk.FlexSdkType2)2 OrderRoot (com.intellij.openapi.roots.libraries.ui.OrderRoot)2 IOException (java.io.IOException)2 AndroidSdkData (org.jetbrains.android.sdk.AndroidSdkData)2 Contract (org.jetbrains.annotations.Contract)2