当前位置: 首页>>代码示例>>Java>>正文


Java ProjectBuildingRequest类代码示例

本文整理汇总了Java中org.apache.maven.project.ProjectBuildingRequest的典型用法代码示例。如果您正苦于以下问题:Java ProjectBuildingRequest类的具体用法?Java ProjectBuildingRequest怎么用?Java ProjectBuildingRequest使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。


ProjectBuildingRequest类属于org.apache.maven.project包,在下文中一共展示了ProjectBuildingRequest类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: asArtifact

import org.apache.maven.project.ProjectBuildingRequest; //导入依赖的package包/类
@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();
	
}
 
开发者ID:commsen,项目名称:EM,代码行数:19,代码来源:Dependencies.java

示例2: readProjectWithDependencies

import org.apache.maven.project.ProjectBuildingRequest; //导入依赖的package包/类
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;
}
 
开发者ID:apache,项目名称:incubator-netbeans,代码行数:23,代码来源:MavenEmbedder.java

示例3: load

import org.apache.maven.project.ProjectBuildingRequest; //导入依赖的package包/类
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;
}
 
开发者ID:apache,项目名称:incubator-netbeans,代码行数:23,代码来源:ArtifactDependencyIndexCreator.java

示例4: buildProjects

import org.apache.maven.project.ProjectBuildingRequest; //导入依赖的package包/类
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);
    }
}
 
开发者ID:wildfly-swarm,项目名称:wildfly-swarm-fraction-plugin,代码行数:20,代码来源:AbstractFractionsMojo.java

示例5: lookupConfiguredMojo

import org.apache.maven.project.ProjectBuildingRequest; //导入依赖的package包/类
/**
 * 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;
}
 
开发者ID:andi12,项目名称:msbuild-maven-plugin,代码行数:33,代码来源:AbstractMSBuildMojoTestCase.java

示例6: resolveDependenciesFromPOM

import org.apache.maven.project.ProjectBuildingRequest; //导入依赖的package包/类
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;
}
 
开发者ID:forge,项目名称:furnace,代码行数:19,代码来源:ProjectHelper.java

示例7: resolve

import org.apache.maven.project.ProjectBuildingRequest; //导入依赖的package包/类
@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();
}
 
开发者ID:wildfly,项目名称:wildfly-maven-plugin,代码行数:19,代码来源:EclipseAetherArtifactResolver.java

示例8: testSomething

import org.apache.maven.project.ProjectBuildingRequest; //导入依赖的package包/类
/**
 * @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());
}
 
开发者ID:avityuk,项目名称:ginger,代码行数:26,代码来源:MavenGeneratorTest.java

示例9: prepareDependencies

import org.apache.maven.project.ProjectBuildingRequest; //导入依赖的package包/类
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;

	}
 
开发者ID:commsen,项目名称:EM,代码行数:32,代码来源:ExportMojo.java

示例10: managedAsArtifacts

import org.apache.maven.project.ProjectBuildingRequest; //导入依赖的package包/类
public Set<Artifact> managedAsArtifacts(ProjectBuildingRequest projectBuildingRequest, MavenProject project) throws MavenExecutionException {
	if (project.getDependencyManagement() != null) {
		return asArtifacts(projectBuildingRequest, project.getDependencyManagement().getDependencies());
	} else {
		return Collections.emptySet();
	}
}
 
开发者ID:commsen,项目名称:EM,代码行数:8,代码来源:Dependencies.java

示例11: loadParentOf

import org.apache.maven.project.ProjectBuildingRequest; //导入依赖的package包/类
/**
 * 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;
}
 
开发者ID:apache,项目名称:incubator-netbeans,代码行数:45,代码来源:NbMavenProjectImpl.java

示例12: loadMavenProject

import org.apache.maven.project.ProjectBuildingRequest; //导入依赖的package包/类
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;
    }
 
开发者ID:apache,项目名称:incubator-netbeans,代码行数:28,代码来源:RepositoryMavenCPProvider.java

示例13: getRelocation

import org.apache.maven.project.ProjectBuildingRequest; //导入依赖的package包/类
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;
}
 
开发者ID:apache,项目名称:incubator-netbeans,代码行数:28,代码来源:DependencyNode.java

示例14: runMavenValidationImpl

import org.apache.maven.project.ProjectBuildingRequest; //导入依赖的package包/类
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;
}
 
开发者ID:apache,项目名称:incubator-netbeans,代码行数:31,代码来源:EffectivePomMD.java

示例15: buildProject

import org.apache.maven.project.ProjectBuildingRequest; //导入依赖的package包/类
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;
}
 
开发者ID:apache,项目名称:incubator-netbeans,代码行数:12,代码来源:MavenEmbedder.java


注:本文中的org.apache.maven.project.ProjectBuildingRequest类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。