Search in sources :

Example 46 with IMavenProjectFacade

use of org.eclipse.m2e.core.project.IMavenProjectFacade in project liferay-ide by liferay.

the class BuildServiceGoalAction method updateProject.

@Override
protected void updateProject(IProject p, IProgressMonitor monitor) {
    MavenProjectBuilder builder = new MavenProjectBuilder(p);
    try {
        IMavenProjectFacade projectFacade = MavenUtil.getProjectFacade(p, monitor);
        builder.refreshSiblingProject(projectFacade, monitor);
    } catch (CoreException ce) {
        LiferayMavenUI.logError("Unable to refresh sibling project", ce);
    }
}
Also used : MavenProjectBuilder(com.liferay.ide.maven.core.MavenProjectBuilder) CoreException(org.eclipse.core.runtime.CoreException) IMavenProjectFacade(org.eclipse.m2e.core.project.IMavenProjectFacade)

Example 47 with IMavenProjectFacade

use of org.eclipse.m2e.core.project.IMavenProjectFacade 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;
        }
    };
}
Also used : Arrays(java.util.Arrays) MavenExecutionPlan(org.apache.maven.lifecycle.MavenExecutionPlan) IFolder(org.eclipse.core.resources.IFolder) AbstractBuildParticipant(org.eclipse.m2e.core.project.configurator.AbstractBuildParticipant) SubMonitor(org.eclipse.core.runtime.SubMonitor) AbstractProjectConfigurator(org.eclipse.m2e.core.project.configurator.AbstractProjectConfigurator) CoreException(org.eclipse.core.runtime.CoreException) AtomicReference(java.util.concurrent.atomic.AtomicReference) ProjectRegistryManager(org.eclipse.m2e.core.internal.project.registry.ProjectRegistryManager) ArrayList(java.util.ArrayList) ResolverConfiguration(org.eclipse.m2e.core.project.ResolverConfiguration) IStatus(org.eclipse.core.runtime.IStatus) Component(org.osgi.service.component.annotations.Component) MavenPluginActivator(org.eclipse.m2e.core.internal.MavenPluginActivator) IProject(org.eclipse.core.resources.IProject) MavenProject(org.apache.maven.project.MavenProject) IPath(org.eclipse.core.runtime.IPath) Jar(aQute.bnd.osgi.Jar) IMarker(org.eclipse.core.resources.IMarker) ILogger(org.bndtools.api.ILogger) Analyzer(aQute.bnd.osgi.Analyzer) Job(org.eclipse.core.runtime.jobs.Job) IMavenProjectFacade(org.eclipse.m2e.core.project.IMavenProjectFacade) IPluginExecutionMetadata(org.eclipse.m2e.core.lifecyclemapping.model.IPluginExecutionMetadata) Collection(java.util.Collection) MojoExecution(org.apache.maven.plugin.MojoExecution) BndProjectInfo(org.bndtools.build.api.IProjectDecorator.BndProjectInfo) Set(java.util.Set) Status(org.eclipse.core.runtime.Status) MojoExecutionBuildParticipant(org.eclipse.m2e.core.project.configurator.MojoExecutionBuildParticipant) File(java.io.File) IProgressMonitor(org.eclipse.core.runtime.IProgressMonitor) IJavaModelMarker(org.eclipse.jdt.core.IJavaModelMarker) WorkspaceJob(org.eclipse.core.resources.WorkspaceJob) AbstractBuildParticipant2(org.eclipse.m2e.core.project.configurator.AbstractBuildParticipant2) List(java.util.List) IMavenExecutionContext(org.eclipse.m2e.core.embedder.IMavenExecutionContext) Packages(aQute.bnd.osgi.Packages) ICallable(org.eclipse.m2e.core.embedder.ICallable) IResource(org.eclipse.core.resources.IResource) Path(org.eclipse.core.runtime.Path) MavenPlugin(org.eclipse.m2e.core.MavenPlugin) Logger(org.bndtools.api.Logger) IProjectDecorator(org.bndtools.build.api.IProjectDecorator) ProjectConfigurationRequest(org.eclipse.m2e.core.project.configurator.ProjectConfigurationRequest) Reference(org.osgi.service.component.annotations.Reference) IMaven(org.eclipse.m2e.core.embedder.IMaven) IPath(org.eclipse.core.runtime.IPath) WorkspaceJob(org.eclipse.core.resources.WorkspaceJob) SubMonitor(org.eclipse.core.runtime.SubMonitor) IProject(org.eclipse.core.resources.IProject) IProgressMonitor(org.eclipse.core.runtime.IProgressMonitor) MavenProject(org.apache.maven.project.MavenProject) IMarker(org.eclipse.core.resources.IMarker) Job(org.eclipse.core.runtime.jobs.Job) WorkspaceJob(org.eclipse.core.resources.WorkspaceJob) MojoExecutionBuildParticipant(org.eclipse.m2e.core.project.configurator.MojoExecutionBuildParticipant) IFolder(org.eclipse.core.resources.IFolder)

Example 48 with IMavenProjectFacade

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

the class MavenImplicitProjectRepository method getOutputFile.

private File getOutputFile(IClasspathAttribute[] extraAttributes) {
    String groupId = null, artifactId = null, version = null;
    for (IClasspathAttribute attribute : extraAttributes) {
        if ("maven.groupId".equals(attribute.getName())) {
            groupId = attribute.getValue();
        } else if ("maven.artifactId".equals(attribute.getName())) {
            artifactId = attribute.getValue();
        } else if ("maven.version".equals(attribute.getName())) {
            version = attribute.getValue();
        }
    }
    IMavenProjectFacade mavenProjectFacade = mavenProjectRegistry.getMavenProject(groupId, artifactId, version);
    return guessBundleFile(mavenProjectFacade);
}
Also used : IClasspathAttribute(org.eclipse.jdt.core.IClasspathAttribute) IMavenProjectFacade(org.eclipse.m2e.core.project.IMavenProjectFacade)

Example 49 with IMavenProjectFacade

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

the class MavenWorkspaceRepository method init.

private void init() {
    inited = true;
    final IProgressMonitor monitor = new NullProgressMonitor();
    for (IMavenProjectFacade projectFacade : mavenProjectRegistry.getProjects()) {
        try {
            String bsnGuess = guessBsnFromProjectFacade(projectFacade);
            if (bsnGuess != null) {
                bsnMap.put(bsnGuess, projectFacade);
            } else {
                MavenProject mavenProject = getMavenProject(projectFacade, monitor);
                String bsn = getBsnFromMavenProject(mavenProject);
                if (bsn != null) {
                    bsnMap.put(bsn, projectFacade);
                }
            }
        } catch (Exception e) {
            logger.logError("Unable to get bundle symbolic name for " + projectFacade.getProject().getName(), e);
        }
    }
    mavenProjectRegistry.addMavenProjectChangedListener(this);
}
Also used : NullProgressMonitor(org.eclipse.core.runtime.NullProgressMonitor) IProgressMonitor(org.eclipse.core.runtime.IProgressMonitor) MavenProject(org.apache.maven.project.MavenProject) IMavenProjectFacade(org.eclipse.m2e.core.project.IMavenProjectFacade) CoreException(org.eclipse.core.runtime.CoreException) IOException(java.io.IOException)

Example 50 with IMavenProjectFacade

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

the class MavenWorkspaceRepository method get.

@Override
public File get(final String bsn, final Version version, Map<String, String> properties, final DownloadListener... listeners) throws Exception {
    if (!inited) {
        init();
    }
    final IMavenProjectFacade projectFacade = bsnMap.get(bsn);
    if (projectFacade == null) {
        return null;
    }
    // add the eclipse project that this comes from so we can look it up in the launch
    // see bndtools.launch.BndDependencySourceContainer.createSourceContainers()
    final String projectName = projectFacade.getProject().getName();
    properties.put("sourceProjectName", projectName);
    File bundleFile = guessBundleFile(projectFacade);
    if (bundleFile == null || !bundleFile.exists()) {
        MavenProject mavenProject = getMavenProject(projectFacade, new NullProgressMonitor());
        bundleFile = getBundleFile(mavenProject);
    }
    if (!bundleFile.exists()) {
        for (DownloadListener listener : listeners) {
            try {
                listener.failure(bundleFile, "Could not get bundle file for " + bsn + ":" + version);
            } catch (Throwable t) {
                logger.logError("Download listener error", t);
            }
        }
        return null;
    }
    for (DownloadListener listener : listeners) {
        try {
            listener.success(bundleFile);
        } catch (Throwable t) {
            logger.logError("Download listener error", t);
        }
    }
    return bundleFile;
}
Also used : NullProgressMonitor(org.eclipse.core.runtime.NullProgressMonitor) MavenProject(org.apache.maven.project.MavenProject) IMavenProjectFacade(org.eclipse.m2e.core.project.IMavenProjectFacade) 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