use of org.eclipse.m2e.core.internal.index.IndexedArtifact in project m2e-core by eclipse-m2e.
the class MavenDependenciesWizardPage method createArtifacts.
private void createArtifacts(Composite composite) {
Label mavenArtifactsLabel = new Label(composite, SWT.NONE);
mavenArtifactsLabel.setLayoutData(new GridData(SWT.LEFT, SWT.CENTER, false, false, 3, 1));
mavenArtifactsLabel.setText(org.eclipse.m2e.core.ui.internal.Messages.MavenDependenciesWizardPage_lblArtifacts);
dependencyViewer = new TableViewer(composite, SWT.BORDER | SWT.MULTI | SWT.V_SCROLL | SWT.H_SCROLL);
dependencyViewer.getTable().setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true, 2, 2));
dependencyViewer.setUseHashlookup(true);
dependencyViewer.setLabelProvider(new ArtifactLabelProvider());
dependencyViewer.setComparator(new DependencySorter());
dependencyViewer.add(dependencies);
Button addDependencyButton = new Button(composite, SWT.PUSH);
GridData gd_addDependencyButton = new GridData(SWT.FILL, SWT.TOP, false, false);
addDependencyButton.setLayoutData(gd_addDependencyButton);
addDependencyButton.setText(Messages.wizardProjectPageDependenciesAdd);
addDependencyButton.addSelectionListener(SelectionListener.widgetSelectedAdapter(e -> {
MavenRepositorySearchDialog dialog = //
MavenRepositorySearchDialog.createSearchDependencyDialog(//
getShell(), org.eclipse.m2e.core.ui.internal.Messages.MavenDependenciesWizardPage_searchDialog_title, null, null, false);
if (dialog.open() == Window.OK) {
Object result = dialog.getFirstResult();
if (result instanceof IndexedArtifactFile) {
Dependency dependency = ((IndexedArtifactFile) result).getDependency();
dependency.setScope(dialog.getSelectedScope());
dependencyViewer.add(dependency);
notifyListeners();
} else if (result instanceof IndexedArtifact) {
// If we have an ArtifactInfo, we add the first FileInfo it contains
// which corresponds to the latest version of the artifact.
Set<IndexedArtifactFile> files = ((IndexedArtifact) result).getFiles();
if (files != null && !files.isEmpty()) {
dependencyViewer.add(files.iterator().next().getDependency());
notifyListeners();
}
}
}
}));
final Button removeDependencyButton = new Button(composite, SWT.PUSH);
removeDependencyButton.setLayoutData(new GridData(SWT.FILL, SWT.TOP, false, true));
removeDependencyButton.setText(Messages.wizardProjectPageDependenciesRemove);
removeDependencyButton.setEnabled(false);
removeDependencyButton.addSelectionListener(SelectionListener.widgetSelectedAdapter(e -> {
IStructuredSelection selection = (IStructuredSelection) dependencyViewer.getSelection();
if (selection != null) {
dependencyViewer.remove(selection.toArray());
notifyListeners();
}
}));
dependencyViewer.addSelectionChangedListener(event -> {
IStructuredSelection selection = (IStructuredSelection) event.getSelection();
removeDependencyButton.setEnabled(selection.size() > 0);
});
}
use of org.eclipse.m2e.core.internal.index.IndexedArtifact in project m2e-core by eclipse-m2e.
the class MavenPomSelectionComponent method getIndexedArtifact.
public IndexedArtifact getIndexedArtifact() {
IStructuredSelection selection = (IStructuredSelection) searchResultViewer.getSelection();
Object element = selection.getFirstElement();
if (element instanceof IndexedArtifact) {
return (IndexedArtifact) element;
}
TreeItem[] treeItems = searchResultViewer.getTree().getSelection();
if (treeItems.length == 0) {
return null;
}
return (IndexedArtifact) treeItems[0].getParentItem().getData();
}
use of org.eclipse.m2e.core.internal.index.IndexedArtifact in project m2e-core by eclipse-m2e.
the class MavenPomSelectionComponent method getSelectedIndexedArtifactFiles.
List<IndexedArtifactFile> getSelectedIndexedArtifactFiles(IStructuredSelection selection) {
ArrayList<IndexedArtifactFile> result = new ArrayList<>();
for (Object element : selection.toList()) {
if (element instanceof IndexedArtifact) {
// the idea here is that if we have a managed version for something, then the IndexedArtifact shall
// represent that value..
IndexedArtifact ia = (IndexedArtifact) element;
if (managedKeys.contains(getKey(ia))) {
for (IndexedArtifactFile file : ia.getFiles()) {
if (managedKeys.contains(getKey(file))) {
result.add(file);
}
}
} else {
// 335383 find first non-snasphot version in case none is managed
boolean added = false;
for (IndexedArtifactFile file : ia.getFiles()) {
// what better means of recognizing snapshots?
if (file.version != null && !file.version.endsWith("-SNAPSHOT")) {
// $NON-NLS-1$
added = true;
result.add(file);
break;
}
}
if (!added) {
// just in case we deal with all snapshots..
result.add(ia.getFiles().iterator().next());
}
}
} else if (element instanceof IndexedArtifactFile) {
result.add((IndexedArtifactFile) element);
}
}
return result;
}
use of org.eclipse.m2e.core.internal.index.IndexedArtifact in project m2e-core by eclipse-m2e.
the class MavenRepositoryView method makeActions.
private void makeActions() {
collapseAllAction = new Action(Messages.MavenRepositoryView_btnCollapse) {
@Override
public void run() {
viewer.collapseAll();
}
};
collapseAllAction.setToolTipText(Messages.MavenRepositoryView_btnCollapse_tooltip);
collapseAllAction.setImageDescriptor(PlatformUI.getWorkbench().getSharedImages().getImageDescriptor(ISharedImages.IMG_ELCL_COLLAPSEALL));
reloadSettings = new Action(Messages.MavenRepositoryView_action_reload) {
@Override
public void run() {
String msg = Messages.MavenRepositoryView_reload_msg;
boolean res = //
MessageDialog.openConfirm(//
getViewSite().getShell(), Messages.MavenRepositoryView_reload_title, msg);
if (res) {
Job job = new WorkspaceJob(Messages.MavenRepositoryView_job_reloading) {
@Override
public IStatus runInWorkspace(IProgressMonitor monitor) {
try {
MavenPlugin.getMaven().reloadSettings();
} catch (CoreException ex) {
return ex.getStatus();
}
return Status.OK_STATUS;
}
};
job.schedule();
}
}
};
reloadSettings.setImageDescriptor(MavenImages.REFRESH);
openPomAction = new BaseSelectionListenerAction(Messages.MavenRepositoryView_action_open) {
@Override
public void run() {
ISelection selection = viewer.getSelection();
Object element = ((IStructuredSelection) selection).getFirstElement();
if (element instanceof IArtifactNode) {
Artifact f = ((IArtifactNode) element).getArtifact();
OpenPomAction.openEditor(f.getGroupId(), f.getArtifactId(), f.getVersion(), null);
}
}
@Override
protected boolean updateSelection(IStructuredSelection selection) {
return selection.getFirstElement() instanceof IArtifactNode;
}
};
openPomAction.setToolTipText(Messages.MavenRepositoryView_action_open_tooltip);
openPomAction.setImageDescriptor(MavenImages.POM);
copyUrlAction = new BaseSelectionListenerAction(Messages.MavenRepositoryView_action_copy) {
@Override
public void run() {
Object element = getStructuredSelection().getFirstElement();
String url = null;
if (element instanceof RepositoryNode) {
url = ((RepositoryNode) element).getRepositoryUrl();
} else if (element instanceof IndexedArtifact) {
//
} else if (element instanceof IndexedArtifactFile) {
//
}
if (url != null) {
Clipboard clipboard = new Clipboard(Display.getCurrent());
clipboard.setContents(new String[] { url }, new Transfer[] { TextTransfer.getInstance() });
clipboard.dispose();
}
}
@Override
protected boolean updateSelection(IStructuredSelection selection) {
Object element = selection.getFirstElement();
return element instanceof RepositoryNode;
}
};
copyUrlAction.setToolTipText(Messages.MavenRepositoryView_action_copy_tooltip);
copyUrlAction.setImageDescriptor(PlatformUI.getWorkbench().getSharedImages().getImageDescriptor(ISharedImages.IMG_TOOL_COPY));
// materializeProjectAction = new BaseSelectionListenerAction(Messages.MavenRepositoryView_action_materialize) {
// public void run() {
// Object element = getStructuredSelection().getFirstElement();
// if(element instanceof IndexedArtifactFileNode){
// MaterializeAction action = new MaterializeAction();
// StructuredSelection sel = new StructuredSelection(new Object[]{((IndexedArtifactFileNode) element).getIndexedArtifactFile()});
// action.selectionChanged(this, sel);
// action.run(this);
// }
// }
//
// protected boolean updateSelection(IStructuredSelection selection) {
// return selection.getFirstElement() instanceof IndexedArtifactFileNode;
// }
// };
// materializeProjectAction.setImageDescriptor(MavenImages.IMPORT_PROJECT);
viewer.addSelectionChangedListener(openPomAction);
viewer.addSelectionChangedListener(copyUrlAction);
// viewer.addSelectionChangedListener(materializeProjectAction);
}
use of org.eclipse.m2e.core.internal.index.IndexedArtifact in project m2e-core by eclipse-m2e.
the class JavaProjectConversionParticipant method getMostRecentPluginVersion.
/**
* Returns the highest, non-snapshot plugin version between the given reference version and the versions found in the
* Nexus indexes.
*/
@SuppressWarnings("restriction")
private // TODO extract as API when stabilized?
String getMostRecentPluginVersion(String groupId, String artifactId, String referenceVersion) {
Assert.isNotNull(groupId, "groupId can not be null");
Assert.isNotNull(artifactId, "artifactId can not be null");
String version = referenceVersion;
// $NON-NLS-1$
String partialKey = artifactId + " : " + groupId;
SearchExpression a = new SourcedSearchExpression(artifactId);
// For some reason, an exact search using :
// ISearchEngine searchEngine = M2EUIPluginActivator.getDefault().getSearchEngine(null)
// searchEngine.findVersions(groupId, artifactId, searchExpression, packaging)
//
// doesn't yield the expected results (the latest versions are not returned), so we rely on a fuzzier search
// and refine the results.
// was using index, but should use searchEngine as mentioned above
Map<String, IndexedArtifact> values = Map.of();
if (!values.isEmpty()) {
SortedSet<ComparableVersion> versions = new TreeSet<>();
ComparableVersion referenceComparableVersion = referenceVersion == null ? null : new ComparableVersion(referenceVersion);
for (Map.Entry<String, IndexedArtifact> e : values.entrySet()) {
if (!(e.getKey().endsWith(partialKey))) {
continue;
}
for (IndexedArtifactFile f : e.getValue().getFiles()) {
if (groupId.equals(f.group) && artifactId.equals(f.artifact) && !f.version.contains("SNAPSHOT")) {
ComparableVersion v = new ComparableVersion(f.version);
if (referenceComparableVersion == null || v.compareTo(referenceComparableVersion) > 0) {
versions.add(v);
}
}
}
if (!versions.isEmpty()) {
List<String> sorted = new ArrayList<>(versions.size());
for (ComparableVersion v : versions) {
sorted.add(v.toString());
}
Collections.reverse(sorted);
version = sorted.iterator().next();
}
}
}
return version;
}
Aggregations