本文整理汇总了Java中org.apache.maven.project.ProjectBuildingRequest.setSystemProperties方法的典型用法代码示例。如果您正苦于以下问题:Java ProjectBuildingRequest.setSystemProperties方法的具体用法?Java ProjectBuildingRequest.setSystemProperties怎么用?Java ProjectBuildingRequest.setSystemProperties使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.apache.maven.project.ProjectBuildingRequest
的用法示例。
在下文中一共展示了ProjectBuildingRequest.setSystemProperties方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: 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);
}
}
示例2: addGav
import org.apache.maven.project.ProjectBuildingRequest; //导入方法依赖的package包/类
/**
* Find the SCM URL for the given {@code g, a, v} triple and store the association for the later retrieval via
* {@link #createSortedScmRepositoryMap()}.
*
* @param g
* {@code groupId}
* @param a
* {@code artifactId}
* @param v
* {@code version}
* @param failOnUnresolvable
* see {@link SrcdepsInitMojo#failOnUnresolvable}
* @throws MojoExecutionException
*/
public void addGav(String g, String a, String v, boolean failOnUnresolvable) throws MojoExecutionException {
final Gav gav = new Gav(g, a, v);
if (!seenGavs.contains(gav)) {
seenGavs.add(gav);
final Ga ga = new Ga(g, a);
log.debug("Adding GA: {}", ga);
ProjectBuildingRequest projectBuildingRequest = new DefaultProjectBuildingRequest();
projectBuildingRequest.setLocalRepository(session.getLocalRepository());
projectBuildingRequest
.setRemoteRepositories(session.getProjectBuildingRequest().getRemoteRepositories());
projectBuildingRequest.setValidationLevel(ModelBuildingRequest.VALIDATION_LEVEL_MINIMAL);
projectBuildingRequest.setProcessPlugins(false);
projectBuildingRequest.setRepositoryMerging(ProjectBuildingRequest.RepositoryMerging.REQUEST_DOMINANT);
projectBuildingRequest.setSystemProperties(session.getSystemProperties());
projectBuildingRequest.setRepositorySession(repoSession);
Artifact pomArtifact = repositorySystem.createProjectArtifact(g, a, v, "compile");
try {
ProjectBuildingResult result = projectBuilder.build(pomArtifact, projectBuildingRequest);
MavenProject dependencyProject = result.getProject();
ScmUrlAncestry ancestry = ScmUrlAncestry.of(dependencyProject);
if (!ancestry.hasUrl()) {
log.warn("No SCM connection for artifact [{}]", ga);
} else {
final String url = ancestry.getUrl();
if (unsupportedUrls.contains(url)) {
/* was reported once already */
} else if (isScmUrlSupported(url)) {
log.debug("Found SCM URL [{}] for GA [{}]", url, ga);
int len = ancestry.getLength();
for (int i = 0; i < len; i++) {
this.add(url, ancestry.getGaAt(i));
}
Set<Ga> rootGas = urlRootGasMap.get(url);
if (rootGas == null) {
rootGas = new TreeSet<>();
urlRootGasMap.put(url, rootGas);
}
rootGas.add(ancestry.getRootGa());
} else {
log.warn("Unsupported SCM URL [{}] for GAV [{}]", url, ga);
unsupportedUrls.add(url);
}
}
} catch (ProjectBuildingException e) {
final String msg = String.format("Could not resolve [%s] using remote repositories [%s]",
pomArtifact, remoteRepos);
if (failOnUnresolvable) {
throw new MojoExecutionException(msg, e);
} else {
log.warn(msg);
}
}
}
}
示例3: execute
import org.apache.maven.project.ProjectBuildingRequest; //导入方法依赖的package包/类
@Override
public void execute() throws MojoExecutionException, MojoFailureException {
try {
// find the nar dependency
Artifact narArtifact = null;
for (final Artifact artifact : project.getDependencyArtifacts()) {
if (NAR.equals(artifact.getType())) {
// ensure the project doesn't have two nar dependencies
if (narArtifact != null) {
throw new MojoExecutionException("Project can only have one NAR dependency.");
}
// record the nar dependency
narArtifact = artifact;
}
}
// ensure there is a nar dependency
if (narArtifact == null) {
throw new MojoExecutionException("Project does not have any NAR dependencies.");
}
// build the project for the nar artifact
final ProjectBuildingRequest narRequest = new DefaultProjectBuildingRequest();
narRequest.setRepositorySession(repoSession);
narRequest.setSystemProperties(System.getProperties());
final ProjectBuildingResult narResult = projectBuilder.build(narArtifact, narRequest);
// get the artifact handler for excluding dependencies
final ArtifactHandler narHandler = excludesDependencies(narArtifact);
narArtifact.setArtifactHandler(narHandler);
// nar artifacts by nature includes dependencies, however this prevents the
// transitive dependencies from printing using tools like dependency:tree.
// here we are overriding the artifact handler for all nars so the
// dependencies can be listed. this is important because nar dependencies
// will be used as the parent classloader for this nar and seeing what
// dependencies are provided is critical.
final Map<String, ArtifactHandler> narHandlerMap = new HashMap<>();
narHandlerMap.put(NAR, narHandler);
artifactHandlerManager.addHandlers(narHandlerMap);
// get the dependency tree
final DependencyNode root = dependencyTreeBuilder.buildDependencyTree(narResult.getProject(), localRepository, null);
// write the appropriate output
DependencyNodeVisitor visitor = null;
if ("tree".equals(mode)) {
visitor = new TreeWriter();
} else if ("pom".equals(mode)) {
visitor = new PomWriter();
}
// ensure the mode was specified correctly
if (visitor == null) {
throw new MojoExecutionException("The specified mode is invalid. Supported options are 'tree' and 'pom'.");
}
// visit and print the results
root.accept(visitor);
getLog().info("--- Provided NAR Dependencies ---\n\n" + visitor.toString());
} catch (DependencyTreeBuilderException | ProjectBuildingException e) {
throw new MojoExecutionException("Cannot build project dependency tree", e);
}
}