Java Code Examples for org.apache.maven.project.ProjectBuildingResult#getProject()
The following examples show how to use
org.apache.maven.project.ProjectBuildingResult#getProject() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: SpringBootStarterMojo.java From camel-spring-boot with Apache License 2.0 | 6 votes |
private Set<String> filterIncludedArtifacts(Set<String> artifacts) { Set<Artifact> dependencies; try { Artifact artifact = project.getArtifactMap().get(getMainDepGroupId() + ":" + getMainDepArtifactId()); ProjectBuildingResult result = projectBuilder.build(artifact, project.getProjectBuildingRequest()); MavenProject prj = result.getProject(); prj.setRemoteArtifactRepositories(project.getRemoteArtifactRepositories()); dependencies = projectDependenciesResolver.resolve(prj, Collections.singleton(Artifact.SCOPE_COMPILE), session); } catch (Exception e) { throw new RuntimeException("Unable to build project dependency tree", e); } Set<String> included = new TreeSet<>(); dependencies.stream() .filter(a -> !Artifact.SCOPE_TEST.equals(a.getScope())) .map(a -> a.getGroupId() + ":" + a.getArtifactId()) .forEach(included::add); included.retainAll(artifacts); return included; }
Example 2
Source File: ArtifactDependencyIndexCreator.java From netbeans with Apache License 2.0 | 6 votes |
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; }
Example 3
Source File: RepositoryUtility.java From cloud-opensource-java with Apache License 2.0 | 5 votes |
static MavenProject createMavenProject(Path pomFile, RepositorySystemSession session) throws MavenRepositoryException { // MavenCli's way to instantiate PlexusContainer ClassWorld classWorld = new ClassWorld("plexus.core", Thread.currentThread().getContextClassLoader()); ContainerConfiguration containerConfiguration = new DefaultContainerConfiguration() .setClassWorld(classWorld) .setRealm(classWorld.getClassRealm("plexus.core")) .setClassPathScanning(PlexusConstants.SCANNING_INDEX) .setAutoWiring(true) .setJSR250Lifecycle(true) .setName("linkage-checker"); try { PlexusContainer container = new DefaultPlexusContainer(containerConfiguration); MavenExecutionRequest mavenExecutionRequest = new DefaultMavenExecutionRequest(); ProjectBuildingRequest projectBuildingRequest = mavenExecutionRequest.getProjectBuildingRequest(); projectBuildingRequest.setRepositorySession(session); // Profile activation needs properties such as JDK version Properties properties = new Properties(); // allowing duplicate entries properties.putAll(projectBuildingRequest.getSystemProperties()); properties.putAll(OsProperties.detectOsProperties()); properties.putAll(System.getProperties()); projectBuildingRequest.setSystemProperties(properties); ProjectBuilder projectBuilder = container.lookup(ProjectBuilder.class); ProjectBuildingResult projectBuildingResult = projectBuilder.build(pomFile.toFile(), projectBuildingRequest); return projectBuildingResult.getProject(); } catch (PlexusContainerException | ComponentLookupException | ProjectBuildingException ex) { throw new MavenRepositoryException(ex); } }
Example 4
Source File: RepositoryMavenCPProvider.java From netbeans with Apache License 2.0 | 5 votes |
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; }
Example 5
Source File: RootLocationMojo.java From build-helper-maven-plugin with MIT License | 5 votes |
/** * Finds the local root of the specified project. * * @param project The project to find the local root for. * @return The local root project (this may be the current project) */ private MavenProject getLocalRoot( final MavenProject project ) throws IOException { MavenProject currentProject = project; MavenProject localRootProject = project; List<File> parentDirs = new ArrayList<>(); getAllParentDirectories( project.getBasedir(), parentDirs ); for (File parentDir : parentDirs) { getLog().debug( "Checking to see if " + parentDir + " is an aggregator parent" ); File parent = new File( parentDir, "pom.xml" ); if ( parent.isFile() ) { try { final ProjectBuildingResult result = projectBuilder.build( parent, session.getProjectBuildingRequest() ); final MavenProject parentProject = result.getProject(); final String currentProjectCanonicalPath = currentProject.getBasedir().getCanonicalPath(); if ( getAllChildModules( parentProject ).contains( currentProjectCanonicalPath ) ) { getLog().debug( parentDir + " is an aggregator parent of current project " ); localRootProject = parentProject; currentProject = parentProject; } else { getLog().debug( parentDir + " is not an aggregator parent of current project ("+getAllChildModules( parentProject )+"/"+currentProjectCanonicalPath+") " ); } } catch ( ProjectBuildingException e ) { getLog().warn( e ); } } } getLog().debug( "Local aggregation root is " + localRootProject.getBasedir() ); return localRootProject; }
Example 6
Source File: AbstractGitFlowMojo.java From gitflow-maven-plugin with Apache License 2.0 | 5 votes |
/** * Reloads project info from file * * @param project * @return * @throws MojoFailureException */ private MavenProject reloadProject(MavenProject project) throws MojoFailureException { try { ProjectBuildingResult result = projectBuilder.build(project.getFile(), mavenSession.getProjectBuildingRequest()); return result.getProject(); } catch (Exception e) { throw new MojoFailureException("Error re-loading project info", e); } }