本文整理汇总了Java中org.apache.maven.project.ProjectBuildingRequest.setLocalRepository方法的典型用法代码示例。如果您正苦于以下问题:Java ProjectBuildingRequest.setLocalRepository方法的具体用法?Java ProjectBuildingRequest.setLocalRepository怎么用?Java ProjectBuildingRequest.setLocalRepository使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.apache.maven.project.ProjectBuildingRequest
的用法示例。
在下文中一共展示了ProjectBuildingRequest.setLocalRepository方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: 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;
}
示例2: buildProject
import org.apache.maven.project.ProjectBuildingRequest; //导入方法依赖的package包/类
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;
}
示例3: 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;
}
示例4: buildPom
import org.apache.maven.project.ProjectBuildingRequest; //导入方法依赖的package包/类
private PomTestWrapper buildPom( String pomPath )
throws Exception
{
File pomFile = new File( testDirectory + File.separator + pomPath, "pom.xml" );
File settingsFile = new File( testDirectory + File.separator + pomPath, "settings.xml" );
Settings settings = readSettingsFile( settingsFile );
ProjectBuildingRequest config = new DefaultProjectBuildingRequest();
for ( org.apache.maven.settings.Profile rawProfile : settings.getProfiles() )
{
Profile profile = SettingsUtils.convertFromSettingsProfile( rawProfile );
config.addProfile( profile );
}
String localRepoUrl =
System.getProperty( "maven.repo.local", System.getProperty( "user.home" ) + "/.m2/repository" );
localRepoUrl = "file://" + localRepoUrl;
config.setLocalRepository( repositorySystem.createArtifactRepository( "local", localRepoUrl,
new DefaultRepositoryLayout(), null, null ) );
config.setActiveProfileIds( settings.getActiveProfiles() );
MavenRepositorySystemSession repoSession = new MavenRepositorySystemSession( true );
repoSession.setLocalRepositoryManager( new SimpleLocalRepositoryManager(
new File(
config.getLocalRepository().getBasedir() ) ) );
config.setRepositorySession( repoSession );
return new PomTestWrapper( pomFile, projectBuilder.build( pomFile, config ).getProject() );
}
示例5: 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);
}
}
}
}