Search in sources :

Example 16 with MavenProject

use of org.apache.maven.project.MavenProject in project asterixdb by apache.

the class LicenseMojo method resolveDependency.

protected MavenProject resolveDependency(Artifact depObj) throws ProjectBuildingException {
    String key = depObj.getGroupId() + ":" + depObj.getArtifactId() + ":" + depObj.getVersion();
    MavenProject depProj = projectCache.get(key);
    if (depProj == null) {
        try {
            depProj = projectBuilder.buildFromRepository(depObj, remoteRepositories, localRepository, false);
        } catch (ProjectBuildingException e) {
            throw new ProjectBuildingException(key, "Error creating dependent artifacts", e);
        }
        Model supplement = supplementModels.get(SupplementalModelHelper.generateSupplementMapKey(depObj.getGroupId(), depObj.getArtifactId()));
        if (supplement != null) {
            Model merged = SupplementalModelHelper.mergeModels(assembler, depProj.getModel(), supplement);
            Set<String> origLicenses = depProj.getModel().getLicenses().stream().map(License::getUrl).collect(Collectors.toSet());
            Set<String> newLicenses = merged.getLicenses().stream().map(License::getUrl).collect(Collectors.toSet());
            if (!origLicenses.equals(newLicenses)) {
                getLog().warn("license list for " + toGav(depProj) + " changed with supplemental model; was: " + origLicenses + ", now: " + newLicenses);
            }
            depProj = new MavenProject(merged);
            depProj.setArtifact(depObj);
            depProj.setVersion(depObj.getVersion());
        }
        depProj.getArtifact().setScope(depObj.getScope());
        projectCache.put(key, depProj);
    }
    return depProj;
}
Also used : ProjectBuildingException(org.apache.maven.project.ProjectBuildingException) MavenProject(org.apache.maven.project.MavenProject) Model(org.apache.maven.model.Model)

Example 17 with MavenProject

use of org.apache.maven.project.MavenProject in project asterixdb by apache.

the class LicenseMojo method gatherProjectDependencies.

private void gatherProjectDependencies(MavenProject project, Map<MavenProject, List<Pair<String, String>>> dependencyLicenseMap, Map<String, MavenProject> dependencyGavMap) throws ProjectBuildingException {
    final Set dependencyArtifacts = project.getArtifacts();
    if (dependencyArtifacts != null) {
        for (Object depArtifactObj : dependencyArtifacts) {
            final Artifact depArtifact = (Artifact) depArtifactObj;
            if (!excludedScopes.contains(depArtifact.getScope())) {
                MavenProject dep = resolveDependency(depArtifact);
                dep.setArtifact(depArtifact);
                dependencyGavMap.put(toGav(dep), dep);
                List<Pair<String, String>> licenseUrls = new ArrayList<>();
                for (Object license : dep.getLicenses()) {
                    final License license1 = (License) license;
                    String url = license1.getUrl() != null ? license1.getUrl() : (license1.getName() != null ? license1.getName() : "LICENSE_EMPTY_NAME_URL");
                    licenseUrls.add(new ImmutablePair<>(url, license1.getName()));
                }
                dependencyLicenseMap.put(dep, licenseUrls);
            }
        }
    }
}
Also used : TreeSet(java.util.TreeSet) HashSet(java.util.HashSet) Set(java.util.Set) MavenProject(org.apache.maven.project.MavenProject) ArrayList(java.util.ArrayList) License(org.apache.maven.model.License) Artifact(org.apache.maven.artifact.Artifact) Pair(org.apache.commons.lang3.tuple.Pair) ImmutablePair(org.apache.commons.lang3.tuple.ImmutablePair)

Example 18 with MavenProject

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

the class DefaultAssemblyReader method readAssembly.

public Assembly readAssembly(Reader reader, final String locationDescription, final File assemblyDir, final AssemblerConfigurationSource configSource) throws AssemblyReadException, InvalidAssemblerConfigurationException {
    Assembly assembly;
    final MavenProject project = configSource.getProject();
    try {
        InterpolationState is = new InterpolationState();
        final RecursionInterceptor interceptor = new PrefixAwareRecursionInterceptor(InterpolationConstants.PROJECT_PREFIXES, true);
        is.setRecursionInterceptor(interceptor);
        FixedStringSearchInterpolator interpolator = AssemblyInterpolator.fullInterpolator(project, createProjectInterpolator(project), configSource);
        AssemblyXpp3Reader.ContentTransformer transformer = AssemblyInterpolator.assemblyInterpolator(interpolator, is, getLogger());
        final AssemblyXpp3Reader r = new AssemblyXpp3Reader(transformer);
        assembly = r.read(reader);
        ComponentXpp3Reader.ContentTransformer ctrans = AssemblyInterpolator.componentInterpolator(interpolator, is, getLogger());
        mergeComponentsWithMainAssembly(assembly, assemblyDir, configSource, ctrans);
        debugPrintAssembly("After assembly is interpolated:", assembly);
        AssemblyInterpolator.checkErrors(AssemblyId.createAssemblyId(assembly), is, getLogger());
        reader.close();
        reader = null;
    } catch (final IOException e) {
        throw new AssemblyReadException("Error reading descriptor: " + locationDescription + ": " + e.getMessage(), e);
    } catch (final XmlPullParserException e) {
        throw new AssemblyReadException("Error reading descriptor: " + locationDescription + ": " + e.getMessage(), e);
    } finally {
        IOUtil.close(reader);
    }
    if (assembly.isIncludeSiteDirectory()) {
        includeSiteInAssembly(assembly, configSource);
    }
    return assembly;
}
Also used : FixedStringSearchInterpolator(org.codehaus.plexus.interpolation.fixed.FixedStringSearchInterpolator) AssemblyXpp3Reader(org.apache.maven.plugins.assembly.model.io.xpp3.AssemblyXpp3Reader) IOException(java.io.IOException) MavenProject(org.apache.maven.project.MavenProject) ComponentXpp3Reader(org.apache.maven.plugins.assembly.model.io.xpp3.ComponentXpp3Reader) PrefixAwareRecursionInterceptor(org.codehaus.plexus.interpolation.PrefixAwareRecursionInterceptor) RecursionInterceptor(org.codehaus.plexus.interpolation.RecursionInterceptor) InterpolationState(org.codehaus.plexus.interpolation.fixed.InterpolationState) XmlPullParserException(org.codehaus.plexus.util.xml.pull.XmlPullParserException) PrefixAwareRecursionInterceptor(org.codehaus.plexus.interpolation.PrefixAwareRecursionInterceptor) Assembly(org.apache.maven.plugins.assembly.model.Assembly)

Example 19 with MavenProject

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

the class DependencySetAssemblyPhaseTest method testExecute_ShouldAddOneDependencyFromProject.

public void testExecute_ShouldAddOneDependencyFromProject() throws AssemblyFormattingException, ArchiveCreationException, IOException, InvalidAssemblerConfigurationException, DependencyResolutionException {
    final String outputLocation = "/out";
    final MavenProject project = newMavenProject("group", "project", "0");
    final ArtifactMock projectArtifactMock = new ArtifactMock(mm, "group", "project", "0", "jar", false);
    project.setArtifact(projectArtifactMock.getArtifact());
    final DependencySet ds = new DependencySet();
    ds.setUseProjectArtifact(false);
    ds.setOutputDirectory(outputLocation);
    ds.setOutputFileNameMapping("${artifact.artifactId}");
    ds.setUnpack(false);
    ds.setScope(Artifact.SCOPE_COMPILE);
    ds.setFileMode(Integer.toString(10, 8));
    final Assembly assembly = new Assembly();
    assembly.setId("test");
    assembly.setIncludeBaseDirectory(false);
    assembly.addDependencySet(ds);
    final MockAndControlForAddDependencySetsTask macTask = new MockAndControlForAddDependencySetsTask(mm, project);
    final ArtifactMock artifactMock = new ArtifactMock(mm, "group", "dep", "1", "jar", false);
    System.out.println("On test setup, hashcode for dependency artifact: " + artifactMock.getArtifact().hashCode());
    macTask.expectCSGetRepositories(null, null);
    macTask.expectGetDestFile(new File("junk"));
    //        macTask.expectAddFile( artifactFile, "out/dep", 10 );
    project.setArtifacts(Collections.singleton(artifactMock.getArtifact()));
    macTask.expectCSGetFinalName("final-name");
    final Logger logger = new ConsoleLogger(Logger.LEVEL_DEBUG, "test");
    final MavenProject depProject = newMavenProject("group", "dep", "1");
    macTask.expectBuildFromRepository(depProject);
    macTask.expectResolveDependencySets();
    mm.replayAll();
    createPhase(macTask, logger, macTask.dependencyResolver).execute(assembly, macTask.archiver, macTask.configSource);
    mm.verifyAll();
}
Also used : MockAndControlForAddDependencySetsTask(org.apache.maven.plugins.assembly.archive.task.testutils.MockAndControlForAddDependencySetsTask) MavenProject(org.apache.maven.project.MavenProject) ConsoleLogger(org.codehaus.plexus.logging.console.ConsoleLogger) DependencySet(org.apache.maven.plugins.assembly.model.DependencySet) ArtifactMock(org.apache.maven.plugins.assembly.archive.task.testutils.ArtifactMock) ConsoleLogger(org.codehaus.plexus.logging.console.ConsoleLogger) Logger(org.codehaus.plexus.logging.Logger) File(java.io.File) Assembly(org.apache.maven.plugins.assembly.model.Assembly)

Example 20 with MavenProject

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

the class DependencySetAssemblyPhaseTest method newMavenProject.

private MavenProject newMavenProject(final String groupId, final String artifactId, final String version) {
    final Model model = new Model();
    model.setGroupId(groupId);
    model.setArtifactId(artifactId);
    model.setVersion(version);
    return new MavenProject(model);
}
Also used : MavenProject(org.apache.maven.project.MavenProject) Model(org.apache.maven.model.Model)

Aggregations

MavenProject (org.apache.maven.project.MavenProject)291 File (java.io.File)134 ArrayList (java.util.ArrayList)63 Artifact (org.apache.maven.artifact.Artifact)63 Model (org.apache.maven.model.Model)57 ConsoleLogger (org.codehaus.plexus.logging.console.ConsoleLogger)36 MojoExecutionException (org.apache.maven.plugin.MojoExecutionException)32 Assembly (org.apache.maven.plugins.assembly.model.Assembly)28 IOException (java.io.IOException)27 EasyMockSupport (org.easymock.classextension.EasyMockSupport)27 ArtifactMock (org.apache.maven.plugins.assembly.archive.task.testutils.ArtifactMock)20 HashSet (java.util.HashSet)16 DependencySet (org.apache.maven.plugins.assembly.model.DependencySet)16 ProjectBuildingException (org.apache.maven.project.ProjectBuildingException)16 HashMap (java.util.HashMap)15 LinkedHashSet (java.util.LinkedHashSet)15 ArtifactRepository (org.apache.maven.artifact.repository.ArtifactRepository)15 MavenSession (org.apache.maven.execution.MavenSession)15 FileSet (org.apache.maven.plugins.assembly.model.FileSet)15 Logger (org.codehaus.plexus.logging.Logger)15