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);
}
}
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());
}
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);
}
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();
}
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();
}
Aggregations