use of org.apache.maven.plugin.MojoExecution in project liferay-ide by liferay.
the class MavenProjectBuilder method execJarMojo.
public IStatus execJarMojo(IMavenProjectFacade projectFacade, IProgressMonitor monitor) throws CoreException {
IStatus retval = null;
ICallable<IStatus> callable = new ICallable<IStatus>() {
public IStatus call(IMavenExecutionContext context, IProgressMonitor monitor) throws CoreException {
MavenProject mavenProject = projectFacade.getMavenProject();
if (mavenProject == null) {
mavenProject = projectFacade.getMavenProject(monitor);
}
IMaven maven = MavenPlugin.getMaven();
MavenExecutionPlan plan = maven.calculateExecutionPlan(mavenProject, Arrays.asList("jar:jar"), true, monitor);
List<MojoExecution> mojoExecutions = plan.getMojoExecutions();
if (mojoExecutions != null) {
for (MojoExecution mojoExecution : mojoExecutions) {
MavenPlugin.getMaven().execute(mavenProject, mojoExecution, monitor);
}
}
return Status.OK_STATUS;
}
};
retval = executeMaven(projectFacade, callable, monitor);
return retval;
}
use of org.apache.maven.plugin.MojoExecution in project fabric8-maven-plugin by fabric8io.
the class GoalFinder method checkGoalInPhase.
private boolean checkGoalInPhase(MavenProject project, MavenSession session, String goal, String phase) throws MojoExecutionException {
Lifecycle lifecycle = defaultLifeCycles.get(phase);
if (lifecycle == null) {
throw new MojoExecutionException("Cannot find lifecycle phase " + phase);
}
LifecycleMappingDelegate delegate = findDelegate(lifecycle);
try {
Map<String, List<MojoExecution>> executionsMap = delegate.calculateLifecycleMappings(session, project, lifecycle, phase);
boolean foundPhase = false;
boolean foundGoal = false;
for (String p : lifecycle.getPhases()) {
List<MojoExecution> executions = executionsMap.get(p);
if (executions != null) {
for (MojoExecution execution : executions) {
MojoDescriptor desc = execution.getMojoDescriptor();
if (desc != null && desc.getFullGoalName().equals(goal)) {
foundGoal = true;
break;
}
}
}
if (phase.equals(p)) {
foundPhase = true;
break;
}
}
return foundPhase && foundGoal;
} catch (Exception e) {
throw new MojoExecutionException("Interna: Cannot extract executions", e);
}
}
use of org.apache.maven.plugin.MojoExecution in project m2e-nar by maven-nar.
the class MavenUtils method buildTestCompileNarExecutions.
public static List<NarExecution> buildTestCompileNarExecutions(final ConfiguratorContext context, final IMavenProjectFacade facade, final IProgressMonitor monitor) throws CoreException {
List<NarExecution> narExecutions = new ArrayList<NarExecution>();
List<MojoExecution> testCompileExecutions = MavenUtils.getTestCompileExecutions(context, facade, monitor);
for (MojoExecution testCompileExecution : testCompileExecutions) {
NarExecution narSettings = MavenUtils.readTestCompileSettings(context, facade, testCompileExecution, monitor);
narExecutions.add(narSettings);
}
return narExecutions;
}
use of org.apache.maven.plugin.MojoExecution in project antlr4 by tunnelvisionlabs.
the class Antlr4MojoTest method importsCustomLayout.
@Test
public void importsCustomLayout() throws Exception {
File baseDir = resources.getBasedir("importsCustom");
File antlrDir = new File(baseDir, "src/main/antlr4");
File generatedSources = new File(baseDir, "src/main/java");
File genTestLexer = new File(generatedSources, "foo/TestLexer.java");
File genTestParser = new File(generatedSources, "foo/TestParser.java");
File genHello = new File(generatedSources, "foo/HelloParser.java");
File baseGrammar = new File(antlrDir, "imports/TestBaseLexer.g4");
File lexerGrammar = new File(antlrDir, "TestLexer.g4");
File parserGrammar = new File(antlrDir, "TestParser.g4");
Xpp3Dom outputDirectory = TestMavenRuntime.newParameter("outputDirectory", "src/main/java/foo");
Xpp3Dom arguments = new Xpp3Dom("arguments");
arguments.addChild(TestMavenRuntime.newParameter("argument", "-package"));
arguments.addChild(TestMavenRuntime.newParameter("argument", "foo"));
MavenProject project = maven.readMavenProject(baseDir);
MavenSession session = maven.newMavenSession(project);
MojoExecution exec = maven.newMojoExecution("antlr4", outputDirectory, arguments);
// //////////////////////////////////////////////////////////////////////
// 1st - all grammars have to be processed
// //////////////////////////////////////////////////////////////////////
assertFalse(genHello.exists());
assertFalse(genTestParser.exists());
assertFalse(genTestLexer.exists());
maven.executeMojo(session, project, exec);
assertTrue(genHello.isFile());
assertTrue(genTestParser.isFile());
assertTrue(genTestLexer.isFile());
// //////////////////////////////////////////////////////////////////////
// 2nd - nothing has been modified, no grammars have to be processed
// //////////////////////////////////////////////////////////////////////
{
byte[] testLexerSum = checksum(genTestLexer);
byte[] testParserSum = checksum(genTestParser);
byte[] helloSum = checksum(genHello);
maven.executeMojo(session, project, exec);
assertTrue(Arrays.equals(testLexerSum, checksum(genTestLexer)));
assertTrue(Arrays.equals(testParserSum, checksum(genTestParser)));
assertTrue(Arrays.equals(helloSum, checksum(genHello)));
}
// //////////////////////////////////////////////////////////////////////
// 3rd - the imported grammar changed, every dependency has to be processed
// //////////////////////////////////////////////////////////////////////
// modify the grammar to make checksum comparison detect a change
Change change = Change.of(baseGrammar, "DOT: '.' ;");
try {
byte[] testLexerSum = checksum(genTestLexer);
byte[] testParserSum = checksum(genTestParser);
byte[] helloSum = checksum(genHello);
maven.executeMojo(session, project, exec);
assertFalse(Arrays.equals(testLexerSum, checksum(genTestLexer)));
assertFalse(Arrays.equals(testParserSum, checksum(genTestParser)));
assertTrue(Arrays.equals(helloSum, checksum(genHello)));
} finally {
change.close();
}
// //////////////////////////////////////////////////////////////////////
// 4th - the lexer grammar changed, the parser grammar has to be processed as well
// //////////////////////////////////////////////////////////////////////
// modify the grammar to make checksum comparison detect a change
change = Change.of(lexerGrammar, "fragment DOT : '.';");
try {
byte[] testLexerSum = checksum(genTestLexer);
byte[] testParserSum = checksum(genTestParser);
byte[] helloSum = checksum(genHello);
maven.executeMojo(session, project, exec);
assertFalse(Arrays.equals(testLexerSum, checksum(genTestLexer)));
assertFalse(Arrays.equals(testParserSum, checksum(genTestParser)));
assertTrue(Arrays.equals(helloSum, checksum(genHello)));
} finally {
change.close();
}
// //////////////////////////////////////////////////////////////////////
// 5th - the parser grammar changed, no other grammars have to be processed
// //////////////////////////////////////////////////////////////////////
// modify the grammar to make checksum comparison detect a change
change = Change.of(parserGrammar, " t : WS* ;");
try {
byte[] testLexerSum = checksum(genTestLexer);
byte[] testParserSum = checksum(genTestParser);
byte[] helloSum = checksum(genHello);
maven.executeMojo(session, project, exec);
assumeTrue(Arrays.equals(testLexerSum, checksum(genTestLexer)));
assertFalse(Arrays.equals(testParserSum, checksum(genTestParser)));
assertTrue(Arrays.equals(helloSum, checksum(genHello)));
} finally {
change.close();
}
}
use of org.apache.maven.plugin.MojoExecution in project bndtools by bndtools.
the class BndConfigurator method getBuildParticipant.
@Override
public AbstractBuildParticipant getBuildParticipant(final IMavenProjectFacade projectFacade, MojoExecution execution, IPluginExecutionMetadata executionMetadata) {
return new MojoExecutionBuildParticipant(execution, true, true) {
@Override
public Set<IProject> build(int kind, IProgressMonitor monitor) throws Exception {
// build mojo like normal
final Set<IProject> build = super.build(kind, monitor);
// nothing to do if configuration build
if (kind == AbstractBuildParticipant2.PRECONFIGURE_BUILD) {
return build;
}
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 build jar
return build;
}
// now we make sure jar is built in separate job, doing this during maven builder will throw lifecycle
// errors
Job job = new WorkspaceJob("Executing " + project.getName() + " jar:jar goal") {
@Override
public IStatus runInWorkspace(IProgressMonitor monitor) throws CoreException {
SubMonitor progress = SubMonitor.convert(monitor, 3);
execJarMojo(projectFacade, progress.newChild(1, SubMonitor.SUPPRESS_NONE));
// Find the maven output directory (usually "target")
MavenProject mvnProject = getMavenProject(projectFacade, progress.newChild(1));
IPath buildDirPath = Path.fromOSString(mvnProject.getBuild().getDirectory());
IPath projectPath = project.getLocation();
IPath relativeBuildDirPath = buildDirPath.makeRelativeTo(projectPath);
IFolder buildDir = project.getFolder(relativeBuildDirPath);
if (buildDir != null) {
// TODO: there *may* be a remaining issue here if a source-generation plugin gets triggered
// by the above invocation of the jar:jar goal.
// This could cause Eclipse to think that the Java sources are dirty and queue the project
// for rebuilding, thus entering an infinite loop.
// One solution would be to find the output artifact jar and refresh ONLY that. However we
// have not been able to create the condition we
// are worried about so we are deferring any extra work on this until it's shown to be a
// real problem.
buildDir.refreshLocal(IResource.DEPTH_INFINITE, progress.newChild(1));
} else {
Logger.getLogger(BndConfigurator.class).logError(String.format("Project build folder '%s' does not exist, or is not a child of the project path '%s'", buildDirPath, projectPath), null);
progress.worked(1);
}
return Status.OK_STATUS;
}
};
job.setRule(project);
job.schedule();
return build;
}
};
}
Aggregations