Search in sources :

Example 6 with ParentHierarchyEntry

use of org.eclipse.m2e.core.ui.internal.util.ParentHierarchyEntry in project m2e-core by eclipse-m2e.

the class ManageDependenciesDialog method computeResult.

@Override
protected void computeResult() {
    final ParentHierarchyEntry currentPOM = getCurrentPOM();
    final ParentHierarchyEntry targetPOM = getTargetPOM();
    final IFile current = currentPOM.getResource();
    final IFile target = targetPOM.getResource();
    if (target == null || current == null) {
        return;
    }
    final boolean same = targetPOM.equals(currentPOM);
    final LinkedList<Dependency> modelDeps = getDependenciesList();
    /*
     * 1) Remove version values from the dependencies from the current POM
     * 2) Add dependencies to dependencyManagement of targetPOM
     */
    // First we remove the version from the original dependency
    Job perform = new Job("Updating POM file(s)") {

        @Override
        protected IStatus run(IProgressMonitor monitor) {
            try {
                if (same) {
                    performOnDOMDocument(new OperationTuple(current, new CompoundOperation(createManageOperation(modelDeps), createRemoveVersionOperation(modelDeps))));
                } else {
                    performOnDOMDocument(new OperationTuple(target, createManageOperation(modelDeps)), new OperationTuple(current, createRemoveVersionOperation(modelDeps)));
                }
            } catch (Exception e) {
                LOG.error("Error updating managed dependencies", e);
                return new Status(IStatus.ERROR, MavenEditorPlugin.PLUGIN_ID, "Error updating managed dependencies", e);
            }
            return Status.OK_STATUS;
        }
    };
    perform.setUser(false);
    perform.setSystem(true);
    perform.schedule();
}
Also used : ParentHierarchyEntry(org.eclipse.m2e.core.ui.internal.util.ParentHierarchyEntry) IStatus(org.eclipse.core.runtime.IStatus) Status(org.eclipse.core.runtime.Status) IProgressMonitor(org.eclipse.core.runtime.IProgressMonitor) IFile(org.eclipse.core.resources.IFile) OperationTuple(org.eclipse.m2e.core.ui.internal.editing.PomEdits.OperationTuple) CompoundOperation(org.eclipse.m2e.core.ui.internal.editing.PomEdits.CompoundOperation) Dependency(org.apache.maven.model.Dependency) Job(org.eclipse.core.runtime.jobs.Job)

Example 7 with ParentHierarchyEntry

use of org.eclipse.m2e.core.ui.internal.util.ParentHierarchyEntry in project m2e-core by eclipse-m2e.

the class DependenciesComposite method openManageDependenciesDialog.

void openManageDependenciesDialog() throws InvocationTargetException, InterruptedException {
    /*
     * A linked list representing the path from child to root parent pom.
     * The head is the child, the tail is the root pom
     */
    final List<ParentHierarchyEntry> hierarchy = new ArrayList<>();
    IRunnableWithProgress projectLoader = monitor -> {
        try {
            IMavenProjectRegistry projectManager = MavenPlugin.getMavenProjectRegistry();
            IMavenProjectFacade projectFacade = projectManager.create(pomEditor.getPomFile(), true, monitor);
            if (projectFacade != null) {
                hierarchy.addAll(new ParentGatherer(projectFacade).getParentHierarchy(monitor));
            }
        } catch (CoreException e) {
            throw new InvocationTargetException(e);
        }
    };
    PlatformUI.getWorkbench().getProgressService().run(false, true, projectLoader);
    if (hierarchy.isEmpty()) {
        // User has already been notified to fix the problem.
        return;
    }
    final ManageDependenciesDialog manageDepDialog = new ManageDependenciesDialog(getShell(), new ValueProvider<List<org.apache.maven.model.Dependency>>() {

        @Override
        public List<org.apache.maven.model.Dependency> getValue() {
            List<org.apache.maven.model.Dependency> toRet = new ArrayList<>();
            for (DependenciesComposite.Dependency d : getDependencies()) {
                toRet.add(toApacheDependency(d));
            }
            return toRet;
        }
    }, hierarchy, dependenciesEditor.getSelection());
    manageDepDialog.open();
}
Also used : ParentHierarchyEntry(org.eclipse.m2e.core.ui.internal.util.ParentHierarchyEntry) SYSTEM_PATH(org.eclipse.m2e.core.ui.internal.editing.PomEdits.SYSTEM_PATH) ArtifactKey(org.eclipse.m2e.core.embedder.ArtifactKey) TableViewer(org.eclipse.jface.viewers.TableViewer) SashForm(org.eclipse.swt.custom.SashForm) ParentGatherer(org.eclipse.m2e.core.ui.internal.util.ParentGatherer) LoggerFactory(org.slf4j.LoggerFactory) DependencyManagement(org.apache.maven.model.DependencyManagement) CoreException(org.eclipse.core.runtime.CoreException) PomHelper(org.eclipse.m2e.core.ui.internal.editing.PomHelper) CLASSIFIER(org.eclipse.m2e.core.ui.internal.editing.PomEdits.CLASSIFIER) PomEdits.getTextValue(org.eclipse.m2e.core.ui.internal.editing.PomEdits.getTextValue) IStatus(org.eclipse.core.runtime.IStatus) PomEdits.performOnDOMDocument(org.eclipse.m2e.core.ui.internal.editing.PomEdits.performOnDOMDocument) MavenProject(org.apache.maven.project.MavenProject) EditDependencyDialog(org.eclipse.m2e.core.ui.internal.dialogs.EditDependencyDialog) ARTIFACT_ID(org.eclipse.m2e.core.ui.internal.editing.PomEdits.ARTIFACT_ID) Composite(org.eclipse.swt.widgets.Composite) OPTIONAL(org.eclipse.m2e.core.ui.internal.editing.PomEdits.OPTIONAL) OperationTuple(org.eclipse.m2e.core.ui.internal.editing.PomEdits.OperationTuple) SCOPE(org.eclipse.m2e.core.ui.internal.editing.PomEdits.SCOPE) PomEdits.childEquals(org.eclipse.m2e.core.ui.internal.editing.PomEdits.childEquals) PomEdits.removeChild(org.eclipse.m2e.core.ui.internal.editing.PomEdits.removeChild) IAdaptable(org.eclipse.core.runtime.IAdaptable) Messages(org.eclipse.m2e.editor.internal.Messages) DEPENDENCY_MANAGEMENT(org.eclipse.m2e.core.ui.internal.editing.PomEdits.DEPENDENCY_MANAGEMENT) Button(org.eclipse.swt.widgets.Button) PlatformUI(org.eclipse.ui.PlatformUI) MavenPomEditor(org.eclipse.m2e.editor.pom.MavenPomEditor) MavenPomEditorPage(org.eclipse.m2e.editor.pom.MavenPomEditorPage) Status(org.eclipse.core.runtime.Status) Display(org.eclipse.swt.widgets.Display) MavenEditorPlugin(org.eclipse.m2e.editor.MavenEditorPlugin) IMavenProjectRegistry(org.eclipse.m2e.core.project.IMavenProjectRegistry) InvocationTargetException(java.lang.reflect.InvocationTargetException) IProgressMonitor(org.eclipse.core.runtime.IProgressMonitor) List(java.util.List) Window(org.eclipse.jface.window.Window) PomEdits.removeIfNoChildElement(org.eclipse.m2e.core.ui.internal.editing.PomEdits.removeIfNoChildElement) SWT(org.eclipse.swt.SWT) ISelection(org.eclipse.jface.viewers.ISelection) DEPENDENCY(org.eclipse.m2e.core.ui.internal.editing.PomEdits.DEPENDENCY) IStructuredSelection(org.eclipse.jface.viewers.IStructuredSelection) SelectionListener(org.eclipse.swt.events.SelectionListener) ExpandableComposite(org.eclipse.ui.forms.widgets.ExpandableComposite) PomEdits.findChilds(org.eclipse.m2e.core.ui.internal.editing.PomEdits.findChilds) TYPE(org.eclipse.m2e.core.ui.internal.editing.PomEdits.TYPE) WorkbenchJob(org.eclipse.ui.progress.WorkbenchJob) PomEdits.getChild(org.eclipse.m2e.core.ui.internal.editing.PomEdits.getChild) ArrayList(java.util.ArrayList) DelegatingStyledCellLabelProvider(org.eclipse.jface.viewers.DelegatingStyledCellLabelProvider) VERSION(org.eclipse.m2e.core.ui.internal.editing.PomEdits.VERSION) GROUP_ID(org.eclipse.m2e.core.ui.internal.editing.PomEdits.GROUP_ID) MavenRepositorySearchDialog(org.eclipse.m2e.core.ui.internal.dialogs.MavenRepositorySearchDialog) PomEdits.findChild(org.eclipse.m2e.core.ui.internal.editing.PomEdits.findChild) GridData(org.eclipse.swt.layout.GridData) SearchMatcher(org.eclipse.m2e.editor.pom.SearchMatcher) ValueProvider(org.eclipse.m2e.editor.pom.ValueProvider) LinkedList(java.util.LinkedList) Section(org.eclipse.ui.forms.widgets.Section) SearchControl(org.eclipse.m2e.editor.pom.SearchControl) ViewerFilter(org.eclipse.jface.viewers.ViewerFilter) Logger(org.slf4j.Logger) Iterator(java.util.Iterator) Viewer(org.eclipse.jface.viewers.Viewer) Job(org.eclipse.core.runtime.jobs.Job) IMavenProjectFacade(org.eclipse.m2e.core.project.IMavenProjectFacade) FormToolkit(org.eclipse.ui.forms.widgets.FormToolkit) Action(org.eclipse.jface.action.Action) DEPENDENCIES(org.eclipse.m2e.core.ui.internal.editing.PomEdits.DEPENDENCIES) Element(org.w3c.dom.Element) IRunnableWithProgress(org.eclipse.jface.operation.IRunnableWithProgress) ParentHierarchyEntry(org.eclipse.m2e.core.ui.internal.util.ParentHierarchyEntry) ToolBarManager(org.eclipse.jface.action.ToolBarManager) MavenPlugin(org.eclipse.m2e.core.MavenPlugin) IndexedArtifactFile(org.eclipse.m2e.core.internal.index.IndexedArtifactFile) MavenEditorImages(org.eclipse.m2e.editor.MavenEditorImages) Collections(java.util.Collections) GridLayout(org.eclipse.swt.layout.GridLayout) ManageDependenciesDialog(org.eclipse.m2e.editor.dialogs.ManageDependenciesDialog) ArrayList(java.util.ArrayList) IMavenProjectRegistry(org.eclipse.m2e.core.project.IMavenProjectRegistry) ManageDependenciesDialog(org.eclipse.m2e.editor.dialogs.ManageDependenciesDialog) InvocationTargetException(java.lang.reflect.InvocationTargetException) IRunnableWithProgress(org.eclipse.jface.operation.IRunnableWithProgress) ParentGatherer(org.eclipse.m2e.core.ui.internal.util.ParentGatherer) CoreException(org.eclipse.core.runtime.CoreException) List(java.util.List) ArrayList(java.util.ArrayList) LinkedList(java.util.LinkedList) IMavenProjectFacade(org.eclipse.m2e.core.project.IMavenProjectFacade)

Example 8 with ParentHierarchyEntry

use of org.eclipse.m2e.core.ui.internal.util.ParentHierarchyEntry in project m2e-core-tests by tesla.

the class ExcludeArtifactRefactoringTest method createRefactoring.

private static ExcludeArtifactRefactoring createRefactoring(IFile pomFile, ArtifactKey[] keys, IFile exclusionPoint) throws CoreException {
    ExcludeArtifactRefactoring refactoring = new ExcludeArtifactRefactoring(keys);
    IMavenProjectFacade facade = MavenPlugin.getMavenProjectRegistry().create(pomFile, true, monitor);
    ParentGatherer g = new ParentGatherer(facade);
    List<ParentHierarchyEntry> hierarchy = g.getParentHierarchy(monitor);
    refactoring.setHierarchy(hierarchy);
    ParentHierarchyEntry exclusionModel = null;
    for (ParentHierarchyEntry model : hierarchy) {
        if (exclusionPoint.equals(model.getResource())) {
            exclusionModel = model;
            break;
        }
    }
    if (exclusionModel == null) {
        fail("Exclusion point is not present in project parent hierarchy");
    }
    refactoring.setExclusionPoint(exclusionModel);
    return refactoring;
}
Also used : ParentHierarchyEntry(org.eclipse.m2e.core.ui.internal.util.ParentHierarchyEntry) ParentGatherer(org.eclipse.m2e.core.ui.internal.util.ParentGatherer) IMavenProjectFacade(org.eclipse.m2e.core.project.IMavenProjectFacade) ExcludeArtifactRefactoring(org.eclipse.m2e.refactoring.exclude.ExcludeArtifactRefactoring)

Aggregations

ParentHierarchyEntry (org.eclipse.m2e.core.ui.internal.util.ParentHierarchyEntry)8 ArrayList (java.util.ArrayList)3 IFile (org.eclipse.core.resources.IFile)3 IStatus (org.eclipse.core.runtime.IStatus)3 Status (org.eclipse.core.runtime.Status)3 Dependency (org.apache.maven.model.Dependency)2 MavenProject (org.apache.maven.project.MavenProject)2 IProgressMonitor (org.eclipse.core.runtime.IProgressMonitor)2 Job (org.eclipse.core.runtime.jobs.Job)2 MavenPlugin (org.eclipse.m2e.core.MavenPlugin)2 ArtifactKey (org.eclipse.m2e.core.embedder.ArtifactKey)2 IMavenProjectFacade (org.eclipse.m2e.core.project.IMavenProjectFacade)2 CompoundOperation (org.eclipse.m2e.core.ui.internal.editing.PomEdits.CompoundOperation)2 OperationTuple (org.eclipse.m2e.core.ui.internal.editing.PomEdits.OperationTuple)2 ParentGatherer (org.eclipse.m2e.core.ui.internal.util.ParentGatherer)2 File (java.io.File)1 InvocationTargetException (java.lang.reflect.InvocationTargetException)1 Collections (java.util.Collections)1 HashSet (java.util.HashSet)1 Iterator (java.util.Iterator)1