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