use of org.jetbrains.jps.model.library.sdk.JpsSdkReference in project intellij-community by JetBrains.
the class IdeaJdk method setupSdkPathsFromIDEAProject.
private static void setupSdkPathsFromIDEAProject(Sdk sdk, SdkModificator sdkModificator, SdkModel sdkModel) throws IOException {
ProgressIndicator indicator = ObjectUtils.assertNotNull(ProgressManager.getInstance().getProgressIndicator());
String sdkHome = ObjectUtils.notNull(sdk.getHomePath());
JpsModel model = JpsSerializationManager.getInstance().loadModel(sdkHome, PathManager.getOptionsPath());
JpsSdkReference<JpsDummyElement> sdkRef = model.getProject().getSdkReferencesTable().getSdkReference(JpsJavaSdkType.INSTANCE);
String sdkName = sdkRef == null ? null : sdkRef.getSdkName();
Sdk internalJava = sdkModel.findSdk(sdkName);
if (internalJava != null && isValidInternalJdk(sdk, internalJava)) {
setInternalJdk(sdk, sdkModificator, internalJava);
}
Set<VirtualFile> addedRoots = ContainerUtil.newTroveSet();
VirtualFileManager vfsManager = VirtualFileManager.getInstance();
JpsJavaExtensionService javaService = JpsJavaExtensionService.getInstance();
boolean isUltimate = vfsManager.findFileByUrl(VfsUtilCore.pathToUrl(sdkHome + "/ultimate/ultimate-resources")) != null;
Set<String> suppressedModules = ContainerUtil.newTroveSet("jps-plugin-system");
Set<String> ultimateModules = ContainerUtil.newTroveSet("platform-ultimate", "ultimate-resources", "ultimate-verifier", "diagram-api", "diagram-impl", "uml-plugin");
List<JpsModule> modules = JBIterable.from(model.getProject().getModules()).filter(o -> {
if (suppressedModules.contains(o.getName()))
return false;
if (o.getName().endsWith("-ide"))
return false;
String contentUrl = ContainerUtil.getFirstItem(o.getContentRootsList().getUrls());
if (contentUrl == null)
return true;
return !isUltimate || contentUrl.contains("/community/") || ultimateModules.contains(o.getName());
}).toList();
indicator.setIndeterminate(false);
double delta = 1 / (2 * Math.max(0.5, modules.size()));
for (JpsModule o : modules) {
indicator.setFraction(indicator.getFraction() + delta);
for (JpsDependencyElement dep : o.getDependenciesList().getDependencies()) {
ProgressManager.checkCanceled();
JpsLibrary library = dep instanceof JpsLibraryDependency ? ((JpsLibraryDependency) dep).getLibrary() : null;
JpsLibraryType<?> libraryType = library == null ? null : library.getType();
if (!(libraryType instanceof JpsJavaLibraryType))
continue;
JpsJavaDependencyExtension extension = javaService.getDependencyExtension(dep);
if (extension == null)
continue;
// do not check extension.getScope(), plugin projects need tests too
for (JpsLibraryRoot jps : library.getRoots(JpsOrderRootType.COMPILED)) {
VirtualFile root = vfsManager.findFileByUrl(jps.getUrl());
if (root == null || !addedRoots.add(root))
continue;
sdkModificator.addRoot(root, OrderRootType.CLASSES);
}
for (JpsLibraryRoot jps : library.getRoots(JpsOrderRootType.SOURCES)) {
VirtualFile root = vfsManager.findFileByUrl(jps.getUrl());
if (root == null || !addedRoots.add(root))
continue;
sdkModificator.addRoot(root, OrderRootType.SOURCES);
}
}
}
for (JpsModule o : modules) {
indicator.setFraction(indicator.getFraction() + delta);
String outputUrl = javaService.getOutputUrl(o, false);
VirtualFile outputRoot = outputUrl == null ? null : vfsManager.findFileByUrl(outputUrl);
if (outputRoot == null)
continue;
sdkModificator.addRoot(outputRoot, OrderRootType.CLASSES);
for (JpsModuleSourceRoot jps : o.getSourceRoots()) {
ProgressManager.checkCanceled();
VirtualFile root = vfsManager.findFileByUrl(jps.getUrl());
if (root == null || !addedRoots.add(root))
continue;
sdkModificator.addRoot(root, OrderRootType.SOURCES);
}
}
indicator.setFraction(1.0);
}
use of org.jetbrains.jps.model.library.sdk.JpsSdkReference in project intellij-community by JetBrains.
the class JpsModuleRootModelSerializer method saveRootModel.
public static void saveRootModel(JpsModule module, Element rootModelElement) {
List<JpsModuleSourceRoot> sourceRoots = module.getSourceRoots();
List<String> excludedUrls = getSortedList(module.getExcludeRootsList().getUrls());
for (String url : getSortedList(module.getContentRootsList().getUrls())) {
Element contentElement = new Element(CONTENT_TAG);
contentElement.setAttribute(URL_ATTRIBUTE, url);
rootModelElement.addContent(contentElement);
for (JpsModuleSourceRoot root : sourceRoots) {
if (FileUtil.startsWith(root.getUrl(), url)) {
saveSourceRoot(contentElement, root.asTyped().getUrl(), root.asTyped());
}
}
for (String excludedUrl : excludedUrls) {
if (FileUtil.startsWith(excludedUrl, url)) {
Element element = new Element(EXCLUDE_FOLDER_TAG).setAttribute(URL_ATTRIBUTE, excludedUrl);
contentElement.addContent(element);
}
}
}
for (JpsDependencyElement dependency : module.getDependenciesList().getDependencies()) {
if (dependency instanceof JpsModuleSourceDependency) {
rootModelElement.addContent(createDependencyElement(SOURCE_FOLDER_TYPE).setAttribute("forTests", "false"));
} else if (dependency instanceof JpsSdkDependency) {
JpsSdkType<?> sdkType = ((JpsSdkDependency) dependency).getSdkType();
JpsSdkReferencesTable table = module.getSdkReferencesTable();
JpsSdkReference<?> reference = table.getSdkReference(sdkType);
if (reference == null) {
rootModelElement.addContent(createDependencyElement(INHERITED_JDK_TYPE));
} else {
Element element = createDependencyElement(JDK_TYPE);
element.setAttribute(JDK_NAME_ATTRIBUTE, reference.getSdkName());
element.setAttribute(JDK_TYPE_ATTRIBUTE, JpsSdkTableSerializer.getLoader(sdkType).getTypeId());
rootModelElement.addContent(element);
}
} else if (dependency instanceof JpsLibraryDependency) {
JpsLibraryReference reference = ((JpsLibraryDependency) dependency).getLibraryReference();
JpsElementReference<? extends JpsCompositeElement> parentReference = reference.getParentReference();
Element element;
if (parentReference instanceof JpsModuleReference) {
element = createDependencyElement(MODULE_LIBRARY_TYPE);
saveModuleDependencyProperties(dependency, element);
Element libraryElement = new Element(LIBRARY_TAG);
JpsLibrary library = reference.resolve();
String libraryName = library.getName();
JpsLibraryTableSerializer.saveLibrary(library, libraryElement, isGeneratedName(libraryName) ? null : libraryName);
element.addContent(libraryElement);
} else {
element = createDependencyElement(LIBRARY_TYPE);
saveModuleDependencyProperties(dependency, element);
element.setAttribute(NAME_ATTRIBUTE, reference.getLibraryName());
element.setAttribute(LEVEL_ATTRIBUTE, JpsLibraryTableSerializer.getLevelId(parentReference));
}
rootModelElement.addContent(element);
} else if (dependency instanceof JpsModuleDependency) {
Element element = createDependencyElement(MODULE_TYPE);
element.setAttribute(MODULE_NAME_ATTRIBUTE, ((JpsModuleDependency) dependency).getModuleReference().getModuleName());
saveModuleDependencyProperties(dependency, element);
rootModelElement.addContent(element);
}
}
for (JpsModelSerializerExtension extension : JpsModelSerializerExtension.getExtensions()) {
extension.saveRootModel(module, rootModelElement);
}
}
Aggregations