use of org.eclipse.m2e.core.project.configurator.MojoExecutionBuildParticipant 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;
}
};
}
use of org.eclipse.m2e.core.project.configurator.MojoExecutionBuildParticipant 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;
}
};
}
Aggregations