Search in sources :

Example 16 with MavenArtifact

use of org.jetbrains.idea.maven.model.MavenArtifact in project intellij-community by JetBrains.

the class ManifestImporter method getClasspath.

@NotNull
public String getClasspath(@NotNull MavenProject mavenProject, @Nullable Element manifestConfiguration) {
    StringBuilder classpath = new StringBuilder();
    String classpathPrefix = getClasspathPrefix(manifestConfiguration);
    for (MavenArtifact mavenArtifact : mavenProject.getDependencies()) {
        final DependencyScope scope = MavenModuleImporter.selectScope(mavenArtifact.getScope());
        if (scope.isForProductionCompile() || scope.isForProductionRuntime()) {
            if (classpath.length() > 0) {
                classpath.append(" ");
            }
            classpath.append(classpathPrefix);
            String artifactFileName = mavenArtifact.getArtifactId() + "-" + mavenArtifact.getVersion() + "." + mavenArtifact.getExtension();
            classpath.append(doGetClasspathItem(mavenProject, mavenArtifact, artifactFileName));
        }
    }
    return classpath.toString();
}
Also used : DependencyScope(com.intellij.openapi.roots.DependencyScope) MavenArtifact(org.jetbrains.idea.maven.model.MavenArtifact) NotNull(org.jetbrains.annotations.NotNull)

Example 17 with MavenArtifact

use of org.jetbrains.idea.maven.model.MavenArtifact in project intellij-community by JetBrains.

the class ArtifactsDownloadingTest method testDownloadingSpecificDependency.

public void testDownloadingSpecificDependency() throws Exception {
    importProject("<groupId>test</groupId>" + "<artifactId>project</artifactId>" + "<version>1</version>" + "<dependencies>" + "  <dependency>" + "    <groupId>jmock</groupId>" + "    <artifactId>jmock</artifactId>" + "    <version>1.2.0</version>" + "  </dependency>" + "  <dependency>" + "    <groupId>junit</groupId>" + "    <artifactId>junit</artifactId>" + "    <version>4.0</version>" + "  </dependency>" + "</dependencies>");
    File sources = new File(getRepositoryPath(), "/jmock/jmock/1.2.0/jmock-1.2.0-sources.jar");
    File javadoc = new File(getRepositoryPath(), "/jmock/jmock/1.2.0/jmock-1.2.0-javadoc.jar");
    assertFalse(sources.exists());
    assertFalse(javadoc.exists());
    MavenProject project = myProjectsTree.getRootProjects().get(0);
    MavenArtifact dep = project.getDependencies().get(0);
    downloadArtifacts(Arrays.asList(project), Arrays.asList(dep));
    assertTrue(sources.exists());
    assertTrue(javadoc.exists());
    assertFalse(new File(getRepositoryPath(), "/junit/junit/4.0/junit-4.0-sources.jar").exists());
    assertFalse(new File(getRepositoryPath(), "/junit/junit/4.0/junit-4.0-javadoc.jar").exists());
}
Also used : MavenProject(org.jetbrains.idea.maven.project.MavenProject) File(java.io.File) MavenArtifact(org.jetbrains.idea.maven.model.MavenArtifact)

Example 18 with MavenArtifact

use of org.jetbrains.idea.maven.model.MavenArtifact in project intellij-community by JetBrains.

the class JUnit4IntegrationTest method before.

@Before
public void before() throws Throwable {
    EdtTestUtil.runInEdtAndWait(() -> {
        setUp();
        Module module = createEmptyModule();
        String communityPath = PlatformTestUtil.getCommunityPath().replace(File.separatorChar, '/');
        String methodName = myNameRule.getMethodName();
        methodName = methodName.substring(0, methodName.indexOf("["));
        String testDataPath = communityPath + File.separator + "plugins" + File.separator + "junit5_rt_tests" + File.separator + "testData" + File.separator + "integration" + File.separator + methodName;
        MavenId mavenId = new MavenId("junit", "junit", myJUnitVersion);
        MavenRepositoryInfo repositoryInfo = new MavenRepositoryInfo("maven", "maven", "http://maven.labs.intellij.net/repo1");
        RepositoryAttachHandler.doResolveInner(getProject(), mavenId, Collections.emptyList(), Collections.singleton(repositoryInfo), artifacts -> {
            for (MavenArtifact artifact : artifacts) {
                ModuleRootModificationUtil.addModuleLibrary(module, VfsUtilCore.pathToUrl(artifact.getPath()));
            }
            return true;
        }, new DumbProgressIndicator());
        ModuleRootModificationUtil.setModuleSdk(module, JavaAwareProjectJdkTableImpl.getInstanceEx().getInternalJdk());
        ModuleRootModificationUtil.updateModel(module, model -> {
            ContentEntry contentEntry = model.addContentEntry(VfsUtilCore.pathToUrl(testDataPath));
            contentEntry.addSourceFolder(VfsUtilCore.pathToUrl(testDataPath + File.separator + "test"), true);
            CompilerModuleExtension moduleExtension = model.getModuleExtension(CompilerModuleExtension.class);
            moduleExtension.inheritCompilerOutputPath(false);
            moduleExtension.setCompilerOutputPathForTests(VfsUtilCore.pathToUrl(testDataPath + File.separator + "out"));
        });
    });
}
Also used : MavenId(org.jetbrains.idea.maven.model.MavenId) ContentEntry(com.intellij.openapi.roots.ContentEntry) MavenRepositoryInfo(org.jetbrains.idea.maven.model.MavenRepositoryInfo) Module(com.intellij.openapi.module.Module) DumbProgressIndicator(com.intellij.openapi.progress.DumbProgressIndicator) MavenArtifact(org.jetbrains.idea.maven.model.MavenArtifact) CompilerModuleExtension(com.intellij.openapi.roots.CompilerModuleExtension) Before(org.junit.Before)

Example 19 with MavenArtifact

use of org.jetbrains.idea.maven.model.MavenArtifact in project intellij-plugins by JetBrains.

the class ImporterUtil method postProcessAdditionalProperties.

/**
   * Postprocessing step which handles Embed-Dependency and replaces placeholders on Import-Resources etc.
   */
static void postProcessAdditionalProperties(@NotNull Map<String, String> props, @NotNull MavenProject mavenProject, @NotNull Project project) {
    Analyzer analyzer = new FakeAnalyzer(props);
    Collection<MavenArtifact> dependencies = collectDependencies(props, mavenProject);
    DependencyEmbedder embedder = new DependencyEmbedder(dependencies);
    try {
        embedder.processHeaders(analyzer);
    } catch (DependencyEmbedderException e) {
        String message = OsmorcBundle.message("maven.import.embed.error", mavenProject.getPath(), e.getMessage());
        OsmorcProjectComponent.IMPORTANT_NOTIFICATIONS.createNotification(message, NotificationType.ERROR).notify(project);
    }
    ResourceCollector.includeMavenResources(mavenProject, analyzer);
    // finally post-process the Include-Resources header to account for backslashes and relative paths
    sanitizeIncludedResources(props, mavenProject);
}
Also used : Analyzer(aQute.bnd.osgi.Analyzer) FakeAnalyzer(org.jetbrains.osgi.jps.build.FakeAnalyzer) FakeAnalyzer(org.jetbrains.osgi.jps.build.FakeAnalyzer) MavenArtifact(org.jetbrains.idea.maven.model.MavenArtifact)

Example 20 with MavenArtifact

use of org.jetbrains.idea.maven.model.MavenArtifact in project intellij-plugins by JetBrains.

the class ImporterUtil method collectDependencies.

/**
   * Collects the dependencies for the given project. Takes into account any transitive embedding instructions.
   *
   * @param props   the properties with additional instructions
   * @param project the maven project
   * @return a collection of dependencies.
   */
@NotNull
static Collection<MavenArtifact> collectDependencies(@NotNull Map<String, String> props, @NotNull MavenProject project) {
    Collection<MavenArtifact> dependencies;
    if (Boolean.parseBoolean(props.get(DependencyEmbedder.EMBED_TRANSITIVE))) {
        Set<MavenArtifact> processed = new HashSet<>();
        // flatten the tree while taking care of endless recursions
        LinkedList<MavenArtifactNode> nodes = new LinkedList<>(project.getDependencyTree());
        while (!nodes.isEmpty()) {
            MavenArtifactNode node = nodes.pop();
            MavenArtifact artifact = node.getArtifact();
            if (!processed.contains(artifact)) {
                processed.add(artifact);
                nodes.addAll(node.getDependencies());
            }
        }
        dependencies = processed;
    } else {
        dependencies = project.getDependencies();
    }
    return dependencies;
}
Also used : MavenArtifactNode(org.jetbrains.idea.maven.model.MavenArtifactNode) MavenArtifact(org.jetbrains.idea.maven.model.MavenArtifact) NotNull(org.jetbrains.annotations.NotNull)

Aggregations

MavenArtifact (org.jetbrains.idea.maven.model.MavenArtifact)21 File (java.io.File)5 NotNull (org.jetbrains.annotations.NotNull)4 MavenId (org.jetbrains.idea.maven.model.MavenId)4 MavenProject (org.jetbrains.idea.maven.project.MavenProject)4 VirtualFile (com.intellij.openapi.vfs.VirtualFile)3 Library (com.intellij.openapi.roots.libraries.Library)2 SmartList (com.intellij.util.SmartList)2 THashSet (gnu.trove.THashSet)2 List (java.util.List)2 Map (java.util.Map)2 Attrs (aQute.bnd.header.Attrs)1 Parameters (aQute.bnd.header.Parameters)1 Analyzer (aQute.bnd.osgi.Analyzer)1 AccessToken (com.intellij.openapi.application.AccessToken)1 Module (com.intellij.openapi.module.Module)1 DumbProgressIndicator (com.intellij.openapi.progress.DumbProgressIndicator)1 Project (com.intellij.openapi.project.Project)1 CompilerModuleExtension (com.intellij.openapi.roots.CompilerModuleExtension)1 ContentEntry (com.intellij.openapi.roots.ContentEntry)1