use of org.apache.maven.plugin.LegacySupport in project intellij-community by JetBrains.
the class Maven30ServerEmbedderImpl method loadExtensions.
/**
* adapted from {@link DefaultMaven#doExecute(MavenExecutionRequest)}
*/
private void loadExtensions(MavenProject project, List<Exception> exceptions) {
ClassLoader originalClassLoader = Thread.currentThread().getContextClassLoader();
Collection<AbstractMavenLifecycleParticipant> lifecycleParticipants = getLifecycleParticipants(Arrays.asList(project));
if (!lifecycleParticipants.isEmpty()) {
LegacySupport legacySupport = getComponent(LegacySupport.class);
MavenSession session = legacySupport.getSession();
session.setCurrentProject(project);
session.setProjects(Arrays.asList(project));
for (AbstractMavenLifecycleParticipant listener : lifecycleParticipants) {
Thread.currentThread().setContextClassLoader(listener.getClass().getClassLoader());
try {
listener.afterProjectsRead(session);
} catch (MavenExecutionException e) {
exceptions.add(e);
} finally {
Thread.currentThread().setContextClassLoader(originalClassLoader);
}
}
}
}
use of org.apache.maven.plugin.LegacySupport in project intellij-community by JetBrains.
the class Maven3ServerEmbedderImpl method executeWithMavenSession.
public void executeWithMavenSession(MavenExecutionRequest request, Runnable runnable) {
DefaultMaven maven = (DefaultMaven) getComponent(Maven.class);
RepositorySystemSession repositorySession = maven.newRepositorySession(request);
request.getProjectBuildingRequest().setRepositorySession(repositorySession);
MavenSession mavenSession = new MavenSession(myContainer, repositorySession, request, new DefaultMavenExecutionResult());
LegacySupport legacySupport = getComponent(LegacySupport.class);
MavenSession oldSession = legacySupport.getSession();
legacySupport.setSession(mavenSession);
/** adapted from {@link DefaultMaven#doExecute(MavenExecutionRequest)} */
try {
for (AbstractMavenLifecycleParticipant listener : getLifecycleParticipants(Collections.<MavenProject>emptyList())) {
listener.afterSessionStart(mavenSession);
}
} catch (MavenExecutionException e) {
throw new RuntimeException(e);
}
try {
runnable.run();
} finally {
legacySupport.setSession(oldSession);
}
}
use of org.apache.maven.plugin.LegacySupport in project maven-plugins by apache.
the class TestGetMojo method setUp.
protected void setUp() throws Exception {
// required for mojo lookups to work
super.setUp("markers", false);
File testPom = new File(getBasedir(), "target/test-classes/unit/get-test/plugin-config.xml");
assert testPom.exists();
mojo = (GetMojo) lookupMojo("get", testPom);
assertNotNull(mojo);
LegacySupport legacySupport = lookup(LegacySupport.class);
legacySupport.setSession(newMavenSession(new MavenProjectStub()));
DefaultRepositorySystemSession repoSession = (DefaultRepositorySystemSession) legacySupport.getRepositorySession();
repoSession.setLocalRepositoryManager(new SimpleLocalRepositoryManager(testDir.getAbsolutePath()));
setVariableValueToObject(mojo, "session", legacySupport.getSession());
}
use of org.apache.maven.plugin.LegacySupport in project maven-plugins by apache.
the class TestCopyDependenciesMojo2 method setUp.
protected void setUp() throws Exception {
// required for mojo lookups to work
super.setUp("copy-dependencies", true);
File testPom = new File(getBasedir(), "target/test-classes/unit/copy-dependencies-test/plugin-config.xml");
mojo = (CopyDependenciesMojo) lookupMojo("copy-dependencies", testPom);
mojo.outputDirectory = new File(this.testDir, "outputDirectory");
// mojo.silent = true;
assertNotNull(mojo);
assertNotNull(mojo.getProject());
MavenProject project = mojo.getProject();
Set<Artifact> artifacts = this.stubFactory.getScopedArtifacts();
Set<Artifact> directArtifacts = this.stubFactory.getReleaseAndSnapshotArtifacts();
artifacts.addAll(directArtifacts);
project.setArtifacts(artifacts);
project.setDependencyArtifacts(directArtifacts);
mojo.markersDirectory = new File(this.testDir, "markers");
LegacySupport legacySupport = lookup(LegacySupport.class);
MavenSession session = newMavenSession(project);
setVariableValueToObject(mojo, "session", session);
legacySupport.setSession(session);
DefaultRepositorySystemSession repoSession = (DefaultRepositorySystemSession) legacySupport.getRepositorySession();
repoSession.setLocalRepositoryManager(new SimpleLocalRepositoryManager(testDir.getAbsolutePath()));
}
use of org.apache.maven.plugin.LegacySupport in project maven-plugins by apache.
the class JavadocReportTest method testTagletArtifacts.
/**
* Method to test the <code><tagletArtifacts/></code> parameter.
*
* @throws Exception if any
*/
public void testTagletArtifacts() throws Exception {
File testPom = new File(unit, "tagletArtifacts-test/tagletArtifacts-test-plugin-config.xml");
JavadocReport mojo = lookupMojo(testPom);
MavenSession session = spy(newMavenSession(mojo.project));
ProjectBuildingRequest buildingRequest = mock(ProjectBuildingRequest.class);
when(buildingRequest.getRemoteRepositories()).thenReturn(mojo.project.getRemoteArtifactRepositories());
when(session.getProjectBuildingRequest()).thenReturn(buildingRequest);
MavenRepositorySystemSession repositorySession = new MavenRepositorySystemSession();
repositorySession.setLocalRepositoryManager(new SimpleLocalRepositoryManager(localRepo));
when(buildingRequest.getRepositorySession()).thenReturn(repositorySession);
when(session.getRepositorySession()).thenReturn(repositorySession);
LegacySupport legacySupport = lookup(LegacySupport.class);
legacySupport.setSession(session);
setVariableValueToObject(mojo, "session", session);
mojo.execute();
File optionsFile = new File(mojo.getOutputDirectory(), "options");
assertTrue(optionsFile.exists());
String options = readFile(optionsFile);
// count -taglet
assertEquals(20, StringUtils.countMatches(options, LINE_SEPARATOR + "-taglet" + LINE_SEPARATOR));
assertTrue(options.contains("org.apache.maven.tools.plugin.javadoc.MojoAggregatorTypeTaglet"));
assertTrue(options.contains("org.apache.maven.tools.plugin.javadoc.MojoComponentFieldTaglet"));
assertTrue(options.contains("org.apache.maven.tools.plugin.javadoc.MojoConfiguratorTypeTaglet"));
assertTrue(options.contains("org.apache.maven.tools.plugin.javadoc.MojoExecuteTypeTaglet"));
assertTrue(options.contains("org.apache.maven.tools.plugin.javadoc.MojoExecutionStrategyTypeTaglet"));
assertTrue(options.contains("org.apache.maven.tools.plugin.javadoc.MojoGoalTypeTaglet"));
assertTrue(options.contains("org.apache.maven.tools.plugin.javadoc.MojoInheritByDefaultTypeTaglet"));
assertTrue(options.contains("org.apache.maven.tools.plugin.javadoc.MojoInstantiationStrategyTypeTaglet"));
assertTrue(options.contains("org.apache.maven.tools.plugin.javadoc.MojoParameterFieldTaglet"));
assertTrue(options.contains("org.apache.maven.tools.plugin.javadoc.MojoPhaseTypeTaglet"));
assertTrue(options.contains("org.apache.maven.tools.plugin.javadoc.MojoReadOnlyFieldTaglet"));
assertTrue(options.contains("org.apache.maven.tools.plugin.javadoc.MojoRequiredFieldTaglet"));
assertTrue(options.contains("org.apache.maven.tools.plugin.javadoc.MojoRequiresDependencyResolutionTypeTaglet"));
assertTrue(options.contains("org.apache.maven.tools.plugin.javadoc.MojoRequiresDirectInvocationTypeTaglet"));
assertTrue(options.contains("org.apache.maven.tools.plugin.javadoc.MojoRequiresOnLineTypeTaglet"));
assertTrue(options.contains("org.apache.maven.tools.plugin.javadoc.MojoRequiresProjectTypeTaglet"));
assertTrue(options.contains("org.apache.maven.tools.plugin.javadoc.MojoRequiresReportsTypeTaglet"));
assertTrue(options.contains("org.codehaus.plexus.javadoc.PlexusConfigurationTaglet"));
assertTrue(options.contains("org.codehaus.plexus.javadoc.PlexusRequirementTaglet"));
assertTrue(options.contains("org.codehaus.plexus.javadoc.PlexusComponentTaglet"));
}
Aggregations