use of org.eclipse.m2e.core.ui.internal.editing.RemoveDependencyOperation in project m2e-core-tests by tesla.
the class RemoveDependencyOperationTest method testMissingDependency_emptyDependenciesElement.
@Test
public void testMissingDependency_emptyDependenciesElement() throws Exception {
//
document.setText(//
StructuredModelManager.getModelManager(), //
"<project><dependencies>" + "</dependencies></project>");
PomEdits.performOnDOMDocument(new OperationTuple(tempModel, new RemoveDependencyOperation(d)));
assertEquals("Expected dependency removed: " + d.toString() + "\n" + document.getText(), 0, dependencyCount(tempModel, d));
assertEquals("Dependency Count: \n" + document.getText(), 0, getDependencyCount(tempModel));
}
use of org.eclipse.m2e.core.ui.internal.editing.RemoveDependencyOperation in project m2e-core-tests by tesla.
the class RemoveDependencyOperationTest method testMissingDependency_withDependencies.
@Test
public void testMissingDependency_withDependencies() throws Exception {
//
document.setText(//
StructuredModelManager.getModelManager(), //
"<project><dependencies>" + //
"<dependency><groupId>AAA</groupId><artifactId>BBB</artifactId><version>1.0</version></dependency>" + //
"<dependency><groupId>AAAB</groupId><artifactId>BBB</artifactId><version>1.0</version></dependency>" + "</dependencies></project>");
PomEdits.performOnDOMDocument(new OperationTuple(tempModel, new RemoveDependencyOperation(d)));
assertEquals("Expected dependency removed: " + d.toString() + "\n" + document.getText(), 0, dependencyCount(tempModel, d));
assertEquals("Dependency Count: \n" + document.getText(), 2, getDependencyCount(tempModel));
}
use of org.eclipse.m2e.core.ui.internal.editing.RemoveDependencyOperation 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();
}
use of org.eclipse.m2e.core.ui.internal.editing.RemoveDependencyOperation in project m2e-core-tests by tesla.
the class RemoveDependencyOperationTest method testRemoveDependency.
@Test
public void testRemoveDependency() throws Exception {
//
document.setText(//
StructuredModelManager.getModelManager(), //
"<project><dependencies>" + //
"<dependency><groupId>AAA</groupId><artifactId>BBB</artifactId><version>1.0</version></dependency>" + //
"<dependency><groupId>AAAB</groupId><artifactId>BBB</artifactId><version>1.0</version></dependency>" + //
"<dependency><groupId>AAA</groupId><artifactId>BBBB</artifactId><version>1.0</version></dependency>" + "</dependencies></project>");
PomEdits.performOnDOMDocument(new OperationTuple(tempModel, new RemoveDependencyOperation(d)));
assertEquals("Expected dependency removed: " + d.toString() + "\n" + document.getText(), 0, dependencyCount(tempModel, d));
assertEquals("Dependency Count: \n" + document.getText(), 2, getDependencyCount(tempModel));
}
use of org.eclipse.m2e.core.ui.internal.editing.RemoveDependencyOperation in project m2e-core-tests by tesla.
the class RemoveDependencyOperationTest method testMissingDependency_noDependenciesElement.
@Test
public void testMissingDependency_noDependenciesElement() throws Exception {
//
document.setText(//
StructuredModelManager.getModelManager(), "<project></project>");
PomEdits.performOnDOMDocument(new OperationTuple(tempModel, new RemoveDependencyOperation(d)));
assertEquals("Expected dependency removed: " + d.toString() + "\n" + document.getText(), 0, dependencyCount(tempModel, d));
assertEquals("Dependency Count: \n" + document.getText(), 0, getDependencyCount(tempModel));
}
Aggregations