Example usage for org.apache.maven.model.building ModelBuildingRequest VALIDATION_LEVEL_MINIMAL

List of usage examples for org.apache.maven.model.building ModelBuildingRequest VALIDATION_LEVEL_MINIMAL

Introduction

In this page you can find the example usage for org.apache.maven.model.building ModelBuildingRequest VALIDATION_LEVEL_MINIMAL.

Prototype

int VALIDATION_LEVEL_MINIMAL

To view the source code for org.apache.maven.model.building ModelBuildingRequest VALIDATION_LEVEL_MINIMAL.

Click Source Link

Document

Denotes minimal validation of POMs.

Usage

From source file:biz.itcf.maven.plugins.dependencytransfer.TransferMojo.java

License:Apache License

private ArtifactResult resolveParent(Artifact pomArtifact) throws MojoFailureException {
    try {//from   w  w w . j a v  a  2s  . co m
        ModelBuildingRequest buildingRequest = new DefaultModelBuildingRequest();
        buildingRequest.setModelResolver(new AvailableModelResolver(repoSession, null, null, artifactResolver,
                remoteRepositoryManager, projectRepos));
        buildingRequest.setPomFile(pomArtifact.getFile());
        buildingRequest.setTwoPhaseBuilding(false);
        buildingRequest.setSystemProperties(System.getProperties());
        buildingRequest.setValidationLevel(ModelBuildingRequest.VALIDATION_LEVEL_MINIMAL);

        ModelBuildingResult build = modelBuilder.build(buildingRequest);
        Parent dependencyParent = build.getRawModel().getParent();
        if (dependencyParent != null) {
            ArtifactRequest parentArtifactRequest = new ArtifactRequest();
            parentArtifactRequest.setArtifact(new DefaultArtifact(dependencyParent.getGroupId(),
                    dependencyParent.getArtifactId(), "pom", dependencyParent.getVersion()));
            parentArtifactRequest.setRepositories(projectRepos);
            return repoSystem.resolveArtifact(repoSession, parentArtifactRequest);
        } else {
            return null;
        }
    } catch (ArtifactResolutionException e) {
        throw new MojoFailureException("Could not resolve parent artifact.", e);
    } catch (ModelBuildingException e) {
        throw new MojoFailureException("Could not build Maven model for given artifact.", e);
    }
}

From source file:com.buschmais.jqassistant.plugin.m2repo.impl.scanner.EffectiveModelBuilder.java

@Override
public Model getModel(final File pomFile) throws IOException {
    DefaultModelBuilder builder = new DefaultModelBuilderFactory().newInstance();
    ModelBuildingRequest req = new DefaultModelBuildingRequest();
    req.setProcessPlugins(false);//w ww . j  av  a2 s .  co  m
    req.setPomFile(pomFile);
    req.setModelResolver(modelResolver);
    req.setValidationLevel(ModelBuildingRequest.VALIDATION_LEVEL_MINIMAL);
    req.setSystemProperties(System.getProperties());
    builder.setModelValidator(new ModelValidatorImpl());
    try {
        return builder.build(req).getEffectiveModel();
    } catch (ModelBuildingException e) {
        LOGGER.warn("Cannot build effective model for " + pomFile.getAbsolutePath(), e);
        return new EffectiveModel(rawModelBuilder.getModel(pomFile));
    }
}

From source file:com.github.nethad.clustermeister.provisioning.dependencymanager.MavenRepositorySystem.java

License:Apache License

/**
 * Resolve the effective Maven model (pom) for a POM file.
 * /*from  w  w  w .j  a v  a2 s.c  o m*/
 * This resolves the POM hierarchy (parents and modules) and creates an 
 * overall model.
 * 
 * @param pom the POM file to resolve.
 * @return the effective model.
 */
protected Model getEffectiveModel(File pom) {
    ModelBuildingRequest req = new DefaultModelBuildingRequest();
    req.setProcessPlugins(false);
    req.setPomFile(pom);
    req.setModelResolver(new SimpleModelResolver(repositorySystem, createSession(),
            getRepositories(Collections.EMPTY_LIST)));
    req.setValidationLevel(ModelBuildingRequest.VALIDATION_LEVEL_MINIMAL);

    ModelBuilder builder = new DefaultModelBuilderFactory().newInstance();
    try {
        return builder.build(req).getEffectiveModel();
    } catch (ModelBuildingException ex) {
        logger.warn("Could not build maven model.", ex);
    }

    return new Model();
}

From source file:com.redhat.rcm.version.mgr.VersionManager.java

License:Open Source License

private synchronized ModelBuildingRequest newModelBuildingRequest(final File pom,
        final VersionManagerSession session) {
    if (baseMbr == null) {
        final DefaultModelBuildingRequest mbr = new DefaultModelBuildingRequest();
        mbr.setSystemProperties(System.getProperties());
        mbr.setValidationLevel(ModelBuildingRequest.VALIDATION_LEVEL_MINIMAL);
        mbr.setProcessPlugins(false);/*from  ww  w  . ja v a2  s. c om*/
        mbr.setLocationTracking(true);

        this.baseMbr = mbr;
    }

    final DefaultModelBuildingRequest req = new DefaultModelBuildingRequest(baseMbr);
    req.setModelSource(new FileModelSource(pom));

    final VManModelResolver resolver = new VManModelResolver(session, pom, artifactResolver,
            remoteRepositoryManager);

    req.setModelResolver(resolver);

    return req;
}

From source file:com.tobedevoured.naether.maven.Project.java

License:Apache License

/**
 * Load Maven pom/*from  w w  w .  j av  a  2 s .com*/
 *
 * @param pomPath String path
 * @param localRepo String
 * @param repositories {@link Collection<RemoteRepository>}
 * @return {@link Model}
 * @throws ProjectException if fails to open, read, or parse the POM
 */
public static Model loadPOM(String pomPath, String localRepo, Collection<RemoteRepository> repositories)
        throws ProjectException {
    RepositoryClient repoClient = new RepositoryClient(localRepo);
    NaetherModelResolver resolver = new NaetherModelResolver(repoClient, repositories);

    ModelBuildingRequest req = new DefaultModelBuildingRequest();
    req.setProcessPlugins(false);
    req.setPomFile(new File(pomPath));
    req.setModelResolver(resolver);
    req.setValidationLevel(ModelBuildingRequest.VALIDATION_LEVEL_MINIMAL);

    DefaultModelBuilder builder = (new DefaultModelBuilderFactory()).newInstance();
    try {
        return builder.build(req).getEffectiveModel();
    } catch (ModelBuildingException e) {
        throw new ProjectException("Failed to build project from pom", e);
    }
}

From source file:com.xpn.xwiki.tool.backup.AbstractImportMojo.java

License:Open Source License

protected MavenProject getMavenProject(Artifact artifact) throws MojoExecutionException {
    try {//from ww w  .  j  a v  a2 s . c  o m
        ProjectBuildingRequest request = new DefaultProjectBuildingRequest(
                this.session.getProjectBuildingRequest())
                        // We don't want to execute any plugin here
                        .setProcessPlugins(false)
                        // It's not this plugin job to validate this pom.xml
                        .setValidationLevel(ModelBuildingRequest.VALIDATION_LEVEL_MINIMAL)
                        // Use the repositories configured for the built project instead of the default Maven ones
                        .setRemoteRepositories(
                                this.session.getCurrentProject().getRemoteArtifactRepositories());
        // Note: build() will automatically get the POM artifact corresponding to the passed artifact.
        ProjectBuildingResult result = this.projectBuilder.build(artifact, request);
        return result.getProject();
    } catch (ProjectBuildingException e) {
        throw new MojoExecutionException(String.format("Failed to build project for [%s]", artifact), e);
    }
}

From source file:com.xwikisas.xcs.tools.dependenciespackager.PackageExtensionsMojo.java

License:Open Source License

private MavenProject getMavenProject(Artifact artifact) throws MojoExecutionException {
    try {//w  w w  .  j  a  va2 s  .c  o m
        ProjectBuildingRequest request = new DefaultProjectBuildingRequest(
                this.session.getProjectBuildingRequest())
                        // We don't want to execute any plugin here
                        .setProcessPlugins(false)
                        // It's not this plugin job to validate this pom.xml
                        .setValidationLevel(ModelBuildingRequest.VALIDATION_LEVEL_MINIMAL)
                        // Use the repositories configured for the built project instead of the default Maven ones
                        .setRemoteRepositories(
                                this.session.getCurrentProject().getRemoteArtifactRepositories());
        // Note: build() will automatically get the POM artifact corresponding to the passed artifact.
        ProjectBuildingResult result = this.projectBuilder.build(artifact, request);
        return result.getProject();
    } catch (ProjectBuildingException e) {
        throw new MojoExecutionException(String.format("Failed to build project for [%s]", artifact), e);
    }
}

From source file:fr.inria.spirals.repairnator.process.maven.MavenHelper.java

public static Model readPomXml(File pomXml, String localMavenRepository) {
    ModelBuildingRequest req = new DefaultModelBuildingRequest();
    req.setProcessPlugins(true);/*from  www  .  j a  v a 2 s. c o  m*/
    req.setPomFile(pomXml);
    req.setValidationLevel(ModelBuildingRequest.VALIDATION_LEVEL_MINIMAL);
    req.setModelResolver(new RepositoryModelResolver(localMavenRepository));

    DefaultModelBuilder defaultModelBuilder = new DefaultModelBuilderFactory().newInstance();

    // we try to build the model, and if we fail, we try to get the raw model
    try {
        ModelBuildingResult modelBuildingResult = defaultModelBuilder.build(req);
        return modelBuildingResult.getEffectiveModel();
    } catch (ModelBuildingException e) {
        LOGGER.error("Error while building complete model. The raw model will be used. Error message: "
                + e.getMessage());
        return defaultModelBuilder.buildRawModel(pomXml, ModelBuildingRequest.VALIDATION_LEVEL_MINIMAL, true)
                .get();
    }

}

From source file:io.tesla.aether.internal.DefaultTeslaAether.java

License:Open Source License

public Model resolveModel(File pom) throws ModelBuildingException {

    RequestTrace trace = new RequestTrace(pom);
    ModelBuildingRequest modelRequest = new DefaultModelBuildingRequest();
    modelRequest.setValidationLevel(ModelBuildingRequest.VALIDATION_LEVEL_MINIMAL);
    modelRequest.setProcessPlugins(false);
    modelRequest.setTwoPhaseBuilding(false);
    modelRequest.setSystemProperties(toProperties(session.getUserProperties(), session.getSystemProperties()));
    //// www .j  a  v a 2 s . c o m
    // The model cache and default model resolver should be injected
    //
    modelRequest.setModelCache(new DefaultModelCache());
    modelRequest.setModelResolver(new DefaultModelResolver(session, trace.newChild(modelRequest), "bithub",
            artifactResolver, remoteRepositoryManager, remoteRepositories));
    modelRequest.setPomFile(pom);
    return modelBuilder.build(modelRequest).getEffectiveModel();
}

From source file:io.tesla.maven.bridge.support.ModelBuildingRequestBuilder.java

License:Open Source License

private ModelBuildingRequestBuilder() {
    setSystemProperties(System.getProperties());
    setValidationLevel(ModelBuildingRequest.VALIDATION_LEVEL_MINIMAL);
    setLocationTracking(false);
    setProcessPlugins(false);
}