Java Code Examples for org.apache.maven.project.ProjectBuildingRequest#setLocalRepository()
The following examples show how to use
org.apache.maven.project.ProjectBuildingRequest#setLocalRepository() .
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: ExtensionClassLoaderFactory.java From nifi-maven with Apache License 2.0 | 6 votes |
private Set<Artifact> getNarDependencies(final Artifact narArtifact) throws MojoExecutionException, ProjectBuildingException { final ProjectBuildingRequest narRequest = new DefaultProjectBuildingRequest(); narRequest.setRepositorySession(repoSession); narRequest.setSystemProperties(System.getProperties()); narRequest.setLocalRepository(localRepo); final ProjectBuildingResult narResult = projectBuilder.build(narArtifact, narRequest); final Set<Artifact> narDependencies = new TreeSet<>(); gatherArtifacts(narResult.getProject(), narDependencies); narDependencies.remove(narArtifact); narDependencies.remove(project.getArtifact()); getLog().debug("Found NAR dependency of " + narArtifact + ", which resolved to the following artifacts: " + narDependencies); return narDependencies; }
Example 2
Source File: EffectivePomMD.java From netbeans with Apache License 2.0 | 5 votes |
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; }
Example 3
Source File: MavenEmbedder.java From netbeans with Apache License 2.0 | 5 votes |
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; }
Example 4
Source File: StatusProvider.java From netbeans with Apache License 2.0 | 5 votes |
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; }
Example 5
Source File: MavenUtils.java From mvn-golang with Apache License 2.0 | 5 votes |
/** * Make resolve artifact project building request. * * @param session maven session, must not be null * @param remoteRepositories list of remote repositories, must not be null and * can't contain null * @return created request, must not be null */ @Nonnull public static ProjectBuildingRequest makeResolveArtifactProjectBuildingRequest( @Nonnull final MavenSession session, @Nonnull @MustNotContainNull final List<ArtifactRepository> remoteRepositories ) { final ProjectBuildingRequest result = new DefaultProjectBuildingRequest(session.getProjectBuildingRequest()); result.setRemoteRepositories(remoteRepositories); result.setLocalRepository(session.getLocalRepository()); return result; }
Example 6
Source File: ExtensionClassLoaderFactory.java From nifi-maven with Apache License 2.0 | 5 votes |
private String findProvidedDependencyVersion(final Set<Artifact> artifacts, final String groupId, final String artifactId) { final ProjectBuildingRequest projectRequest = new DefaultProjectBuildingRequest(); projectRequest.setRepositorySession(repoSession); projectRequest.setSystemProperties(System.getProperties()); projectRequest.setLocalRepository(localRepo); for (final Artifact artifact : artifacts) { final Set<Artifact> artifactDependencies = new HashSet<>(); try { final ProjectBuildingResult projectResult = projectBuilder.build(artifact, projectRequest); gatherArtifacts(projectResult.getProject(), artifactDependencies); getLog().debug("For Artifact " + artifact + ", found the following dependencies:"); artifactDependencies.forEach(dep -> getLog().debug(dep.toString())); for (final Artifact dependency : artifactDependencies) { if (dependency.getGroupId().equals(groupId) && dependency.getArtifactId().equals(artifactId)) { getLog().debug("Found version of " + groupId + ":" + artifactId + " to be " + artifact.getVersion()); return artifact.getVersion(); } } } catch (final Exception e) { getLog().warn("Unable to construct Maven Project for " + artifact + " when attempting to determine the expected version of NiFi API"); getLog().debug("Unable to construct Maven Project for " + artifact + " when attempting to determine the expected version of NiFi API", e); } } return null; }