本文整理汇总了Java中org.apache.maven.project.ProjectBuildingRequest.setRemoteRepositories方法的典型用法代码示例。如果您正苦于以下问题:Java ProjectBuildingRequest.setRemoteRepositories方法的具体用法?Java ProjectBuildingRequest.setRemoteRepositories怎么用?Java ProjectBuildingRequest.setRemoteRepositories使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.apache.maven.project.ProjectBuildingRequest
的用法示例。
在下文中一共展示了ProjectBuildingRequest.setRemoteRepositories方法的9个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: load
import org.apache.maven.project.ProjectBuildingRequest; //导入方法依赖的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;
}
示例2: 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);
}
}
示例3: loadParentOf
import org.apache.maven.project.ProjectBuildingRequest; //导入方法依赖的package包/类
/**
* replacement for MavenProject.getParent() which has bad long term memory behaviour. We offset it by recalculating/reparsing everything
* therefore should not be used lightly!
* pass a MavenProject instance and current configuration and other settings will be applied when loading the parent.
* @param project
* @return null or the parent mavenproject
*/
public MavenProject loadParentOf(MavenEmbedder embedder, MavenProject project) throws ProjectBuildingException {
MavenProject parent = null;
ProjectBuilder builder = embedder.lookupComponent(ProjectBuilder.class);
MavenExecutionRequest req = embedder.createMavenExecutionRequest();
M2Configuration active = configProvider.getActiveConfiguration();
req.addActiveProfiles(active.getActivatedProfiles());
req.setNoSnapshotUpdates(true);
req.setUpdateSnapshots(false);
req.setInteractiveMode(false);
req.setRecursive(false);
req.setOffline(true);
//#238800 important to merge, not replace
Properties uprops = req.getUserProperties();
uprops.putAll(MavenProjectCache.createUserPropsForProjectLoading(active.getProperties()));
req.setUserProperties(uprops);
ProjectBuildingRequest request = req.getProjectBuildingRequest();
request.setRemoteRepositories(project.getRemoteArtifactRepositories());
DefaultMaven maven = (DefaultMaven) embedder.lookupComponent(Maven.class);
request.setRepositorySession(maven.newRepositorySession(req));
if (project.getParentFile() != null) {
parent = builder.build(project.getParentFile(), request).getProject();
} else if (project.getModel().getParent() != null) {
parent = builder.build(project.getParentArtifact(), request).getProject();
}
//clear the project building request, it references multiple Maven Models via the RepositorySession cache
//is not used in maven itself, most likely used by m2e only..
if (parent != null) {
parent.setProjectBuildingRequest(null);
}
MavenEmbedder.normalizePaths(parent);
return parent;
}
示例4: loadMavenProject
import org.apache.maven.project.ProjectBuildingRequest; //导入方法依赖的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;
}
示例5: getRelocation
import org.apache.maven.project.ProjectBuildingRequest; //导入方法依赖的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;
}
示例6: runMavenValidationImpl
import org.apache.maven.project.ProjectBuildingRequest; //导入方法依赖的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;
}
示例7: runMavenValidationImpl
import org.apache.maven.project.ProjectBuildingRequest; //导入方法依赖的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;
}
示例8: execute
import org.apache.maven.project.ProjectBuildingRequest; //导入方法依赖的package包/类
@Override
@SuppressWarnings("PMD.EmptyCatchBlock")
public void execute() throws MojoExecutionException, MojoFailureException {
ArrayNode root = new ArrayNode(JsonNodeFactory.instance);
URLClassLoader classLoader = null;
try {
PluginDescriptor desc = (PluginDescriptor) getPluginContext().get("pluginDescriptor");
List<Artifact> artifacts = desc.getArtifacts();
ProjectBuildingRequest buildingRequest =
new DefaultProjectBuildingRequest(session.getProjectBuildingRequest());
buildingRequest.setRemoteRepositories(remoteRepositories);
for (Artifact artifact : artifacts) {
ArtifactResult result = artifactResolver.resolveArtifact(buildingRequest, artifact);
File jar = result.getArtifact().getFile();
classLoader = createClassLoader(jar);
if (classLoader == null) {
throw new IOException("Can not create classloader for " + jar);
}
ObjectNode entry = new ObjectNode(JsonNodeFactory.instance);
addConnectorMeta(entry, classLoader);
addComponentMeta(entry, classLoader);
if (entry.size() > 0) {
addGav(entry, artifact);
root.add(entry);
}
}
if (root.size() > 0) {
saveCamelMetaData(root);
}
} catch (ArtifactResolverException | IOException e) {
throw new MojoExecutionException(e.getMessage(), e);
} finally {
if (classLoader != null) {
try {
classLoader.close();
} catch (IOException ignored) {
}
}
}
}
示例9: 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);
}
}
}
}