http://git-wip-us.apache.org/repos/asf/maven-resolver/blob/3a1b8ae0/aether-util/src/main/java/org/eclipse/aether/util/version/GenericVersionRange.java ---------------------------------------------------------------------- diff --git a/aether-util/src/main/java/org/eclipse/aether/util/version/GenericVersionRange.java b/aether-util/src/main/java/org/eclipse/aether/util/version/GenericVersionRange.java deleted file mode 100644 index 832dd94..0000000 --- a/aether-util/src/main/java/org/eclipse/aether/util/version/GenericVersionRange.java +++ /dev/null @@ -1,242 +0,0 @@ -package org.eclipse.aether.util.version; - -/* - * 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 org.eclipse.aether.version.InvalidVersionSpecificationException; -import org.eclipse.aether.version.Version; -import org.eclipse.aether.version.VersionRange; - -/** - * A version range inspired by mathematical range syntax. For example, "[1.0,2.0)", "[1.0,)" or "[1.0]". - */ -final class GenericVersionRange - implements VersionRange -{ - - private final Bound lowerBound; - - private final Bound upperBound; - - /** - * Creates a version range from the specified range specification. - * - * @param range The range specification to parse, must not be {@code null}. - * @throws InvalidVersionSpecificationException If the range could not be parsed. - */ - public GenericVersionRange( String range ) - throws InvalidVersionSpecificationException - { - String process = range; - - boolean lowerBoundInclusive, upperBoundInclusive; - Version lowerBound, upperBound; - - if ( range.startsWith( "[" ) ) - { - lowerBoundInclusive = true; - } - else if ( range.startsWith( "(" ) ) - { - lowerBoundInclusive = false; - } - else - { - throw new InvalidVersionSpecificationException( range, "Invalid version range " + range - + ", a range must start with either [ or (" ); - } - - if ( range.endsWith( "]" ) ) - { - upperBoundInclusive = true; - } - else if ( range.endsWith( ")" ) ) - { - upperBoundInclusive = false; - } - else - { - throw new InvalidVersionSpecificationException( range, "Invalid version range " + range - + ", a range must end with either [ or (" ); - } - - process = process.substring( 1, process.length() - 1 ); - - int index = process.indexOf( "," ); - - if ( index < 0 ) - { - if ( !lowerBoundInclusive || !upperBoundInclusive ) - { - throw new InvalidVersionSpecificationException( range, "Invalid version range " + range - + ", single version must be surrounded by []" ); - } - - String version = process.trim(); - if ( version.endsWith( ".*" ) ) - { - String prefix = version.substring( 0, version.length() - 1 ); - lowerBound = parse( prefix + "min" ); - upperBound = parse( prefix + "max" ); - } - else - { - lowerBound = upperBound = parse( version ); - } - } - else - { - String parsedLowerBound = process.substring( 0, index ).trim(); - String parsedUpperBound = process.substring( index + 1 ).trim(); - - // more than two bounds, e.g. (1,2,3) - if ( parsedUpperBound.contains( "," ) ) - { - throw new InvalidVersionSpecificationException( range, "Invalid version range " + range - + ", bounds may not contain additional ','" ); - } - - lowerBound = parsedLowerBound.length() > 0 ? parse( parsedLowerBound ) : null; - upperBound = parsedUpperBound.length() > 0 ? parse( parsedUpperBound ) : null; - - if ( upperBound != null && lowerBound != null ) - { - if ( upperBound.compareTo( lowerBound ) < 0 ) - { - throw new InvalidVersionSpecificationException( range, "Invalid version range " + range - + ", lower bound must not be greater than upper bound" ); - } - } - } - - this.lowerBound = ( lowerBound != null ) ? new Bound( lowerBound, lowerBoundInclusive ) : null; - this.upperBound = ( upperBound != null ) ? new Bound( upperBound, upperBoundInclusive ) : null; - } - - private Version parse( String version ) - { - return new GenericVersion( version ); - } - - public Bound getLowerBound() - { - return lowerBound; - } - - public Bound getUpperBound() - { - return upperBound; - } - - public boolean containsVersion( Version version ) - { - if ( lowerBound != null ) - { - int comparison = lowerBound.getVersion().compareTo( version ); - - if ( comparison == 0 && !lowerBound.isInclusive() ) - { - return false; - } - if ( comparison > 0 ) - { - return false; - } - } - - if ( upperBound != null ) - { - int comparison = upperBound.getVersion().compareTo( version ); - - if ( comparison == 0 && !upperBound.isInclusive() ) - { - return false; - } - if ( comparison < 0 ) - { - return false; - } - } - - return true; - } - - @Override - public boolean equals( Object obj ) - { - if ( obj == this ) - { - return true; - } - else if ( obj == null || !getClass().equals( obj.getClass() ) ) - { - return false; - } - - GenericVersionRange that = (GenericVersionRange) obj; - - return eq( upperBound, that.upperBound ) && eq( lowerBound, that.lowerBound ); - } - - private static <T> boolean eq( T s1, T s2 ) - { - return s1 != null ? s1.equals( s2 ) : s2 == null; - } - - @Override - public int hashCode() - { - int hash = 17; - hash = hash * 31 + hash( upperBound ); - hash = hash * 31 + hash( lowerBound ); - return hash; - } - - private static int hash( Object obj ) - { - return obj != null ? obj.hashCode() : 0; - } - - @Override - public String toString() - { - StringBuilder buffer = new StringBuilder( 64 ); - if ( lowerBound != null ) - { - buffer.append( lowerBound.isInclusive() ? '[' : '(' ); - buffer.append( lowerBound.getVersion() ); - } - else - { - buffer.append( '(' ); - } - buffer.append( ',' ); - if ( upperBound != null ) - { - buffer.append( upperBound.getVersion() ); - buffer.append( upperBound.isInclusive() ? ']' : ')' ); - } - else - { - buffer.append( ')' ); - } - return buffer.toString(); - } - -}
http://git-wip-us.apache.org/repos/asf/maven-resolver/blob/3a1b8ae0/aether-util/src/main/java/org/eclipse/aether/util/version/GenericVersionScheme.java ---------------------------------------------------------------------- diff --git a/aether-util/src/main/java/org/eclipse/aether/util/version/GenericVersionScheme.java b/aether-util/src/main/java/org/eclipse/aether/util/version/GenericVersionScheme.java deleted file mode 100644 index 8fc0488..0000000 --- a/aether-util/src/main/java/org/eclipse/aether/util/version/GenericVersionScheme.java +++ /dev/null @@ -1,149 +0,0 @@ -package org.eclipse.aether.util.version; - -/* - * 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.eclipse.aether.version.InvalidVersionSpecificationException; -import org.eclipse.aether.version.Version; -import org.eclipse.aether.version.VersionConstraint; -import org.eclipse.aether.version.VersionRange; -import org.eclipse.aether.version.VersionScheme; - -/** - * A version scheme using a generic version syntax and common sense sorting. - * <p> - * This scheme accepts versions of any form, interpreting a version as a sequence of numeric and alphabetic segments. - * The characters '-', '_', and '.' as well as the mere transitions from digit to letter and vice versa delimit the - * version segments. Delimiters are treated as equivalent. - * </p> - * <p> - * Numeric segments are compared mathematically, alphabetic segments are compared lexicographically and - * case-insensitively. However, the following qualifier strings are recognized and treated specially: "alpha" = "a" < - * "beta" = "b" < "milestone" = "m" < "cr" = "rc" < "snapshot" < "final" = "ga" < "sp". All of those - * well-known qualifiers are considered smaller/older than other strings. An empty segment/string is equivalent to 0. - * </p> - * <p> - * In addition to the above mentioned qualifiers, the tokens "min" and "max" may be used as final version segment to - * denote the smallest/greatest version having a given prefix. For example, "1.2.min" denotes the smallest version in - * the 1.2 line, "1.2.max" denotes the greatest version in the 1.2 line. A version range of the form "[M.N.*]" is short - * for "[M.N.min, M.N.max]". - * </p> - * <p> - * Numbers and strings are considered incomparable against each other. Where version segments of different kind would - * collide, comparison will instead assume that the previous segments are padded with trailing 0 or "ga" segments, - * respectively, until the kind mismatch is resolved, e.g. "1-alpha" = "1.0.0-alpha" < "1.0.1-ga" = "1.0.1". - * </p> - */ -public final class GenericVersionScheme - implements VersionScheme -{ - - /** - * Creates a new instance of the version scheme for parsing versions. - */ - public GenericVersionScheme() - { - } - - public Version parseVersion( final String version ) - throws InvalidVersionSpecificationException - { - return new GenericVersion( version ); - } - - public VersionRange parseVersionRange( final String range ) - throws InvalidVersionSpecificationException - { - return new GenericVersionRange( range ); - } - - public VersionConstraint parseVersionConstraint( final String constraint ) - throws InvalidVersionSpecificationException - { - Collection<VersionRange> ranges = new ArrayList<VersionRange>(); - - String process = constraint; - - while ( process.startsWith( "[" ) || process.startsWith( "(" ) ) - { - int index1 = process.indexOf( ')' ); - int index2 = process.indexOf( ']' ); - - int index = index2; - if ( index2 < 0 || ( index1 >= 0 && index1 < index2 ) ) - { - index = index1; - } - - if ( index < 0 ) - { - throw new InvalidVersionSpecificationException( constraint, "Unbounded version range " + constraint ); - } - - VersionRange range = parseVersionRange( process.substring( 0, index + 1 ) ); - ranges.add( range ); - - process = process.substring( index + 1 ).trim(); - - if ( process.length() > 0 && process.startsWith( "," ) ) - { - process = process.substring( 1 ).trim(); - } - } - - if ( process.length() > 0 && !ranges.isEmpty() ) - { - throw new InvalidVersionSpecificationException( constraint, "Invalid version range " + constraint - + ", expected [ or ( but got " + process ); - } - - VersionConstraint result; - if ( ranges.isEmpty() ) - { - result = new GenericVersionConstraint( parseVersion( constraint ) ); - } - else - { - result = new GenericVersionConstraint( UnionVersionRange.from( ranges ) ); - } - - return result; - } - - @Override - public boolean equals( final Object obj ) - { - if ( this == obj ) - { - return true; - } - - return obj != null && getClass().equals( obj.getClass() ); - } - - @Override - public int hashCode() - { - return getClass().hashCode(); - } - -} http://git-wip-us.apache.org/repos/asf/maven-resolver/blob/3a1b8ae0/aether-util/src/main/java/org/eclipse/aether/util/version/UnionVersionRange.java ---------------------------------------------------------------------- diff --git a/aether-util/src/main/java/org/eclipse/aether/util/version/UnionVersionRange.java b/aether-util/src/main/java/org/eclipse/aether/util/version/UnionVersionRange.java deleted file mode 100644 index c54a4b4..0000000 --- a/aether-util/src/main/java/org/eclipse/aether/util/version/UnionVersionRange.java +++ /dev/null @@ -1,181 +0,0 @@ -package org.eclipse.aether.util.version; - -/* - * 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.Arrays; -import java.util.Collection; -import java.util.Collections; -import java.util.HashSet; -import java.util.Set; - -import org.eclipse.aether.version.Version; -import org.eclipse.aether.version.VersionRange; - -/** - * A union of version ranges. - */ -final class UnionVersionRange - implements VersionRange -{ - - private final Set<VersionRange> ranges; - - private final Bound lowerBound; - - private final Bound upperBound; - - public static VersionRange from( VersionRange... ranges ) - { - if ( ranges == null ) - { - return from( Collections.<VersionRange>emptySet() ); - } - return from( Arrays.asList( ranges ) ); - } - - public static VersionRange from( Collection<? extends VersionRange> ranges ) - { - if ( ranges != null && ranges.size() == 1 ) - { - return ranges.iterator().next(); - } - return new UnionVersionRange( ranges ); - } - - private UnionVersionRange( Collection<? extends VersionRange> ranges ) - { - if ( ranges == null || ranges.isEmpty() ) - { - this.ranges = Collections.emptySet(); - lowerBound = upperBound = null; - } - else - { - this.ranges = new HashSet<VersionRange>( ranges ); - Bound lowerBound = null, upperBound = null; - for ( VersionRange range : this.ranges ) - { - Bound lb = range.getLowerBound(); - if ( lb == null ) - { - lowerBound = null; - break; - } - else if ( lowerBound == null ) - { - lowerBound = lb; - } - else - { - int c = lb.getVersion().compareTo( lowerBound.getVersion() ); - if ( c < 0 || ( c == 0 && !lowerBound.isInclusive() ) ) - { - lowerBound = lb; - } - } - } - for ( VersionRange range : this.ranges ) - { - Bound ub = range.getUpperBound(); - if ( ub == null ) - { - upperBound = null; - break; - } - else if ( upperBound == null ) - { - upperBound = ub; - } - else - { - int c = ub.getVersion().compareTo( upperBound.getVersion() ); - if ( c > 0 || ( c == 0 && !upperBound.isInclusive() ) ) - { - upperBound = ub; - } - } - } - this.lowerBound = lowerBound; - this.upperBound = upperBound; - } - } - - public boolean containsVersion( Version version ) - { - for ( VersionRange range : ranges ) - { - if ( range.containsVersion( version ) ) - { - return true; - } - } - return false; - } - - public Bound getLowerBound() - { - return lowerBound; - } - - public Bound getUpperBound() - { - return upperBound; - } - - @Override - public boolean equals( Object obj ) - { - if ( obj == this ) - { - return true; - } - else if ( obj == null || !getClass().equals( obj.getClass() ) ) - { - return false; - } - - UnionVersionRange that = (UnionVersionRange) obj; - - return ranges.equals( that.ranges ); - } - - @Override - public int hashCode() - { - int hash = 97 * ranges.hashCode(); - return hash; - } - - @Override - public String toString() - { - StringBuilder buffer = new StringBuilder( 128 ); - for ( VersionRange range : ranges ) - { - if ( buffer.length() > 0 ) - { - buffer.append( ", " ); - } - buffer.append( range ); - } - return buffer.toString(); - } - -} http://git-wip-us.apache.org/repos/asf/maven-resolver/blob/3a1b8ae0/aether-util/src/main/java/org/eclipse/aether/util/version/package-info.java ---------------------------------------------------------------------- diff --git a/aether-util/src/main/java/org/eclipse/aether/util/version/package-info.java b/aether-util/src/main/java/org/eclipse/aether/util/version/package-info.java deleted file mode 100644 index 18dc724..0000000 --- a/aether-util/src/main/java/org/eclipse/aether/util/version/package-info.java +++ /dev/null @@ -1,24 +0,0 @@ -// CHECKSTYLE_OFF: RegexpHeader -/* - * 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. - */ -/** - * Ready-to-use version schemes for parsing/comparing versions. - */ -package org.eclipse.aether.util.version; - http://git-wip-us.apache.org/repos/asf/maven-resolver/blob/3a1b8ae0/aether-util/src/site/site.xml ---------------------------------------------------------------------- diff --git a/aether-util/src/site/site.xml b/aether-util/src/site/site.xml deleted file mode 100644 index 096b05c..0000000 --- a/aether-util/src/site/site.xml +++ /dev/null @@ -1,37 +0,0 @@ -<?xml version="1.0" encoding="UTF-8"?> - -<!-- -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. ---> - -<project xmlns="http://maven.apache.org/DECORATION/1.0.0" - xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" - xsi:schemaLocation="http://maven.apache.org/DECORATION/1.0.0 http://maven.apache.org/xsd/decoration-1.0.0.xsd" - name="Utilities"> - <body> - <menu name="Overview"> - <item name="Introduction" href="index.html"/> - <item name="JavaDocs" href="apidocs/index.html"/> - <item name="Source Xref" href="xref/index.html"/> - <!--item name="FAQ" href="faq.html"/--> - </menu> - - <menu ref="parent"/> - <menu ref="reports"/> - </body> -</project> \ No newline at end of file http://git-wip-us.apache.org/repos/asf/maven-resolver/blob/3a1b8ae0/aether-util/src/test/java/org/eclipse/aether/util/ChecksumUtilTest.java ---------------------------------------------------------------------- diff --git a/aether-util/src/test/java/org/eclipse/aether/util/ChecksumUtilTest.java b/aether-util/src/test/java/org/eclipse/aether/util/ChecksumUtilTest.java deleted file mode 100644 index 05da6f4..0000000 --- a/aether-util/src/test/java/org/eclipse/aether/util/ChecksumUtilTest.java +++ /dev/null @@ -1,185 +0,0 @@ -package org.eclipse.aether.util; - -/* - * 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 static org.eclipse.aether.internal.test.util.TestFileUtils.*; -import static org.junit.Assert.*; - -import java.io.File; -import java.io.IOException; -import java.util.Arrays; -import java.util.HashMap; -import java.util.Map; -import java.util.Map.Entry; - -import org.eclipse.aether.util.ChecksumUtils; -import org.junit.Before; -import org.junit.BeforeClass; -import org.junit.Test; - -public class ChecksumUtilTest -{ - private File emptyFile; - - private File patternFile; - - private File textFile; - - private static Map<String, String> emptyFileChecksums = new HashMap<String, String>(); - - private static Map<String, String> patternFileChecksums = new HashMap<String, String>(); - - private static Map<String, String> textFileChecksums = new HashMap<String, String>(); - - private Map<File, Map<String, String>> sums = new HashMap<File, Map<String, String>>(); - - @BeforeClass - public static void beforeClass() - throws IOException - { - emptyFileChecksums.put( "MD5", "d41d8cd98f00b204e9800998ecf8427e" ); - emptyFileChecksums.put( "SHA-1", "da39a3ee5e6b4b0d3255bfef95601890afd80709" ); - patternFileChecksums.put( "MD5", "14f01d6c7de7d4cf0a4887baa3528b5a" ); - patternFileChecksums.put( "SHA-1", "feeeda19f626f9b0ef6cbf5948c1ec9531694295" ); - textFileChecksums.put( "MD5", "12582d1a662cefe3385f2113998e43ed" ); - textFileChecksums.put( "SHA-1", "a8ae272db549850eef2ff54376f8cac2770745ee" ); - } - - @Before - public void before() - throws IOException - { - sums.clear(); - - emptyFile = createTempFile( new byte[] {}, 0 ); - sums.put( emptyFile, emptyFileChecksums ); - - patternFile = - createTempFile( new byte[] { 0, 1, 2, 4, 8, 16, 32, 64, 127, -1, -2, -4, -8, -16, -32, -64, -127 }, 1000 ); - sums.put( patternFile, patternFileChecksums ); - - textFile = createTempFile( "the quick brown fox jumps over the lazy dog\n".getBytes( "UTF-8" ), 500 ); - sums.put( textFile, textFileChecksums ); - - } - - @Test - public void testEquality() - throws Throwable - { - Map<String, Object> checksums = null; - - for ( File file : new File[] { emptyFile, patternFile, textFile } ) - { - - checksums = ChecksumUtils.calc( file, Arrays.asList( "SHA-1", "MD5" ) ); - - for ( Entry<String, Object> entry : checksums.entrySet() ) - { - if ( entry.getValue() instanceof Throwable ) - { - throw (Throwable) entry.getValue(); - } - String actual = entry.getValue().toString(); - String expected = sums.get( file ).get( entry.getKey() ); - assertEquals( String.format( "checksums do not match for '%s', algorithm '%s'", file.getName(), - entry.getKey() ), expected, actual ); - } - assertTrue( "Could not delete file", file.delete() ); - } - } - - @Test - public void testFileHandleLeakage() - throws IOException - { - for ( File file : new File[] { emptyFile, patternFile, textFile } ) - { - for ( int i = 0; i < 150; i++ ) - { - ChecksumUtils.calc( file, Arrays.asList( "SHA-1", "MD5" ) ); - } - assertTrue( "Could not delete file", file.delete() ); - } - - } - - @Test - public void testRead() - throws IOException - { - for ( Map<String, String> checksums : sums.values() ) - { - String sha1 = checksums.get( "SHA-1" ); - String md5 = checksums.get( "MD5" ); - - File sha1File = createTempFile( sha1 ); - File md5File = createTempFile( md5 ); - - assertEquals( sha1, ChecksumUtils.read( sha1File ) ); - assertEquals( md5, ChecksumUtils.read( md5File ) ); - - assertTrue( "ChecksumUtils leaks file handles (cannot delete checksums.sha1)", sha1File.delete() ); - assertTrue( "ChecksumUtils leaks file handles (cannot delete checksums.md5)", md5File.delete() ); - } - } - - @Test - public void testReadSpaces() - throws IOException - { - for ( Map<String, String> checksums : sums.values() ) - { - String sha1 = checksums.get( "SHA-1" ); - String md5 = checksums.get( "MD5" ); - - File sha1File = createTempFile( "sha1-checksum = " + sha1 ); - File md5File = createTempFile( md5 + " test" ); - - assertEquals( sha1, ChecksumUtils.read( sha1File ) ); - assertEquals( md5, ChecksumUtils.read( md5File ) ); - - assertTrue( "ChecksumUtils leaks file handles (cannot delete checksums.sha1)", sha1File.delete() ); - assertTrue( "ChecksumUtils leaks file handles (cannot delete checksums.md5)", md5File.delete() ); - } - } - - @Test - public void testReadEmptyFile() - throws IOException - { - File file = createTempFile( "" ); - - assertEquals( "", ChecksumUtils.read( file ) ); - - assertTrue( "ChecksumUtils leaks file handles (cannot delete checksum.empty)", file.delete() ); - } - - @Test - public void testToHexString() - { - assertEquals( null, ChecksumUtils.toHexString( null ) ); - assertEquals( "", ChecksumUtils.toHexString( new byte[] {} ) ); - assertEquals( "00", ChecksumUtils.toHexString( new byte[] { 0 } ) ); - assertEquals( "ff", ChecksumUtils.toHexString( new byte[] { -1 } ) ); - assertEquals( "00017f", ChecksumUtils.toHexString( new byte[] { 0, 1, 127 } ) ); - } - -} http://git-wip-us.apache.org/repos/asf/maven-resolver/blob/3a1b8ae0/aether-util/src/test/java/org/eclipse/aether/util/ConfigUtilsTest.java ---------------------------------------------------------------------- diff --git a/aether-util/src/test/java/org/eclipse/aether/util/ConfigUtilsTest.java b/aether-util/src/test/java/org/eclipse/aether/util/ConfigUtilsTest.java deleted file mode 100644 index 442d501..0000000 --- a/aether-util/src/test/java/org/eclipse/aether/util/ConfigUtilsTest.java +++ /dev/null @@ -1,229 +0,0 @@ -package org.eclipse.aether.util; - -/* - * 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 static org.junit.Assert.*; - -import java.util.ArrayList; -import java.util.Arrays; -import java.util.Collection; -import java.util.Collections; -import java.util.HashMap; -import java.util.List; -import java.util.Map; - -import org.junit.Test; - -public class ConfigUtilsTest -{ - - Map<Object, Object> config = new HashMap<Object, Object>(); - - @Test - public void testGetObject_Default() - { - Object val = new Object(); - assertSame( val, ConfigUtils.getObject( config, val, "no-value" ) ); - } - - @Test - public void testGetObject_AlternativeKeys() - { - Object val = new Object(); - config.put( "some-object", val ); - assertSame( val, ConfigUtils.getObject( config, null, "no-object", "some-object" ) ); - } - - @Test - public void testGetMap_Default() - { - Map<?, ?> val = new HashMap<Object, Object>(); - assertSame( val, ConfigUtils.getMap( config, val, "no-value" ) ); - } - - @Test - public void testGetMap_AlternativeKeys() - { - Map<?, ?> val = new HashMap<Object, Object>(); - config.put( "some-map", val ); - assertSame( val, ConfigUtils.getMap( config, null, "no-object", "some-map" ) ); - } - - @Test - public void testGetList_Default() - { - List<?> val = new ArrayList<Object>(); - assertSame( val, ConfigUtils.getList( config, val, "no-value" ) ); - } - - @Test - public void testGetList_AlternativeKeys() - { - List<?> val = new ArrayList<Object>(); - config.put( "some-list", val ); - assertSame( val, ConfigUtils.getList( config, null, "no-object", "some-list" ) ); - } - - @Test - public void testGetList_CollectionConversion() - { - Collection<?> val = Collections.singleton( "item" ); - config.put( "some-collection", val ); - assertEquals( Arrays.asList( "item" ), ConfigUtils.getList( config, null, "some-collection" ) ); - } - - @Test - public void testGetString_Default() - { - config.put( "no-string", new Object() ); - assertEquals( "default", ConfigUtils.getString( config, "default", "no-value" ) ); - assertEquals( "default", ConfigUtils.getString( config, "default", "no-string" ) ); - } - - @Test - public void testGetString_AlternativeKeys() - { - config.put( "no-string", new Object() ); - config.put( "some-string", "passed" ); - assertEquals( "passed", ConfigUtils.getString( config, "default", "no-string", "some-string" ) ); - } - - @Test - public void testGetBoolean_Default() - { - config.put( "no-boolean", new Object() ); - assertEquals( true, ConfigUtils.getBoolean( config, true, "no-value" ) ); - assertEquals( false, ConfigUtils.getBoolean( config, false, "no-value" ) ); - assertEquals( true, ConfigUtils.getBoolean( config, true, "no-boolean" ) ); - assertEquals( false, ConfigUtils.getBoolean( config, false, "no-boolean" ) ); - } - - @Test - public void testGetBoolean_AlternativeKeys() - { - config.put( "no-boolean", new Object() ); - config.put( "some-boolean", true ); - assertEquals( true, ConfigUtils.getBoolean( config, false, "no-boolean", "some-boolean" ) ); - config.put( "some-boolean", false ); - assertEquals( false, ConfigUtils.getBoolean( config, true, "no-boolean", "some-boolean" ) ); - } - - @Test - public void testGetBoolean_StringConversion() - { - config.put( "some-boolean", "true" ); - assertEquals( true, ConfigUtils.getBoolean( config, false, "some-boolean" ) ); - config.put( "some-boolean", "false" ); - assertEquals( false, ConfigUtils.getBoolean( config, true, "some-boolean" ) ); - } - - @Test - public void testGetInteger_Default() - { - config.put( "no-integer", new Object() ); - assertEquals( -17, ConfigUtils.getInteger( config, -17, "no-value" ) ); - assertEquals( 43, ConfigUtils.getInteger( config, 43, "no-integer" ) ); - } - - @Test - public void testGetInteger_AlternativeKeys() - { - config.put( "no-integer", "text" ); - config.put( "some-integer", 23 ); - assertEquals( 23, ConfigUtils.getInteger( config, 0, "no-integer", "some-integer" ) ); - } - - @Test - public void testGetInteger_StringConversion() - { - config.put( "some-integer", "-123456" ); - assertEquals( -123456, ConfigUtils.getInteger( config, 0, "some-integer" ) ); - } - - @Test - public void testGetInteger_NumberConversion() - { - config.put( "some-number", -123456.789 ); - assertEquals( -123456, ConfigUtils.getInteger( config, 0, "some-number" ) ); - } - - @Test - public void testGetLong_Default() - { - config.put( "no-long", new Object() ); - assertEquals( -17, ConfigUtils.getLong( config, -17L, "no-value" ) ); - assertEquals( 43, ConfigUtils.getLong( config, 43L, "no-long" ) ); - } - - @Test - public void testGetLong_AlternativeKeys() - { - config.put( "no-long", "text" ); - config.put( "some-long", 23 ); - assertEquals( 23, ConfigUtils.getLong( config, 0, "no-long", "some-long" ) ); - } - - @Test - public void testGetLong_StringConversion() - { - config.put( "some-long", "-123456789012" ); - assertEquals( -123456789012L, ConfigUtils.getLong( config, 0, "some-long" ) ); - } - - @Test - public void testGetLong_NumberConversion() - { - config.put( "some-number", -123456789012.789 ); - assertEquals( -123456789012L, ConfigUtils.getLong( config, 0, "some-number" ) ); - } - - @Test - public void testGetFloat_Default() - { - config.put( "no-float", new Object() ); - assertEquals( -17.1f, ConfigUtils.getFloat( config, -17.1f, "no-value" ), 0.01f ); - assertEquals( 43.2f, ConfigUtils.getFloat( config, 43.2f, "no-float" ), 0.01f ); - } - - @Test - public void testGetFloat_AlternativeKeys() - { - config.put( "no-float", "text" ); - config.put( "some-float", 12.3f ); - assertEquals( 12.3f, ConfigUtils.getFloat( config, 0, "no-float", "some-float" ), 0.01f ); - } - - @Test - public void testGetFloat_StringConversion() - { - config.put( "some-float", "-12.3" ); - assertEquals( -12.3f, ConfigUtils.getFloat( config, 0, "some-float" ), 0.01f ); - config.put( "some-float", "NaN" ); - assertEquals( true, Float.isNaN( ConfigUtils.getFloat( config, 0, "some-float" ) ) ); - } - - @Test - public void testGetFloat_NumberConversion() - { - config.put( "some-number", -1234 ); - assertEquals( -1234f, ConfigUtils.getFloat( config, 0, "some-number" ), 0.1f ); - } - -} http://git-wip-us.apache.org/repos/asf/maven-resolver/blob/3a1b8ae0/aether-util/src/test/java/org/eclipse/aether/util/StringUtilsTest.java ---------------------------------------------------------------------- diff --git a/aether-util/src/test/java/org/eclipse/aether/util/StringUtilsTest.java b/aether-util/src/test/java/org/eclipse/aether/util/StringUtilsTest.java deleted file mode 100644 index 4ac2f7e..0000000 --- a/aether-util/src/test/java/org/eclipse/aether/util/StringUtilsTest.java +++ /dev/null @@ -1,41 +0,0 @@ -package org.eclipse.aether.util; - -/* - * 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 static org.junit.Assert.*; - -import org.eclipse.aether.util.StringUtils; -import org.junit.Test; - -/** - */ -public class StringUtilsTest -{ - - @Test - public void testIsEmpty() - { - assertTrue( StringUtils.isEmpty( null ) ); - assertTrue( StringUtils.isEmpty( "" ) ); - assertFalse( StringUtils.isEmpty( " " ) ); - assertFalse( StringUtils.isEmpty( "test" ) ); - } - -} http://git-wip-us.apache.org/repos/asf/maven-resolver/blob/3a1b8ae0/aether-util/src/test/java/org/eclipse/aether/util/artifact/ArtifactIdUtilsTest.java ---------------------------------------------------------------------- diff --git a/aether-util/src/test/java/org/eclipse/aether/util/artifact/ArtifactIdUtilsTest.java b/aether-util/src/test/java/org/eclipse/aether/util/artifact/ArtifactIdUtilsTest.java deleted file mode 100644 index 36193f3..0000000 --- a/aether-util/src/test/java/org/eclipse/aether/util/artifact/ArtifactIdUtilsTest.java +++ /dev/null @@ -1,201 +0,0 @@ -package org.eclipse.aether.util.artifact; - -/* - * 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 static org.junit.Assert.*; - -import org.eclipse.aether.artifact.Artifact; -import org.eclipse.aether.artifact.DefaultArtifact; -import org.junit.Test; - -/** - */ -public class ArtifactIdUtilsTest -{ - - @Test - public void testToIdArtifact() - { - Artifact artifact = null; - assertSame( null, ArtifactIdUtils.toId( artifact ) ); - - artifact = new DefaultArtifact( "gid", "aid", "ext", "1.0-20110205.132618-23" ); - assertEquals( "gid:aid:ext:1.0-20110205.132618-23", ArtifactIdUtils.toId( artifact ) ); - - artifact = new DefaultArtifact( "gid", "aid", "cls", "ext", "1.0-20110205.132618-23" ); - assertEquals( "gid:aid:ext:cls:1.0-20110205.132618-23", ArtifactIdUtils.toId( artifact ) ); - } - - @Test - public void testToIdStrings() - { - assertEquals( ":::", ArtifactIdUtils.toId( null, null, null, null, null ) ); - - assertEquals( "gid:aid:ext:1", ArtifactIdUtils.toId( "gid", "aid", "ext", "", "1" ) ); - - assertEquals( "gid:aid:ext:cls:1", ArtifactIdUtils.toId( "gid", "aid", "ext", "cls", "1" ) ); - } - - @Test - public void testToBaseIdArtifact() - { - Artifact artifact = null; - assertSame( null, ArtifactIdUtils.toBaseId( artifact ) ); - - artifact = new DefaultArtifact( "gid", "aid", "ext", "1.0-20110205.132618-23" ); - assertEquals( "gid:aid:ext:1.0-SNAPSHOT", ArtifactIdUtils.toBaseId( artifact ) ); - - artifact = new DefaultArtifact( "gid", "aid", "cls", "ext", "1.0-20110205.132618-23" ); - assertEquals( "gid:aid:ext:cls:1.0-SNAPSHOT", ArtifactIdUtils.toBaseId( artifact ) ); - } - - @Test - public void testToVersionlessIdArtifact() - { - Artifact artifact = null; - assertSame( null, ArtifactIdUtils.toId( artifact ) ); - - artifact = new DefaultArtifact( "gid", "aid", "ext", "1" ); - assertEquals( "gid:aid:ext", ArtifactIdUtils.toVersionlessId( artifact ) ); - - artifact = new DefaultArtifact( "gid", "aid", "cls", "ext", "1" ); - assertEquals( "gid:aid:ext:cls", ArtifactIdUtils.toVersionlessId( artifact ) ); - } - - @Test - public void testToVersionlessIdStrings() - { - assertEquals( "::", ArtifactIdUtils.toVersionlessId( null, null, null, null ) ); - - assertEquals( "gid:aid:ext", ArtifactIdUtils.toVersionlessId( "gid", "aid", "ext", "" ) ); - - assertEquals( "gid:aid:ext:cls", ArtifactIdUtils.toVersionlessId( "gid", "aid", "ext", "cls" ) ); - } - - @Test - public void testEqualsId() - { - Artifact artifact1 = null; - Artifact artifact2 = null; - assertEquals( false, ArtifactIdUtils.equalsId( artifact1, artifact2 ) ); - assertEquals( false, ArtifactIdUtils.equalsId( artifact2, artifact1 ) ); - - artifact1 = new DefaultArtifact( "gid", "aid", "ext", "1.0-20110205.132618-23" ); - assertEquals( false, ArtifactIdUtils.equalsId( artifact1, artifact2 ) ); - assertEquals( false, ArtifactIdUtils.equalsId( artifact2, artifact1 ) ); - - artifact2 = new DefaultArtifact( "gidX", "aid", "ext", "1.0-20110205.132618-23" ); - assertEquals( false, ArtifactIdUtils.equalsId( artifact1, artifact2 ) ); - assertEquals( false, ArtifactIdUtils.equalsId( artifact2, artifact1 ) ); - - artifact2 = new DefaultArtifact( "gid", "aidX", "ext", "1.0-20110205.132618-23" ); - assertEquals( false, ArtifactIdUtils.equalsId( artifact1, artifact2 ) ); - assertEquals( false, ArtifactIdUtils.equalsId( artifact2, artifact1 ) ); - - artifact2 = new DefaultArtifact( "gid", "aid", "extX", "1.0-20110205.132618-23" ); - assertEquals( false, ArtifactIdUtils.equalsId( artifact1, artifact2 ) ); - assertEquals( false, ArtifactIdUtils.equalsId( artifact2, artifact1 ) ); - - artifact2 = new DefaultArtifact( "gid", "aid", "ext", "1.0-20110205.132618-24" ); - assertEquals( false, ArtifactIdUtils.equalsId( artifact1, artifact2 ) ); - assertEquals( false, ArtifactIdUtils.equalsId( artifact2, artifact1 ) ); - - artifact2 = new DefaultArtifact( "gid", "aid", "ext", "1.0-20110205.132618-23" ); - assertEquals( true, ArtifactIdUtils.equalsId( artifact1, artifact2 ) ); - assertEquals( true, ArtifactIdUtils.equalsId( artifact2, artifact1 ) ); - - assertEquals( true, ArtifactIdUtils.equalsId( artifact1, artifact1 ) ); - } - - @Test - public void testEqualsBaseId() - { - Artifact artifact1 = null; - Artifact artifact2 = null; - assertEquals( false, ArtifactIdUtils.equalsBaseId( artifact1, artifact2 ) ); - assertEquals( false, ArtifactIdUtils.equalsBaseId( artifact2, artifact1 ) ); - - artifact1 = new DefaultArtifact( "gid", "aid", "ext", "1.0-20110205.132618-23" ); - assertEquals( false, ArtifactIdUtils.equalsBaseId( artifact1, artifact2 ) ); - assertEquals( false, ArtifactIdUtils.equalsBaseId( artifact2, artifact1 ) ); - - artifact2 = new DefaultArtifact( "gidX", "aid", "ext", "1.0-20110205.132618-23" ); - assertEquals( false, ArtifactIdUtils.equalsBaseId( artifact1, artifact2 ) ); - assertEquals( false, ArtifactIdUtils.equalsBaseId( artifact2, artifact1 ) ); - - artifact2 = new DefaultArtifact( "gid", "aidX", "ext", "1.0-20110205.132618-23" ); - assertEquals( false, ArtifactIdUtils.equalsBaseId( artifact1, artifact2 ) ); - assertEquals( false, ArtifactIdUtils.equalsBaseId( artifact2, artifact1 ) ); - - artifact2 = new DefaultArtifact( "gid", "aid", "extX", "1.0-20110205.132618-23" ); - assertEquals( false, ArtifactIdUtils.equalsBaseId( artifact1, artifact2 ) ); - assertEquals( false, ArtifactIdUtils.equalsBaseId( artifact2, artifact1 ) ); - - artifact2 = new DefaultArtifact( "gid", "aid", "ext", "X.0-20110205.132618-23" ); - assertEquals( false, ArtifactIdUtils.equalsBaseId( artifact1, artifact2 ) ); - assertEquals( false, ArtifactIdUtils.equalsBaseId( artifact2, artifact1 ) ); - - artifact2 = new DefaultArtifact( "gid", "aid", "ext", "1.0-20110205.132618-24" ); - assertEquals( true, ArtifactIdUtils.equalsBaseId( artifact1, artifact2 ) ); - assertEquals( true, ArtifactIdUtils.equalsBaseId( artifact2, artifact1 ) ); - - artifact2 = new DefaultArtifact( "gid", "aid", "ext", "1.0-20110205.132618-23" ); - assertEquals( true, ArtifactIdUtils.equalsBaseId( artifact1, artifact2 ) ); - assertEquals( true, ArtifactIdUtils.equalsBaseId( artifact2, artifact1 ) ); - - assertEquals( true, ArtifactIdUtils.equalsBaseId( artifact1, artifact1 ) ); - } - - @Test - public void testEqualsVersionlessId() - { - Artifact artifact1 = null; - Artifact artifact2 = null; - assertEquals( false, ArtifactIdUtils.equalsVersionlessId( artifact1, artifact2 ) ); - assertEquals( false, ArtifactIdUtils.equalsVersionlessId( artifact2, artifact1 ) ); - - artifact1 = new DefaultArtifact( "gid", "aid", "ext", "1.0-20110205.132618-23" ); - assertEquals( false, ArtifactIdUtils.equalsVersionlessId( artifact1, artifact2 ) ); - assertEquals( false, ArtifactIdUtils.equalsVersionlessId( artifact2, artifact1 ) ); - - artifact2 = new DefaultArtifact( "gidX", "aid", "ext", "1.0-20110205.132618-23" ); - assertEquals( false, ArtifactIdUtils.equalsVersionlessId( artifact1, artifact2 ) ); - assertEquals( false, ArtifactIdUtils.equalsVersionlessId( artifact2, artifact1 ) ); - - artifact2 = new DefaultArtifact( "gid", "aidX", "ext", "1.0-20110205.132618-23" ); - assertEquals( false, ArtifactIdUtils.equalsVersionlessId( artifact1, artifact2 ) ); - assertEquals( false, ArtifactIdUtils.equalsVersionlessId( artifact2, artifact1 ) ); - - artifact2 = new DefaultArtifact( "gid", "aid", "extX", "1.0-20110205.132618-23" ); - assertEquals( false, ArtifactIdUtils.equalsVersionlessId( artifact1, artifact2 ) ); - assertEquals( false, ArtifactIdUtils.equalsVersionlessId( artifact2, artifact1 ) ); - - artifact2 = new DefaultArtifact( "gid", "aid", "ext", "1.0-20110205.132618-24" ); - assertEquals( true, ArtifactIdUtils.equalsVersionlessId( artifact1, artifact2 ) ); - assertEquals( true, ArtifactIdUtils.equalsVersionlessId( artifact2, artifact1 ) ); - - artifact2 = new DefaultArtifact( "gid", "aid", "ext", "1.0-20110205.132618-23" ); - assertEquals( true, ArtifactIdUtils.equalsVersionlessId( artifact1, artifact2 ) ); - assertEquals( true, ArtifactIdUtils.equalsVersionlessId( artifact2, artifact1 ) ); - - assertEquals( true, ArtifactIdUtils.equalsVersionlessId( artifact1, artifact1 ) ); - } - -} http://git-wip-us.apache.org/repos/asf/maven-resolver/blob/3a1b8ae0/aether-util/src/test/java/org/eclipse/aether/util/artifact/SubArtifactTest.java ---------------------------------------------------------------------- diff --git a/aether-util/src/test/java/org/eclipse/aether/util/artifact/SubArtifactTest.java b/aether-util/src/test/java/org/eclipse/aether/util/artifact/SubArtifactTest.java deleted file mode 100644 index dc0e472..0000000 --- a/aether-util/src/test/java/org/eclipse/aether/util/artifact/SubArtifactTest.java +++ /dev/null @@ -1,158 +0,0 @@ -package org.eclipse.aether.util.artifact; - -/* - * 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 static org.junit.Assert.*; - -import java.io.File; -import java.util.Collections; -import java.util.HashMap; -import java.util.Map; - -import org.eclipse.aether.artifact.Artifact; -import org.eclipse.aether.artifact.DefaultArtifact; -import org.eclipse.aether.util.artifact.SubArtifact; -import org.junit.Test; - -/** - */ -public class SubArtifactTest -{ - - private Artifact newMainArtifact( String coords ) - { - return new DefaultArtifact( coords ); - } - - @Test - public void testMainArtifactFileNotRetained() - { - Artifact a = newMainArtifact( "gid:aid:ver" ).setFile( new File( "" ) ); - assertNotNull( a.getFile() ); - a = new SubArtifact( a, "", "pom" ); - assertNull( a.getFile() ); - } - - @Test - public void testMainArtifactPropertiesNotRetained() - { - Artifact a = newMainArtifact( "gid:aid:ver" ).setProperties( Collections.singletonMap( "key", "value" ) ); - assertEquals( 1, a.getProperties().size() ); - a = new SubArtifact( a, "", "pom" ); - assertEquals( 0, a.getProperties().size() ); - assertSame( null, a.getProperty( "key", null ) ); - } - - @Test( expected = IllegalArgumentException.class ) - public void testMainArtifactMissing() - { - new SubArtifact( null, "", "pom" ); - } - - @Test - public void testEmptyClassifier() - { - Artifact main = newMainArtifact( "gid:aid:ext:cls:ver" ); - Artifact sub = new SubArtifact( main, "", "pom" ); - assertEquals( "", sub.getClassifier() ); - sub = new SubArtifact( main, null, "pom" ); - assertEquals( "", sub.getClassifier() ); - } - - @Test - public void testEmptyExtension() - { - Artifact main = newMainArtifact( "gid:aid:ext:cls:ver" ); - Artifact sub = new SubArtifact( main, "tests", "" ); - assertEquals( "", sub.getExtension() ); - sub = new SubArtifact( main, "tests", null ); - assertEquals( "", sub.getExtension() ); - } - - @Test - public void testSameClassifier() - { - Artifact main = newMainArtifact( "gid:aid:ext:cls:ver" ); - Artifact sub = new SubArtifact( main, "*", "pom" ); - assertEquals( "cls", sub.getClassifier() ); - } - - @Test - public void testSameExtension() - { - Artifact main = newMainArtifact( "gid:aid:ext:cls:ver" ); - Artifact sub = new SubArtifact( main, "tests", "*" ); - assertEquals( "ext", sub.getExtension() ); - } - - @Test - public void testDerivedClassifier() - { - Artifact main = newMainArtifact( "gid:aid:ext:cls:ver" ); - Artifact sub = new SubArtifact( main, "*-tests", "pom" ); - assertEquals( "cls-tests", sub.getClassifier() ); - sub = new SubArtifact( main, "tests-*", "pom" ); - assertEquals( "tests-cls", sub.getClassifier() ); - - main = newMainArtifact( "gid:aid:ext:ver" ); - sub = new SubArtifact( main, "*-tests", "pom" ); - assertEquals( "tests", sub.getClassifier() ); - sub = new SubArtifact( main, "tests-*", "pom" ); - assertEquals( "tests", sub.getClassifier() ); - } - - @Test - public void testDerivedExtension() - { - Artifact main = newMainArtifact( "gid:aid:ext:cls:ver" ); - Artifact sub = new SubArtifact( main, "", "*.asc" ); - assertEquals( "ext.asc", sub.getExtension() ); - sub = new SubArtifact( main, "", "asc.*" ); - assertEquals( "asc.ext", sub.getExtension() ); - } - - @Test - public void testImmutability() - { - Artifact a = new SubArtifact( newMainArtifact( "gid:aid:ver" ), "", "pom" ); - assertNotSame( a, a.setFile( new File( "file" ) ) ); - assertNotSame( a, a.setVersion( "otherVersion" ) ); - assertNotSame( a, a.setProperties( Collections.singletonMap( "key", "value" ) ) ); - } - - @Test - public void testPropertiesCopied() - { - Map<String, String> props = new HashMap<String, String>(); - props.put( "key", "value1" ); - - Artifact a = new SubArtifact( newMainArtifact( "gid:aid:ver" ), "", "pom", props, null ); - assertEquals( "value1", a.getProperty( "key", null ) ); - props.clear(); - assertEquals( "value1", a.getProperty( "key", null ) ); - - props.put( "key", "value2" ); - a = a.setProperties( props ); - assertEquals( "value2", a.getProperty( "key", null ) ); - props.clear(); - assertEquals( "value2", a.getProperty( "key", null ) ); - } - -} http://git-wip-us.apache.org/repos/asf/maven-resolver/blob/3a1b8ae0/aether-util/src/test/java/org/eclipse/aether/util/filter/AbstractDependencyFilterTest.java ---------------------------------------------------------------------- diff --git a/aether-util/src/test/java/org/eclipse/aether/util/filter/AbstractDependencyFilterTest.java b/aether-util/src/test/java/org/eclipse/aether/util/filter/AbstractDependencyFilterTest.java deleted file mode 100644 index 835c1ce..0000000 --- a/aether-util/src/test/java/org/eclipse/aether/util/filter/AbstractDependencyFilterTest.java +++ /dev/null @@ -1,55 +0,0 @@ -package org.eclipse.aether.util.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.List; - -import org.eclipse.aether.graph.DependencyFilter; -import org.eclipse.aether.graph.DependencyNode; - -public abstract class AbstractDependencyFilterTest -{ - - protected DependencyFilter getAcceptFilter() - { - return new DependencyFilter() - { - - public boolean accept( DependencyNode node, List<DependencyNode> parents ) - { - return true; - } - - }; - } - - protected DependencyFilter getDenyFilter() - { - return new DependencyFilter() - { - - public boolean accept( DependencyNode node, List<DependencyNode> parents ) - { - return false; - } - }; - } - -} http://git-wip-us.apache.org/repos/asf/maven-resolver/blob/3a1b8ae0/aether-util/src/test/java/org/eclipse/aether/util/filter/AndDependencyFilterTest.java ---------------------------------------------------------------------- diff --git a/aether-util/src/test/java/org/eclipse/aether/util/filter/AndDependencyFilterTest.java b/aether-util/src/test/java/org/eclipse/aether/util/filter/AndDependencyFilterTest.java deleted file mode 100644 index 45a7f3d..0000000 --- a/aether-util/src/test/java/org/eclipse/aether/util/filter/AndDependencyFilterTest.java +++ /dev/null @@ -1,92 +0,0 @@ -package org.eclipse.aether.util.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 static org.junit.Assert.*; - -import java.util.Collection; -import java.util.LinkedList; -import java.util.List; - -import org.eclipse.aether.graph.DependencyFilter; -import org.eclipse.aether.graph.DependencyNode; -import org.eclipse.aether.internal.test.util.NodeBuilder; -import org.eclipse.aether.util.filter.AndDependencyFilter; -import org.junit.Test; - -public class AndDependencyFilterTest - extends AbstractDependencyFilterTest -{ - @Test - public void acceptTest() - { - NodeBuilder builder = new NodeBuilder(); - builder.artifactId( "test" ); - List<DependencyNode> parents = new LinkedList<DependencyNode>(); - - // Empty AND - assertTrue( new AndDependencyFilter().accept( builder.build(), parents ) ); - - // Basic Boolean Input - assertTrue( new AndDependencyFilter( getAcceptFilter() ).accept( builder.build(), parents ) ); - assertFalse( new AndDependencyFilter( getDenyFilter() ).accept( builder.build(), parents ) ); - - assertFalse( new AndDependencyFilter( getDenyFilter(), getDenyFilter() ).accept( builder.build(), parents ) ); - assertFalse( new AndDependencyFilter( getDenyFilter(), getAcceptFilter() ).accept( builder.build(), parents ) ); - assertFalse( new AndDependencyFilter( getAcceptFilter(), getDenyFilter() ).accept( builder.build(), parents ) ); - assertTrue( new AndDependencyFilter( getAcceptFilter(), getAcceptFilter() ).accept( builder.build(), parents ) ); - - assertFalse( new AndDependencyFilter( getDenyFilter(), getDenyFilter(), getDenyFilter() ).accept( builder.build(), - parents ) ); - assertFalse( new AndDependencyFilter( getAcceptFilter(), getDenyFilter(), getDenyFilter() ).accept( builder.build(), - parents ) ); - assertFalse( new AndDependencyFilter( getAcceptFilter(), getAcceptFilter(), getDenyFilter() ).accept( builder.build(), - parents ) ); - assertTrue( new AndDependencyFilter( getAcceptFilter(), getAcceptFilter(), getAcceptFilter() ).accept( builder.build(), - parents ) ); - - // User another constructor - Collection<DependencyFilter> filters = new LinkedList<DependencyFilter>(); - filters.add( getDenyFilter() ); - filters.add( getAcceptFilter() ); - assertFalse( new AndDependencyFilter( filters ).accept( builder.build(), parents ) ); - - filters = new LinkedList<DependencyFilter>(); - filters.add( getDenyFilter() ); - filters.add( getDenyFilter() ); - assertFalse( new AndDependencyFilter( filters ).accept( builder.build(), parents ) ); - - filters = new LinkedList<DependencyFilter>(); - filters.add( getAcceptFilter() ); - filters.add( getAcceptFilter() ); - assertTrue( new AndDependencyFilter( filters ).accept( builder.build(), parents ) ); - - // newInstance - assertTrue( AndDependencyFilter.newInstance( getAcceptFilter(), getAcceptFilter() ).accept( builder.build(), - parents ) ); - assertFalse( AndDependencyFilter.newInstance( getAcceptFilter(), getDenyFilter() ).accept( builder.build(), - parents ) ); - - assertFalse( AndDependencyFilter.newInstance( getDenyFilter(), null ).accept( builder.build(), parents ) ); - assertTrue( AndDependencyFilter.newInstance( getAcceptFilter(), null ).accept( builder.build(), parents ) ); - assertNull( AndDependencyFilter.newInstance( null, null ) ); - } - -} http://git-wip-us.apache.org/repos/asf/maven-resolver/blob/3a1b8ae0/aether-util/src/test/java/org/eclipse/aether/util/filter/DependencyFilterUtilsTest.java ---------------------------------------------------------------------- diff --git a/aether-util/src/test/java/org/eclipse/aether/util/filter/DependencyFilterUtilsTest.java b/aether-util/src/test/java/org/eclipse/aether/util/filter/DependencyFilterUtilsTest.java deleted file mode 100644 index 28bde57..0000000 --- a/aether-util/src/test/java/org/eclipse/aether/util/filter/DependencyFilterUtilsTest.java +++ /dev/null @@ -1,141 +0,0 @@ -package org.eclipse.aether.util.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 static org.junit.Assert.*; - -import java.util.Collections; -import java.util.List; - -import org.eclipse.aether.graph.DependencyFilter; -import org.eclipse.aether.graph.DependencyNode; -import org.eclipse.aether.internal.test.util.NodeBuilder; -import org.eclipse.aether.util.filter.DependencyFilterUtils; -import org.junit.Test; - -/** - */ -public class DependencyFilterUtilsTest -{ - - private static List<DependencyNode> PARENTS = Collections.emptyList(); - - @Test - public void testClasspathFilterCompile() - { - NodeBuilder builder = new NodeBuilder().artifactId( "aid" ); - DependencyFilter filter = DependencyFilterUtils.classpathFilter( "compile" ); - - assertTrue( filter.accept( builder.scope( "compile" ).build(), PARENTS ) ); - assertTrue( filter.accept( builder.scope( "system" ).build(), PARENTS ) ); - assertTrue( filter.accept( builder.scope( "provided" ).build(), PARENTS ) ); - assertFalse( filter.accept( builder.scope( "runtime" ).build(), PARENTS ) ); - assertFalse( filter.accept( builder.scope( "test" ).build(), PARENTS ) ); - } - - @Test - public void testClasspathFilterRuntime() - { - NodeBuilder builder = new NodeBuilder().artifactId( "aid" ); - DependencyFilter filter = DependencyFilterUtils.classpathFilter( "runtime" ); - - assertTrue( filter.accept( builder.scope( "compile" ).build(), PARENTS ) ); - assertFalse( filter.accept( builder.scope( "system" ).build(), PARENTS ) ); - assertFalse( filter.accept( builder.scope( "provided" ).build(), PARENTS ) ); - assertTrue( filter.accept( builder.scope( "runtime" ).build(), PARENTS ) ); - assertFalse( filter.accept( builder.scope( "test" ).build(), PARENTS ) ); - } - - @Test - public void testClasspathFilterTest() - { - NodeBuilder builder = new NodeBuilder().artifactId( "aid" ); - DependencyFilter filter = DependencyFilterUtils.classpathFilter( "test" ); - - assertTrue( filter.accept( builder.scope( "compile" ).build(), PARENTS ) ); - assertTrue( filter.accept( builder.scope( "system" ).build(), PARENTS ) ); - assertTrue( filter.accept( builder.scope( "provided" ).build(), PARENTS ) ); - assertTrue( filter.accept( builder.scope( "runtime" ).build(), PARENTS ) ); - assertTrue( filter.accept( builder.scope( "test" ).build(), PARENTS ) ); - } - - @Test - public void testClasspathFilterCompileRuntime() - { - NodeBuilder builder = new NodeBuilder().artifactId( "aid" ); - DependencyFilter filter = DependencyFilterUtils.classpathFilter( "compile", "runtime" ); - - assertTrue( filter.accept( builder.scope( "compile" ).build(), PARENTS ) ); - assertTrue( filter.accept( builder.scope( "system" ).build(), PARENTS ) ); - assertTrue( filter.accept( builder.scope( "provided" ).build(), PARENTS ) ); - assertTrue( filter.accept( builder.scope( "runtime" ).build(), PARENTS ) ); - assertFalse( filter.accept( builder.scope( "test" ).build(), PARENTS ) ); - } - - @Test - public void testClasspathFilterCompilePlusRuntime() - { - NodeBuilder builder = new NodeBuilder().artifactId( "aid" ); - DependencyFilter filter = DependencyFilterUtils.classpathFilter( "compile+runtime" ); - - assertTrue( filter.accept( builder.scope( "compile" ).build(), PARENTS ) ); - assertTrue( filter.accept( builder.scope( "system" ).build(), PARENTS ) ); - assertTrue( filter.accept( builder.scope( "provided" ).build(), PARENTS ) ); - assertTrue( filter.accept( builder.scope( "runtime" ).build(), PARENTS ) ); - assertFalse( filter.accept( builder.scope( "test" ).build(), PARENTS ) ); - } - - @Test - public void testClasspathFilterRuntimeCommaSystem() - { - NodeBuilder builder = new NodeBuilder().artifactId( "aid" ); - DependencyFilter filter = DependencyFilterUtils.classpathFilter( "runtime,system" ); - - assertTrue( filter.accept( builder.scope( "compile" ).build(), PARENTS ) ); - assertTrue( filter.accept( builder.scope( "system" ).build(), PARENTS ) ); - assertFalse( filter.accept( builder.scope( "provided" ).build(), PARENTS ) ); - assertTrue( filter.accept( builder.scope( "runtime" ).build(), PARENTS ) ); - assertFalse( filter.accept( builder.scope( "test" ).build(), PARENTS ) ); - } - - @Test - public void testClasspathFilterNull() - { - NodeBuilder builder = new NodeBuilder().artifactId( "aid" ); - DependencyFilter filter = DependencyFilterUtils.classpathFilter( (String[]) null ); - - assertFalse( filter.accept( builder.scope( "compile" ).build(), PARENTS ) ); - assertFalse( filter.accept( builder.scope( "system" ).build(), PARENTS ) ); - assertFalse( filter.accept( builder.scope( "provided" ).build(), PARENTS ) ); - assertFalse( filter.accept( builder.scope( "runtime" ).build(), PARENTS ) ); - assertFalse( filter.accept( builder.scope( "test" ).build(), PARENTS ) ); - } - - @Test - public void testClasspathFilterUnknownScope() - { - NodeBuilder builder = new NodeBuilder().artifactId( "aid" ); - DependencyFilter filter = DependencyFilterUtils.classpathFilter( "compile" ); - - assertTrue( filter.accept( builder.scope( "" ).build(), PARENTS ) ); - assertTrue( filter.accept( builder.scope( "unknown" ).build(), PARENTS ) ); - } - -} http://git-wip-us.apache.org/repos/asf/maven-resolver/blob/3a1b8ae0/aether-util/src/test/java/org/eclipse/aether/util/filter/ExclusionDependencyFilterTest.java ---------------------------------------------------------------------- diff --git a/aether-util/src/test/java/org/eclipse/aether/util/filter/ExclusionDependencyFilterTest.java b/aether-util/src/test/java/org/eclipse/aether/util/filter/ExclusionDependencyFilterTest.java deleted file mode 100644 index a0be592..0000000 --- a/aether-util/src/test/java/org/eclipse/aether/util/filter/ExclusionDependencyFilterTest.java +++ /dev/null @@ -1,60 +0,0 @@ -package org.eclipse.aether.util.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 static org.junit.Assert.*; - -import java.util.Arrays; -import java.util.Collection; -import java.util.LinkedList; -import java.util.List; - -import org.eclipse.aether.graph.DependencyNode; -import org.eclipse.aether.internal.test.util.NodeBuilder; -import org.eclipse.aether.util.filter.ExclusionsDependencyFilter; -import org.junit.Test; - -public class ExclusionDependencyFilterTest -{ - - @Test - public void acceptTest() - { - - NodeBuilder builder = new NodeBuilder(); - builder.groupId( "com.example.test" ).artifactId( "testArtifact" ); - List<DependencyNode> parents = new LinkedList<DependencyNode>(); - String[] excludes; - - excludes = new String[] { "com.example.test:testArtifact" }; - assertFalse( new ExclusionsDependencyFilter( Arrays.asList( excludes ) ).accept( builder.build(), parents ) ); - - excludes = new String[] { "com.example.test:testArtifact", "com.foo:otherArtifact" }; - assertFalse( new ExclusionsDependencyFilter( Arrays.asList( excludes ) ).accept( builder.build(), parents ) ); - - excludes = new String[] { "testArtifact" }; - assertFalse( new ExclusionsDependencyFilter( Arrays.asList( excludes ) ).accept( builder.build(), parents ) ); - - excludes = new String[] { "otherArtifact" }; - assertTrue( new ExclusionsDependencyFilter( Arrays.asList( excludes ) ).accept( builder.build(), parents ) ); - - assertTrue( new ExclusionsDependencyFilter( (Collection<String>) null ).accept( builder.build(), parents ) ); - } -} http://git-wip-us.apache.org/repos/asf/maven-resolver/blob/3a1b8ae0/aether-util/src/test/java/org/eclipse/aether/util/filter/OrDependencyFilterTest.java ---------------------------------------------------------------------- diff --git a/aether-util/src/test/java/org/eclipse/aether/util/filter/OrDependencyFilterTest.java b/aether-util/src/test/java/org/eclipse/aether/util/filter/OrDependencyFilterTest.java deleted file mode 100644 index 03b80ea..0000000 --- a/aether-util/src/test/java/org/eclipse/aether/util/filter/OrDependencyFilterTest.java +++ /dev/null @@ -1,87 +0,0 @@ -package org.eclipse.aether.util.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 static org.junit.Assert.*; - -import java.util.Collection; -import java.util.LinkedList; -import java.util.List; - -import org.eclipse.aether.graph.DependencyFilter; -import org.eclipse.aether.graph.DependencyNode; -import org.eclipse.aether.internal.test.util.NodeBuilder; -import org.eclipse.aether.util.filter.AndDependencyFilter; -import org.eclipse.aether.util.filter.OrDependencyFilter; -import org.junit.Test; - -public class OrDependencyFilterTest - extends AbstractDependencyFilterTest -{ - - @Test - public void acceptTest() - { - NodeBuilder builder = new NodeBuilder(); - builder.artifactId( "test" ); - List<DependencyNode> parents = new LinkedList<DependencyNode>(); - // Empty OR - assertFalse( new OrDependencyFilter().accept( builder.build(), parents ) ); - - // Basic Boolean Input - assertTrue( new OrDependencyFilter( getAcceptFilter() ).accept( builder.build(), parents ) ); - assertFalse( new OrDependencyFilter( getDenyFilter() ).accept( builder.build(), parents ) ); - - assertFalse( new OrDependencyFilter( getDenyFilter(), getDenyFilter() ).accept( builder.build(), parents ) ); - assertTrue( new OrDependencyFilter( getDenyFilter(), getAcceptFilter() ).accept( builder.build(), parents ) ); - assertTrue( new OrDependencyFilter( getAcceptFilter(), getDenyFilter() ).accept( builder.build(), parents ) ); - assertTrue( new OrDependencyFilter( getAcceptFilter(), getAcceptFilter() ).accept( builder.build(), parents ) ); - - assertFalse( new OrDependencyFilter( getDenyFilter(), getDenyFilter(), getDenyFilter() ).accept( builder.build(), - parents ) ); - assertTrue( new OrDependencyFilter( getAcceptFilter(), getDenyFilter(), getDenyFilter() ).accept( builder.build(), - parents ) ); - assertTrue( new OrDependencyFilter( getAcceptFilter(), getAcceptFilter(), getDenyFilter() ).accept( builder.build(), - parents ) ); - assertTrue( new OrDependencyFilter( getAcceptFilter(), getAcceptFilter(), getAcceptFilter() ).accept( builder.build(), - parents ) ); - - // User another constructor - Collection<DependencyFilter> filters = new LinkedList<DependencyFilter>(); - filters.add( getDenyFilter() ); - filters.add( getAcceptFilter() ); - assertTrue( new OrDependencyFilter( filters ).accept( builder.build(), parents ) ); - - filters = new LinkedList<DependencyFilter>(); - filters.add( getDenyFilter() ); - filters.add( getDenyFilter() ); - assertFalse( new OrDependencyFilter( filters ).accept( builder.build(), parents ) ); - - // newInstance - assertTrue( AndDependencyFilter.newInstance( getAcceptFilter(), getAcceptFilter() ).accept( builder.build(), - parents ) ); - assertFalse( AndDependencyFilter.newInstance( getAcceptFilter(), getDenyFilter() ).accept( builder.build(), - parents ) ); - assertTrue( AndDependencyFilter.newInstance( getAcceptFilter(), null ).accept( builder.build(), parents ) ); - assertFalse( AndDependencyFilter.newInstance( getDenyFilter(), null ).accept( builder.build(), parents ) ); - assertNull( AndDependencyFilter.newInstance( null, null ) ); - } - -} http://git-wip-us.apache.org/repos/asf/maven-resolver/blob/3a1b8ae0/aether-util/src/test/java/org/eclipse/aether/util/filter/PatternExclusionsDependencyFilterTest.java ---------------------------------------------------------------------- diff --git a/aether-util/src/test/java/org/eclipse/aether/util/filter/PatternExclusionsDependencyFilterTest.java b/aether-util/src/test/java/org/eclipse/aether/util/filter/PatternExclusionsDependencyFilterTest.java deleted file mode 100644 index b5b307e..0000000 --- a/aether-util/src/test/java/org/eclipse/aether/util/filter/PatternExclusionsDependencyFilterTest.java +++ /dev/null @@ -1,187 +0,0 @@ -package org.eclipse.aether.util.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 static org.junit.Assert.*; - -import java.util.LinkedList; -import java.util.List; - -import org.eclipse.aether.graph.DependencyNode; -import org.eclipse.aether.internal.test.util.NodeBuilder; -import org.eclipse.aether.util.filter.PatternExclusionsDependencyFilter; -import org.eclipse.aether.util.version.GenericVersionScheme; -import org.eclipse.aether.version.VersionScheme; -import org.junit.Test; - -public class PatternExclusionsDependencyFilterTest -{ - - @Test - public void acceptTestCornerCases() - { - NodeBuilder builder = new NodeBuilder(); - builder.artifactId( "testArtifact" ); - DependencyNode node = builder.build(); - List<DependencyNode> parents = new LinkedList<DependencyNode>(); - - // Empty String, Empty List - assertTrue( dontAccept( node, "" ) ); - assertTrue( new PatternExclusionsDependencyFilter( new LinkedList<String>() ).accept( node, parents ) ); - assertTrue( new PatternExclusionsDependencyFilter( (String[]) null ).accept( node, parents ) ); - assertTrue( new PatternExclusionsDependencyFilter( (VersionScheme) null, "[1,10]" ).accept( node, parents ) ); - } - - @Test - public void acceptTestMatches() - { - NodeBuilder builder = new NodeBuilder(); - builder.groupId( "com.example.test" ).artifactId( "testArtifact" ).ext( "jar" ).version( "1.0.3" ); - DependencyNode node = builder.build(); - - // full match - assertEquals( "com.example.test:testArtifact:jar:1.0.3", true, - dontAccept( node, "com.example.test:testArtifact:jar:1.0.3" ) ); - - // single wildcard - assertEquals( "*:testArtifact:jar:1.0.3", true, dontAccept( node, "*:testArtifact:jar:1.0.3" ) ); - assertEquals( "com.example.test:*:jar:1.0.3", true, dontAccept( node, "com.example.test:*:jar:1.0.3" ) ); - assertEquals( "com.example.test:testArtifact:*:1.0.3", true, - dontAccept( node, "com.example.test:testArtifact:*:1.0.3" ) ); - assertEquals( "com.example.test:testArtifact:*:1.0.3", true, - dontAccept( node, "com.example.test:testArtifact:*:1.0.3" ) ); - - // implicit wildcard - assertEquals( ":testArtifact:jar:1.0.3", true, dontAccept( node, ":testArtifact:jar:1.0.3" ) ); - assertEquals( "com.example.test::jar:1.0.3", true, dontAccept( node, "com.example.test::jar:1.0.3" ) ); - assertEquals( "com.example.test:testArtifact::1.0.3", true, - dontAccept( node, "com.example.test:testArtifact::1.0.3" ) ); - assertEquals( "com.example.test:testArtifact:jar:", true, - dontAccept( node, "com.example.test:testArtifact:jar:" ) ); - - // multi wildcards - assertEquals( "*:*:jar:1.0.3", true, dontAccept( node, "*:*:jar:1.0.3" ) ); - assertEquals( "com.example.test:*:*:1.0.3", true, dontAccept( node, "com.example.test:*:*:1.0.3" ) ); - assertEquals( "com.example.test:testArtifact:*:*", true, dontAccept( node, "com.example.test:testArtifact:*:*" ) ); - assertEquals( "*:testArtifact:jar:*", true, dontAccept( node, "*:testArtifact:jar:*" ) ); - assertEquals( "*:*:jar:*", true, dontAccept( node, "*:*:jar:*" ) ); - assertEquals( ":*:jar:", true, dontAccept( node, ":*:jar:" ) ); - - // partial wildcards - assertEquals( "*.example.test:testArtifact:jar:1.0.3", true, - dontAccept( node, "*.example.test:testArtifact:jar:1.0.3" ) ); - assertEquals( "com.example.test:testArtifact:*ar:1.0.*", true, - dontAccept( node, "com.example.test:testArtifact:*ar:1.0.*" ) ); - assertEquals( "com.example.test:testArtifact:jar:1.0.*", true, - dontAccept( node, "com.example.test:testArtifact:jar:1.0.*" ) ); - assertEquals( "*.example.*:testArtifact:jar:1.0.3", true, - dontAccept( node, "*.example.*:testArtifact:jar:1.0.3" ) ); - - // wildcard as empty string - assertEquals( "com.example.test*:testArtifact:jar:1.0.3", true, - dontAccept( node, "com.example.test*:testArtifact:jar:1.0.3" ) ); - } - - @Test - public void acceptTestLessToken() - { - NodeBuilder builder = new NodeBuilder(); - builder.groupId( "com.example.test" ).artifactId( "testArtifact" ).ext( "jar" ).version( "1.0.3" ); - DependencyNode node = builder.build(); - - assertEquals( "com.example.test:testArtifact:jar", true, dontAccept( node, "com.example.test:testArtifact:jar" ) ); - assertEquals( "com.example.test:testArtifact", true, dontAccept( node, "com.example.test:testArtifact" ) ); - assertEquals( "com.example.test", true, dontAccept( node, "com.example.test" ) ); - - assertEquals( "com.example.foo", false, dontAccept( node, "com.example.foo" ) ); - } - - @Test - public void acceptTestMissmatch() - { - NodeBuilder builder = new NodeBuilder(); - builder.groupId( "com.example.test" ).artifactId( "testArtifact" ).ext( "jar" ).version( "1.0.3" ); - DependencyNode node = builder.build(); - - assertEquals( "OTHER.GROUP.ID:testArtifact:jar:1.0.3", false, - dontAccept( node, "OTHER.GROUP.ID:testArtifact:jar:1.0.3" ) ); - assertEquals( "com.example.test:OTHER_ARTIFACT:jar:1.0.3", false, - dontAccept( node, "com.example.test:OTHER_ARTIFACT:jar:1.0.3" ) ); - assertEquals( "com.example.test:OTHER_ARTIFACT:jar:1.0.3", false, - dontAccept( node, "com.example.test:OTHER_ARTIFACT:jar:1.0.3" ) ); - assertEquals( "com.example.test:testArtifact:WAR:1.0.3", false, - dontAccept( node, "com.example.test:testArtifact:WAR:1.0.3" ) ); - assertEquals( "com.example.test:testArtifact:jar:SNAPSHOT", false, - dontAccept( node, "com.example.test:testArtifact:jar:SNAPSHOT" ) ); - - assertEquals( "*:*:war:*", false, dontAccept( node, "*:*:war:*" ) ); - assertEquals( "OTHER.GROUP.ID", false, dontAccept( node, "OTHER.GROUP.ID" ) ); - } - - @Test - public void acceptTestMoreToken() - { - NodeBuilder builder = new NodeBuilder(); - builder.groupId( "com.example.test" ).artifactId( "testArtifact" ).ext( "jar" ).version( "1.0.3" ); - - DependencyNode node = builder.build(); - assertEquals( "com.example.test:testArtifact:jar:1.0.3:foo", false, - dontAccept( node, "com.example.test:testArtifact:jar:1.0.3:foo" ) ); - } - - @Test - public void acceptTestRange() - { - NodeBuilder builder = new NodeBuilder(); - builder.groupId( "com.example.test" ).artifactId( "testArtifact" ).ext( "jar" ).version( "1.0.3" ); - DependencyNode node = builder.build(); - - String prefix = "com.example.test:testArtifact:jar:"; - - assertTrue( prefix + "[1.0.3,1.0.4)", dontAcceptVersionRange( node, prefix + "[1.0.3,1.0.4)" ) ); - assertTrue( prefix + "[1.0.3,)", dontAcceptVersionRange( node, prefix + "[1.0.3,)" ) ); - assertTrue( prefix + "[1.0.3,]", dontAcceptVersionRange( node, prefix + "[1.0.3,]" ) ); - assertTrue( prefix + "(,1.0.3]", dontAcceptVersionRange( node, prefix + "(,1.0.3]" ) ); - assertTrue( prefix + "[1.0,]", dontAcceptVersionRange( node, prefix + "[1.0,]" ) ); - assertTrue( prefix + "[1,4]", dontAcceptVersionRange( node, prefix + "[1,4]" ) ); - assertTrue( prefix + "(1,4)", dontAcceptVersionRange( node, prefix + "(1,4)" ) ); - - assertTrue( prefix + "(1.0.2,1.0.3]", - dontAcceptVersionRange( node, prefix + "(1.0.2,1.0.3]", prefix + "(1.1,)" ) ); - - assertFalse( prefix + "(1.0.3,2.0]", dontAcceptVersionRange( node, prefix + "(1.0.3,2.0]" ) ); - assertFalse( prefix + "(1,1.0.2]", dontAcceptVersionRange( node, prefix + "(1,1.0.2]" ) ); - - assertFalse( prefix + "(1.0.2,1.0.3)", - dontAcceptVersionRange( node, prefix + "(1.0.2,1.0.3)", prefix + "(1.0.3,)" ) ); - } - - private boolean dontAccept( DependencyNode node, String expression ) - { - return !new PatternExclusionsDependencyFilter( expression ).accept( node, new LinkedList<DependencyNode>() ); - } - - private boolean dontAcceptVersionRange( DependencyNode node, String... expression ) - { - return !new PatternExclusionsDependencyFilter( new GenericVersionScheme(), expression ).accept( node, - new LinkedList<DependencyNode>() ); - } - -}