You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@maven.apache.org by rf...@apache.org on 2015/05/18 22:36:27 UTC

svn commit: r1680090 - in /maven/shared/trunk/maven-artifact-transfer/src/main/java/org/apache/maven/shared/artifact/resolve: filter/ internal/

Author: rfscholte
Date: Mon May 18 20:36:26 2015
New Revision: 1680090

URL: http://svn.apache.org/r1680090
Log:
Filters can be chained, so we must use Visitor pattern in order to transform them all.
Added FilterTransformer implementations for both Aether versions

Added:
    maven/shared/trunk/maven-artifact-transfer/src/main/java/org/apache/maven/shared/artifact/resolve/filter/
    maven/shared/trunk/maven-artifact-transfer/src/main/java/org/apache/maven/shared/artifact/resolve/filter/AndFilter.java
    maven/shared/trunk/maven-artifact-transfer/src/main/java/org/apache/maven/shared/artifact/resolve/filter/ExclusionsFilter.java
    maven/shared/trunk/maven-artifact-transfer/src/main/java/org/apache/maven/shared/artifact/resolve/filter/FilterTransformer.java
    maven/shared/trunk/maven-artifact-transfer/src/main/java/org/apache/maven/shared/artifact/resolve/filter/OrFilter.java
    maven/shared/trunk/maven-artifact-transfer/src/main/java/org/apache/maven/shared/artifact/resolve/filter/ScopeFilter.java
    maven/shared/trunk/maven-artifact-transfer/src/main/java/org/apache/maven/shared/artifact/resolve/filter/TransformableFilter.java
    maven/shared/trunk/maven-artifact-transfer/src/main/java/org/apache/maven/shared/artifact/resolve/internal/EclipseAetherFilterTransformer.java
    maven/shared/trunk/maven-artifact-transfer/src/main/java/org/apache/maven/shared/artifact/resolve/internal/SonatypeAetherFilterTransformer.java

Added: maven/shared/trunk/maven-artifact-transfer/src/main/java/org/apache/maven/shared/artifact/resolve/filter/AndFilter.java
URL: http://svn.apache.org/viewvc/maven/shared/trunk/maven-artifact-transfer/src/main/java/org/apache/maven/shared/artifact/resolve/filter/AndFilter.java?rev=1680090&view=auto
==============================================================================
--- maven/shared/trunk/maven-artifact-transfer/src/main/java/org/apache/maven/shared/artifact/resolve/filter/AndFilter.java (added)
+++ maven/shared/trunk/maven-artifact-transfer/src/main/java/org/apache/maven/shared/artifact/resolve/filter/AndFilter.java Mon May 18 20:36:26 2015
@@ -0,0 +1,63 @@
+package org.apache.maven.shared.artifact.resolve.filter;
+
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *  http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+import java.util.Collection;
+import java.util.Collections;
+
+/**
+ * A filter that combines zero or more other filters using a logical {@code AND}.
+ * 
+ * @author Robert Scholte
+ *
+ */
+public class AndFilter
+    implements TransformableFilter
+{
+    private final Collection<TransformableFilter> filters;
+
+    /**
+     * 
+     * @param filters the filters, may not be {@code null}
+     */
+    public AndFilter( Collection<TransformableFilter> filters )
+    {
+        this.filters = Collections.unmodifiableCollection( filters );
+    }
+
+    /**
+     * @return the filters, never {@code null} 
+     */
+    public Collection<TransformableFilter> getFilters()
+    {
+        return filters;
+    }
+
+    /**
+     * Transform this filter to a tool specific implementation
+     * 
+     * @param transformer the transformer
+     */
+    public <T> T transform( FilterTransformer<T> transformer )
+    {
+        return transformer.transform( this );
+    }
+
+}

Added: maven/shared/trunk/maven-artifact-transfer/src/main/java/org/apache/maven/shared/artifact/resolve/filter/ExclusionsFilter.java
URL: http://svn.apache.org/viewvc/maven/shared/trunk/maven-artifact-transfer/src/main/java/org/apache/maven/shared/artifact/resolve/filter/ExclusionsFilter.java?rev=1680090&view=auto
==============================================================================
--- maven/shared/trunk/maven-artifact-transfer/src/main/java/org/apache/maven/shared/artifact/resolve/filter/ExclusionsFilter.java (added)
+++ maven/shared/trunk/maven-artifact-transfer/src/main/java/org/apache/maven/shared/artifact/resolve/filter/ExclusionsFilter.java Mon May 18 20:36:26 2015
@@ -0,0 +1,58 @@
+package org.apache.maven.shared.artifact.resolve.filter;
+
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *  http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+import java.util.Collection;
+import java.util.Collections;
+
+/**
+ * 
+ * 
+ * @author Robert Scholte
+ *
+ */
+public class ExclusionsFilter
+    implements TransformableFilter
+{
+    private final Collection<String> excludes;
+
+    /**
+     * @param excludes the keys to exclude, may not be {@code null}
+     */
+    public ExclusionsFilter( Collection<String> excludes )
+    {
+        this.excludes = Collections.unmodifiableCollection( excludes );
+    }
+
+    public final Collection<String> getExcludes()
+    {
+        return excludes;
+    }
+
+    /**
+     * Transform this filter to a tool specific implementation
+     * 
+     * @param transformer the transformer
+     */
+    public <T> T transform( FilterTransformer<T> transformer )
+    {
+        return transformer.transform( this );
+    }
+}

Added: maven/shared/trunk/maven-artifact-transfer/src/main/java/org/apache/maven/shared/artifact/resolve/filter/FilterTransformer.java
URL: http://svn.apache.org/viewvc/maven/shared/trunk/maven-artifact-transfer/src/main/java/org/apache/maven/shared/artifact/resolve/filter/FilterTransformer.java?rev=1680090&view=auto
==============================================================================
--- maven/shared/trunk/maven-artifact-transfer/src/main/java/org/apache/maven/shared/artifact/resolve/filter/FilterTransformer.java (added)
+++ maven/shared/trunk/maven-artifact-transfer/src/main/java/org/apache/maven/shared/artifact/resolve/filter/FilterTransformer.java Mon May 18 20:36:26 2015
@@ -0,0 +1,59 @@
+package org.apache.maven.shared.artifact.resolve.filter;
+
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *  http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+/**
+ * Provide a mechanism to transform a Filter to a tool specific equivalent.
+ * For example: Aether has its own set of filters.  
+ * 
+ * @author Robert Scholte
+ *
+ * @param <T> the tool specific filter
+ */
+public interface FilterTransformer<T>
+{
+    /**
+     * 
+     * @param scopeFilter the filter 
+     * @return the transformed filter
+     */
+    T transform( ScopeFilter scopeFilter );
+
+    /**
+     * 
+     * @param andFilter the filter
+     * @return the transformed filter
+     */
+    T transform( AndFilter andFilter );
+
+    /**
+     * 
+     * @param exclusionsFilter the filter
+     * @return the transformed filter
+     */
+    T transform( ExclusionsFilter exclusionsFilter );
+
+    /**
+     * 
+     * @param orFilter the filter
+     * @return the transformed filter
+     */
+    T transform( OrFilter orFilter );
+}

Added: maven/shared/trunk/maven-artifact-transfer/src/main/java/org/apache/maven/shared/artifact/resolve/filter/OrFilter.java
URL: http://svn.apache.org/viewvc/maven/shared/trunk/maven-artifact-transfer/src/main/java/org/apache/maven/shared/artifact/resolve/filter/OrFilter.java?rev=1680090&view=auto
==============================================================================
--- maven/shared/trunk/maven-artifact-transfer/src/main/java/org/apache/maven/shared/artifact/resolve/filter/OrFilter.java (added)
+++ maven/shared/trunk/maven-artifact-transfer/src/main/java/org/apache/maven/shared/artifact/resolve/filter/OrFilter.java Mon May 18 20:36:26 2015
@@ -0,0 +1,62 @@
+package org.apache.maven.shared.artifact.resolve.filter;
+
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *  http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+import java.util.Collection;
+import java.util.Collections;
+
+/**
+ * A filter that combines zero or more other filters using a logical {@code OR}.
+ * 
+ * @author Robert Scholte
+ *
+ */
+public class OrFilter implements TransformableFilter
+{
+
+    private final Collection<TransformableFilter> filters;
+
+    /**
+     * 
+     * @param filters the filters, may not be {@code null}
+     */
+    public OrFilter( Collection<TransformableFilter> filters )
+    {
+        this.filters = Collections.unmodifiableCollection( filters );
+    }
+    
+    /**
+     * @return the filters, never {@code null} 
+     */
+    public Collection<TransformableFilter> getFilters()
+    {
+        return filters;
+    }
+    
+    /**
+     * Transform this filter to a tool specific implementation
+     * 
+     * @param transformer the transformer
+     */
+    public <T> T transform( FilterTransformer<T> transformer )
+    {
+        return transformer.transform( this );
+    }
+}

Added: maven/shared/trunk/maven-artifact-transfer/src/main/java/org/apache/maven/shared/artifact/resolve/filter/ScopeFilter.java
URL: http://svn.apache.org/viewvc/maven/shared/trunk/maven-artifact-transfer/src/main/java/org/apache/maven/shared/artifact/resolve/filter/ScopeFilter.java?rev=1680090&view=auto
==============================================================================
--- maven/shared/trunk/maven-artifact-transfer/src/main/java/org/apache/maven/shared/artifact/resolve/filter/ScopeFilter.java (added)
+++ maven/shared/trunk/maven-artifact-transfer/src/main/java/org/apache/maven/shared/artifact/resolve/filter/ScopeFilter.java Mon May 18 20:36:26 2015
@@ -0,0 +1,74 @@
+package org.apache.maven.shared.artifact.resolve.filter;
+
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *  http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+import java.util.Collection;
+import java.util.Collections;
+
+/**
+ * Filter based on scope. <em>Note:<em> There's no logic for inherited scoped
+ * 
+ * @author Robert Scholte
+ */
+public class ScopeFilter implements TransformableFilter
+{
+    private final Collection<String> excluded;
+
+    private final Collection<String> included;
+    
+    /**
+     * 
+     * @param included specific scopes to include or {@null} to include all
+     * @param excluded specific scopes to exclude or {@null} to exclude none
+     */
+    public ScopeFilter( Collection<String> included, Collection<String> excluded )
+    {
+        this.included = ( included == null ? null : Collections.unmodifiableCollection( included ) );
+        this.excluded = ( excluded == null ? null : Collections.unmodifiableCollection( excluded ) );
+    }
+    
+    /**
+     * 
+     * @return the scopes to exclude, may be {@code null}
+     */
+    public final Collection<String> getExcluded()
+    {
+        return excluded;
+    }
+    
+    /**
+     * 
+     * @return the scopes to include, may be {@code null}
+     */
+    public final Collection<String> getIncluded()
+    {
+        return included;
+    }
+    
+    /**
+     * Transform this filter to a tool specific implementation
+     * 
+     * @param transformer the transformer
+     */
+    public <T> T transform ( FilterTransformer<T> transformer )
+    {
+        return transformer.transform( this );
+    }
+}

Added: maven/shared/trunk/maven-artifact-transfer/src/main/java/org/apache/maven/shared/artifact/resolve/filter/TransformableFilter.java
URL: http://svn.apache.org/viewvc/maven/shared/trunk/maven-artifact-transfer/src/main/java/org/apache/maven/shared/artifact/resolve/filter/TransformableFilter.java?rev=1680090&view=auto
==============================================================================
--- maven/shared/trunk/maven-artifact-transfer/src/main/java/org/apache/maven/shared/artifact/resolve/filter/TransformableFilter.java (added)
+++ maven/shared/trunk/maven-artifact-transfer/src/main/java/org/apache/maven/shared/artifact/resolve/filter/TransformableFilter.java Mon May 18 20:36:26 2015
@@ -0,0 +1,38 @@
+package org.apache.maven.shared.artifact.resolve.filter;
+
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *  http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+public interface TransformableFilter
+{
+    /**
+     * Subclasses should include the following code:
+     * <pre>
+     *   &#64;Override
+     *   public abstract &lt;T&gt; T transform( FilterTransformer&lt;T&gt; transformer )
+     *   {
+     *       return transformer.transform( this );
+     *   }
+     * </pre>
+     * 
+     * @param transformer the tool specific transformer
+     * @return the transformed value
+     */
+    public abstract <T> T transform( FilterTransformer<T> transformer );
+}

Added: maven/shared/trunk/maven-artifact-transfer/src/main/java/org/apache/maven/shared/artifact/resolve/internal/EclipseAetherFilterTransformer.java
URL: http://svn.apache.org/viewvc/maven/shared/trunk/maven-artifact-transfer/src/main/java/org/apache/maven/shared/artifact/resolve/internal/EclipseAetherFilterTransformer.java?rev=1680090&view=auto
==============================================================================
--- maven/shared/trunk/maven-artifact-transfer/src/main/java/org/apache/maven/shared/artifact/resolve/internal/EclipseAetherFilterTransformer.java (added)
+++ maven/shared/trunk/maven-artifact-transfer/src/main/java/org/apache/maven/shared/artifact/resolve/internal/EclipseAetherFilterTransformer.java Mon May 18 20:36:26 2015
@@ -0,0 +1,69 @@
+package org.apache.maven.shared.artifact.resolve.internal;
+
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *  http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+import java.util.ArrayList;
+import java.util.Collection;
+
+import org.apache.maven.shared.artifact.resolve.filter.TransformableFilter;
+import org.apache.maven.shared.artifact.resolve.filter.AndFilter;
+import org.apache.maven.shared.artifact.resolve.filter.ExclusionsFilter;
+import org.apache.maven.shared.artifact.resolve.filter.FilterTransformer;
+import org.apache.maven.shared.artifact.resolve.filter.OrFilter;
+import org.apache.maven.shared.artifact.resolve.filter.ScopeFilter;
+import org.eclipse.aether.util.filter.AndDependencyFilter;
+import org.eclipse.aether.util.filter.ExclusionsDependencyFilter;
+import org.eclipse.aether.util.filter.ScopeDependencyFilter;
+import org.eclipse.aether.graph.DependencyFilter;
+
+class EclipseAetherFilterTransformer implements FilterTransformer<DependencyFilter>
+{
+    
+    public AndDependencyFilter transform( AndFilter andFilter )
+    {
+        Collection<DependencyFilter> filters = new ArrayList<DependencyFilter>();
+        for ( TransformableFilter filter : andFilter.getFilters() )
+        {
+            filters.add( filter.transform( this ) );
+        }
+        return new AndDependencyFilter( filters );
+    }
+
+    public ExclusionsDependencyFilter transform( ExclusionsFilter filter )
+    {
+        return new ExclusionsDependencyFilter( filter.getExcludes() );
+    }
+
+    public AndDependencyFilter transform( OrFilter orFilter )
+    {
+        Collection<DependencyFilter> filters = new ArrayList<DependencyFilter>();
+        for ( TransformableFilter filter : orFilter.getFilters() )
+        {
+            filters.add( filter.transform( this ) );
+        }
+        return new AndDependencyFilter( filters );
+    }
+
+    public ScopeDependencyFilter transform( ScopeFilter filter )
+    {
+        return new ScopeDependencyFilter( filter.getIncluded(), filter.getExcluded() );
+    }
+
+}

Added: maven/shared/trunk/maven-artifact-transfer/src/main/java/org/apache/maven/shared/artifact/resolve/internal/SonatypeAetherFilterTransformer.java
URL: http://svn.apache.org/viewvc/maven/shared/trunk/maven-artifact-transfer/src/main/java/org/apache/maven/shared/artifact/resolve/internal/SonatypeAetherFilterTransformer.java?rev=1680090&view=auto
==============================================================================
--- maven/shared/trunk/maven-artifact-transfer/src/main/java/org/apache/maven/shared/artifact/resolve/internal/SonatypeAetherFilterTransformer.java (added)
+++ maven/shared/trunk/maven-artifact-transfer/src/main/java/org/apache/maven/shared/artifact/resolve/internal/SonatypeAetherFilterTransformer.java Mon May 18 20:36:26 2015
@@ -0,0 +1,70 @@
+package org.apache.maven.shared.artifact.resolve.internal;
+
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *  http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+import java.util.ArrayList;
+import java.util.Collection;
+
+import org.apache.maven.shared.artifact.resolve.filter.TransformableFilter;
+import org.apache.maven.shared.artifact.resolve.filter.AndFilter;
+import org.apache.maven.shared.artifact.resolve.filter.ExclusionsFilter;
+import org.apache.maven.shared.artifact.resolve.filter.FilterTransformer;
+import org.apache.maven.shared.artifact.resolve.filter.OrFilter;
+import org.apache.maven.shared.artifact.resolve.filter.ScopeFilter;
+import org.sonatype.aether.graph.DependencyFilter;
+import org.sonatype.aether.util.filter.AndDependencyFilter;
+import org.sonatype.aether.util.filter.ExclusionsDependencyFilter;
+import org.sonatype.aether.util.filter.OrDependencyFilter;
+import org.sonatype.aether.util.filter.ScopeDependencyFilter;
+
+class SonatypeAetherFilterTransformer implements FilterTransformer<DependencyFilter>
+{
+    public AndDependencyFilter transform( AndFilter filter )
+    {
+        Collection<DependencyFilter> filters = new ArrayList<DependencyFilter>( filter.getFilters().size() );
+        for ( TransformableFilter dependencyFilter : filter.getFilters() )
+        {
+            filters.add( dependencyFilter.transform( this ) );
+        }
+        return new AndDependencyFilter( filters );
+    }
+
+
+    public ExclusionsDependencyFilter transform( ExclusionsFilter filter )
+    {
+        return new ExclusionsDependencyFilter( filter.getExcludes() );
+    }
+    
+    public OrDependencyFilter transform( OrFilter filter )
+    {
+        Collection<DependencyFilter> filters = new ArrayList<DependencyFilter>( filter.getFilters().size() );
+        for ( TransformableFilter dependencyFilter : filter.getFilters() )
+        {
+            filters.add( dependencyFilter.transform( this ) );
+        }
+        return new OrDependencyFilter( filters );
+    }
+    
+    public ScopeDependencyFilter transform( ScopeFilter filter )
+    {
+        return new ScopeDependencyFilter( filter.getIncluded(), filter.getExcluded() );
+    }
+
+}