Search in sources :

Example 1 with SdkAdditionalData

use of com.intellij.openapi.projectRoots.SdkAdditionalData in project intellij-community by JetBrains.

the class PythonCommandLineState method getAddedPaths.

public static List<String> getAddedPaths(Sdk pythonSdk) {
    List<String> pathList = new ArrayList<>();
    final SdkAdditionalData sdkAdditionalData = pythonSdk.getSdkAdditionalData();
    if (sdkAdditionalData instanceof PythonSdkAdditionalData) {
        final Set<VirtualFile> addedPaths = ((PythonSdkAdditionalData) sdkAdditionalData).getAddedPathFiles();
        for (VirtualFile file : addedPaths) {
            addToPythonPath(file, pathList);
        }
    }
    return pathList;
}
Also used : VirtualFile(com.intellij.openapi.vfs.VirtualFile) PythonSdkAdditionalData(com.jetbrains.python.sdk.PythonSdkAdditionalData) PythonSdkAdditionalData(com.jetbrains.python.sdk.PythonSdkAdditionalData) SdkAdditionalData(com.intellij.openapi.projectRoots.SdkAdditionalData)

Example 2 with SdkAdditionalData

use of com.intellij.openapi.projectRoots.SdkAdditionalData in project intellij-community by JetBrains.

the class PyRemotePackageManagerImpl method getPythonProcessOutput.

@NotNull
@Override
protected ProcessOutput getPythonProcessOutput(@NotNull String helperPath, @NotNull List<String> args, boolean askForSudo, boolean showProgress, @Nullable final String workingDir) throws ExecutionException {
    final Sdk sdk = getSdk();
    final String homePath = sdk.getHomePath();
    if (homePath == null) {
        throw new ExecutionException("Cannot find Python interpreter for SDK " + sdk.getName());
    }
    final SdkAdditionalData sdkData = sdk.getSdkAdditionalData();
    if (sdkData instanceof PyRemoteSdkAdditionalDataBase) {
        //remote interpreter
        final PythonRemoteInterpreterManager manager = PythonRemoteInterpreterManager.getInstance();
        RemoteSdkCredentials remoteSdkCredentials;
        if (CaseCollector.useRemoteCredentials((PyRemoteSdkAdditionalDataBase) sdkData)) {
            try {
                remoteSdkCredentials = ((RemoteSdkAdditionalData) sdkData).getRemoteSdkCredentials(false);
            } catch (InterruptedException e) {
                LOG.error(e);
                remoteSdkCredentials = null;
            } catch (ExecutionException e) {
                throw analyzeException(e, helperPath, args);
            }
            if (manager != null && remoteSdkCredentials != null) {
                if (askForSudo) {
                    askForSudo = !manager.ensureCanWrite(null, remoteSdkCredentials, remoteSdkCredentials.getInterpreterPath());
                }
            } else {
                throw new PyExecutionException(PythonRemoteInterpreterManager.WEB_DEPLOYMENT_PLUGIN_IS_DISABLED, helperPath, args);
            }
        }
        if (manager != null) {
            final List<String> cmdline = new ArrayList<>();
            cmdline.add(homePath);
            cmdline.add(RemoteFile.detectSystemByPath(homePath).createRemoteFile(helperPath).getPath());
            cmdline.addAll(Collections2.transform(args, new Function<String, String>() {

                @Override
                public String apply(@Nullable String input) {
                    return quoteIfNeeded(input);
                }
            }));
            ProcessOutput processOutput;
            do {
                final PyRemoteSdkAdditionalDataBase remoteSdkAdditionalData = (PyRemoteSdkAdditionalDataBase) sdkData;
                final PyRemotePathMapper pathMapper = manager.setupMappings(null, remoteSdkAdditionalData, null);
                try {
                    processOutput = PyRemoteProcessStarterManagerUtil.getManager(remoteSdkAdditionalData).executeRemoteProcess(null, ArrayUtil.toStringArray(cmdline), workingDir, manager, remoteSdkAdditionalData, pathMapper, askForSudo, true);
                } catch (InterruptedException e) {
                    throw new ExecutionException(e);
                }
                if (askForSudo && processOutput.getStderr().contains("sudo: 3 incorrect password attempts")) {
                    continue;
                }
                break;
            } while (true);
            return processOutput;
        } else {
            throw new PyExecutionException(PythonRemoteInterpreterManager.WEB_DEPLOYMENT_PLUGIN_IS_DISABLED, helperPath, args);
        }
    } else {
        throw new PyExecutionException("Invalid remote SDK", helperPath, args);
    }
}
Also used : ArrayList(java.util.ArrayList) PyRemoteSdkAdditionalDataBase(com.jetbrains.python.remote.PyRemoteSdkAdditionalDataBase) PythonRemoteInterpreterManager(com.jetbrains.python.remote.PythonRemoteInterpreterManager) PyRemotePathMapper(com.jetbrains.python.remote.PyRemotePathMapper) Function(com.google.common.base.Function) ProcessOutput(com.intellij.execution.process.ProcessOutput) Sdk(com.intellij.openapi.projectRoots.Sdk) ExecutionException(com.intellij.execution.ExecutionException) Nullable(org.jetbrains.annotations.Nullable) RemoteSdkAdditionalData(com.intellij.remote.RemoteSdkAdditionalData) SdkAdditionalData(com.intellij.openapi.projectRoots.SdkAdditionalData) RemoteSdkCredentials(com.intellij.remote.RemoteSdkCredentials) NotNull(org.jetbrains.annotations.NotNull)

Example 3 with SdkAdditionalData

use of com.intellij.openapi.projectRoots.SdkAdditionalData in project intellij-community by JetBrains.

the class PythonSdkDetailsStep method getVEnvCallback.

@NotNull
private AbstractCreateVirtualEnvDialog.VirtualEnvCallback getVEnvCallback() {
    return new CreateVirtualEnvDialog.VirtualEnvCallback() {

        @Override
        public void virtualEnvCreated(Sdk sdk, boolean associateWithProject) {
            if (associateWithProject) {
                SdkAdditionalData additionalData = sdk.getSdkAdditionalData();
                if (additionalData == null) {
                    additionalData = new PythonSdkAdditionalData(PythonSdkFlavor.getFlavor(sdk.getHomePath()));
                    ((ProjectJdkImpl) sdk).setSdkAdditionalData(additionalData);
                }
                if (myNewProject) {
                    ((PythonSdkAdditionalData) additionalData).associateWithNewProject();
                } else {
                    ((PythonSdkAdditionalData) additionalData).associateWithProject(myProject);
                }
            }
            mySdkAddedCallback.consume(sdk);
        }
    };
}
Also used : ProjectJdkImpl(com.intellij.openapi.projectRoots.impl.ProjectJdkImpl) Sdk(com.intellij.openapi.projectRoots.Sdk) SdkAdditionalData(com.intellij.openapi.projectRoots.SdkAdditionalData) NotNull(org.jetbrains.annotations.NotNull)

Example 4 with SdkAdditionalData

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

the class DependenciesModuleSetupStep method addExtraSdkLibrariesAsDependencies.

/**
   * Sets the 'useLibrary' libraries or SDK add-ons as library dependencies.
   * <p>
   * These libraries are set at the project level, which makes it impossible to add them to a IDE SDK definition because the IDE SDK is
   * global to the whole IDE. To work around this limitation, we set these libraries as module dependencies instead.
   * </p>
   */
private void addExtraSdkLibrariesAsDependencies(@NotNull Module module, @NotNull IdeModifiableModelsProvider modelsProvider, @NotNull AndroidProject androidProject) {
    ModifiableRootModel moduleModel = modelsProvider.getModifiableRootModel(module);
    Sdk sdk = moduleModel.getSdk();
    // If we got here, SDK will *NOT* be null.
    assert sdk != null;
    String suffix = null;
    AndroidSdkData sdkData = AndroidSdkData.getSdkData(sdk);
    if (sdkData != null) {
        SdkAdditionalData data = sdk.getSdkAdditionalData();
        if (data instanceof AndroidSdkAdditionalData) {
            AndroidSdkAdditionalData androidSdkData = (AndroidSdkAdditionalData) data;
            suffix = androidSdkData.getBuildTargetHashString();
        }
    }
    if (suffix == null) {
        // In practice, we won't get here. A proper Android SDK has been already configured by now, and the suffix won't be null.
        suffix = androidProject.getCompileTarget();
    }
    Set<String> currentIdeSdkFilePaths = Sets.newHashSetWithExpectedSize(5);
    for (VirtualFile sdkFile : sdk.getRootProvider().getFiles(CLASSES)) {
        // We need to convert the VirtualFile to java.io.File, because the path of the VirtualPath is using 'jar' protocol and it won't match
        // the path returned by AndroidProject#getBootClasspath().
        File sdkFilePath = virtualToIoFile(sdkFile);
        currentIdeSdkFilePaths.add(sdkFilePath.getPath());
    }
    Collection<String> bootClasspath = androidProject.getBootClasspath();
    for (String library : bootClasspath) {
        if (isNotEmpty(library) && !currentIdeSdkFilePaths.contains(library)) {
            // Library is not in the SDK IDE definition. Add it as library and make the module depend on it.
            File binaryPath = new File(library);
            String name = binaryPath.isFile() ? getNameWithoutExtension(binaryPath) : sanitizeFileName(library);
            // Include compile target as part of the name, to ensure the library name is unique to this Android platform.
            // e.g. maps-android-23, effects-android-23 (it follows the library naming convention: library-version
            name = name + "-" + suffix;
            myDependenciesSetup.setUpLibraryDependency(module, modelsProvider, name, COMPILE, binaryPath);
        }
    }
}
Also used : ModifiableRootModel(com.intellij.openapi.roots.ModifiableRootModel) VirtualFile(com.intellij.openapi.vfs.VirtualFile) AndroidSdkAdditionalData(org.jetbrains.android.sdk.AndroidSdkAdditionalData) AndroidSdkData(org.jetbrains.android.sdk.AndroidSdkData) Sdk(com.intellij.openapi.projectRoots.Sdk) VirtualFile(com.intellij.openapi.vfs.VirtualFile) VfsUtilCore.virtualToIoFile(com.intellij.openapi.vfs.VfsUtilCore.virtualToIoFile) File(java.io.File) SdkAdditionalData(com.intellij.openapi.projectRoots.SdkAdditionalData) AndroidSdkAdditionalData(org.jetbrains.android.sdk.AndroidSdkAdditionalData)

Example 5 with SdkAdditionalData

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

the class GradleSyncTest method sdkCreationForAddons.

// https://code.google.com/p/android/issues/detail?id=185313
@Test
public void sdkCreationForAddons() throws IOException {
    guiTest.importSimpleApplication();
    IdeFrameFixture ideFrame = guiTest.ideFrame();
    Project project = ideFrame.getProject();
    Module appModule = ideFrame.getModule("app");
    GradleBuildFile buildFile = GradleBuildFile.get(appModule);
    execute(new GuiTask() {

        @Override
        protected void executeInEDT() throws Throwable {
            runWriteCommandAction(project, () -> buildFile.setValue(BuildFileKey.COMPILE_SDK_VERSION, "Google Inc.:Google APIs:24"));
        }
    });
    ideFrame.requestProjectSync().waitForGradleProjectSyncToFinish();
    Sdk sdk = ModuleRootManager.getInstance(appModule).getSdk();
    AndroidSdkData sdkData = AndroidSdkData.getSdkData(sdk);
    SdkAdditionalData data = sdk.getSdkAdditionalData();
    assertThat(data).isInstanceOf(AndroidSdkAdditionalData.class);
    AndroidSdkAdditionalData androidSdkData = (AndroidSdkAdditionalData) data;
    IAndroidTarget buildTarget = androidSdkData.getBuildTarget(sdkData);
    // By checking that there are no additional libraries in the SDK, we are verifying that an additional SDK was not created for add-ons.
    assertThat(buildTarget.getAdditionalLibraries()).hasSize(0);
}
Also used : GuiTask(org.fest.swing.edt.GuiTask) Project(com.intellij.openapi.project.Project) AndroidSdkAdditionalData(org.jetbrains.android.sdk.AndroidSdkAdditionalData) AndroidSdkData(org.jetbrains.android.sdk.AndroidSdkData) GradleBuildFile(com.android.tools.idea.gradle.parser.GradleBuildFile) GradleUtil.getGradleBuildFile(com.android.tools.idea.gradle.util.GradleUtil.getGradleBuildFile) JavaSdk(com.intellij.openapi.projectRoots.JavaSdk) Sdk(com.intellij.openapi.projectRoots.Sdk) IAndroidTarget(com.android.sdklib.IAndroidTarget) Module(com.intellij.openapi.module.Module) AndroidSdkAdditionalData(org.jetbrains.android.sdk.AndroidSdkAdditionalData) SdkAdditionalData(com.intellij.openapi.projectRoots.SdkAdditionalData) Test(org.junit.Test)

Aggregations

SdkAdditionalData (com.intellij.openapi.projectRoots.SdkAdditionalData)15 Sdk (com.intellij.openapi.projectRoots.Sdk)11 ExecutionException (com.intellij.execution.ExecutionException)4 VirtualFile (com.intellij.openapi.vfs.VirtualFile)4 PyRemoteSdkAdditionalDataBase (com.jetbrains.python.remote.PyRemoteSdkAdditionalDataBase)4 PythonSdkAdditionalData (com.jetbrains.python.sdk.PythonSdkAdditionalData)4 NotNull (org.jetbrains.annotations.NotNull)4 File (java.io.File)3 AndroidSdkAdditionalData (org.jetbrains.android.sdk.AndroidSdkAdditionalData)3 Nullable (org.jetbrains.annotations.Nullable)3 Project (com.intellij.openapi.project.Project)2 ProjectJdkImpl (com.intellij.openapi.projectRoots.impl.ProjectJdkImpl)2 RemoteSdkAdditionalData (com.intellij.remote.RemoteSdkAdditionalData)2 RemoteSdkCredentials (com.intellij.remote.RemoteSdkCredentials)2 PyRemotePathMapper (com.jetbrains.python.remote.PyRemotePathMapper)2 PyDetectedSdk (com.jetbrains.python.sdk.PyDetectedSdk)2 ArrayList (java.util.ArrayList)2 AndroidSdkData (org.jetbrains.android.sdk.AndroidSdkData)2 IAndroidTarget (com.android.sdklib.IAndroidTarget)1 GradleBuildFile (com.android.tools.idea.gradle.parser.GradleBuildFile)1