本文整理汇总了Java中org.apache.maven.project.ProjectBuildingRequest.setRepositorySession方法的典型用法代码示例。如果您正苦于以下问题:Java ProjectBuildingRequest.setRepositorySession方法的具体用法?Java ProjectBuildingRequest.setRepositorySession怎么用?Java ProjectBuildingRequest.setRepositorySession使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.apache.maven.project.ProjectBuildingRequest
的用法示例。
在下文中一共展示了ProjectBuildingRequest.setRepositorySession方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的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: 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: 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;
}
示例5: 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;
}
示例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: lookupMojo
import org.apache.maven.project.ProjectBuildingRequest; //导入方法依赖的package包/类
protected Mojo lookupMojo(Path pomPath, String goal) throws Exception {
File pom = getTestFile(pomPath.toString());
assertTrue(pom.exists());
MavenExecutionRequest executionRequest = new DefaultMavenExecutionRequest();
ProjectBuildingRequest buildingRequest = executionRequest.getProjectBuildingRequest();
buildingRequest.setRepositorySession(new DefaultRepositorySystemSession());
ProjectBuilder projectBuilder = lookup(ProjectBuilder.class);
MavenProject project = projectBuilder.build(pom, buildingRequest).getProject();
return lookupConfiguredMojo(project, goal);
}
示例8: lookupConfiguredMojo
import org.apache.maven.project.ProjectBuildingRequest; //导入方法依赖的package包/类
private Mojo lookupConfiguredMojo(String goal, File pom) throws Exception
{
MavenExecutionRequest request = new DefaultMavenExecutionRequest();
request.setBaseDirectory(pom.getParentFile());
ProjectBuildingRequest configuration = request.getProjectBuildingRequest();
// Fix for bug: https://git-wip-us.apache.org/repos/asf?p=maven-plugin-testing.git;a=commit;h=3cd5f47c586499e438a3f9393304ac9d1f9a7f53
configuration.setRepositorySession(new DefaultRepositorySystemSession());
MavenProject project = lookup(ProjectBuilder.class).build(pom, configuration).getProject();
return super.lookupConfiguredMojo(project, goal);
}
示例9: readMavenProject
import org.apache.maven.project.ProjectBuildingRequest; //导入方法依赖的package包/类
private MavenProject readMavenProject(File basedir, Properties properties) throws Exception {
File pom = new File(basedir, "pom.xml");
MavenExecutionRequest request = new DefaultMavenExecutionRequest();
request.setUserProperties(properties);
request.setBaseDirectory(basedir);
ProjectBuildingRequest configuration = request.getProjectBuildingRequest();
configuration.setRepositorySession(new DefaultRepositorySystemSession());
MavenProject project = mojos.lookup(ProjectBuilder.class).build(pom, configuration).getProject();
Assert.assertNotNull(project);
return project;
}
示例10: initRepoSession
import org.apache.maven.project.ProjectBuildingRequest; //导入方法依赖的package包/类
protected void initRepoSession( ProjectBuildingRequest request )
{
File localRepo = new File( request.getLocalRepository().getBasedir() );
MavenRepositorySystemSession session = new MavenRepositorySystemSession( true );
session.setLocalRepositoryManager( new SimpleLocalRepositoryManager( localRepo ) );
request.setRepositorySession( session );
}
示例11: 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() );
}
示例12: readMavenProject
import org.apache.maven.project.ProjectBuildingRequest; //导入方法依赖的package包/类
public MavenProject readMavenProject(Path pom)
throws Exception {
MavenExecutionRequest request = new DefaultMavenExecutionRequest();
request.setBaseDirectory(pom.getParent().toFile());
ProjectBuildingRequest configuration = request.getProjectBuildingRequest();
configuration.setRepositorySession(new DefaultRepositorySystemSession());
MavenProject project = rule.lookup(ProjectBuilder.class).build(pom.toFile(), configuration).getProject();
Assert.assertNotNull(project);
return project;
}
示例13: 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);
}
}
}
}
示例14: lookupConfiguredMojo
import org.apache.maven.project.ProjectBuildingRequest; //导入方法依赖的package包/类
public E lookupConfiguredMojo(File pom, String goal, TestDB testDb) throws Exception {
// Mojoテストリソースディレクトリのパスをシステムプロパティに設定しておく
// System.setProperty("MojoTestRoot", getMojoTestRoot());
// 各DBの接続情報をシステムプロパティへマージする
Properties prop = new Properties();
prop.load(new FileInputStream(new File(Thread.currentThread().getContextClassLoader().getResource("jdbc_test.properties").getPath())));
System.getProperties().putAll(prop);
// Maven実行リクエスト初期化
MavenExecutionRequest executionRequest = new DefaultMavenExecutionRequest();
// テスト用のsettingファイルで初期化
// File settings = new File(this.getClass().getResource("settings.xml").getPath());
File settings = new File(Thread.currentThread().getContextClassLoader().getResource("settings.xml").getPath());
MavenExecutionRequestPopulator populator = getContainer().lookup(MavenExecutionRequestPopulator.class);
MavenSettingsBuilder mb = this.lookup(MavenSettingsBuilder.class);
Settings st = mb.buildSettings(settings);
populator.populateFromSettings(executionRequest, st);
// カレントディレクトリをセット
executionRequest.setBaseDirectory(pom.getParentFile());
// プロファイルを指定DBのプロファイルにセット
executionRequest.setActiveProfiles(Collections.singletonList(testDb.name()));
// ローカルリポジトリオブジェクトのセット
String localRepoPath = this.getClass().getResource("testLocalRepo").toURI().toURL().toString();
executionRequest.setLocalRepository(new MavenArtifactRepository(RepositorySystem.DEFAULT_LOCAL_REPO_ID,
localRepoPath, new DefaultRepositoryLayout(),
new ArtifactRepositoryPolicy(), new ArtifactRepositoryPolicy()));
// 実行プロジェクトを作成
ProjectBuildingRequest buildingRequest = executionRequest.getProjectBuildingRequest();
DefaultMaven maven = (DefaultMaven) getContainer().lookup(Maven.class);
DefaultRepositorySystemSession repoSession = (DefaultRepositorySystemSession) maven
.newRepositorySession(executionRequest);
repoSession.setOffline(true);
buildingRequest.setRepositorySession(repoSession);
ProjectBuilder projectBuilder = this.lookup(ProjectBuilder.class);
MavenProject project = projectBuilder.build(pom, buildingRequest).getProject();
currentMavenExecutionRequest = executionRequest;
// 指定ゴールを持つMojoを取得
Mojo mojo = this.lookupConfiguredMojo(project, goal);
currentProject = project;
return (E) mojo;
}
示例15: 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);
}
}