Search in sources :

Example 1 with ParentHierarchyEntry

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

the class LifecycleMappingDialog method selectionChanged.

@Override
public void selectionChanged(SelectionChangedEvent event) {
    ParentHierarchyEntry project = pomComposite.fromSelection();
    if (getButton(OK) != null) {
        getButton(OK).setEnabled(project != null && project.getResource() != null);
    }
    updateStatus(project);
}
Also used : ParentHierarchyEntry(org.eclipse.m2e.core.ui.internal.util.ParentHierarchyEntry)

Example 2 with ParentHierarchyEntry

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

the class ExcludeArtifactRefactoring method getWorkspaceAncestors.

private Collection<ParentHierarchyEntry> getWorkspaceAncestors() {
    List<ParentHierarchyEntry> ancestors = new ArrayList<>();
    boolean add = false;
    for (ParentHierarchyEntry project : getHierarchy()) {
        if (project == exclusionPoint) {
            add = !add;
        } else if (add) {
            if (project.getFacade() != null) {
                ancestors.add(project);
            }
        }
    }
    return ancestors;
}
Also used : ParentHierarchyEntry(org.eclipse.m2e.core.ui.internal.util.ParentHierarchyEntry) ArrayList(java.util.ArrayList)

Example 3 with ParentHierarchyEntry

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

the class ExcludeWizardPage method updateState.

private void updateState() {
    ParentHierarchyEntry project;
    if (hierarchy.getSelection()) {
        project = pomHierarchy.fromSelection();
    } else {
        project = pomHierarchy.getProject();
    }
    updateStatusBar(project);
    getRefactoring().setExclusionPoint(project);
}
Also used : ParentHierarchyEntry(org.eclipse.m2e.core.ui.internal.util.ParentHierarchyEntry)

Example 4 with ParentHierarchyEntry

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

the class LifecycleMappingDialog method locatePlugin.

private ParentHierarchyEntry locatePlugin() {
    // if we got here, facade.getMavenProject cannot be null
    MavenProject project = facade.getMavenProject();
    Plugin plugin = project.getPlugin(pluginGroupId + ":" + pluginArtifactId);
    if (plugin == null) {
        // can't really happy
        return null;
    }
    InputLocation location = plugin.getLocation("");
    if (location == null || location.getSource() == null || location.getSource().getLocation() == null) {
        // that's odd. where does this come from???
        return null;
    }
    // should be canonical file already
    File basedir = new File(location.getSource().getLocation()).getParentFile();
    for (ParentHierarchyEntry other : pomComposite.getHierarchy()) {
        if (basedir.equals(other.getFile().getParentFile())) {
            return other;
        }
    }
    return null;
}
Also used : ParentHierarchyEntry(org.eclipse.m2e.core.ui.internal.util.ParentHierarchyEntry) InputLocation(org.apache.maven.model.InputLocation) MavenProject(org.apache.maven.project.MavenProject) File(java.io.File) IFile(org.eclipse.core.resources.IFile) Plugin(org.apache.maven.model.Plugin) MavenPlugin(org.eclipse.m2e.core.MavenPlugin)

Example 5 with ParentHierarchyEntry

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

the class ExcludeArtifactRefactoring method checkFinalConditions0.

RefactoringStatus checkFinalConditions0(IProgressMonitor pm) throws CoreException, OperationCanceledException {
    if (hierarchy == null || exclusionPoint == null) {
        return RefactoringStatus.createFatalErrorStatus(Messages.ExcludeArtifactRefactoring_unableToLocateProject);
    }
    changes = new ArrayList<>();
    Set<ArtifactKey> locatedKeys = new HashSet<>();
    List<IStatus> statuses = new ArrayList<>();
    SubMonitor monitor = SubMonitor.convert(pm, 3);
    List<Operation> exclusionOp = new ArrayList<>();
    // Exclusion point
    for (Entry<Dependency, Set<ArtifactKey>> entry : getDependencyExcludes(exclusionPoint, monitor.newChild(1)).entrySet()) {
        locatedKeys.addAll(entry.getValue());
        Dependency dependency = entry.getKey();
        if (contains(entry.getValue(), dependency)) {
            exclusionOp.add(new RemoveDependencyOperation(dependency));
        } else {
            for (ArtifactKey key : entry.getValue()) {
                if (!hasExclusion(exclusionPoint, dependency, key)) {
                    exclusionOp.add(new AddExclusionOperation(dependency, key));
                }
            }
        }
    }
    // Below exclusion point - pull up dependency to exclusion point
    for (ParentHierarchyEntry project : getWorkspaceDescendants()) {
        List<Operation> operations = new ArrayList<>();
        for (Entry<Dependency, Set<ArtifactKey>> entry : getDependencyExcludes(project, monitor.newChild(1)).entrySet()) {
            locatedKeys.addAll(entry.getValue());
            Dependency dependency = entry.getKey();
            operations.add(new RemoveDependencyOperation(dependency));
            if (!contains(entry.getValue(), dependency)) {
                if (!hasDependency(exclusionPoint, dependency)) {
                    exclusionOp.add(new AddDependencyOperation(dependency));
                }
                for (ArtifactKey key : entry.getValue()) {
                    if (!hasExclusion(exclusionPoint, dependency, key)) {
                        exclusionOp.add(new AddExclusionOperation(dependency, key));
                    }
                }
            }
        }
        if (operations.size() > 0) {
            IFile pom = project.getResource();
            changes.add(PomHelper.createChange(pom, new CompoundOperation(operations.toArray(new Operation[operations.size()])), getName(pom)));
        }
    }
    // Above exclusion - Add dep to exclusionPoint
    for (ParentHierarchyEntry project : getWorkspaceAncestors()) {
        for (Entry<Dependency, Set<ArtifactKey>> entry : getDependencyExcludes(project, monitor.newChild(1)).entrySet()) {
            locatedKeys.addAll(entry.getValue());
            Dependency dependency = entry.getKey();
            if (contains(entry.getValue(), dependency)) {
                IFile pom = project.getResource();
                if (pom != null) {
                    statuses.add(new Status(IStatus.INFO, PLUGIN_ID, NLS.bind(Messages.ExcludeArtifactRefactoring_removeDependencyFrom, toString(dependency), pom.getFullPath())));
                    changes.add(PomHelper.createChange(pom, new RemoveDependencyOperation(dependency), getName(pom)));
                }
            } else {
                exclusionOp.add(new AddDependencyOperation(dependency));
                for (ArtifactKey key : entry.getValue()) {
                    if (!hasExclusion(exclusionPoint, dependency, key)) {
                        exclusionOp.add(new AddExclusionOperation(dependency, key));
                    }
                }
            }
        }
    }
    if (!exclusionOp.isEmpty()) {
        IFile pom = exclusionPoint.getResource();
        changes.add(PomHelper.createChange(pom, new CompoundOperation(exclusionOp.toArray(new Operation[exclusionOp.size()])), getName(pom)));
    }
    if (statuses.size() == 1) {
        return RefactoringStatus.create(statuses.get(0));
    } else if (statuses.size() > 1) {
        return RefactoringStatus.create(new MultiStatus(PLUGIN_ID, 0, statuses.toArray(new IStatus[statuses.size()]), Messages.ExcludeArtifactRefactoring_errorCreatingRefactoring, null));
    } else if (locatedKeys.isEmpty()) {
        return RefactoringStatus.createFatalErrorStatus(Messages.ExcludeArtifactRefactoring_noTargets);
    } else if (locatedKeys.size() != excludes.length) {
        StringBuilder sb = new StringBuilder();
        for (ArtifactKey key : excludes) {
            if (!locatedKeys.contains(key)) {
                sb.append(key.toString()).append(',');
            }
        }
        sb.deleteCharAt(sb.length() - 1);
        return RefactoringStatus.createErrorStatus(NLS.bind(Messages.ExcludeArtifactRefactoring_failedToLocateArtifact, sb.toString()));
    }
    return new RefactoringStatus();
}
Also used : ParentHierarchyEntry(org.eclipse.m2e.core.ui.internal.util.ParentHierarchyEntry) MultiStatus(org.eclipse.core.runtime.MultiStatus) IStatus(org.eclipse.core.runtime.IStatus) RefactoringStatus(org.eclipse.ltk.core.refactoring.RefactoringStatus) Status(org.eclipse.core.runtime.Status) IStatus(org.eclipse.core.runtime.IStatus) ArtifactKey(org.eclipse.m2e.core.embedder.ArtifactKey) HashSet(java.util.HashSet) Set(java.util.Set) IFile(org.eclipse.core.resources.IFile) AddDependencyOperation(org.eclipse.m2e.core.ui.internal.editing.AddDependencyOperation) RemoveDependencyOperation(org.eclipse.m2e.core.ui.internal.editing.RemoveDependencyOperation) ArrayList(java.util.ArrayList) SubMonitor(org.eclipse.core.runtime.SubMonitor) MultiStatus(org.eclipse.core.runtime.MultiStatus) RefactoringStatus(org.eclipse.ltk.core.refactoring.RefactoringStatus) AddExclusionOperation(org.eclipse.m2e.core.ui.internal.editing.AddExclusionOperation) AddDependencyOperation(org.eclipse.m2e.core.ui.internal.editing.AddDependencyOperation) RemoveDependencyOperation(org.eclipse.m2e.core.ui.internal.editing.RemoveDependencyOperation) CompoundOperation(org.eclipse.m2e.core.ui.internal.editing.PomEdits.CompoundOperation) Operation(org.eclipse.m2e.core.ui.internal.editing.PomEdits.Operation) Dependency(org.apache.maven.model.Dependency) CompoundOperation(org.eclipse.m2e.core.ui.internal.editing.PomEdits.CompoundOperation) AddExclusionOperation(org.eclipse.m2e.core.ui.internal.editing.AddExclusionOperation) HashSet(java.util.HashSet)

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