use of com.intellij.openapi.projectRoots.SdkModificator in project intellij-community by JetBrains.
the class PsiTestUtil method addRootsToJdk.
@NotNull
@Contract(pure = true)
public static Sdk addRootsToJdk(@NotNull Sdk sdk, @NotNull OrderRootType rootType, @NotNull VirtualFile... roots) {
Sdk clone;
try {
clone = (Sdk) sdk.clone();
} catch (CloneNotSupportedException e) {
throw new RuntimeException(e);
}
SdkModificator sdkModificator = clone.getSdkModificator();
for (VirtualFile root : roots) {
sdkModificator.addRoot(root, rootType);
}
sdkModificator.commitChanges();
return clone;
}
use of com.intellij.openapi.projectRoots.SdkModificator in project intellij-community by JetBrains.
the class MagicConstantInspection method checkAnnotationsJarAttached.
private static void checkAnnotationsJarAttached(@NotNull PsiFile file, @NotNull ProblemsHolder holder) {
final Project project = file.getProject();
if (!holder.isOnTheFly()) {
final Boolean found = project.getUserData(NO_ANNOTATIONS_FOUND);
if (found != null)
return;
}
PsiClass event = JavaPsiFacade.getInstance(project).findClass("java.awt.event.InputEvent", GlobalSearchScope.allScope(project));
// no jdk to attach
if (event == null)
return;
PsiMethod[] methods = event.findMethodsByName("getModifiers", false);
// no jdk to attach
if (methods.length != 1)
return;
PsiMethod getModifiers = methods[0];
PsiAnnotation annotation = ExternalAnnotationsManager.getInstance(project).findExternalAnnotation(getModifiers, MagicConstant.class.getName());
if (annotation != null)
return;
final VirtualFile virtualFile = PsiUtilCore.getVirtualFile(getModifiers);
// no jdk to attach
if (virtualFile == null)
return;
final List<OrderEntry> entries = ProjectRootManager.getInstance(project).getFileIndex().getOrderEntriesForFile(virtualFile);
Sdk jdk = null;
for (OrderEntry orderEntry : entries) {
if (orderEntry instanceof JdkOrderEntry) {
jdk = ((JdkOrderEntry) orderEntry).getJdk();
if (jdk != null)
break;
}
}
// no jdk to attach
if (jdk == null)
return;
if (!holder.isOnTheFly()) {
project.putUserData(NO_ANNOTATIONS_FOUND, Boolean.TRUE);
}
final Sdk finalJdk = jdk;
String path = finalJdk.getHomePath();
String text = "No IDEA annotations attached to the JDK " + finalJdk.getName() + (path == null ? "" : " (" + FileUtil.toSystemDependentName(path) + ")") + ", some issues will not be found";
holder.registerProblem(file, text, ProblemHighlightType.GENERIC_ERROR_OR_WARNING, new LocalQuickFix() {
@NotNull
@Override
public String getFamilyName() {
return "Attach annotations";
}
@Nullable
@Override
public PsiElement getElementToMakeWritable(@NotNull PsiFile file) {
return null;
}
@Override
public void applyFix(@NotNull Project project, @NotNull ProblemDescriptor descriptor) {
SdkModificator modificator = finalJdk.getSdkModificator();
JavaSdkImpl.attachJdkAnnotations(modificator);
modificator.commitChanges();
}
});
}
use of com.intellij.openapi.projectRoots.SdkModificator in project intellij-community by JetBrains.
the class ExternalAnnotationsManagerImpl method appendChosenAnnotationsRoot.
private void appendChosenAnnotationsRoot(@NotNull final OrderEntry entry, @NotNull final VirtualFile vFile) {
if (entry instanceof LibraryOrderEntry) {
Library library = ((LibraryOrderEntry) entry).getLibrary();
LOG.assertTrue(library != null);
final Library.ModifiableModel model = library.getModifiableModel();
model.addRoot(vFile, AnnotationOrderRootType.getInstance());
model.commit();
} else if (entry instanceof ModuleSourceOrderEntry) {
final ModifiableRootModel model = ModuleRootManager.getInstance(entry.getOwnerModule()).getModifiableModel();
final JavaModuleExternalPaths extension = model.getModuleExtension(JavaModuleExternalPaths.class);
extension.setExternalAnnotationUrls(ArrayUtil.mergeArrays(extension.getExternalAnnotationsUrls(), vFile.getUrl()));
model.commit();
} else if (entry instanceof JdkOrderEntry) {
final SdkModificator sdkModificator = ((JdkOrderEntry) entry).getJdk().getSdkModificator();
sdkModificator.addRoot(vFile, AnnotationOrderRootType.getInstance());
sdkModificator.commitChanges();
}
dropCache();
}
use of com.intellij.openapi.projectRoots.SdkModificator in project intellij-community by JetBrains.
the class PluginRunConfiguration method getState.
@Override
public RunProfileState getState(@NotNull final Executor executor, @NotNull final ExecutionEnvironment env) throws ExecutionException {
final Module module = getModule();
if (module == null) {
throw new ExecutionException(DevKitBundle.message("run.configuration.no.module.specified"));
}
final ModuleRootManager rootManager = ModuleRootManager.getInstance(module);
final Sdk jdk = rootManager.getSdk();
if (jdk == null) {
throw CantRunException.noJdkForModule(module);
}
final Sdk ideaJdk = IdeaJdk.findIdeaJdk(jdk);
if (ideaJdk == null) {
throw new ExecutionException(DevKitBundle.message("sdk.type.incorrect.common"));
}
String sandboxHome = ((Sandbox) ideaJdk.getSdkAdditionalData()).getSandboxHome();
if (sandboxHome == null) {
throw new ExecutionException(DevKitBundle.message("sandbox.no.configured"));
}
try {
sandboxHome = new File(sandboxHome).getCanonicalPath();
} catch (IOException e) {
throw new ExecutionException(DevKitBundle.message("sandbox.no.configured"));
}
final String canonicalSandbox = sandboxHome;
//copy license from running instance of idea
IdeaLicenseHelper.copyIDEALicense(sandboxHome);
final JavaCommandLineState state = new JavaCommandLineState(env) {
@Override
protected JavaParameters createJavaParameters() throws ExecutionException {
final JavaParameters params = new JavaParameters();
ParametersList vm = params.getVMParametersList();
fillParameterList(vm, VM_PARAMETERS);
fillParameterList(params.getProgramParametersList(), PROGRAM_PARAMETERS);
Sdk usedIdeaJdk = ideaJdk;
String alternativeIdePath = getAlternativeJrePath();
if (isAlternativeJreEnabled() && !StringUtil.isEmptyOrSpaces(alternativeIdePath)) {
final Sdk configuredJdk = ProjectJdkTable.getInstance().findJdk(alternativeIdePath);
if (configuredJdk != null) {
usedIdeaJdk = configuredJdk;
} else {
try {
usedIdeaJdk = (Sdk) usedIdeaJdk.clone();
} catch (CloneNotSupportedException e) {
throw new ExecutionException(e.getMessage());
}
final SdkModificator sdkToSetUp = usedIdeaJdk.getSdkModificator();
sdkToSetUp.setHomePath(alternativeIdePath);
sdkToSetUp.commitChanges();
}
}
String ideaJdkHome = usedIdeaJdk.getHomePath();
boolean fromIdeaProject = IdeaJdk.isFromIDEAProject(ideaJdkHome);
if (!fromIdeaProject) {
String bootPath = "/lib/boot.jar";
vm.add("-Xbootclasspath/a:" + ideaJdkHome + toSystemDependentName(bootPath));
}
vm.defineProperty("idea.config.path", canonicalSandbox + File.separator + "config");
vm.defineProperty("idea.system.path", canonicalSandbox + File.separator + "system");
vm.defineProperty("idea.plugins.path", canonicalSandbox + File.separator + "plugins");
vm.defineProperty("idea.classpath.index.enabled", "false");
if (!vm.hasProperty(JetBrainsProtocolHandler.REQUIRED_PLUGINS_KEY) && PluginModuleType.isOfType(module)) {
final String id = DescriptorUtil.getPluginId(module);
if (id != null) {
vm.defineProperty(JetBrainsProtocolHandler.REQUIRED_PLUGINS_KEY, id);
}
}
if (SystemInfo.isMac) {
vm.defineProperty("idea.smooth.progress", "false");
vm.defineProperty("apple.laf.useScreenMenuBar", "true");
vm.defineProperty("apple.awt.fileDialogForDirectories", "true");
}
if (SystemInfo.isXWindow) {
if (VM_PARAMETERS == null || !VM_PARAMETERS.contains("-Dsun.awt.disablegrab")) {
// See http://devnet.jetbrains.net/docs/DOC-1142
vm.defineProperty("sun.awt.disablegrab", "true");
}
}
if (!vm.hasProperty(PlatformUtils.PLATFORM_PREFIX_KEY)) {
String buildNumber = IdeaJdk.getBuildNumber(ideaJdkHome);
if (buildNumber != null) {
String prefix = IntelliJPlatformProduct.fromBuildNumber(buildNumber).getPlatformPrefix();
if (prefix != null) {
vm.defineProperty(PlatformUtils.PLATFORM_PREFIX_KEY, prefix);
}
}
}
params.setWorkingDirectory(ideaJdkHome + File.separator + "bin" + File.separator);
params.setJdk(usedIdeaJdk);
if (fromIdeaProject) {
OrderEnumerator enumerator = OrderEnumerator.orderEntries(module).recursively();
for (VirtualFile file : enumerator.getAllLibrariesAndSdkClassesRoots()) {
params.getClassPath().add(file);
}
} else {
for (String path : Arrays.asList("log4j.jar", "jdom.jar", "trove4j.jar", "openapi.jar", "util.jar", "extensions.jar", "bootstrap.jar", "idea_rt.jar", "idea.jar")) {
params.getClassPath().add(ideaJdkHome + toSystemDependentName("/lib/" + path));
}
}
params.getClassPath().addFirst(((JavaSdkType) usedIdeaJdk.getSdkType()).getToolsPath(usedIdeaJdk));
params.setMainClass("com.intellij.idea.Main");
return params;
}
};
return state;
}
use of com.intellij.openapi.projectRoots.SdkModificator in project intellij-community by JetBrains.
the class ModuleRootManagerTestCase method retainRtJarOnlyAndSetVersion.
@NotNull
@Contract(pure = true)
private static Sdk retainRtJarOnlyAndSetVersion(Sdk jdk) {
try {
jdk = (Sdk) jdk.clone();
} catch (CloneNotSupportedException e) {
throw new RuntimeException(e);
}
final SdkModificator modificator = jdk.getSdkModificator();
VirtualFile rtJar = null;
for (VirtualFile root : modificator.getRoots(OrderRootType.CLASSES)) {
if (root.getName().equals("rt.jar")) {
rtJar = root;
break;
}
}
assertNotNull("rt.jar not found in jdk: " + jdk, rtJar);
modificator.setVersionString(IdeaTestUtil.getMockJdkVersion(jdk.getHomePath()));
modificator.removeAllRoots();
modificator.addRoot(rtJar, OrderRootType.CLASSES);
modificator.commitChanges();
return jdk;
}
Aggregations