Search in sources :

Example 1 with ProjectBuildingException

use of org.apache.maven.project.ProjectBuildingException in project che by eclipse.

the class MavenServerImpl method validate.

private void validate(File pom, List<Exception> exceptions, List<MavenProjectProblem> problems) throws RemoteException {
    for (Throwable exception : exceptions) {
        if (exception instanceof IllegalStateException && exception.getCause() != null) {
            exception = exception.getCause();
        }
        if (exception instanceof InvalidProjectModelException) {
            ModelValidationResult validationResult = ((InvalidProjectModelException) exception).getValidationResult();
            if (validationResult != null) {
                problems.addAll(validationResult.getMessages().stream().map(s -> MavenProjectProblem.newStructureProblem(pom.getPath(), s)).collect(Collectors.toList()));
            } else {
                problems.add(MavenProjectProblem.newStructureProblem(pom.getPath(), exception.getCause().getMessage()));
            }
        }
        if (exception instanceof ProjectBuildingException) {
            String message = exception.getCause() == null ? exception.getMessage() : exception.getCause().getMessage();
            problems.add(MavenProjectProblem.newStructureProblem(pom.getPath(), message));
        } else {
            MavenServerContext.getLogger().info(exception);
            problems.add(MavenProjectProblem.newStructureProblem(pom.getPath(), exception.getMessage()));
        }
    }
}
Also used : InvalidProjectModelException(org.apache.maven.project.InvalidProjectModelException) ModelValidationResult(org.apache.maven.project.validation.ModelValidationResult) ProjectBuildingException(org.apache.maven.project.ProjectBuildingException)

Example 2 with ProjectBuildingException

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

the class GenerateFileMojo method execute.

@java.lang.Override
public void execute() throws MojoExecutionException, MojoFailureException {
    try {
        init();
        readExtraMaps();
        addDependenciesToLicenseMap();
        resolveLicenseContent();
        resolveNoticeFiles();
        resolveLicenseFiles();
        rebuildLicenseContentProjectMap();
        combineCommonGavs();
        SourcePointerResolver.execute(this);
        persistLicenseMap();
        buildNoticeProjectMap();
        generateFiles();
    } catch (IOException | TemplateException | ProjectBuildingException e) {
        throw new MojoExecutionException("Unexpected exception: " + e, e);
    }
}
Also used : ProjectBuildingException(org.apache.maven.project.ProjectBuildingException) MojoExecutionException(org.apache.maven.plugin.MojoExecutionException) TemplateException(freemarker.template.TemplateException) IOException(java.io.IOException)

Example 3 with ProjectBuildingException

use of org.apache.maven.project.ProjectBuildingException 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 4 with ProjectBuildingException

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

the class DownloadLicensesMojo method execute.

@java.lang.Override
public void execute() throws MojoExecutionException, MojoFailureException {
    try {
        init();
        addDependenciesToLicenseMap();
        final int timeoutMillis = (int) TimeUnit.SECONDS.toMillis(timeoutSecs);
        //noinspection ResultOfMethodCallIgnored
        downloadDir.mkdirs();
        AtomicInteger counter = new AtomicInteger();
        getLicenseMap().values().parallelStream().forEach(entry -> {
            final int i = counter.incrementAndGet();
            final String url = entry.getLicense().getUrl();
            String fileName = entry.getLicense().getContentFile(false);
            doDownload(timeoutMillis, i, url, fileName);
        });
    } catch (IOException | ProjectBuildingException e) {
        throw new MojoExecutionException("Unexpected exception: " + e, e);
    }
}
Also used : ProjectBuildingException(org.apache.maven.project.ProjectBuildingException) MojoExecutionException(org.apache.maven.plugin.MojoExecutionException) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) IOException(java.io.IOException)

Example 5 with ProjectBuildingException

use of org.apache.maven.project.ProjectBuildingException in project karaf by apache.

the class MojoSupport method createManagedVersionMap.

protected Map createManagedVersionMap(String projectId, DependencyManagement dependencyManagement) throws ProjectBuildingException {
    Map map;
    if (dependencyManagement != null && dependencyManagement.getDependencies() != null) {
        map = new HashMap();
        for (Dependency d : dependencyManagement.getDependencies()) {
            try {
                VersionRange versionRange = VersionRange.createFromVersionSpec(d.getVersion());
                Artifact artifact = factory.createDependencyArtifact(d.getGroupId(), d.getArtifactId(), versionRange, d.getType(), d.getClassifier(), d.getScope());
                map.put(d.getManagementKey(), artifact);
            } catch (InvalidVersionSpecificationException e) {
                throw new ProjectBuildingException(projectId, "Unable to parse version '" + d.getVersion() + "' for dependency '" + d.getManagementKey() + "': " + e.getMessage(), e);
            }
        }
    } else {
        map = Collections.EMPTY_MAP;
    }
    return map;
}
Also used : ProjectBuildingException(org.apache.maven.project.ProjectBuildingException) InvalidVersionSpecificationException(org.apache.maven.artifact.versioning.InvalidVersionSpecificationException) HashMap(java.util.HashMap) VersionRange(org.apache.maven.artifact.versioning.VersionRange) Dependency(org.apache.maven.model.Dependency) HashMap(java.util.HashMap) Map(java.util.Map) 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