本文整理汇总了Java中org.apache.maven.execution.MavenSession.setProjects方法的典型用法代码示例。如果您正苦于以下问题:Java MavenSession.setProjects方法的具体用法?Java MavenSession.setProjects怎么用?Java MavenSession.setProjects使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.apache.maven.execution.MavenSession
的用法示例。
在下文中一共展示了MavenSession.setProjects方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: loadExtensions
import org.apache.maven.execution.MavenSession; //导入方法依赖的package包/类
private void loadExtensions(MavenProject project, List<Exception> exceptions) {
ClassLoader currentClassLoader = Thread.currentThread().getContextClassLoader();
Collection<AbstractMavenLifecycleParticipant> participants =
getLifecycleParticipants(Collections.singletonList(project));
if (!participants.isEmpty()) {
LegacySupport legacySupport = getMavenComponent(LegacySupport.class);
MavenSession session = legacySupport.getSession();
session.setCurrentProject(project);
session.setProjects(Collections.singletonList(project));
for (AbstractMavenLifecycleParticipant participant : participants) {
Thread.currentThread().setContextClassLoader(participant.getClass().getClassLoader());
try {
participant.afterProjectsRead(session);
} catch (MavenExecutionException e) {
exceptions.add(e);
} finally {
Thread.currentThread().setContextClassLoader(currentClassLoader);
}
}
}
}
示例2: newMavenSession
import org.apache.maven.execution.MavenSession; //导入方法依赖的package包/类
@Override
protected MavenSession newMavenSession(MavenProject project) {
MavenExecutionResult result = new DefaultMavenExecutionResult();
MavenSession session = new MavenSession(getContainer(),
project.getProjectBuildingRequest().getRepositorySession(), currentMavenExecutionRequest, result);
session.setCurrentProject(project);
session.setProjects(Arrays.asList(project));
try {
LegacySupport legacySupport = this.lookup(LegacySupport.class);
legacySupport.setSession(session);
} catch (Exception e) {
e.printStackTrace();
}
return session;
}
示例3: newSession
import org.apache.maven.execution.MavenSession; //导入方法依赖的package包/类
private MavenSession newSession(MavenProject project, File localrepo, Properties properties) throws Exception {
MavenExecutionRequest request = new DefaultMavenExecutionRequest();
MavenExecutionResult result = new DefaultMavenExecutionResult();
DefaultRepositorySystemSession repoSession = MavenRepositorySystemUtils.newSession();
LocalRepository localRepo = new LocalRepository(localrepo);
repoSession.setLocalRepositoryManager(mojos.getContainer().lookup(LocalRepositoryManagerFactory.class, "simple").newInstance(repoSession, localRepo));
MavenSession session = new MavenSession(mojos.getContainer(), repoSession, request, result);
List<MavenProject> projects = new ArrayList<>();
projects.add(project);
for (String module : project.getModules()) {
MavenProject moduleProject = readMavenProject(new File(project.getBasedir(), module), properties);
moduleProject.setParent(project);
projects.add(moduleProject);
}
session.setProjects(projects);
return session;
}
示例4: testSourcepathDependency
import org.apache.maven.execution.MavenSession; //导入方法依赖的package包/类
@Test
public void testSourcepathDependency() throws Exception {
// assert that MojoAnnotationProcessorMojo honours sourcepath=reactorDependencies
File basedir = resources.getBasedir("plugin-descriptor/sourcepath-dependency");
File dependency = new File(basedir, "dependency");
File plugin = new File(basedir, "plugin");
MavenProject dependencyProject = mojos.readMavenProject(dependency);
MavenProject pluginProject = mojos.readMavenProject(plugin);
addDependencies(pluginProject, "apache-plugin-annotations-jar", "maven-plugin-api-jar");
mojos.newDependency(new File(dependencyProject.getBuild().getOutputDirectory())) //
.setGroupId(dependencyProject.getGroupId()) //
.setArtifactId(dependencyProject.getArtifactId()) //
.setVersion(dependencyProject.getVersion()) //
.addTo(pluginProject);
Artifact dependencyArtifact = dependencyProject.getArtifact();
dependencyArtifact.setScope(Artifact.SCOPE_COMPILE);
pluginProject.getArtifacts().add(dependencyArtifact);
MavenSession session = mojos.newMavenSession(pluginProject);
session.setProjects(ImmutableList.of(dependencyProject, pluginProject));
session.setCurrentProject(pluginProject);
mojos.executeMojo(session, pluginProject, "mojo-annotation-processor", newParameter("sourcepath", "reactorDependencies"));
mojos.executeMojo(session, pluginProject, "plugin-descriptor");
mojos.assertBuildOutputs(plugin, "target/classes/META-INF/maven/plugin.xml", "target/classes/META-INF/m2e/lifecycle-mapping-metadata.xml");
}
示例5: testSourcepathSecondatytype
import org.apache.maven.execution.MavenSession; //导入方法依赖的package包/类
@Test
@Ignore("Neither javac nor jdt support secondary types on sourcepath")
public void testSourcepathSecondatytype() throws Exception {
File processor = compileAnnotationProcessor();
File basedir = resources.getBasedir("compile-proc/proc-sourcepath-secondarytype");
File dependencyBasedir = new File(basedir, "dependency");
File projectBasedir = new File(basedir, "project");
Xpp3Dom processors = newProcessors("processor.Processor");
Xpp3Dom sourcepath = newParameter("sourcepath", "reactorDependencies");
MavenProject dependency = mojos.readMavenProject(dependencyBasedir);
MavenProject project = mojos.readMavenProject(projectBasedir);
mojos.newDependency(new File(dependencyBasedir, "target/classes")) //
.setGroupId(dependency.getGroupId()) //
.setArtifactId(dependency.getArtifactId()) //
.setVersion(dependency.getVersion()) //
.addTo(project);
MavenSession session = mojos.newMavenSession(project);
session.setProjects(Arrays.asList(project, dependency));
processAnnotations(session, project, "compile", processor, Proc.only, processors, sourcepath);
}
示例6: afterProjectsRead
import org.apache.maven.execution.MavenSession; //导入方法依赖的package包/类
@Override
public void afterProjectsRead(MavenSession session) throws MavenExecutionException {
logger.debug("BW lifecycle participant");
propertiesManager = AbstractBWMojo.propertiesManager(session, session.getCurrentProject());
List<MavenProject> projects = prepareProjects(session.getProjects(), session);
session.setProjects(projects);
}
示例7: build
import org.apache.maven.execution.MavenSession; //导入方法依赖的package包/类
private void build(MavenSession session, MavenProject project, List<MavenProject> allProjects, GoalSet goals) throws MojoExecutionException {
session.setProjects(allProjects);
ProjectIndex projectIndex = new ProjectIndex(session.getProjects());
try {
ReactorBuildStatus reactorBuildStatus = new ReactorBuildStatus(new BomDependencyGraph(session.getProjects()));
ReactorContext reactorContext = new ReactorContextFactory(new MavenVersion(mavenVersion)).create(session.getResult(), projectIndex, Thread.currentThread().getContextClassLoader(),
reactorBuildStatus, builder);
List<TaskSegment> segments = segmentCalculator.calculateTaskSegments(session);
for (TaskSegment segment : segments) {
builder.buildProject(session, reactorContext, project, filterSegment(segment, goals));
}
} catch (Throwable t) {
throw new MojoExecutionException("Error building generated bom:" + project.getArtifactId(), t);
}
}
示例8: newMavenSession
import org.apache.maven.execution.MavenSession; //导入方法依赖的package包/类
/** Extends the super to use the new {@link #newMavenSession()} introduced here
* which sets the defaults one expects from maven; the standard test case leaves a lot of things blank */
@Override
protected MavenSession newMavenSession(MavenProject project) {
MavenSession session = newMavenSession();
session.setCurrentProject( project );
session.setProjects( Arrays.asList( project ) );
return session;
}
示例9: testRequireProc_processorpath
import org.apache.maven.execution.MavenSession; //导入方法依赖的package包/类
@Test
public void testRequireProc_processorpath() throws Exception {
MavenProject annotations = mojos.readMavenProject(resources.getBasedir("compile-proc/processorpath-annotation"));
mojos.compile(annotations);
MavenProject processor = mojos.readMavenProject(resources.getBasedir("compile-proc/processorpath-processor"));
mojos.newDependency(new File(annotations.getBasedir(), "target/classes")).setArtifactId("annotations").addTo(processor);
mojos.compile(processor);
cp(processor.getBasedir(), "src/main/resources/META-INF/services/javax.annotation.processing.Processor", "target/classes/META-INF/services/javax.annotation.processing.Processor");
File basedir = resources.getBasedir("compile-proc/proc");
MavenProject project = mojos.readMavenProject(basedir);
mojos.newDependency(new File(annotations.getBasedir(), "target/classes")).setArtifactId("annotations").addTo(project);
MavenSession session = mojos.newMavenSession(project);
SimpleReactorReader.builder() //
.addProjects(annotations, processor, project) //
.toSession(session.getRepositorySession());
session.setProjects(Arrays.asList(annotations, processor, project));
session.setCurrentProject(project);
Xpp3Dom processorpath = new Xpp3Dom("processorpath");
processorpath.addChild(newProcessorpathEntry(processor));
try {
mojos.compile(session, project, processorpath);
fail();
} catch (IllegalArgumentException expected) {
// TODO assert message
}
}
示例10: testProc_processorpath
import org.apache.maven.execution.MavenSession; //导入方法依赖的package包/类
@Test
public void testProc_processorpath() throws Exception {
MavenProject annotations = mojos.readMavenProject(resources.getBasedir("compile-proc/processorpath-annotation"));
mojos.compile(annotations);
MavenProject processor = mojos.readMavenProject(resources.getBasedir("compile-proc/processorpath-processor"));
mojos.newDependency(new File(annotations.getBasedir(), "target/classes")).setArtifactId("annotations").addTo(processor);
mojos.compile(processor);
cp(processor.getBasedir(), "src/main/resources/META-INF/services/javax.annotation.processing.Processor", "target/classes/META-INF/services/javax.annotation.processing.Processor");
File basedir = resources.getBasedir("compile-proc/proc");
MavenProject project = mojos.readMavenProject(basedir);
mojos.newDependency(new File(annotations.getBasedir(), "target/classes")).setArtifactId("annotations").addTo(project);
MavenSession session = mojos.newMavenSession(project);
SimpleReactorReader.builder() //
.addProjects(annotations, processor, project) //
.toSession(session.getRepositorySession());
session.setProjects(Arrays.asList(annotations, processor, project));
session.setCurrentProject(project);
Xpp3Dom processorpath = new Xpp3Dom("processorpath");
processorpath.addChild(newProcessorpathEntry(processor));
mojos.compile(session, project, newParameter("proc", "proc"), processorpath);
mojos.assertBuildOutputs(new File(basedir, "target"), //
"classes/proc/Source.class", //
"generated-sources/annotations/proc/GeneratedSource.java", //
"classes/proc/GeneratedSource.class");
}
示例11: testSourcepathDependency
import org.apache.maven.execution.MavenSession; //导入方法依赖的package包/类
@Test
public void testSourcepathDependency() throws Exception {
File processor = compileAnnotationProcessor();
File basedir = resources.getBasedir("compile-proc/proc-sourcepath");
File dependencyBasedir = new File(basedir, "dependency");
File projectBasedir = new File(basedir, "project");
Xpp3Dom processors = newProcessors("processor.Processor");
Xpp3Dom sourcepath = newParameter("sourcepath", "reactorDependencies");
MavenProject dependency = mojos.readMavenProject(dependencyBasedir);
MavenProject project = mojos.readMavenProject(projectBasedir);
mojos.newDependency(new File(dependencyBasedir, "target/classes")) //
.setGroupId(dependency.getGroupId()) //
.setArtifactId(dependency.getArtifactId()) //
.setVersion(dependency.getVersion()) //
.addTo(project);
MavenSession session = mojos.newMavenSession(project);
session.setProjects(Arrays.asList(project, dependency));
processAnnotations(session, project, "compile", processor, Proc.only, processors, sourcepath);
mojos.assertBuildOutputs(new File(projectBasedir, "target"), //
"generated-sources/annotations/sourcepath/project/GeneratedSource.java" //
);
}
示例12: testSourcepathDependency_classifiedDependency
import org.apache.maven.execution.MavenSession; //导入方法依赖的package包/类
@Test
public void testSourcepathDependency_classifiedDependency() throws Exception {
File processor = compileAnnotationProcessor();
File basedir = resources.getBasedir("compile-proc/proc-sourcepath");
File dependencyBasedir = new File(basedir, "dependency");
File projectBasedir = new File(basedir, "project");
Xpp3Dom processors = newProcessors("processor.Processor");
Xpp3Dom sourcepath = newParameter("sourcepath", "reactorDependencies");
MavenProject dependency = mojos.readMavenProject(dependencyBasedir);
MavenProject project = mojos.readMavenProject(projectBasedir);
mojos.newDependency(new File(dependencyBasedir, "target/classes")) //
.setGroupId(dependency.getGroupId()) //
.setArtifactId(dependency.getArtifactId()) //
.setVersion(dependency.getVersion()) //
.setClassifier("classifier") //
.addTo(project);
MavenSession session = mojos.newMavenSession(project);
session.setProjects(Arrays.asList(project, dependency));
try {
processAnnotations(session, project, "compile", processor, Proc.only, processors, sourcepath);
Assert.fail();
} catch (MojoExecutionException expected) {
Assert.assertTrue(expected.getMessage().contains(dependency.getGroupId() + ":" + dependency.getArtifactId()));
}
}
示例13: testSourcepathDependency_testCompile
import org.apache.maven.execution.MavenSession; //导入方法依赖的package包/类
@Test
public void testSourcepathDependency_testCompile() throws Exception {
File processor = compileAnnotationProcessor();
File basedir = resources.getBasedir("compile-proc/proc-sourcepath");
File dependencyBasedir = new File(basedir, "dependency");
File projectBasedir = new File(basedir, "project");
Xpp3Dom processors = newProcessors("processor.Processor");
Xpp3Dom sourcepath = newParameter("sourcepath", "reactorDependencies");
MavenProject dependency = mojos.readMavenProject(dependencyBasedir);
MavenProject project = mojos.readMavenProject(projectBasedir);
mojos.newDependency(new File(dependencyBasedir, "target/classes")) //
.setGroupId(dependency.getGroupId()) //
.setArtifactId(dependency.getArtifactId()) //
.setVersion(dependency.getVersion()) //
.addTo(project);
mojos.newDependency(new File(dependencyBasedir, "target/test-classes")) //
.setGroupId(dependency.getGroupId()) //
.setArtifactId(dependency.getArtifactId()) //
.setType("test-jar") //
.setVersion(dependency.getVersion()) //
.addTo(project);
MavenSession session = mojos.newMavenSession(project);
session.setProjects(Arrays.asList(project, dependency));
processAnnotations(session, project, "testCompile", processor, Proc.only, processors, sourcepath);
mojos.assertBuildOutputs(new File(projectBasedir, "target"), //
"generated-test-sources/test-annotations/sourcepath/project/test/GeneratedSourceTest.java" //
);
}
示例14: getMavenSession
import org.apache.maven.execution.MavenSession; //导入方法依赖的package包/类
public static MavenSession getMavenSession()
{
final DefaultMavenExecutionResult defaultMavenExecutionResult = new DefaultMavenExecutionResult();
MavenExecutionRequest mavenExecutionRequest = new DefaultMavenExecutionRequest();
mavenExecutionRequest.setExecutionListener( new AbstractExecutionListener() );
mavenExecutionRequest.setGoals( Arrays.asList( "clean", "aggr", "install" ) );
final MavenSession session = new MavenSession( null, null, mavenExecutionRequest, defaultMavenExecutionResult );
final ProjectDependencyGraphStub dependencyGraphStub = new ProjectDependencyGraphStub();
session.setProjectDependencyGraph( dependencyGraphStub );
session.setProjects( dependencyGraphStub.getSortedProjects() );
return session;
}
示例15: createMavenSession
import org.apache.maven.execution.MavenSession; //导入方法依赖的package包/类
protected MavenSession createMavenSession( File pom, Properties executionProperties )
throws Exception
{
MavenExecutionRequest request = createMavenExecutionRequest( pom );
ProjectBuildingRequest configuration = new DefaultProjectBuildingRequest()
.setLocalRepository( request.getLocalRepository() )
.setRemoteRepositories( request.getRemoteRepositories() )
.setPluginArtifactRepositories( request.getPluginArtifactRepositories() )
.setSystemProperties( executionProperties );
MavenProject project = null;
if ( pom != null )
{
project = projectBuilder.build( pom, configuration ).getProject();
}
else
{
project = createStubMavenProject();
project.setRemoteArtifactRepositories( request.getRemoteRepositories() );
project.setPluginArtifactRepositories( request.getPluginArtifactRepositories() );
}
initRepoSession( configuration );
MavenSession session =
new MavenSession( getContainer(), configuration.getRepositorySession(), request,
new DefaultMavenExecutionResult() );
session.setProjects( Arrays.asList( project ) );
return session;
}