Search in sources :

Example 36 with MavenProject

use of org.apache.maven.project.MavenProject in project maven-plugins by apache.

the class DefaultDependencyResolver method resolveTransitively.

private Set<Artifact> resolveTransitively(final Set<Artifact> dependencyArtifacts, final List<ArtifactRepository> repos, final ArtifactFilter filter, final AssemblerConfigurationSource configSource) throws DependencyResolutionException {
    final MavenProject project = configSource.getProject();
    ArtifactResolutionRequest req = new ArtifactResolutionRequest();
    req.setLocalRepository(configSource.getLocalRepository());
    req.setResolveRoot(false);
    req.setRemoteRepositories(repos);
    req.setResolveTransitively(true);
    req.setArtifact(project.getArtifact());
    req.setArtifactDependencies(dependencyArtifacts);
    req.setManagedVersionMap(project.getManagedVersionMap());
    req.setCollectionFilter(filter);
    req.setOffline(configSource.getMavenSession().isOffline());
    req.setForceUpdate(configSource.getMavenSession().getRequest().isUpdateSnapshots());
    req.setServers(configSource.getMavenSession().getRequest().getServers());
    req.setMirrors(configSource.getMavenSession().getRequest().getMirrors());
    req.setProxies(configSource.getMavenSession().getRequest().getProxies());
    ArtifactResolutionResult result;
    result = resolver.resolve(req);
    if (result.hasExceptions()) {
        throw new DependencyResolutionException("Failed to resolve dependencies for assembly: ", result.getExceptions().get(0));
    }
    getLogger().debug("While resolving dependencies of " + project.getId() + ":");
    FilterUtils.reportFilteringStatistics(Collections.singleton(filter), getLogger());
    return result.getArtifacts();
}
Also used : MavenProject(org.apache.maven.project.MavenProject) ArtifactResolutionRequest(org.apache.maven.artifact.resolver.ArtifactResolutionRequest) ArtifactResolutionResult(org.apache.maven.artifact.resolver.ArtifactResolutionResult)

Example 37 with MavenProject

use of org.apache.maven.project.MavenProject in project maven-plugins by apache.

the class DefaultDependencyResolver method resolveNonTransitively.

Set<Artifact> resolveNonTransitively(final Assembly assembly, final Set<Artifact> dependencyArtifacts, final AssemblerConfigurationSource configSource, final List<ArtifactRepository> repos) throws DependencyResolutionException {
    final List<Artifact> missing = new ArrayList<Artifact>();
    final Set<Artifact> resolved = new LinkedHashSet<Artifact>();
    for (final Artifact depArtifact : dependencyArtifacts) {
        ArtifactResolutionRequest req = new ArtifactResolutionRequest();
        req.setLocalRepository(configSource.getLocalRepository());
        req.setRemoteRepositories(repos);
        req.setArtifact(depArtifact);
        ArtifactResolutionResult resolve = resolver.resolve(req);
        if (resolve.hasExceptions()) {
            if (getLogger().isDebugEnabled()) {
                getLogger().debug("Failed to resolve: " + depArtifact.getId() + " for assembly: " + assembly.getId());
            }
            missing.add(depArtifact);
        } else {
            resolved.add(depArtifact);
        }
    }
    if (!missing.isEmpty()) {
        final MavenProject project = configSource.getProject();
        final Artifact rootArtifact = project.getArtifact();
        final Throwable error = new MultipleArtifactsNotFoundException(rootArtifact, new ArrayList<Artifact>(resolved), missing, repos);
        throw new DependencyResolutionException("Failed to resolve dependencies for: " + assembly.getId(), error);
    }
    return resolved;
}
Also used : LinkedHashSet(java.util.LinkedHashSet) MavenProject(org.apache.maven.project.MavenProject) ArtifactResolutionRequest(org.apache.maven.artifact.resolver.ArtifactResolutionRequest) ArtifactResolutionResult(org.apache.maven.artifact.resolver.ArtifactResolutionResult) ArrayList(java.util.ArrayList) MultipleArtifactsNotFoundException(org.apache.maven.artifact.resolver.MultipleArtifactsNotFoundException) Artifact(org.apache.maven.artifact.Artifact)

Example 38 with MavenProject

use of org.apache.maven.project.MavenProject in project maven-plugins by apache.

the class DefaultDependencyResolver method updateModuleSetResolutionRequirements.

void updateModuleSetResolutionRequirements(AssemblyId assemblyId, ModuleSet set, DependencySet dependencySet, final ResolutionManagementInfo requirements, final AssemblerConfigurationSource configSource) throws DependencyResolutionException {
    final ModuleBinaries binaries = set.getBinaries();
    if (binaries != null) {
        Set<MavenProject> projects;
        try {
            projects = ModuleSetAssemblyPhase.getModuleProjects(set, configSource, getLogger());
        } catch (final ArchiveCreationException e) {
            throw new DependencyResolutionException("Error determining project-set for moduleSet with binaries.", e);
        }
        if (!projects.isEmpty()) {
            for (final MavenProject p : projects) {
                requirements.enableProjectResolution(p);
                if (p.getArtifact() == null) {
                    // TODO: such a call in MavenMetadataSource too - packaging not really the intention of
                    // type
                    final Artifact artifact = resolver.createArtifact(p.getGroupId(), p.getArtifactId(), p.getVersion(), p.getPackaging());
                    p.setArtifact(artifact);
                }
            }
        }
        if (binaries.isIncludeDependencies()) {
            updateDependencySetResolutionRequirements(dependencySet, requirements, assemblyId, configSource.getMavenSession().getProjectBuildingRequest(), projects.toArray(new MavenProject[projects.size()]));
        }
    }
}
Also used : ModuleBinaries(org.apache.maven.plugins.assembly.model.ModuleBinaries) MavenProject(org.apache.maven.project.MavenProject) ArchiveCreationException(org.apache.maven.plugins.assembly.archive.ArchiveCreationException) Artifact(org.apache.maven.artifact.Artifact)

Example 39 with MavenProject

use of org.apache.maven.project.MavenProject in project maven-plugins by apache.

the class DefaultDependencyResolver method resolveDependencySets.

@Override
public Map<DependencySet, Set<Artifact>> resolveDependencySets(final Assembly assembly, ModuleSet moduleSet, final AssemblerConfigurationSource configSource, List<DependencySet> dependencySets) throws DependencyResolutionException {
    Map<DependencySet, Set<Artifact>> result = new LinkedHashMap<DependencySet, Set<Artifact>>();
    for (DependencySet dependencySet : dependencySets) {
        final MavenProject currentProject = configSource.getProject();
        final ResolutionManagementInfo info = new ResolutionManagementInfo(currentProject);
        updateRepositoryResolutionRequirements(assembly, info);
        final AssemblyId assemblyId = AssemblyId.createAssemblyId(assembly);
        updateDependencySetResolutionRequirements(dependencySet, info, assemblyId, configSource.getMavenSession().getProjectBuildingRequest(), currentProject);
        updateModuleSetResolutionRequirements(assemblyId, moduleSet, dependencySet, info, configSource);
        resolve(assembly, configSource, result, dependencySet, info);
    }
    return result;
}
Also used : ModuleSet(org.apache.maven.plugins.assembly.model.ModuleSet) HashSet(java.util.HashSet) LinkedHashSet(java.util.LinkedHashSet) Set(java.util.Set) DependencySet(org.apache.maven.plugins.assembly.model.DependencySet) MavenProject(org.apache.maven.project.MavenProject) DependencySet(org.apache.maven.plugins.assembly.model.DependencySet) AssemblyId(org.apache.maven.plugins.assembly.resolved.AssemblyId) Artifact(org.apache.maven.artifact.Artifact) LinkedHashMap(java.util.LinkedHashMap)

Example 40 with MavenProject

use of org.apache.maven.project.MavenProject in project maven-plugins by apache.

the class AntBuildWriterUtilTest method testGetMavenJavadocPluginConfiguration.

/**
     * Test method for 'org.apache.maven.plugin.ant.AntBuildWriterUtil.getMavenJavadocPluginConfiguration(MavenProject, String, String)'
     *
     * @throws Exception
     */
public void testGetMavenJavadocPluginConfiguration() throws Exception {
    File testPom = new File(getBasedir(), "src/test/resources/unit/ant-javadoc-test/pom.xml");
    MavenEmbedder maven = new MavenEmbedder();
    maven.setClassLoader(Thread.currentThread().getContextClassLoader());
    maven.setLogger(new MavenEmbedderConsoleLogger());
    maven.setLocalRepositoryDirectory(getTestFile("target/local-repo"));
    maven.setOffline(true);
    maven.start();
    MavenProject project = maven.readProject(testPom);
    assertEquals(AntBuildWriterUtil.getMavenJavadocPluginBasicOption(project, "doclet", null), "gr.spinellis.umlgraph.doclet.UmlGraphDoc");
    assertNotNull(AntBuildWriterUtil.getMavenJavadocPluginOptions(project, "links", null));
    assertEquals(AntBuildWriterUtil.getMavenJavadocPluginOptions(project, "links", null).length, 2);
    assertNotNull(AntBuildWriterUtil.getMavenJavadocPluginOptions(project, "docletArtifacts", null));
    assertEquals(AntBuildWriterUtil.getMavenJavadocPluginOptions(project, "docletArtifacts", null).length, 2);
    Map[] options = AntBuildWriterUtil.getMavenJavadocPluginOptions(project, "tags", null);
    assertNotNull(options);
    assertEquals(options.length, 1);
    assertEquals(1, options[0].size());
    Map properties = (Map) options[0].get("tag");
    assertNotNull(properties);
    assertEquals("requirement", properties.get("name"));
    assertEquals("a", properties.get("placement"));
    assertEquals("Software Requirement:", properties.get("head"));
    maven.stop();
}
Also used : MavenEmbedderConsoleLogger(org.apache.maven.embedder.MavenEmbedderConsoleLogger) MavenProject(org.apache.maven.project.MavenProject) MavenEmbedder(org.apache.maven.embedder.MavenEmbedder) File(java.io.File) Map(java.util.Map)

Aggregations

MavenProject (org.apache.maven.project.MavenProject)297 File (java.io.File)138 Artifact (org.apache.maven.artifact.Artifact)66 ArrayList (java.util.ArrayList)64 Model (org.apache.maven.model.Model)57 ConsoleLogger (org.codehaus.plexus.logging.console.ConsoleLogger)36 MojoExecutionException (org.apache.maven.plugin.MojoExecutionException)33 IOException (java.io.IOException)29 Assembly (org.apache.maven.plugins.assembly.model.Assembly)28 EasyMockSupport (org.easymock.classextension.EasyMockSupport)27 ArtifactMock (org.apache.maven.plugins.assembly.archive.task.testutils.ArtifactMock)20 Test (org.junit.Test)17 HashMap (java.util.HashMap)16 HashSet (java.util.HashSet)16 MavenSession (org.apache.maven.execution.MavenSession)16 DependencySet (org.apache.maven.plugins.assembly.model.DependencySet)16 ProjectBuildingException (org.apache.maven.project.ProjectBuildingException)16 LinkedHashSet (java.util.LinkedHashSet)15 ArtifactRepository (org.apache.maven.artifact.repository.ArtifactRepository)15 FileSet (org.apache.maven.plugins.assembly.model.FileSet)15