Search in sources :

Example 16 with ProjectBuildingException

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

the class AddDependencySetsTaskTest method testAddDependencySet_ShouldNotAddDependenciesWhenProjectIsStubbed.

// TODO: Find a better way of testing the project-stubbing behavior when a ProjectBuildingException takes place.
public void testAddDependencySet_ShouldNotAddDependenciesWhenProjectIsStubbed() throws AssemblyFormattingException, ArchiveCreationException, InvalidAssemblerConfigurationException, IOException {
    final MavenProject project = new MavenProject(new Model());
    final ProjectBuildingException pbe = new ProjectBuildingException("test", "Test error.", new Throwable());
    final MockAndControlForAddDependencySetsTask macTask = new MockAndControlForAddDependencySetsTask(mockManager, new MavenProject(new Model()));
    final String gid = "org.test";
    final String aid = "test-dep";
    final String version = "2.0-SNAPSHOT";
    final String type = "jar";
    final File file = new File("dep-artifact.jar");
    final ArtifactMock depMock = new ArtifactMock(mockManager, gid, aid, version, type, true);
    depMock.setBaseVersion(version);
    depMock.setFile(file);
    final File destFile = new File("assembly-dep-set.zip");
    macTask.expectGetDestFile(destFile);
    macTask.expectBuildFromRepository(pbe);
    macTask.expectCSGetRepositories(null, null);
    macTask.expectCSGetFinalName("final-name");
    macTask.expectAddFile(file, "out/" + aid + "-" + version + "." + type);
    macTask.expectGetMode(0222, 0222);
    final DependencySet ds = new DependencySet();
    ds.setOutputDirectory("/out");
    DefaultAssemblyArchiverTest.setupInterpolators(macTask.configSource);
    mockManager.replayAll();
    final Logger logger = new ConsoleLogger(Logger.LEVEL_DEBUG, "test");
    final AddDependencySetsTask task = new AddDependencySetsTask(Collections.singletonList(ds), Collections.singleton(depMock.getArtifact()), project, macTask.projectBuilder, logger);
    task.addDependencySet(ds, macTask.archiver, macTask.configSource);
    mockManager.verifyAll();
}
Also used : MockAndControlForAddDependencySetsTask(org.apache.maven.plugins.assembly.archive.task.testutils.MockAndControlForAddDependencySetsTask) ProjectBuildingException(org.apache.maven.project.ProjectBuildingException) MavenProject(org.apache.maven.project.MavenProject) ConsoleLogger(org.codehaus.plexus.logging.console.ConsoleLogger) Model(org.apache.maven.model.Model) 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) MockAndControlForAddDependencySetsTask(org.apache.maven.plugins.assembly.archive.task.testutils.MockAndControlForAddDependencySetsTask)

Example 17 with ProjectBuildingException

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

the class DependencyManagementRenderer method getDependencyRow.

@SuppressWarnings("unchecked")
private String[] getDependencyRow(Dependency dependency, boolean hasClassifier) {
    Artifact artifact = artifactFactory.createProjectArtifact(dependency.getGroupId(), dependency.getArtifactId(), dependency.getVersion());
    StringBuilder licensesBuffer = new StringBuilder();
    String url = null;
    try {
        VersionRange range = VersionRange.createFromVersionSpec(dependency.getVersion());
        if (range.getRecommendedVersion() == null) {
            // MPIR-216: no direct version but version range: need to choose one precise version
            log.debug("Resolving range for DependencyManagement on " + artifact.getId());
            List<ArtifactVersion> versions = artifactMetadataSource.retrieveAvailableVersions(artifact, localRepository, remoteRepositories);
            // only use versions from range
            for (Iterator<ArtifactVersion> iter = versions.iterator(); iter.hasNext(); ) {
                if (!range.containsVersion(iter.next())) {
                    iter.remove();
                }
            }
            // select latest, assuming pom information will be the most accurate
            if (versions.size() > 0) {
                ArtifactVersion maxArtifactVersion = Collections.max(versions);
                artifact.setVersion(maxArtifactVersion.toString());
                log.debug("DependencyManagement resolved: " + artifact.getId());
            }
        }
        url = ProjectInfoReportUtils.getArtifactUrl(artifactFactory, artifact, mavenProjectBuilder, remoteRepositories, localRepository);
        MavenProject artifactProject = repoUtils.getMavenProjectFromRepository(artifact);
        List<License> licenses = artifactProject.getLicenses();
        for (License license : licenses) {
            String licenseCell = ProjectInfoReportUtils.getArtifactIdCell(license.getName(), license.getUrl());
            if (licensesBuffer.length() > 0) {
                licensesBuffer.append(", ");
            }
            licensesBuffer.append(licenseCell);
        }
    } catch (InvalidVersionSpecificationException e) {
        log.warn("Unable to parse version for " + artifact.getId(), e);
    } catch (ArtifactMetadataRetrievalException e) {
        log.warn("Unable to retrieve versions for " + artifact.getId() + " from repository.", e);
    } catch (ProjectBuildingException e) {
        log.warn("Unable to create Maven project for " + artifact.getId() + " from repository.", e);
    }
    String artifactIdCell = ProjectInfoReportUtils.getArtifactIdCell(artifact.getArtifactId(), url);
    if (hasClassifier) {
        return new String[] { dependency.getGroupId(), artifactIdCell, dependency.getVersion(), dependency.getClassifier(), dependency.getType(), licensesBuffer.toString() };
    }
    return new String[] { dependency.getGroupId(), artifactIdCell, dependency.getVersion(), dependency.getType(), licensesBuffer.toString() };
}
Also used : ArtifactMetadataRetrievalException(org.apache.maven.artifact.metadata.ArtifactMetadataRetrievalException) ProjectBuildingException(org.apache.maven.project.ProjectBuildingException) License(org.apache.maven.model.License) VersionRange(org.apache.maven.artifact.versioning.VersionRange) Artifact(org.apache.maven.artifact.Artifact) ArtifactVersion(org.apache.maven.artifact.versioning.ArtifactVersion) InvalidVersionSpecificationException(org.apache.maven.artifact.versioning.InvalidVersionSpecificationException) MavenProject(org.apache.maven.project.MavenProject)

Example 18 with ProjectBuildingException

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

the class AddDependencySetsTask method addDependencySet.

void addDependencySet(final DependencySet dependencySet, final Archiver archiver, final AssemblerConfigurationSource configSource) throws AssemblyFormattingException, ArchiveCreationException, InvalidAssemblerConfigurationException {
    logger.debug("Processing DependencySet (output=" + dependencySet.getOutputDirectory() + ")");
    if (!dependencySet.isUseTransitiveDependencies() && dependencySet.isUseTransitiveFiltering()) {
        logger.warn("DependencySet has nonsensical configuration: useTransitiveDependencies == false " + "AND useTransitiveFiltering == true. Transitive filtering flag will be ignored.");
    }
    final Set<Artifact> dependencyArtifacts = resolveDependencyArtifacts(dependencySet);
    if (!unpackTransformsContent(dependencySet) && dependencyArtifacts.size() > 1) {
        checkMultiArtifactOutputConfig(dependencySet);
    }
    logger.debug("Adding " + dependencyArtifacts.size() + " dependency artifacts.");
    InputStreamTransformer fileSetTransformers = isUnpackWithOptions(dependencySet) ? ReaderFormatter.getFileSetTransformers(configSource, dependencySet.getUnpackOptions().isFiltered(), dependencySet.getUnpackOptions().getLineEnding()) : null;
    for (final Artifact depArtifact : dependencyArtifacts) {
        ProjectBuildingRequest pbr = getProjectBuildingRequest(configSource);
        MavenProject depProject;
        try {
            ProjectBuildingResult build = projectBuilder1.build(depArtifact, pbr);
            depProject = build.getProject();
        } catch (final ProjectBuildingException e) {
            logger.debug("Error retrieving POM of module-dependency: " + depArtifact.getId() + "; Reason: " + e.getMessage() + "\n\nBuilding stub project instance.");
            depProject = buildProjectStub(depArtifact);
        }
        if (NON_ARCHIVE_DEPENDENCY_TYPES.contains(depArtifact.getType())) {
            addNonArchiveDependency(depArtifact, depProject, dependencySet, archiver, configSource);
        } else {
            addNormalArtifact(dependencySet, depArtifact, depProject, archiver, configSource, fileSetTransformers);
        }
    }
}
Also used : ProjectBuildingRequest(org.apache.maven.project.ProjectBuildingRequest) ProjectBuildingException(org.apache.maven.project.ProjectBuildingException) MavenProject(org.apache.maven.project.MavenProject) ProjectBuildingResult(org.apache.maven.project.ProjectBuildingResult) InputStreamTransformer(org.codehaus.plexus.components.io.functions.InputStreamTransformer) Artifact(org.apache.maven.artifact.Artifact)

Aggregations

ProjectBuildingException (org.apache.maven.project.ProjectBuildingException)18 MavenProject (org.apache.maven.project.MavenProject)12 Artifact (org.apache.maven.artifact.Artifact)9 MojoExecutionException (org.apache.maven.plugin.MojoExecutionException)7 IOException (java.io.IOException)3 ArrayList (java.util.ArrayList)3 VersionRange (org.apache.maven.artifact.versioning.VersionRange)3 License (org.apache.maven.model.License)3 Model (org.apache.maven.model.Model)3 DefaultProjectBuildingRequest (org.apache.maven.project.DefaultProjectBuildingRequest)3 ProjectBuildingRequest (org.apache.maven.project.ProjectBuildingRequest)3 File (java.io.File)2 HashMap (java.util.HashMap)2 ArtifactRepository (org.apache.maven.artifact.repository.ArtifactRepository)2 InvalidVersionSpecificationException (org.apache.maven.artifact.versioning.InvalidVersionSpecificationException)2 ModelBuildingException (org.apache.maven.model.building.ModelBuildingException)2 ModelSource (org.apache.maven.model.building.ModelSource)2 StringModelSource (org.apache.maven.model.building.StringModelSource)2 MojoFailureException (org.apache.maven.plugin.MojoFailureException)2 InvalidProjectModelException (org.apache.maven.project.InvalidProjectModelException)2