Java 类org.apache.maven.project.ProjectBuildingRequest 实例源码

项目:EM    文件:Dependencies.java   
@SuppressWarnings("deprecation")
public Artifact asArtifact (ProjectBuildingRequest projectBuildingRequest, Dependency dependency) throws MavenExecutionException {
    DefaultArtifactCoordinate coordinate = new DefaultArtifactCoordinate();
    coordinate.setGroupId(dependency.getGroupId());
    coordinate.setArtifactId(dependency.getArtifactId());
    coordinate.setVersion(dependency.getVersion());
    coordinate.setExtension(dependency.getType());
    coordinate.setClassifier(dependency.getClassifier());

    ArtifactResult ar;
    try {
        ar = artifactResolver.resolveArtifact(projectBuildingRequest, coordinate);
    } catch (ArtifactResolverException e) {
        throw new MavenExecutionException("Failed to resolve artifact " + coordinate, e);
    }
    return ar.getArtifact();

}
项目:incubator-netbeans    文件:MavenEmbedder.java   
public MavenExecutionResult readProjectWithDependencies(MavenExecutionRequest req, boolean useWorkspaceResolution) {
    if (useWorkspaceResolution) {
        req.setWorkspaceReader(new NbWorkspaceReader());
    }
    File pomFile = req.getPom();
    MavenExecutionResult result = new DefaultMavenExecutionResult();
    try {
        ProjectBuildingRequest configuration = req.getProjectBuildingRequest();
        configuration.setValidationLevel(ModelBuildingRequest.VALIDATION_LEVEL_MINIMAL);
        configuration.setResolveDependencies(true);
        configuration.setRepositorySession(maven.newRepositorySession(req));
        ProjectBuildingResult projectBuildingResult = projectBuilder.build(pomFile, configuration);
        result.setProject(projectBuildingResult.getProject());
        result.setDependencyResolutionResult(projectBuildingResult.getDependencyResolutionResult());
    } catch (ProjectBuildingException ex) {
        //don't add the exception here. this should come out as a build marker, not fill
        //the error logs with msgs
        return result.addException(ex);
    }
    normalizePaths(result.getProject());
    return result;
}
项目:incubator-netbeans    文件:ArtifactDependencyIndexCreator.java   
private MavenProject load(ArtifactInfo ai) {
    try {
        Artifact projectArtifact = embedder.createArtifact(ai.getGroupId(), ai.getArtifactId(), ai.getVersion(), ai.getPackaging() != null ? ai.getPackaging() : "jar");
        ProjectBuildingRequest dpbr = embedder.createMavenExecutionRequest().getProjectBuildingRequest();
        //mkleint: remote repositories don't matter we use project embedder.
        dpbr.setRemoteRepositories(remoteRepos);
        dpbr.setProcessPlugins(false);
        dpbr.setValidationLevel(ModelBuildingRequest.VALIDATION_LEVEL_MINIMAL);

        ProjectBuildingResult res = embedder.buildProject(projectArtifact, dpbr);
        if (res.getProject() != null) {
            return res.getProject();
        } else {
            LOG.log(Level.FINER, "No project model from repository for {0}: {1}", new Object[] {ai, res.getProblems()});
        }
    } catch (ProjectBuildingException ex) {
        LOG.log(Level.FINER, "Failed to load project model from repository for {0}: {1}", new Object[] {ai, ex});
    } catch (Exception exception) {
        LOG.log(Level.FINER, "Failed to load project model from repository for " + ai, exception);
    }
    return null;
}
项目:wildfly-swarm-fraction-plugin    文件:AbstractFractionsMojo.java   
private void buildProjects() throws MojoExecutionException {
    final ProjectBuildingRequest request = new DefaultProjectBuildingRequest();
    request.setProcessPlugins(false);
    request.setSystemProperties(System.getProperties());
    request.setRemoteRepositories(this.project.getRemoteArtifactRepositories());
    request.setRepositorySession(this.repositorySystemSession);
    request.setResolveDependencies(true);

    try {
        PROBABLE_FRACTIONS = this.projectBuilder
                .build(Collections.singletonList(findRoot(this.project).getFile()), true, request)
                .stream()
                .filter(this::isNotArquillianArtifact)
                .map(ProjectBuildingResult::getProject)
                .collect(Collectors.toList());
    } catch (ProjectBuildingException e) {
        throw new MojoExecutionException("Error generating list of PROBABLE_FRACTIONS", e);
    }
}
项目:msbuild-maven-plugin    文件:AbstractMSBuildMojoTestCase.java   
/**
 * Workaround for parent class lookupMojo and lookupConfiguredMojo.
 * @param name the name of the Mojo to lookup
 * @param pomPath where to find the POM file
 * @return a configured MSBuild Mojo for testing
 * @throws Exception if we can't find the Mojo or the POM is malformed
 */
protected final Mojo lookupConfiguredMojo( String name, String pomPath ) throws Exception
{
    File pom = new File( getClass().getResource( pomPath ).getPath() );
    assertTrue( pom.exists() );

    // The following 4 lines are simply to get a MavenProject object
    MavenExecutionRequest executionRequest = new DefaultMavenExecutionRequest();
    ProjectBuildingRequest buildingRequest = executionRequest.getProjectBuildingRequest();
    ProjectBuilder projectBuilder = this.lookup( ProjectBuilder.class );
    MavenProject mavenProject = projectBuilder.build( pom, buildingRequest ).getProject();
    assertNotNull( mavenProject );

    // Used lookupMojo as it sets up most of what we need and reads configuration
    // variables from the poms.
    // It doesn't set a MavenProject so we have to do that manually
    // lookupConfiguredMojo doesn't work properly, configuration variables are no expanded
    // as we expect and it fails to setup a Log.
    Mojo mojo = lookupMojo( name, pom );
    //Mojo mojo = super.lookupConfiguredMojo( mavenProject, name );
    assertNotNull( mojo );

    setVariableValueToObject( mojo, "mavenProject", mavenProject );

    return mojo;
}
项目:furnace    文件:ProjectHelper.java   
public List<Dependency> resolveDependenciesFromPOM(File pomFile) throws Exception
{
   PlexusContainer plexus = new PlexusContainer();
   List<Dependency> result;
   try
   {
      ProjectBuildingRequest request = getBuildingRequest(plexus);
      request.setResolveDependencies(true);
      ProjectBuilder builder = plexus.lookup(ProjectBuilder.class);
      ProjectBuildingResult build = builder.build(pomFile, request);
      result = build.getDependencyResolutionResult().getDependencies();
   }
   finally
   {
      plexus.shutdown();
   }
   return result;
}
项目:wildfly-maven-plugin    文件:EclipseAetherArtifactResolver.java   
@Override
public File resolve(final MavenProject project, final String artifact) {
    final ArtifactResult result;
    try {
        final ProjectBuildingRequest projectBuildingRequest = project.getProjectBuildingRequest();

        final ArtifactRequest request = new ArtifactRequest();
        final ArtifactNameSplitter splitter = ArtifactNameSplitter.of(artifact).split();
        final Artifact defaultArtifact = new DefaultArtifact(splitter.getGroupId(), splitter.getArtifactId(), splitter.getClassifier(), splitter.getPackaging(), splitter.getVersion());
        request.setArtifact(defaultArtifact);
        final List<RemoteRepository> repos = project.getRemoteProjectRepositories();
        request.setRepositories(repos);
        result = repoSystem.resolveArtifact(projectBuildingRequest.getRepositorySession(), request);
    } catch (ArtifactResolutionException e) {
        throw new RuntimeException(e.getMessage(), e);
    }
    return result.getArtifact().getFile();
}
项目:ginger    文件:MavenGeneratorTest.java   
/**
 * @throws Exception if any
 */
@Test
public void testSomething()
        throws Exception {
    File projectBase = getTestFile("src/test/resources/com/vityuk/ginger/maven/");
    File pom = new File(projectBase, "pom.xml");
    assertNotNull(pom);
    assertTrue(pom.exists());

    MavenExecutionRequest executionRequest = new DefaultMavenExecutionRequest();
    ProjectBuildingRequest buildingRequest = executionRequest.getProjectBuildingRequest();
    ProjectBuilder projectBuilder = lookup(ProjectBuilder.class);
    MavenProject project = projectBuilder.build(pom, buildingRequest).getProject();

    MavenGeneratorMojo myMojo = (MavenGeneratorMojo) lookupConfiguredMojo(project, "ginger-generator");
    assertNotNull(myMojo);

    myMojo.execute();

    File outputDirectory = new File(myMojo.outputDirectory);
    File resultFile = new File(outputDirectory, "com/vityuk/ginger/test1/GeneralConstants.java");
    assertTrue("GeneralConstants.java is NOT generated", resultFile.exists());
}
项目:forge-furnace    文件:ProjectHelper.java   
public List<Dependency> resolveDependenciesFromPOM(File pomFile) throws Exception
{
   PlexusContainer plexus = new PlexusContainer();
   List<Dependency> result;
   try
   {
      ProjectBuildingRequest request = getBuildingRequest(plexus);
      request.setResolveDependencies(true);
      ProjectBuilder builder = plexus.lookup(ProjectBuilder.class);
      ProjectBuildingResult build = builder.build(pomFile, request);
      result = build.getDependencyResolutionResult().getDependencies();
   }
   finally
   {
      plexus.shutdown();
   }
   return result;
}
项目:EM    文件:ExportMojo.java   
private Set<File> prepareDependencies(ProjectBuildingRequest projectBuildingRequest, MavenProject project) {

        if (logger.isDebugEnabled()) {
            logger.debug("Analysing project's BOMs!");
        } else if (Flag.verbose()) {
            logger.info("Analysing project's BOMs!");
        }

        Set<File> bundleSet = new HashSet<File>();

        boolean generateIndex = project.getProperties().containsKey(PROP_CONFIG_INDEX);

        processModules(projectBuildingRequest, project);

        Set<Artifact> artifacts = new HashSet<>();
        try {
            artifacts.addAll(dependencies.asArtifacts(projectBuildingRequest, project));
            artifacts.addAll(dependencies.managedAsArtifacts(projectBuildingRequest, project));
        } catch (MavenExecutionException e) {
            throw new RuntimeException("Failed to analyze dependencies", e);
        }

        /*
         * For each artifact : - convert to bundle if it's not - add it to the bundle
         * set
         */
        artifacts.stream().forEach(a -> addToBundleSet(a, emProjectGeneratedModules.toFile(), bundleSet, generateIndex));

        return bundleSet;

    }
项目:EM    文件:Dependencies.java   
public Set<Artifact> managedAsArtifacts(ProjectBuildingRequest projectBuildingRequest, MavenProject project) throws MavenExecutionException {
    if (project.getDependencyManagement() != null) {
        return asArtifacts(projectBuildingRequest, project.getDependencyManagement().getDependencies());
    } else {
        return Collections.emptySet();
    }
}
项目:incubator-netbeans    文件:NbMavenProjectImpl.java   
/**
 * replacement for MavenProject.getParent() which has bad long term memory behaviour. We offset it by recalculating/reparsing everything
 * therefore should not be used lightly!
 * pass a MavenProject instance and current configuration and other settings will be applied when loading the parent.
 * @param project
 * @return null or the parent mavenproject
 */

public MavenProject loadParentOf(MavenEmbedder embedder, MavenProject project) throws ProjectBuildingException {

    MavenProject parent = null;
    ProjectBuilder builder = embedder.lookupComponent(ProjectBuilder.class);
    MavenExecutionRequest req = embedder.createMavenExecutionRequest();
    M2Configuration active = configProvider.getActiveConfiguration();
    req.addActiveProfiles(active.getActivatedProfiles());
    req.setNoSnapshotUpdates(true);
    req.setUpdateSnapshots(false);
    req.setInteractiveMode(false);
    req.setRecursive(false);
    req.setOffline(true);
    //#238800 important to merge, not replace
    Properties uprops = req.getUserProperties();
    uprops.putAll(MavenProjectCache.createUserPropsForProjectLoading(active.getProperties()));
    req.setUserProperties(uprops);

    ProjectBuildingRequest request = req.getProjectBuildingRequest();
    request.setRemoteRepositories(project.getRemoteArtifactRepositories());
    DefaultMaven maven = (DefaultMaven) embedder.lookupComponent(Maven.class);

    request.setRepositorySession(maven.newRepositorySession(req));

    if (project.getParentFile() != null) {
        parent = builder.build(project.getParentFile(), request).getProject();
    } else if (project.getModel().getParent() != null) {
        parent = builder.build(project.getParentArtifact(), request).getProject();
    }
    //clear the project building request, it references multiple Maven Models via the RepositorySession cache
    //is not used in maven itself, most likely used by m2e only..
    if (parent != null) {
        parent.setProjectBuildingRequest(null);
    }
    MavenEmbedder.normalizePaths(parent);
    return parent;
}
项目:incubator-netbeans    文件:RepositoryMavenCPProvider.java   
private MavenProject loadMavenProject(File pom, String groupId, String artifactId, String version) {
        MavenEmbedder embedder = EmbedderFactory.getProjectEmbedder();
        Artifact projectArtifact = embedder.createArtifact(groupId, artifactId, version,  "jar");
        try {
            ProjectBuildingRequest dpbr = embedder.createMavenExecutionRequest().getProjectBuildingRequest();
            dpbr.setValidationLevel(ModelBuildingRequest.VALIDATION_LEVEL_MINIMAL);

            dpbr.setProcessPlugins(false);
            dpbr.setResolveDependencies(true);
            ArrayList<ArtifactRepository> remoteRepos = new ArrayList<ArtifactRepository>();
//for project embedder doens't matter            
//            remoteRepos = RepositoryPreferences.getInstance().remoteRepositories();
            dpbr.setRemoteRepositories(remoteRepos);

            ProjectBuildingResult res = embedder.buildProject(projectArtifact, dpbr);
            if (res.getProject() != null) {
                return res.getProject();
            } else {
                LOG.log(Level.INFO, "No project model from repository for {0}: {1}", new Object[] {projectArtifact, res.getProblems()});
            }
        } catch (ProjectBuildingException ex) {
            LOG.log(Level.FINER, "Failed to load project model from repository for {0}: {1}", new Object[] {projectArtifact, ex});
        } catch (Exception exception) {
            LOG.log(Level.FINER, "Failed to load project model from repository for " + projectArtifact, exception);
        }
        return null;
    }
项目:incubator-netbeans    文件:DependencyNode.java   
private Relocation getRelocation(org.netbeans.modules.maven.model.pom.Dependency d) {
    ProjectBuildingRequest dpbr = EmbedderFactory.getProjectEmbedder().createMavenExecutionRequest().getProjectBuildingRequest();
    dpbr.setValidationLevel(ModelBuildingRequest.VALIDATION_LEVEL_MINIMAL);
    dpbr.setProcessPlugins(false);
    dpbr.setResolveDependencies(false);
    ArrayList<ArtifactRepository> remoteRepos = new ArrayList<>();
    dpbr.setRemoteRepositories(remoteRepos);
    String groupId = d.getGroupId();
    String artifactId = d.getArtifactId();
    String version = d.getVersion();
    if(groupId != null && !"".equals(groupId.trim()) &&
       artifactId != null && !"".equals(artifactId.trim()) &&
       version != null && !"".equals(version.trim())) 
    {           
        MavenEmbedder embedder = EmbedderFactory.getProjectEmbedder();
        Artifact a = embedder.createProjectArtifact(groupId, artifactId, version);
        try {
            ProjectBuildingResult r = embedder.buildProject(a, dpbr);
            DistributionManagement dm = r.getProject().getDistributionManagement();
            return dm != null ? dm.getRelocation() : null;
        } catch (ProjectBuildingException ex) {
            // just log and hope for the best ...
            Logger.getLogger(DependencyNode.class.getName()).log(Level.INFO, version, ex);                
        }
    }
    return null;
}
项目:incubator-netbeans    文件:EffectivePomMD.java   
static List<ModelProblem> runMavenValidationImpl(final File pom) {
    //TODO profiles based on current configuration??
    MavenEmbedder embedder = EmbedderFactory.getProjectEmbedder();
    MavenExecutionRequest meReq = embedder.createMavenExecutionRequest();
    ProjectBuildingRequest req = meReq.getProjectBuildingRequest();
    req.setValidationLevel(ModelBuildingRequest.VALIDATION_LEVEL_MAVEN_3_1); // currently enables just <reporting> warning
    req.setLocalRepository(embedder.getLocalRepository());
    List<ArtifactRepository> remoteRepos = RepositoryPreferences.getInstance().remoteRepositories(embedder);
    req.setRemoteRepositories(remoteRepos);
    req.setRepositorySession(((DefaultMaven) embedder.lookupComponent(Maven.class)).newRepositorySession(meReq));
    List<ModelProblem> problems;
    try {
        problems = embedder.lookupComponent(ProjectBuilder.class).build(pom, req).getProblems();
    } catch (ProjectBuildingException x) {
        problems = new ArrayList<ModelProblem>();
        List<ProjectBuildingResult> results = x.getResults();
        if (results != null) { //one code point throwing ProjectBuildingException contains results,
            for (ProjectBuildingResult result : results) {
                problems.addAll(result.getProblems());
            }
        } else {
            // another code point throwing ProjectBuildingException doesn't contain results..
            Throwable cause = x.getCause();
            if (cause instanceof ModelBuildingException) {
                problems.addAll(((ModelBuildingException) cause).getProblems());
            }
        }
    }
    return problems;
}
项目:incubator-netbeans    文件:MavenEmbedder.java   
public ProjectBuildingResult buildProject(Artifact art, ProjectBuildingRequest req) throws ProjectBuildingException {
    if (req.getLocalRepository() == null) {
       req.setLocalRepository(getLocalRepository());
    }
    MavenExecutionRequest request = createMavenExecutionRequest();
    req.setProcessPlugins(false);
    req.setRepositorySession(maven.newRepositorySession(request));
    ProjectBuildingResult res = projectBuilder.build(art, req);
    normalizePaths(res.getProject());
    return res;
}
项目:incubator-netbeans    文件:StatusProvider.java   
static List<ModelProblem> runMavenValidationImpl(final File pom) {
    MavenEmbedder embedder = EmbedderFactory.getProjectEmbedder();
    MavenExecutionRequest meReq = embedder.createMavenExecutionRequest();
    ProjectBuildingRequest req = meReq.getProjectBuildingRequest();
    req.setValidationLevel(ModelBuildingRequest.VALIDATION_LEVEL_MAVEN_3_0); // 3.1 currently enables just <reporting> warning, see issue 223562 for details on why it's bad to show.
    req.setLocalRepository(embedder.getLocalRepository());
    List<ArtifactRepository> remoteRepos = RepositoryPreferences.getInstance().remoteRepositories(embedder);
    req.setRemoteRepositories(remoteRepos);
    req.setRepositorySession(((DefaultMaven) embedder.lookupComponent(Maven.class)).newRepositorySession(meReq));
    List<ModelProblem> problems;
    try {
        problems = embedder.lookupComponent(ProjectBuilder.class).build(pom, req).getProblems();
    } catch (ProjectBuildingException x) {
        problems = new ArrayList<ModelProblem>();
        List<ProjectBuildingResult> results = x.getResults();
        if (results != null) { //one code point throwing ProjectBuildingException contains results,
            for (ProjectBuildingResult result : results) {
                problems.addAll(result.getProblems());
            }
        } else {
            // another code point throwing ProjectBuildingException doesn't contain results..
            Throwable cause = x.getCause();
            if (cause instanceof ModelBuildingException) {
                problems.addAll(((ModelBuildingException) cause).getProblems());
            }
        }
    }
    List<ModelProblem> toRet = new LinkedList<ModelProblem>();
    for (ModelProblem problem : problems) {
        if(ModelUtils.checkByCLIMavenValidationLevel(problem)) {
            toRet.add(problem);
        }
    }
    return toRet;
}
项目:mvn-golang    文件:GolangMojoCfgTest.java   
private <T extends AbstractGolangMojo> T findMojo(final Class<T> klazz, final String pomName, final String goal) throws Exception {
  final File pomFile = new File(GolangMojoCfgTest.class.getResource(pomName).toURI());
  final MavenExecutionRequest executionRequest = new DefaultMavenExecutionRequest();
  final ProjectBuildingRequest buildingRequest = executionRequest.getProjectBuildingRequest();
  final ProjectBuilder projectBuilder = this.lookup(ProjectBuilder.class);
  final MavenProject project = projectBuilder.build(pomFile, buildingRequest).getProject();
  return klazz.cast(this.lookupConfiguredMojo(project, goal));
}
项目:rpm-systemd-maven-plugin    文件:AbstractHarnessMojoTestCase.java   
protected Mojo lookupMojo(Path pomPath, String goal) throws Exception {
    File pom = getTestFile(pomPath.toString());
    assertTrue(pom.exists());

    MavenExecutionRequest executionRequest = new DefaultMavenExecutionRequest();
    ProjectBuildingRequest buildingRequest = executionRequest.getProjectBuildingRequest();
    buildingRequest.setRepositorySession(new DefaultRepositorySystemSession());

    ProjectBuilder projectBuilder = lookup(ProjectBuilder.class);
    MavenProject project = projectBuilder.build(pom, buildingRequest).getProject();

    return lookupConfiguredMojo(project, goal);
}
项目:avrohugger-maven-plugin    文件:AbstractHarnessMojoTestCase.java   
protected Mojo lookupMojo(Path pomPath, String goal) throws Exception {
    File pom = getTestFile(pomPath.toString());
    assertTrue(pom.exists());

    MavenExecutionRequest executionRequest = new DefaultMavenExecutionRequest();
    ProjectBuildingRequest buildingRequest = executionRequest.getProjectBuildingRequest();
    buildingRequest.setRepositorySession(new DefaultRepositorySystemSession());

    ProjectBuilder projectBuilder = lookup(ProjectBuilder.class);
    MavenProject project = projectBuilder.build(pom, buildingRequest).getProject();

    return lookupConfiguredMojo(project, goal);
}
项目:hub-maven-plugin    文件:MavenDependencyExtractor.java   
public DependencyNode getRootDependencyNode(final DependencyGraphBuilder dependencyGraphBuilder, final MavenSession session, final MavenProject project,
        final String projectName,
        final String versionName) throws MojoExecutionException {
    org.apache.maven.shared.dependency.graph.DependencyNode rootNode = null;
    final ProjectBuildingRequest buildRequest = new DefaultProjectBuildingRequest(
            session.getProjectBuildingRequest());
    buildRequest.setProject(project);
    buildRequest.setResolveDependencies(true);

    try {
        rootNode = dependencyGraphBuilder.buildDependencyGraph(buildRequest, null);
    } catch (final DependencyGraphBuilderException ex) {
        throw new MojoExecutionException(EXCEPTION_MSG_NO_DEPENDENCY_GRAPH, ex);
    }

    final String groupId = project.getGroupId();
    final String artifactId = project.getArtifactId();
    final String version = versionName;
    final MavenExternalId projectGav = new MavenExternalId(groupId, artifactId, version);

    final Set<DependencyNode> children = new LinkedHashSet<>();
    final DependencyNode root = new DependencyNode(projectName, versionName, projectGav, children);
    for (final org.apache.maven.shared.dependency.graph.DependencyNode child : rootNode.getChildren()) {
        if (includedScopes.contains(child.getArtifact().getScope())) {
            children.add(createCommonDependencyNode(child));
        }
    }

    for (final MavenProject moduleProject : project.getCollectedProjects()) {
        if (!excludedModules.contains(moduleProject.getArtifactId())) {
            final DependencyNode moduleRootNode = getRootDependencyNode(dependencyGraphBuilder, session, moduleProject, moduleProject.getArtifactId(),
                    moduleProject.getVersion());
            children.addAll(moduleRootNode.children);
        }
    }

    return root;
}
项目:copybook4java    文件:CodeGenMojoTest.java   
private Mojo lookupConfiguredMojo(String goal, File pom) throws Exception
{
    MavenExecutionRequest request = new DefaultMavenExecutionRequest();
    request.setBaseDirectory(pom.getParentFile());
    ProjectBuildingRequest configuration = request.getProjectBuildingRequest();
    // Fix for bug: https://git-wip-us.apache.org/repos/asf?p=maven-plugin-testing.git;a=commit;h=3cd5f47c586499e438a3f9393304ac9d1f9a7f53
    configuration.setRepositorySession(new DefaultRepositorySystemSession());
    MavenProject project = lookup(ProjectBuilder.class).build(pom, configuration).getProject();
    return super.lookupConfiguredMojo(project, goal);
}
项目:spring-cloud-function    文件:DependencyResolver.java   
private ProjectBuildingRequest getProjectBuildingRequest(Properties properties)
        throws NoLocalRepositoryManagerException {
    DefaultProjectBuildingRequest projectBuildingRequest = new DefaultProjectBuildingRequest();
    DefaultRepositorySystemSession session = createSession(properties);
    projectBuildingRequest.setRepositoryMerging(RepositoryMerging.REQUEST_DOMINANT);
    projectBuildingRequest.setRemoteRepositories(mavenRepositories(properties));
    projectBuildingRequest.getRemoteRepositories()
            .addAll(mavenRepositories(settings));
    projectBuildingRequest.setRepositorySession(session);
    projectBuildingRequest.setProcessPlugins(false);
    projectBuildingRequest.setBuildStartTime(new Date());
    projectBuildingRequest.setUserProperties(properties);
    projectBuildingRequest.setSystemProperties(System.getProperties());
    return projectBuildingRequest;
}
项目:spring-cloud-function    文件:DependencyResolver.java   
public Model readModel(final Resource resource, final Properties properties) {
    initialize();
    try {
        ProjectBuildingRequest request = getProjectBuildingRequest(properties);
        request.setResolveDependencies(false);
        ProjectBuildingResult result = projectBuilder
                .build(new PropertiesModelSource(properties, resource), request);
        return result.getProject().getModel();
    }
    catch (Exception e) {
        throw new IllegalStateException("Failed to build model from effective pom",
                e);
    }
}
项目:tibco-bwmaven    文件:BWLifecycleParticipant.java   
private List<MavenProject> prepareProjects(List<MavenProject> projects, MavenSession session) throws MavenExecutionException {
    List<MavenProject> result = new ArrayList<MavenProject>();

    ProjectBuildingRequest projectBuildingRequest = session.getProjectBuildingRequest();

    for (MavenProject mavenProject : projects) {
        logger.debug("project: " + mavenProject.getGroupId()+":"+mavenProject.getArtifactId());

        List<String> oldActiveProfileIds = projectBuildingRequest.getActiveProfileIds();
        try {
            List<String> activeProfileIds = activateProfilesWithProperties(mavenProject, oldActiveProfileIds);
            if (activeProfileIds.size() != oldActiveProfileIds.size()) {
                projectBuildingRequest.setActiveProfileIds(activeProfileIds);
                if (mavenProject.getFile() != null) {
                    List<File> files = new ArrayList<File>();
                    files.add(mavenProject.getFile());
                    List<ProjectBuildingResult> results = null;
                    try {
                        results = projectBuilder.build(files, true, projectBuildingRequest);
                    } catch (ProjectBuildingException e) {
                    }

                    for (ProjectBuildingResult projectBuildingResult : results) {
                        mavenProject = projectBuildingResult.getProject();
                    }
                }
            }
        } finally {
            projectBuildingRequest.setActiveProfileIds(oldActiveProfileIds);
        }

        if (mavenProject.getPackaging().startsWith(AbstractBWMojo.BWEAR_TYPE) || "true".equals(propertiesManager.getPropertyValue("enableBWLifecycle"))) {
            addTIBCODependenciesToPlugin(mavenProject, logger);
        }
        result.add(mavenProject);
    }

    return result;
}
项目:xml-maven-plugin    文件:AbstractXmlMojoTestCase.java   
protected AbstractXmlMojo newMojo( String pDir )
        throws Exception
    {
        File testPom = new File( new File( getBasedir(), pDir ), "pom.xml" );

        MavenExecutionRequest executionRequest = new DefaultMavenExecutionRequest();
        ProjectBuildingRequest buildingRequest = executionRequest.getProjectBuildingRequest();
        ProjectBuilder projectBuilder = this.lookup(ProjectBuilder.class);
        MavenProject project = projectBuilder.build(testPom, buildingRequest).getProject();
//        final Build build = new Build();
//        build.setDirectory( "target" );
//        project.setBuild(build);
        project.getBuild().setDirectory("target");
        AbstractXmlMojo vm = (AbstractXmlMojo) lookupConfiguredMojo(project, getGoal());
        setVariableValueToObject( vm, "basedir", new File( getBasedir(), pDir ) );
        final Log log = new SilentLog();
        DefaultResourceManager rm = new DefaultResourceManager();
        setVariableValueToObject( rm, "logger", log );
        setVariableValueToObject( vm, "locator", rm );
        final Map<String, ResourceLoader> resourceLoaders = new HashMap<String, ResourceLoader>();
        resourceLoaders.put( "file", new FileResourceLoader() );
        resourceLoaders.put( "jar", new JarResourceLoader() );
        resourceLoaders.put( "classloader", new ThreadContextClasspathResourceLoader() );
        URLResourceLoader url = new URLResourceLoader();
        setVariableValueToObject( url, "logger", log );
        resourceLoaders.put( "url", url );
        setVariableValueToObject( rm, "resourceLoaders", resourceLoaders );

//        MavenProjectStub project = new MavenProjectStub()
//        {
//            public Build getBuild()
//            {
//                return build;
//            }
//        };
//        setVariableValueToObject( vm, "project", project );
        return vm;
    }
项目:flatten-maven-plugin    文件:FlattenModelResolver.java   
/**
 * The constructor.
 * @param localRepository is the local repository.
 * @param artifactFactory is the factory used to create project artifact instances.
 * @param dependencyResolver is the resolver to use for resolving version ranges.
 * @param projectBuildingRequest
 * @param reactorModels is the list of modules of the project being built.
 */
public FlattenModelResolver( ArtifactRepository localRepository, ArtifactFactory artifactFactory,
                            DependencyResolver dependencyResolver,
                            ProjectBuildingRequest projectBuildingRequest, List<MavenProject> reactorModels )
{
    this.localRepository = localRepository;
    this.artifactFactory = artifactFactory;
    this.depencencyResolver = dependencyResolver;
    this.projectBuildingRequest = projectBuildingRequest;
    this.reactorModelPool = new ReactorModelPool();
    reactorModelPool.addProjects( reactorModels );
}
项目:dOOv    文件:DependencyUtils.java   
/**
 * @param artifact the artifact to resolve
 * @param project  the current Maven project
 * @return the resolved artifact from the current local repository
 */
static File resolve(Artifact artifact, MavenProject project) {
    ProjectBuildingRequest projectBuildingRequest = project.getProjectBuildingRequest();
    ArtifactRepository localRepository = projectBuildingRequest.getLocalRepository();
    Artifact resolvedArtifact = localRepository.find(artifact);
    return resolvedArtifact != null ? resolvedArtifact.getFile() : null;
}
项目:java-binary-block-parser    文件:JBBPGenerateMojoTest.java   
private JBBPGenerateMojo findMojo(final String pomName, final String goal) throws Exception {
    final File pomFile = new File(this.getClass().getResource(pomName).toURI());
    final MavenExecutionRequest executionRequest = new DefaultMavenExecutionRequest();
    final ProjectBuildingRequest buildingRequest = executionRequest.getProjectBuildingRequest();
    final ProjectBuilder projectBuilder = this.lookup(ProjectBuilder.class);
    final MavenProject project = projectBuilder.build(pomFile, buildingRequest).getProject();
    return (JBBPGenerateMojo) this.lookupConfiguredMojo(project, goal);
}
项目:uber-pom    文件:UPomMojoConfigTest.java   
private UPomMojo init(final File config) throws Exception {
  final MavenExecutionRequest executionRequest = new DefaultMavenExecutionRequest();
  final ProjectBuildingRequest buildingRequest = executionRequest.getProjectBuildingRequest();
  final ProjectBuilder projectBuilder = this.lookup(ProjectBuilder.class);
  final MavenProject project = projectBuilder.build(config, buildingRequest).getProject();
  final UPomMojo mojo = (UPomMojo) this.lookupConfiguredMojo(project, "upom");
  return mojo;
}
项目:license-audit-maven-plugin    文件:BetterAbstractMojoTestCase.java   
/** As {@link #lookupConfiguredMojo(MavenProject, String)} but taking the pom file 
 * and creating the {@link MavenProject}. */
protected Mojo lookupConfiguredMojo(File pom, String goal) throws Exception {
    assertNotNull( pom );
    assertTrue( pom.exists() );

    ProjectBuildingRequest buildingRequest = newMavenSession().getProjectBuildingRequest();
    ProjectBuilder projectBuilder = lookup(ProjectBuilder.class);
    MavenProject project = projectBuilder.build(pom, buildingRequest).getProject();

    return lookupConfiguredMojo(project, goal);
}
项目:yeoman-maven-plugin    文件:YeomanMojoTest.java   
private MavenProject getMavenProject(String pomPath) throws Exception {
    File pom = new File(pomPath);
    MavenExecutionRequest request = new DefaultMavenExecutionRequest();
    request.setPom(pom);
    ProjectBuildingRequest configuration = request.getProjectBuildingRequest();
    return lookup( ProjectBuilder.class ).build( pom, configuration ).getProject();
}
项目:takari-lifecycle    文件:InstallDeployTest.java   
private MavenProject readMavenProject(File basedir, Properties properties) throws Exception {
  File pom = new File(basedir, "pom.xml");
  MavenExecutionRequest request = new DefaultMavenExecutionRequest();
  request.setUserProperties(properties);
  request.setBaseDirectory(basedir);
  ProjectBuildingRequest configuration = request.getProjectBuildingRequest();
  configuration.setRepositorySession(new DefaultRepositorySystemSession());
  MavenProject project = mojos.lookup(ProjectBuilder.class).build(pom, configuration).getProject();
  Assert.assertNotNull(project);
  return project;
}
项目:oceano    文件:DefaultMaven.java   
private void collectProjects( List<MavenProject> projects, List<File> files, MavenExecutionRequest request )
    throws ProjectBuildingException
{
    ProjectBuildingRequest projectBuildingRequest = request.getProjectBuildingRequest();

    List<ProjectBuildingResult> results = projectBuilder.build( files, request.isRecursive(), projectBuildingRequest );

    boolean problems = false;

    for ( ProjectBuildingResult result : results )
    {
        projects.add( result.getProject() );

        if ( !result.getProblems().isEmpty() && logger.isWarnEnabled() )
        {
            logger.warn( "" );
            logger.warn( "Some problems were encountered while building the effective model for "
                + result.getProject().getId() );

            for ( ModelProblem problem : result.getProblems() )
            {
                String location = ModelProblemUtils.formatLocation( problem, result.getProjectId() );
                logger.warn( problem.getMessage() + ( StringUtils.isNotEmpty( location ) ? " @ " + location : "" ) );
            }

            problems = true;
        }
    }

    if ( problems )
    {
        logger.warn( "" );
        logger.warn( "It is highly recommended to fix these problems"
            + " because they threaten the stability of your build." );
        logger.warn( "" );
        logger.warn( "For this reason, future Maven versions might no"
            + " longer support building such malformed projects." );
        logger.warn( "" );
    }
}
项目:oceano    文件:AbstractCoreMavenComponentTestCase.java   
protected MavenSession createMavenSession( File pom, Properties executionProperties )
    throws Exception
{
    MavenExecutionRequest request = createMavenExecutionRequest( pom );

    ProjectBuildingRequest configuration = new DefaultProjectBuildingRequest()
        .setLocalRepository( request.getLocalRepository() )
        .setRemoteRepositories( request.getRemoteRepositories() )
        .setPluginArtifactRepositories( request.getPluginArtifactRepositories() )
        .setSystemProperties( executionProperties );

    MavenProject project = null;

    if ( pom != null )
    {
        project = projectBuilder.build( pom, configuration ).getProject();
    }
    else
    {
        project = createStubMavenProject();
        project.setRemoteArtifactRepositories( request.getRemoteRepositories() );
        project.setPluginArtifactRepositories( request.getPluginArtifactRepositories() );
    }

    initRepoSession( configuration );

    MavenSession session =
        new MavenSession( getContainer(), configuration.getRepositorySession(), request,
                          new DefaultMavenExecutionResult() );
    session.setProjects( Arrays.asList( project ) );

    return session;
}
项目:oceano    文件:AbstractCoreMavenComponentTestCase.java   
protected void initRepoSession( ProjectBuildingRequest request )
{
    File localRepo = new File( request.getLocalRepository().getBasedir() );
    MavenRepositorySystemSession session = new MavenRepositorySystemSession( true );
    session.setLocalRepositoryManager( new SimpleLocalRepositoryManager( localRepo ) );
    request.setRepositorySession( session );
}
项目:oceano    文件:PomConstructionWithSettingsTest.java   
private PomTestWrapper buildPom( String pomPath )
    throws Exception
{
    File pomFile = new File( testDirectory + File.separator + pomPath, "pom.xml" );
    File settingsFile = new File( testDirectory + File.separator + pomPath, "settings.xml" );
    Settings settings = readSettingsFile( settingsFile );

    ProjectBuildingRequest config = new DefaultProjectBuildingRequest();

    for ( org.apache.maven.settings.Profile rawProfile : settings.getProfiles() )
    {
        Profile profile = SettingsUtils.convertFromSettingsProfile( rawProfile );
        config.addProfile( profile );
    }

    String localRepoUrl =
        System.getProperty( "maven.repo.local", System.getProperty( "user.home" ) + "/.m2/repository" );
    localRepoUrl = "file://" + localRepoUrl;
    config.setLocalRepository( repositorySystem.createArtifactRepository( "local", localRepoUrl,
                                                                          new DefaultRepositoryLayout(), null, null ) );
    config.setActiveProfileIds( settings.getActiveProfiles() );
    MavenRepositorySystemSession repoSession = new MavenRepositorySystemSession( true );
    repoSession.setLocalRepositoryManager( new SimpleLocalRepositoryManager(
                                                                             new File(
                                                                                       config.getLocalRepository().getBasedir() ) ) );
    config.setRepositorySession( repoSession );

    return new PomTestWrapper( pomFile, projectBuilder.build( pomFile, config ).getProject() );
}
项目:xapi    文件:ProjectIterable.java   
public ProjectIterable(
    MavenProject project,
    ProjectBuilder builder,
    ProjectBuildingRequest request,
    boolean includeSelf
) {
  root = project;
  final ArrayList<MavenProject> transientList = new ArrayList<>();
  if (includeSelf) {
    transientList.add(project);
  }
  addAllProjects(transientList, project, builder, request);
  projects = ImmutableList.copyOf(transientList);
}
项目:xapi    文件:ProjectIterable.java   
private void addAllProjects(
    final List<MavenProject> projects,
    final MavenProject project,
    final ProjectBuilder builder,
    final ProjectBuildingRequest request
) {

  final List<String> modules = root.getModules();
  File file = project.getFile().getParentFile();
  for (String module : modules) {
    final File moduleFile = new File(
        new File(file, module),
        "pom.xml"
    );
    try {
      final ProjectBuildingResult result = builder.build(
          moduleFile,
          request
      );
      if (!result.getProblems().isEmpty()) {
        X_Log.warn(getClass(), "Problems encountered looking up module ", moduleFile, result.getProblems());
      }
      projects.add(result.getProject());
      if (!result.getProject().getModules().isEmpty()) {
        addAllProjects(projects, result.getProject(), builder, request);
      }
    } catch (ProjectBuildingException e) {
      X_Log.warn(getClass(), "Unable to build module for ", moduleFile);
    }
  }
}
项目:wildfly-maven-plugin    文件:AbstractWildFlyMojoTest.java   
public MavenProject readMavenProject(Path pom)
        throws Exception {
    MavenExecutionRequest request = new DefaultMavenExecutionRequest();
    request.setBaseDirectory(pom.getParent().toFile());
    ProjectBuildingRequest configuration = request.getProjectBuildingRequest();
    configuration.setRepositorySession(new DefaultRepositorySystemSession());
    MavenProject project = rule.lookup(ProjectBuilder.class).build(pom.toFile(), configuration).getProject();
    Assert.assertNotNull(project);
    return project;
}