Search in sources :

Example 1 with JpsDependencyElement

use of org.jetbrains.jps.model.module.JpsDependencyElement in project intellij-community by JetBrains.

the class DependencyResolvingBuilder method getRepositoryLibraries.

@NotNull
private static Collection<JpsTypedLibrary<JpsSimpleElement<RepositoryLibraryDescriptor>>> getRepositoryLibraries(ModuleChunk chunk) {
    final Collection<JpsTypedLibrary<JpsSimpleElement<RepositoryLibraryDescriptor>>> result = new SmartHashSet<>();
    for (JpsModule module : chunk.getModules()) {
        for (JpsDependencyElement dep : module.getDependenciesList().getDependencies()) {
            if (dep instanceof JpsLibraryDependency) {
                final JpsLibrary _lib = ((JpsLibraryDependency) dep).getLibrary();
                final JpsTypedLibrary<JpsSimpleElement<RepositoryLibraryDescriptor>> lib = _lib != null ? _lib.asTyped(JpsMavenRepositoryLibraryType.INSTANCE) : null;
                if (lib != null) {
                    result.add(lib);
                }
            }
        }
    }
    return result;
}
Also used : JpsLibraryDependency(org.jetbrains.jps.model.module.JpsLibraryDependency) SmartHashSet(com.intellij.util.containers.SmartHashSet) JpsModule(org.jetbrains.jps.model.module.JpsModule) JpsTypedLibrary(org.jetbrains.jps.model.library.JpsTypedLibrary) JpsDependencyElement(org.jetbrains.jps.model.module.JpsDependencyElement) RepositoryLibraryDescriptor(org.jetbrains.jps.maven.model.RepositoryLibraryDescriptor) JpsSimpleElement(org.jetbrains.jps.model.JpsSimpleElement) JpsLibrary(org.jetbrains.jps.model.library.JpsLibrary) NotNull(org.jetbrains.annotations.NotNull)

Example 2 with JpsDependencyElement

use of org.jetbrains.jps.model.module.JpsDependencyElement in project intellij-community by JetBrains.

the class JpsMavenModuleSerializationTest method testLoadProject.

public void testLoadProject() {
    loadProject("plugins/maven/jps-plugin/testData/compiler/classpathTest");
    List<JpsModule> modules = myProject.getModules();
    assertEquals(3, modules.size());
    JpsModule main = modules.get(0);
    assertEquals("main", main.getName());
    JpsModule dep = modules.get(1);
    assertEquals("dep", dep.getName());
    JpsModule depTest = modules.get(2);
    assertEquals("dep-test", depTest.getName());
    for (JpsModule module : modules) {
        assertNotNull(getService().getExtension(module));
    }
    List<JpsDependencyElement> dependencies = main.getDependenciesList().getDependencies();
    assertEquals(5, dependencies.size());
    assertTrue(getService().isProductionOnTestDependency(dependencies.get(3)));
    assertFalse(getService().isProductionOnTestDependency(dependencies.get(4)));
}
Also used : JpsModule(org.jetbrains.jps.model.module.JpsModule) JpsDependencyElement(org.jetbrains.jps.model.module.JpsDependencyElement)

Example 3 with JpsDependencyElement

use of org.jetbrains.jps.model.module.JpsDependencyElement 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 4 with JpsDependencyElement

use of org.jetbrains.jps.model.module.JpsDependencyElement in project android by JetBrains.

the class AndroidBuildDataCache method collectAndroidDependencies.

private static void collectAndroidDependencies(@NotNull JpsModule module, @NotNull MyAndroidDeps result, @NotNull Set<String> visitedSet, boolean fillLibs, boolean recursively) {
    final List<JpsDependencyElement> dependencies = new ArrayList<JpsDependencyElement>(JpsJavaExtensionService.getInstance().getDependencies(module, JpsJavaClasspathKind.PRODUCTION_RUNTIME, false));
    for (int i = dependencies.size() - 1; i >= 0; i--) {
        final JpsDependencyElement item = dependencies.get(i);
        if (item instanceof JpsModuleDependency) {
            final JpsModule depModule = ((JpsModuleDependency) item).getModule();
            if (depModule != null) {
                final JpsAndroidModuleExtension depExtension = AndroidJpsUtil.getExtension(depModule);
                if (depExtension != null && visitedSet.add(depModule.getName())) {
                    if (recursively) {
                        final boolean newRecursively = AndroidJpsUtil.shouldProcessDependenciesRecursively(depModule);
                        collectAndroidDependencies(depModule, result, visitedSet, fillLibs && depExtension.isLibrary(), newRecursively);
                    }
                    result.myAndroidDeps.add(depExtension);
                    if (fillLibs && depExtension.isLibrary()) {
                        result.myLibAndroidDeps.add(depExtension);
                    }
                }
            }
        }
    }
}
Also used : JpsModule(org.jetbrains.jps.model.module.JpsModule) JpsModuleDependency(org.jetbrains.jps.model.module.JpsModuleDependency) JpsDependencyElement(org.jetbrains.jps.model.module.JpsDependencyElement) JpsAndroidModuleExtension(org.jetbrains.jps.android.model.JpsAndroidModuleExtension)

Example 5 with JpsDependencyElement

use of org.jetbrains.jps.model.module.JpsDependencyElement in project intellij-community by JetBrains.

the class JpsJavaExtensionTest method testDependency.

public void testDependency() {
    final JpsModel model = myModel.createModifiableModel(new TestJpsEventDispatcher());
    final JpsModule module = model.getProject().addModule("m", JpsJavaModuleType.INSTANCE);
    final JpsLibrary library = model.getProject().addLibrary("l", JpsJavaLibraryType.INSTANCE);
    final JpsLibraryDependency dependency = module.getDependenciesList().addLibraryDependency(library);
    getJavaService().getOrCreateDependencyExtension(dependency).setScope(JpsJavaDependencyScope.TEST);
    getJavaService().getOrCreateDependencyExtension(dependency).setExported(true);
    model.commit();
    List<JpsDependencyElement> dependencies = assertOneElement(myProject.getModules()).getDependenciesList().getDependencies();
    assertEquals(2, dependencies.size());
    final JpsDependencyElement dep = dependencies.get(1);
    final JpsJavaDependencyExtension extension = getJavaService().getDependencyExtension(dep);
    assertNotNull(extension);
    assertTrue(extension.isExported());
    assertSame(JpsJavaDependencyScope.TEST, extension.getScope());
}
Also used : JpsLibraryDependency(org.jetbrains.jps.model.module.JpsLibraryDependency) JpsModule(org.jetbrains.jps.model.module.JpsModule) JpsDependencyElement(org.jetbrains.jps.model.module.JpsDependencyElement) JpsLibrary(org.jetbrains.jps.model.library.JpsLibrary)

Aggregations

JpsDependencyElement (org.jetbrains.jps.model.module.JpsDependencyElement)7 JpsModule (org.jetbrains.jps.model.module.JpsModule)7 JpsLibrary (org.jetbrains.jps.model.library.JpsLibrary)3 JpsLibraryDependency (org.jetbrains.jps.model.module.JpsLibraryDependency)3 File (java.io.File)2 NotNull (org.jetbrains.annotations.NotNull)2 JpsModuleDependency (org.jetbrains.jps.model.module.JpsModuleDependency)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