You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@maven.apache.org by hb...@apache.org on 2016/09/03 20:23:45 UTC
[22/51] [partial] maven-aether git commit: [MNG-6007] rename Aether
to Maven Artifact Resolver
http://git-wip-us.apache.org/repos/asf/maven-aether/blob/27f8bd73/aether-test-util/src/main/java/org/eclipse/aether/internal/test/util/DependencyGraphParser.java
----------------------------------------------------------------------
diff --git a/aether-test-util/src/main/java/org/eclipse/aether/internal/test/util/DependencyGraphParser.java b/aether-test-util/src/main/java/org/eclipse/aether/internal/test/util/DependencyGraphParser.java
deleted file mode 100644
index e4deefb..0000000
--- a/aether-test-util/src/main/java/org/eclipse/aether/internal/test/util/DependencyGraphParser.java
+++ /dev/null
@@ -1,565 +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.BufferedReader;
-import java.io.IOException;
-import java.io.InputStream;
-import java.io.InputStreamReader;
-import java.io.StringReader;
-import java.net.URL;
-import java.util.ArrayList;
-import java.util.Arrays;
-import java.util.Collection;
-import java.util.Collections;
-import java.util.HashMap;
-import java.util.Iterator;
-import java.util.LinkedList;
-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;
-
-/**
- * Creates a dependency graph from a text description. <h2>Definition</h2> Each (non-empty) line in the input defines
- * one node of the resulting graph:
- *
- * <pre>
- * line ::= (indent? ("(null)" | node | reference))? comment?
- * comment ::= "#" rest-of-line
- * indent ::= "| "* ("+" | "\\") "- "
- * reference ::= "^" id
- * node ::= coords (range)? space (scope("<" premanagedScope)?)? space "optional"? space ("relocations=" coords ("," coords)*)? ("(" id ")")?
- * coords ::= groupId ":" artifactId (":" extension (":" classifier)?)? ":" version
- * </pre>
- *
- * The special token {@code (null)} may be used to indicate an "empty" root node with no dependency.
- * <p>
- * If {@code indent} is empty, the line defines the root node. Only one root node may be defined. The level is
- * calculated by the distance from the beginning of the line. One level is three characters of indentation.
- * <p>
- * The {@code ^id} syntax allows to reuse a previously built node to share common sub graphs among different parent
- * nodes.
- * <h2>Example</h2>
- *
- * <pre>
- * gid:aid:ver
- * +- gid:aid2:ver scope
- * | \- gid:aid3:ver (id1) # assign id for reference below
- * +- gid:aid4:ext:ver scope
- * \- ^id1 # reuse previous node
- * </pre>
- *
- * <h2>Multiple definitions in one resource</h2>
- * <p>
- * By using {@link #parseMultiResource(String)}, definitions divided by a line beginning with "---" can be read from the
- * same resource. The rest of the line is ignored.
- * <h2>Substitutions</h2>
- * <p>
- * You may define substitutions (see {@link #setSubstitutions(String...)},
- * {@link #DependencyGraphParser(String, Collection)}). Every '%s' in the definition will be substituted by the next
- * String in the defined substitutions.
- * <h3>Example</h3>
- *
- * <pre>
- * parser.setSubstitutions( "foo", "bar" );
- * String def = "gid:%s:ext:ver\n" + "+- gid:%s:ext:ver";
- * </pre>
- *
- * The first node will have "foo" as its artifact id, the second node (child to the first) will have "bar" as its
- * artifact id.
- */
-public class DependencyGraphParser
-{
-
- private final VersionScheme versionScheme;
-
- private final String prefix;
-
- private Collection<String> substitutions;
-
- /**
- * Create a parser with the given prefix and the given substitution strings.
- *
- * @see DependencyGraphParser#parseResource(String)
- */
- public DependencyGraphParser( String prefix, Collection<String> substitutions )
- {
- this.prefix = prefix;
- this.substitutions = substitutions;
- versionScheme = new TestVersionScheme();
- }
-
- /**
- * Create a parser with the given prefix.
- *
- * @see DependencyGraphParser#parseResource(String)
- */
- public DependencyGraphParser( String prefix )
- {
- this( prefix, Collections.<String>emptyList() );
- }
-
- /**
- * Create a parser with an empty prefix.
- */
- public DependencyGraphParser()
- {
- this( "" );
- }
-
- /**
- * Parse the given graph definition.
- */
- public DependencyNode parseLiteral( String dependencyGraph )
- throws IOException
- {
- BufferedReader reader = new BufferedReader( new StringReader( dependencyGraph ) );
- DependencyNode node = parse( reader );
- reader.close();
- return node;
- }
-
- /**
- * Parse the graph definition read from the given classpath resource. If a prefix is set, this method will load the
- * resource from 'prefix + resource'.
- */
- public DependencyNode parseResource( String resource )
- throws IOException
- {
- URL res = this.getClass().getClassLoader().getResource( prefix + resource );
- if ( res == null )
- {
- throw new IOException( "Could not find classpath resource " + prefix + resource );
- }
- return parse( res );
- }
-
- /**
- * Parse multiple graphs in one resource, divided by "---".
- */
- public List<DependencyNode> parseMultiResource( String resource )
- throws IOException
- {
- URL res = this.getClass().getClassLoader().getResource( prefix + resource );
- if ( res == null )
- {
- throw new IOException( "Could not find classpath resource " + prefix + resource );
- }
-
- BufferedReader reader = new BufferedReader( new InputStreamReader( res.openStream(), "UTF-8" ) );
-
- List<DependencyNode> ret = new ArrayList<DependencyNode>();
- DependencyNode root = null;
- while ( ( root = parse( reader ) ) != null )
- {
- ret.add( root );
- }
- return ret;
- }
-
- /**
- * Parse the graph definition read from the given URL.
- */
- public DependencyNode parse( URL resource )
- throws IOException
- {
- InputStream stream = null;
- try
- {
- stream = resource.openStream();
- final DependencyNode node = parse( new BufferedReader( new InputStreamReader( stream, "UTF-8" ) ) );
- stream.close();
- stream = null;
- return node;
- }
- finally
- {
- try
- {
- if ( stream != null )
- {
- stream.close();
- }
- }
- catch ( final IOException e )
- {
- // Suppressed
- }
- }
- }
-
- private DependencyNode parse( BufferedReader in )
- throws IOException
- {
- Iterator<String> substitutionIterator = ( substitutions != null ) ? substitutions.iterator() : null;
-
- String line = null;
-
- DependencyNode root = null;
- DependencyNode node = null;
- int prevLevel = 0;
-
- Map<String, DependencyNode> nodes = new HashMap<String, DependencyNode>();
- LinkedList<DependencyNode> stack = new LinkedList<DependencyNode>();
- boolean isRootNode = true;
-
- while ( ( line = in.readLine() ) != null )
- {
- line = cutComment( line );
-
- if ( isEmpty( line ) )
- {
- // skip empty line
- continue;
- }
-
- if ( isEOFMarker( line ) )
- {
- // stop parsing
- break;
- }
-
- while ( line.contains( "%s" ) )
- {
- if ( !substitutionIterator.hasNext() )
- {
- throw new IllegalArgumentException( "not enough substitutions to fill placeholders" );
- }
- line = line.replaceFirst( "%s", substitutionIterator.next() );
- }
-
- LineContext ctx = createContext( line );
- if ( prevLevel < ctx.getLevel() )
- {
- // previous node is new parent
- stack.add( node );
- }
-
- // get to real parent
- while ( prevLevel > ctx.getLevel() )
- {
- stack.removeLast();
- prevLevel -= 1;
- }
-
- prevLevel = ctx.getLevel();
-
- if ( ctx.getDefinition() != null && ctx.getDefinition().reference != null )
- {
- String reference = ctx.getDefinition().reference;
- DependencyNode child = nodes.get( reference );
- if ( child == null )
- {
- throw new IllegalArgumentException( "undefined reference " + reference );
- }
- node.getChildren().add( child );
- }
- else
- {
-
- node = build( isRootNode ? null : stack.getLast(), ctx, isRootNode );
-
- if ( isRootNode )
- {
- root = node;
- isRootNode = false;
- }
-
- if ( ctx.getDefinition() != null && ctx.getDefinition().id != null )
- {
- nodes.put( ctx.getDefinition().id, node );
- }
- }
- }
-
- return root;
- }
-
- private boolean isEOFMarker( String line )
- {
- return line.startsWith( "---" );
- }
-
- private static boolean isEmpty( String line )
- {
- return line == null || line.length() == 0;
- }
-
- private static String cutComment( String line )
- {
- int idx = line.indexOf( '#' );
-
- if ( idx != -1 )
- {
- line = line.substring( 0, idx );
- }
-
- return line;
- }
-
- private DependencyNode build( DependencyNode parent, LineContext ctx, boolean isRoot )
- {
- NodeDefinition def = ctx.getDefinition();
- if ( !isRoot && parent == null )
- {
- throw new IllegalArgumentException( "dangling node: " + def );
- }
- else if ( ctx.getLevel() == 0 && parent != null )
- {
- throw new IllegalArgumentException( "inconsistent leveling (parent for level 0?): " + def );
- }
-
- DefaultDependencyNode node;
- if ( def != null )
- {
- DefaultArtifact artifact = new DefaultArtifact( def.coords, def.properties );
- Dependency dependency = new Dependency( artifact, def.scope, def.optional );
- node = new DefaultDependencyNode( parent, dependency );
- int managedBits = 0;
- if ( def.premanagedScope != null )
- {
- managedBits |= DependencyNode.MANAGED_SCOPE;
- node.setData( "premanaged.scope", def.premanagedScope );
- }
- if ( def.premanagedVersion != null )
- {
- managedBits |= DependencyNode.MANAGED_VERSION;
- node.setData( "premanaged.version", def.premanagedVersion );
- }
- node.setManagedBits( managedBits );
- if ( def.relocations != null )
- {
- List<Artifact> relocations = new ArrayList<Artifact>();
- for ( String relocation : def.relocations )
- {
- relocations.add( new DefaultArtifact( relocation ) );
- }
- node.setRelocations( relocations );
- }
- try
- {
- node.setVersion( versionScheme.parseVersion( artifact.getVersion() ) );
- node.setVersionConstraint( versionScheme.parseVersionConstraint( def.range != null ? def.range
- : artifact.getVersion() ) );
- }
- catch ( InvalidVersionSpecificationException e )
- {
- throw new IllegalArgumentException( "bad version: " + e.getMessage(), e );
- }
- }
- else
- {
- node = new DefaultDependencyNode( (Dependency) null );
- }
-
- if ( parent != null )
- {
- parent.getChildren().add( node );
- }
-
- return node;
- }
-
- public String dump( DependencyNode root )
- {
- StringBuilder ret = new StringBuilder();
-
- List<NodeEntry> entries = new ArrayList<NodeEntry>();
-
- addNode( root, 0, entries );
-
- for ( NodeEntry nodeEntry : entries )
- {
- char[] level = new char[( nodeEntry.getLevel() * 3 )];
- Arrays.fill( level, ' ' );
-
- if ( level.length != 0 )
- {
- level[level.length - 3] = '+';
- level[level.length - 2] = '-';
- }
-
- String definition = nodeEntry.getDefinition();
-
- ret.append( level ).append( definition ).append( "\n" );
- }
-
- return ret.toString();
-
- }
-
- private void addNode( DependencyNode root, int level, List<NodeEntry> entries )
- {
-
- NodeEntry entry = new NodeEntry();
- Dependency dependency = root.getDependency();
- StringBuilder defBuilder = new StringBuilder();
- if ( dependency == null )
- {
- defBuilder.append( "(null)" );
- }
- else
- {
- Artifact artifact = dependency.getArtifact();
-
- defBuilder.append( artifact.getGroupId() ).append( ":" ).append( artifact.getArtifactId() ).append( ":" ).append( artifact.getExtension() ).append( ":" ).append( artifact.getVersion() );
- if ( dependency.getScope() != null && ( !"".equals( dependency.getScope() ) ) )
- {
- defBuilder.append( ":" ).append( dependency.getScope() );
- }
-
- Map<String, String> properties = artifact.getProperties();
- if ( !( properties == null || properties.isEmpty() ) )
- {
- for ( Map.Entry<String, String> prop : properties.entrySet() )
- {
- defBuilder.append( ";" ).append( prop.getKey() ).append( "=" ).append( prop.getValue() );
- }
- }
- }
-
- entry.setDefinition( defBuilder.toString() );
- entry.setLevel( level++ );
-
- entries.add( entry );
-
- for ( DependencyNode node : root.getChildren() )
- {
- addNode( node, level, entries );
- }
-
- }
-
- class NodeEntry
- {
- int level;
-
- String definition;
-
- Map<String, String> properties;
-
- public int getLevel()
- {
- return level;
- }
-
- public void setLevel( int level )
- {
- this.level = level;
- }
-
- public String getDefinition()
- {
- return definition;
- }
-
- public void setDefinition( String definition )
- {
- this.definition = definition;
- }
-
- public Map<String, String> getProperties()
- {
- return properties;
- }
-
- public void setProperties( Map<String, String> properties )
- {
- this.properties = properties;
- }
- }
-
- private static LineContext createContext( String line )
- {
- LineContext ctx = new LineContext();
- String definition;
-
- String[] split = line.split( "- " );
- if ( split.length == 1 ) // root
- {
- ctx.setLevel( 0 );
- definition = split[0];
- }
- else
- {
- ctx.setLevel( (int) Math.ceil( (double) split[0].length() / (double) 3 ) );
- definition = split[1];
- }
-
- if ( "(null)".equalsIgnoreCase( definition ) )
- {
- return ctx;
- }
-
- ctx.setDefinition( new NodeDefinition( definition ) );
-
- return ctx;
- }
-
- static class LineContext
- {
- NodeDefinition definition;
-
- int level;
-
- public NodeDefinition getDefinition()
- {
- return definition;
- }
-
- public void setDefinition( NodeDefinition definition )
- {
- this.definition = definition;
- }
-
- public int getLevel()
- {
- return level;
- }
-
- public void setLevel( int level )
- {
- this.level = level;
- }
- }
-
- public Collection<String> getSubstitutions()
- {
- return substitutions;
- }
-
- public void setSubstitutions( Collection<String> substitutions )
- {
- this.substitutions = substitutions;
- }
-
- public void setSubstitutions( String... substitutions )
- {
- setSubstitutions( Arrays.asList( substitutions ) );
- }
-
-}
http://git-wip-us.apache.org/repos/asf/maven-aether/blob/27f8bd73/aether-test-util/src/main/java/org/eclipse/aether/internal/test/util/IniArtifactDataReader.java
----------------------------------------------------------------------
diff --git a/aether-test-util/src/main/java/org/eclipse/aether/internal/test/util/IniArtifactDataReader.java b/aether-test-util/src/main/java/org/eclipse/aether/internal/test/util/IniArtifactDataReader.java
deleted file mode 100644
index b38c4d6..0000000
--- a/aether-test-util/src/main/java/org/eclipse/aether/internal/test/util/IniArtifactDataReader.java
+++ /dev/null
@@ -1,391 +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.BufferedReader;
-import java.io.IOException;
-import java.io.InputStreamReader;
-import java.io.Reader;
-import java.io.StringReader;
-import java.net.URL;
-import java.util.ArrayList;
-import java.util.Collection;
-import java.util.HashMap;
-import java.util.List;
-import java.util.Locale;
-import java.util.Map;
-
-import org.eclipse.aether.artifact.Artifact;
-import org.eclipse.aether.artifact.DefaultArtifact;
-import org.eclipse.aether.graph.Dependency;
-import org.eclipse.aether.graph.Exclusion;
-import org.eclipse.aether.repository.RemoteRepository;
-
-/**
- * @see IniArtifactDescriptorReader
- */
-class IniArtifactDataReader
-{
-
- private String prefix = "";
-
- /**
- * Constructs a data reader with the prefix {@code ""}.
- */
- public IniArtifactDataReader()
- {
- this( "" );
- }
-
- /**
- * Constructs a data reader with the given prefix.
- *
- * @param prefix the prefix to use for loading resources from the classpath.
- */
- public IniArtifactDataReader( String prefix )
- {
- this.prefix = prefix;
-
- }
-
- /**
- * Load an artifact description from the classpath and parse it.
- */
- public ArtifactDescription parse( String resource )
- throws IOException
- {
- URL res = this.getClass().getClassLoader().getResource( prefix + resource );
-
- if ( res == null )
- {
- throw new IOException( "cannot find resource: " + resource );
- }
- return parse( res );
- }
-
- /**
- * Open the given URL and parse ist.
- */
- public ArtifactDescription parse( URL res )
- throws IOException
- {
- return parse( new InputStreamReader( res.openStream(), "UTF-8" ) );
- }
-
- /**
- * Parse the given String.
- */
- public ArtifactDescription parseLiteral( String description )
- throws IOException
- {
- StringReader reader = new StringReader( description );
- return parse( reader );
- }
-
- private enum State
- {
- NONE, RELOCATION, DEPENDENCIES, MANAGEDDEPENDENCIES, REPOSITORIES
- }
-
- private ArtifactDescription parse( Reader reader )
- throws IOException
- {
- State state = State.NONE;
- Map<State, List<String>> sections = new HashMap<State, List<String>>();
- BufferedReader in = null;
- try
- {
- in = new BufferedReader( reader );
- for ( String line = in.readLine(); line != null; line = in.readLine() )
- {
- line = cutComment( line );
- if ( isEmpty( line ) )
- {
- continue;
- }
-
- if ( line.startsWith( "[" ) )
- {
- try
- {
- String name = line.substring( 1, line.length() - 1 );
- name = name.replace( "-", "" ).toUpperCase( Locale.ENGLISH );
- state = State.valueOf( name );
- sections.put( state, new ArrayList<String>() );
- }
- catch ( IllegalArgumentException e )
- {
- throw new IOException( "unknown section: " + line );
- }
- }
- else
- {
- List<String> lines = sections.get( state );
- if ( lines == null )
- {
- throw new IOException( "missing section: " + line );
- }
- lines.add( line.trim() );
- }
- }
-
- in.close();
- in = null;
- }
- finally
- {
- try
- {
- if ( in != null )
- {
- in.close();
- }
- }
- catch ( final IOException e )
- {
- // Suppressed
- }
- }
-
- Artifact relocation = relocation( sections.get( State.RELOCATION ) );
- List<Dependency> dependencies = dependencies( sections.get( State.DEPENDENCIES ), false );
- List<Dependency> managedDependencies = dependencies( sections.get( State.MANAGEDDEPENDENCIES ), true );
- List<RemoteRepository> repositories = repositories( sections.get( State.REPOSITORIES ) );
-
- ArtifactDescription description =
- new ArtifactDescription( relocation, dependencies, managedDependencies, repositories );
- return description;
- }
-
- private List<RemoteRepository> repositories( List<String> list )
- {
- ArrayList<RemoteRepository> ret = new ArrayList<RemoteRepository>();
- if ( list == null )
- {
- return ret;
- }
- for ( String coords : list )
- {
- String[] split = coords.split( ":", 3 );
- String id = split[0];
- String type = split[1];
- String url = split[2];
-
- ret.add( new RemoteRepository.Builder( id, type, url ).build() );
- }
- return ret;
- }
-
- private List<Dependency> dependencies( List<String> list, boolean managed )
- {
- List<Dependency> ret = new ArrayList<Dependency>();
- if ( list == null )
- {
- return ret;
- }
-
- Collection<Exclusion> exclusions = new ArrayList<Exclusion>();
-
- Boolean optional = null;
- Artifact artifact = null;
- String scope = null;
-
- for ( String coords : list )
- {
- if ( coords.startsWith( "-" ) )
- {
- coords = coords.substring( 1 );
- String[] split = coords.split( ":" );
- exclusions.add( new Exclusion( split[0], split[1], "*", "*" ) );
- }
- else
- {
- if ( artifact != null )
- {
- // commit dependency
- Dependency dep = new Dependency( artifact, scope, optional, exclusions );
- ret.add( dep );
-
- exclusions = new ArrayList<Exclusion>();
- }
-
- ArtifactDefinition def = new ArtifactDefinition( coords );
-
- optional = managed ? def.getOptional() : Boolean.valueOf( Boolean.TRUE.equals( def.getOptional() ) );
-
- scope = "".equals( def.getScope() ) && !managed ? "compile" : def.getScope();
-
- artifact =
- new DefaultArtifact( def.getGroupId(), def.getArtifactId(), "", def.getExtension(),
- def.getVersion() );
- }
- }
- if ( artifact != null )
- {
- // commit dependency
- Dependency dep = new Dependency( artifact, scope, optional, exclusions );
- ret.add( dep );
- }
-
- return ret;
- }
-
- private Artifact relocation( List<String> list )
- {
- if ( list == null || list.isEmpty() )
- {
- return null;
- }
- String coords = list.get( 0 );
- ArtifactDefinition def = new ArtifactDefinition( coords );
- return new DefaultArtifact( def.getGroupId(), def.getArtifactId(), "", def.getExtension(), def.getVersion() );
- }
-
- private static boolean isEmpty( String line )
- {
- return line == null || line.length() == 0;
- }
-
- private static String cutComment( String line )
- {
- int idx = line.indexOf( '#' );
-
- if ( idx != -1 )
- {
- line = line.substring( 0, idx );
- }
-
- return line;
- }
-
- static class Definition
- {
- private String groupId;
-
- private String artifactId;
-
- private String extension;
-
- private String version;
-
- private String scope = "";
-
- private String definition;
-
- private String id = null;
-
- private String reference = null;
-
- private boolean optional = false;
-
- public Definition( String def )
- {
- this.definition = def.trim();
-
- if ( definition.startsWith( "(" ) )
- {
- int idx = definition.indexOf( ')' );
- this.id = definition.substring( 1, idx );
- this.definition = definition.substring( idx + 1 );
- }
- else if ( definition.startsWith( "^" ) )
- {
- this.reference = definition.substring( 1 );
- return;
- }
-
- String[] split = definition.split( ":" );
- if ( split.length < 4 )
- {
- throw new IllegalArgumentException( "Need definition like 'gid:aid:ext:ver[:scope]', but was: "
- + definition );
- }
- groupId = split[0];
- artifactId = split[1];
- extension = split[2];
- version = split[3];
- if ( split.length > 4 )
- {
- scope = split[4];
- }
- if ( split.length > 5 && "true".equalsIgnoreCase( split[5] ) )
- {
- optional = true;
- }
- }
-
- public String getGroupId()
- {
- return groupId;
- }
-
- public String getArtifactId()
- {
- return artifactId;
- }
-
- public String getType()
- {
- return extension;
- }
-
- public String getVersion()
- {
- return version;
- }
-
- public String getScope()
- {
- return scope;
- }
-
- @Override
- public String toString()
- {
- return definition;
- }
-
- public String getId()
- {
- return id;
- }
-
- public String getReference()
- {
- return reference;
- }
-
- public boolean isReference()
- {
- return reference != null;
- }
-
- public boolean hasId()
- {
- return id != null;
- }
-
- public boolean isOptional()
- {
- return optional;
- }
- }
-
-}
http://git-wip-us.apache.org/repos/asf/maven-aether/blob/27f8bd73/aether-test-util/src/main/java/org/eclipse/aether/internal/test/util/IniArtifactDescriptorReader.java
----------------------------------------------------------------------
diff --git a/aether-test-util/src/main/java/org/eclipse/aether/internal/test/util/IniArtifactDescriptorReader.java b/aether-test-util/src/main/java/org/eclipse/aether/internal/test/util/IniArtifactDescriptorReader.java
deleted file mode 100644
index 4efe880..0000000
--- a/aether-test-util/src/main/java/org/eclipse/aether/internal/test/util/IniArtifactDescriptorReader.java
+++ /dev/null
@@ -1,125 +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.RepositorySystemSession;
-import org.eclipse.aether.artifact.Artifact;
-import org.eclipse.aether.resolution.ArtifactDescriptorException;
-import org.eclipse.aether.resolution.ArtifactDescriptorRequest;
-import org.eclipse.aether.resolution.ArtifactDescriptorResult;
-
-/**
- * An artifact descriptor reader that gets data from a simple text file on the classpath. The data file for an artifact
- * with the coordinates {@code gid:aid:ext:ver} is expected to be named {@code gid_aid_ver.ini} and can optionally have
- * some prefix. The data file can have the following sections:
- * <ul>
- * <li>relocation</li>
- * <li>dependencies</li>
- * <li>managedDependencies</li>
- * <li>repositories</li>
- * </ul>
- * The relocation and dependency sections contain artifact coordinates of the form:
- *
- * <pre>
- * gid:aid:ext:ver[:scope][:optional]
- * </pre>
- *
- * The dependency sections may also specify exclusions:
- *
- * <pre>
- * -gid:aid
- * </pre>
- *
- * A repository definition is of the form:
- *
- * <pre>
- * id:type:url
- * </pre>
- *
- * <h2>Example</h2>
- *
- * <pre>
- * [relocation]
- * gid:aid:ext:ver
- *
- * [dependencies]
- * gid:aid:ext:ver:scope
- * -exclusion:aid
- * gid:aid2:ext:ver:scope:optional
- *
- * [managed-dependencies]
- * gid:aid2:ext:ver2:scope
- * -gid:aid
- * -gid:aid
- *
- * [repositories]
- * id:type:file:///test-repo
- * </pre>
- */
-public class IniArtifactDescriptorReader
-{
- private IniArtifactDataReader reader;
-
- /**
- * Use the given prefix to load the artifact descriptions from the classpath.
- */
- public IniArtifactDescriptorReader( String prefix )
- {
- reader = new IniArtifactDataReader( prefix );
- }
-
- /**
- * Parses the resource {@code $prefix/gid_aid_ver.ini} from the request artifact as an artifact description and
- * wraps it into an ArtifactDescriptorResult.
- */
- public ArtifactDescriptorResult readArtifactDescriptor( RepositorySystemSession session,
- ArtifactDescriptorRequest request )
- throws ArtifactDescriptorException
- {
- ArtifactDescriptorResult result = new ArtifactDescriptorResult( request );
- for ( Artifact artifact = request.getArtifact();; )
- {
- String resourceName =
- String.format( "%s_%s_%s.ini", artifact.getGroupId(), artifact.getArtifactId(), artifact.getVersion() );
- try
- {
- ArtifactDescription data = reader.parse( resourceName );
- if ( data.getRelocation() != null )
- {
- result.addRelocation( artifact );
- artifact = data.getRelocation();
- }
- else
- {
- result.setArtifact( artifact );
- result.setDependencies( data.getDependencies() );
- result.setManagedDependencies( data.getManagedDependencies() );
- result.setRepositories( data.getRepositories() );
- return result;
- }
- }
- catch ( Exception e )
- {
- throw new ArtifactDescriptorException( result, e.getMessage(), e );
- }
- }
- }
-
-}
http://git-wip-us.apache.org/repos/asf/maven-aether/blob/27f8bd73/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-aether/blob/27f8bd73/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-aether/blob/27f8bd73/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-aether/blob/27f8bd73/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-aether/blob/27f8bd73/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 6744583..0000000
--- a/aether-test-util/src/main/java/org/eclipse/aether/internal/test/util/TestFileProcessor.java
+++ /dev/null
@@ -1,223 +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();
- fos = null;
- }
- 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();
- fos = null;
- }
- 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
- {
- InputStream fis = null;
- OutputStream fos = null;
- try
- {
- fis = new FileInputStream( source );
-
- mkdirs( target.getAbsoluteFile().getParentFile() );
-
- fos = new BufferedOutputStream( new FileOutputStream( target ) );
-
- final long total = copy( fos, fis, listener );
-
- // allow output to report any flush/close errors
- fos.close();
- fos = null;
-
- fis.close();
- fis = null;
-
- return total;
- }
- finally
- {
- close( fis );
- close( fos );
- }
- }
-
- 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-aether/blob/27f8bd73/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 be04bdc..0000000
--- a/aether-test-util/src/main/java/org/eclipse/aether/internal/test/util/TestFileUtils.java
+++ /dev/null
@@ -1,331 +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
- {
- FileInputStream fis = null;
- OutputStream fos = null;
- try
- {
- fis = new FileInputStream( source );
-
- mkdirs( target.getParentFile() );
-
- fos = new BufferedOutputStream( new FileOutputStream( target ) );
-
- long total = 0;
-
- 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();
- fos = null;
-
- fis.close();
- fis = null;
-
- return total;
- }
- finally
- {
- close( fis );
- close( fos );
- }
- }
-
- 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 );
- in.close();
- in = null;
- 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();
- out = null;
- }
- 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 );
- fis.close();
- fis = null;
- }
- 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();
- fos = null;
- }
- finally
- {
- close( fos );
- }
- }
-
-}
http://git-wip-us.apache.org/repos/asf/maven-aether/blob/27f8bd73/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-aether/blob/27f8bd73/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-aether/blob/27f8bd73/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-aether/blob/27f8bd73/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-aether/blob/27f8bd73/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;
- }
-
-}