本文整理汇总了Java中org.apache.maven.project.ProjectBuildingException类的典型用法代码示例。如果您正苦于以下问题:Java ProjectBuildingException类的具体用法?Java ProjectBuildingException怎么用?Java ProjectBuildingException使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
ProjectBuildingException类属于org.apache.maven.project包,在下文中一共展示了ProjectBuildingException类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: readMavenProject
import org.apache.maven.project.ProjectBuildingException; //导入依赖的package包/类
private static MavenProject readMavenProject(MavenEmbedder embedder, Artifact artifact, List<ArtifactRepository> remoteRepos) throws ProjectBuildingException {
ProjectBuilder bldr = embedder.lookupComponent(ProjectBuilder.class);
assert bldr !=null : "ProjectBuilder component not found in maven";
DefaultMaven maven = (DefaultMaven) embedder.lookupComponent(Maven.class);
assert bldr !=null : "DefaultMaven component not found in maven";
MavenExecutionRequest req = embedder.createMavenExecutionRequest();
req.setLocalRepository(embedder.getLocalRepository());
req.setRemoteRepositories(remoteRepos);
ProjectBuildingRequest configuration = req.getProjectBuildingRequest();
configuration.setValidationLevel(ModelBuildingRequest.VALIDATION_LEVEL_MINIMAL);
configuration.setResolveDependencies(true);
configuration.setRepositorySession(maven.newRepositorySession(req));
ProjectBuildingResult projectBuildingResult = bldr.build(artifact, configuration);
return projectBuildingResult.getProject();
}
示例2: getParents
import org.apache.maven.project.ProjectBuildingException; //导入依赖的package包/类
protected List<File> getParents() {
LinkedList<File> ret = new LinkedList<>();
MavenProject project = getOriginalMavenProject();
while(true) {
try {
MavenProject parent = loadParentOf(getEmbedder(), project);
File parentFile = parent != null ? parent.getFile() : null;
if(parentFile != null) {
ret.add(parentFile);
project = parent;
} else {
break;
}
} catch (ProjectBuildingException ex) {
break;
}
}
return ret;
}
示例3: readProjectWithDependencies
import org.apache.maven.project.ProjectBuildingException; //导入依赖的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;
}
示例4: load
import org.apache.maven.project.ProjectBuildingException; //导入依赖的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;
}
示例5: warProjects
import org.apache.maven.project.ProjectBuildingException; //导入依赖的package包/类
private void warProjects(FileNode pomXml, Properties userProperties, List<String> profiles,
List<MavenProject> result) throws IOException {
MavenProject root;
FileNode modulePom;
try {
root = maven().loadPom(pomXml, false, userProperties, profiles, null);
} catch (ProjectBuildingException | RepositoryException e) {
throw new IOException("cannot parse " + pomXml + ": " + e.getMessage(), e);
}
session.console.verbose.println("loading " + pomXml);
if ("war".equals(root.getPackaging())) {
result.add(root);
} else {
for (String module : root.getModules()) {
modulePom = session.world.file(root.getBasedir()).join(module);
if (modulePom.isDirectory()) {
modulePom = modulePom.join("pom.xml");
}
warProjects(modulePom, userProperties, profiles, result);
}
}
}
示例6: getMavenProjectFromRepository
import org.apache.maven.project.ProjectBuildingException; //导入依赖的package包/类
/**
* Get the <code>Maven project</code> from the repository depending
* the <code>Artifact</code> given.
*
* @param artifact an artifact
* @return the Maven project for the given artifact
* @throws org.apache.maven.project.ProjectBuildingException
* if any
*/
private MavenProject getMavenProjectFromRepository( Artifact artifact, ArtifactRepository localRepository )
throws ProjectBuildingException
{
Artifact projectArtifact = artifact;
boolean allowStubModel = false;
if ( !"pom".equals( artifact.getType() ) )
{
projectArtifact = factory.createProjectArtifact( artifact.getGroupId(), artifact.getArtifactId(),
artifact.getVersion(), artifact.getScope() );
allowStubModel = true;
}
// TODO: we should use the MavenMetadataSource instead
return mavenProjectBuilder.buildFromRepository( projectArtifact, project.getRemoteArtifactRepositories(),
localRepository, allowStubModel );
}
示例7: createManagedVersionMap
import org.apache.maven.project.ProjectBuildingException; //导入依赖的package包/类
/**
*
* @param projectId
* @param dependencyManagement
* @return
* @throws ProjectBuildingException
*/
private Map createManagedVersionMap(String projectId, DependencyManagement dependencyManagement) throws ProjectBuildingException {
Map map;
if (dependencyManagement != null && dependencyManagement.getDependencies() != null) {
map = new HashMap();
for (Dependency d : dependencyManagement.getDependencies()) {
try {
VersionRange versionRange = VersionRange.createFromVersionSpec(d.getVersion());
Artifact artifact = factory.createDependencyArtifact(d.getGroupId(), d.getArtifactId(),
versionRange, d.getType(), d.getClassifier(),
d.getScope());
map.put(d.getManagementKey(), artifact);
} catch (InvalidVersionSpecificationException e) {
throw new ProjectBuildingException(projectId, "Unable to parse version '" + d.getVersion()
+ "' for dependency '" + d.getManagementKey() + "': " + e.getMessage(), e);
}
}
} else {
map = Collections.EMPTY_MAP;
}
return map;
}
示例8: getTransitiveDependencies
import org.apache.maven.project.ProjectBuildingException; //导入依赖的package包/类
protected List getTransitiveDependencies( final Set previousArtifacts )
throws ProjectBuildingException, InvalidDependencyVersionException, ArtifactResolutionException,
ArtifactNotFoundException
{
final List dependencies = new ArrayList();
for ( Iterator iter = previousArtifacts.iterator(); iter.hasNext(); )
{
final Artifact a = (Artifact) iter.next();
final Artifact pomArtifact =
factory.createArtifact( a.getGroupId(), a.getArtifactId(), a.getVersion(), a.getScope(), "pom" );
final MavenProject pomProject =
mavenProjectBuilder.buildFromRepository( pomArtifact, project.getRemoteArtifactRepositories(),
localRepository );
final Set pomProjectArtifacts = pomProject.createArtifacts( factory, null, null );
final ArtifactResolutionResult result =
resolver.resolveTransitively( pomProjectArtifacts, pomArtifact, localRepository,
project.getRemoteArtifactRepositories(), metadataSource, null );
dependencies.addAll( result.getArtifacts() );
}
return dependencies;
}
示例9: buildProjects
import org.apache.maven.project.ProjectBuildingException; //导入依赖的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);
}
}
示例10: resolveFromPom
import org.apache.maven.project.ProjectBuildingException; //导入依赖的package包/类
/**
* Construct a PomModel from a pom.xml file
* @param pomStream InputStream to the pom.xml file
* @return a populated PomModel or throws exception if the file could not be parsed or deployed
*/
public static PomModel resolveFromPom(InputStream pomStream) throws Exception {
try {
return PomModel.Parser.parse("pom.xml",
pomStream);
} catch (final Exception e) {
if (e.getCause() != null) {
if (e.getCause() instanceof ProjectBuildingException) {
throw (ProjectBuildingException) e.getCause();
}
if (e.getCause() instanceof MavenEmbedderException) {
throw (MavenEmbedderException) e.getCause();
}
}
log.info("Failed to process pom.xml for GAV information.",
e);
throw e;
}
}
示例11: getProjectsForMavenReactor
import org.apache.maven.project.ProjectBuildingException; //导入依赖的package包/类
private List<MavenProject> getProjectsForMavenReactor( MavenSession session )
throws ProjectBuildingException
{
MavenExecutionRequest request = session.getRequest();
request.getProjectBuildingRequest().setRepositorySession( session.getRepositorySession() );
List<MavenProject> projects = new ArrayList<MavenProject>();
// We have no POM file.
//
if ( request.getPom() == null )
{
ModelSource modelSource = new UrlModelSource( DefaultMaven.class.getResource( "project/standalone.xml" ) );
MavenProject project =
projectBuilder.build( modelSource, request.getProjectBuildingRequest() ).getProject();
project.setExecutionRoot( true );
projects.add( project );
request.setProjectPresent( false );
return projects;
}
List<File> files = Arrays.asList( request.getPom().getAbsoluteFile() );
collectProjects( projects, files, request );
return projects;
}
示例12: findEffectiveReactor
import org.apache.maven.project.ProjectBuildingException; //导入依赖的package包/类
/**
* Manually constructs an list of effective reactor projects by recursively
* searching parent and submodule projects. This allows the intention of the
* reactor to be preserved, as long as it is fully available on disk, even
* when building a submodule directly.
*
* @param defaultReactor Return value to use if a comprehensive list can not
* be discovered.
* @param baseProject {@link MavenProject} where invocation started.
* @return A list of MavenProjects that can be treated as though within the
* current reactor.
* @throws ProjectBuildingException
*/
public static List<MavenProject> findEffectiveReactor(
final List<MavenProject> defaultReactor, final MavenSession session,
final MavenProject baseProject, final MavenProjectBuilder projectBuilder,
final ArtifactRepository localRepository) throws ProjectBuildingException
{
final Set<MavenProject> reactor = new HashSet<MavenProject>();
final Set<MavenProject> visited = new HashSet<MavenProject>();
final ProfileManager profileManager = getProfileManager(session);
findEffectiveReactor(reactor, visited, baseProject, baseProject,
projectBuilder, localRepository, profileManager);
if (reactor.size() <= 1 || !reactor.contains(baseProject)) return defaultReactor;
return new ArrayList<MavenProject>(reactor);
}
示例13: execute
import org.apache.maven.project.ProjectBuildingException; //导入依赖的package包/类
@Override
public void execute() throws MojoExecutionException, MojoFailureException {
// Find the plugin in the project dependencies
final List<DependencyNode> projectChildren = resolveDependencies(getProject(), new FlumePluginDependencyArtifactFilter(dependency));
if (projectChildren.isEmpty()) {
throw new MojoFailureException(String.format("No dependency found matching %s in dependency list.", dependency.getFormattedIdentifier()));
} else if (projectChildren.size() > 1) {
throw new MojoFailureException(String.format("More than one dependency matching %s found in project dependencies: %s", dependency.getFormattedIdentifier(), projectChildren));
}
// Resolve the dependencies of the project we've located
final Artifact projectChildArtifact = projectChildren.get(0).getArtifact();
final File projectChildFile = getArtifactRepository().find(projectChildArtifact).getFile();
try {
buildFlumePluginArchive(projectChildFile, projectBuilder.buildFromRepository(projectChildArtifact, getRemoteArtifactRepositories(), getArtifactRepository()));
} catch (ProjectBuildingException e) {
throw new MojoExecutionException(String.format("Failed to resolve project for artifact %s", formatIdentifier(projectChildArtifact)), e);
}
}
示例14: hasMissingParentPom
import org.apache.maven.project.ProjectBuildingException; //导入依赖的package包/类
private ModelProblem hasMissingParentPom( ProjectBuildingException e )
{
if ( e.getCause() instanceof ModelBuildingException )
{
ModelBuildingException mbe = (ModelBuildingException) e.getCause();
for ( ModelProblem problem : mbe.getProblems() )
{
if ( problem.getException() instanceof UnresolvableModelException )
{
return problem;
}
}
}
return null;
}
示例15: getProjectsForMavenReactor
import org.apache.maven.project.ProjectBuildingException; //导入依赖的package包/类
private List<MavenProject> getProjectsForMavenReactor( MavenExecutionRequest request )
throws ProjectBuildingException
{
List<MavenProject> projects = new ArrayList<MavenProject>();
// We have no POM file.
//
if ( request.getPom() == null )
{
ModelSource modelSource = new UrlModelSource( DefaultMaven.class.getResource( "project/standalone.xml" ) );
MavenProject project =
projectBuilder.build( modelSource, request.getProjectBuildingRequest() ).getProject();
project.setExecutionRoot( true );
projects.add( project );
request.setProjectPresent( false );
return projects;
}
List<File> files = Arrays.asList( request.getPom().getAbsoluteFile() );
collectProjects( projects, files, request );
return projects;
}