本文整理汇总了Java中org.apache.maven.project.ProjectBuildingResult类的典型用法代码示例。如果您正苦于以下问题:Java ProjectBuildingResult类的具体用法?Java ProjectBuildingResult怎么用?Java ProjectBuildingResult使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
ProjectBuildingResult类属于org.apache.maven.project包,在下文中一共展示了ProjectBuildingResult类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: readProjectWithDependencies
import org.apache.maven.project.ProjectBuildingResult; //导入依赖的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;
}
示例2: load
import org.apache.maven.project.ProjectBuildingResult; //导入依赖的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;
}
示例3: buildProjects
import org.apache.maven.project.ProjectBuildingResult; //导入依赖的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);
}
}
示例4: resolveDependenciesFromPOM
import org.apache.maven.project.ProjectBuildingResult; //导入依赖的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;
}
示例5: handle
import org.apache.maven.project.ProjectBuildingResult; //导入依赖的package包/类
private ExceptionSummary handle( ProjectBuildingResult result )
{
List<ExceptionSummary> children = new ArrayList<ExceptionSummary>();
for ( ModelProblem problem : result.getProblems() )
{
ExceptionSummary child = handle( problem, result.getProjectId() );
if ( child != null )
{
children.add( child );
}
}
if ( children.isEmpty() )
{
return null;
}
String message =
"\nThe project " + result.getProjectId() + " (" + result.getPomFile() + ") has "
+ children.size() + " error" + ( children.size() == 1 ? "" : "s" );
return new ExceptionSummary( null, message, null, children );
}
示例6: loadMavenProject
import org.apache.maven.project.ProjectBuildingResult; //导入依赖的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;
}
示例7: getRelocation
import org.apache.maven.project.ProjectBuildingResult; //导入依赖的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;
}
示例8: runMavenValidationImpl
import org.apache.maven.project.ProjectBuildingResult; //导入依赖的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;
}
示例9: buildProject
import org.apache.maven.project.ProjectBuildingResult; //导入依赖的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;
}
示例10: setResult
import org.apache.maven.project.ProjectBuildingResult; //导入依赖的package包/类
private void setResult(ProjectBuildingResult pbr, Map<File, MavenExecutionResult> results) {
DefaultMavenExecutionResult r = new DefaultMavenExecutionResult();
normalizePaths(pbr.getProject());
r.setProject(pbr.getProject());
r.setDependencyResolutionResult(pbr.getDependencyResolutionResult());
results.put(pbr.getPomFile(), r);
}
示例11: runMavenValidationImpl
import org.apache.maven.project.ProjectBuildingResult; //导入依赖的package包/类
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;
}
示例12: readModel
import org.apache.maven.project.ProjectBuildingResult; //导入依赖的package包/类
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);
}
}
示例13: prepareProjects
import org.apache.maven.project.ProjectBuildingResult; //导入依赖的package包/类
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;
}
示例14: loadProject
import org.apache.maven.project.ProjectBuildingResult; //导入依赖的package包/类
protected MavenProject loadProject(org.apache.maven.artifact.Artifact mda) {
// older code creates a new PBReq but it lacks user props; this seems to work better
String projectId = Coords.of(mda).normal();
MavenProject p = projectByIdCache.get(projectId);
if (p!=null) return p;
try {
getLog().debug("Loading project for "+mda);
ProjectBuildingResult res = projectBuilder.build(mda, true, mavenSession.getProjectBuildingRequest());
p = res.getProject();
} catch (ProjectBuildingException e) {
if (e.getResults().size()==1) {
getLog().warn("Error loading maven project/model for "+mda+" (but got a result so ignoring): "+e);
p = e.getResults().get(0).getProject();
} else {
getLog().error("Errors loading maven project/model for "+mda+": "+e);
addError(projectId, e);
return null;
}
}
if (p==null) {
addError(projectId, "Failure with no data when trying to load project");
return null;
}
projectByIdCache.put(projectId, p);
return p;
}
示例15: testSensibleSession
import org.apache.maven.project.ProjectBuildingResult; //导入依赖的package包/类
public void testSensibleSession(MavenSession s) throws Exception {
MavenSession ms = newMavenSession(); //((LicenseAuditMojo)mojo).mavenSession;
assertNotNull( ms );
assertNotNull( ms.getLocalRepository().getBasedir() );
System.out.println("Basedir: "+ms.getLocalRepository().getBasedir());
// The following artifacts could not be resolved: org.apache.maven:maven-core:jar:2.0.7
RepositorySystem rs = lookup(RepositorySystem.class);
assertNotNull( rs );
// check we can access stuff in remote repos
// (fails if we don't have proper aether connectors + transforms,
// or if we've not "populated" with default remote repos)
ArtifactResult art;
art = resolveArtifact(rs, ms, "org.apache.maven:maven-core:jar:2.0.7");
System.out.println(art);
assertNotNull(art.getArtifact());
// check we avoid this:
// [ERROR] Failed to determine Java version for profile java-1.5-detected @ org.apache.commons:commons-parent:22, /Users/alex/.m2/repository/org/apache/commons/commons-parent/22/commons-parent-22.pom, line 909, column 14
art = resolveArtifact(rs, ms, "org.apache.commons:commons-lang3:3.1");
System.out.println(art);
assertNotNull(art.getArtifact());
ProjectBuilder projectBuilder = lookup(ProjectBuilder.class);
ProjectBuildingResult res = projectBuilder.build(RepositoryUtils.toArtifact(art.getArtifact()), true, ms.getProjectBuildingRequest());
System.out.println(res);
if (!res.getProblems().isEmpty()) fail("Problems: "+res.getProblems());
}