[GitHub] [maven-common-artifact-filters] elharo commented on a change in pull request #15: Big speed improvements for patterns that do not contain any wildcard

2021-01-25 Thread GitBox


elharo commented on a change in pull request #15:
URL: 
https://github.com/apache/maven-common-artifact-filters/pull/15#discussion_r563684005



##
File path: 
src/test/java/org/apache/maven/shared/artifact/filter/OldPatternIncludesArtifactFilter.java
##
@@ -0,0 +1,428 @@
+package org.apache.maven.shared.artifact.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.ArrayList;
+import java.util.Collection;
+import java.util.HashSet;
+import java.util.List;
+import java.util.Set;
+
+import org.apache.maven.artifact.Artifact;
+import org.apache.maven.artifact.ArtifactUtils;
+import org.apache.maven.artifact.resolver.filter.ArtifactFilter;
+import org.apache.maven.artifact.versioning.DefaultArtifactVersion;
+import 
org.apache.maven.artifact.versioning.InvalidVersionSpecificationException;
+import org.apache.maven.artifact.versioning.VersionRange;
+import org.codehaus.plexus.logging.Logger;
+
+/**
+ * TODO: include in maven-artifact in future
+ *
+ * @author mailto:br...@apache.org;>Brett Porter
+ * @see StrictPatternIncludesArtifactFilter
+ */
+public class OldPatternIncludesArtifactFilter
+implements ArtifactFilter, StatisticsReportingArtifactFilter
+{
+private final List positivePatterns;
+
+private final List negativePatterns;
+
+private final boolean actTransitively;
+
+private final Set patternsTriggered = new HashSet<>();
+
+private final List filteredArtifactIds = new ArrayList<>();
+
+/**
+ * @param patterns The pattern to be used.
+ */
+public OldPatternIncludesArtifactFilter( final Collection patterns 
)
+{
+this( patterns, false );
+}
+
+/**
+ * @param patterns The pattern to be used.
+ * @param actTransitively transitive yes/no.
+ */
+public OldPatternIncludesArtifactFilter( final Collection 
patterns, final boolean actTransitively )
+{
+this.actTransitively = actTransitively;
+final List pos = new ArrayList<>();
+final List neg = new ArrayList<>();
+if ( patterns != null && !patterns.isEmpty() )
+{
+for ( String pattern : patterns )
+{
+if ( pattern.startsWith( "!" ) )
+{
+neg.add( pattern.substring( 1 ) );
+}
+else
+{
+pos.add( pattern );
+}
+}
+}
+
+positivePatterns = pos;
+negativePatterns = neg;
+}
+
+/** {@inheritDoc} */
+public boolean include( final Artifact artifact )
+{
+final boolean shouldInclude = patternMatches( artifact );
+
+if ( !shouldInclude )
+{
+addFilteredArtifactId( artifact.getId() );
+}
+
+return shouldInclude;
+}
+
+/**
+ * @param artifact to check for.
+ * @return true if the match is true false otherwise.
+ */
+protected boolean patternMatches( final Artifact artifact )
+{
+return positiveMatch( artifact ) == Boolean.TRUE || negativeMatch( 
artifact ) == Boolean.FALSE;
+}
+
+/**
+ * @param artifactId add artifact to the filtered artifacts list.
+ */
+protected void addFilteredArtifactId( final String artifactId )
+{
+filteredArtifactIds.add( artifactId );
+}
+
+private Boolean negativeMatch( final Artifact artifact )
+{
+if ( negativePatterns == null || negativePatterns.isEmpty() )
+{
+return null;
+}
+else
+{
+return match( artifact, negativePatterns );
+}
+}
+
+/**
+ * @param artifact check for positive match.
+ * @return true/false.
+ */
+protected Boolean positiveMatch( final Artifact artifact )
+{
+if ( positivePatterns == null || positivePatterns.isEmpty() )
+{
+return null;
+}
+else
+{
+return match( artifact, positivePatterns );
+}
+}
+
+private boolean match( final Artifact artifact, final List 
patterns )
+{
+final String shortId = ArtifactUtils.versionlessKey( artifact );
+final String id = 

[GitHub] [maven-common-artifact-filters] elharo commented on a change in pull request #15: Big speed improvements for patterns that do not contain any wildcard

2021-01-25 Thread GitBox


elharo commented on a change in pull request #15:
URL: 
https://github.com/apache/maven-common-artifact-filters/pull/15#discussion_r563721313



##
File path: 
src/test/java/org/apache/maven/shared/artifact/filter/OldPatternIncludesArtifactFilter.java
##
@@ -0,0 +1,428 @@
+package org.apache.maven.shared.artifact.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.ArrayList;
+import java.util.Collection;
+import java.util.HashSet;
+import java.util.List;
+import java.util.Set;
+
+import org.apache.maven.artifact.Artifact;
+import org.apache.maven.artifact.ArtifactUtils;
+import org.apache.maven.artifact.resolver.filter.ArtifactFilter;
+import org.apache.maven.artifact.versioning.DefaultArtifactVersion;
+import 
org.apache.maven.artifact.versioning.InvalidVersionSpecificationException;
+import org.apache.maven.artifact.versioning.VersionRange;
+import org.codehaus.plexus.logging.Logger;
+
+/**
+ * TODO: include in maven-artifact in future
+ *
+ * @author mailto:br...@apache.org;>Brett Porter
+ * @see StrictPatternIncludesArtifactFilter
+ */
+public class OldPatternIncludesArtifactFilter
+implements ArtifactFilter, StatisticsReportingArtifactFilter
+{
+private final List positivePatterns;
+
+private final List negativePatterns;
+
+private final boolean actTransitively;
+
+private final Set patternsTriggered = new HashSet<>();
+
+private final List filteredArtifactIds = new ArrayList<>();
+
+/**
+ * @param patterns The pattern to be used.
+ */
+public OldPatternIncludesArtifactFilter( final Collection patterns 
)
+{
+this( patterns, false );
+}
+
+/**
+ * @param patterns The pattern to be used.
+ * @param actTransitively transitive yes/no.
+ */
+public OldPatternIncludesArtifactFilter( final Collection 
patterns, final boolean actTransitively )
+{
+this.actTransitively = actTransitively;
+final List pos = new ArrayList<>();
+final List neg = new ArrayList<>();
+if ( patterns != null && !patterns.isEmpty() )
+{
+for ( String pattern : patterns )
+{
+if ( pattern.startsWith( "!" ) )
+{
+neg.add( pattern.substring( 1 ) );
+}
+else
+{
+pos.add( pattern );
+}
+}
+}
+
+positivePatterns = pos;
+negativePatterns = neg;
+}
+
+/** {@inheritDoc} */
+public boolean include( final Artifact artifact )
+{
+final boolean shouldInclude = patternMatches( artifact );
+
+if ( !shouldInclude )
+{
+addFilteredArtifactId( artifact.getId() );
+}
+
+return shouldInclude;
+}
+
+/**
+ * @param artifact to check for.
+ * @return true if the match is true false otherwise.
+ */
+protected boolean patternMatches( final Artifact artifact )
+{
+return positiveMatch( artifact ) == Boolean.TRUE || negativeMatch( 
artifact ) == Boolean.FALSE;
+}
+
+/**
+ * @param artifactId add artifact to the filtered artifacts list.
+ */
+protected void addFilteredArtifactId( final String artifactId )
+{
+filteredArtifactIds.add( artifactId );
+}
+
+private Boolean negativeMatch( final Artifact artifact )
+{
+if ( negativePatterns == null || negativePatterns.isEmpty() )
+{
+return null;
+}
+else
+{
+return match( artifact, negativePatterns );
+}
+}
+
+/**
+ * @param artifact check for positive match.
+ * @return true/false.
+ */
+protected Boolean positiveMatch( final Artifact artifact )
+{
+if ( positivePatterns == null || positivePatterns.isEmpty() )
+{
+return null;
+}
+else
+{
+return match( artifact, positivePatterns );
+}
+}
+
+private boolean match( final Artifact artifact, final List 
patterns )
+{
+final String shortId = ArtifactUtils.versionlessKey( artifact );
+final String id = 

[GitHub] [maven-common-artifact-filters] elharo commented on a change in pull request #15: Big speed improvements for patterns that do not contain any wildcard

2021-01-25 Thread GitBox


elharo commented on a change in pull request #15:
URL: 
https://github.com/apache/maven-common-artifact-filters/pull/15#discussion_r563684005



##
File path: 
src/test/java/org/apache/maven/shared/artifact/filter/OldPatternIncludesArtifactFilter.java
##
@@ -0,0 +1,428 @@
+package org.apache.maven.shared.artifact.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.ArrayList;
+import java.util.Collection;
+import java.util.HashSet;
+import java.util.List;
+import java.util.Set;
+
+import org.apache.maven.artifact.Artifact;
+import org.apache.maven.artifact.ArtifactUtils;
+import org.apache.maven.artifact.resolver.filter.ArtifactFilter;
+import org.apache.maven.artifact.versioning.DefaultArtifactVersion;
+import 
org.apache.maven.artifact.versioning.InvalidVersionSpecificationException;
+import org.apache.maven.artifact.versioning.VersionRange;
+import org.codehaus.plexus.logging.Logger;
+
+/**
+ * TODO: include in maven-artifact in future
+ *
+ * @author mailto:br...@apache.org;>Brett Porter
+ * @see StrictPatternIncludesArtifactFilter
+ */
+public class OldPatternIncludesArtifactFilter
+implements ArtifactFilter, StatisticsReportingArtifactFilter
+{
+private final List positivePatterns;
+
+private final List negativePatterns;
+
+private final boolean actTransitively;
+
+private final Set patternsTriggered = new HashSet<>();
+
+private final List filteredArtifactIds = new ArrayList<>();
+
+/**
+ * @param patterns The pattern to be used.
+ */
+public OldPatternIncludesArtifactFilter( final Collection patterns 
)
+{
+this( patterns, false );
+}
+
+/**
+ * @param patterns The pattern to be used.
+ * @param actTransitively transitive yes/no.
+ */
+public OldPatternIncludesArtifactFilter( final Collection 
patterns, final boolean actTransitively )
+{
+this.actTransitively = actTransitively;
+final List pos = new ArrayList<>();
+final List neg = new ArrayList<>();
+if ( patterns != null && !patterns.isEmpty() )
+{
+for ( String pattern : patterns )
+{
+if ( pattern.startsWith( "!" ) )
+{
+neg.add( pattern.substring( 1 ) );
+}
+else
+{
+pos.add( pattern );
+}
+}
+}
+
+positivePatterns = pos;
+negativePatterns = neg;
+}
+
+/** {@inheritDoc} */
+public boolean include( final Artifact artifact )
+{
+final boolean shouldInclude = patternMatches( artifact );
+
+if ( !shouldInclude )
+{
+addFilteredArtifactId( artifact.getId() );
+}
+
+return shouldInclude;
+}
+
+/**
+ * @param artifact to check for.
+ * @return true if the match is true false otherwise.
+ */
+protected boolean patternMatches( final Artifact artifact )
+{
+return positiveMatch( artifact ) == Boolean.TRUE || negativeMatch( 
artifact ) == Boolean.FALSE;
+}
+
+/**
+ * @param artifactId add artifact to the filtered artifacts list.
+ */
+protected void addFilteredArtifactId( final String artifactId )
+{
+filteredArtifactIds.add( artifactId );
+}
+
+private Boolean negativeMatch( final Artifact artifact )
+{
+if ( negativePatterns == null || negativePatterns.isEmpty() )
+{
+return null;
+}
+else
+{
+return match( artifact, negativePatterns );
+}
+}
+
+/**
+ * @param artifact check for positive match.
+ * @return true/false.
+ */
+protected Boolean positiveMatch( final Artifact artifact )
+{
+if ( positivePatterns == null || positivePatterns.isEmpty() )
+{
+return null;
+}
+else
+{
+return match( artifact, positivePatterns );
+}
+}
+
+private boolean match( final Artifact artifact, final List 
patterns )
+{
+final String shortId = ArtifactUtils.versionlessKey( artifact );
+final String id = 

[GitHub] [maven-common-artifact-filters] elharo commented on a change in pull request #15: Big speed improvements for patterns that do not contain any wildcard

2021-01-24 Thread GitBox


elharo commented on a change in pull request #15:
URL: 
https://github.com/apache/maven-common-artifact-filters/pull/15#discussion_r563294869



##
File path: 
src/test/java/org/apache/maven/shared/artifact/filter/PatternFilterPerfTest.java
##
@@ -0,0 +1,122 @@
+package org.apache.maven.shared.artifact.filter;

Review comment:
   Needs a copyright statement





This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
us...@infra.apache.org