use of org.jetbrains.jps.model.library.JpsLibraryRoot in project intellij-community by JetBrains.
the class JpsLibraryDelegate method getFiles.
@NotNull
@Override
public VirtualFile[] getFiles(@NotNull OrderRootType rootType) {
final VirtualFilePointerContainer container = myRoots.get(rootType);
if (container == null)
return VirtualFile.EMPTY_ARRAY;
final List<VirtualFile> expanded = new ArrayList<>();
for (JpsLibraryRoot root : myJpsLibrary.getRoots(getJpsRootType(rootType))) {
final VirtualFilePointer pointer = container.findByUrl(root.getUrl());
if (pointer == null)
continue;
VirtualFile file = pointer.getFile();
if (file == null)
continue;
if (file.isDirectory() && root.getInclusionOptions() != JpsLibraryRoot.InclusionOptions.ROOT_ITSELF) {
LibraryImpl.collectJarFiles(file, expanded, root.getInclusionOptions() == JpsLibraryRoot.InclusionOptions.ARCHIVES_UNDER_ROOT_RECURSIVELY);
continue;
}
expanded.add(file);
}
return VfsUtilCore.toVirtualFileArray(expanded);
}
use of org.jetbrains.jps.model.library.JpsLibraryRoot 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.JpsLibraryRoot in project kotlin by JetBrains.
the class JpsUtils method isJsKotlinModuleImpl.
private static boolean isJsKotlinModuleImpl(@NotNull ModuleBuildTarget target) {
TargetPlatformKind<?> targetPlatform = JpsKotlinCompilerSettingsKt.getTargetPlatform(target.getModule());
if (targetPlatform != null)
return targetPlatform == TargetPlatformKind.JavaScript.INSTANCE;
Set<JpsLibrary> libraries = getAllDependencies(target).getLibraries();
for (JpsLibrary library : libraries) {
for (JpsLibraryRoot root : library.getRoots(JpsOrderRootType.COMPILED)) {
String url = root.getUrl();
Boolean cachedValue = IS_KOTLIN_JS_STDLIB_JAR_CACHE.get(url);
if (cachedValue != null) {
if (cachedValue.booleanValue())
return true;
else
continue;
}
boolean isKotlinJavascriptStdLibrary = LibraryUtils.isKotlinJavascriptStdLibrary(JpsPathUtil.urlToFile(url));
IS_KOTLIN_JS_STDLIB_JAR_CACHE.put(url, isKotlinJavascriptStdLibrary);
if (isKotlinJavascriptStdLibrary)
return true;
}
}
return false;
}
use of org.jetbrains.jps.model.library.JpsLibraryRoot in project android by JetBrains.
the class AndroidJpsUtil method processClasspath.
private static void processClasspath(@NotNull BuildDataPaths paths, @NotNull final JpsModule module, @NotNull final AndroidDependencyProcessor processor, @NotNull final Set<String> visitedModules, final boolean exportedLibrariesOnly, final boolean recursive, final boolean resolveJars, final boolean withAarDeps) {
if (!visitedModules.add(module.getName())) {
return;
}
if (processor.isToProcess(AndroidDependencyType.EXTERNAL_LIBRARY)) {
for (JpsDependencyElement item : JpsJavaExtensionService.getInstance().getDependencies(module, JpsJavaClasspathKind.PRODUCTION_RUNTIME, exportedLibrariesOnly)) {
if (item instanceof JpsLibraryDependency) {
final JpsLibrary library = ((JpsLibraryDependency) item).getLibrary();
if (library != null && (withAarDeps || getResDirAndJarsIfAar(library) == null)) {
for (JpsLibraryRoot root : library.getRoots(JpsOrderRootType.COMPILED)) {
final File file = JpsPathUtil.urlToFile(root.getUrl());
if (resolveJars) {
processClassFilesAndJarsRecursively(file, new Processor<File>() {
@Override
public boolean process(File file) {
processor.processExternalLibrary(file);
return true;
}
});
} else {
processor.processExternalLibrary(file);
}
}
}
}
}
}
if (processor.isToProcess(AndroidDependencyType.PROVIDED_LIBRARY)) {
for (JpsDependencyElement item : module.getDependenciesList().getDependencies()) {
if (item instanceof JpsLibraryDependency) {
final JpsLibrary library = ((JpsLibraryDependency) item).getLibrary();
final JpsJavaDependencyExtension extension = JpsJavaExtensionService.getInstance().getDependencyExtension(item);
if (library != null && extension != null && extension.getScope() == JpsJavaDependencyScope.PROVIDED) {
for (JpsLibraryRoot root : library.getRoots(JpsOrderRootType.COMPILED)) {
processor.processProvidedLibrary(JpsPathUtil.urlToFile(root.getUrl()));
}
}
}
}
}
for (JpsDependencyElement item : JpsJavaExtensionService.getInstance().getDependencies(module, JpsJavaClasspathKind.PRODUCTION_RUNTIME, false)) {
if (item instanceof JpsModuleDependency) {
final JpsModule depModule = ((JpsModuleDependency) item).getModule();
if (depModule == null)
continue;
final JpsAndroidModuleExtension depExtension = getExtension(depModule);
final boolean depLibrary = depExtension != null && depExtension.isLibrary();
final File depClassDir = new ModuleBuildTarget(depModule, JavaModuleBuildTargetType.PRODUCTION).getOutputDir();
if (depLibrary) {
if (processor.isToProcess(AndroidDependencyType.ANDROID_LIBRARY_PACKAGE)) {
final File intArtifactsDir = getDirectoryForIntermediateArtifacts(paths, depModule);
final File packagedClassesJar = new File(intArtifactsDir, AndroidCommonUtils.CLASSES_JAR_FILE_NAME);
processor.processAndroidLibraryPackage(packagedClassesJar, depModule);
}
if (processor.isToProcess(AndroidDependencyType.ANDROID_LIBRARY_OUTPUT_DIRECTORY)) {
if (depClassDir != null) {
processor.processAndroidLibraryOutputDirectory(depClassDir);
}
}
} else if (processor.isToProcess(AndroidDependencyType.JAVA_MODULE_OUTPUT_DIR) && depExtension == null && depClassDir != null) {
// do not support android-app->android-app compile dependencies
processor.processJavaModuleOutputDirectory(depClassDir);
}
if (recursive) {
final boolean newRecursive = shouldProcessDependenciesRecursively(depModule);
processClasspath(paths, depModule, processor, visitedModules, !depLibrary || exportedLibrariesOnly, newRecursive, resolveJars, withAarDeps);
}
}
}
}
use of org.jetbrains.jps.model.library.JpsLibraryRoot in project intellij-community by JetBrains.
the class JpsSdkTableSerializer method saveSdk.
private static <P extends JpsElement> void saveSdk(final JpsSdk<P> sdk, Element sdkTag) {
JpsLibrary library = sdk.getParent();
sdkTag.setAttribute("version", "2");
setAttributeValue(sdkTag, NAME_TAG, library.getName());
JpsSdkPropertiesSerializer<P> serializer = getSdkPropertiesSerializer(sdk.getSdkType());
setAttributeValue(sdkTag, TYPE_TAG, serializer.getTypeId());
String versionString = sdk.getVersionString();
if (versionString != null) {
setAttributeValue(sdkTag, VERSION_TAG, versionString);
}
setAttributeValue(sdkTag, HOME_PATH_TAG, sdk.getHomePath());
Element rootsTag = new Element(ROOTS_TAG);
for (JpsLibraryRootTypeSerializer rootTypeSerializer : getRootTypeSerializers()) {
Element rootTypeTag = new Element(rootTypeSerializer.getTypeId());
Element compositeTag = new Element(ROOT_TAG);
compositeTag.setAttribute(TYPE_ATTRIBUTE, COMPOSITE_TYPE);
List<JpsLibraryRoot> roots = library.getRoots(rootTypeSerializer.getType());
for (JpsLibraryRoot root : roots) {
compositeTag.addContent(new Element(ROOT_TAG).setAttribute(TYPE_ATTRIBUTE, SIMPLE_TYPE).setAttribute(URL_ATTRIBUTE, root.getUrl()));
}
rootTypeTag.addContent(compositeTag);
rootsTag.addContent(rootTypeTag);
}
sdkTag.addContent(rootsTag);
Element additionalTag = new Element(ADDITIONAL_TAG);
serializer.saveProperties(sdk.getSdkProperties(), additionalTag);
sdkTag.addContent(additionalTag);
}
Aggregations