Search in sources :

Example 6 with SdkAdditionalData

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

the class AndroidJunitPatcher method patchJavaParameters.

@Override
public void patchJavaParameters(@Nullable Module module, JavaParameters javaParameters) {
    if (module == null) {
        return;
    }
    AndroidModuleModel androidModel = AndroidModuleModel.get(module);
    if (androidModel == null) {
        return;
    }
    // Modify the class path only if we're dealing with the unit test artifact.
    PathsList classPath = javaParameters.getClassPath();
    Sdk sdk = ModuleRootManager.getInstance(module).getSdk();
    if (sdk == null || !(sdk.getSdkType() instanceof AndroidSdkType)) {
        return;
    }
    SdkAdditionalData data = sdk.getSdkAdditionalData();
    if (!(data instanceof AndroidSdkAdditionalData)) {
        return;
    }
    AndroidPlatform platform = ((AndroidSdkAdditionalData) data).getAndroidPlatform();
    if (platform == null) {
        return;
    }
    classPath.remove(platform.getTarget().getPath(IAndroidTarget.ANDROID_JAR));
    // Move the mockable android jar to the end.
    String mockableJarPath = null;
    for (String path : classPath.getPathList()) {
        if (new File(FileUtil.toSystemDependentName(path)).getName().startsWith("mockable-android")) {
            // PathsList stores strings - use the one that's actually stored there.
            mockableJarPath = path;
            break;
        }
    }
    if (mockableJarPath != null) {
        classPath.remove(mockableJarPath);
        classPath.addTail(mockableJarPath);
    }
}
Also used : AndroidSdkAdditionalData(org.jetbrains.android.sdk.AndroidSdkAdditionalData) PathsList(com.intellij.util.PathsList) AndroidModuleModel(com.android.tools.idea.gradle.project.model.AndroidModuleModel) AndroidSdkType(org.jetbrains.android.sdk.AndroidSdkType) AndroidPlatform(org.jetbrains.android.sdk.AndroidPlatform) Sdk(com.intellij.openapi.projectRoots.Sdk) File(java.io.File) SdkAdditionalData(com.intellij.openapi.projectRoots.SdkAdditionalData) AndroidSdkAdditionalData(org.jetbrains.android.sdk.AndroidSdkAdditionalData)

Example 7 with SdkAdditionalData

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

the class FlexSdkUtils method createOrGetSdk.

@Nullable
public static Sdk createOrGetSdk(final SdkType sdkType, final String path) {
    // todo work with sdk modifiable model if Project Structure is open!
    final VirtualFile sdkHome = path == null ? null : LocalFileSystem.getInstance().findFileByPath(path);
    if (sdkHome == null)
        return null;
    final ProjectJdkTable projectJdkTable = ProjectJdkTable.getInstance();
    for (final Sdk flexSdk : projectJdkTable.getSdksOfType(sdkType)) {
        final String existingHome = flexSdk.getHomePath();
        if (existingHome != null && sdkHome.getPath().equals(FileUtil.toSystemIndependentName(existingHome))) {
            if (sdkType instanceof FlexmojosSdkType) {
                final SdkAdditionalData data = flexSdk.getSdkAdditionalData();
                if (data == null || ((FlexmojosSdkAdditionalData) data).getFlexCompilerClasspath().isEmpty()) {
                    sdkType.setupSdkPaths(flexSdk);
                }
            }
            return flexSdk;
        }
    }
    return createSdk(sdkType, sdkHome.getPath());
}
Also used : VirtualFile(com.intellij.openapi.vfs.VirtualFile) ProjectJdkTable(com.intellij.openapi.projectRoots.ProjectJdkTable) Sdk(com.intellij.openapi.projectRoots.Sdk) SdkAdditionalData(com.intellij.openapi.projectRoots.SdkAdditionalData) Nullable(org.jetbrains.annotations.Nullable)

Example 8 with SdkAdditionalData

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

the class PythonSdkConfigurator method configureProject.

public void configureProject(final Project project, @NotNull final VirtualFile baseDir, Ref<Module> moduleRef) {
    // it it a virtualenv?
    final List<VirtualFile> children = VfsUtil.getChildren(baseDir, new VirtualFileFilter() {

        @Override
        public boolean accept(VirtualFile file) {
            return !Project.DIRECTORY_STORE_FOLDER.equals(file.getName());
        }
    });
    if (children.isEmpty())
        return;
    final PythonSdkType sdkType = PythonSdkType.getInstance();
    //find virtualEnv in project directory
    final List<String> candidates = new ArrayList<>();
    if (project == null)
        return;
    final VirtualFile rootDir = project.getBaseDir();
    if (rootDir != null)
        candidates.addAll(VirtualEnvSdkFlavor.findInDirectory(rootDir));
    if (!candidates.isEmpty()) {
        String filePath = candidates.get(0);
        if (StringUtil.startsWithChar(filePath, '~')) {
            final String home = SystemProperties.getUserHome();
            filePath = home + filePath.substring(1);
        }
        final Sdk virtualEnvSdk = SdkConfigurationUtil.createAndAddSDK(filePath, sdkType);
        if (virtualEnvSdk != null) {
            SdkConfigurationUtil.setDirectoryProjectSdk(project, virtualEnvSdk);
            SdkAdditionalData additionalData = virtualEnvSdk.getSdkAdditionalData();
            if (additionalData == null) {
                additionalData = new PythonSdkAdditionalData(PythonSdkFlavor.getFlavor(virtualEnvSdk.getHomePath()));
                ((ProjectJdkImpl) virtualEnvSdk).setSdkAdditionalData(additionalData);
            }
            ((PythonSdkAdditionalData) additionalData).associateWithProject(project);
            return;
        }
        return;
    }
    final Sdk existingSdk = ProjectRootManager.getInstance(project).getProjectSdk();
    // SdkConfigurationUtil does the same
    if (existingSdk != null && existingSdk.getSdkType() == sdkType)
        return;
    final File executableFile = PythonSdkType.findExecutableFile(new File(project.getBasePath(), "bin"), "python");
    if (executableFile != null) {
        final File virtualEnvRoot = PythonSdkType.getVirtualEnvRoot(executableFile.getPath());
        if (virtualEnvRoot != null) {
            // yes, an unknown virtualenv; set it up as SDK
            final Sdk sdk = SdkConfigurationUtil.createAndAddSDK(executableFile.getPath(), sdkType);
            if (sdk != null) {
                SdkConfigurationUtil.setDirectoryProjectSdk(project, sdk);
                return;
            }
        }
    }
    // default
    SdkConfigurationUtil.configureDirectoryProjectSdk(project, new PreferredSdkComparator(), sdkType);
}
Also used : VirtualFile(com.intellij.openapi.vfs.VirtualFile) PreferredSdkComparator(com.jetbrains.python.sdk.PreferredSdkComparator) ArrayList(java.util.ArrayList) PythonSdkAdditionalData(com.jetbrains.python.sdk.PythonSdkAdditionalData) ProjectJdkImpl(com.intellij.openapi.projectRoots.impl.ProjectJdkImpl) VirtualFileFilter(com.intellij.openapi.vfs.VirtualFileFilter) PythonSdkType(com.jetbrains.python.sdk.PythonSdkType) Sdk(com.intellij.openapi.projectRoots.Sdk) VirtualFile(com.intellij.openapi.vfs.VirtualFile) File(java.io.File) PythonSdkAdditionalData(com.jetbrains.python.sdk.PythonSdkAdditionalData) SdkAdditionalData(com.intellij.openapi.projectRoots.SdkAdditionalData)

Example 9 with SdkAdditionalData

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

the class PythonSdkUpdater method getRemoteSdkMappedPaths.

/**
   * Returns local paths for a remote SDK that have been mapped to remote paths during the skeleton refresh step.
   *
   * Returns all the existing paths except those manually excluded by the user.
   */
@NotNull
private static List<VirtualFile> getRemoteSdkMappedPaths(@NotNull Sdk sdk, @Nullable Project project) {
    final SdkAdditionalData additionalData = sdk.getSdkAdditionalData();
    if (additionalData instanceof PyRemoteSdkAdditionalDataBase) {
        final PyRemoteSdkAdditionalDataBase remoteSdkData = (PyRemoteSdkAdditionalDataBase) additionalData;
        final List<String> paths = Lists.newArrayList();
        for (PathMappingSettings.PathMapping mapping : remoteSdkData.getPathMappings().getPathMappings()) {
            paths.add(mapping.getLocalRoot());
        }
        return filterRootPaths(sdk, paths, project);
    }
    return Collections.emptyList();
}
Also used : PathMappingSettings(com.intellij.util.PathMappingSettings) PyRemoteSdkAdditionalDataBase(com.jetbrains.python.remote.PyRemoteSdkAdditionalDataBase) SdkAdditionalData(com.intellij.openapi.projectRoots.SdkAdditionalData) NotNull(org.jetbrains.annotations.NotNull)

Example 10 with SdkAdditionalData

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

the class PythonSdkUpdater method getUserAddedPaths.

/**
   * Returns all the paths manually added to an SDK by the user.
   */
@NotNull
private static List<VirtualFile> getUserAddedPaths(@NotNull Sdk sdk) {
    final SdkAdditionalData additionalData = sdk.getSdkAdditionalData();
    final PythonSdkAdditionalData pythonAdditionalData = PyUtil.as(additionalData, PythonSdkAdditionalData.class);
    return pythonAdditionalData != null ? Lists.newArrayList(pythonAdditionalData.getAddedPathFiles()) : Collections.emptyList();
}
Also used : SdkAdditionalData(com.intellij.openapi.projectRoots.SdkAdditionalData) NotNull(org.jetbrains.annotations.NotNull)

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