Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
Diffstat (limited to 'org.eclipse.m2e.core')
-rw-r--r--org.eclipse.m2e.core/META-INF/MANIFEST.MF1
-rw-r--r--org.eclipse.m2e.core/plugin.xml1
-rw-r--r--org.eclipse.m2e.core/schema/artifactFilters.exsd114
-rw-r--r--org.eclipse.m2e.core/src/org/eclipse/m2e/core/internal/MavenPluginActivator.java11
-rw-r--r--org.eclipse.m2e.core/src/org/eclipse/m2e/core/internal/index/filter/ArtifactFilterManager.java77
-rw-r--r--org.eclipse.m2e.core/src/org/eclipse/m2e/core/internal/index/filter/FilteredIndex.java111
-rw-r--r--org.eclipse.m2e.core/src/org/eclipse/m2e/core/internal/index/filter/IArtifactFilter.java33
-rw-r--r--org.eclipse.m2e.core/src/org/eclipse/m2e/core/internal/markers/SourceLocationHelper.java8
8 files changed, 353 insertions, 3 deletions
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

Back to the top