use of org.eclipse.m2e.core.ui.internal.editing.PomEdits.ARTIFACT_ID in project m2e-core-tests by tesla.
the class ExcludeArtifactRefactoringTest method hasExclusionSet.
/*
* The editor has the given exclusion set
*/
protected static boolean hasExclusionSet(MavenPomEditor editor, final ArtifactKey dependencyKey, final ArtifactKey excluded) throws Exception {
final boolean[] found = new boolean[1];
found[0] = false;
performOnDOMDocument(new OperationTuple(editor.getDocument(), document -> {
Element dep = findChild(findChild(document.getDocumentElement(), DEPENDENCIES), DEPENDENCY, childEquals(GROUP_ID, dependencyKey.getGroupId()), childEquals(ARTIFACT_ID, dependencyKey.getArtifactId()), childEquals(VERSION, dependencyKey.getVersion()));
if (dep != null) {
Element exclusion = findChild(findChild(dep, EXCLUSIONS), EXCLUSION, childEquals(GROUP_ID, excluded.getGroupId()), childEquals(ARTIFACT_ID, excluded.getArtifactId()));
found[0] = exclusion != null;
}
}, true));
return found[0];
}
use of org.eclipse.m2e.core.ui.internal.editing.PomEdits.ARTIFACT_ID in project m2e-core by eclipse-m2e.
the class OverviewPage method addSelectedModules.
private void addSelectedModules(Object[] result, boolean updateParentSection) {
final String[] vals = new String[3];
try {
performOnDOMDocument(new OperationTuple(getPomEditor().getDocument(), document -> {
Element root = document.getDocumentElement();
String grid = getTextValue(findChild(root, GROUP_ID));
Element parent = findChild(root, PARENT);
if (grid == null) {
grid = getTextValue(findChild(parent, GROUP_ID));
}
String artifactId = getTextValue(findChild(root, ARTIFACT_ID));
String version = getTextValue(findChild(root, VERSION));
if (version == null) {
version = getTextValue(findChild(parent, VERSION));
}
vals[0] = grid;
vals[1] = artifactId;
vals[2] = version;
}, true));
} catch (Exception ex) {
LOG.error("Error getting values from document", ex);
}
final String parentGroupId = vals[0];
final String parentArtifactId = vals[1];
final String parentVersion = vals[2];
final IPath projectPath = getProject().getLocation();
for (Object selection : result) {
IContainer container = null;
IFile pomFile = null;
if (selection instanceof IFile) {
pomFile = (IFile) selection;
if (!IMavenConstants.POM_FILE_NAME.equals(pomFile.getName())) {
continue;
}
container = pomFile.getParent();
} else if (selection instanceof IContainer && !selection.equals(getProject())) {
container = (IContainer) selection;
pomFile = container.getFile(new Path(IMavenConstants.POM_FILE_NAME));
}
if (pomFile == null || !pomFile.exists() || container == null) {
continue;
}
IPath resultPath = container.getLocation();
String path = resultPath.makeRelativeTo(projectPath).toString();
if (updateParentSection) {
final String relativePath = projectPath.makeRelativeTo(resultPath).toString();
try {
performOnDOMDocument(new OperationTuple(pomFile, (Operation) document -> {
Element root = document.getDocumentElement();
Element parent = getChild(root, PARENT);
setText(getChild(parent, GROUP_ID), parentGroupId);
setText(getChild(parent, ARTIFACT_ID), parentArtifactId);
setText(getChild(parent, VERSION), parentVersion);
setText(getChild(parent, RELATIVE_PATH), relativePath);
Element grId = findChild(root, GROUP_ID);
String grIdText = getTextValue(grId);
if (grIdText != null && grIdText.equals(parentGroupId)) {
removeChild(root, grId);
}
Element ver = findChild(root, VERSION);
String verText = getTextValue(ver);
if (verText != null && verText.equals(parentVersion)) {
removeChild(root, ver);
}
}));
} catch (Exception e) {
LOG.error("Error updating parent reference in file:" + pomFile, e);
}
}
createNewModule(path);
}
}
use of org.eclipse.m2e.core.ui.internal.editing.PomEdits.ARTIFACT_ID in project m2e-core by eclipse-m2e.
the class DependenciesComposite method createDependenciesSection.
private void createDependenciesSection(SashForm verticalSash) {
Section dependenciesSection = toolkit.createSection(verticalSash, ExpandableComposite.TITLE_BAR);
dependenciesSection.marginWidth = 3;
dependenciesSection.setText(Messages.DependenciesComposite_sectionDependencies);
dependenciesComparator = new DependenciesComparator<>();
dependenciesContentProvider.setComparator(dependenciesComparator);
dependenciesEditor = new DependenciesListComposite<>(dependenciesSection, SWT.NONE, true);
dependenciesEditor.setCellLabelProvider(new DelegatingStyledCellLabelProvider(dependencyLabelProvider));
dependenciesEditor.setContentProvider(dependenciesContentProvider);
dependenciesEditor.setRemoveButtonListener(SelectionListener.widgetSelectedAdapter(e -> {
final List<Object> dependencyList = dependenciesEditor.getSelection();
try {
editorPage.performEditOperation(document -> {
Element deps = findChild(document.getDocumentElement(), DEPENDENCIES);
if (deps == null) {
// TODO log
return;
}
for (Object dependency : dependencyList) {
if (dependency instanceof Dependency) {
Element dep = findChild(deps, DEPENDENCY, childEquals(GROUP_ID, ((Dependency) dependency).groupId), childEquals(ARTIFACT_ID, ((Dependency) dependency).artifactId));
removeChild(deps, dep);
}
}
removeIfNoChildElement(deps);
}, log, "error removing dependencies");
} finally {
setDependenciesInput();
}
}));
dependenciesEditor.setPropertiesListener(SelectionListener.widgetSelectedAdapter(e -> {
Object selection = dependenciesEditor.getSelection().get(0);
if (selection instanceof Dependency) {
Dependency dependency = (Dependency) selection;
EditDependencyDialog d = new EditDependencyDialog(getShell(), false, editorPage.getProject(), editorPage.getPomEditor().getMavenProject());
d.setDependency(toApacheDependency(dependency));
if (d.open() == Window.OK) {
try {
editorPage.performEditOperation(d.getEditOperation(), log, "Error updating dependency");
} finally {
setDependenciesInput();
dependenciesEditor.setSelection(Collections.singletonList((Object) dependency));
}
}
} else if (selection instanceof org.apache.maven.model.Dependency) {
/*
* TODO: Support editing or displaying of inherited/managed dependencies.
*/
}
}));
dependenciesSection.setClient(dependenciesEditor);
toolkit.adapt(dependenciesEditor);
toolkit.paintBordersFor(dependenciesEditor);
dependenciesEditor.setManageButtonListener(SelectionListener.widgetSelectedAdapter(e -> {
try {
openManageDependenciesDialog();
} catch (InvocationTargetException e1) {
MavenEditorPlugin.getDefault().getLog().log(// $NON-NLS-1$
new Status(IStatus.ERROR, MavenEditorPlugin.PLUGIN_ID, "Error: ", e1));
} catch (InterruptedException e1) {
MavenEditorPlugin.getDefault().getLog().log(// $NON-NLS-1$
new Status(IStatus.ERROR, MavenEditorPlugin.PLUGIN_ID, "Error: ", e1));
}
}));
dependenciesEditor.setAddButtonListener(SelectionListener.widgetSelectedAdapter(e -> {
final MavenRepositorySearchDialog addDepDialog = MavenRepositorySearchDialog.createSearchDependencyDialog(getShell(), Messages.DependenciesComposite_action_selectDependency, editorPage.getPomEditor().getMavenProject(), editorPage.getProject(), false);
if (addDepDialog.open() == Window.OK) {
final IndexedArtifactFile dep = (IndexedArtifactFile) addDepDialog.getFirstResult();
final String selectedScope = addDepDialog.getSelectedScope();
try {
editorPage.performEditOperation(document -> {
Element depsEl = getChild(document.getDocumentElement(), DEPENDENCIES);
PomHelper.addOrUpdateDependency(depsEl, dep.group, dep.artifact, isManaged(dep.group, dep.artifact, dep.version) ? null : dep.version, dep.type, selectedScope, dep.classifier);
}, log, "errror adding dependency");
} finally {
setDependenciesInput();
List<Dependency> deps = getDependencies();
if (!deps.isEmpty()) {
dependenciesEditor.setSelection(Collections.<Object>singletonList(deps.get(deps.size() - 1)));
}
}
}
}));
ToolBarManager modulesToolBarManager = new ToolBarManager(SWT.FLAT);
modulesToolBarManager.add(new Action(Messages.DependenciesComposite_action_sortAlphabetically, MavenEditorImages.SORT) {
{
setChecked(false);
}
@Override
public int getStyle() {
return AS_CHECK_BOX;
}
@Override
public void run() {
dependenciesContentProvider.setShouldSort(isChecked());
dependenciesEditor.getViewer().refresh();
}
});
modulesToolBarManager.add(new Action(Messages.DependenciesComposite_action_showInheritedDependencies, MavenEditorImages.SHOW_INHERITED_DEPENDENCIES) {
{
setChecked(false);
}
@Override
public int getStyle() {
return AS_CHECK_BOX;
}
@Override
public void run() {
if (isChecked()) {
showInheritedDependencies = true;
} else {
showInheritedDependencies = false;
}
ISelection selection = dependenciesEditor.getViewer().getSelection();
setDependenciesInput();
dependenciesEditor.getViewer().refresh();
dependenciesEditor.getViewer().setSelection(selection, true);
}
});
modulesToolBarManager.add(new Action(Messages.DependenciesComposite_action_showgroupid, MavenEditorImages.SHOW_GROUP) {
{
setChecked(false);
dependenciesComparator.setSortByGroups(false);
}
@Override
public int getStyle() {
return AS_CHECK_BOX;
}
@Override
public void run() {
dependencyLabelProvider.setShowGroupId(isChecked());
dependenciesComparator.setSortByGroups(isChecked());
dependenciesEditor.getViewer().refresh();
}
});
modulesToolBarManager.add(new Action(Messages.DependenciesComposite_action_filter, MavenEditorImages.FILTER) {
{
setChecked(true);
}
@Override
public int getStyle() {
return AS_CHECK_BOX;
}
@Override
public void run() {
TableViewer viewer = dependenciesEditor.getViewer();
if (isChecked()) {
viewer.addFilter(searchFilter);
} else {
viewer.removeFilter(searchFilter);
}
viewer.refresh();
if (isChecked()) {
searchControl.getSearchText().setFocus();
}
}
});
Composite toolbarComposite = toolkit.createComposite(dependenciesSection);
GridLayout toolbarLayout = new GridLayout(1, true);
toolbarLayout.marginHeight = 0;
toolbarLayout.marginWidth = 0;
toolbarComposite.setLayout(toolbarLayout);
toolbarComposite.setBackground(null);
modulesToolBarManager.createControl(toolbarComposite);
dependenciesSection.setTextClient(toolbarComposite);
}
use of org.eclipse.m2e.core.ui.internal.editing.PomEdits.ARTIFACT_ID in project m2e-core by eclipse-m2e.
the class DependenciesComposite method createDependencyManagementSection.
private void createDependencyManagementSection(SashForm verticalSash) {
Section dependencyManagementSection = toolkit.createSection(verticalSash, ExpandableComposite.TITLE_BAR);
dependencyManagementSection.marginWidth = 3;
dependencyManagementSection.setText(Messages.DependenciesComposite_sectionDependencyManagement);
dependencyManagementComparator = new DependenciesComparator<>();
dependencyManagementContentProvider.setComparator(dependencyManagementComparator);
dependencyManagementEditor = new PropertiesListComposite<>(dependencyManagementSection, SWT.NONE, true);
dependencyManagementEditor.setContentProvider(dependencyManagementContentProvider);
dependencyManagementEditor.setLabelProvider(dependencyManagementLabelProvider);
dependencyManagementSection.setClient(dependencyManagementEditor);
dependencyManagementEditor.setRemoveButtonListener(SelectionListener.widgetSelectedAdapter(e -> {
final List<Dependency> dependencyList = dependencyManagementEditor.getSelection();
try {
editorPage.performEditOperation(document -> {
Element deps = findChild(findChild(document.getDocumentElement(), DEPENDENCY_MANAGEMENT), DEPENDENCIES);
if (deps == null) {
// TODO log
return;
}
for (Dependency dependency : dependencyList) {
Element dep = findChild(deps, DEPENDENCY, childEquals(GROUP_ID, dependency.groupId), childEquals(ARTIFACT_ID, dependency.artifactId));
removeChild(deps, dep);
}
removeIfNoChildElement(deps);
}, log, "error removing managed dependencies");
} finally {
setDependencyManagementInput();
dependenciesEditor.refresh();
}
}));
dependencyManagementEditor.setPropertiesListener(SelectionListener.widgetSelectedAdapter(e -> {
Dependency dependency = dependencyManagementEditor.getSelection().get(0);
EditDependencyDialog d = new EditDependencyDialog(getShell(), true, editorPage.getProject(), editorPage.getPomEditor().getMavenProject());
d.setDependency(toApacheDependency(dependency));
if (d.open() == Window.OK) {
try {
editorPage.performEditOperation(d.getEditOperation(), log, "Error updating dependency");
} finally {
setDependencyManagementInput();
dependencyManagementEditor.setSelection(Collections.singletonList(dependency));
// refresh this one to update decorations..
dependenciesEditor.refresh();
}
}
}));
dependencyManagementEditor.addSelectionListener(event -> {
List<Dependency> selection = dependencyManagementEditor.getSelection();
if (!selection.isEmpty()) {
dependenciesEditor.setSelection(Collections.<Object>emptyList());
}
});
toolkit.adapt(dependencyManagementEditor);
toolkit.paintBordersFor(dependencyManagementEditor);
dependencyManagementEditor.setAddButtonListener(SelectionListener.widgetSelectedAdapter(e -> {
final MavenRepositorySearchDialog addDepDialog = MavenRepositorySearchDialog.createSearchDependencyDialog(getShell(), Messages.DependenciesComposite_action_selectDependency, editorPage.getPomEditor().getMavenProject(), editorPage.getProject(), true);
if (addDepDialog.open() == Window.OK) {
final IndexedArtifactFile dep = (IndexedArtifactFile) addDepDialog.getFirstResult();
final String selectedScope = addDepDialog.getSelectedScope();
try {
editorPage.performEditOperation(document -> {
Element depsEl = getChild(document.getDocumentElement(), DEPENDENCY_MANAGEMENT, DEPENDENCIES);
PomHelper.addOrUpdateDependency(depsEl, dep.group, dep.artifact, dep.version, dep.type, selectedScope, dep.classifier);
}, log, "errror adding dependency");
} finally {
setDependencyManagementInput();
List<Dependency> dlist = getManagedDependencies();
if (!dlist.isEmpty()) {
dependencyManagementEditor.setSelection(Collections.<Dependency>singletonList(dlist.get(dlist.size() - 1)));
}
// refresh this one to update decorations..
dependenciesEditor.refresh();
}
}
}));
ToolBarManager modulesToolBarManager = new ToolBarManager(SWT.FLAT);
modulesToolBarManager.add(new Action(Messages.DependenciesComposite_action_sortAlphabetically, MavenEditorImages.SORT) {
{
setChecked(false);
dependencyManagementContentProvider.setShouldSort(false);
}
@Override
public int getStyle() {
return AS_CHECK_BOX;
}
@Override
public void run() {
dependencyManagementContentProvider.setShouldSort(isChecked());
dependencyManagementEditor.getViewer().refresh();
}
});
modulesToolBarManager.add(new Action(Messages.DependenciesComposite_action_showgroupid, MavenEditorImages.SHOW_GROUP) {
{
setChecked(false);
dependencyManagementComparator.setSortByGroups(false);
}
@Override
public int getStyle() {
return AS_CHECK_BOX;
}
@Override
public void run() {
dependencyManagementLabelProvider.setShowGroupId(isChecked());
dependencyManagementComparator.setSortByGroups(isChecked());
dependencyManagementEditor.getViewer().refresh();
}
});
modulesToolBarManager.add(new Action(Messages.DependenciesComposite_action_filter, MavenEditorImages.FILTER) {
{
setChecked(true);
}
@Override
public int getStyle() {
return AS_CHECK_BOX;
}
@Override
public void run() {
TableViewer viewer = dependencyManagementEditor.getViewer();
if (isChecked()) {
viewer.addFilter(searchFilter);
} else {
viewer.removeFilter(searchFilter);
}
viewer.refresh();
if (isChecked()) {
searchControl.getSearchText().setFocus();
}
}
});
Composite toolbarComposite = toolkit.createComposite(dependencyManagementSection);
GridLayout toolbarLayout = new GridLayout(1, true);
toolbarLayout.marginHeight = 0;
toolbarLayout.marginWidth = 0;
toolbarComposite.setLayout(toolbarLayout);
toolbarComposite.setBackground(null);
modulesToolBarManager.createControl(toolbarComposite);
dependencyManagementSection.setTextClient(toolbarComposite);
}
use of org.eclipse.m2e.core.ui.internal.editing.PomEdits.ARTIFACT_ID in project m2e-core by eclipse-m2e.
the class OverviewPage method loadThis.
private void loadThis(final int mask) {
Display.getDefault().asyncExec(() -> {
removeNotifyListener(parentGroupIdText);
removeNotifyListener(parentArtifactIdText);
removeNotifyListener(parentVersionText);
removeNotifyListener(parentRelativePathText);
removeNotifyListener(artifactGroupIdText);
removeNotifyListener(artifactIdText);
removeNotifyListener(artifactVersionText);
removeNotifyListener(artifactPackagingCombo);
removeNotifyListener(projectNameText);
removeNotifyListener(projectDescriptionText);
removeNotifyListener(projectUrlText);
removeNotifyListener(inceptionYearText);
removeNotifyListener(organizationNameText);
removeNotifyListener(organizationUrlText);
removeNotifyListener(scmUrlText);
removeNotifyListener(scmConnectionText);
removeNotifyListener(scmDevConnectionText);
removeNotifyListener(scmTagText);
removeNotifyListener(ciManagementUrlCombo);
removeNotifyListener(ciManagementSystemCombo);
removeNotifyListener(issueManagementUrlCombo);
removeNotifyListener(issueManagementSystemCombo);
try {
performOnDOMDocument(new OperationTuple(getPomEditor().getDocument(), document -> {
Element root = document.getDocumentElement();
String pack = nvl(getTextValue(findChild(root, PACKAGING)));
// $NON-NLS-1$ //$NON-NLS-2$
pack = "".equals(pack) ? "jar" : pack;
if ((mask & RELOAD_BASE) != 0) {
setText(artifactGroupIdText, nvl(getTextValue(findChild(root, GROUP_ID))));
setText(artifactIdText, nvl(getTextValue(findChild(root, ARTIFACT_ID))));
setText(artifactVersionText, nvl(getTextValue(findChild(root, VERSION))));
setText(artifactPackagingCombo, pack);
String name = getTextValue(findChild(root, NAME));
setText(projectNameText, nvl(name));
String desc = getTextValue(findChild(root, DESCRIPTION));
setText(projectDescriptionText, nvl(desc));
String url = getTextValue(findChild(root, URL));
setText(projectUrlText, nvl(url));
String incep = getTextValue(findChild(root, INCEPTION_YEAR));
setText(inceptionYearText, nvl(incep));
boolean expandProjectSection = name != null || desc != null || url != null || incep != null;
projectSectionData.grabExcessVerticalSpace = expandProjectSection;
projectSection.setExpanded(expandProjectSection);
}
if ((mask & RELOAD_PARENT) != 0) {
// parent section
Element parent = findChild(root, PARENT);
String parentGrId = getTextValue(findChild(parent, GROUP_ID));
String parentArtId = getTextValue(findChild(parent, ARTIFACT_ID));
String parentVers = getTextValue(findChild(parent, VERSION));
setText(parentGroupIdText, nvl(parentGrId));
setText(parentArtifactIdText, nvl(parentArtId));
setText(parentVersionText, nvl(parentVers));
setText(parentRelativePathText, nvl(getTextValue(findChild(parent, RELATIVE_PATH))));
parentSelectAction.setEnabled(!isReadOnly());
// only enable when all 3 coordinates are actually present.
parentOpenAction.setEnabled(root != null && parentGrId != null && parentArtId != null && parentVers != null);
parentSection.setExpanded(parent != null);
}
if ((mask & RELOAD_ORG) != 0) {
// organization section
Element org = findChild(root, ORGANIZATION);
setText(organizationNameText, nvl(getTextValue(findChild(org, NAME))));
setText(organizationUrlText, nvl(getTextValue(findChild(org, URL))));
organizationSection.setExpanded(org != null);
}
if ((mask & RELOAD_SCM) != 0) {
// scm section
Element scm = findChild(root, SCM);
setText(scmUrlText, nvl(getTextValue(findChild(scm, URL))));
setText(scmConnectionText, nvl(getTextValue(findChild(scm, CONNECTION))));
setText(scmDevConnectionText, nvl(getTextValue(findChild(scm, DEV_CONNECTION))));
setText(scmTagText, nvl(getTextValue(findChild(scm, TAG))));
scmSection.setExpanded(scm != null);
}
if ((mask & RELOAD_CI) != 0) {
// ci section
Element ci = findChild(root, CI_MANAGEMENT);
setText(ciManagementSystemCombo, nvl(getTextValue(findChild(ci, SYSTEM))));
setText(ciManagementUrlCombo, nvl(getTextValue(findChild(ci, URL))));
ciManagementSection.setExpanded(ci != null);
}
if ((mask & RELOAD_IM) != 0) {
// issue management
Element im = findChild(root, ISSUE_MANAGEMENT);
setText(issueManagementSystemCombo, nvl(getTextValue(findChild(im, SYSTEM))));
setText(issueManagementUrlCombo, nvl(getTextValue(findChild(im, URL))));
issueManagementSection.setExpanded(im != null);
}
if ((mask & RELOAD_MODULES) != 0) {
// modules section..
List<Element> moduleEls = findChilds(findChild(root, MODULES), MODULE);
List<String> modules = new ArrayList<>();
for (Element moduleEl : moduleEls) {
String text = getTextValue(moduleEl);
if (text != null) {
modules.add(text);
}
}
loadModules(modules, pack);
// #335337 no editing of packaging when there are modules, results in error anyway
artifactPackagingCombo.setEnabled(modules.isEmpty());
}
if ((mask & RELOAD_PROPERTIES) != 0) {
propertiesSection.refresh();
Element props = findChild(root, PROPERTIES);
propertiesSection.setExpanded(props != null);
// TODO used to check teh model's empty state as well, not done now..
}
}, true));
} catch (Exception e) {
LOG.error("Failed to populate overview panel", e);
}
addNotifyListener(artifactGroupIdText);
addNotifyListener(artifactIdText);
addNotifyListener(artifactVersionText);
addNotifyListener(artifactPackagingCombo);
addNotifyListener(projectNameText);
addNotifyListener(projectDescriptionText);
addNotifyListener(projectUrlText);
addNotifyListener(inceptionYearText);
addNotifyListener(parentGroupIdText);
addNotifyListener(parentArtifactIdText);
addNotifyListener(parentVersionText);
addNotifyListener(parentRelativePathText);
addNotifyListener(organizationNameText);
addNotifyListener(organizationUrlText);
addNotifyListener(scmUrlText);
addNotifyListener(scmConnectionText);
addNotifyListener(scmDevConnectionText);
addNotifyListener(scmTagText);
addNotifyListener(ciManagementUrlCombo);
addNotifyListener(ciManagementSystemCombo);
addNotifyListener(issueManagementUrlCombo);
addNotifyListener(issueManagementSystemCombo);
});
}
Aggregations