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);
}
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;
}
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);
}
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;
}
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();
}
Aggregations