Search in sources :

Example 1 with ModelBuildingException

use of org.apache.maven.model.building.ModelBuildingException in project buck by facebook.

the class Resolver method loadPomModel.

private Model loadPomModel(Path pomFile) {
    DefaultModelBuildingRequest request = new DefaultModelBuildingRequest();
    request.setPomFile(pomFile.toFile());
    try {
        ModelBuildingResult result = modelBuilder.build(request);
        return result.getRawModel();
    } catch (ModelBuildingException | IllegalArgumentException e) {
        // IllegalArg can be thrown if the parent POM cannot be resolved.
        throw new RuntimeException(e);
    }
}
Also used : ModelBuildingResult(org.apache.maven.model.building.ModelBuildingResult) DefaultModelBuildingRequest(org.apache.maven.model.building.DefaultModelBuildingRequest) ModelBuildingException(org.apache.maven.model.building.ModelBuildingException)

Example 2 with ModelBuildingException

use of org.apache.maven.model.building.ModelBuildingException in project bazel by bazelbuild.

the class DefaultModelResolver method getEffectiveModel.

public Model getEffectiveModel(ModelSource modelSource, EventHandler handler) {
    DefaultModelBuildingRequest request = new DefaultModelBuildingRequest();
    request.setModelResolver(this);
    request.setModelSource(modelSource);
    Model model;
    try {
        ModelBuildingResult result = modelBuilder.build(request);
        model = result.getEffectiveModel();
    } catch (ModelBuildingException | IllegalArgumentException e) {
        // IllegalArg can be thrown if the parent POM cannot be resolved.
        handler.handle(Event.error("Unable to resolve Maven model from " + modelSource.getLocation() + ": " + e.getMessage()));
        return null;
    }
    return model;
}
Also used : ModelBuildingResult(org.apache.maven.model.building.ModelBuildingResult) DefaultModelBuildingRequest(org.apache.maven.model.building.DefaultModelBuildingRequest) Model(org.apache.maven.model.Model) ModelBuildingException(org.apache.maven.model.building.ModelBuildingException)

Example 3 with ModelBuildingException

use of org.apache.maven.model.building.ModelBuildingException in project maven-plugins by apache.

the class InstallFileMojo method createMavenProject.

/**
     * Creates a Maven project in-memory from the user-supplied groupId, artifactId and version. When a classifier is
     * supplied, the packaging must be POM because the project with only have attachments. This project serves as basis
     * to attach the artifacts to install to.
     * 
     * @return The created Maven project, never <code>null</code>.
     * @throws MojoExecutionException When the model of the project could not be built.
     * @throws MojoFailureException When building the project failed.
     */
private MavenProject createMavenProject() throws MojoExecutionException, MojoFailureException {
    if (groupId == null || artifactId == null || version == null || packaging == null) {
        throw new MojoExecutionException("The artifact information is incomplete: 'groupId', 'artifactId', " + "'version' and 'packaging' are required.");
    }
    ModelSource modelSource = new StringModelSource("<project><modelVersion>4.0.0</modelVersion><groupId>" + groupId + "</groupId><artifactId>" + artifactId + "</artifactId><version>" + version + "</version><packaging>" + (classifier == null ? packaging : "pom") + "</packaging></project>");
    ProjectBuildingRequest pbr = new DefaultProjectBuildingRequest(session.getProjectBuildingRequest());
    pbr.setProcessPlugins(false);
    try {
        return projectBuilder.build(modelSource, pbr).getProject();
    } catch (ProjectBuildingException e) {
        if (e.getCause() instanceof ModelBuildingException) {
            throw new MojoExecutionException("The artifact information is not valid:" + Os.LINE_SEP + e.getCause().getMessage());
        }
        throw new MojoFailureException("Unable to create the project.", e);
    }
}
Also used : ProjectBuildingRequest(org.apache.maven.project.ProjectBuildingRequest) DefaultProjectBuildingRequest(org.apache.maven.project.DefaultProjectBuildingRequest) ProjectBuildingException(org.apache.maven.project.ProjectBuildingException) MojoExecutionException(org.apache.maven.plugin.MojoExecutionException) MojoFailureException(org.apache.maven.plugin.MojoFailureException) ModelBuildingException(org.apache.maven.model.building.ModelBuildingException) StringModelSource(org.apache.maven.model.building.StringModelSource) StringModelSource(org.apache.maven.model.building.StringModelSource) ModelSource(org.apache.maven.model.building.ModelSource) DefaultProjectBuildingRequest(org.apache.maven.project.DefaultProjectBuildingRequest)

Example 4 with ModelBuildingException

use of org.apache.maven.model.building.ModelBuildingException in project bazel by bazelbuild.

the class DefaultModelResolver method getRawModel.

public Model getRawModel(FileModelSource fileModelSource, EventHandler handler) {
    DefaultModelBuildingRequest request = new DefaultModelBuildingRequest();
    request.setModelResolver(this);
    request.setModelSource(fileModelSource);
    Model model;
    try {
        ModelBuildingResult result = modelBuilder.build(request);
        model = result.getRawModel();
    } catch (ModelBuildingException | IllegalArgumentException e) {
        // IllegalArg can be thrown if the parent POM cannot be resolved.
        handler.handle(Event.error("Unable to resolve raw Maven model from " + fileModelSource.getLocation() + ": " + e.getMessage()));
        return null;
    }
    return model;
}
Also used : ModelBuildingResult(org.apache.maven.model.building.ModelBuildingResult) DefaultModelBuildingRequest(org.apache.maven.model.building.DefaultModelBuildingRequest) Model(org.apache.maven.model.Model) ModelBuildingException(org.apache.maven.model.building.ModelBuildingException)

Example 5 with ModelBuildingException

use of org.apache.maven.model.building.ModelBuildingException in project buck by facebook.

the class Pom method constructModel.

private Model constructModel(File file, Model model) {
    ModelBuilder modelBuilder = MODEL_BUILDER_FACTORY.newInstance();
    try {
        ModelBuildingRequest req = new DefaultModelBuildingRequest().setPomFile(file);
        ModelBuildingResult modelBuildingResult = modelBuilder.build(req);
        Model constructed = Preconditions.checkNotNull(modelBuildingResult.getRawModel());
        return merge(model, constructed);
    } catch (ModelBuildingException e) {
        throw new RuntimeException(e);
    }
}
Also used : ModelBuilder(org.apache.maven.model.building.ModelBuilder) ModelBuildingRequest(org.apache.maven.model.building.ModelBuildingRequest) DefaultModelBuildingRequest(org.apache.maven.model.building.DefaultModelBuildingRequest) ModelBuildingResult(org.apache.maven.model.building.ModelBuildingResult) DefaultModelBuildingRequest(org.apache.maven.model.building.DefaultModelBuildingRequest) Model(org.apache.maven.model.Model) ModelBuildingException(org.apache.maven.model.building.ModelBuildingException)

Aggregations

ModelBuildingException (org.apache.maven.model.building.ModelBuildingException)6 DefaultModelBuildingRequest (org.apache.maven.model.building.DefaultModelBuildingRequest)4 ModelBuildingResult (org.apache.maven.model.building.ModelBuildingResult)4 Model (org.apache.maven.model.Model)3 ModelSource (org.apache.maven.model.building.ModelSource)2 StringModelSource (org.apache.maven.model.building.StringModelSource)2 MojoExecutionException (org.apache.maven.plugin.MojoExecutionException)2 MojoFailureException (org.apache.maven.plugin.MojoFailureException)2 DefaultProjectBuildingRequest (org.apache.maven.project.DefaultProjectBuildingRequest)2 ProjectBuildingException (org.apache.maven.project.ProjectBuildingException)2 ModelBuilder (org.apache.maven.model.building.ModelBuilder)1 ModelBuildingRequest (org.apache.maven.model.building.ModelBuildingRequest)1 ProjectBuildingRequest (org.apache.maven.project.ProjectBuildingRequest)1