diff options
16 files changed, 501 insertions, 94 deletions
diff --git a/org.eclipse.m2e.core.ui/plugin.xml b/org.eclipse.m2e.core.ui/plugin.xml index 8b54e497..06f215a1 100644 --- a/org.eclipse.m2e.core.ui/plugin.xml +++ b/org.eclipse.m2e.core.ui/plugin.xml @@ -29,10 +29,7 @@ state="true"> <description>%m2.decorator.description</description> <enablement> - <or> - <objectState name="nature" value="org.eclipse.m2e.core.maven2Nature"/> - <!--objectState name="name" value="pom.xml"/--> - </or> + <objectState name="nature" value="org.eclipse.m2e.core.maven2Nature"/> </enablement> </decorator> @@ -44,10 +41,7 @@ state="false"> <description>%m2.decorator.version.description</description> <enablement> - <or> - <objectState name="nature" value="org.eclipse.m2e.core.maven2Nature"/> - <!--objectState name="name" value="pom.xml"/--> - </or> + <objectState name="nature" value="org.eclipse.m2e.core.maven2Nature"/> </enablement> </decorator> </extension> @@ -550,4 +544,17 @@ file="helpContext.xml"> </contexts> </extension> -</plugin>
\ No newline at end of file + <extension + point="org.eclipse.core.runtime.adapters"> + <factory + adaptableType="org.eclipse.m2e.core.ui.internal.views.nodes.IndexedArtifactFileNode" + class="org.eclipse.m2e.core.ui.internal.views.nodes.IndexedArtifactFileNode$AdapterFactory"> + <adapter + type="org.eclipse.m2e.core.internal.index.IndexedArtifactFile"> + </adapter> + <adapter + type="org.eclipse.m2e.core.embedder.ArtifactKey"> + </adapter> + </factory> + </extension> +</plugin> diff --git a/org.eclipse.m2e.core.ui/src/org/eclipse/m2e/core/ui/internal/M2EUIPluginActivator.java b/org.eclipse.m2e.core.ui/src/org/eclipse/m2e/core/ui/internal/M2EUIPluginActivator.java index 37e3411e..3118f996 100644 --- a/org.eclipse.m2e.core.ui/src/org/eclipse/m2e/core/ui/internal/M2EUIPluginActivator.java +++ b/org.eclipse.m2e.core.ui/src/org/eclipse/m2e/core/ui/internal/M2EUIPluginActivator.java @@ -26,6 +26,7 @@ import org.eclipse.ui.preferences.ScopedPreferenceStore; import org.eclipse.m2e.core.MavenPlugin; import org.eclipse.m2e.core.internal.IMavenConstants; +import org.eclipse.m2e.core.internal.index.filter.FilteredIndex; import org.eclipse.m2e.core.internal.lifecyclemapping.discovery.IMavenDiscovery; import org.eclipse.m2e.core.ui.internal.console.MavenConsoleImpl; import org.eclipse.m2e.core.ui.internal.search.util.IndexSearchEngine; @@ -105,7 +106,7 @@ public class M2EUIPluginActivator extends AbstractUIPlugin { } public SearchEngine getSearchEngine(IProject project) throws CoreException { - return new IndexSearchEngine(MavenPlugin.getIndexManager().getIndex(project)); + return new IndexSearchEngine(new FilteredIndex(project, MavenPlugin.getIndexManager().getIndex(project))); } @SuppressWarnings({"rawtypes", "unchecked"}) diff --git a/org.eclipse.m2e.core.ui/src/org/eclipse/m2e/core/ui/internal/dialogs/MavenRepositorySearchDialog.java b/org.eclipse.m2e.core.ui/src/org/eclipse/m2e/core/ui/internal/dialogs/MavenRepositorySearchDialog.java index cc503bb0..5f5b65f8 100644 --- a/org.eclipse.m2e.core.ui/src/org/eclipse/m2e/core/ui/internal/dialogs/MavenRepositorySearchDialog.java +++ b/org.eclipse.m2e.core.ui/src/org/eclipse/m2e/core/ui/internal/dialogs/MavenRepositorySearchDialog.java @@ -222,7 +222,7 @@ public class MavenRepositorySearchDialog extends AbstractMavenDialog { } pomSelectionComponent = new MavenPomSelectionComponent(composite, SWT.NONE); - pomSelectionComponent.init(queryText, queryType, artifacts, managed); + pomSelectionComponent.init(queryText, queryType, project, artifacts, managed); pomSelectionComponent.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true)); diff --git a/org.eclipse.m2e.core.ui/src/org/eclipse/m2e/core/ui/internal/views/MavenRepositoryView.java b/org.eclipse.m2e.core.ui/src/org/eclipse/m2e/core/ui/internal/views/MavenRepositoryView.java index e47b790e..36a0471c 100644 --- a/org.eclipse.m2e.core.ui/src/org/eclipse/m2e/core/ui/internal/views/MavenRepositoryView.java +++ b/org.eclipse.m2e.core.ui/src/org/eclipse/m2e/core/ui/internal/views/MavenRepositoryView.java @@ -32,6 +32,7 @@ import org.eclipse.jface.action.IToolBarManager; import org.eclipse.jface.action.MenuManager; import org.eclipse.jface.action.Separator; import org.eclipse.jface.dialogs.MessageDialog; +import org.eclipse.jface.viewers.DecoratingStyledCellLabelProvider; import org.eclipse.jface.viewers.DoubleClickEvent; import org.eclipse.jface.viewers.IDoubleClickListener; import org.eclipse.jface.viewers.ISelection; @@ -80,6 +81,7 @@ import org.eclipse.m2e.core.ui.internal.views.nodes.RepositoryNode; * * @author dyocum */ +@SuppressWarnings("restriction") public class MavenRepositoryView extends ViewPart { /** @@ -137,8 +139,11 @@ public class MavenRepositoryView extends ViewPart { viewer = new TreeViewer(parent, SWT.MULTI | SWT.H_SCROLL | SWT.V_SCROLL); contentProvider = new RepositoryViewContentProvider(); viewer.setContentProvider(contentProvider); - viewer.setLabelProvider(new RepositoryViewLabelProvider(viewer.getTree().getFont())); - + + RepositoryViewLabelProvider labelProvider = new RepositoryViewLabelProvider(viewer.getTree().getFont()); + viewer.setLabelProvider(new DecoratingStyledCellLabelProvider(labelProvider, PlatformUI.getWorkbench() + .getDecoratorManager().getLabelDecorator(), null)); + viewer.addDoubleClickListener(new IDoubleClickListener() { public void doubleClick(DoubleClickEvent event) { diff --git a/org.eclipse.m2e.core.ui/src/org/eclipse/m2e/core/ui/internal/views/RepositoryViewLabelProvider.java b/org.eclipse.m2e.core.ui/src/org/eclipse/m2e/core/ui/internal/views/RepositoryViewLabelProvider.java index f65adaf6..e83707bf 100644 --- a/org.eclipse.m2e.core.ui/src/org/eclipse/m2e/core/ui/internal/views/RepositoryViewLabelProvider.java +++ b/org.eclipse.m2e.core.ui/src/org/eclipse/m2e/core/ui/internal/views/RepositoryViewLabelProvider.java @@ -11,9 +11,12 @@ package org.eclipse.m2e.core.ui.internal.views; +import org.eclipse.jface.viewers.DelegatingStyledCellLabelProvider.IStyledLabelProvider; import org.eclipse.jface.viewers.IColorProvider; import org.eclipse.jface.viewers.IFontProvider; import org.eclipse.jface.viewers.LabelProvider; +import org.eclipse.jface.viewers.StyledString; + import org.eclipse.m2e.core.ui.internal.util.M2EUIUtils; import org.eclipse.m2e.core.ui.internal.views.nodes.IMavenRepositoryNode; import org.eclipse.m2e.core.ui.internal.views.nodes.RepositoryNode; @@ -31,7 +34,7 @@ import org.eclipse.ui.PlatformUI; * * @author dyocum */ -public class RepositoryViewLabelProvider extends LabelProvider implements IColorProvider, IFontProvider { +public class RepositoryViewLabelProvider extends LabelProvider implements IStyledLabelProvider, IColorProvider, IFontProvider { private Font italicFont; public RepositoryViewLabelProvider(Font treeFont){ @@ -93,4 +96,8 @@ public class RepositoryViewLabelProvider extends LabelProvider implements IColor return null; } + public StyledString getStyledText(Object element) { + return new StyledString(getText(element)); + } + } diff --git a/org.eclipse.m2e.core.ui/src/org/eclipse/m2e/core/ui/internal/views/nodes/IndexedArtifactFileNode.java b/org.eclipse.m2e.core.ui/src/org/eclipse/m2e/core/ui/internal/views/nodes/IndexedArtifactFileNode.java index 95a0c3f6..2dcc4eec 100644 --- a/org.eclipse.m2e.core.ui/src/org/eclipse/m2e/core/ui/internal/views/nodes/IndexedArtifactFileNode.java +++ b/org.eclipse.m2e.core.ui/src/org/eclipse/m2e/core/ui/internal/views/nodes/IndexedArtifactFileNode.java @@ -12,40 +12,39 @@ package org.eclipse.m2e.core.ui.internal.views.nodes; import org.eclipse.core.runtime.IAdaptable; +import org.eclipse.core.runtime.IAdapterFactory; +import org.eclipse.core.runtime.PlatformObject; +import org.eclipse.swt.graphics.Image; + import org.eclipse.m2e.core.embedder.ArtifactKey; import org.eclipse.m2e.core.internal.index.IIndex; import org.eclipse.m2e.core.internal.index.IndexedArtifactFile; import org.eclipse.m2e.core.internal.index.nexus.NexusIndexManager; import org.eclipse.m2e.core.ui.internal.MavenImages; -import org.eclipse.swt.graphics.Image; + /** * IndexedArtifactFileNode - * + * * @author dyocum */ -public class IndexedArtifactFileNode implements IMavenRepositoryNode, IArtifactNode, IAdaptable { +@SuppressWarnings("restriction") +public class IndexedArtifactFileNode extends PlatformObject implements IMavenRepositoryNode, IArtifactNode, IAdaptable { private IndexedArtifactFile artifactFile; - public IndexedArtifactFileNode(IndexedArtifactFile artifactFile){ + public IndexedArtifactFileNode(IndexedArtifactFile artifactFile) { this.artifactFile = artifactFile; } - - public IndexedArtifactFile getIndexedArtifactFile(){ + + public IndexedArtifactFile getIndexedArtifactFile() { return this.artifactFile; } - - /* (non-Javadoc) - * @see org.eclipse.m2e.ui.internal.views.IMavenRepositoryNode#getChildren() - */ + public Object[] getChildren() { return null; } - /* (non-Javadoc) - * @see org.eclipse.m2e.ui.internal.views.IMavenRepositoryNode#getName() - */ public String getName() { String label = artifactFile.artifact; if(artifactFile.classifier != null) { @@ -57,16 +56,10 @@ public class IndexedArtifactFileNode implements IMavenRepositoryNode, IArtifactN return label; } - /* (non-Javadoc) - * @see org.eclipse.m2e.ui.internal.views.IMavenRepositoryNode#hasChildren() - */ public boolean hasChildren() { return false; } - /* (non-Javadoc) - * @see org.eclipse.m2e.ui.internal.views.nodes.IMavenRepositoryNode#getImage() - */ public Image getImage() { if(artifactFile.sourcesExists == IIndex.PRESENT) { return MavenImages.IMG_VERSION_SRC; @@ -75,28 +68,36 @@ public class IndexedArtifactFileNode implements IMavenRepositoryNode, IArtifactN } - /* (non-Javadoc) - * @see org.eclipse.m2e.ui.internal.views.nodes.IArtifactNode#getDocumentKey() - */ public String getDocumentKey() { return NexusIndexManager.getDocumentKey(artifactFile.getArtifactKey()); } - /* (non-Javadoc) - * @see org.eclipse.m2e.ui.internal.views.nodes.IMavenRepositoryNode#isUpdating() - */ public boolean isUpdating() { return false; } - /* (non-Javadoc) - * @see org.eclipse.core.runtime.IAdaptable#getAdapter(java.lang.Class) - */ - public Object getAdapter(Class adapter) { - if (ArtifactKey.class.equals(adapter)) { - return new ArtifactKey(artifactFile.group, artifactFile.artifact, artifactFile.version, artifactFile.classifier); + @SuppressWarnings("rawtypes") + public static class AdapterFactory implements IAdapterFactory { + + private static final Class[] ADAPTERS = new Class[] {ArtifactKey.class, IndexedArtifactFile.class}; + + public Object getAdapter(Object adaptableObject, Class adapterType) { + if(adaptableObject instanceof IndexedArtifactFileNode) { + IndexedArtifactFileNode node = (IndexedArtifactFileNode) adaptableObject; + IndexedArtifactFile artifactFile = node.artifactFile; + if(ArtifactKey.class.equals(adapterType)) { + return new ArtifactKey(artifactFile.group, artifactFile.artifact, artifactFile.version, + artifactFile.classifier); + } else if(IndexedArtifactFile.class.equals(adapterType)) { + return artifactFile; + } + } + return null; } - return null; - } + public Class[] getAdapterList() { + return ADAPTERS; + } + + } } diff --git a/org.eclipse.m2e.core.ui/src/org/eclipse/m2e/core/ui/internal/views/nodes/IndexedArtifactNode.java b/org.eclipse.m2e.core.ui/src/org/eclipse/m2e/core/ui/internal/views/nodes/IndexedArtifactNode.java index d0778c62..f9f3d22d 100644 --- a/org.eclipse.m2e.core.ui/src/org/eclipse/m2e/core/ui/internal/views/nodes/IndexedArtifactNode.java +++ b/org.eclipse.m2e.core.ui/src/org/eclipse/m2e/core/ui/internal/views/nodes/IndexedArtifactNode.java @@ -14,77 +14,66 @@ package org.eclipse.m2e.core.ui.internal.views.nodes; import java.util.ArrayList; import java.util.Set; +import org.eclipse.swt.graphics.Image; + import org.eclipse.m2e.core.internal.index.IndexedArtifact; import org.eclipse.m2e.core.internal.index.IndexedArtifactFile; -import org.eclipse.m2e.core.ui.internal.Messages; import org.eclipse.m2e.core.ui.internal.MavenImages; -import org.eclipse.swt.graphics.Image; +import org.eclipse.m2e.core.ui.internal.Messages; + /** * IndexedArtifactNode - * + * * @author dyocum */ +@SuppressWarnings("restriction") public class IndexedArtifactNode implements IMavenRepositoryNode, IArtifactNode { private IndexedArtifact artifact; + private Object[] kids = null; - public IndexedArtifactNode(IndexedArtifact artifact){ + + public IndexedArtifactNode(IndexedArtifact artifact) { this.artifact = artifact; } - /* (non-Javadoc) - * @see org.eclipse.m2e.ui.internal.views.IMavenRepositoryNode#getChildren() - */ + public Object[] getChildren() { Set<IndexedArtifactFile> files = artifact.getFiles(); - if(files == null){ + if(files == null) { return new Object[0]; } ArrayList<Object> fileList = new ArrayList<Object>(); - for(IndexedArtifactFile iaf : files){ + for(IndexedArtifactFile iaf : files) { fileList.add(new IndexedArtifactFileNode(iaf)); } kids = fileList.toArray(new IndexedArtifactFileNode[fileList.size()]); return kids; } - /* (non-Javadoc) - * @see org.eclipse.m2e.ui.internal.views.IMavenRepositoryNode#getName() - */ public String getName() { // return a.group + ":" + a.artifact; String pkg = artifact.getPackaging(); - if(pkg == null){ + if(pkg == null) { pkg = Messages.IndexedArtifactNode_no_pack; } return artifact.getArtifactId() + " - " + pkg; //$NON-NLS-1$ } - /* (non-Javadoc) - * @see org.eclipse.m2e.ui.internal.views.IMavenRepositoryNode#hasChildren() - */ public boolean hasChildren() { //return kids != null && kids.length > 0; return true; } - - /* (non-Javadoc) - * @see org.eclipse.m2e.ui.internal.views.nodes.IMavenRepositoryNode#getImage() - */ + public Image getImage() { return MavenImages.IMG_JAR; } - /* (non-Javadoc) - * @see org.eclipse.m2e.ui.internal.views.nodes.IArtifactNode#getDocumentKey() - */ + public String getDocumentKey() { return artifact.getArtifactId(); } - /* (non-Javadoc) - * @see org.eclipse.m2e.ui.internal.views.nodes.IMavenRepositoryNode#isUpdating() - */ + public boolean isUpdating() { - // TODO Auto-generated method isUpdating return false; } diff --git a/org.eclipse.m2e.core.ui/src/org/eclipse/m2e/core/ui/internal/wizards/MavenPomSelectionComponent.java b/org.eclipse.m2e.core.ui/src/org/eclipse/m2e/core/ui/internal/wizards/MavenPomSelectionComponent.java index 146d9943..74e17928 100644 --- a/org.eclipse.m2e.core.ui/src/org/eclipse/m2e/core/ui/internal/wizards/MavenPomSelectionComponent.java +++ b/org.eclipse.m2e.core.ui/src/org/eclipse/m2e/core/ui/internal/wizards/MavenPomSelectionComponent.java @@ -11,18 +11,23 @@ package org.eclipse.m2e.core.ui.internal.wizards; +import java.util.ArrayList; import java.util.Collections; import java.util.HashSet; import java.util.LinkedHashMap; +import java.util.List; import java.util.Map; import java.util.Set; import com.ibm.icu.text.DateFormat; +import org.eclipse.core.resources.IProject; import org.eclipse.core.runtime.IProgressMonitor; import org.eclipse.core.runtime.IStatus; import org.eclipse.core.runtime.Status; import org.eclipse.core.runtime.jobs.Job; +import org.eclipse.jface.viewers.DecoratingStyledCellLabelProvider; +import org.eclipse.jface.viewers.DecorationContext; import org.eclipse.jface.viewers.DelegatingStyledCellLabelProvider; import org.eclipse.jface.viewers.IColorProvider; import org.eclipse.jface.viewers.IDecoration; @@ -54,17 +59,21 @@ import org.eclipse.swt.widgets.Label; import org.eclipse.swt.widgets.Text; import org.eclipse.swt.widgets.Tree; import org.eclipse.swt.widgets.TreeItem; +import org.eclipse.ui.PlatformUI; import org.apache.lucene.search.BooleanQuery; import org.eclipse.m2e.core.MavenPlugin; import org.eclipse.m2e.core.embedder.ArtifactKey; import org.eclipse.m2e.core.internal.IMavenConstants; +import org.eclipse.m2e.core.internal.MavenPluginActivator; import org.eclipse.m2e.core.internal.index.IIndex; import org.eclipse.m2e.core.internal.index.IndexManager; import org.eclipse.m2e.core.internal.index.IndexedArtifact; import org.eclipse.m2e.core.internal.index.IndexedArtifactFile; import org.eclipse.m2e.core.internal.index.UserInputSearchExpression; +import org.eclipse.m2e.core.internal.index.filter.ArtifactFilterManager; +import org.eclipse.m2e.core.ui.internal.M2EUIPluginActivator; import org.eclipse.m2e.core.ui.internal.MavenImages; import org.eclipse.m2e.core.ui.internal.Messages; @@ -74,8 +83,12 @@ import org.eclipse.m2e.core.ui.internal.Messages; * * @author Eugene Kuleshov */ +@SuppressWarnings("restriction") public class MavenPomSelectionComponent extends Composite { + public static final String PROP_DECORATION_CONTEXT_PROJECT = M2EUIPluginActivator.PLUGIN_ID + + ".decorationContextProject"; //$NON-NLS-1$ + /* (non-Javadoc) * @see org.eclipse.swt.widgets.Widget#dispose() */ @@ -123,6 +136,8 @@ public class MavenPomSelectionComponent extends Composite { final HashSet<String> artifactKeys = new HashSet<String>(); final HashSet<String> managedKeys = new HashSet<String>(); + private IProject project; + public MavenPomSelectionComponent(Composite parent, int style) { super(parent, style); createSearchComposite(); @@ -199,8 +214,10 @@ public class MavenPomSelectionComponent extends Composite { } - public void init(String queryText, String queryType, Set<ArtifactKey> artifacts, Set<ArtifactKey> managed) { + 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); @@ -220,13 +237,36 @@ public class MavenPomSelectionComponent extends Composite { } searchResultViewer.setContentProvider(new SearchResultContentProvider()); - searchResultViewer.setLabelProvider(new DelegatingStyledCellLabelProvider(new SearchResultLabelProvider(artifactKeys, managedKeys))); + + 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(new ISelectionChangedListener() { public void selectionChanged(SelectionChangedEvent event) { IStructuredSelection selection = (IStructuredSelection) event.getSelection(); if(!selection.isEmpty()) { - if(selection.size() == 1) { - IndexedArtifactFile f = getSelectedIndexedArtifactFile(selection.getFirstElement()); + List<IndexedArtifactFile> files = getSelectedIndexedArtifactFiles(selection); + + ArtifactFilterManager filterManager = MavenPluginActivator.getDefault().getArifactFilterManager(); + + for (IndexedArtifactFile file : files) { + ArtifactKey key = (ArtifactKey) file.getAdapter(ArtifactKey.class); + IStatus status = filterManager.filter(MavenPomSelectionComponent.this.project, key); + if (!status.isOK()) { + setStatus(IStatus.ERROR, status.getMessage()); + return; // TODO not nice to exit method like this + } + } + + 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); @@ -284,25 +324,32 @@ public class MavenPomSelectionComponent extends Composite { } public IndexedArtifactFile getIndexedArtifactFile() { - IStructuredSelection selection = (IStructuredSelection) searchResultViewer.getSelection(); - return getSelectedIndexedArtifactFile(selection.getFirstElement()); + List<IndexedArtifactFile> files = getSelectedIndexedArtifactFiles((IStructuredSelection) searchResultViewer.getSelection()); + return !files.isEmpty()? files.get(0): null; } - IndexedArtifactFile getSelectedIndexedArtifactFile(Object element) { - 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))) { - return file; + List<IndexedArtifactFile> getSelectedIndexedArtifactFiles(IStructuredSelection selection) { + ArrayList<IndexedArtifactFile> result = new ArrayList<IndexedArtifactFile>(); + 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 { + result.add(ia.getFiles().iterator().next()); } + } else if(element instanceof IndexedArtifactFile) { + result.add((IndexedArtifactFile) element); } - return ia.getFiles().iterator().next(); } - return (IndexedArtifactFile) element; + + return result; } void scheduleSearch(String query, boolean delay) { diff --git a/org.eclipse.m2e.core/META-INF/MANIFEST.MF b/org.eclipse.m2e.core/META-INF/MANIFEST.MF index 534b647c..72330a50 100644 --- a/org.eclipse.m2e.core/META-INF/MANIFEST.MF +++ b/org.eclipse.m2e.core/META-INF/MANIFEST.MF @@ -32,6 +32,7 @@ Export-Package: org.eclipse.m2e.core, org.eclipse.m2e.core.internal.content;x-internal:=true, org.eclipse.m2e.core.internal.embedder;x-internal:=true, org.eclipse.m2e.core.internal.index;x-internal:=true, + org.eclipse.m2e.core.internal.index.filter;x-internal:=true, org.eclipse.m2e.core.internal.index.nexus;x-internal:=true, org.eclipse.m2e.core.internal.jobs;x-internal:=true, org.eclipse.m2e.core.internal.lifecyclemapping;x-internal:=true, diff --git a/org.eclipse.m2e.core/plugin.xml b/org.eclipse.m2e.core/plugin.xml index ae16eec3..3806cb48 100644 --- a/org.eclipse.m2e.core/plugin.xml +++ b/org.eclipse.m2e.core/plugin.xml @@ -15,6 +15,7 @@ <extension-point id="mavenComponentContributors" name="%extension-point.component.name" schema="schema/mavenComponentContributors.exsd"/> <extension-point id="mavenProjectChangedListeners" name="%extension-point.changed.name" schema="schema/mavenProjectChangedListeners.exsd"/> <extension-point id="lifecycleMappingMetadataSource" name="%extension-point.lifecycleMappingMetadataSource.name" schema="schema/lifecycleMappingMetadataSource.exsd"/> + <extension-point id="artifactFilters" name="%extension-point.artifactFilters-name" schema="schema/artifactFilters.exsd"/> <extension point="org.eclipse.core.runtime.contentTypes"> <content-type id="pomFile" name="%content-type.name" diff --git a/org.eclipse.m2e.core/schema/artifactFilters.exsd b/org.eclipse.m2e.core/schema/artifactFilters.exsd new file mode 100644 index 00000000..94cc0946 --- /dev/null +++ b/org.eclipse.m2e.core/schema/artifactFilters.exsd @@ -0,0 +1,114 @@ +<?xml version='1.0' encoding='UTF-8'?> +<!-- Schema file written by PDE --> +<schema targetNamespace="org.eclipse.m2e.core" xmlns="http://www.w3.org/2001/XMLSchema"> +<annotation> + <appInfo> + <meta.schema plugin="org.eclipse.m2e.core" id="artifactFilters" name="%extension-point.artifactFilters-name"/> + </appInfo> + <documentation> + [Enter description of this extension point.] + </documentation> + </annotation> + + <element name="extension"> + <annotation> + <appInfo> + <meta.element /> + </appInfo> + </annotation> + <complexType> + <sequence> + <element ref="artifactFilter" minOccurs="1" maxOccurs="unbounded"/> + </sequence> + <attribute name="point" type="string" use="required"> + <annotation> + <documentation> + + </documentation> + </annotation> + </attribute> + <attribute name="id" type="string"> + <annotation> + <documentation> + + </documentation> + </annotation> + </attribute> + <attribute name="name" type="string"> + <annotation> + <documentation> + + </documentation> + <appInfo> + <meta.attribute translatable="true"/> + </appInfo> + </annotation> + </attribute> + </complexType> + </element> + + <element name="artifactFilter"> + <complexType> + <attribute name="class" type="string"> + <annotation> + <documentation> + + </documentation> + <appInfo> + <meta.attribute kind="java" basedOn=":org.eclipse.m2e.core.internal.index.filter.IArtifactFilter"/> + </appInfo> + </annotation> + </attribute> + </complexType> + </element> + + <annotation> + <appInfo> + <meta.section type="since"/> + </appInfo> + <documentation> + [Enter the first release in which this extension point appears.] + </documentation> + </annotation> + + <annotation> + <appInfo> + <meta.section type="examples"/> + </appInfo> + <documentation> + [Enter extension point usage example here.] + </documentation> + </annotation> + + <annotation> + <appInfo> + <meta.section type="apiinfo"/> + </appInfo> + <documentation> + [Enter API information here.] + </documentation> + </annotation> + + <annotation> + <appInfo> + <meta.section type="implementation"/> + </appInfo> + <documentation> + [Enter information about supplied implementation of this extension point.] + </documentation> + </annotation> + + <annotation> + <appinfo> + <meta.section type="copyright"/> + </appinfo> + <documentation> + Copyright (c) 2007, 2008 Sonatype, Inc. +All rights reserved. This program and the accompanying materials +are made available under the terms of the Eclipse Public License v1.0 +which accompanies this distribution, and is available at +http://www.eclipse.org/legal/epl-v10.html + </documentation> + </annotation> + +</schema> diff --git a/org.eclipse.m2e.core/src/org/eclipse/m2e/core/internal/MavenPluginActivator.java b/org.eclipse.m2e.core/src/org/eclipse/m2e/core/internal/MavenPluginActivator.java index f4cc3420..471a8b09 100644 --- a/org.eclipse.m2e.core/src/org/eclipse/m2e/core/internal/MavenPluginActivator.java +++ b/org.eclipse.m2e.core/src/org/eclipse/m2e/core/internal/MavenPluginActivator.java @@ -60,6 +60,7 @@ import org.eclipse.m2e.core.internal.embedder.MavenEmbeddedRuntime; import org.eclipse.m2e.core.internal.embedder.MavenImpl; import org.eclipse.m2e.core.internal.embedder.MavenWorkspaceRuntime; import org.eclipse.m2e.core.internal.index.IndexManager; +import org.eclipse.m2e.core.internal.index.filter.ArtifactFilterManager; import org.eclipse.m2e.core.internal.index.nexus.IndexesExtensionReader; import org.eclipse.m2e.core.internal.index.nexus.IndexingTransferListener; import org.eclipse.m2e.core.internal.index.nexus.NexusIndexManager; @@ -113,6 +114,8 @@ public class MavenPluginActivator extends Plugin { private RepositoryRegistry repositoryRegistry; + private ArtifactFilterManager artifactFilterManager; + private String version = "0.0.0"; //$NON-NLS-1$ private String qualifiedVersion = "0.0.0.qualifier"; //$NON-NLS-1$ @@ -228,7 +231,10 @@ public class MavenPluginActivator extends Plugin { this.repositoryRegistry.addRepositoryIndexer(indexManager); this.repositoryRegistry.addRepositoryDiscoverer(new IndexesExtensionReader(indexManager)); context.addBundleListener(bundleListener); - + + // + this.artifactFilterManager = new ArtifactFilterManager(); + // fork repository registry update. must after index manager registered as a listener this.repositoryRegistry.updateRegistry(); } @@ -413,4 +419,7 @@ public class MavenPluginActivator extends Plugin { return old; } + public ArtifactFilterManager getArifactFilterManager() { + return artifactFilterManager; + } } diff --git a/org.eclipse.m2e.core/src/org/eclipse/m2e/core/internal/index/filter/ArtifactFilterManager.java b/org.eclipse.m2e.core/src/org/eclipse/m2e/core/internal/index/filter/ArtifactFilterManager.java new file mode 100644 index 00000000..53885df5 --- /dev/null +++ b/org.eclipse.m2e.core/src/org/eclipse/m2e/core/internal/index/filter/ArtifactFilterManager.java @@ -0,0 +1,77 @@ +/******************************************************************************* + * Copyright (c) 2010 Sonatype, Inc. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Sonatype, Inc. - initial API and implementation + *******************************************************************************/ + +package org.eclipse.m2e.core.internal.index.filter; + +import java.util.ArrayList; +import java.util.List; + +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +import org.eclipse.core.resources.IProject; +import org.eclipse.core.runtime.CoreException; +import org.eclipse.core.runtime.IConfigurationElement; +import org.eclipse.core.runtime.IExtension; +import org.eclipse.core.runtime.IExtensionPoint; +import org.eclipse.core.runtime.IExtensionRegistry; +import org.eclipse.core.runtime.IStatus; +import org.eclipse.core.runtime.Platform; +import org.eclipse.core.runtime.Status; + +import org.eclipse.m2e.core.embedder.ArtifactKey; +import org.eclipse.m2e.core.internal.IMavenConstants; + + +/** + * ArtifactFilterManager + * + * @author igor + */ +public class ArtifactFilterManager { + private static final Logger log = LoggerFactory.getLogger(ArtifactFilterManager.class); + + public IStatus filter(IProject project, ArtifactKey artifact) { + for(IArtifactFilter filter : getFilters()) { + IStatus status = filter.filter(project, artifact); + if(status != null && status.matches(IStatus.ERROR)) { + // TODO should we aggregate multiple not-OK statuses? + return status; + } + } + return Status.OK_STATUS; + } + + private List<IArtifactFilter> getFilters() { + ArrayList<IArtifactFilter> filters = new ArrayList<IArtifactFilter>(); + + IExtensionRegistry registry = Platform.getExtensionRegistry(); + IExtensionPoint filtersExtensionPoint = registry.getExtensionPoint(IMavenConstants.PLUGIN_ID + ".artifactFilters"); + if(filtersExtensionPoint != null) { + IExtension[] filtersExtensions = filtersExtensionPoint.getExtensions(); + for(IExtension extension : filtersExtensions) { + IConfigurationElement[] elements = extension.getConfigurationElements(); + for(IConfigurationElement element : elements) { + if("artifactFilter".equals(element.getName())) { + try { + filters.add((IArtifactFilter) element.createExecutableExtension("class")); + } catch(CoreException ex) { + log.warn("Could not instantiate extension", ex); + } + } + } + } + } + + return filters; + } + +} diff --git a/org.eclipse.m2e.core/src/org/eclipse/m2e/core/internal/index/filter/FilteredIndex.java b/org.eclipse.m2e.core/src/org/eclipse/m2e/core/internal/index/filter/FilteredIndex.java new file mode 100644 index 00000000..7989141c --- /dev/null +++ b/org.eclipse.m2e.core/src/org/eclipse/m2e/core/internal/index/filter/FilteredIndex.java @@ -0,0 +1,111 @@ +/******************************************************************************* + * Copyright (c) 2010 Sonatype, Inc. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Sonatype, Inc. - initial API and implementation + *******************************************************************************/ + +package org.eclipse.m2e.core.internal.index.filter; + +import java.io.File; +import java.util.ArrayList; +import java.util.Collection; +import java.util.LinkedHashMap; +import java.util.Map; + +import org.eclipse.core.resources.IProject; +import org.eclipse.core.runtime.CoreException; + +import org.eclipse.m2e.core.embedder.ArtifactKey; +import org.eclipse.m2e.core.internal.MavenPluginActivator; +import org.eclipse.m2e.core.internal.index.IIndex; +import org.eclipse.m2e.core.internal.index.IndexedArtifact; +import org.eclipse.m2e.core.internal.index.IndexedArtifactFile; +import org.eclipse.m2e.core.internal.index.SearchExpression; + + +/** + * FilteredIndex + * + * @author igor + */ +public class FilteredIndex implements IIndex { + + private final IIndex index; + + private final IProject project; + + public FilteredIndex(IProject project, IIndex index) { + this.project = project; + this.index = index; + } + + public IndexedArtifactFile getIndexedArtifactFile(ArtifactKey artifact) throws CoreException { + return index.getIndexedArtifactFile(artifact); + } + + public IndexedArtifactFile identify(File file) throws CoreException { + return identify(file); + } + + public Collection<IndexedArtifact> find(SearchExpression groupId, SearchExpression artifactId, + SearchExpression version, SearchExpression packaging) throws CoreException { + return filter(index.find(groupId, artifactId, version, packaging)); + } + + public Collection<IndexedArtifact> find(Collection<SearchExpression> groupId, + Collection<SearchExpression> artifactId, Collection<SearchExpression> version, + Collection<SearchExpression> packaging) throws CoreException { + return filter(index.find(groupId, artifactId, version, packaging)); + } + + public Map<String, IndexedArtifact> search(SearchExpression expression, String searchType) throws CoreException { + return filter(index.search(expression, searchType)); + } + + public Map<String, IndexedArtifact> search(SearchExpression expression, String searchType, int classifier) + throws CoreException { + return filter(index.search(expression, searchType, classifier)); + } + + // filter methods + + protected Collection<IndexedArtifact> filter(Collection<IndexedArtifact> indexedArtifacts) { + ArrayList<IndexedArtifact> result = new ArrayList<IndexedArtifact>(); + for(IndexedArtifact indexedArtifact : indexedArtifacts) { + indexedArtifact = filter(indexedArtifact); + if(indexedArtifact != null && !indexedArtifact.getFiles().isEmpty()) { + result.add(indexedArtifact); + } + } + return result; + } + + protected IndexedArtifact filter(IndexedArtifact original) { + ArtifactFilterManager arifactFilterManager = MavenPluginActivator.getDefault().getArifactFilterManager(); + IndexedArtifact result = new IndexedArtifact(original.getGroupId(), original.getArtifactId(), + original.getPackageName(), original.getClassname(), original.getPackaging()); + for(IndexedArtifactFile file : original.getFiles()) { + if(arifactFilterManager.filter(project, (ArtifactKey) file.getAdapter(ArtifactKey.class)).isOK()) { + result.addFile(file); + } + } + return result; + } + + private Map<String, IndexedArtifact> filter(Map<String, IndexedArtifact> original) { + LinkedHashMap<String, IndexedArtifact> result = new LinkedHashMap<String, IndexedArtifact>(); + for(Map.Entry<String, IndexedArtifact> entry : original.entrySet()) { + IndexedArtifact filtered = filter(entry.getValue()); + if(filtered != null && !filtered.getFiles().isEmpty()) { + result.put(entry.getKey(), filtered); + } + } + return result; + } + +} diff --git a/org.eclipse.m2e.core/src/org/eclipse/m2e/core/internal/index/filter/IArtifactFilter.java b/org.eclipse.m2e.core/src/org/eclipse/m2e/core/internal/index/filter/IArtifactFilter.java new file mode 100644 index 00000000..a6d9eff0 --- /dev/null +++ b/org.eclipse.m2e.core/src/org/eclipse/m2e/core/internal/index/filter/IArtifactFilter.java @@ -0,0 +1,33 @@ +/******************************************************************************* + * Copyright (c) 2010 Sonatype, Inc. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Sonatype, Inc. - initial API and implementation + *******************************************************************************/ + +package org.eclipse.m2e.core.internal.index.filter; + +import org.eclipse.core.resources.IProject; +import org.eclipse.core.runtime.IStatus; + +import org.eclipse.m2e.core.embedder.ArtifactKey; + + +/** + * Experimental extension point interface that allows filtering of maven index artifacts from appearing from various + * places where m2e allows selection of artifacts. + */ +public interface IArtifactFilter { + + /** + * @param project is the filtering context project. can be <code>null</code> if no project context. + * @param artifact is the artifact to filter + * @return <code>null</code> or OK status if the artifact should be allowed, INFO/WARNING status to allow with a + * message and ERROR status to block the artifact. + */ + public IStatus filter(IProject project, ArtifactKey artifact); +} diff --git a/org.eclipse.m2e.core/src/org/eclipse/m2e/core/internal/markers/SourceLocationHelper.java b/org.eclipse.m2e.core/src/org/eclipse/m2e/core/internal/markers/SourceLocationHelper.java index 780fd075..2ecd6ed1 100644 --- a/org.eclipse.m2e.core/src/org/eclipse/m2e/core/internal/markers/SourceLocationHelper.java +++ b/org.eclipse.m2e.core/src/org/eclipse/m2e/core/internal/markers/SourceLocationHelper.java @@ -166,9 +166,13 @@ public class SourceLocationHelper { public static SourceLocation findLocation(MavenProject mavenProject, Dependency dependency) { org.apache.maven.model.Dependency mavenDependency = getMavenDependency(mavenProject, dependency); + return findLocation(mavenProject, mavenDependency); + } + + public static SourceLocation findLocation(MavenProject mavenProject, org.apache.maven.model.Dependency dependency) { InputLocation inputLocation = null; - if(mavenDependency != null) { - inputLocation = mavenDependency.getLocation(SELF); + if(dependency != null) { + inputLocation = dependency.getLocation(SELF); } if(inputLocation == null) { // Should never happen |