use of org.apache.maven.plugin.MojoExecution in project bndtools by bndtools.
the class BndConfigurator method execJarMojo.
private void execJarMojo(final IMavenProjectFacade projectFacade, IProgressMonitor monitor) throws CoreException {
final IMaven maven = MavenPlugin.getMaven();
ProjectRegistryManager projectRegistryManager = MavenPluginActivator.getDefault().getMavenProjectManagerImpl();
ResolverConfiguration resolverConfiguration = new ResolverConfiguration();
resolverConfiguration.setResolveWorkspaceProjects(true);
IMavenExecutionContext context = projectRegistryManager.createExecutionContext(projectFacade.getPom(), resolverConfiguration);
context.execute(new ICallable<Void>() {
@Override
public Void call(IMavenExecutionContext context, IProgressMonitor monitor) throws CoreException {
SubMonitor progress = SubMonitor.convert(monitor);
MavenProject mavenProject = getMavenProject(projectFacade, progress.newChild(1));
MavenExecutionPlan plan = maven.calculateExecutionPlan(mavenProject, Arrays.asList("jar:jar"), true, monitor);
List<MojoExecution> mojoExecutions = plan.getMojoExecutions();
if (mojoExecutions != null) {
for (MojoExecution mojoExecution : mojoExecutions) {
maven.execute(mavenProject, mojoExecution, progress.newChild(1));
}
}
// We can now decorate based on the build we just did.
try {
IProjectDecorator decorator = Injector.ref.get();
if (decorator != null) {
BndProjectInfo info = new MavenProjectInfo(mavenProject);
decorator.updateDecoration(projectFacade.getProject(), info);
}
} catch (Exception e) {
logger.logError("Failed to decorate project " + projectFacade.getProject().getName(), e);
}
return null;
}
}, monitor);
}
use of org.apache.maven.plugin.MojoExecution in project bndtools by bndtools.
the class IndexConfigurator method getBuildParticipant.
/**
* We have to temporarily override the ongoing maven build by creating a new context. This allows us to replace the
* workspace repository with our own.
*/
@Override
public AbstractBuildParticipant getBuildParticipant(final IMavenProjectFacade projectFacade, MojoExecution execution, final IPluginExecutionMetadata executionMetadata) {
return new MojoExecutionBuildParticipant(execution, true, false) {
@Override
public Set<IProject> build(int kind, IProgressMonitor monitor) throws Exception {
if (appliesToBuildKind(kind)) {
final IProject project = projectFacade.getProject();
IMarker[] imarkers = project.findMarkers(IJavaModelMarker.JAVA_MODEL_PROBLEM_MARKER, false, IResource.DEPTH_INFINITE);
if (imarkers != null && Arrays.stream(imarkers).map(m -> m.getAttribute(IMarker.SEVERITY, IMarker.SEVERITY_INFO)).anyMatch(s -> s == IMarker.SEVERITY_ERROR)) {
// there are compile errors, don't index
return null;
}
final SubMonitor progress = SubMonitor.convert(monitor, "Executing indexer plugin", 2);
final IMaven maven = MavenPlugin.getMaven();
IMavenExecutionContext context = maven.createExecutionContext();
context.getExecutionRequest().setWorkspaceReader(new IndexerWorkspaceRepository());
final MavenProject mavenProject = getMavenProject(projectFacade, progress.newChild(1));
context.execute(new ICallable<Void>() {
@Override
public Void call(IMavenExecutionContext context, IProgressMonitor monitor) throws CoreException {
maven.execute(mavenProject, getMojoExecution(), monitor);
IPath buildDirPath = Path.fromOSString(mavenProject.getBuild().getDirectory());
IProject project = projectFacade.getProject();
IPath projectPath = project.getLocation();
IPath relativeBuildDirPath = buildDirPath.makeRelativeTo(projectPath);
IFolder buildDir = project.getFolder(relativeBuildDirPath);
buildDir.refreshLocal(IResource.DEPTH_INFINITE, progress.newChild(1));
return null;
}
}, progress.newChild(1));
}
return null;
}
};
}
use of org.apache.maven.plugin.MojoExecution in project antlr4 by antlr.
the class Antlr4MojoTest method importTokens.
@Test
public void importTokens() throws Exception {
Path baseDir = resources.getBasedir("importTokens").toPath();
Path antlrDir = baseDir.resolve("src/main/antlr4");
Path generatedSources = baseDir.resolve("target/generated-sources/antlr4");
Path genParser = generatedSources.resolve("test/SimpleParser.java");
Path tokens = antlrDir.resolve("imports/SimpleLexer.tokens");
MavenProject project = maven.readMavenProject(baseDir.toFile());
MavenSession session = maven.newMavenSession(project);
MojoExecution exec = maven.newMojoExecution("antlr4");
// //////////////////////////////////////////////////////////////////////
// 1st - all grammars have to be processed
// //////////////////////////////////////////////////////////////////////
assertFalse(Files.exists(genParser));
maven.executeMojo(session, project, exec);
assertTrue(Files.exists(genParser));
// //////////////////////////////////////////////////////////////////////
// 2nd - nothing has been modified, no grammars have to be processed
// //////////////////////////////////////////////////////////////////////
{
byte[] sum = checksum(genParser);
maven.executeMojo(session, project, exec);
assertTrue(Arrays.equals(sum, checksum(genParser)));
}
try (Change change = Change.of(tokens, "DOT=4")) {
byte[] sum = checksum(genParser);
maven.executeMojo(session, project, exec);
assertFalse(Arrays.equals(sum, checksum(genParser)));
}
}
use of org.apache.maven.plugin.MojoExecution in project antlr4 by antlr.
the class Antlr4MojoTest method importsStandardLayout.
@Test
public void importsStandardLayout() throws Exception {
Path baseDir = resources.getBasedir("importsStandard").toPath();
Path antlrDir = baseDir.resolve("src/main/antlr4");
Path generatedSources = baseDir.resolve("target/generated-sources/antlr4");
Path genTestLexer = generatedSources.resolve("test/TestLexer.java");
Path genTestParser = generatedSources.resolve("test/TestParser.java");
Path genHello = generatedSources.resolve("test/HelloParser.java");
Path baseGrammar = antlrDir.resolve("imports/TestBaseLexer.g4");
Path baseGrammar2 = antlrDir.resolve("imports/TestBaseLexer2.g4");
Path lexerGrammar = antlrDir.resolve("test/TestLexer.g4");
Path parserGrammar = antlrDir.resolve("test/TestParser.g4");
MavenProject project = maven.readMavenProject(baseDir.toFile());
MavenSession session = maven.newMavenSession(project);
MojoExecution exec = maven.newMojoExecution("antlr4");
// //////////////////////////////////////////////////////////////////////
// 1st - all grammars have to be processed
// //////////////////////////////////////////////////////////////////////
assertFalse(Files.exists(genHello));
assertFalse(Files.exists(genTestParser));
assertFalse(Files.exists(genTestLexer));
maven.executeMojo(session, project, exec);
assertTrue(Files.exists(genHello));
assertTrue(Files.exists(genTestParser));
assertTrue(Files.exists(genTestLexer));
byte[] origTestLexerSum = checksum(genTestLexer);
byte[] origTestParserSum = checksum(genTestParser);
byte[] origHelloSum = checksum(genHello);
// //////////////////////////////////////////////////////////////////////
// 2nd - nothing has been modified, no grammars have to be processed
// //////////////////////////////////////////////////////////////////////
{
maven.executeMojo(session, project, exec);
assertTrue(Arrays.equals(origTestLexerSum, checksum(genTestLexer)));
assertTrue(Arrays.equals(origTestParserSum, checksum(genTestParser)));
assertTrue(Arrays.equals(origHelloSum, checksum(genHello)));
}
// modify the grammar to make checksum comparison detect a change
try (Change change = Change.of(baseGrammar, "DOT: '.' ;")) {
maven.executeMojo(session, project, exec);
assertFalse(Arrays.equals(origTestLexerSum, checksum(genTestLexer)));
assertFalse(Arrays.equals(origTestParserSum, checksum(genTestParser)));
assertTrue(Arrays.equals(origHelloSum, checksum(genHello)));
}
// Restore file and confirm it was restored.
maven.executeMojo(session, project, exec);
assertTrue(Arrays.equals(origTestLexerSum, checksum(genTestLexer)));
assertTrue(Arrays.equals(origTestParserSum, checksum(genTestParser)));
assertTrue(Arrays.equals(origHelloSum, checksum(genHello)));
// modify the grammar to make checksum comparison detect a change
try (Change change = Change.of(baseGrammar2, "BANG: '!' ;")) {
maven.executeMojo(session, project, exec);
assertFalse(Arrays.equals(origTestLexerSum, checksum(genTestLexer)));
assertFalse(Arrays.equals(origTestParserSum, checksum(genTestParser)));
assertTrue(Arrays.equals(origHelloSum, checksum(genHello)));
}
// Restore file and confirm it was restored.
maven.executeMojo(session, project, exec);
assertTrue(Arrays.equals(origTestLexerSum, checksum(genTestLexer)));
assertTrue(Arrays.equals(origTestParserSum, checksum(genTestParser)));
assertTrue(Arrays.equals(origHelloSum, checksum(genHello)));
// modify the grammar to make checksum comparison detect a change
try (Change change = Change.of(lexerGrammar, "FOO: 'foo' ;")) {
maven.executeMojo(session, project, exec);
assertFalse(Arrays.equals(origTestLexerSum, checksum(genTestLexer)));
assertFalse(Arrays.equals(origTestParserSum, checksum(genTestParser)));
assertTrue(Arrays.equals(origHelloSum, checksum(genHello)));
}
// Restore file and confirm it was restored.
maven.executeMojo(session, project, exec);
assertTrue(Arrays.equals(origTestLexerSum, checksum(genTestLexer)));
assertTrue(Arrays.equals(origTestParserSum, checksum(genTestParser)));
assertTrue(Arrays.equals(origHelloSum, checksum(genHello)));
// modify the grammar to make checksum comparison detect a change
try (Change change = Change.of(parserGrammar, " t : WS* ;")) {
maven.executeMojo(session, project, exec);
assertTrue(Arrays.equals(origTestLexerSum, checksum(genTestLexer)));
assertFalse(Arrays.equals(origTestParserSum, checksum(genTestParser)));
assertTrue(Arrays.equals(origHelloSum, checksum(genHello)));
}
// Restore file and confirm it was restored.
maven.executeMojo(session, project, exec);
assertTrue(Arrays.equals(origTestLexerSum, checksum(genTestLexer)));
assertTrue(Arrays.equals(origTestParserSum, checksum(genTestParser)));
assertTrue(Arrays.equals(origHelloSum, checksum(genHello)));
}
use of org.apache.maven.plugin.MojoExecution in project maven-plugins by apache.
the class JavadocJarTest method lookupMojo.
private JavadocJar lookupMojo(File testPom) throws Exception {
JavadocJar mojo = (JavadocJar) lookupMojo("jar", testPom);
MojoExecution mojoExec = new MojoExecution(new Plugin(), "javadoc", null);
setVariableValueToObject(mojo, "mojo", mojoExec);
MavenProject currentProject = new MavenProjectStub();
currentProject.setGroupId("GROUPID");
currentProject.setArtifactId("ARTIFACTID");
setVariableValueToObject(mojo, "session", newMavenSession(currentProject));
return mojo;
}
Aggregations