本文整理匯總了Java中org.apache.maven.execution.MavenSession.setCurrentProject方法的典型用法代碼示例。如果您正苦於以下問題:Java MavenSession.setCurrentProject方法的具體用法?Java MavenSession.setCurrentProject怎麽用?Java MavenSession.setCurrentProject使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類org.apache.maven.execution.MavenSession
的用法示例。
在下文中一共展示了MavenSession.setCurrentProject方法的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: 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");
}
示例4: testResolveBuildPlan
import org.apache.maven.execution.MavenSession; //導入方法依賴的package包/類
public void testResolveBuildPlan()
throws Exception
{
MavenSession original = ProjectDependencyGraphStub.getMavenSession();
final TaskSegment taskSegment1 = new TaskSegment( false );
final MavenSession session1 = original.clone();
session1.setCurrentProject( ProjectDependencyGraphStub.A );
final BuilderCommon builderCommon = getBuilderCommon();
final MavenExecutionPlan plan =
builderCommon.resolveBuildPlan( session1, ProjectDependencyGraphStub.A, taskSegment1,
new HashSet<Artifact>() );
assertEquals( LifecycleExecutionPlanCalculatorStub.getProjectAExceutionPlan().size(), plan.size() );
}
示例5: createExpressionEvaluator
import org.apache.maven.execution.MavenSession; //導入方法依賴的package包/類
private ExpressionEvaluator createExpressionEvaluator( MavenProject project, PluginDescriptor pluginDescriptor, Properties executionProperties )
throws Exception
{
ArtifactRepository repo = factory.createDefaultLocalRepository();
MutablePlexusContainer container = (MutablePlexusContainer) getContainer();
MavenSession session = createSession( container, repo, executionProperties );
session.setCurrentProject( project );
MojoDescriptor mojo = new MojoDescriptor();
mojo.setPluginDescriptor( pluginDescriptor );
mojo.setGoal( "goal" );
MojoExecution mojoExecution = new MojoExecution( mojo );
return new PluginParameterExpressionEvaluator( session, mojoExecution );
}
示例6: invokePITest
import org.apache.maven.execution.MavenSession; //導入方法依賴的package包/類
private void invokePITest() {
MavenEnvironment theEnvironment = MavenEnvironment.get();
MavenSession theSession = theEnvironment.getMavenSession();
for (MavenProject theProject : theSession.getAllProjects()) {
MavenProject theOldProject = theSession.getCurrentProject();
log.info("Invoking PITest for {}:{}", theProject.getGroupId(), theProject.getArtifact());
theSession.setCurrentProject(theProject);
String theCurrentVersion = getClass().getPackage().getImplementationVersion();
List<Dependency> theDependencies = new ArrayList<>();
theDependencies.add(dependency("de.mirkosertic.mavensonarsputnik", "pitest-plugins", theCurrentVersion));
try {
executeMojo(
plugin(
groupId("org.pitest"),
artifactId("pitest-maven"),
version(properties.getProperty("pitest.pluginversion")),
theDependencies
),
goal(properties.getProperty("pitest.pluginGoal")),
createConfiguration(),
executionEnvironment(
theProject,
theEnvironment.getMavenSession(),
theEnvironment.getBuildPluginManager()
)
);
} catch (Exception e) {
log.warn("Error invoking PITest, but analysis will continue", e);
} finally {
theSession.setCurrentProject(theOldProject);
}
}
}
示例7: 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;
}
示例8: testDeployAtEnd
import org.apache.maven.execution.MavenSession; //導入方法依賴的package包/類
@Test
public void testDeployAtEnd() throws Exception {
File basedir = resources.getBasedir("install-deploy/deploy-at-end");
File localrepo = new File(basedir, "target/localrepo");
Assert.assertTrue(localrepo.mkdirs());
File remoterepo = new File(basedir, "target/remoterepo");
Assert.assertTrue(remoterepo.mkdirs());
Properties properties = new Properties();
properties.put("version", "1.0");
properties.put("repopath", remoterepo.getCanonicalPath());
MavenProject project = readMavenProject(basedir, properties);
MavenSession session = newSession(project, localrepo, properties);
DeployParticipant deployParticipant = mojos.getContainer().lookup(DeployParticipant.class);
Assert.assertEquals(0, deployParticipant.getDeployAtEndRequests().size());
for (MavenProject reactorProject : session.getProjects()) {
session.setCurrentProject(reactorProject);
if (!reactorProject.getPackaging().equals("pom")) {
mojos.executeMojo(session, reactorProject, "compile");
mojos.executeMojo(session, reactorProject, "jar");
}
mojos.executeMojo(session, reactorProject, "deploy");
}
Assert.assertFalse(new File(remoterepo, "io/takari/lifecycle/its/test/1.0/test-1.0.pom").canRead());
Assert.assertFalse(new File(remoterepo, "io/takari/lifecycle/its/test-modulea/1.0/test-modulea-1.0.jar").canRead());
Assert.assertFalse(new File(remoterepo, "io/takari/lifecycle/its/test-modulea/1.0/test-modulea-1.0.pom").canRead());
Assert.assertFalse(new File(remoterepo, "io/takari/lifecycle/its/test-moduleb/1.0/test-moduleb-1.0.jar").canRead());
Assert.assertFalse(new File(remoterepo, "io/takari/lifecycle/its/test-moduleb/1.0/test-moduleb-1.0.pom").canRead());
Assert.assertEquals(3, deployParticipant.getDeployAtEndRequests().size());
}
示例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: closeAll
import org.apache.maven.execution.MavenSession; //導入方法依賴的package包/類
public void closeAll()
{
for ( ProjectSegment item : items )
{
MavenSession sessionForThisModule = item.getSession();
sessionForThisModule.setCurrentProject( null );
}
}
示例12: calculateProjectBuilds
import org.apache.maven.execution.MavenSession; //導入方法依賴的package包/類
public ProjectBuildList calculateProjectBuilds( MavenSession session, List<TaskSegment> taskSegments )
{
List<ProjectSegment> projectBuilds = new ArrayList<ProjectSegment>();
MavenProject rootProject = session.getTopLevelProject();
for ( TaskSegment taskSegment : taskSegments )
{
List<MavenProject> projects;
if ( taskSegment.isAggregating() )
{
projects = Collections.singletonList( rootProject );
}
else
{
projects = session.getProjects();
}
for ( MavenProject project : projects )
{
BuilderCommon.attachToThread( project ); // Not totally sure if this is needed for anything
MavenSession copiedSession = session.clone();
copiedSession.setCurrentProject( project );
projectBuilds.add( new ProjectSegment( project, taskSegment, copiedSession ) );
}
}
return new ProjectBuildList( projectBuilds );
}
示例13: testSourcepathCache
import org.apache.maven.execution.MavenSession; //導入方法依賴的package包/類
@Test
public void testSourcepathCache() throws Exception {
// project-a has its generated sources directory configured as compile source root
// project-b depends on project-a generated sources
// both project-a and project-b run proc=only sourcepath=reactorDependencies
File processor = compileAnnotationProcessor();
File basedir = resources.getBasedir("compile-proc/proc-sourcepath-cache");
Xpp3Dom processors = newProcessors("processor.Processor");
Xpp3Dom sourcepath = newParameter("sourcepath", "reactorDependencies");
Xpp3Dom procOnly = newParameter("proc", Proc.only.name());
// setting up project-a
File projectaBasedir = new File(basedir, "project-a");
MavenProject projecta = mojos.readMavenProject(projectaBasedir);
addDependency(projecta, "processor", new File(processor, "target/classes"));
projecta.addCompileSourceRoot(new File(projectaBasedir, "target/generated-sources/annotations").getCanonicalPath());
// setting up project-b
File projectbBasedir = new File(basedir, "project-b");
MavenProject projectb = mojos.readMavenProject(projectbBasedir);
addDependency(projectb, "processor", new File(processor, "target/classes"));
mojos.newDependency(new File(projectaBasedir, "target/classes")) //
.setGroupId(projecta.getGroupId()) //
.setArtifactId(projecta.getArtifactId()) //
.setVersion(projecta.getVersion()) //
.addTo(projectb);
MavenSession session = mojos.newMavenSession(projecta);
session.setProjects(Arrays.asList(projecta, projecta));
// process annotations in project-a
mojos.executeMojo(session, projecta, "compile", procOnly, processors, sourcepath);
mojos.assertBuildOutputs(new File(projectaBasedir, "target"), //
"generated-sources/annotations/sourcepath/projecta/GeneratedSourceA.java" //
);
// process annotations in project-b, requires access to project-a generated sources
session.setCurrentProject(projectb);
mojos.executeMojo(session, projectb, "compile", procOnly, processors, sourcepath);
mojos.assertBuildOutputs(new File(projectbBasedir, "target"), //
"generated-sources/annotations/sourcepath/projectb/GeneratedSourceB.java" //
);
}
示例14: buildProject
import org.apache.maven.execution.MavenSession; //導入方法依賴的package包/類
public void buildProject( MavenSession session, MavenSession rootSession, ReactorContext reactorContext,
MavenProject currentProject, TaskSegment taskSegment )
{
session.setCurrentProject( currentProject );
long buildStartTime = System.currentTimeMillis();
try
{
if ( reactorContext.getReactorBuildStatus().isHaltedOrBlacklisted( currentProject ) )
{
eventCatapult.fire( ExecutionEvent.Type.ProjectSkipped, session, null );
return;
}
eventCatapult.fire( ExecutionEvent.Type.ProjectStarted, session, null );
BuilderCommon.attachToThread( currentProject );
MavenExecutionPlan executionPlan =
builderCommon.resolveBuildPlan( session, currentProject, taskSegment, new HashSet<Artifact>() );
mojoExecutor.execute( session, executionPlan.getMojoExecutions(), reactorContext.getProjectIndex() );
long buildEndTime = System.currentTimeMillis();
reactorContext.getResult().addBuildSummary(
new BuildSuccess( currentProject, buildEndTime - buildStartTime ) );
eventCatapult.fire( ExecutionEvent.Type.ProjectSucceeded, session, null );
}
catch ( Exception e )
{
builderCommon.handleBuildError( reactorContext, rootSession, currentProject, e, buildStartTime );
}
finally
{
session.setCurrentProject( null );
Thread.currentThread().setContextClassLoader( reactorContext.getOriginalContextClassLoader() );
}
}
示例15: getMavenSession
import org.apache.maven.execution.MavenSession; //導入方法依賴的package包/類
public static MavenSession getMavenSession( MavenProject mavenProject )
{
final MavenSession session = getMavenSession();
session.setCurrentProject( mavenProject );
return session;
}