http://git-wip-us.apache.org/repos/asf/maven-resolver/blob/3a1b8ae0/aether-test-util/src/main/java/org/eclipse/aether/internal/test/util/NodeBuilder.java ---------------------------------------------------------------------- diff --git a/aether-test-util/src/main/java/org/eclipse/aether/internal/test/util/NodeBuilder.java b/aether-test-util/src/main/java/org/eclipse/aether/internal/test/util/NodeBuilder.java deleted file mode 100644 index fdd988a..0000000 --- a/aether-test-util/src/main/java/org/eclipse/aether/internal/test/util/NodeBuilder.java +++ /dev/null @@ -1,164 +0,0 @@ -package org.eclipse.aether.internal.test.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 java.io.File; -import java.util.ArrayList; -import java.util.Collections; -import java.util.HashMap; -import java.util.List; -import java.util.Map; - -import org.eclipse.aether.artifact.Artifact; -import org.eclipse.aether.artifact.DefaultArtifact; -import org.eclipse.aether.graph.DefaultDependencyNode; -import org.eclipse.aether.graph.Dependency; -import org.eclipse.aether.graph.DependencyNode; -import org.eclipse.aether.version.InvalidVersionSpecificationException; -import org.eclipse.aether.version.VersionScheme; - -/** - * A builder to create dependency nodes for unit testing. - */ -public class NodeBuilder -{ - - private String groupId = "test"; - - private String artifactId = ""; - - private String version = "0.1"; - - private String range; - - private String ext = "jar"; - - private String classifier = ""; - - private String scope = "compile"; - - private boolean optional = false; - - private String context; - - private List<Artifact> relocations = new ArrayList<Artifact>(); - - private VersionScheme versionScheme = new TestVersionScheme(); - - private Map<String, String> properties = new HashMap<String, String>( 0 ); - - public NodeBuilder artifactId( String artifactId ) - { - this.artifactId = artifactId; - return this; - } - - public NodeBuilder groupId( String groupId ) - { - this.groupId = groupId; - return this; - - } - - public NodeBuilder ext( String ext ) - { - this.ext = ext; - return this; - } - - public NodeBuilder version( String version ) - { - this.version = version; - this.range = null; - return this; - } - - public NodeBuilder range( String range ) - { - this.range = range; - return this; - } - - public NodeBuilder scope( String scope ) - { - this.scope = scope; - return this; - } - - public NodeBuilder optional( boolean optional ) - { - this.optional = optional; - return this; - } - - public NodeBuilder context( String context ) - { - this.context = context; - return this; - } - - public NodeBuilder reloc( String artifactId ) - { - Artifact relocation = new DefaultArtifact( groupId, artifactId, classifier, ext, version ); - relocations.add( relocation ); - return this; - } - - public NodeBuilder reloc( String groupId, String artifactId, String version ) - { - Artifact relocation = new DefaultArtifact( groupId, artifactId, classifier, ext, version ); - relocations.add( relocation ); - return this; - } - - public NodeBuilder properties( Map<String, String> properties ) - { - this.properties = properties != null ? properties : Collections.<String, String>emptyMap(); - return this; - } - - public DependencyNode build() - { - Dependency dependency = null; - if ( artifactId != null && artifactId.length() > 0 ) - { - Artifact artifact = - new DefaultArtifact( groupId, artifactId, classifier, ext, version, properties, (File) null ); - dependency = new Dependency( artifact, scope, optional ); - } - DefaultDependencyNode node = new DefaultDependencyNode( dependency ); - if ( artifactId != null && artifactId.length() > 0 ) - { - try - { - node.setVersion( versionScheme.parseVersion( version ) ); - node.setVersionConstraint( versionScheme.parseVersionConstraint( range != null ? range : version ) ); - } - catch ( InvalidVersionSpecificationException e ) - { - throw new IllegalArgumentException( "bad version: " + e.getMessage(), e ); - } - } - node.setRequestContext( context ); - node.setRelocations( relocations ); - return node; - } - -}
http://git-wip-us.apache.org/repos/asf/maven-resolver/blob/3a1b8ae0/aether-test-util/src/main/java/org/eclipse/aether/internal/test/util/NodeDefinition.java ---------------------------------------------------------------------- diff --git a/aether-test-util/src/main/java/org/eclipse/aether/internal/test/util/NodeDefinition.java b/aether-test-util/src/main/java/org/eclipse/aether/internal/test/util/NodeDefinition.java deleted file mode 100644 index 64910f1..0000000 --- a/aether-test-util/src/main/java/org/eclipse/aether/internal/test/util/NodeDefinition.java +++ /dev/null @@ -1,144 +0,0 @@ -package org.eclipse.aether.internal.test.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 java.util.ArrayList; -import java.util.Collections; -import java.util.LinkedHashMap; -import java.util.List; -import java.util.Map; -import java.util.regex.Matcher; -import java.util.regex.Pattern; - -/** - * A definition of a dependency node via a single line of text. - * - * @see DependencyGraphParser - */ -class NodeDefinition -{ - - static final String ID = "\\(([-_a-zA-Z0-9]+)\\)"; - - static final String IDREF = "\\^([-_a-zA-Z0-9]+)"; - - static final String COORDS = "([^: \\(]+):([^: ]+)(?::([^: ]*)(?::([^: ]+))?)?:([^: \\[\\(<]+)"; - - private static final String COORDS_NC = NodeDefinition.COORDS.replaceAll( "\\((?=\\[)", "(?:" ); - - private static final String RANGE_NC = "[\\(\\[][^\\(\\)\\[\\]]+[\\)\\]]"; - - static final String RANGE = "(" + RANGE_NC + ")"; - - static final String SCOPE = "(?:scope\\s*=\\s*)?((?!optional)[-_a-zA-Z0-9]+)(?:<([-_a-zA-Z0-9]+))?"; - - static final String OPTIONAL = "(!?optional)"; - - static final String RELOCATIONS = "relocations\\s*=\\s*(" + COORDS_NC + "(?:\\s*,\\s*" + COORDS_NC + ")*)"; - - static final String KEY_VAL = "(?:[-_a-zA-Z0-9]+)\\s*:\\s*(?:[-_a-zA-Z0-9]*)"; - - static final String PROPS = "props\\s*=\\s*(" + KEY_VAL + "(?:\\s*,\\s*" + KEY_VAL + ")*)"; - - static final String COORDSX = "(" + COORDS_NC + ")" + RANGE + "?(?:<((?:" + RANGE_NC + ")|\\S+))?"; - - static final String NODE = COORDSX + "(?:\\s+" + PROPS + ")?" + "(?:\\s+" + SCOPE + ")?" + "(?:\\s+" + OPTIONAL - + ")?" + "(?:\\s+" + RELOCATIONS + ")?" + "(?:\\s+" + ID + ")?"; - - static final String LINE = "(?:" + IDREF + ")|(?:" + NODE + ")"; - - private static final Pattern PATTERN = Pattern.compile( LINE ); - - private final String def; - - String coords; - - Map<String, String> properties; - - String range; - - String premanagedVersion; - - String scope; - - String premanagedScope; - - Boolean optional; - - List<String> relocations; - - String id; - - String reference; - - public NodeDefinition( String definition ) - { - def = definition.trim(); - - Matcher m = PATTERN.matcher( def ); - if ( !m.matches() ) - { - throw new IllegalArgumentException( "bad syntax: " + def ); - } - - reference = m.group( 1 ); - if ( reference != null ) - { - return; - } - - coords = m.group( 2 ); - range = m.group( 3 ); - premanagedVersion = m.group( 4 ); - - String props = m.group( 5 ); - if ( props != null ) - { - properties = new LinkedHashMap<String, String>(); - for ( String prop : props.split( "\\s*,\\s*" ) ) - { - int sep = prop.indexOf( ':' ); - String key = prop.substring( 0, sep ); - String val = prop.substring( sep + 1 ); - properties.put( key, val ); - } - } - - scope = m.group( 6 ); - premanagedScope = m.group( 7 ); - optional = ( m.group( 8 ) != null ) ? !m.group( 8 ).startsWith( "!" ) : Boolean.FALSE; - - String relocs = m.group( 9 ); - if ( relocs != null ) - { - relocations = new ArrayList<String>(); - Collections.addAll( relocations, relocs.split( "\\s*,\\s*" ) ); - } - - id = m.group( 10 ); - } - - @Override - public String toString() - { - return def; - } - -} http://git-wip-us.apache.org/repos/asf/maven-resolver/blob/3a1b8ae0/aether-test-util/src/main/java/org/eclipse/aether/internal/test/util/TestDependencyCollectionContext.java ---------------------------------------------------------------------- diff --git a/aether-test-util/src/main/java/org/eclipse/aether/internal/test/util/TestDependencyCollectionContext.java b/aether-test-util/src/main/java/org/eclipse/aether/internal/test/util/TestDependencyCollectionContext.java deleted file mode 100644 index b4f4155..0000000 --- a/aether-test-util/src/main/java/org/eclipse/aether/internal/test/util/TestDependencyCollectionContext.java +++ /dev/null @@ -1,78 +0,0 @@ -package org.eclipse.aether.internal.test.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 java.util.List; - -import org.eclipse.aether.RepositorySystemSession; -import org.eclipse.aether.artifact.Artifact; -import org.eclipse.aether.collection.DependencyCollectionContext; -import org.eclipse.aether.graph.Dependency; - -/** - */ -final class TestDependencyCollectionContext - implements DependencyCollectionContext -{ - - private final RepositorySystemSession session; - - private final Artifact artifact; - - private final Dependency dependency; - - private final List<Dependency> managedDependencies; - - public TestDependencyCollectionContext( RepositorySystemSession session, Artifact artifact, Dependency dependency, - List<Dependency> managedDependencies ) - { - this.session = session; - this.artifact = ( dependency != null ) ? dependency.getArtifact() : artifact; - this.dependency = dependency; - this.managedDependencies = managedDependencies; - } - - public RepositorySystemSession getSession() - { - return session; - } - - public Artifact getArtifact() - { - return artifact; - } - - public Dependency getDependency() - { - return dependency; - } - - public List<Dependency> getManagedDependencies() - { - return managedDependencies; - } - - @Override - public String toString() - { - return String.valueOf( getDependency() ); - } - -} http://git-wip-us.apache.org/repos/asf/maven-resolver/blob/3a1b8ae0/aether-test-util/src/main/java/org/eclipse/aether/internal/test/util/TestDependencyGraphTransformationContext.java ---------------------------------------------------------------------- diff --git a/aether-test-util/src/main/java/org/eclipse/aether/internal/test/util/TestDependencyGraphTransformationContext.java b/aether-test-util/src/main/java/org/eclipse/aether/internal/test/util/TestDependencyGraphTransformationContext.java deleted file mode 100644 index c3da4d9..0000000 --- a/aether-test-util/src/main/java/org/eclipse/aether/internal/test/util/TestDependencyGraphTransformationContext.java +++ /dev/null @@ -1,80 +0,0 @@ -package org.eclipse.aether.internal.test.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 java.util.HashMap; -import java.util.Map; - -import org.eclipse.aether.RepositorySystemSession; -import org.eclipse.aether.collection.DependencyGraphTransformationContext; - -/** - */ -class TestDependencyGraphTransformationContext - implements DependencyGraphTransformationContext -{ - - private final RepositorySystemSession session; - - private final Map<Object, Object> map; - - public TestDependencyGraphTransformationContext( RepositorySystemSession session ) - { - this.session = session; - this.map = new HashMap<Object, Object>(); - } - - public RepositorySystemSession getSession() - { - return session; - } - - public Object get( Object key ) - { - if ( key == null ) - { - throw new IllegalArgumentException( "key must not be null" ); - } - return map.get( key ); - } - - public Object put( Object key, Object value ) - { - if ( key == null ) - { - throw new IllegalArgumentException( "key must not be null" ); - } - if ( value != null ) - { - return map.put( key, value ); - } - else - { - return map.remove( key ); - } - } - - @Override - public String toString() - { - return String.valueOf( map ); - } - -} http://git-wip-us.apache.org/repos/asf/maven-resolver/blob/3a1b8ae0/aether-test-util/src/main/java/org/eclipse/aether/internal/test/util/TestFileProcessor.java ---------------------------------------------------------------------- diff --git a/aether-test-util/src/main/java/org/eclipse/aether/internal/test/util/TestFileProcessor.java b/aether-test-util/src/main/java/org/eclipse/aether/internal/test/util/TestFileProcessor.java deleted file mode 100644 index fe130a3..0000000 --- a/aether-test-util/src/main/java/org/eclipse/aether/internal/test/util/TestFileProcessor.java +++ /dev/null @@ -1,219 +0,0 @@ -package org.eclipse.aether.internal.test.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 java.io.BufferedOutputStream; -import java.io.Closeable; -import java.io.File; -import java.io.FileInputStream; -import java.io.FileOutputStream; -import java.io.IOException; -import java.io.InputStream; -import java.io.OutputStream; -import java.nio.ByteBuffer; - -import org.eclipse.aether.spi.io.FileProcessor; - -/** - * A simple file processor implementation to help satisfy component requirements during tests. - */ -public class TestFileProcessor - implements FileProcessor -{ - - private static void close( Closeable closeable ) - { - if ( closeable != null ) - { - try - { - closeable.close(); - } - catch ( IOException e ) - { - // too bad but who cares - } - } - } - - public boolean mkdirs( File directory ) - { - if ( directory == null ) - { - return false; - } - - if ( directory.exists() ) - { - return false; - } - if ( directory.mkdir() ) - { - return true; - } - - File canonDir = null; - try - { - canonDir = directory.getCanonicalFile(); - } - catch ( IOException e ) - { - return false; - } - - File parentDir = canonDir.getParentFile(); - return ( parentDir != null && ( mkdirs( parentDir ) || parentDir.exists() ) && canonDir.mkdir() ); - } - - public void write( File file, String data ) - throws IOException - { - mkdirs( file.getParentFile() ); - - FileOutputStream fos = null; - try - { - fos = new FileOutputStream( file ); - - if ( data != null ) - { - fos.write( data.getBytes( "UTF-8" ) ); - } - - // allow output to report any flush/close errors - fos.close(); - } - finally - { - close( fos ); - } - } - - public void write( File target, InputStream source ) - throws IOException - { - mkdirs( target.getAbsoluteFile().getParentFile() ); - - OutputStream fos = null; - try - { - fos = new BufferedOutputStream( new FileOutputStream( target ) ); - - copy( fos, source, null ); - - // allow output to report any flush/close errors - fos.close(); - } - finally - { - close( fos ); - } - } - - public void copy( File source, File target ) - throws IOException - { - copy( source, target, null ); - } - - public long copy( File source, File target, ProgressListener listener ) - throws IOException - { - long total = 0; - - InputStream fis = null; - OutputStream fos = null; - try - { - fis = new FileInputStream( source ); - - mkdirs( target.getAbsoluteFile().getParentFile() ); - - fos = new BufferedOutputStream( new FileOutputStream( target ) ); - - total = copy( fos, fis, listener ); - - // allow output to report any flush/close errors - fos.close(); - } - finally - { - close( fis ); - close( fos ); - } - - return total; - } - - private long copy( OutputStream os, InputStream is, ProgressListener listener ) - throws IOException - { - long total = 0; - - ByteBuffer buffer = ByteBuffer.allocate( 1024 * 32 ); - byte[] array = buffer.array(); - - while ( true ) - { - int bytes = is.read( array ); - if ( bytes < 0 ) - { - break; - } - - os.write( array, 0, bytes ); - - total += bytes; - - if ( listener != null && bytes > 0 ) - { - try - { - buffer.rewind(); - buffer.limit( bytes ); - listener.progressed( buffer ); - } - catch ( Exception e ) - { - // too bad - } - } - } - - return total; - } - - public void move( File source, File target ) - throws IOException - { - target.delete(); - - if ( !source.renameTo( target ) ) - { - copy( source, target ); - - target.setLastModified( source.lastModified() ); - - source.delete(); - } - } - -} http://git-wip-us.apache.org/repos/asf/maven-resolver/blob/3a1b8ae0/aether-test-util/src/main/java/org/eclipse/aether/internal/test/util/TestFileUtils.java ---------------------------------------------------------------------- diff --git a/aether-test-util/src/main/java/org/eclipse/aether/internal/test/util/TestFileUtils.java b/aether-test-util/src/main/java/org/eclipse/aether/internal/test/util/TestFileUtils.java deleted file mode 100644 index 9757daa..0000000 --- a/aether-test-util/src/main/java/org/eclipse/aether/internal/test/util/TestFileUtils.java +++ /dev/null @@ -1,321 +0,0 @@ -package org.eclipse.aether.internal.test.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 java.io.BufferedOutputStream; -import java.io.Closeable; -import java.io.File; -import java.io.FileInputStream; -import java.io.FileOutputStream; -import java.io.IOException; -import java.io.OutputStream; -import java.io.RandomAccessFile; -import java.util.ArrayList; -import java.util.Collection; -import java.util.Properties; -import java.util.UUID; - -/** - * Provides utility methods to read and write (temporary) files. - */ -public class TestFileUtils -{ - - private static final File TMP = new File( System.getProperty( "java.io.tmpdir" ), "aether-" - + UUID.randomUUID().toString().substring( 0, 8 ) ); - - static - { - Runtime.getRuntime().addShutdownHook( new Thread() - { - @Override - public void run() - { - try - { - deleteFile( TMP ); - } - catch ( IOException e ) - { - e.printStackTrace(); - } - } - } ); - } - - private TestFileUtils() - { - // hide constructor - } - - public static void deleteTempFiles() - throws IOException - { - deleteFile( TMP ); - } - - public static void deleteFile( File file ) - throws IOException - { - if ( file == null ) - { - return; - } - - Collection<File> undeletables = new ArrayList<File>(); - - delete( file, undeletables ); - - if ( !undeletables.isEmpty() ) - { - throw new IOException( "Failed to delete " + undeletables ); - } - } - - private static void delete( File file, Collection<File> undeletables ) - { - String[] children = file.list(); - if ( children != null ) - { - for ( String child : children ) - { - delete( new File( file, child ), undeletables ); - } - } - - if ( !del( file ) ) - { - undeletables.add( file.getAbsoluteFile() ); - } - } - - private static boolean del( File file ) - { - for ( int i = 0; i < 10; i++ ) - { - if ( file.delete() || !file.exists() ) - { - return true; - } - } - return false; - } - - public static boolean mkdirs( File directory ) - { - if ( directory == null ) - { - return false; - } - - if ( directory.exists() ) - { - return false; - } - if ( directory.mkdir() ) - { - return true; - } - - File canonDir = null; - try - { - canonDir = directory.getCanonicalFile(); - } - catch ( IOException e ) - { - return false; - } - - File parentDir = canonDir.getParentFile(); - return ( parentDir != null && ( mkdirs( parentDir ) || parentDir.exists() ) && canonDir.mkdir() ); - } - - public static File createTempFile( String contents ) - throws IOException - { - return createTempFile( contents.getBytes( "UTF-8" ), 1 ); - } - - public static File createTempFile( byte[] pattern, int repeat ) - throws IOException - { - mkdirs( TMP ); - File tmpFile = File.createTempFile( "tmpfile-", ".data", TMP ); - writeBytes( tmpFile, pattern, repeat ); - return tmpFile; - } - - public static File createTempDir() - throws IOException - { - return createTempDir( "" ); - } - - public static File createTempDir( String suffix ) - throws IOException - { - mkdirs( TMP ); - File tmpFile = File.createTempFile( "tmpdir-", suffix, TMP ); - deleteFile( tmpFile ); - mkdirs( tmpFile ); - return tmpFile; - } - - private static void close( Closeable c ) - throws IOException - { - if ( c != null ) - { - try - { - c.close(); - } - catch ( IOException e ) - { - // ignore - } - } - } - - public static long copyFile( File source, File target ) - throws IOException - { - long total = 0; - - FileInputStream fis = null; - OutputStream fos = null; - try - { - fis = new FileInputStream( source ); - - mkdirs( target.getParentFile() ); - - fos = new BufferedOutputStream( new FileOutputStream( target ) ); - - for ( byte[] buffer = new byte[1024 * 32];; ) - { - int bytes = fis.read( buffer ); - if ( bytes < 0 ) - { - break; - } - - fos.write( buffer, 0, bytes ); - - total += bytes; - } - - fos.close(); - } - finally - { - close( fis ); - close( fos ); - } - - return total; - } - - public static byte[] readBytes( File file ) - throws IOException - { - RandomAccessFile in = null; - try - { - in = new RandomAccessFile( file, "r" ); - byte[] actual = new byte[(int) in.length()]; - in.readFully( actual ); - return actual; - } - finally - { - close( in ); - } - } - - public static void writeBytes( File file, byte[] pattern, int repeat ) - throws IOException - { - file.deleteOnExit(); - file.getParentFile().mkdirs(); - OutputStream out = null; - try - { - out = new BufferedOutputStream( new FileOutputStream( file ) ); - for ( int i = 0; i < repeat; i++ ) - { - out.write( pattern ); - } - out.close(); - } - finally - { - close( out ); - } - } - - public static String readString( File file ) - throws IOException - { - byte[] content = readBytes( file ); - return new String( content, "UTF-8" ); - } - - public static void writeString( File file, String content ) - throws IOException - { - writeBytes( file, content.getBytes( "UTF-8" ), 1 ); - } - - public static void readProps( File file, Properties props ) - throws IOException - { - FileInputStream fis = null; - try - { - fis = new FileInputStream( file ); - props.load( fis ); - } - finally - { - close( fis ); - } - } - - public static void writeProps( File file, Properties props ) - throws IOException - { - file.getParentFile().mkdirs(); - - FileOutputStream fos = null; - try - { - fos = new FileOutputStream( file ); - props.store( fos, "aether-test" ); - fos.close(); - } - finally - { - close( fos ); - } - } - -} http://git-wip-us.apache.org/repos/asf/maven-resolver/blob/3a1b8ae0/aether-test-util/src/main/java/org/eclipse/aether/internal/test/util/TestLocalRepositoryManager.java ---------------------------------------------------------------------- diff --git a/aether-test-util/src/main/java/org/eclipse/aether/internal/test/util/TestLocalRepositoryManager.java b/aether-test-util/src/main/java/org/eclipse/aether/internal/test/util/TestLocalRepositoryManager.java deleted file mode 100644 index f97fb78..0000000 --- a/aether-test-util/src/main/java/org/eclipse/aether/internal/test/util/TestLocalRepositoryManager.java +++ /dev/null @@ -1,159 +0,0 @@ -package org.eclipse.aether.internal.test.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 java.io.File; -import java.io.IOException; -import java.util.HashSet; -import java.util.Set; - -import org.eclipse.aether.RepositorySystemSession; -import org.eclipse.aether.artifact.Artifact; -import org.eclipse.aether.metadata.Metadata; -import org.eclipse.aether.repository.LocalArtifactRegistration; -import org.eclipse.aether.repository.LocalArtifactRequest; -import org.eclipse.aether.repository.LocalArtifactResult; -import org.eclipse.aether.repository.LocalMetadataRegistration; -import org.eclipse.aether.repository.LocalMetadataRequest; -import org.eclipse.aether.repository.LocalMetadataResult; -import org.eclipse.aether.repository.LocalRepository; -import org.eclipse.aether.repository.LocalRepositoryManager; -import org.eclipse.aether.repository.RemoteRepository; - -/** - * A simplistic local repository manager that uses a temporary base directory. - */ -public class TestLocalRepositoryManager - implements LocalRepositoryManager -{ - - private LocalRepository localRepository; - - private Set<Artifact> unavailableArtifacts = new HashSet<Artifact>(); - - private Set<Artifact> artifactRegistrations = new HashSet<Artifact>(); - - private Set<Metadata> metadataRegistrations = new HashSet<Metadata>(); - - public TestLocalRepositoryManager() - { - try - { - localRepository = new LocalRepository( TestFileUtils.createTempDir( "test-local-repo" ) ); - } - catch ( IOException e ) - { - throw new IllegalStateException( e ); - } - } - - public LocalRepository getRepository() - { - return localRepository; - } - - public String getPathForLocalArtifact( Artifact artifact ) - { - String artifactId = artifact.getArtifactId(); - String groupId = artifact.getGroupId(); - String extension = artifact.getExtension(); - String version = artifact.getVersion(); - String classifier = artifact.getClassifier(); - - String path = - String.format( "%s/%s/%s/%s-%s-%s%s.%s", groupId, artifactId, version, groupId, artifactId, version, - classifier, extension ); - return path; - } - - public String getPathForRemoteArtifact( Artifact artifact, RemoteRepository repository, String context ) - { - return getPathForLocalArtifact( artifact ); - } - - public String getPathForLocalMetadata( Metadata metadata ) - { - String artifactId = metadata.getArtifactId(); - String groupId = metadata.getGroupId(); - String version = metadata.getVersion(); - return String.format( "%s/%s/%s/%s-%s-%s.xml", groupId, artifactId, version, groupId, artifactId, version ); - } - - public String getPathForRemoteMetadata( Metadata metadata, RemoteRepository repository, String context ) - { - return getPathForLocalMetadata( metadata ); - } - - public LocalArtifactResult find( RepositorySystemSession session, LocalArtifactRequest request ) - { - Artifact artifact = request.getArtifact(); - - LocalArtifactResult result = new LocalArtifactResult( request ); - File file = new File( localRepository.getBasedir(), getPathForLocalArtifact( artifact ) ); - result.setFile( file.isFile() ? file : null ); - result.setAvailable( file.isFile() && !unavailableArtifacts.contains( artifact ) ); - - return result; - } - - public void add( RepositorySystemSession session, LocalArtifactRegistration request ) - { - artifactRegistrations.add( request.getArtifact() ); - } - - public LocalMetadataResult find( RepositorySystemSession session, LocalMetadataRequest request ) - { - Metadata metadata = request.getMetadata(); - - LocalMetadataResult result = new LocalMetadataResult( request ); - File file = new File( localRepository.getBasedir(), getPathForLocalMetadata( metadata ) ); - result.setFile( file.isFile() ? file : null ); - - return result; - } - - public void add( RepositorySystemSession session, LocalMetadataRegistration request ) - { - metadataRegistrations.add( request.getMetadata() ); - } - - public Set<Artifact> getArtifactRegistration() - { - return artifactRegistrations; - } - - public Set<Metadata> getMetadataRegistration() - { - return metadataRegistrations; - } - - public void setArtifactAvailability( Artifact artifact, boolean available ) - { - if ( available ) - { - unavailableArtifacts.remove( artifact ); - } - else - { - unavailableArtifacts.add( artifact ); - } - } - -} http://git-wip-us.apache.org/repos/asf/maven-resolver/blob/3a1b8ae0/aether-test-util/src/main/java/org/eclipse/aether/internal/test/util/TestLoggerFactory.java ---------------------------------------------------------------------- diff --git a/aether-test-util/src/main/java/org/eclipse/aether/internal/test/util/TestLoggerFactory.java b/aether-test-util/src/main/java/org/eclipse/aether/internal/test/util/TestLoggerFactory.java deleted file mode 100644 index ea92825..0000000 --- a/aether-test-util/src/main/java/org/eclipse/aether/internal/test/util/TestLoggerFactory.java +++ /dev/null @@ -1,108 +0,0 @@ -package org.eclipse.aether.internal.test.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 java.io.PrintStream; - -import org.eclipse.aether.spi.log.Logger; -import org.eclipse.aether.spi.log.LoggerFactory; - -/** - * A logger factory that writes to some {@link PrintStream}. - */ -public final class TestLoggerFactory - implements LoggerFactory -{ - - private final Logger logger; - - /** - * Creates a new logger factory that writes to {@link System#out}. - */ - public TestLoggerFactory() - { - this( null ); - } - - /** - * Creates a new logger factory that writes to the specified print stream. - */ - public TestLoggerFactory( PrintStream out ) - { - logger = new TestLogger( out ); - } - - public Logger getLogger( String name ) - { - return logger; - } - - private static final class TestLogger - implements Logger - { - - private final PrintStream out; - - public TestLogger( PrintStream out ) - { - this.out = ( out != null ) ? out : System.out; - } - - public boolean isWarnEnabled() - { - return true; - } - - public void warn( String msg, Throwable error ) - { - out.println( "[WARN] " + msg ); - if ( error != null ) - { - error.printStackTrace( out ); - } - } - - public void warn( String msg ) - { - warn( msg, null ); - } - - public boolean isDebugEnabled() - { - return true; - } - - public void debug( String msg, Throwable error ) - { - out.println( "[DEBUG] " + msg ); - if ( error != null ) - { - error.printStackTrace( out ); - } - } - - public void debug( String msg ) - { - debug( msg, null ); - } - - } - -} http://git-wip-us.apache.org/repos/asf/maven-resolver/blob/3a1b8ae0/aether-test-util/src/main/java/org/eclipse/aether/internal/test/util/TestUtils.java ---------------------------------------------------------------------- diff --git a/aether-test-util/src/main/java/org/eclipse/aether/internal/test/util/TestUtils.java b/aether-test-util/src/main/java/org/eclipse/aether/internal/test/util/TestUtils.java deleted file mode 100644 index cc0c4cb..0000000 --- a/aether-test-util/src/main/java/org/eclipse/aether/internal/test/util/TestUtils.java +++ /dev/null @@ -1,92 +0,0 @@ -package org.eclipse.aether.internal.test.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 java.util.List; - -import org.eclipse.aether.DefaultRepositorySystemSession; -import org.eclipse.aether.RepositorySystemSession; -import org.eclipse.aether.artifact.Artifact; -import org.eclipse.aether.collection.DependencyCollectionContext; -import org.eclipse.aether.collection.DependencyGraphTransformationContext; -import org.eclipse.aether.collection.VersionFilter; -import org.eclipse.aether.graph.Dependency; -import org.eclipse.aether.resolution.VersionRangeResult; - -/** - * Utility methods to help unit testing. - */ -public class TestUtils -{ - - private TestUtils() - { - // hide constructor - } - - /** - * Creates a new repository session whose local repository manager is initialized with an instance of - * {@link TestLocalRepositoryManager}. - */ - public static DefaultRepositorySystemSession newSession() - { - DefaultRepositorySystemSession session = new DefaultRepositorySystemSession(); - session.setLocalRepositoryManager( new TestLocalRepositoryManager() ); - return session; - } - - /** - * Creates a new dependency collection context. - */ - public static DependencyCollectionContext newCollectionContext( RepositorySystemSession session, - Dependency dependency, - List<Dependency> managedDependencies ) - { - return new TestDependencyCollectionContext( session, null, dependency, managedDependencies ); - } - - /** - * Creates a new dependency collection context. - */ - public static DependencyCollectionContext newCollectionContext( RepositorySystemSession session, Artifact artifact, - Dependency dependency, - List<Dependency> managedDependencies ) - { - return new TestDependencyCollectionContext( session, artifact, dependency, managedDependencies ); - } - - /** - * Creates a new dependency graph transformation context. - */ - public static DependencyGraphTransformationContext newTransformationContext( RepositorySystemSession session ) - { - return new TestDependencyGraphTransformationContext( session ); - } - - /** - * Creates a new version filter context from the specified session and version range result. - */ - public static VersionFilter.VersionFilterContext newVersionFilterContext( RepositorySystemSession session, - VersionRangeResult rangeResult ) - { - return new TestVersionFilterContext( session, rangeResult ); - } - -} http://git-wip-us.apache.org/repos/asf/maven-resolver/blob/3a1b8ae0/aether-test-util/src/main/java/org/eclipse/aether/internal/test/util/TestVersion.java ---------------------------------------------------------------------- diff --git a/aether-test-util/src/main/java/org/eclipse/aether/internal/test/util/TestVersion.java b/aether-test-util/src/main/java/org/eclipse/aether/internal/test/util/TestVersion.java deleted file mode 100644 index 0fc9bab..0000000 --- a/aether-test-util/src/main/java/org/eclipse/aether/internal/test/util/TestVersion.java +++ /dev/null @@ -1,88 +0,0 @@ -package org.eclipse.aether.internal.test.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 org.eclipse.aether.version.Version; - -/** - * Version ordering by {@link String#compareToIgnoreCase(String)}. - */ -final class TestVersion - implements Version -{ - - private String version; - - public TestVersion( String version ) - { - this.version = version == null ? "" : version; - } - - public int compareTo( Version o ) - { - return version.compareTo( o.toString() ); - } - - @Override - public int hashCode() - { - final int prime = 31; - int result = 1; - result = prime * result + ( ( version == null ) ? 0 : version.hashCode() ); - return result; - } - - @Override - public boolean equals( Object obj ) - { - if ( this == obj ) - { - return true; - } - if ( obj == null ) - { - return false; - } - if ( getClass() != obj.getClass() ) - { - return false; - } - TestVersion other = (TestVersion) obj; - if ( version == null ) - { - if ( other.version != null ) - { - return false; - } - } - else if ( !version.equals( other.version ) ) - { - return false; - } - return true; - } - - @Override - public String toString() - { - return version; - } - -} http://git-wip-us.apache.org/repos/asf/maven-resolver/blob/3a1b8ae0/aether-test-util/src/main/java/org/eclipse/aether/internal/test/util/TestVersionConstraint.java ---------------------------------------------------------------------- diff --git a/aether-test-util/src/main/java/org/eclipse/aether/internal/test/util/TestVersionConstraint.java b/aether-test-util/src/main/java/org/eclipse/aether/internal/test/util/TestVersionConstraint.java deleted file mode 100644 index bd84687..0000000 --- a/aether-test-util/src/main/java/org/eclipse/aether/internal/test/util/TestVersionConstraint.java +++ /dev/null @@ -1,131 +0,0 @@ -package org.eclipse.aether.internal.test.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 org.eclipse.aether.version.Version; -import org.eclipse.aether.version.VersionConstraint; -import org.eclipse.aether.version.VersionRange; - -/** - * A constraint on versions for a dependency. - */ -final class TestVersionConstraint - implements VersionConstraint -{ - - private final VersionRange range; - - private final Version version; - - /** - * Creates a version constraint from the specified version range. - * - * @param range The version range, must not be {@code null}. - */ - public TestVersionConstraint( VersionRange range ) - { - if ( range == null ) - { - throw new IllegalArgumentException( "version range missing" ); - } - this.range = range; - this.version = null; - } - - /** - * Creates a version constraint from the specified version. - * - * @param version The version, must not be {@code null}. - */ - public TestVersionConstraint( Version version ) - { - if ( version == null ) - { - throw new IllegalArgumentException( "version missing" ); - } - this.version = version; - this.range = null; - } - - public VersionRange getRange() - { - return range; - } - - public Version getVersion() - { - return version; - } - - public boolean containsVersion( Version version ) - { - if ( range == null ) - { - return version.equals( this.version ); - } - else - { - return range.containsVersion( version ); - } - } - - @Override - public String toString() - { - return String.valueOf( ( range == null ) ? version : range ); - } - - @Override - public boolean equals( Object obj ) - { - if ( this == obj ) - { - return true; - } - if ( obj == null || !getClass().equals( obj.getClass() ) ) - { - return false; - } - - TestVersionConstraint that = (TestVersionConstraint) obj; - - return eq( range, that.range ) && eq( version, that.getVersion() ); - } - - 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( getRange() ); - hash = hash * 31 + hash( getVersion() ); - return hash; - } - - private static int hash( Object obj ) - { - return obj != null ? obj.hashCode() : 0; - } - -} http://git-wip-us.apache.org/repos/asf/maven-resolver/blob/3a1b8ae0/aether-test-util/src/main/java/org/eclipse/aether/internal/test/util/TestVersionFilterContext.java ---------------------------------------------------------------------- diff --git a/aether-test-util/src/main/java/org/eclipse/aether/internal/test/util/TestVersionFilterContext.java b/aether-test-util/src/main/java/org/eclipse/aether/internal/test/util/TestVersionFilterContext.java deleted file mode 100644 index 2647c56..0000000 --- a/aether-test-util/src/main/java/org/eclipse/aether/internal/test/util/TestVersionFilterContext.java +++ /dev/null @@ -1,93 +0,0 @@ -package org.eclipse.aether.internal.test.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 java.util.ArrayList; -import java.util.Collections; -import java.util.Iterator; -import java.util.List; - -import org.eclipse.aether.RepositorySystemSession; -import org.eclipse.aether.collection.VersionFilter; -import org.eclipse.aether.graph.Dependency; -import org.eclipse.aether.repository.ArtifactRepository; -import org.eclipse.aether.repository.RemoteRepository; -import org.eclipse.aether.resolution.VersionRangeResult; -import org.eclipse.aether.version.Version; -import org.eclipse.aether.version.VersionConstraint; - -/** - */ -class TestVersionFilterContext - implements VersionFilter.VersionFilterContext -{ - - private final RepositorySystemSession session; - - private final Dependency dependency; - - private final VersionRangeResult result; - - private final List<Version> versions; - - public TestVersionFilterContext( RepositorySystemSession session, VersionRangeResult result ) - { - this.session = session; - this.result = result; - dependency = new Dependency( result.getRequest().getArtifact(), "" ); - versions = new ArrayList<Version>( result.getVersions() ); - } - - public RepositorySystemSession getSession() - { - return session; - } - - public Dependency getDependency() - { - return dependency; - } - - public int getCount() - { - return versions.size(); - } - - public Iterator<Version> iterator() - { - return versions.iterator(); - } - - public VersionConstraint getVersionConstraint() - { - return result.getVersionConstraint(); - } - - public ArtifactRepository getRepository( Version version ) - { - return result.getRepository( version ); - } - - public List<RemoteRepository> getRepositories() - { - return Collections.unmodifiableList( result.getRequest().getRepositories() ); - } - -} http://git-wip-us.apache.org/repos/asf/maven-resolver/blob/3a1b8ae0/aether-test-util/src/main/java/org/eclipse/aether/internal/test/util/TestVersionRange.java ---------------------------------------------------------------------- diff --git a/aether-test-util/src/main/java/org/eclipse/aether/internal/test/util/TestVersionRange.java b/aether-test-util/src/main/java/org/eclipse/aether/internal/test/util/TestVersionRange.java deleted file mode 100644 index dd5950e..0000000 --- a/aether-test-util/src/main/java/org/eclipse/aether/internal/test/util/TestVersionRange.java +++ /dev/null @@ -1,247 +0,0 @@ -package org.eclipse.aether.internal.test.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 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 TestVersionRange - implements VersionRange -{ - - private final Version lowerBound; - - private final boolean lowerBoundInclusive; - - private final Version upperBound; - - private final boolean upperBoundInclusive; - - /** - * 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 TestVersionRange( String range ) - throws InvalidVersionSpecificationException - { - String process = range; - - 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 []" ); - } - - lowerBound = upperBound = new TestVersion( process.trim() ); - } - 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 ? new TestVersion( parsedLowerBound ) : null; - upperBound = parsedUpperBound.length() > 0 ? new TestVersion( 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" ); - } - } - } - } - - public Bound getLowerBound() - { - return new Bound( lowerBound, lowerBoundInclusive ); - } - - public Bound getUpperBound() - { - return new Bound( upperBound, upperBoundInclusive ); - } - - public boolean acceptsSnapshots() - { - return isSnapshot( lowerBound ) || isSnapshot( upperBound ); - } - - public boolean containsVersion( Version version ) - { - boolean snapshot = isSnapshot( version ); - - if ( lowerBound != null ) - { - int comparison = lowerBound.compareTo( version ); - - if ( snapshot && comparison == 0 ) - { - return true; - } - - if ( comparison == 0 && !lowerBoundInclusive ) - { - return false; - } - if ( comparison > 0 ) - { - return false; - } - } - - if ( upperBound != null ) - { - int comparison = upperBound.compareTo( version ); - - if ( snapshot && comparison == 0 ) - { - return true; - } - - if ( comparison == 0 && !upperBoundInclusive ) - { - return false; - } - if ( comparison < 0 ) - { - return false; - } - } - - if ( lowerBound != null || upperBound != null ) - { - return !snapshot; - } - - return true; - } - - private boolean isSnapshot( Version version ) - { - return version != null && version.toString().endsWith( "SNAPSHOT" ); - } - - @Override - public boolean equals( Object obj ) - { - if ( obj == this ) - { - return true; - } - else if ( obj == null || !getClass().equals( obj.getClass() ) ) - { - return false; - } - - TestVersionRange that = (TestVersionRange) obj; - - return upperBoundInclusive == that.upperBoundInclusive && lowerBoundInclusive == that.lowerBoundInclusive - && 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 + ( upperBoundInclusive ? 1 : 0 ); - hash = hash * 31 + hash( lowerBound ); - hash = hash * 31 + ( lowerBoundInclusive ? 1 : 0 ); - return hash; - } - - private static int hash( Object obj ) - { - return obj != null ? obj.hashCode() : 0; - } - - @Override - public String toString() - { - StringBuilder buffer = new StringBuilder( 64 ); - buffer.append( lowerBoundInclusive ? '[' : '(' ); - if ( lowerBound != null ) - { - buffer.append( lowerBound ); - } - buffer.append( ',' ); - if ( upperBound != null ) - { - buffer.append( upperBound ); - } - buffer.append( upperBoundInclusive ? ']' : ')' ); - return buffer.toString(); - } - -} http://git-wip-us.apache.org/repos/asf/maven-resolver/blob/3a1b8ae0/aether-test-util/src/main/java/org/eclipse/aether/internal/test/util/TestVersionScheme.java ---------------------------------------------------------------------- diff --git a/aether-test-util/src/main/java/org/eclipse/aether/internal/test/util/TestVersionScheme.java b/aether-test-util/src/main/java/org/eclipse/aether/internal/test/util/TestVersionScheme.java deleted file mode 100644 index 5865f6c..0000000 --- a/aether-test-util/src/main/java/org/eclipse/aether/internal/test/util/TestVersionScheme.java +++ /dev/null @@ -1,120 +0,0 @@ -package org.eclipse.aether.internal.test.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 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. - */ -final class TestVersionScheme - implements VersionScheme -{ - - public Version parseVersion( final String version ) - throws InvalidVersionSpecificationException - { - return new TestVersion( version ); - } - - public VersionRange parseVersionRange( final String range ) - throws InvalidVersionSpecificationException - { - return new TestVersionRange( 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 TestVersionConstraint( parseVersion( constraint ) ); - } - else - { - result = new TestVersionConstraint( ranges.iterator().next() ); - } - - 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-test-util/src/main/java/org/eclipse/aether/internal/test/util/package-info.java ---------------------------------------------------------------------- diff --git a/aether-test-util/src/main/java/org/eclipse/aether/internal/test/util/package-info.java b/aether-test-util/src/main/java/org/eclipse/aether/internal/test/util/package-info.java deleted file mode 100644 index 4d874da..0000000 --- a/aether-test-util/src/main/java/org/eclipse/aether/internal/test/util/package-info.java +++ /dev/null @@ -1,26 +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. - */ -/** - * Utility classes to ease unit testing. This package supports the needs of Aether's own codebase but implementors of - * extensions might find some of these classes useful, too, as long as they understand that these classes do not denote - * a stable API and are subject to change without prior notice. - */ -package org.eclipse.aether.internal.test.util; - http://git-wip-us.apache.org/repos/asf/maven-resolver/blob/3a1b8ae0/aether-test-util/src/site/site.xml ---------------------------------------------------------------------- diff --git a/aether-test-util/src/site/site.xml b/aether-test-util/src/site/site.xml deleted file mode 100644 index 32ad754..0000000 --- a/aether-test-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="Test 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-test-util/src/test/java/org/eclipse/aether/internal/test/util/DependencyGraphParserTest.java ---------------------------------------------------------------------- diff --git a/aether-test-util/src/test/java/org/eclipse/aether/internal/test/util/DependencyGraphParserTest.java b/aether-test-util/src/test/java/org/eclipse/aether/internal/test/util/DependencyGraphParserTest.java deleted file mode 100644 index 86e8a77..0000000 --- a/aether-test-util/src/test/java/org/eclipse/aether/internal/test/util/DependencyGraphParserTest.java +++ /dev/null @@ -1,300 +0,0 @@ -package org.eclipse.aether.internal.test.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.io.IOException; -import java.io.UnsupportedEncodingException; -import java.util.Arrays; -import java.util.List; -import java.util.Map; - -import org.eclipse.aether.artifact.Artifact; -import org.eclipse.aether.graph.Dependency; -import org.eclipse.aether.graph.DependencyNode; -import org.eclipse.aether.internal.test.util.DependencyGraphParser; -import org.junit.Before; -import org.junit.Test; - -/** - */ -public class DependencyGraphParserTest -{ - - private DependencyGraphParser parser; - - @Before - public void setup() - { - this.parser = new DependencyGraphParser(); - } - - @Test - public void testOnlyRoot() - throws IOException - { - String def = "gid:aid:jar:1 scope"; - - DependencyNode node = parser.parseLiteral( def ); - - assertNotNull( node ); - assertEquals( 0, node.getChildren().size() ); - - Dependency dependency = node.getDependency(); - assertNotNull( dependency ); - assertEquals( "scope", dependency.getScope() ); - - Artifact artifact = dependency.getArtifact(); - assertNotNull( artifact ); - - assertEquals( "gid", artifact.getGroupId() ); - assertEquals( "aid", artifact.getArtifactId() ); - assertEquals( "jar", artifact.getExtension() ); - assertEquals( "1", artifact.getVersion() ); - } - - @Test - public void testOptionalScope() - throws IOException - { - String def = "gid:aid:jar:1"; - - DependencyNode node = parser.parseLiteral( def ); - - assertNotNull( node ); - assertEquals( 0, node.getChildren().size() ); - - Dependency dependency = node.getDependency(); - assertNotNull( dependency ); - assertEquals( "", dependency.getScope() ); - } - - @Test - public void testWithChildren() - throws IOException - { - String def = - "gid1:aid1:ext1:ver1 scope1\n" + "+- gid2:aid2:ext2:ver2 scope2\n" + "\\- gid3:aid3:ext3:ver3 scope3\n"; - - DependencyNode node = parser.parseLiteral( def ); - assertNotNull( node ); - - int idx = 1; - - assertNodeProperties( node, idx++ ); - - List<DependencyNode> children = node.getChildren(); - assertEquals( 2, children.size() ); - - for ( DependencyNode child : children ) - { - assertNodeProperties( child, idx++ ); - } - - } - - @Test - public void testDeepChildren() - throws IOException - { - String def = - "gid1:aid1:ext1:ver1\n" + "+- gid2:aid2:ext2:ver2 scope2\n" + "| \\- gid3:aid3:ext3:ver3\n" - + "\\- gid4:aid4:ext4:ver4 scope4"; - - DependencyNode node = parser.parseLiteral( def ); - assertNodeProperties( node, 1 ); - - assertEquals( 2, node.getChildren().size() ); - assertNodeProperties( node.getChildren().get( 1 ), 4 ); - DependencyNode lvl1Node = node.getChildren().get( 0 ); - assertNodeProperties( lvl1Node, 2 ); - - assertEquals( 1, lvl1Node.getChildren().size() ); - assertNodeProperties( lvl1Node.getChildren().get( 0 ), 3 ); - } - - private void assertNodeProperties( DependencyNode node, int idx ) - { - assertNodeProperties( node, String.valueOf( idx ) ); - } - - private void assertNodeProperties( DependencyNode node, String suffix ) - { - assertNotNull( node ); - Dependency dependency = node.getDependency(); - assertNotNull( dependency ); - if ( !"".equals( dependency.getScope() ) ) - { - assertEquals( "scope" + suffix, dependency.getScope() ); - } - - Artifact artifact = dependency.getArtifact(); - assertNotNull( artifact ); - - assertEquals( "gid" + suffix, artifact.getGroupId() ); - assertEquals( "aid" + suffix, artifact.getArtifactId() ); - assertEquals( "ext" + suffix, artifact.getExtension() ); - assertEquals( "ver" + suffix, artifact.getVersion() ); - } - - @Test - public void testComments() - throws IOException - { - String def = "# first line\n#second line\ngid:aid:ext:ver # root artifact asdf:qwer:zcxv:uip"; - - DependencyNode node = parser.parseLiteral( def ); - - assertNodeProperties( node, "" ); - } - - @Test - public void testId() - throws IOException - { - String def = "gid:aid:ext:ver (id)\n\\- ^id"; - DependencyNode node = parser.parseLiteral( def ); - assertNodeProperties( node, "" ); - - assertNotNull( node.getChildren() ); - assertEquals( 1, node.getChildren().size() ); - - assertSame( node, node.getChildren().get( 0 ) ); - } - - @Test - public void testResourceLoading() - throws UnsupportedEncodingException, IOException - { - String prefix = "org/eclipse/aether/internal/test/util/"; - String name = "testResourceLoading.txt"; - - DependencyNode node = parser.parseResource( prefix + name ); - assertEquals( 0, node.getChildren().size() ); - assertNodeProperties( node, "" ); - } - - @Test - public void testResourceLoadingWithPrefix() - throws UnsupportedEncodingException, IOException - { - String prefix = "org/eclipse/aether/internal/test/util/"; - parser = new DependencyGraphParser( prefix ); - - String name = "testResourceLoading.txt"; - - DependencyNode node = parser.parseResource( name ); - assertEquals( 0, node.getChildren().size() ); - assertNodeProperties( node, "" ); - } - - @Test - public void testProperties() - throws IOException - { - String def = "gid:aid:ext:ver props=test:foo,test2:fizzle"; - DependencyNode node = parser.parseLiteral( def ); - - assertNodeProperties( node, "" ); - - Map<String, String> properties = node.getDependency().getArtifact().getProperties(); - assertNotNull( properties ); - assertEquals( 2, properties.size() ); - - assertTrue( properties.containsKey( "test" ) ); - assertEquals( "foo", properties.get( "test" ) ); - assertTrue( properties.containsKey( "test2" ) ); - assertEquals( "fizzle", properties.get( "test2" ) ); - } - - @Test - public void testSubstitutions() - throws IOException - { - parser.setSubstitutions( Arrays.asList( "subst1", "subst2" ) ); - String def = "%s:%s:ext:ver"; - DependencyNode root = parser.parseLiteral( def ); - Artifact artifact = root.getDependency().getArtifact(); - assertEquals( "subst2", artifact.getArtifactId() ); - assertEquals( "subst1", artifact.getGroupId() ); - - def = "%s:aid:ext:ver\n\\- %s:aid:ext:ver"; - root = parser.parseLiteral( def ); - - assertEquals( "subst1", root.getDependency().getArtifact().getGroupId() ); - assertEquals( "subst2", root.getChildren().get( 0 ).getDependency().getArtifact().getGroupId() ); - } - - @Test - public void testMultiple() - throws IOException - { - String prefix = "org/eclipse/aether/internal/test/util/"; - String name = "testResourceLoading.txt"; - - List<DependencyNode> nodes = parser.parseMultiResource( prefix + name ); - - assertEquals( 2, nodes.size() ); - assertEquals( "aid", nodes.get( 0 ).getDependency().getArtifact().getArtifactId() ); - assertEquals( "aid2", nodes.get( 1 ).getDependency().getArtifact().getArtifactId() ); - } - - @Test - public void testRootNullDependency() - throws IOException - { - String literal = "(null)\n+- gid:aid:ext:ver"; - DependencyNode root = parser.parseLiteral( literal ); - - assertNull( root.getDependency() ); - assertEquals( 1, root.getChildren().size() ); - } - - @Test - public void testChildNullDependency() - throws IOException - { - String literal = "gid:aid:ext:ver\n+- (null)"; - DependencyNode root = parser.parseLiteral( literal ); - - assertNotNull( root.getDependency() ); - assertEquals( 1, root.getChildren().size() ); - assertNull( root.getChildren().get( 0 ).getDependency() ); - } - - @Test - public void testOptional() - throws IOException - { - String def = "gid:aid:jar:1 compile optional"; - - DependencyNode node = parser.parseLiteral( def ); - - assertNotNull( node ); - assertEquals( 0, node.getChildren().size() ); - - Dependency dependency = node.getDependency(); - assertNotNull( dependency ); - assertEquals( "compile", dependency.getScope() ); - assertEquals( true, dependency.isOptional() ); - } - -}