Search in sources :

Example 51 with IMavenProjectFacade

use of org.eclipse.m2e.core.project.IMavenProjectFacade 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;
        }
    };
}
Also used : ArtifactKey(org.eclipse.m2e.core.embedder.ArtifactKey) Arrays(java.util.Arrays) IFolder(org.eclipse.core.resources.IFolder) ResourcesPlugin(org.eclipse.core.resources.ResourcesPlugin) AbstractBuildParticipant(org.eclipse.m2e.core.project.configurator.AbstractBuildParticipant) SubMonitor(org.eclipse.core.runtime.SubMonitor) AbstractProjectConfigurator(org.eclipse.m2e.core.project.configurator.AbstractProjectConfigurator) Exceptions(aQute.lib.exceptions.Exceptions) HashMap(java.util.HashMap) CoreException(org.eclipse.core.runtime.CoreException) ArrayList(java.util.ArrayList) IStatus(org.eclipse.core.runtime.IStatus) IProject(org.eclipse.core.resources.IProject) MavenProject(org.apache.maven.project.MavenProject) IPath(org.eclipse.core.runtime.IPath) LocalArtifactRepository(org.apache.maven.repository.LocalArtifactRepository) IResourceDelta(org.eclipse.core.resources.IResourceDelta) Map(java.util.Map) Artifact(org.apache.maven.artifact.Artifact) IMarker(org.eclipse.core.resources.IMarker) WorkspaceRepository(org.eclipse.aether.repository.WorkspaceRepository) MojoExecutionKey(org.eclipse.m2e.core.project.configurator.MojoExecutionKey) Job(org.eclipse.core.runtime.jobs.Job) IMavenProjectFacade(org.eclipse.m2e.core.project.IMavenProjectFacade) IPluginExecutionMetadata(org.eclipse.m2e.core.lifecyclemapping.model.IPluginExecutionMetadata) FULL_BUILD(org.eclipse.core.resources.IncrementalProjectBuilder.FULL_BUILD) MojoExecution(org.apache.maven.plugin.MojoExecution) Set(java.util.Set) Status(org.eclipse.core.runtime.Status) MojoExecutionBuildParticipant(org.eclipse.m2e.core.project.configurator.MojoExecutionBuildParticipant) POST_BUILD(org.eclipse.core.resources.IResourceChangeEvent.POST_BUILD) File(java.io.File) WorkspaceReader(org.eclipse.aether.repository.WorkspaceReader) IResourceChangeEvent(org.eclipse.core.resources.IResourceChangeEvent) IProgressMonitor(org.eclipse.core.runtime.IProgressMonitor) IJavaModelMarker(org.eclipse.jdt.core.IJavaModelMarker) WorkspaceJob(org.eclipse.core.resources.WorkspaceJob) List(java.util.List) IMavenExecutionContext(org.eclipse.m2e.core.embedder.IMavenExecutionContext) ICallable(org.eclipse.m2e.core.embedder.ICallable) IResource(org.eclipse.core.resources.IResource) Path(org.eclipse.core.runtime.Path) IResourceChangeListener(org.eclipse.core.resources.IResourceChangeListener) MavenPlugin(org.eclipse.m2e.core.MavenPlugin) ProjectConfigurationRequest(org.eclipse.m2e.core.project.configurator.ProjectConfigurationRequest) IMaven(org.eclipse.m2e.core.embedder.IMaven) IPath(org.eclipse.core.runtime.IPath) SubMonitor(org.eclipse.core.runtime.SubMonitor) IProject(org.eclipse.core.resources.IProject) IProgressMonitor(org.eclipse.core.runtime.IProgressMonitor) MavenProject(org.apache.maven.project.MavenProject) CoreException(org.eclipse.core.runtime.CoreException) IMavenExecutionContext(org.eclipse.m2e.core.embedder.IMavenExecutionContext) IMarker(org.eclipse.core.resources.IMarker) IMaven(org.eclipse.m2e.core.embedder.IMaven) MojoExecutionBuildParticipant(org.eclipse.m2e.core.project.configurator.MojoExecutionBuildParticipant) IFolder(org.eclipse.core.resources.IFolder)

Example 52 with IMavenProjectFacade

use of org.eclipse.m2e.core.project.IMavenProjectFacade in project bndtools by bndtools.

the class MavenWorkspaceRepository method versions.

@Override
public SortedSet<Version> versions(String bsn) throws Exception {
    if (!inited) {
        init();
    }
    Version version = null;
    final IMavenProjectFacade projectFacade = bsnMap.get(bsn);
    if (projectFacade != null) {
        File bundleFile = guessBundleFile(projectFacade);
        if (bundleFile == null || !bundleFile.exists()) {
            MavenProject mavenProject = getMavenProject(projectFacade, new NullProgressMonitor());
            bundleFile = getBundleFile(mavenProject);
        }
        if (bundleFile != null && bundleFile.exists()) {
            Domain domain = Domain.domain(bundleFile);
            version = new Version(domain.getBundleVersion());
        }
    }
    if (version == null) {
        return SortedList.empty();
    }
    return new SortedList<Version>(version);
}
Also used : NullProgressMonitor(org.eclipse.core.runtime.NullProgressMonitor) MavenProject(org.apache.maven.project.MavenProject) Version(aQute.bnd.version.Version) SortedList(aQute.lib.collections.SortedList) IMavenProjectFacade(org.eclipse.m2e.core.project.IMavenProjectFacade) Domain(aQute.bnd.osgi.Domain) File(java.io.File)

Aggregations

IMavenProjectFacade (org.eclipse.m2e.core.project.IMavenProjectFacade)52 MavenProject (org.apache.maven.project.MavenProject)21 NullProgressMonitor (org.eclipse.core.runtime.NullProgressMonitor)19 IProject (org.eclipse.core.resources.IProject)18 CoreException (org.eclipse.core.runtime.CoreException)18 IPath (org.eclipse.core.runtime.IPath)14 IFile (org.eclipse.core.resources.IFile)12 File (java.io.File)11 IProgressMonitor (org.eclipse.core.runtime.IProgressMonitor)10 Path (org.eclipse.core.runtime.Path)10 IStatus (org.eclipse.core.runtime.IStatus)9 Test (org.junit.Test)9 MavenPlugin (org.eclipse.m2e.core.MavenPlugin)6 Plugin (org.apache.maven.model.Plugin)5 IFolder (org.eclipse.core.resources.IFolder)5 ICallable (org.eclipse.m2e.core.embedder.ICallable)5 IMavenExecutionContext (org.eclipse.m2e.core.embedder.IMavenExecutionContext)5 FacetedMavenProject (com.liferay.ide.maven.core.FacetedMavenProject)4 ArrayList (java.util.ArrayList)4 IMavenProjectRegistry (org.eclipse.m2e.core.project.IMavenProjectRegistry)4