本文整理汇总了Java中org.apache.maven.project.ProjectBuildingRequest.setValidationLevel方法的典型用法代码示例。如果您正苦于以下问题:Java ProjectBuildingRequest.setValidationLevel方法的具体用法?Java ProjectBuildingRequest.setValidationLevel怎么用?Java ProjectBuildingRequest.setValidationLevel使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.apache.maven.project.ProjectBuildingRequest
的用法示例。
在下文中一共展示了ProjectBuildingRequest.setValidationLevel方法的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: readProjectWithDependencies
import org.apache.maven.project.ProjectBuildingRequest; //导入方法依赖的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;
}
示例2: 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;
}
示例3: 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;
}
示例4: 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;
}
示例5: 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;
}
示例6: 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;
}
示例7: 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);
}
}
}
}