Search in sources :

Example 11 with IMavenProjectFacade

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

the class MavenProjectBuilder method updateProjectDependency.

@Override
public IStatus updateProjectDependency(IProject project, List<String[]> dependencies) throws CoreException {
    IMavenProjectFacade projectFacade = MavenUtil.getProjectFacade(project, new NullProgressMonitor());
    if (projectFacade != null) {
        MavenProject mavenProject = projectFacade.getMavenProject(new NullProgressMonitor());
        List<Dependency> existedDependencies = mavenProject.getDependencies();
        IMaven maven = MavenPlugin.getMaven();
        File pomFile = new File(project.getLocation().toOSString(), IMavenConstants.POM_FILE_NAME);
        Model model = maven.readModel(pomFile);
        for (String[] dependency : dependencies) {
            Dependency de = new Dependency();
            de.setGroupId(dependency[0]);
            de.setArtifactId(dependency[1]);
            de.setVersion(dependency[2]);
            String newKey = de.getManagementKey();
            boolean existed = false;
            for (Dependency existedDependency : existedDependencies) {
                String existedKey = existedDependency.getManagementKey();
                if (existedKey.equals(newKey)) {
                    existed = true;
                    break;
                }
            }
            if ((existed == false) && (model != null)) {
                model.addDependency(de);
            }
        }
        try (OutputStream out = Files.newOutputStream(pomFile.toPath())) {
            maven.writeModel(model, out);
            out.flush();
            out.close();
            WorkspaceJob job = new WorkspaceJob("Updating project " + project.getName()) {

                public IStatus runInWorkspace(IProgressMonitor monitor) {
                    try {
                        project.refreshLocal(IResource.DEPTH_INFINITE, new NullProgressMonitor());
                        MavenPlugin.getProjectConfigurationManager().updateProjectConfiguration(project, monitor);
                    } catch (CoreException ce) {
                        return ce.getStatus();
                    }
                    return Status.OK_STATUS;
                }
            };
            job.schedule();
        } catch (Exception e) {
            return LiferayMavenCore.createErrorStatus("Error updating maven project dependency", e);
        }
    }
    return Status.OK_STATUS;
}
Also used : NullProgressMonitor(org.eclipse.core.runtime.NullProgressMonitor) OutputStream(java.io.OutputStream) WorkspaceJob(org.eclipse.core.resources.WorkspaceJob) Dependency(org.apache.maven.model.Dependency) CoreException(org.eclipse.core.runtime.CoreException) IProgressMonitor(org.eclipse.core.runtime.IProgressMonitor) MavenProject(org.apache.maven.project.MavenProject) CoreException(org.eclipse.core.runtime.CoreException) Model(org.apache.maven.model.Model) IMavenProjectFacade(org.eclipse.m2e.core.project.IMavenProjectFacade) IFile(org.eclipse.core.resources.IFile) File(java.io.File) IMaven(org.eclipse.m2e.core.embedder.IMaven)

Example 12 with IMavenProjectFacade

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

the class MavenProjectRemoteServerPublisher method publishModuleFull.

public IPath publishModuleFull(IProgressMonitor monitor) throws CoreException {
    IPath retval = null;
    if (_runMavenGoal(getProject(), monitor)) {
        IMavenProjectFacade projectFacade = MavenUtil.getProjectFacade(getProject(), monitor);
        MavenProject mavenProject = projectFacade.getMavenProject(monitor);
        String targetFolder = mavenProject.getBuild().getDirectory();
        String targetWar = mavenProject.getBuild().getFinalName() + "." + mavenProject.getPackaging();
        retval = new Path(targetFolder).append(targetWar);
    }
    return retval;
}
Also used : IPath(org.eclipse.core.runtime.IPath) Path(org.eclipse.core.runtime.Path) IPath(org.eclipse.core.runtime.IPath) MavenProject(org.apache.maven.project.MavenProject) IMavenProjectFacade(org.eclipse.m2e.core.project.IMavenProjectFacade)

Example 13 with IMavenProjectFacade

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

the class BundleProjectConfigurator method _isMavenBundlePlugin.

private boolean _isMavenBundlePlugin(IProject project) {
    NullProgressMonitor monitor = new NullProgressMonitor();
    IMavenProjectFacade facade = MavenUtil.getProjectFacade(project, monitor);
    if (facade != null) {
        try {
            MavenProject mavenProject = facade.getMavenProject(new NullProgressMonitor());
            if ((mavenProject != null) && "bundle".equals(mavenProject.getPackaging())) {
                Plugin mavenBundlePlugin = MavenUtil.getPlugin(facade, ILiferayMavenConstants.MAVEN_BUNDLE_PLUGIN_KEY, monitor);
                if (mavenBundlePlugin != null) {
                    return true;
                }
            } else if ((mavenProject != null) && "jar".equals(mavenProject.getPackaging())) {
                Plugin bndMavenPlugin = MavenUtil.getPlugin(facade, ILiferayMavenConstants.BND_MAVEN_PLUGIN_KEY, monitor);
                if (bndMavenPlugin != null) {
                    return true;
                }
            }
        } catch (CoreException ce) {
        }
    }
    return false;
}
Also used : NullProgressMonitor(org.eclipse.core.runtime.NullProgressMonitor) MavenProject(org.apache.maven.project.MavenProject) CoreException(org.eclipse.core.runtime.CoreException) IMavenProjectFacade(org.eclipse.m2e.core.project.IMavenProjectFacade) Plugin(org.apache.maven.model.Plugin)

Example 14 with IMavenProjectFacade

use of org.eclipse.m2e.core.project.IMavenProjectFacade in project m2e-nar by maven-nar.

the class BuildPathManager method updateBuildPaths.

private void updateBuildPaths(IProject project, IProgressMonitor monitor) throws CoreException {
    final IMavenProjectFacade facade = projectManager.getProject(project);
    if (facade != null) {
        final ICProjectDescriptionManager mngr = CoreModel.getDefault().getProjectDescriptionManager();
        final ICProjectDescription des = mngr.getProjectDescription(project, true);
        if (des != null) {
            boolean changed = false;
            logger.debug("updateBuildPaths: project=" + project.getName());
            final ConfiguratorContext context = new ConfiguratorContext(MavenPlugin.getMaven(), projectManager);
            List<NarExecution> narExecutions = MavenUtils.buildCompileNarExecutions(context, facade, monitor);
            narExecutions.addAll(MavenUtils.buildTestCompileNarExecutions(context, facade, monitor));
            for (NarExecution narSettings : narExecutions) {
                if (!narSettings.isSkip()) {
                    final String os = narSettings.getOS();
                    final String linkerName = narSettings.getLinkerName();
                    final AbstractSettingsSynchroniser synchro = SynchroniserFactory.getSettingsSynchroniser(os, linkerName);
                    changed = updateCdtBuildPaths(des, synchro, narSettings);
                }
            }
            if (changed) {
                mngr.setProjectDescription(project, des);
            }
        }
    }
}
Also used : ICProjectDescription(org.eclipse.cdt.core.settings.model.ICProjectDescription) ICProjectDescriptionManager(org.eclipse.cdt.core.settings.model.ICProjectDescriptionManager) AbstractSettingsSynchroniser(com.github.sdedwards.m2e_nar.internal.cdt.AbstractSettingsSynchroniser) IMavenProjectFacade(org.eclipse.m2e.core.project.IMavenProjectFacade) NarExecution(com.github.sdedwards.m2e_nar.internal.model.NarExecution)

Example 15 with IMavenProjectFacade

use of org.eclipse.m2e.core.project.IMavenProjectFacade in project m2e-nar by maven-nar.

the class CProjectConfigurator method configure.

@Override
public void configure(ProjectConfigurationRequest request, IProgressMonitor monitor) throws CoreException {
    final ConfiguratorContext context = new ConfiguratorContext(maven, projectManager);
    IProject project = request.getProject();
    monitor.setTaskName(Messages.CProjectConfigurator_task_name + project.getName());
    logger.info("configure");
    ICProjectDescriptionManager mngr = CoreModel.getDefault().getProjectDescriptionManager();
    // Set the first created configuration as active.
    boolean setActive = true;
    final IMavenProjectFacade facade = request.getMavenProjectFacade();
    List<NarExecution> narExecutions = MavenUtils.buildCompileNarExecutions(context, facade, monitor);
    narExecutions.addAll(MavenUtils.buildTestCompileNarExecutions(context, facade, monitor));
    for (NarExecution narSettings : narExecutions) {
        if (!narSettings.isSkip()) {
            final String os = narSettings.getOS();
            final String linkerName = narSettings.getLinkerName();
            final AbstractSettingsSynchroniser synchro = SynchroniserFactory.getSettingsSynchroniser(os, linkerName);
            final String toolchain = synchro.getToolchain();
            for (NarBuildArtifact artifactSettings : narSettings.getArtifactSettings()) {
                final String configName = artifactSettings.getConfigName();
                final String cdtArtefactType = CdtUtils.convertArtefactType(artifactSettings.getType());
                IToolChain tc = getToolChain(toolchain, cdtArtefactType);
                ICProjectDescription desc = getCdtProject(project, tc, cdtArtefactType, monitor);
                ICConfigurationDescription cfg = getCdtMavenConfig(project, desc, tc, cdtArtefactType, configName, setActive, monitor);
                setActive = false;
                synchro.fullSync(cfg, artifactSettings);
                mngr.setProjectDescription(project, desc);
            }
        }
    }
    AbstractProjectConfigurator jConfig = LifecycleMappingFactory.createProjectConfigurator(JAVA_CONFIGURATOR_ID);
    jConfig.configure(request, monitor);
    // ensure CDT builder is after the Maven one
    boolean changed = false;
    IProjectDescription description = project.getDescription();
    ICommand cdtBuilder = null;
    ICommand mavenBuilder = null;
    ArrayList<ICommand> newSpec = new ArrayList<ICommand>();
    for (ICommand command : description.getBuildSpec()) {
        if (ManagedCProjectNature.getBuilderID().equals(command.getBuilderName()) && mavenBuilder == null) {
            cdtBuilder = command;
        } else {
            newSpec.add(command);
        }
        if (IMavenConstants.BUILDER_ID.equals(command.getBuilderName())) {
            mavenBuilder = command;
            if (cdtBuilder != null) {
                newSpec.add(cdtBuilder);
                changed = true;
            }
        }
    }
    if (changed) {
        description.setBuildSpec(newSpec.toArray(new ICommand[newSpec.size()]));
        project.setDescription(description, monitor);
    }
}
Also used : ICProjectDescription(org.eclipse.cdt.core.settings.model.ICProjectDescription) IToolChain(org.eclipse.cdt.managedbuilder.core.IToolChain) ArrayList(java.util.ArrayList) ICProjectDescriptionManager(org.eclipse.cdt.core.settings.model.ICProjectDescriptionManager) IProject(org.eclipse.core.resources.IProject) NarBuildArtifact(com.github.sdedwards.m2e_nar.internal.model.NarBuildArtifact) ICommand(org.eclipse.core.resources.ICommand) IProjectDescription(org.eclipse.core.resources.IProjectDescription) AbstractSettingsSynchroniser(com.github.sdedwards.m2e_nar.internal.cdt.AbstractSettingsSynchroniser) AbstractProjectConfigurator(org.eclipse.m2e.core.project.configurator.AbstractProjectConfigurator) ICConfigurationDescription(org.eclipse.cdt.core.settings.model.ICConfigurationDescription) IMavenProjectFacade(org.eclipse.m2e.core.project.IMavenProjectFacade) NarExecution(com.github.sdedwards.m2e_nar.internal.model.NarExecution)

Aggregations

IMavenProjectFacade (org.eclipse.m2e.core.project.IMavenProjectFacade)54 MavenProject (org.apache.maven.project.MavenProject)21 IProject (org.eclipse.core.resources.IProject)19 NullProgressMonitor (org.eclipse.core.runtime.NullProgressMonitor)19 CoreException (org.eclipse.core.runtime.CoreException)18 IPath (org.eclipse.core.runtime.IPath)16 IFile (org.eclipse.core.resources.IFile)13 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