You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@maven.apache.org by og...@apache.org on 2009/04/23 00:57:04 UTC

svn commit: r767705 [2/31] - in /maven/mercury/trunk/mercury-core: ./ src/ src/main/ src/main/java/ src/main/java/org/ src/main/java/org/apache/ src/main/java/org/apache/maven/ src/main/java/org/apache/maven/mercury/ src/main/java/org/apache/maven/merc...

Added: maven/mercury/trunk/mercury-core/pom.xml
URL: http://svn.apache.org/viewvc/maven/mercury/trunk/mercury-core/pom.xml?rev=767705&view=auto
==============================================================================
--- maven/mercury/trunk/mercury-core/pom.xml (added)
+++ maven/mercury/trunk/mercury-core/pom.xml Wed Apr 22 22:56:48 2009
@@ -0,0 +1,130 @@
+<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
+  <parent>
+    <artifactId>mercury</artifactId>
+    <groupId>org.apache.maven.mercury</groupId>
+    <version>1.0-alpha-7-SNAPSHOT</version>
+  </parent>
+  <modelVersion>4.0.0</modelVersion>
+  <groupId>org.apache.maven.mercury</groupId>
+  <artifactId>mercury-core</artifactId>
+  <name>Mercury Core</name>
+  <version>1.0-alpha-7-SNAPSHOT</version>
+
+  <dependencies>
+  	<dependency>
+  		<groupId>commons-cli</groupId>
+  		<artifactId>commons-cli</artifactId>
+  	</dependency>
+
+    <!-- SAT solver used to calculate viable ranges when dependencies are expressed pseudo boolean form -->
+    <dependency>
+      <groupId>org.sat4j</groupId>
+      <artifactId>org.sat4j.core</artifactId>
+    </dependency>
+
+    <dependency>
+      <groupId>org.sat4j</groupId>
+      <artifactId>org.sat4j.pb</artifactId>
+    </dependency>
+
+   <dependency>
+      <groupId>bouncycastle</groupId>
+      <artifactId>bcprov-jdk15</artifactId>
+      <optional>true</optional>
+    </dependency>
+
+    <dependency>
+      <groupId>bouncycastle</groupId>
+      <artifactId>bcpg-jdk15</artifactId>
+      <optional>true</optional>
+    </dependency>    
+
+    <dependency>
+      <groupId>org.mortbay.jetty</groupId>
+      <artifactId>jetty-client</artifactId>
+      <classifier>assembly</classifier>
+      <exclusions>
+        <exclusion>
+         <groupId>org.mortbay.jetty</groupId>
+         <artifactId>jetty</artifactId>
+        </exclusion>
+        <exclusion>
+         <groupId>org.mortbay.jetty</groupId>
+         <artifactId>jetty-sslengine</artifactId>
+        </exclusion>
+        <exclusion>
+         <groupId>org.mortbay.jetty</groupId>
+         <artifactId>jetty-util</artifactId>
+        </exclusion>
+      </exclusions>
+    </dependency>
+
+    <dependency>
+      <groupId>org.mortbay.jetty</groupId>
+      <artifactId>jetty-util5</artifactId>
+    </dependency>
+
+    <dependency>
+      <groupId>org.codehaus.plexus</groupId>
+      <artifactId>plexus-utils</artifactId>
+    </dependency>
+
+    <!-- Test Dependencies -->
+    <dependency>
+      <groupId>org.mortbay.jetty</groupId>
+      <artifactId>jetty-servlet-tester</artifactId>
+      <scope>test</scope>
+    </dependency>
+
+
+    <dependency>
+      <groupId>commons-digester</groupId>
+      <artifactId>commons-digester</artifactId>
+      <scope>test</scope>
+    </dependency>
+ 
+
+  </dependencies>
+
+  <build>
+    <plugins>
+      <plugin>
+        <groupId>org.codehaus.modello</groupId>
+        <artifactId>modello-maven-plugin</artifactId>
+        <configuration>
+          <version>1.0.0</version>
+          <models>
+            <model>src/main/mdo/cached-metadata.mdo</model>
+            <model>src/main/mdo/metadata.mdo</model>
+            <model>src/main/mdo/forest.mdo</model>
+          </models>
+        </configuration>
+        <executions>
+          <execution>
+            <id>standard</id>
+            <goals>
+              <goal>java</goal>
+              <goal>xpp3-reader</goal>
+              <goal>xpp3-writer</goal>
+            </goals>
+          </execution>
+        </executions>
+      </plugin>
+
+      <plugin>
+        <groupId>org.apache.maven.plugins</groupId>
+        <artifactId>maven-jar-plugin</artifactId>
+        <executions>
+          <execution>
+            <id>package-tests</id>
+            <goals>
+              <goal>test-jar</goal>
+            </goals>
+          </execution>
+        </executions>
+      </plugin>
+    </plugins>
+  </build>
+
+
+</project>
\ No newline at end of file

Propchange: maven/mercury/trunk/mercury-core/pom.xml
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: maven/mercury/trunk/mercury-core/pom.xml
------------------------------------------------------------------------------
    svn:keywords = Author Date Id Revision

Added: maven/mercury/trunk/mercury-core/src/main/java/org/apache/maven/mercury/artifact/Artifact.java
URL: http://svn.apache.org/viewvc/maven/mercury/trunk/mercury-core/src/main/java/org/apache/maven/mercury/artifact/Artifact.java?rev=767705&view=auto
==============================================================================
--- maven/mercury/trunk/mercury-core/src/main/java/org/apache/maven/mercury/artifact/Artifact.java (added)
+++ maven/mercury/trunk/mercury-core/src/main/java/org/apache/maven/mercury/artifact/Artifact.java Wed Apr 22 22:56:48 2009
@@ -0,0 +1,102 @@
+package org.apache.maven.mercury.artifact;
+
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more contributor license
+ * agreements. See the NOTICE file distributed with this work for additional information regarding
+ * copyright ownership. The ASF licenses this file to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance with the License. You may obtain a
+ * copy of the License at
+ * 
+ * http://www.apache.org/licenses/LICENSE-2.0
+ * 
+ * Unless required by applicable law or agreed to in writing, software distributed under the License
+ * is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express
+ * or implied. See the License for the specific language governing permissions and limitations under
+ * the License.
+ */
+
+import java.io.File;
+import java.io.InputStream;
+import java.util.regex.Pattern;
+
+/**
+ * TODO: Oleg: don't know if this should be interface or class, so there is a little disparate:
+ *  ArtifactMetadata is a class, Artifact is an interface. Will clear out  
+ *
+ *
+ * @author Oleg Gusakov
+ * @version $Id$
+ *
+ */
+public interface Artifact
+extends Comparable<Artifact>
+{
+    static final String LATEST_VERSION = "LATEST";
+
+    static final String SNAPSHOT_VERSION = "SNAPSHOT";
+
+    static final String RELEASE_VERSION = "RELEASE";
+
+    static final String  SNAPSHOT_TS_REGEX = ".+-\\d{8}\\.\\d{6}-\\d+";
+
+    static final Pattern VERSION_FILE_PATTERN = Pattern.compile( "^(.*)-([0-9]{8}.[0-9]{6})-([0-9]+)$" );
+
+    // TODO: into artifactScope handler
+
+    static final String SCOPE_COMPILE = ArtifactScopeEnum.compile.toString();
+
+    static final String SCOPE_TEST = ArtifactScopeEnum.test.toString();
+
+    static final String SCOPE_RUNTIME = ArtifactScopeEnum.runtime.toString();
+
+    static final String SCOPE_PROVIDED = ArtifactScopeEnum.provided.toString();
+
+    static final String SCOPE_SYSTEM = ArtifactScopeEnum.system.toString();
+
+    String getGroupId();
+
+    String getArtifactId();
+
+    String getVersion();
+
+    void setVersion( String version );
+
+    /**
+     * Get the artifactScope of the artifact. If the artifact is a standalone rather than a dependency, it's artifactScope will be
+     * <code>null</code>. The artifactScope may not be the same as it was declared on the original dependency, as this is the
+     * result of combining it with the main project artifactScope.
+     *
+     * @return the artifactScope
+     */
+    String getScope();
+
+    String getType();
+
+    String getClassifier();
+
+    // only providing this since classifier is *very* optional...
+    boolean hasClassifier();
+
+    File getFile();
+    
+    // in case binary is supplied as a Stream, not a File
+    InputStream getStream();
+
+    void setFile( File destination );
+    
+    byte [] getPomBlob();
+    
+    void setPomBlob( byte [] pomBlob );
+    
+    String getBaseName();
+    
+    String getBaseName( String classifier );
+
+    // ----------------------------------------------------------------------
+
+    String getId();
+
+    void setGroupId( String groupId );
+
+    void setArtifactId( String artifactId );
+}
\ No newline at end of file

Propchange: maven/mercury/trunk/mercury-core/src/main/java/org/apache/maven/mercury/artifact/Artifact.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: maven/mercury/trunk/mercury-core/src/main/java/org/apache/maven/mercury/artifact/Artifact.java
------------------------------------------------------------------------------
    svn:keywords = Author Date Id Revision

Added: maven/mercury/trunk/mercury-core/src/main/java/org/apache/maven/mercury/artifact/ArtifactCoordinates.java
URL: http://svn.apache.org/viewvc/maven/mercury/trunk/mercury-core/src/main/java/org/apache/maven/mercury/artifact/ArtifactCoordinates.java?rev=767705&view=auto
==============================================================================
--- maven/mercury/trunk/mercury-core/src/main/java/org/apache/maven/mercury/artifact/ArtifactCoordinates.java (added)
+++ maven/mercury/trunk/mercury-core/src/main/java/org/apache/maven/mercury/artifact/ArtifactCoordinates.java Wed Apr 22 22:56:48 2009
@@ -0,0 +1,114 @@
+/**
+ *  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.
+ */
+package org.apache.maven.mercury.artifact;
+
+/**
+ * @author Oleg Gusakov
+ * @version $Id$
+ */
+public class ArtifactCoordinates
+{
+    /**
+     * standard glorified artifact coordinates
+     */
+    protected String groupId;
+
+    protected String artifactId;
+
+    protected String version;
+
+    protected String classifier;
+
+    protected String type;
+
+    public ArtifactCoordinates( String groupId, String artifactId, String version )
+    {
+        this.groupId = groupId;
+        this.artifactId = artifactId;
+        this.version = version;
+    }
+
+    public ArtifactCoordinates( String groupId, String artifactId, String version, String type )
+    {
+        this( groupId, artifactId, version );
+        this.type = type;
+    }
+
+    public ArtifactCoordinates( String groupId, String artifactId, String version, String type, String classifier )
+    {
+        this( groupId, artifactId, version, type );
+        this.classifier = classifier;
+    }
+
+    public String getGroupId()
+    {
+        return groupId;
+    }
+
+    public void setGroupId( String groupId )
+    {
+        this.groupId = groupId;
+    }
+
+    public String getArtifactId()
+    {
+        return artifactId;
+    }
+
+    public void setArtifactId( String artifactId )
+    {
+        this.artifactId = artifactId;
+    }
+
+    public String getVersion()
+    {
+        return version;
+    }
+
+    public void setVersion( String version )
+    {
+        this.version = version;
+    }
+    
+    public String getClassifier()
+    {
+        return classifier;
+    }
+
+    public void setClassifier( String classifier )
+    {
+        this.classifier = classifier;
+    }
+
+    public String getType()
+    {
+        return type;
+    }
+
+    public void setType( String type )
+    {
+        this.type = type;
+    }
+
+    @Override
+    public String toString()
+    {
+        return groupId + ":" + artifactId + ":" + version;
+    }
+}

Propchange: maven/mercury/trunk/mercury-core/src/main/java/org/apache/maven/mercury/artifact/ArtifactCoordinates.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: maven/mercury/trunk/mercury-core/src/main/java/org/apache/maven/mercury/artifact/ArtifactCoordinates.java
------------------------------------------------------------------------------
    svn:keywords = Author Date Id Revision

Added: maven/mercury/trunk/mercury-core/src/main/java/org/apache/maven/mercury/artifact/ArtifactExclusionList.java
URL: http://svn.apache.org/viewvc/maven/mercury/trunk/mercury-core/src/main/java/org/apache/maven/mercury/artifact/ArtifactExclusionList.java?rev=767705&view=auto
==============================================================================
--- maven/mercury/trunk/mercury-core/src/main/java/org/apache/maven/mercury/artifact/ArtifactExclusionList.java (added)
+++ maven/mercury/trunk/mercury-core/src/main/java/org/apache/maven/mercury/artifact/ArtifactExclusionList.java Wed Apr 22 22:56:48 2009
@@ -0,0 +1,55 @@
+/**
+ *  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.
+ */
+package org.apache.maven.mercury.artifact;
+
+import java.util.Collection;
+
+/**
+ * @author Oleg Gusakov
+ * @version $Id$
+ */
+public class ArtifactExclusionList
+    extends ArtifactMetadataList
+{
+
+    /**
+     * @param md
+     */
+    public ArtifactExclusionList( ArtifactMetadata... md )
+    {
+        super( md );
+    }
+
+    /**
+     * @param md
+     */
+    public ArtifactExclusionList( Collection<ArtifactMetadata> md )
+    {
+        super( md );
+    }
+
+    /**
+     * @param mds
+     */
+    public ArtifactExclusionList( String... mds )
+    {
+        super( mds );
+    }
+
+}

Propchange: maven/mercury/trunk/mercury-core/src/main/java/org/apache/maven/mercury/artifact/ArtifactExclusionList.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: maven/mercury/trunk/mercury-core/src/main/java/org/apache/maven/mercury/artifact/ArtifactExclusionList.java
------------------------------------------------------------------------------
    svn:keywords = Author Date Id Revision

Added: maven/mercury/trunk/mercury-core/src/main/java/org/apache/maven/mercury/artifact/ArtifactInclusionList.java
URL: http://svn.apache.org/viewvc/maven/mercury/trunk/mercury-core/src/main/java/org/apache/maven/mercury/artifact/ArtifactInclusionList.java?rev=767705&view=auto
==============================================================================
--- maven/mercury/trunk/mercury-core/src/main/java/org/apache/maven/mercury/artifact/ArtifactInclusionList.java (added)
+++ maven/mercury/trunk/mercury-core/src/main/java/org/apache/maven/mercury/artifact/ArtifactInclusionList.java Wed Apr 22 22:56:48 2009
@@ -0,0 +1,55 @@
+/**
+ *  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.
+ */
+package org.apache.maven.mercury.artifact;
+
+import java.util.Collection;
+
+/**
+ * @author Oleg Gusakov
+ * @version $Id$
+ */
+public class ArtifactInclusionList
+    extends ArtifactMetadataList
+{
+
+    /**
+     * @param md
+     */
+    public ArtifactInclusionList( ArtifactMetadata... md )
+    {
+        super( md );
+    }
+
+    /**
+     * @param md
+     */
+    public ArtifactInclusionList( Collection<ArtifactMetadata> md )
+    {
+        super( md );
+    }
+
+    /**
+     * @param mds
+     */
+    public ArtifactInclusionList( String... mds )
+    {
+        super( mds );
+    }
+
+}

Propchange: maven/mercury/trunk/mercury-core/src/main/java/org/apache/maven/mercury/artifact/ArtifactInclusionList.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: maven/mercury/trunk/mercury-core/src/main/java/org/apache/maven/mercury/artifact/ArtifactInclusionList.java
------------------------------------------------------------------------------
    svn:keywords = Author Date Id Revision

Added: maven/mercury/trunk/mercury-core/src/main/java/org/apache/maven/mercury/artifact/ArtifactMetadata.java
URL: http://svn.apache.org/viewvc/maven/mercury/trunk/mercury-core/src/main/java/org/apache/maven/mercury/artifact/ArtifactMetadata.java?rev=767705&view=auto
==============================================================================
--- maven/mercury/trunk/mercury-core/src/main/java/org/apache/maven/mercury/artifact/ArtifactMetadata.java (added)
+++ maven/mercury/trunk/mercury-core/src/main/java/org/apache/maven/mercury/artifact/ArtifactMetadata.java Wed Apr 22 22:56:48 2009
@@ -0,0 +1,799 @@
+/**
+ *  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.
+ */
+package org.apache.maven.mercury.artifact;
+
+import java.util.ArrayList;
+import java.util.Collection;
+import java.util.HashMap;
+import java.util.LinkedHashMap;
+import java.util.List;
+import java.util.Map;
+
+import org.apache.maven.mercury.artifact.version.DefaultArtifactVersion;
+import org.apache.maven.mercury.artifact.version.VersionException;
+import org.apache.maven.mercury.artifact.version.VersionRange;
+import org.apache.maven.mercury.artifact.version.VersionRangeFactory;
+import org.codehaus.plexus.lang.DefaultLanguage;
+import org.codehaus.plexus.lang.Language;
+
+/**
+ * this is the most primitive metadata there is, usually used to query repository for "real" metadata. It holds
+ * everything a project.dependencies.dependency element can have
+ *
+ * @author Oleg Gusakov
+ * @version $Id$
+ */
+public class ArtifactMetadata
+{
+    public static final String DEFAULT_ARTIFACT_TYPE = "jar";
+
+    private static final Language LANG = new DefaultLanguage( ArtifactMetadata.class );
+
+
+    /**
+     * standard glorified artifact coordinates
+     */
+    protected String groupId;
+
+    protected String artifactId;
+
+    private String version;
+
+    private transient VersionRange versionRange;
+
+    private Quality quality;
+
+    /**
+     * relocation chain after processing by ProjectBuilder
+     */
+    protected List<ArtifactCoordinates> relocations;
+
+    protected ArtifactCoordinates effectiveCoordinates;
+
+    // This is Maven specific. jvz/
+    protected String classifier;
+
+    protected String type = DEFAULT_ARTIFACT_TYPE;
+
+    protected ArtifactScopeEnum artifactScope;
+
+    protected String scope;
+
+    protected boolean optional;
+
+    protected Collection<ArtifactMetadata> inclusions;
+
+    protected Collection<ArtifactMetadata> exclusions;
+
+    protected Map<String, String> attributes;
+    
+    /** conveniency for SNAPSHOT file timestamp */
+    private String timeStamp;
+
+    /**
+     * transient helper objects, used by DependencyBuilder.
+     */
+    transient Object tracker;
+
+    transient Boolean local = false;
+
+    /**
+     * transient external datum to carry along
+     */
+    transient Object datum;
+    
+    /** dependencies of the artifact behind this metadata */
+    protected List<ArtifactMetadata> dependencies;
+
+    /** artifact URI */
+    protected String artifactUri;
+
+    // ------------------------------------------------------------------
+    public ArtifactMetadata()
+    {
+    }
+
+    // ------------------------------------------------------------------
+    private void processAttributes( String as )
+    {
+        if ( as == null || as.length() < 1 )
+        {
+            return;
+        }
+
+        String attrString = as.trim();
+
+        if ( attrString == null || attrString.length() < 1 )
+        {
+            return;
+        }
+
+        int fromCh = attrString.indexOf( '{' );
+        int toCh = attrString.indexOf( '}' );
+
+        if ( fromCh != -1 && toCh != -1 )
+        {
+            attrString = attrString.substring( fromCh + 1, toCh );
+        }
+
+        String[] entries = attrString.split( "," );
+
+        if ( entries != null )
+        {
+            for ( int i = 0; i < entries.length; i++ )
+            {
+                String e = entries[i];
+
+                if ( e == null )
+                {
+                    continue;
+                }
+
+                int eq = e.indexOf( '=' );
+
+                if ( eq == -1 )
+                {
+                    continue;
+                }
+
+                if ( attributes == null )
+                {
+                    attributes = new LinkedHashMap<String, String>( entries.length );
+                }
+
+                String name = e.substring( 0, eq );
+
+                if ( name == null )
+                {
+                    continue;
+                }
+
+                name = name.trim();
+
+                String val = e.substring( eq + 1 );
+
+                if ( val != null )
+                {
+                    val = val.trim();
+                }
+
+                attributes.put( name, val );
+            }
+        }
+    }
+
+    // ------------------------------------------------------------------
+    /**
+     * create basic out of <b>group:artifact:version:classifier:type</b> string, use empty string to specify missing
+     * component - for instance query for common-1.3.zip can be specified as ":common:1.3::zip" - note missing groupId
+     * and classifier.
+     */
+    public ArtifactMetadata( String gavQuery )
+    {
+        if ( gavQuery == null )
+        {
+            return;
+        }
+
+        String[] tokens = gavQuery.split( ":" );
+
+        if ( tokens == null || tokens.length < 1 )
+        {
+            return;
+        }
+
+        int count = tokens.length;
+
+        this.groupId = nullify( tokens[0] );
+
+        if ( count > 1 )
+        {
+            this.artifactId = nullify( tokens[1] );
+        }
+
+        if ( count > 2 )
+        {
+            this.version = nullify( tokens[2] );
+        }
+
+        if ( count > 3 )
+        {
+            this.classifier = nullify( tokens[3] );
+        }
+
+        if ( count > 4 )
+        {
+            setType( nullify( tokens[4] ) );
+        }
+
+        if ( this.type == null || this.type.length() < 1 )
+        {
+            this.type = DEFAULT_ARTIFACT_TYPE;
+        }
+
+        if ( count > 5 )
+        {
+            this.scope = nullify( tokens[5] );
+        }
+
+        if ( count > 6 )
+        {
+            processAttributes( nullify( tokens[6] ) );
+        }
+    }
+    
+    /**
+     * copy constructor
+     * 
+     * @param copyFrom
+     */
+    public ArtifactMetadata( ArtifactMetadata copyFrom )
+    {
+        if( copyFrom == null )
+            throw new IllegalArgumentException( LANG.getMessage( "null.copy.from.md") );
+
+       setGroupId( copyFrom.getGroupId() );
+       setArtifactId( copyFrom.getArtifactId() );
+       setVersion( copyFrom.getVersion() );
+       setClassifier( copyFrom.getClassifier() );
+       setType( copyFrom.getType() );
+       setScope( copyFrom.getScope() );
+       
+       Map<String, String> a = copyFrom.getAttributes(); 
+       if(  a != null && a.size() > 0 )
+       {
+           attributes = new HashMap<String, String>( a.size() );
+           
+           attributes.putAll( a );
+       }
+       
+       setTracker( copyFrom.getTracker() );
+       
+    }
+
+    // ------------------------------------------------------------------
+    /**
+     * create basic out of <b>group:artifact:version:classifier:type</b> string, use empty string to specify missing
+     * component - for instance query for common-1.3.zip can be specified as ":common:1.3::zip" - note missing groupId
+     * and classifier.
+     */
+    public static ArtifactMetadata create( String query )
+    {
+        ArtifactMetadata mdq = new ArtifactMetadata( query );
+
+        return mdq;
+    }
+
+    // ---------------------------------------------------------------------------
+    private static final String nullify( String s )
+    {
+        if ( s == null || s.length() < 1 )
+        {
+            return null;
+        }
+        return s;
+    }
+
+    // ---------------------------------------------------------------------
+    public boolean sameGAV( ArtifactMetadata md )
+    {
+        if ( md == null )
+        {
+            return false;
+        }
+
+        return sameGA( md ) && version != null && version.equals( md.getVersion() );
+    }
+
+    // ---------------------------------------------------------------------
+    public boolean sameGA( ArtifactMetadata md )
+    {
+        if ( md == null )
+        {
+            return false;
+        }
+
+        return groupId != null && artifactId != null && groupId.equals( md.getGroupId() )
+            && artifactId.equals( md.getArtifactId() );
+    }
+
+    public String getGA()
+    {
+        return toDomainString();
+    }
+
+    public String getGAV()
+    {
+        return toString();
+    }
+
+    private static final String nvl( String val, String dflt )
+    {
+        return val == null ? dflt : val;
+    }
+
+    private static final String nvl( String val )
+    {
+        return nvl( val, "" );
+    }
+
+    @Override
+    public String toString()
+    {
+        return nvl( groupId ) + ":" + nvl( artifactId ) + ":" + nvl( version ) + ":" + nvl( classifier ) + ":"
+            + nvl( type, DEFAULT_ARTIFACT_TYPE );
+    }
+
+    public String toScopedString()
+    {
+        return toString() + "-scope:" + getArtifactScope();
+    }
+
+    public String toDomainString()
+    {
+        return groupId + ":" + artifactId;
+    }
+
+    public String toManagementString()
+    {
+        return groupId + ":" + artifactId + ":" + type + ( classifier != null ? ":" + classifier : "" );
+    }
+
+    public String getBaseName()
+    {
+        return artifactId + "-" + version + ( classifier == null ? "" : "-" + classifier );
+    }
+
+    public String getFileName()
+    {
+        return getBaseName() + "." + ( type == null ? DEFAULT_ARTIFACT_TYPE : type );
+    }
+
+    public String getBaseName( String classifier )
+    {
+        return artifactId + "-" + version
+            + ( ( classifier == null || classifier.length() < 1 ) ? "" : "-" + classifier );
+    }
+
+    public String getCheckedType()
+    {
+        return type == null ? "jar" : type;
+    }
+
+    // ---------------------------------------------------------------------------
+    public String getGroupId()
+    {
+        return groupId;
+    }
+
+    public void setGroupId( String groupId )
+    {
+        this.groupId = groupId;
+    }
+
+    public String getArtifactId()
+    {
+        return artifactId;
+    }
+
+    public void setArtifactId( String artifactId )
+    {
+        this.artifactId = artifactId;
+    }
+
+    public String getVersion()
+    {
+        return version;
+    }
+
+    public boolean hasVersion()
+    {
+        return version != null && version.length() > 0;
+    }
+
+    public void setVersion( String version )
+    {
+        this.version = version;
+    }
+    
+    private void checkRangeExists()
+    {
+        if( versionRange == null )
+        {
+            if( version == null )
+                throw new IllegalArgumentException( LANG.getMessage( "artifact.metadata.no.version", toString() ) );
+            else
+            {
+                try
+                {
+                    versionRange = VersionRangeFactory.create( version );
+                }
+                catch ( VersionException e )
+                {
+                    throw new IllegalArgumentException( e.getMessage() );
+                }
+            }
+        }
+    }
+
+    public boolean isSingleton()
+    {
+        checkRangeExists();
+        
+        return versionRange.isSingleton();
+    }
+
+    public boolean isRange()
+    {
+        return !isSingleton();
+    }
+
+    /** code quality used to decide whether try or skip a repository - see repository code quality  */
+    public Quality getRequestedQuality()
+    {
+        if( isRange() )
+            return null;
+        
+        if( isVirtual() )
+        {
+            if( isVirtualSnapshot() )
+                return Quality.SNAPSHOT_QUALITY;
+            else
+                if( isVirtualRelease() )
+                    return Quality.RELEASE_QUALITY;
+            
+            return null;
+        }
+        
+        if( quality != null )
+            return quality;
+        
+        quality = new Quality( getVersion() );
+        
+        return quality;
+    }
+
+    public String getClassifier()
+    {
+        return classifier;
+    }
+
+    public void setClassifier( String classifier )
+    {
+        this.classifier = classifier;
+    }
+
+    public String getType()
+    {
+        return type;
+    }
+
+    public void setType( String type )
+    {
+        if( "test-jar".equals( type ) )
+        {
+            setClassifier( "tests" );
+            setType( "jar" );
+        }
+        else
+            this.type = type;
+    }
+
+    public Map<String, String> getAttributes()
+    {
+        return attributes;
+    }
+
+    public String getScope()
+    {
+        return getArtifactScope().getScope();
+    }
+
+    public ArtifactScopeEnum getScopeAsEnum()
+    {
+        return artifactScope == null ? ArtifactScopeEnum.DEFAULT_SCOPE : artifactScope;
+    }
+
+    public ArtifactScopeEnum getArtifactScope()
+    {
+        return artifactScope == null ? ArtifactScopeEnum.DEFAULT_SCOPE : artifactScope;
+    }
+
+    public void setArtifactScope( ArtifactScopeEnum artifactScope )
+    {
+        this.artifactScope = artifactScope;
+    }
+
+    public void setScope( String scope )
+    {
+        this.artifactScope = scope == null ? ArtifactScopeEnum.DEFAULT_SCOPE : ArtifactScopeEnum.valueOf( scope );
+    }
+
+    public boolean isOptional()
+    {
+        return optional;
+    }
+
+    public void setOptional( boolean optional )
+    {
+        this.optional = optional;
+    }
+
+    public void setOptional( String optional )
+    {
+        this.optional = "true".equals( optional );
+    }
+
+    public Object getTracker()
+    {
+        return tracker;
+    }
+
+    public void setTracker( Object tracker )
+    {
+        this.tracker = tracker;
+    }
+
+    public boolean hasClassifier()
+    {
+        return classifier != null && classifier.length() > 0;
+    }
+
+    public Boolean isLocal()
+    {
+        return local;
+    }
+
+    public void setLocal( Boolean local )
+    {
+        this.local = local;
+    }
+    
+    public boolean isPom()
+    {
+        return "pom".regionMatches( 0, type, 0, 3 );
+    }
+
+    public boolean isVirtual()
+    {
+        return DefaultArtifactVersion.isVirtual( version );
+    }
+
+    public boolean isVirtualSnapshot()
+    {
+        return DefaultArtifactVersion.isVirtualSnapshot( version );
+    }
+
+    public boolean isVirtualRelease()
+    {
+        return DefaultArtifactVersion.isVirtualRelease( version );
+    }
+
+    public boolean isVirtualLatest()
+    {
+        return DefaultArtifactVersion.isVirtualLatest( version );
+    }
+
+    public ArtifactCoordinates getEffectiveCoordinates()
+    {
+        if ( relocations == null || relocations.isEmpty() )
+        {
+            return new ArtifactCoordinates( groupId, artifactId, version );
+        }
+
+        return relocations.get( relocations.size() - 1 );
+    }
+
+    public ArtifactMetadata addRelocation( ArtifactCoordinates coord )
+    {
+        if ( coord == null )
+        {
+            return this;
+        }
+
+        if ( relocations == null )
+        {
+            relocations = new ArrayList<ArtifactCoordinates>( 2 );
+        }
+
+        if ( coord.getGroupId() == null )
+        {
+            coord.setGroupId( groupId );
+        }
+
+        if ( coord.getArtifactId() == null )
+        {
+            coord.setArtifactId( artifactId );
+        }
+
+        if ( coord.getVersion() == null )
+        {
+            coord.setVersion( version );
+        }
+
+        relocations.add( coord );
+        effectiveCoordinates = coord;
+
+        return this;
+    }
+
+    public String getEffectiveGroupId()
+    {
+        return effectiveCoordinates == null ? groupId : effectiveCoordinates.getGroupId();
+    }
+
+    public String getEffectiveArtifactId()
+    {
+        return effectiveCoordinates == null ? artifactId : effectiveCoordinates.getArtifactId();
+    }
+
+    public String getEffectiveersion()
+    {
+        return effectiveCoordinates == null ? version : effectiveCoordinates.getVersion();
+    }
+
+    public boolean hasInclusions()
+    {
+        return inclusions == null ? false : !inclusions.isEmpty();
+    }
+
+    public Collection<ArtifactMetadata> getInclusions()
+    {
+        return inclusions;
+    }
+
+    public void setInclusions( Collection<ArtifactMetadata> inclusions )
+    {
+        this.inclusions = inclusions;
+    }
+
+    public boolean hasExclusions()
+    {
+        return exclusions == null ? false : !exclusions.isEmpty();
+    }
+
+    public Collection<ArtifactMetadata> getExclusions()
+    {
+        return exclusions;
+    }
+
+    public void setExclusions( Collection<ArtifactMetadata> exclusions )
+    {
+        this.exclusions = exclusions;
+    }
+
+    /**
+     * run dependency through inclusion/exclusion filters. Inclusion filter is always a "hole"-filter, which is then
+     * enhanced by exclusion "cork"-filter
+     *
+     * @param dep dependency to vet
+     * @return vet result
+     * @throws VersionException
+     */
+    public boolean allowDependency( ArtifactMetadata dep )
+        throws VersionException
+    {
+        boolean includeDependency = true;
+        if ( hasInclusions() )
+        {
+            includeDependency = !passesFilter( inclusions, dep );
+        }
+
+        if ( !includeDependency )
+        {
+            return false;
+        }
+
+        if ( !hasExclusions() )
+        {
+            return true;
+        }
+
+        if ( passesFilter( exclusions, dep ) )
+        {
+            return true;
+        }
+
+        return false;
+
+    }
+
+    private boolean passesFilter( Collection<ArtifactMetadata> filter, ArtifactMetadata dep )
+        throws VersionException
+    {
+        for ( ArtifactMetadata filterMd : filter )
+        {
+            if ( filterMd.sameGA( dep ) )
+            {
+                if ( !filterMd.hasVersion() )
+                {
+                    return false; // no version in the filter - catch by GA
+                }
+                VersionRange vr = VersionRangeFactory.create( filterMd.getVersion() );
+                if ( vr.includes( dep.getVersion() ) )
+                {
+                    return false; // catch by version query
+                }
+            }
+        }
+
+        return true;
+    }
+
+    @Override
+    public boolean equals( Object obj )
+    {
+        if ( obj == null || !( obj instanceof ArtifactMetadata ) )
+        {
+            return false;
+        }
+
+        return toString().equals( obj.toString() );
+    }
+
+    @Override
+    public int hashCode()
+    {
+        return toString().hashCode();
+    }
+
+    public List<ArtifactMetadata> getDependencies()
+    {
+        return dependencies;
+    }
+
+    public void setDependencies( List<ArtifactMetadata> dependencies )
+    {
+        this.dependencies = dependencies;
+    }
+
+    public String getArtifactUri()
+    {
+        return artifactUri;
+    }
+
+    public void setArtifactUri( String artifactUri )
+    {
+        this.artifactUri = artifactUri;
+    }
+
+    public Object getDatum()
+    {
+        return datum;
+    }
+
+    public void setDatum( Object datum )
+    {
+        this.datum = datum;
+    }
+
+    public String getTimeStamp()
+    {
+        return timeStamp;
+    }
+
+    public void setTimeStamp( String timeStamp )
+    {
+        this.timeStamp = timeStamp;
+    }
+    
+    
+    // ---------------------------------------------------------------------------
+    // ---------------------------------------------------------------------------
+}

Propchange: maven/mercury/trunk/mercury-core/src/main/java/org/apache/maven/mercury/artifact/ArtifactMetadata.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: maven/mercury/trunk/mercury-core/src/main/java/org/apache/maven/mercury/artifact/ArtifactMetadata.java
------------------------------------------------------------------------------
    svn:keywords = Author Date Id Revision

Added: maven/mercury/trunk/mercury-core/src/main/java/org/apache/maven/mercury/artifact/ArtifactMetadataList.java
URL: http://svn.apache.org/viewvc/maven/mercury/trunk/mercury-core/src/main/java/org/apache/maven/mercury/artifact/ArtifactMetadataList.java?rev=767705&view=auto
==============================================================================
--- maven/mercury/trunk/mercury-core/src/main/java/org/apache/maven/mercury/artifact/ArtifactMetadataList.java (added)
+++ maven/mercury/trunk/mercury-core/src/main/java/org/apache/maven/mercury/artifact/ArtifactMetadataList.java Wed Apr 22 22:56:48 2009
@@ -0,0 +1,92 @@
+/**
+ *  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.
+ */
+package org.apache.maven.mercury.artifact;
+
+import java.util.ArrayList;
+import java.util.Collection;
+import java.util.List;
+
+/**
+ * @author Oleg Gusakov
+ * @version $Id$
+ */
+public abstract class ArtifactMetadataList
+{
+    List<ArtifactMetadata> _artifacts = new ArrayList<ArtifactMetadata>( 8 );
+
+    public ArtifactMetadataList( ArtifactMetadata... md )
+    {
+        for ( ArtifactMetadata m : md )
+            add( m );
+    }
+
+    public ArtifactMetadataList( Collection<ArtifactMetadata> md )
+    {
+        add( md );
+    }
+
+    public ArtifactMetadataList( String... mds )
+    {
+        for ( String m : mds )
+            add( new ArtifactMetadata( m ) );
+    }
+
+    public void add( ArtifactMetadata md )
+    {
+        _artifacts.add( md );
+    }
+
+    public void add( Collection<ArtifactMetadata> md )
+    {
+        _artifacts.addAll( md );
+    }
+
+    public void addGav( String md )
+    {
+        _artifacts.add( new ArtifactMetadata( md ) );
+    }
+
+    public void addByGav( Collection<String> mds )
+    {
+        for ( String m : mds )
+        {
+            _artifacts.add( new ArtifactMetadata( m ) );
+        }
+    }
+
+    public List<ArtifactMetadata> getMetadataList()
+    {
+        return _artifacts;
+    }
+
+    public int size()
+    {
+        return _artifacts.size();
+    }
+
+    public boolean isEmpty()
+    {
+        return _artifacts.isEmpty();
+    }
+
+    public void clear()
+    {
+        _artifacts.clear();
+    }
+}

Propchange: maven/mercury/trunk/mercury-core/src/main/java/org/apache/maven/mercury/artifact/ArtifactMetadataList.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: maven/mercury/trunk/mercury-core/src/main/java/org/apache/maven/mercury/artifact/ArtifactMetadataList.java
------------------------------------------------------------------------------
    svn:keywords = Author Date Id Revision

Added: maven/mercury/trunk/mercury-core/src/main/java/org/apache/maven/mercury/artifact/ArtifactQueryList.java
URL: http://svn.apache.org/viewvc/maven/mercury/trunk/mercury-core/src/main/java/org/apache/maven/mercury/artifact/ArtifactQueryList.java?rev=767705&view=auto
==============================================================================
--- maven/mercury/trunk/mercury-core/src/main/java/org/apache/maven/mercury/artifact/ArtifactQueryList.java (added)
+++ maven/mercury/trunk/mercury-core/src/main/java/org/apache/maven/mercury/artifact/ArtifactQueryList.java Wed Apr 22 22:56:48 2009
@@ -0,0 +1,55 @@
+/**
+ *  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.
+ */
+package org.apache.maven.mercury.artifact;
+
+import java.util.Collection;
+
+/**
+ * @author Oleg Gusakov
+ * @version $Id$
+ */
+public class ArtifactQueryList
+    extends ArtifactMetadataList
+{
+
+    /**
+     * @param md
+     */
+    public ArtifactQueryList( ArtifactMetadata... md )
+    {
+        super( md );
+    }
+
+    /**
+     * @param md
+     */
+    public ArtifactQueryList( Collection<ArtifactMetadata> md )
+    {
+        super( md );
+    }
+
+    /**
+     * @param mds
+     */
+    public ArtifactQueryList( String... mds )
+    {
+        super( mds );
+    }
+
+}

Propchange: maven/mercury/trunk/mercury-core/src/main/java/org/apache/maven/mercury/artifact/ArtifactQueryList.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: maven/mercury/trunk/mercury-core/src/main/java/org/apache/maven/mercury/artifact/ArtifactQueryList.java
------------------------------------------------------------------------------
    svn:keywords = Author Date Id Revision

Added: maven/mercury/trunk/mercury-core/src/main/java/org/apache/maven/mercury/artifact/ArtifactScopeEnum.java
URL: http://svn.apache.org/viewvc/maven/mercury/trunk/mercury-core/src/main/java/org/apache/maven/mercury/artifact/ArtifactScopeEnum.java?rev=767705&view=auto
==============================================================================
--- maven/mercury/trunk/mercury-core/src/main/java/org/apache/maven/mercury/artifact/ArtifactScopeEnum.java (added)
+++ maven/mercury/trunk/mercury-core/src/main/java/org/apache/maven/mercury/artifact/ArtifactScopeEnum.java Wed Apr 22 22:56:48 2009
@@ -0,0 +1,123 @@
+/**
+ *  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.
+ */
+package org.apache.maven.mercury.artifact;
+
+/**
+ * Type safe reincarnation of Artifact scope. Also supplies the <code>DEFAULT_SCOPE<code> as well
+ * as convenience method to deal with scope relationships.
+ *
+ * @author <a href="oleg@codehaus.org">Oleg Gusakov</a>
+ */
+public enum ArtifactScopeEnum
+{
+    compile( 1 ), test( 2 ), runtime( 3 ), provided( 4 ), system( 5 ), none( -1 );
+
+    public static final ArtifactScopeEnum DEFAULT_SCOPE = compile;
+
+    private int id;
+
+    // Constructor
+    ArtifactScopeEnum( int id )
+    {
+        this.id = id;
+    }
+
+    int getId()
+    {
+        return id;
+    }
+
+    /**
+     * Helper method to simplify null processing
+     *
+     * @return
+     */
+    public static final ArtifactScopeEnum checkScope( ArtifactScopeEnum scope )
+    {
+        return scope == null ? DEFAULT_SCOPE : scope;
+    }
+
+    /**
+     * @return unsafe String representation of this scope.
+     */
+    public String getScope()
+    {
+        if ( id == 1 )
+        {
+            return Artifact.SCOPE_COMPILE;
+        }
+        else if ( id == 2 )
+        {
+            return Artifact.SCOPE_TEST;
+        }
+        else if ( id == 3 )
+        {
+            return Artifact.SCOPE_RUNTIME;
+        }
+        else if ( id == 4 )
+        {
+            return Artifact.SCOPE_PROVIDED;
+        }
+        else if ( id == 5 )
+        {
+            return Artifact.SCOPE_SYSTEM;
+        }
+        else
+        {
+            return Artifact.SCOPE_SYSTEM;
+        }
+    }
+
+    private static final ArtifactScopeEnum[][][] _compliancySets =
+        { { { compile }, { compile, provided, system } }, { { test }, { compile, test, provided, system } },
+            { { runtime }, { compile, runtime, system } }, { { provided }, { compile, test, provided } } };
+
+    /**
+     * scope relationship function. Used by the graph conflict resolution policies
+     *
+     * @param scope
+     * @return true is supplied scope is an inclusive sub-scope of current one.
+     */
+    public boolean encloses( ArtifactScopeEnum scope )
+    {
+        final ArtifactScopeEnum s = checkScope( scope );
+
+        // system scope is historic only - and simple
+        if ( id == system.id )
+        {
+            return scope.id == system.id;
+        }
+
+        for ( ArtifactScopeEnum[][] set : _compliancySets )
+        {
+            if ( id == set[0][0].id )
+            {
+                for ( ArtifactScopeEnum ase : set[1] )
+                {
+                    if ( s.id == ase.id )
+                    {
+                        return true;
+                    }
+                }
+                break;
+            }
+        }
+        return false;
+    }
+}

Propchange: maven/mercury/trunk/mercury-core/src/main/java/org/apache/maven/mercury/artifact/ArtifactScopeEnum.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: maven/mercury/trunk/mercury-core/src/main/java/org/apache/maven/mercury/artifact/ArtifactScopeEnum.java
------------------------------------------------------------------------------
    svn:keywords = Author Date Id Revision

Added: maven/mercury/trunk/mercury-core/src/main/java/org/apache/maven/mercury/artifact/ConflictException.java
URL: http://svn.apache.org/viewvc/maven/mercury/trunk/mercury-core/src/main/java/org/apache/maven/mercury/artifact/ConflictException.java?rev=767705&view=auto
==============================================================================
--- maven/mercury/trunk/mercury-core/src/main/java/org/apache/maven/mercury/artifact/ConflictException.java (added)
+++ maven/mercury/trunk/mercury-core/src/main/java/org/apache/maven/mercury/artifact/ConflictException.java Wed Apr 22 22:56:48 2009
@@ -0,0 +1,65 @@
+/**
+ *  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.
+ */
+package org.apache.maven.mercury.artifact;
+
+/**
+ * @author Oleg Gusakov
+ * @version $Id$
+ */
+public class ConflictException
+    extends Exception
+{
+
+    /**
+   *
+   */
+    public ConflictException()
+    {
+        // TODO Auto-generated constructor stub
+    }
+
+    /**
+     * @param message
+     */
+    public ConflictException( String message )
+    {
+        super( message );
+        // TODO Auto-generated constructor stub
+    }
+
+    /**
+     * @param cause
+     */
+    public ConflictException( Throwable cause )
+    {
+        super( cause );
+        // TODO Auto-generated constructor stub
+    }
+
+    /**
+     * @param message
+     * @param cause
+     */
+    public ConflictException( String message, Throwable cause )
+    {
+        super( message, cause );
+        // TODO Auto-generated constructor stub
+    }
+
+}

Propchange: maven/mercury/trunk/mercury-core/src/main/java/org/apache/maven/mercury/artifact/ConflictException.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: maven/mercury/trunk/mercury-core/src/main/java/org/apache/maven/mercury/artifact/ConflictException.java
------------------------------------------------------------------------------
    svn:keywords = Author Date Id Revision

Added: maven/mercury/trunk/mercury-core/src/main/java/org/apache/maven/mercury/artifact/DefaultArtifact.java
URL: http://svn.apache.org/viewvc/maven/mercury/trunk/mercury-core/src/main/java/org/apache/maven/mercury/artifact/DefaultArtifact.java?rev=767705&view=auto
==============================================================================
--- maven/mercury/trunk/mercury-core/src/main/java/org/apache/maven/mercury/artifact/DefaultArtifact.java (added)
+++ maven/mercury/trunk/mercury-core/src/main/java/org/apache/maven/mercury/artifact/DefaultArtifact.java Wed Apr 22 22:56:48 2009
@@ -0,0 +1,355 @@
+package org.apache.maven.mercury.artifact;
+
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more contributor license
+ * agreements. See the NOTICE file distributed with this work for additional information regarding
+ * copyright ownership. The ASF licenses this file to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance with the License. You may obtain a
+ * copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software distributed under the License
+ * is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express
+ * or implied. See the License for the specific language governing permissions and limitations under
+ * the License.
+ */
+
+import java.io.File;
+import java.io.InputStream;
+
+/**
+ * @author Jason van Zyl
+ * @version $Id$
+ */
+public class DefaultArtifact
+    extends ArtifactMetadata
+    implements Artifact
+{
+    private File file;
+
+    private InputStream stream;
+
+    private String downloadUrl;
+
+    private String inheritedScope;
+
+    private byte[] pomBlob;
+    
+    /** 
+     * for temporary holding the reference
+     *  to the pom file during data transfer
+     */
+    transient private File pomFile;
+
+    public DefaultArtifact( ArtifactMetadata bmd )
+    {
+        if ( bmd.getVersion() == null )
+        {
+            throw new IllegalArgumentException( "Version cannot be null." );
+        }
+
+        initialize( bmd.getGroupId(), bmd.getArtifactId(), bmd.getVersion(), bmd.getType(), bmd.getClassifier(),
+                    bmd.isOptional(), bmd.getScope(), bmd.getScope() );
+    }
+
+    public String getInheritedScope()
+    {
+        return inheritedScope;
+    }
+
+    private void initialize( String groupId, String artifactId, String version, String type, String classifier,
+                             boolean optional, String scope, String inheritedScope )
+    {
+        this.inheritedScope = inheritedScope;
+        this.groupId = groupId;
+        this.artifactId = artifactId;
+        setVersion( version );
+        // this.scope = scope;
+        this.type = type;
+        this.classifier = classifier;
+        this.optional = optional;
+
+        String desiredScope = Artifact.SCOPE_RUNTIME;
+
+        boolean calc = true;
+
+        if ( inheritedScope == null )
+        {
+            desiredScope = scope;
+        }
+        else if ( Artifact.SCOPE_TEST.equals( scope ) || Artifact.SCOPE_PROVIDED.equals( scope ) )
+        {
+            desiredScope = scope;
+            // calc = false;
+        }
+        else if ( Artifact.SCOPE_COMPILE.equals( scope ) && Artifact.SCOPE_COMPILE.equals( inheritedScope ) )
+        {
+            // added to retain compile artifactScope. Remove if you want compile inherited as runtime
+            desiredScope = Artifact.SCOPE_COMPILE;
+        }
+
+        if ( calc )
+        {
+            if ( Artifact.SCOPE_TEST.equals( inheritedScope ) )
+            {
+                desiredScope = Artifact.SCOPE_TEST;
+            }
+
+            if ( Artifact.SCOPE_PROVIDED.equals( inheritedScope ) )
+            {
+                desiredScope = Artifact.SCOPE_PROVIDED;
+            }
+
+            if ( Artifact.SCOPE_SYSTEM.equals( scope ) )
+            {
+                // system scopes come through unchanged...
+                desiredScope = Artifact.SCOPE_SYSTEM;
+            }
+        }
+
+        this.scope = desiredScope;
+
+        validateIdentity();
+    }
+
+    private void validateIdentity()
+    {
+        if ( empty( groupId ) )
+        {
+            throw new IllegalArgumentException( "The groupId cannot be empty." );
+        }
+
+        if ( artifactId == null )
+        {
+            throw new IllegalArgumentException( "The artifactId cannot be empty." );
+        }
+
+        if ( type == null )
+        {
+            throw new IllegalArgumentException( "The type cannot be empty." );
+        }
+
+        if ( ( getVersion() == null ) )
+        {
+            throw new IllegalArgumentException( "The version cannot be empty." );
+        }
+    }
+
+    private boolean empty( String value )
+    {
+        return ( value == null ) || ( value.trim().length() < 1 );
+    }
+
+    public void setFile( File file )
+    {
+        this.file = file;
+    }
+
+    public File getFile()
+    {
+        return file;
+    }
+
+    public void setPomFile( File file )
+    {
+        this.pomFile = file;
+    }
+
+    public File getPomFile()
+    {
+        return pomFile;
+    }
+
+    public void setStream( InputStream stream )
+    {
+        this.stream = stream;
+    }
+
+    public InputStream getStream()
+    {
+        return stream;
+    }
+
+    // ----------------------------------------------------------------------
+    //
+    // ----------------------------------------------------------------------
+
+    public String getId()
+    {
+        return getDependencyConflictId() + ":" + getVersion();
+    }
+
+    public String getDependencyConflictId()
+    {
+        StringBuilder sb = new StringBuilder();
+        sb.append( getGroupId() );
+        sb.append( ":" );
+        appendArtifactTypeClassifierString( sb );
+        return sb.toString();
+    }
+
+    private void appendArtifactTypeClassifierString( StringBuilder sb )
+    {
+        sb.append( getArtifactId() );
+        sb.append( ":" );
+        sb.append( getType() );
+        if ( hasClassifier() )
+        {
+            sb.append( ":" );
+            sb.append( getClassifier() );
+        }
+    }
+
+    public void setPomBlob( byte[] pomBlob )
+    {
+        this.pomBlob = pomBlob;
+    }
+
+    public byte[] getPomBlob()
+    {
+        return pomBlob;
+    }
+
+    // ----------------------------------------------------------------------
+    // Object overrides
+    // ----------------------------------------------------------------------
+    @Override
+    public String toString()
+    {
+        StringBuilder sb = new StringBuilder();
+        if ( getGroupId() != null )
+        {
+            sb.append( getGroupId() );
+            sb.append( ":" );
+        }
+        appendArtifactTypeClassifierString( sb );
+        sb.append( ":" );
+
+        if ( getVersion() != null )
+        {
+            sb.append( getVersion() );
+        }
+
+        if ( scope != null )
+        {
+            sb.append( ":" );
+            sb.append( scope );
+        }
+        return sb.toString();
+    }
+
+    @Override
+    public int hashCode()
+    {
+        int result = 17;
+        result = 37 * result + groupId.hashCode();
+        result = 37 * result + artifactId.hashCode();
+        result = 37 * result + type.hashCode();
+        if ( getVersion() != null )
+        {
+            result = 37 * result + getVersion().hashCode();
+        }
+        result = 37 * result + ( classifier != null ? classifier.hashCode() : 0 );
+        return result;
+    }
+
+    @Override
+    public boolean equals( Object o )
+    {
+        if ( o == this )
+        {
+            return true;
+        }
+
+        if ( !( o instanceof Artifact ) )
+        {
+            return false;
+        }
+
+        Artifact a = (Artifact) o;
+
+        if ( !a.getGroupId().equals( groupId ) )
+        {
+            return false;
+        }
+        else if ( !a.getArtifactId().equals( artifactId ) )
+        {
+            return false;
+        }
+        else if ( !a.getVersion().equals( getVersion() ) )
+        {
+            return false;
+        }
+        else if ( !a.getType().equals( type ) )
+        {
+            return false;
+        }
+        else if ( a.getClassifier() == null ? classifier != null : !a.getClassifier().equals( classifier ) )
+        {
+            return false;
+        }
+
+        // We don't consider the version range in the comparison, just the resolved version
+
+        return true;
+    }
+
+    public int compareTo( Artifact o )
+    {
+        Artifact a = (Artifact) o;
+
+        int result = groupId.compareTo( a.getGroupId() );
+        if ( result == 0 )
+        {
+            result = artifactId.compareTo( a.getArtifactId() );
+            if ( result == 0 )
+            {
+                result = type.compareTo( a.getType() );
+                if ( result == 0 )
+                {
+                    if ( classifier == null )
+                    {
+                        if ( a.getClassifier() != null )
+                        {
+                            result = 1;
+                        }
+                    }
+                    else
+                    {
+                        if ( a.getClassifier() != null )
+                        {
+                            result = classifier.compareTo( a.getClassifier() );
+                        }
+                        else
+                        {
+                            result = -1;
+                        }
+                    }
+                    if ( result == 0 )
+                    {
+                        // We don't consider the version range in the comparison, just the resolved version
+                        result = getVersion().compareTo( a.getVersion() );
+                    }
+                }
+            }
+        }
+        return result;
+    }
+
+    public String getDownloadUrl()
+    {
+        return downloadUrl;
+    }
+
+    public void setDownloadUrl( String downloadUrl )
+    {
+        this.downloadUrl = downloadUrl;
+    }
+
+    public void setResolvedVersion( String version )
+    {
+        setVersion( version );
+        // retain baseVersion
+    }
+}

Propchange: maven/mercury/trunk/mercury-core/src/main/java/org/apache/maven/mercury/artifact/DefaultArtifact.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: maven/mercury/trunk/mercury-core/src/main/java/org/apache/maven/mercury/artifact/DefaultArtifact.java
------------------------------------------------------------------------------
    svn:keywords = Author Date Id Revision

Added: maven/mercury/trunk/mercury-core/src/main/java/org/apache/maven/mercury/artifact/Messages.properties
URL: http://svn.apache.org/viewvc/maven/mercury/trunk/mercury-core/src/main/java/org/apache/maven/mercury/artifact/Messages.properties?rev=767705&view=auto
==============================================================================
--- maven/mercury/trunk/mercury-core/src/main/java/org/apache/maven/mercury/artifact/Messages.properties (added)
+++ maven/mercury/trunk/mercury-core/src/main/java/org/apache/maven/mercury/artifact/Messages.properties Wed Apr 22 22:56:48 2009
@@ -0,0 +1,23 @@
+#
+#  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.
+#
+
+artifact.metadata.no.version=no version in this metadata: {0}
+null.copy.from.md=cannot create a copy of a null metadata
+
+quality.no.sn.no.rel=cannot decide how to create a quality range when releases=false and snapshots=false

Propchange: maven/mercury/trunk/mercury-core/src/main/java/org/apache/maven/mercury/artifact/Messages.properties
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: maven/mercury/trunk/mercury-core/src/main/java/org/apache/maven/mercury/artifact/Messages.properties
------------------------------------------------------------------------------
    svn:keywords = Author Date Id Revision

Added: maven/mercury/trunk/mercury-core/src/main/java/org/apache/maven/mercury/artifact/MetadataTreeNode.java
URL: http://svn.apache.org/viewvc/maven/mercury/trunk/mercury-core/src/main/java/org/apache/maven/mercury/artifact/MetadataTreeNode.java?rev=767705&view=auto
==============================================================================
--- maven/mercury/trunk/mercury-core/src/main/java/org/apache/maven/mercury/artifact/MetadataTreeNode.java (added)
+++ maven/mercury/trunk/mercury-core/src/main/java/org/apache/maven/mercury/artifact/MetadataTreeNode.java Wed Apr 22 22:56:48 2009
@@ -0,0 +1,399 @@
+/**
+ *  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.
+ */
+package org.apache.maven.mercury.artifact;
+
+import java.io.IOException;
+import java.io.StringWriter;
+import java.io.Writer;
+import java.util.ArrayList;
+import java.util.List;
+import java.util.TreeSet;
+
+import org.codehaus.plexus.lang.DefaultLanguage;
+import org.codehaus.plexus.lang.Language;
+
+/**
+ * metadata [dirty] Tree
+ * 
+ * @author <a href="oleg@codehaus.org">Oleg Gusakov</a>
+ */
+public class MetadataTreeNode
+{
+    /** prevailing # of queries (dependencies) in the dirty tree node */
+    private static final int DEFAULT_QUERY_COUNT = 8;
+
+    /** prevailing # of children in the dirty tree node. If all queries are ranges - 2 hits per range */
+    private static final int DEFAULT_CHILDREN_COUNT = 16;
+
+    private static final Language LANG = new DefaultLanguage( MetadataTreeNode.class );
+
+    /**
+     * this node's artifact MD
+     */
+    ArtifactMetadata md;
+
+    /**
+     * fail resolution if it could not be found?
+     */
+    boolean optional = false;
+
+    /**
+     * is there a real artifact behind this node, or it's just a helper ?
+     */
+    boolean real = true;
+
+    /**
+     * parent node
+     */
+    MetadataTreeNode parent;
+
+    /**
+     * node unique id, used to identify this node in external tree manipulations, such as
+     */
+    int id;
+
+    /**
+     * query node - the one that originated this actual node
+     */
+    ArtifactMetadata query;
+
+    /**
+     * queries - one per POM dependency
+     */
+    List<ArtifactMetadata> queries;
+
+    /**
+     * actual found versions
+     */
+    List<MetadataTreeNode> children;
+    
+    /** unique name of this node. Used in SAT solver */
+    String name;
+
+    // ------------------------------------------------------------------------
+    public int countNodes()
+    {
+        return countNodes( this );
+    }
+
+    // ------------------------------------------------------------------------
+    public static int countNodes( MetadataTreeNode node )
+    {
+        int res = 1;
+
+        if ( node.children != null && node.children.size() > 0 )
+        {
+            for ( MetadataTreeNode child : node.children )
+            {
+                res += countNodes( child );
+            }
+        }
+
+        return res;
+    }
+
+    // ------------------------------------------------------------------------
+    public int countDistinctNodes()
+    {
+        TreeSet<String> nodes = new TreeSet<String>();
+
+        getDistinctNodes( this, nodes );
+
+        return nodes.size();
+    }
+
+    // ------------------------------------------------------------------------
+    public static void getDistinctNodes( MetadataTreeNode node, TreeSet<String> nodes )
+    {
+        if ( node.getMd() == null )
+            throw new IllegalArgumentException( "tree node without metadata" );
+
+        nodes.add( node.getMd().getGAV() );
+
+        if ( node.children != null && node.children.size() > 0 )
+            for ( MetadataTreeNode child : node.children )
+                getDistinctNodes( child, nodes );
+    }
+
+    // ------------------------------------------------------------------------
+    public MetadataTreeNode()
+    {
+    }
+
+    // ------------------------------------------------------------------------
+    /**
+     * pointers to parent and query are a must.
+     */
+    public MetadataTreeNode( ArtifactMetadata md, MetadataTreeNode parent, ArtifactMetadata query )
+    {
+        if ( md != null )
+        {
+            md.setArtifactScope( ArtifactScopeEnum.checkScope( md.getArtifactScope() ) );
+        }
+
+        this.md = md;
+        this.parent = parent;
+        this.query = query;
+    }
+
+    // ------------------------------------------------------------------------
+    /**
+     * dependencies are ordered in the POM - they should be added in the POM order
+     */
+    public MetadataTreeNode addChild( MetadataTreeNode kid )
+    {
+        if ( kid == null )
+        {
+            return this;
+        }
+
+        if ( children == null )
+        {
+            children = new ArrayList<MetadataTreeNode>( DEFAULT_CHILDREN_COUNT );
+        }
+
+        kid.setParent( this );
+        children.add( kid );
+
+        return this;
+    }
+
+    // ------------------------------------------------------------------------
+    /**
+     * dependencies are ordered in the POM - they should be added in the POM order
+     */
+    public MetadataTreeNode addQuery( ArtifactMetadata query )
+    {
+        if ( query == null )
+        {
+            return this;
+        }
+
+        if ( queries == null )
+        {
+            queries = new ArrayList<ArtifactMetadata>( DEFAULT_QUERY_COUNT );
+        }
+
+        queries.add( query );
+
+        return this;
+    }
+
+    // ------------------------------------------------------------------
+    @Override
+    public String toString()
+    {
+        return md == null ? "no metadata, parent " + ( parent == null ? "null" : parent.toString() ) : md.toString()
+            + ":d=" + getDepth();
+    }
+
+    // ------------------------------------------------------------------------
+    public boolean hasChildren()
+    {
+        return children != null;
+    }
+
+    // ------------------------------------------------------------------------
+    public ArtifactMetadata getMd()
+    {
+        return md;
+    }
+
+    public MetadataTreeNode getParent()
+    {
+        return parent;
+    }
+
+    public int getDepth()
+    {
+        int depth = 0;
+
+        for ( MetadataTreeNode p = parent; p != null; p = p.parent )
+            ++depth;
+
+        return depth;
+    }
+
+    public int getMaxDepth( int depth )
+    {
+        int res = 0;
+
+        if ( !hasChildren() )
+            return depth + 1;
+
+        for ( MetadataTreeNode kid : children )
+        {
+            int kidDepth = kid.getMaxDepth( depth + 1 );
+            if ( kidDepth > res )
+                res = kidDepth;
+        }
+
+        return res;
+    }
+
+    public void setParent( MetadataTreeNode parent )
+    {
+        this.parent = parent;
+    }
+
+    public List<MetadataTreeNode> getChildren()
+    {
+        return children;
+    }
+
+    public boolean isOptional()
+    {
+        return optional;
+    }
+
+    public boolean isReal()
+    {
+        return real;
+    }
+
+    public void setReal( boolean real)
+    {
+        this.real = real;
+    }
+
+    public ArtifactMetadata getQuery()
+    {
+        return query;
+    }
+
+    public List<ArtifactMetadata> getQueries()
+    {
+        return queries;
+    }
+
+    // ------------------------------------------------------------------------
+    public static final MetadataTreeNode deepCopy( MetadataTreeNode node )
+    {
+        MetadataTreeNode res = new MetadataTreeNode( node.getMd(), node.getParent(), node.getQuery() );
+        res.setId( node.getId() );
+
+        if ( node.hasChildren() )
+            for ( MetadataTreeNode kid : node.children )
+            {
+                MetadataTreeNode deepKid = deepCopy( kid );
+                res.addChild( deepKid );
+            }
+
+        return res;
+    }
+
+    // ----------------------------------------------------------------
+    /**
+     * helper method to print the tree into a Writer
+     */
+    public static final void showNode( MetadataTreeNode n, int level, Writer wr )
+        throws IOException
+    {
+        if( n == null )
+        {
+            wr.write( "null node" );
+            return;
+        }
+        for ( int i = 0; i < level; i++ )
+            wr.write( "  " );
+
+        wr.write( level + " " + n.getMd() + "\n" );
+
+        if ( n.hasChildren() )
+        {
+            for ( MetadataTreeNode kid : n.getChildren() )
+                showNode( kid, level + 1, wr );
+        }
+    }
+
+    // ----------------------------------------------------------------
+    /**
+     * helper method to print the tree into sysout
+     */
+    public static final void showNode( MetadataTreeNode n, int level )
+        throws IOException
+    {
+        StringWriter sw = new StringWriter();
+        MetadataTreeNode.showNode( n, 0, sw );
+        System.out.println( sw.toString() );
+    }
+
+    // ------------------------------------------------------------------------
+    public int getId()
+    {
+        return id;
+    }
+
+    public void setId( int id )
+    {
+        this.id = id;
+    }
+
+    // ------------------------------------------------------------------------
+    public static void reNumber( MetadataTreeNode node, int startNum )
+    {
+        reNum( node, new Counter( startNum ) );
+    }
+
+    // ------------------------------------------------------------------------
+    private static void reNum( MetadataTreeNode node, Counter num )
+    {
+        node.setId( num.next() );
+
+        if ( node.hasChildren() )
+            for ( MetadataTreeNode kid : node.getChildren() )
+                reNum( kid, num );
+    }
+    
+    public String getName()
+    {
+        return name;
+    }
+
+    public void createNames( int level, int seq )
+    {
+        name = md.toScopedString()+":"+level+"."+seq;
+        
+        if( hasChildren() )
+        {
+            int no = 0;
+            
+            for( MetadataTreeNode kid : children )
+                kid.createNames( level+1, no++ );
+        }
+    }
+    // ------------------------------------------------------------------------
+    // ------------------------------------------------------------------------
+}
+
+// ------------------------------------------------------------------------
+class Counter
+{
+    int n;
+
+    public Counter( int n )
+    {
+        this.n = n;
+    }
+
+    int next()
+    {
+        return n++;
+    }
+}

Propchange: maven/mercury/trunk/mercury-core/src/main/java/org/apache/maven/mercury/artifact/MetadataTreeNode.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: maven/mercury/trunk/mercury-core/src/main/java/org/apache/maven/mercury/artifact/MetadataTreeNode.java
------------------------------------------------------------------------------
    svn:keywords = Author Date Id Revision

Added: maven/mercury/trunk/mercury-core/src/main/java/org/apache/maven/mercury/artifact/Quality.java
URL: http://svn.apache.org/viewvc/maven/mercury/trunk/mercury-core/src/main/java/org/apache/maven/mercury/artifact/Quality.java?rev=767705&view=auto
==============================================================================
--- maven/mercury/trunk/mercury-core/src/main/java/org/apache/maven/mercury/artifact/Quality.java (added)
+++ maven/mercury/trunk/mercury-core/src/main/java/org/apache/maven/mercury/artifact/Quality.java Wed Apr 22 22:56:48 2009
@@ -0,0 +1,201 @@
+/**
+ *  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.
+ */
+package org.apache.maven.mercury.artifact;
+
+/**
+ * @author Oleg Gusakov
+ * @version $Id$
+ */
+public class Quality
+    implements Comparable<Quality>
+{
+    public static final int DEFAULT_QUANTITY = 0;
+
+    public static final int SNAPSHOT_TS_QUANTITY = 1;
+
+    public static final int FIXED_RELEASE_QUANTITY = -2;
+
+    public static final int FIXED_LATEST_QUANTITY = -3;
+
+    public static final Quality UNKNOWN_QUALITY = new Quality( QualityEnum.unknown, -1 );
+
+    public static final Quality SNAPSHOT_QUALITY = new Quality( QualityEnum.snapshot, DEFAULT_QUANTITY );
+
+    public static final Quality SNAPSHOT_TS_QUALITY = new Quality( QualityEnum.snapshot, SNAPSHOT_TS_QUANTITY );
+
+    public static final Quality ALPHA_QUALITY = new Quality( QualityEnum.alpha, DEFAULT_QUANTITY );
+
+    public static final Quality BETA_QUALITY = new Quality( QualityEnum.beta, DEFAULT_QUANTITY );
+
+    public static final Quality RELEASE_QUALITY = new Quality( QualityEnum.release, DEFAULT_QUANTITY );
+
+    public static final Quality FIXED_RELEASE_QUALITY = new Quality( QualityEnum.unknown, FIXED_RELEASE_QUANTITY );
+
+    public static final Quality FIXED_LATEST_QUALITY = new Quality( QualityEnum.unknown, FIXED_LATEST_QUANTITY );
+
+    private static final String snExp = ".+-(SNAPSHOT|\\d{8}\\.\\d{6}-\\d+)";
+
+    private static final String alphaExp = ".+-alpha-\\d+";
+
+    private static final String betaExp = ".+-beta-\\d+";
+
+    protected QualityEnum quality;
+
+    protected int quantity;
+
+    public Quality( QualityEnum quality, int quantity )
+    {
+        this.quality = quality;
+        this.quantity = quantity;
+    }
+
+    public Quality( String version )
+    {
+        if ( version == null || version.length() < 1 )
+        {
+            quality = QualityEnum.unknown;
+            quantity = -1;
+            return;
+        }
+
+        if ( Artifact.RELEASE_VERSION.equals( version ) )
+        {
+            quality = QualityEnum.unknown;
+            quantity = FIXED_RELEASE_QUANTITY;
+            return;
+        }
+
+        if ( Artifact.LATEST_VERSION.equals( version ) )
+        {
+            quality = QualityEnum.unknown;
+            quantity = FIXED_LATEST_QUANTITY;
+            return;
+        }
+
+        if ( version.matches( snExp ) )
+        {
+            quality = QualityEnum.snapshot;
+            if ( version.endsWith( Artifact.SNAPSHOT_VERSION ) )
+            {
+                quantity = DEFAULT_QUANTITY;
+            }
+            else
+            {
+                quantity = SNAPSHOT_TS_QUANTITY;
+            }
+            return;
+        }
+
+        if ( version.matches( alphaExp ) )
+        {
+            quality = QualityEnum.alpha;
+            quantity = Integer.parseInt( version.substring( version.lastIndexOf( '-' ) + 1 ) );
+            return;
+        }
+
+        if ( version.matches( betaExp ) )
+        {
+            quality = QualityEnum.beta;
+            quantity = Integer.parseInt( version.substring( version.lastIndexOf( '-' ) + 1 ) );
+            return;
+        }
+
+        quality = QualityEnum.release;
+        quantity = DEFAULT_QUANTITY;
+
+    }
+
+    public int compareTo( Quality q )
+    {
+        if ( q == null )
+        {
+            return quality == null ? 0 : 1;
+        }
+
+        int ql = ( quality == null ? QualityEnum.unknown : quality ).getId();
+        int ql2 = ( q.quality == null ? QualityEnum.unknown : q.quality ).getId();
+
+        if ( ql == ql2 )
+        {
+            // snapshots are always equal
+            if ( ql == QualityEnum.snapshot.getId() )
+            {
+                return 0;
+            }
+            else
+            {
+                return quantity - q.quantity;
+            }
+        }
+
+        // unknown is less'n anyone
+        // if( ql1 == QualityEnum.unknown.getId() )
+        // return -1;
+
+        return sign( ql - ql2 );
+    }
+
+    private static int sign( int i )
+    {
+        return i < 0 ? -1 : 1;
+    }
+
+    @Override
+    public boolean equals( Object obj )
+    {
+        if ( obj == null )
+        {
+            return false;
+        }
+
+        if ( obj.getClass().isAssignableFrom( Quality.class ) )
+        {
+            return this.compareTo( (Quality) obj ) == 0;
+        }
+        else if ( obj.getClass().isAssignableFrom( QualityEnum.class ) )
+        {
+            return this.compareTo( (QualityEnum) obj ) == 0;
+        }
+
+        return super.equals( obj );
+    }
+
+    public int compareTo( QualityEnum qe )
+    {
+        if ( qe == null )
+        {
+            return quality == null ? 0 : 1;
+        }
+
+        int ql1 = ( quality == null ? QualityEnum.unknown : quality ).getId();
+
+        return sign( ql1 - qe.getId() );
+    }
+
+    public QualityEnum getQuality()
+    {
+        return quality;
+    }
+
+    public int getQuantity()
+    {
+        return quantity;
+    }
+
+}

Propchange: maven/mercury/trunk/mercury-core/src/main/java/org/apache/maven/mercury/artifact/Quality.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: maven/mercury/trunk/mercury-core/src/main/java/org/apache/maven/mercury/artifact/Quality.java
------------------------------------------------------------------------------
    svn:keywords = Author Date Id Revision

Added: maven/mercury/trunk/mercury-core/src/main/java/org/apache/maven/mercury/artifact/QualityEnum.java
URL: http://svn.apache.org/viewvc/maven/mercury/trunk/mercury-core/src/main/java/org/apache/maven/mercury/artifact/QualityEnum.java?rev=767705&view=auto
==============================================================================
--- maven/mercury/trunk/mercury-core/src/main/java/org/apache/maven/mercury/artifact/QualityEnum.java (added)
+++ maven/mercury/trunk/mercury-core/src/main/java/org/apache/maven/mercury/artifact/QualityEnum.java Wed Apr 22 22:56:48 2009
@@ -0,0 +1,44 @@
+/**
+ *  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.
+ */
+package org.apache.maven.mercury.artifact;
+
+/**
+ * @author Oleg Gusakov
+ * @version $Id$
+ */
+public enum QualityEnum
+{
+    unknown( -1 ), snapshot( 1 ), alpha( 2 ), beta( 3 ), release( 10 );
+
+    public static final QualityEnum DEFAULT_QUALITY = unknown;
+
+    private int id;
+
+    // Constructor
+    QualityEnum( int id )
+    {
+        this.id = id;
+    }
+
+    int getId()
+    {
+        return id;
+    }
+
+}

Propchange: maven/mercury/trunk/mercury-core/src/main/java/org/apache/maven/mercury/artifact/QualityEnum.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: maven/mercury/trunk/mercury-core/src/main/java/org/apache/maven/mercury/artifact/QualityEnum.java
------------------------------------------------------------------------------
    svn:keywords = Author Date Id Revision