Search in sources :

Example 1 with JpsLibraryRoot

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);
}
Also used : VirtualFile(com.intellij.openapi.vfs.VirtualFile) JpsLibraryRoot(org.jetbrains.jps.model.library.JpsLibraryRoot) VirtualFilePointer(com.intellij.openapi.vfs.pointers.VirtualFilePointer) VirtualFilePointerContainer(com.intellij.openapi.vfs.pointers.VirtualFilePointerContainer) NotNull(org.jetbrains.annotations.NotNull)

Example 2 with JpsLibraryRoot

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);
}
Also used : VirtualFile(com.intellij.openapi.vfs.VirtualFile) Arrays(java.util.Arrays) JBIterable(com.intellij.util.containers.JBIterable) VirtualFile(com.intellij.openapi.vfs.VirtualFile) JpsJavaLibraryType(org.jetbrains.jps.model.java.JpsJavaLibraryType) VirtualFileManager(com.intellij.openapi.vfs.VirtualFileManager) Messages(com.intellij.openapi.ui.Messages) ZipFile(java.util.zip.ZipFile) FileUtil(com.intellij.openapi.util.io.FileUtil) Logger(com.intellij.openapi.diagnostic.Logger) ZipEntry(java.util.zip.ZipEntry) JpsLibrary(org.jetbrains.jps.model.library.JpsLibrary) ProgressManager(com.intellij.openapi.progress.ProgressManager) LanguageLevel(com.intellij.pom.java.LanguageLevel) OrderRootType(com.intellij.openapi.roots.OrderRootType) Set(java.util.Set) JpsLibraryDependency(org.jetbrains.jps.model.module.JpsLibraryDependency) JpsJavaDependencyExtension(org.jetbrains.jps.model.java.JpsJavaDependencyExtension) JpsModule(org.jetbrains.jps.model.module.JpsModule) ThrowableComputable(com.intellij.openapi.util.ThrowableComputable) Nullable(org.jetbrains.annotations.Nullable) ProgressIndicator(com.intellij.openapi.progress.ProgressIndicator) List(java.util.List) ApplicationStarter(com.intellij.openapi.application.ApplicationStarter) JavaDependentSdkType(com.intellij.openapi.projectRoots.impl.JavaDependentSdkType) JpsSerializationManager(org.jetbrains.jps.model.serialization.JpsSerializationManager) WriteExternalException(com.intellij.openapi.util.WriteExternalException) NotNull(org.jetbrains.annotations.NotNull) DataInputStream(java.io.DataInputStream) JpsDummyElement(org.jetbrains.jps.model.JpsDummyElement) ArrayUtil(com.intellij.util.ArrayUtil) JpsOrderRootType(org.jetbrains.jps.model.library.JpsOrderRootType) PathManager(com.intellij.openapi.application.PathManager) DevkitIcons(icons.DevkitIcons) NonNls(org.jetbrains.annotations.NonNls) InvalidDataException(com.intellij.openapi.util.InvalidDataException) ContainerUtil(com.intellij.util.containers.ContainerUtil) JavadocOrderRootType(com.intellij.openapi.roots.JavadocOrderRootType) JpsLibraryType(org.jetbrains.jps.model.library.JpsLibraryType) ClsParsingUtil(com.intellij.psi.impl.compiled.ClsParsingUtil) ArrayList(java.util.ArrayList) ProcessCanceledException(com.intellij.openapi.progress.ProcessCanceledException) JpsSdkReference(org.jetbrains.jps.model.library.sdk.JpsSdkReference) com.intellij.openapi.projectRoots(com.intellij.openapi.projectRoots) JpsJavaExtensionService(org.jetbrains.jps.model.java.JpsJavaExtensionService) JpsModel(org.jetbrains.jps.model.JpsModel) JpsDependencyElement(org.jetbrains.jps.model.module.JpsDependencyElement) JpsJavaSdkType(org.jetbrains.jps.model.java.JpsJavaSdkType) JpsModuleSourceRoot(org.jetbrains.jps.model.module.JpsModuleSourceRoot) VfsUtilCore(com.intellij.openapi.vfs.VfsUtilCore) JpsLibraryRoot(org.jetbrains.jps.model.library.JpsLibraryRoot) IOException(java.io.IOException) SystemInfo(com.intellij.openapi.util.SystemInfo) File(java.io.File) DevKitBundle(org.jetbrains.idea.devkit.DevKitBundle) AnnotationOrderRootType(com.intellij.openapi.roots.AnnotationOrderRootType) JarFileSystem(com.intellij.openapi.vfs.JarFileSystem) ObjectUtils(com.intellij.util.ObjectUtils) Element(org.jdom.Element) javax.swing(javax.swing) JpsLibraryDependency(org.jetbrains.jps.model.module.JpsLibraryDependency) JpsModel(org.jetbrains.jps.model.JpsModel) VirtualFileManager(com.intellij.openapi.vfs.VirtualFileManager) JpsDependencyElement(org.jetbrains.jps.model.module.JpsDependencyElement) JpsJavaLibraryType(org.jetbrains.jps.model.java.JpsJavaLibraryType) JpsModule(org.jetbrains.jps.model.module.JpsModule) JpsModuleSourceRoot(org.jetbrains.jps.model.module.JpsModuleSourceRoot) JpsJavaExtensionService(org.jetbrains.jps.model.java.JpsJavaExtensionService) ProgressIndicator(com.intellij.openapi.progress.ProgressIndicator) JpsJavaDependencyExtension(org.jetbrains.jps.model.java.JpsJavaDependencyExtension) JpsDummyElement(org.jetbrains.jps.model.JpsDummyElement) JpsLibrary(org.jetbrains.jps.model.library.JpsLibrary) JpsLibraryRoot(org.jetbrains.jps.model.library.JpsLibraryRoot)

Example 3 with JpsLibraryRoot

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;
}
Also used : JpsLibrary(org.jetbrains.jps.model.library.JpsLibrary) JpsLibraryRoot(org.jetbrains.jps.model.library.JpsLibraryRoot)

Example 4 with JpsLibraryRoot

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);
            }
        }
    }
}
Also used : JpsLibrary(org.jetbrains.jps.model.library.JpsLibrary) JpsLibraryRoot(org.jetbrains.jps.model.library.JpsLibraryRoot)

Example 5 with JpsLibraryRoot

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);
}
Also used : JpsElement(org.jetbrains.jps.model.JpsElement) JpsDummyElement(org.jetbrains.jps.model.JpsDummyElement) Element(org.jdom.Element) JpsLibrary(org.jetbrains.jps.model.library.JpsLibrary) JpsLibraryRoot(org.jetbrains.jps.model.library.JpsLibraryRoot)

Aggregations

JpsLibraryRoot (org.jetbrains.jps.model.library.JpsLibraryRoot)7 JpsLibrary (org.jetbrains.jps.model.library.JpsLibrary)6 VirtualFile (com.intellij.openapi.vfs.VirtualFile)2 NotNull (org.jetbrains.annotations.NotNull)2 ApplicationStarter (com.intellij.openapi.application.ApplicationStarter)1 PathManager (com.intellij.openapi.application.PathManager)1 Logger (com.intellij.openapi.diagnostic.Logger)1 ProcessCanceledException (com.intellij.openapi.progress.ProcessCanceledException)1 ProgressIndicator (com.intellij.openapi.progress.ProgressIndicator)1 ProgressManager (com.intellij.openapi.progress.ProgressManager)1 com.intellij.openapi.projectRoots (com.intellij.openapi.projectRoots)1 JavaDependentSdkType (com.intellij.openapi.projectRoots.impl.JavaDependentSdkType)1 AnnotationOrderRootType (com.intellij.openapi.roots.AnnotationOrderRootType)1 JavadocOrderRootType (com.intellij.openapi.roots.JavadocOrderRootType)1 OrderRootType (com.intellij.openapi.roots.OrderRootType)1 Messages (com.intellij.openapi.ui.Messages)1 InvalidDataException (com.intellij.openapi.util.InvalidDataException)1 SystemInfo (com.intellij.openapi.util.SystemInfo)1 ThrowableComputable (com.intellij.openapi.util.ThrowableComputable)1 WriteExternalException (com.intellij.openapi.util.WriteExternalException)1