use of org.eclipse.m2e.core.internal.index.IndexedArtifactFile in project m2e-core by eclipse-m2e.
the class AddPluginAction method run.
@Override
public void run(IAction action) {
IFile file = getPomFileFromPomEditorOrViewSelection();
if (file == null) {
return;
}
MavenProject mp = null;
IProject prj = file.getProject();
if (prj != null && IMavenConstants.POM_FILE_NAME.equals(file.getProjectRelativePath().toString())) {
IMavenProjectFacade facade = MavenPlugin.getMavenProjectRegistry().getProject(prj);
if (facade != null) {
mp = facade.getMavenProject();
}
}
MavenRepositorySearchDialog dialog = MavenRepositorySearchDialog.createSearchPluginDialog(getShell(), Messages.AddPluginAction_searchDialog_title, mp, prj, false);
if (dialog.open() == Window.OK) {
final IndexedArtifactFile indexedArtifactFile = (IndexedArtifactFile) dialog.getFirstResult();
if (indexedArtifactFile != null) {
try {
performOnDOMDocument(new OperationTuple(file, (Operation) document -> {
Element pluginsEl = getChild(document.getDocumentElement(), BUILD, PLUGINS);
PomHelper.createPlugin(pluginsEl, indexedArtifactFile.group, indexedArtifactFile.artifact, indexedArtifactFile.version);
}));
} catch (Exception ex) {
// $NON-NLS-1$
log.error("Can't add plugin to " + file, ex);
}
}
}
}
use of org.eclipse.m2e.core.internal.index.IndexedArtifactFile in project m2e-core by eclipse-m2e.
the class MavenProjectWizardArtifactPage method createControl.
/**
* {@inheritDoc} This wizard page contains a <code>MavenArtifactComponent</code> to gather information about the Maven
* artifact and a <code>Maven2DirectoriesComponent</code> which allows to choose which directories of the default
* Maven directory structure to create.
*/
@Override
public void createControl(Composite parent) {
GridLayout layout = new GridLayout();
layout.marginWidth = 0;
layout.marginHeight = 0;
Composite container = new Composite(parent, SWT.NULL);
container.setLayout(layout);
WidthGroup widthGroup = new WidthGroup();
container.addControlListener(widthGroup);
ModifyListener modifyingListener = e -> validate();
artifactComponent = new MavenArtifactComponent(container, SWT.NONE);
artifactComponent.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true));
artifactComponent.setWidthGroup(widthGroup);
artifactComponent.setModifyingListener(modifyingListener);
artifactComponent.setArtifactIdEditable(!readonlyParent);
parentComponent = new MavenParentComponent(container, readonlyParent ? SWT.READ_ONLY : SWT.NONE);
parentComponent.setLayoutData(new GridData(SWT.FILL, SWT.TOP, false, false));
parentComponent.setWidthGroup(widthGroup);
parentComponent.addModifyListener(modifyingListener);
parentComponent.addBrowseButtonListener(SelectionListener.widgetSelectedAdapter(e -> {
MavenRepositorySearchDialog dialog = MavenRepositorySearchDialog.createSearchParentDialog(getShell(), org.eclipse.m2e.core.ui.internal.Messages.MavenProjectWizardArtifactPage_searchDialog_title, null, null);
if (dialog.open() == Window.OK) {
IndexedArtifactFile indexedArtifactFile = (IndexedArtifactFile) dialog.getFirstResult();
if (indexedArtifactFile != null) {
parentComponent.setValues(indexedArtifactFile.group, indexedArtifactFile.artifact, indexedArtifactFile.version);
}
}
}));
createAdvancedSettings(container, new GridData(SWT.FILL, SWT.TOP, false, false, 2, 1));
resolverConfigurationComponent.setModifyListener(e -> validate());
// $NON-NLS-1$
addFieldWithHistory("groupId", artifactComponent.getGroupIdCombo());
// $NON-NLS-1$
addFieldWithHistory("artifactId", artifactComponent.getArtifactIdCombo());
// $NON-NLS-1$
addFieldWithHistory("version", artifactComponent.getVersionCombo());
// $NON-NLS-1$
addFieldWithHistory("name", artifactComponent.getNameCombo());
// $NON-NLS-1$
addFieldWithHistory("groupId", parentComponent.getGroupIdCombo());
// $NON-NLS-1$
addFieldWithHistory("artifactId", parentComponent.getArtifactIdCombo());
// $NON-NLS-1$
addFieldWithHistory("version", parentComponent.getVersionCombo());
container.layout();
validate();
setControl(container);
}
use of org.eclipse.m2e.core.internal.index.IndexedArtifactFile in project m2e-core by eclipse-m2e.
the class MavenInstallFileArtifactWizardPage method updateFileName.
void updateFileName(String fileName) {
if (!getArtifactFileName().equals(fileName)) {
artifactFileNameText.setText(fileName);
}
File file = new File(fileName);
if (!file.exists() || !file.isFile()) {
return;
}
if (fileName.endsWith(".jar") || fileName.endsWith(".war") || fileName.endsWith(".ear")) {
// $NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
packagingCombo.setText(fileName.substring(fileName.length() - 3));
}
int n = fileName.lastIndexOf('.');
if (n > -1) {
// $NON-NLS-1$
String pomFileName = fileName.substring(0, n) + ".pom";
if (new File(pomFileName).exists()) {
pomFileNameText.setText(pomFileName);
}
} else {
// $NON-NLS-1$
pomFileNameText.setText("");
}
// TODO used to be some indexer request
IndexedArtifactFile iaf = null;
if (iaf != null) {
groupIdCombo.setText(iaf.group);
artifactIdCombo.setText(iaf.artifact);
versionCombo.setText(iaf.version);
if (iaf.classifier != null) {
classifierCombo.setText(iaf.classifier);
}
String name = // //$NON-NLS-1$ //$NON-NLS-2$
iaf.group + ":" + iaf.artifact + "-" + iaf.version + // $NON-NLS-1$
(iaf.classifier == null ? "" : iaf.classifier);
setMessage(NLS.bind(Messages.MavenInstallFileArtifactWizardPage_message, name), WARNING);
return;
}
if (n > -1) {
// $NON-NLS-1$
String pomFileName = fileName.substring(0, n) + ".pom";
if (new File(pomFileName).exists()) {
pomFileNameText.setText(pomFileName);
readPOMFile(pomFileName);
}
}
ArtifactKey artifactKey = SelectionUtil.getType(file, ArtifactKey.class);
if (artifactKey != null) {
groupIdCombo.setText(artifactKey.getGroupId());
artifactIdCombo.setText(artifactKey.getArtifactId());
versionCombo.setText(artifactKey.getVersion());
if (artifactKey.getClassifier() != null) {
classifierCombo.setText(artifactKey.getClassifier());
}
}
}
use of org.eclipse.m2e.core.internal.index.IndexedArtifactFile 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.internal.index.IndexedArtifactFile in project m2e-core by eclipse-m2e.
the class MavenPomSelectionComponent method init.
public void init(String queryText, String queryType, IProject project, Set<ArtifactKey> artifacts, Set<ArtifactKey> managed) {
this.queryType = queryType;
this.project = project;
if (queryText != null) {
searchText.setText(queryText);
}
if (artifacts != null) {
for (ArtifactKey a : artifacts) {
// $NON-NLS-1$
artifactKeys.add(a.getGroupId() + ":" + a.getArtifactId());
// $NON-NLS-1$ //$NON-NLS-2$
artifactKeys.add(a.getGroupId() + ":" + a.getArtifactId() + ":" + a.getVersion());
}
}
if (managed != null) {
for (ArtifactKey a : managed) {
// $NON-NLS-1$
managedKeys.add(a.getGroupId() + ":" + a.getArtifactId());
// $NON-NLS-1$ //$NON-NLS-2$
managedKeys.add(a.getGroupId() + ":" + a.getArtifactId() + ":" + a.getVersion());
}
}
searchResultViewer.setContentProvider(new SearchResultContentProvider());
SearchResultLabelProvider labelProvider = new SearchResultLabelProvider(artifactKeys, managedKeys);
DecoratingStyledCellLabelProvider decoratingLabelProvider = new DecoratingStyledCellLabelProvider(labelProvider, PlatformUI.getWorkbench().getDecoratorManager().getLabelDecorator(), null);
DecorationContext decorationContext = new DecorationContext();
if (project != null) {
decorationContext.putProperty(PROP_DECORATION_CONTEXT_PROJECT, project);
}
decoratingLabelProvider.setDecorationContext(decorationContext);
searchResultViewer.setLabelProvider(decoratingLabelProvider);
searchResultViewer.addSelectionChangedListener(event -> {
IStructuredSelection selection = (IStructuredSelection) event.getSelection();
if (!selection.isEmpty()) {
List<IndexedArtifactFile> files = getSelectedIndexedArtifactFiles(selection);
ArtifactFilterManager filterManager = MavenPluginActivator.getDefault().getArifactFilterManager();
for (IndexedArtifactFile file : files) {
ArtifactKey key = file.getAdapter(ArtifactKey.class);
IStatus status = filterManager.filter(MavenPomSelectionComponent.this.project, key);
if (!status.isOK()) {
setStatus(IStatus.ERROR, status.getMessage());
// TODO not nice to exit method like this
return;
}
}
if (files.size() == 1) {
IndexedArtifactFile f = files.get(0);
// int severity = artifactKeys.contains(f.group + ":" + f.artifact) ? IStatus.ERROR : IStatus.OK;
int severity = IStatus.OK;
String date = DateFormat.getDateTimeInstance(DateFormat.MEDIUM, DateFormat.SHORT).format(f.date);
setStatus(severity, NLS.bind(Messages.MavenPomSelectionComponent_detail1, f.fname, (f.size != -1 ? NLS.bind(Messages.MavenPomSelectionComponent_details2, date, f.size) : date)));
} else {
setStatus(IStatus.OK, NLS.bind(Messages.MavenPomSelectionComponent_selected, selection.size()));
}
} else {
setStatus(IStatus.ERROR, Messages.MavenPomSelectionComponent_nosel);
}
});
setupClassifiers();
// $NON-NLS-1$
setStatus(IStatus.ERROR, "");
scheduleSearch(queryText, false);
}
Aggregations