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

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

Introduction

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

Prototype

ModelBuildingRequest setTwoPhaseBuilding(boolean twoPhaseBuilding);

Source Link

Document

Enables/disables two-phase building.

Usage

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

License:Apache License

private ArtifactResult resolveParent(Artifact pomArtifact) throws MojoFailureException {
    try {//  ww w .  j ava  2 s. c om
        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: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()));
    ////from w  w w .  j a  v a  2s  .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:org.jboss.maven.extension.dependency.resolver.EffectiveModelBuilder.java

License:Apache License

/**
 * Build the effective model for the given pom file
 *
 * @param pomFile/*from  w w  w  . ja v  a  2  s .  c  o  m*/
 * @return effective pom model
 * @throws ModelBuildingException
 */
private Model buildModel(File pomFile, ModelResolver modelResolver) throws ModelBuildingException {
    ModelBuildingRequest request = new DefaultModelBuildingRequest();
    request.setPomFile(pomFile);
    request.setModelResolver(modelResolver);
    request.setValidationLevel(ModelBuildingRequest.VALIDATION_LEVEL_MAVEN_3_0);
    request.setTwoPhaseBuilding(false); // Resolve the complete model in one step
    request.setSystemProperties(System.getProperties());
    ModelBuildingResult result = modelBuilder.build(request);
    return result.getEffectiveModel();
}

From source file:org.talend.components.api.service.internal.ComponentServiceImpl.java

License:Open Source License

Model loadPom(final InputStream pomStream, MavenBooter booter, List<String> profilesList)
        throws ModelBuildingException {

    RepositorySystem system = booter.newRepositorySystem();
    RepositorySystemSession session = booter.newRepositorySystemSession(system);
    ModelBuildingRequest modelRequest = new DefaultModelBuildingRequest();
    modelRequest.setValidationLevel(ModelBuildingRequest.VALIDATION_LEVEL_MINIMAL);
    modelRequest.setProcessPlugins(false);
    modelRequest.setTwoPhaseBuilding(false);
    modelRequest.setSystemProperties(toProperties(session.getUserProperties(), session.getSystemProperties()));
    // modelRequest.setModelCache( DefaultModelCache.newInstance( session ) );
    ProjectModelResolver projectModelResolver = new ProjectModelResolver(session, null, system,
            new DefaultRemoteRepositoryManager(),
            booter.getRemoteRepositoriesWithAuthentification(system, session), null, null);
    modelRequest.setModelResolver(projectModelResolver);
    modelRequest.setActiveProfileIds(profilesList);
    modelRequest.setModelSource(new ModelSource() {

        @Override/*w ww .j  av  a 2 s. com*/
        public InputStream getInputStream() throws IOException {
            return pomStream;
        }

        @Override
        public String getLocation() {
            return "";// FIXME return the component name
        }
    });
    if (modelBuilder == null) {
        modelBuilder = new DefaultModelBuilderFactory().newInstance();
    }
    ModelBuildingResult builtModel = modelBuilder.build(modelRequest);
    LOGGER.debug("built problems:" + builtModel.getProblems());
    return builtModel.getEffectiveModel();
}