archiva-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ol...@apache.org
Subject svn commit: r1403491 [1/4] - in /archiva/trunk/archiva-modules: metadata/metadata-model-maven2/ metadata/metadata-model-maven2/src/ metadata/metadata-model-maven2/src/main/ metadata/metadata-model-maven2/src/main/java/ metadata/metadata-model-maven2/sr...
Date Mon, 29 Oct 2012 20:42:14 GMT
Author: olamy
Date: Mon Oct 29 20:42:12 2012
New Revision: 1403491

URL: http://svn.apache.org/viewvc?rev=1403491&view=rev
Log:
[MRM-1704] Refactor to remove maven specific part from various repository/metadata apis

Added:
    archiva/trunk/archiva-modules/metadata/metadata-model-maven2/
    archiva/trunk/archiva-modules/metadata/metadata-model-maven2/pom.xml   (with props)
    archiva/trunk/archiva-modules/metadata/metadata-model-maven2/src/
    archiva/trunk/archiva-modules/metadata/metadata-model-maven2/src/main/
    archiva/trunk/archiva-modules/metadata/metadata-model-maven2/src/main/java/
    archiva/trunk/archiva-modules/metadata/metadata-model-maven2/src/main/java/org/
    archiva/trunk/archiva-modules/metadata/metadata-model-maven2/src/main/java/org/apache/
    archiva/trunk/archiva-modules/metadata/metadata-model-maven2/src/main/java/org/apache/archiva/
    archiva/trunk/archiva-modules/metadata/metadata-model-maven2/src/main/java/org/apache/archiva/metadata/
    archiva/trunk/archiva-modules/metadata/metadata-model-maven2/src/main/java/org/apache/archiva/metadata/model/
    archiva/trunk/archiva-modules/metadata/metadata-model-maven2/src/main/java/org/apache/archiva/metadata/model/maven2/
    archiva/trunk/archiva-modules/metadata/metadata-model-maven2/src/main/java/org/apache/archiva/metadata/model/maven2/MavenArtifactFacet.java   (with props)
    archiva/trunk/archiva-modules/plugins/maven2-repository/src/main/java/org/apache/archiva/repository/
    archiva/trunk/archiva-modules/plugins/maven2-repository/src/main/java/org/apache/archiva/repository/content/
    archiva/trunk/archiva-modules/plugins/maven2-repository/src/main/java/org/apache/archiva/repository/content/legacy/
    archiva/trunk/archiva-modules/plugins/maven2-repository/src/main/java/org/apache/archiva/repository/content/legacy/AbstractLegacyRepositoryContent.java   (with props)
    archiva/trunk/archiva-modules/plugins/maven2-repository/src/main/java/org/apache/archiva/repository/content/legacy/LegacyPathParser.java   (with props)
    archiva/trunk/archiva-modules/plugins/maven2-repository/src/main/java/org/apache/archiva/repository/content/legacy/ManagedLegacyRepositoryContent.java   (with props)
    archiva/trunk/archiva-modules/plugins/maven2-repository/src/main/java/org/apache/archiva/repository/content/legacy/RemoteLegacyRepositoryContent.java   (with props)
    archiva/trunk/archiva-modules/plugins/maven2-repository/src/main/java/org/apache/archiva/repository/content/maven2/
    archiva/trunk/archiva-modules/plugins/maven2-repository/src/main/java/org/apache/archiva/repository/content/maven2/AbstractDefaultRepositoryContent.java   (with props)
    archiva/trunk/archiva-modules/plugins/maven2-repository/src/main/java/org/apache/archiva/repository/content/maven2/ArtifactExtensionMapping.java   (with props)
    archiva/trunk/archiva-modules/plugins/maven2-repository/src/main/java/org/apache/archiva/repository/content/maven2/DefaultPathParser.java   (with props)
    archiva/trunk/archiva-modules/plugins/maven2-repository/src/main/java/org/apache/archiva/repository/content/maven2/FilenameParser.java   (with props)
    archiva/trunk/archiva-modules/plugins/maven2-repository/src/main/java/org/apache/archiva/repository/content/maven2/ManagedDefaultRepositoryContent.java   (with props)
    archiva/trunk/archiva-modules/plugins/maven2-repository/src/main/java/org/apache/archiva/repository/content/maven2/RemoteDefaultRepositoryContent.java   (with props)
    archiva/trunk/archiva-modules/plugins/maven2-repository/src/main/java/org/apache/archiva/repository/content/maven2/RepositoryRequest.java   (with props)
    archiva/trunk/archiva-modules/plugins/maven2-repository/src/test/java/org/apache/archiva/metadata/repository/storage/maven2/AbstractDefaultRepositoryContentTestCase.java   (with props)
    archiva/trunk/archiva-modules/plugins/maven2-repository/src/test/java/org/apache/archiva/metadata/repository/storage/maven2/AbstractLegacyRepositoryContentTestCase.java   (with props)
    archiva/trunk/archiva-modules/plugins/maven2-repository/src/test/java/org/apache/archiva/metadata/repository/storage/maven2/AbstractRepositoryLayerTestCase.java   (with props)
    archiva/trunk/archiva-modules/plugins/maven2-repository/src/test/java/org/apache/archiva/metadata/repository/storage/maven2/ManagedDefaultRepositoryContentTest.java   (with props)
    archiva/trunk/archiva-modules/plugins/maven2-repository/src/test/java/org/apache/archiva/metadata/repository/storage/maven2/ManagedLegacyRepositoryContentTest.java   (with props)
    archiva/trunk/archiva-modules/plugins/maven2-repository/src/test/java/org/apache/archiva/metadata/repository/storage/maven2/RemoteDefaultRepositoryContentTest.java   (with props)
    archiva/trunk/archiva-modules/plugins/maven2-repository/src/test/java/org/apache/archiva/metadata/repository/storage/maven2/RemoteLegacyRepositoryContentTest.java   (with props)
    archiva/trunk/archiva-modules/plugins/maven2-repository/src/test/java/org/apache/archiva/repository/
    archiva/trunk/archiva-modules/plugins/maven2-repository/src/test/java/org/apache/archiva/repository/content/
    archiva/trunk/archiva-modules/plugins/maven2-repository/src/test/java/org/apache/archiva/repository/content/legacy/
    archiva/trunk/archiva-modules/plugins/maven2-repository/src/test/java/org/apache/archiva/repository/content/legacy/LegacyPathParserTest.java   (with props)
    archiva/trunk/archiva-modules/plugins/maven2-repository/src/test/java/org/apache/archiva/repository/content/maven2/
    archiva/trunk/archiva-modules/plugins/maven2-repository/src/test/java/org/apache/archiva/repository/content/maven2/ArtifactExtensionMappingTest.java   (with props)
    archiva/trunk/archiva-modules/plugins/maven2-repository/src/test/java/org/apache/archiva/repository/content/maven2/DefaultPathParserTest.java   (with props)
    archiva/trunk/archiva-modules/plugins/maven2-repository/src/test/java/org/apache/archiva/repository/content/maven2/FilenameParserTest.java   (with props)
    archiva/trunk/archiva-modules/plugins/maven2-repository/src/test/java/org/apache/archiva/repository/content/maven2/RepositoryRequestTest.java   (with props)

Added: archiva/trunk/archiva-modules/metadata/metadata-model-maven2/pom.xml
URL: http://svn.apache.org/viewvc/archiva/trunk/archiva-modules/metadata/metadata-model-maven2/pom.xml?rev=1403491&view=auto
==============================================================================
--- archiva/trunk/archiva-modules/metadata/metadata-model-maven2/pom.xml (added)
+++ archiva/trunk/archiva-modules/metadata/metadata-model-maven2/pom.xml Mon Oct 29 20:42:12 2012
@@ -0,0 +1,63 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+  ~ Licensed to the Apache Software Foundation (ASF) under one
+  ~ or more contributor license agreements.  See the NOTICE file
+  ~ distributed with this work for additional information
+  ~ regarding copyright ownership.  The ASF licenses this file
+  ~ to you under the Apache License, Version 2.0 (the
+  ~ "License"); you may not use this file except in compliance
+  ~ with the License.  You may obtain a copy of the License at
+  ~
+  ~  http://www.apache.org/licenses/LICENSE-2.0
+  ~
+  ~ Unless required by applicable law or agreed to in writing,
+  ~ software distributed under the License is distributed on an
+  ~ "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+  ~ KIND, either express or implied.  See the License for the
+  ~ specific language governing permissions and limitations
+  ~ under the License.
+  -->
+<project xmlns="http://maven.apache.org/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">
+  <modelVersion>4.0.0</modelVersion>
+  <parent>
+    <artifactId>metadata</artifactId>
+    <groupId>org.apache.archiva</groupId>
+    <version>1.4-M4-SNAPSHOT</version>
+  </parent>
+  <artifactId>metadata-model-maven2</artifactId>
+  <packaging>bundle</packaging>
+  <name>Archiva Metadata :: Maven 2 Model</name>
+
+  <dependencies>
+    <dependency>
+      <groupId>org.apache.archiva</groupId>
+      <artifactId>metadata-model</artifactId>
+    </dependency>
+    <dependency>
+      <groupId>commons-lang</groupId>
+      <artifactId>commons-lang</artifactId>
+    </dependency>
+  </dependencies>
+
+  <build>
+    <plugins>
+      <plugin>
+        <groupId>org.apache.felix</groupId>
+        <artifactId>maven-bundle-plugin</artifactId>
+        <configuration>
+          <instructions>
+            <Bundle-SymbolicName>org.apache.archiva.metadata.model</Bundle-SymbolicName>
+            <Bundle-Version>${project.version}</Bundle-Version>
+            <Export-Package>
+              org.apache.archiva.metadata.model;version=${project.version};-split-package:=merge-first
+            </Export-Package>
+            <Import-Package>
+              javax.xml.bind.annotation,
+              org.apache.commons.lang
+            </Import-Package>
+          </instructions>
+        </configuration>
+      </plugin>
+    </plugins>
+  </build>
+</project>

Propchange: archiva/trunk/archiva-modules/metadata/metadata-model-maven2/pom.xml
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: archiva/trunk/archiva-modules/metadata/metadata-model-maven2/pom.xml
------------------------------------------------------------------------------
    svn:keywords = Author Date Id Revision

Added: archiva/trunk/archiva-modules/metadata/metadata-model-maven2/src/main/java/org/apache/archiva/metadata/model/maven2/MavenArtifactFacet.java
URL: http://svn.apache.org/viewvc/archiva/trunk/archiva-modules/metadata/metadata-model-maven2/src/main/java/org/apache/archiva/metadata/model/maven2/MavenArtifactFacet.java?rev=1403491&view=auto
==============================================================================
--- archiva/trunk/archiva-modules/metadata/metadata-model-maven2/src/main/java/org/apache/archiva/metadata/model/maven2/MavenArtifactFacet.java (added)
+++ archiva/trunk/archiva-modules/metadata/metadata-model-maven2/src/main/java/org/apache/archiva/metadata/model/maven2/MavenArtifactFacet.java Mon Oct 29 20:42:12 2012
@@ -0,0 +1,140 @@
+package org.apache.archiva.metadata.model.maven2;
+
+/*
+ * 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.apache.archiva.metadata.model.MetadataFacet;
+import org.apache.commons.lang.StringUtils;
+
+import java.util.HashMap;
+import java.util.Map;
+
+public class MavenArtifactFacet
+    implements MetadataFacet
+{
+    private String classifier;
+
+    private String type;
+
+    private String timestamp;
+
+    private int buildNumber;
+
+    public static final String FACET_ID = "org.apache.archiva.metadata.repository.storage.maven2.artifact";
+
+    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;
+    }
+
+    public String getTimestamp()
+    {
+        return timestamp;
+    }
+
+    public void setTimestamp( String timestamp )
+    {
+        this.timestamp = timestamp;
+    }
+
+    public int getBuildNumber()
+    {
+        return buildNumber;
+    }
+
+    public void setBuildNumber( int buildNumber )
+    {
+        this.buildNumber = buildNumber;
+    }
+
+    public String getFacetId()
+    {
+        return FACET_ID;
+    }
+
+    public String getName()
+    {
+        // TODO: not needed, perhaps artifact/version metadata facet should be separate interface?
+        return null;
+    }
+
+    public Map<String, String> toProperties()
+    {
+        Map<String, String> properties = new HashMap<String, String>();
+        properties.put( "type", type );
+        if ( classifier != null )
+        {
+            properties.put( "classifier", classifier );
+        }
+        if ( timestamp != null )
+        {
+            properties.put( "timestamp", timestamp );
+        }
+        if ( buildNumber > 0 )
+        {
+            properties.put( "buildNumber", Integer.toString( buildNumber ) );
+        }
+        return properties;
+    }
+
+    public void fromProperties( Map<String, String> properties )
+    {
+        type = properties.get( "type" );
+        classifier = properties.get( "classifier" );
+        timestamp = properties.get( "timestamp" );
+        String buildNumber = properties.get( "buildNumber" );
+        if ( buildNumber != null )
+        {
+            this.buildNumber = Integer.parseInt( buildNumber );
+        }
+    }
+
+    @Override
+    public boolean equals( Object o )
+    {
+        if ( this == o )
+        {
+            return true;
+        }
+        if ( !( o instanceof MavenArtifactFacet ) )
+        {
+            return false;
+        }
+
+        MavenArtifactFacet that = (MavenArtifactFacet) o;
+
+        return StringUtils.equals( that.getClassifier(), this.classifier );
+    }
+
+}

Propchange: archiva/trunk/archiva-modules/metadata/metadata-model-maven2/src/main/java/org/apache/archiva/metadata/model/maven2/MavenArtifactFacet.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: archiva/trunk/archiva-modules/metadata/metadata-model-maven2/src/main/java/org/apache/archiva/metadata/model/maven2/MavenArtifactFacet.java
------------------------------------------------------------------------------
    svn:keywords = Author Date Id Revision

Added: archiva/trunk/archiva-modules/plugins/maven2-repository/src/main/java/org/apache/archiva/repository/content/legacy/AbstractLegacyRepositoryContent.java
URL: http://svn.apache.org/viewvc/archiva/trunk/archiva-modules/plugins/maven2-repository/src/main/java/org/apache/archiva/repository/content/legacy/AbstractLegacyRepositoryContent.java?rev=1403491&view=auto
==============================================================================
--- archiva/trunk/archiva-modules/plugins/maven2-repository/src/main/java/org/apache/archiva/repository/content/legacy/AbstractLegacyRepositoryContent.java (added)
+++ archiva/trunk/archiva-modules/plugins/maven2-repository/src/main/java/org/apache/archiva/repository/content/legacy/AbstractLegacyRepositoryContent.java Mon Oct 29 20:42:12 2012
@@ -0,0 +1,129 @@
+package org.apache.archiva.repository.content.legacy;
+
+/*
+ * 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.apache.archiva.model.ArchivaArtifact;
+import org.apache.archiva.model.ArtifactReference;
+import org.apache.archiva.repository.content.PathParser;
+import org.apache.archiva.repository.content.maven2.ArtifactExtensionMapping;
+import org.apache.archiva.repository.layout.LayoutException;
+import org.apache.commons.lang.StringUtils;
+
+import javax.inject.Inject;
+import javax.inject.Named;
+import java.util.HashMap;
+import java.util.Map;
+
+/**
+ * AbstractLegacyRepositoryContent
+ *
+ *
+ */
+public abstract class AbstractLegacyRepositoryContent
+{
+    private static final String PATH_SEPARATOR = "/";
+
+    private static final Map<String, String> typeToDirectoryMap;
+
+    static
+    {
+        typeToDirectoryMap = new HashMap<String, String>();
+        typeToDirectoryMap.put( "ejb-client", "ejb" );
+        typeToDirectoryMap.put( ArtifactExtensionMapping.MAVEN_ONE_PLUGIN, "plugin" );
+        typeToDirectoryMap.put( "distribution-tgz", "distribution" );
+        typeToDirectoryMap.put( "distribution-zip", "distribution" );
+        typeToDirectoryMap.put( "javadoc", "javadoc.jar" );
+    }
+
+    /**
+     *
+     */
+    @Inject
+    @Named( value = "pathParser#legacy" )
+    private PathParser legacyPathParser;
+
+    public ArtifactReference toArtifactReference( String path )
+        throws LayoutException
+    {
+        return legacyPathParser.toArtifactReference( path );
+    }
+
+    public String toPath( ArchivaArtifact reference )
+    {
+        if ( reference == null )
+        {
+            throw new IllegalArgumentException( "Artifact reference cannot be null" );
+        }
+
+        return toPath( reference.getGroupId(), reference.getArtifactId(), reference.getVersion(),
+                       reference.getClassifier(), reference.getType() );
+    }
+
+    public String toPath( ArtifactReference reference )
+    {
+        if ( reference == null )
+        {
+            throw new IllegalArgumentException( "Artifact reference cannot be null" );
+        }
+
+        return toPath( reference.getGroupId(), reference.getArtifactId(), reference.getVersion(),
+                       reference.getClassifier(), reference.getType() );
+    }
+
+    private String toPath( String groupId, String artifactId, String version, String classifier, String type )
+    {
+        StringBuilder path = new StringBuilder();
+
+        path.append( groupId ).append( PATH_SEPARATOR );
+        path.append( getDirectory( type ) ).append( PATH_SEPARATOR );
+
+        if ( version != null )
+        {
+            path.append( artifactId ).append( '-' ).append( version );
+
+            if ( StringUtils.isNotBlank( classifier ) )
+            {
+                path.append( '-' ).append( classifier );
+            }
+
+            path.append( '.' ).append( ArtifactExtensionMapping.getExtension( type ) );
+        }
+
+        return path.toString();
+    }
+
+    private String getDirectory( String type )
+    {
+        String dirname = typeToDirectoryMap.get( type );
+
+        if ( dirname != null )
+        {
+            return dirname + "s";
+        }
+
+        // Default process.
+        return type + "s";
+    }
+
+    public void setLegacyPathParser( PathParser parser )
+    {
+        this.legacyPathParser = parser;
+    }
+}

Propchange: archiva/trunk/archiva-modules/plugins/maven2-repository/src/main/java/org/apache/archiva/repository/content/legacy/AbstractLegacyRepositoryContent.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: archiva/trunk/archiva-modules/plugins/maven2-repository/src/main/java/org/apache/archiva/repository/content/legacy/AbstractLegacyRepositoryContent.java
------------------------------------------------------------------------------
    svn:keywords = Author Date Id Revision

Added: archiva/trunk/archiva-modules/plugins/maven2-repository/src/main/java/org/apache/archiva/repository/content/legacy/LegacyPathParser.java
URL: http://svn.apache.org/viewvc/archiva/trunk/archiva-modules/plugins/maven2-repository/src/main/java/org/apache/archiva/repository/content/legacy/LegacyPathParser.java?rev=1403491&view=auto
==============================================================================
--- archiva/trunk/archiva-modules/plugins/maven2-repository/src/main/java/org/apache/archiva/repository/content/legacy/LegacyPathParser.java (added)
+++ archiva/trunk/archiva-modules/plugins/maven2-repository/src/main/java/org/apache/archiva/repository/content/legacy/LegacyPathParser.java Mon Oct 29 20:42:12 2012
@@ -0,0 +1,215 @@
+package org.apache.archiva.repository.content.legacy;
+
+/*
+ * 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.apache.archiva.configuration.ArchivaConfiguration;
+import org.apache.archiva.configuration.LegacyArtifactPath;
+import org.apache.archiva.model.ArtifactReference;
+import org.apache.archiva.repository.content.ArtifactClassifierMapping;
+import org.apache.archiva.repository.content.PathParser;
+import org.apache.archiva.repository.content.maven2.ArtifactExtensionMapping;
+import org.apache.archiva.repository.content.maven2.FilenameParser;
+import org.apache.archiva.repository.layout.LayoutException;
+import org.apache.commons.lang.StringUtils;
+
+import java.util.Collection;
+
+/**
+ * LegacyPathParser is a parser for maven 1 (legacy layout) paths to
+ * ArtifactReference.
+ *
+ *
+ */
+public class LegacyPathParser
+    implements PathParser
+{
+    private static final String INVALID_ARTIFACT_PATH = "Invalid path to Artifact: ";
+
+    protected ArchivaConfiguration configuration;
+
+    public LegacyPathParser( ArchivaConfiguration configuration )
+    {
+        this.configuration = configuration;
+    }
+
+
+    /**
+     * {@inheritDoc}
+     *
+     * @see org.apache.archiva.repository.content.PathParser#toArtifactReference(String)
+     */
+    public ArtifactReference toArtifactReference( String path )
+        throws LayoutException
+    {
+        ArtifactReference artifact = new ArtifactReference();
+
+        // First, look if a custom resolution rule has been set for this artifact
+        Collection<LegacyArtifactPath> legacy = configuration.getConfiguration().getLegacyArtifactPaths();
+        for ( LegacyArtifactPath legacyPath : legacy )
+        {
+            if ( legacyPath.match( path ) )
+            {
+                artifact.setGroupId( legacyPath.getGroupId() );
+                artifact.setArtifactId( legacyPath.getArtifactId() );
+                artifact.setClassifier( legacyPath.getClassifier() );
+                artifact.setVersion( legacyPath.getVersion() );
+                artifact.setType( legacyPath.getType() );
+                return artifact;
+            }
+        }
+
+        String normalizedPath = StringUtils.replace( path, "\\", "/" );
+
+        String pathParts[] = StringUtils.split( normalizedPath, '/' );
+
+        /* Always 3 parts. (Never more or less)
+         * 
+         *   path = "commons-lang/jars/commons-lang-2.1.jar"
+         *   path[0] = "commons-lang";          // The Group ID
+         *   path[1] = "jars";                  // The Directory Type
+         *   path[2] = "commons-lang-2.1.jar";  // The Filename.
+         */
+
+        if ( pathParts.length != 3 )
+        {
+            // Illegal Path Parts Length.
+            throw new LayoutException( INVALID_ARTIFACT_PATH
+                                           + "legacy paths should only have 3 parts [groupId]/[type]s/[artifactId]-[version].[type], found "
+                                           + pathParts.length + " instead." );
+        }
+
+        // The Group ID.
+        artifact.setGroupId( pathParts[0] );
+
+        // The Expected Type.
+        String expectedType = pathParts[1];
+
+        // Sanity Check: expectedType should end in "s".
+        if ( !expectedType.endsWith( "s" ) )
+        {
+            throw new LayoutException( INVALID_ARTIFACT_PATH
+                                           + "legacy paths should have an expected type ending in [s] in the second part of the path." );
+        }
+
+        // The Filename.
+        String filename = pathParts[2];
+
+        FilenameParser parser = new FilenameParser( filename );
+
+        artifact.setArtifactId( parser.nextNonVersion() );
+
+        // Sanity Check: does it have an artifact id?
+        if ( StringUtils.isEmpty( artifact.getArtifactId() ) )
+        {
+            // Special Case: The filename might start with a version id (like "test-arch-1.0.jar").
+            int idx = filename.indexOf( '-' );
+            if ( idx > 0 )
+            {
+                parser.reset();
+                // Take the first section regardless of content.
+                String artifactId = parser.next();
+
+                // Is there anything more that is considered not a version id?
+                String moreArtifactId = parser.nextNonVersion();
+                if ( StringUtils.isNotBlank( moreArtifactId ) )
+                {
+                    artifact.setArtifactId( artifactId + "-" + moreArtifactId );
+                }
+                else
+                {
+                    artifact.setArtifactId( artifactId );
+                }
+            }
+
+            // Sanity Check: still no artifact id?
+            if ( StringUtils.isEmpty( artifact.getArtifactId() ) )
+            {
+                throw new LayoutException( INVALID_ARTIFACT_PATH + "no artifact id present." );
+            }
+        }
+
+        artifact.setVersion( parser.remaining() );
+
+        // Sanity Check: does it have a version?
+        if ( StringUtils.isEmpty( artifact.getVersion() ) )
+        {
+            // Special Case: use last section of artifactId as version.
+            String artifactId = artifact.getArtifactId();
+            int idx = artifactId.lastIndexOf( '-' );
+            if ( idx > 0 )
+            {
+                artifact.setVersion( artifactId.substring( idx + 1 ) );
+                artifact.setArtifactId( artifactId.substring( 0, idx ) );
+            }
+            else
+            {
+                throw new LayoutException( INVALID_ARTIFACT_PATH + "no version found." );
+            }
+        }
+
+        String classifier = ArtifactClassifierMapping.getClassifier( expectedType );
+        if ( classifier != null )
+        {
+            String version = artifact.getVersion();
+            if ( !version.endsWith( "-" + classifier ) )
+            {
+                throw new LayoutException(
+                    INVALID_ARTIFACT_PATH + expectedType + " artifacts must use the classifier " + classifier );
+            }
+            version = version.substring( 0, version.length() - classifier.length() - 1 );
+            artifact.setVersion( version );
+            artifact.setClassifier( classifier );
+        }
+
+        String extension = parser.getExtension();
+
+        // Set Type
+        String defaultExtension = expectedType.substring( 0, expectedType.length() - 1 );
+        artifact.setType(
+            ArtifactExtensionMapping.mapExtensionAndClassifierToType( classifier, extension, defaultExtension ) );
+
+        // Sanity Check: does it have an extension?
+        if ( StringUtils.isEmpty( artifact.getType() ) )
+        {
+            throw new LayoutException( INVALID_ARTIFACT_PATH + "no extension found." );
+        }
+
+        // Special Case with Maven Plugins
+        if ( StringUtils.equals( "jar", extension ) && StringUtils.equals( "plugins", expectedType ) )
+        {
+            artifact.setType( ArtifactExtensionMapping.MAVEN_ONE_PLUGIN );
+        }
+        else
+        {
+            // Sanity Check: does extension match pathType on path?
+            String expectedExtension = ArtifactExtensionMapping.getExtension( artifact.getType() );
+
+            if ( !expectedExtension.equals( extension ) )
+            {
+                throw new LayoutException(
+                    INVALID_ARTIFACT_PATH + "mismatch on extension [" + extension + "] and layout specified type ["
+                        + artifact.getType() + "] (which maps to extension: [" + expectedExtension + "]) on path ["
+                        + path + "]" );
+            }
+        }
+
+        return artifact;
+    }
+}

Propchange: archiva/trunk/archiva-modules/plugins/maven2-repository/src/main/java/org/apache/archiva/repository/content/legacy/LegacyPathParser.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: archiva/trunk/archiva-modules/plugins/maven2-repository/src/main/java/org/apache/archiva/repository/content/legacy/LegacyPathParser.java
------------------------------------------------------------------------------
    svn:keywords = Author Date Id Revision

Added: archiva/trunk/archiva-modules/plugins/maven2-repository/src/main/java/org/apache/archiva/repository/content/legacy/ManagedLegacyRepositoryContent.java
URL: http://svn.apache.org/viewvc/archiva/trunk/archiva-modules/plugins/maven2-repository/src/main/java/org/apache/archiva/repository/content/legacy/ManagedLegacyRepositoryContent.java?rev=1403491&view=auto
==============================================================================
--- archiva/trunk/archiva-modules/plugins/maven2-repository/src/main/java/org/apache/archiva/repository/content/legacy/ManagedLegacyRepositoryContent.java (added)
+++ archiva/trunk/archiva-modules/plugins/maven2-repository/src/main/java/org/apache/archiva/repository/content/legacy/ManagedLegacyRepositoryContent.java Mon Oct 29 20:42:12 2012
@@ -0,0 +1,480 @@
+package org.apache.archiva.repository.content.legacy;
+
+/*
+ * 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.apache.archiva.admin.model.beans.ManagedRepository;
+import org.apache.archiva.common.utils.PathUtil;
+import org.apache.archiva.configuration.FileTypes;
+import org.apache.archiva.model.ArchivaArtifact;
+import org.apache.archiva.model.ArtifactReference;
+import org.apache.archiva.model.ProjectReference;
+import org.apache.archiva.model.VersionedReference;
+import org.apache.archiva.repository.ContentNotFoundException;
+import org.apache.archiva.repository.ManagedRepositoryContent;
+import org.apache.archiva.repository.RepositoryException;
+import org.apache.archiva.repository.layout.LayoutException;
+import org.apache.commons.collections.CollectionUtils;
+import org.apache.commons.lang.StringUtils;
+import org.springframework.context.annotation.Scope;
+import org.springframework.stereotype.Service;
+
+import javax.inject.Inject;
+import java.io.File;
+import java.util.HashSet;
+import java.util.Set;
+
+/**
+ * ManagedLegacyRepositoryContent
+ *
+ *
+ * @todo no need to be a component when filetypes, legacy path parser is not
+ */
+@Service( "managedRepositoryContent#legacy" )
+@Scope( "prototype" )
+public class ManagedLegacyRepositoryContent
+    extends AbstractLegacyRepositoryContent
+    implements ManagedRepositoryContent
+{
+    /**
+     *
+     */
+    @Inject
+    private FileTypes filetypes;
+
+    private ManagedRepository repository;
+
+    public void deleteVersion( VersionedReference reference )
+        throws ContentNotFoundException
+    {
+        File groupDir = new File( repository.getLocation(), reference.getGroupId() );
+
+        if ( !groupDir.exists() )
+        {
+            throw new ContentNotFoundException(
+                "Unable to get versions using a non-existant groupId directory: " + groupDir.getAbsolutePath() );
+        }
+
+        if ( !groupDir.isDirectory() )
+        {
+            throw new ContentNotFoundException(
+                "Unable to get versions using a non-directory: " + groupDir.getAbsolutePath() );
+        }
+
+        // First gather up the versions found as artifacts in the managed repository.
+        File typeDirs[] = groupDir.listFiles();
+        for ( File typeDir : typeDirs )
+        {
+            if ( !typeDir.isDirectory() )
+            {
+                // Skip it, we only care about directories.
+                continue;
+            }
+
+            if ( !typeDir.getName().endsWith( "s" ) )
+            {
+                // Skip it, we only care about directories that end in "s".
+            }
+
+            deleteVersions( typeDir, reference );
+        }
+    }
+
+    private void deleteVersions( File typeDir, VersionedReference reference )
+    {
+        File repoFiles[] = typeDir.listFiles();
+        for ( File repoFile : repoFiles )
+        {
+            if ( repoFile.isDirectory() )
+            {
+                // Skip it. it's a directory.
+                continue;
+            }
+
+            String relativePath = PathUtil.getRelative( repository.getLocation(), repoFile );
+
+            if ( filetypes.matchesArtifactPattern( relativePath ) )
+            {
+                try
+                {
+                    ArtifactReference artifact = toArtifactReference( relativePath );
+                    if ( StringUtils.equals( artifact.getArtifactId(), reference.getArtifactId() )
+                        && StringUtils.equals( artifact.getVersion(), reference.getVersion() ) )
+                    {
+                        repoFile.delete();
+                        deleteSupportFiles( repoFile );
+                    }
+                }
+                catch ( LayoutException e )
+                {
+                    /* don't fail the process if there is a bad artifact within the directory. */
+                }
+            }
+        }
+    }
+
+    public void deleteProject( String namespace, String projectId )
+        throws RepositoryException
+    {
+        // TODO implements ??
+    }
+
+    private void deleteSupportFiles( File repoFile )
+    {
+        deleteSupportFile( repoFile, ".sha1" );
+        deleteSupportFile( repoFile, ".md5" );
+        deleteSupportFile( repoFile, ".asc" );
+        deleteSupportFile( repoFile, ".gpg" );
+    }
+
+    private void deleteSupportFile( File repoFile, String supportExtension )
+    {
+        File supportFile = new File( repoFile.getAbsolutePath() + supportExtension );
+        if ( supportFile.exists() && supportFile.isFile() )
+        {
+            supportFile.delete();
+        }
+    }
+
+    public String getId()
+    {
+        return repository.getId();
+    }
+
+    public Set<ArtifactReference> getRelatedArtifacts( ArtifactReference reference )
+        throws ContentNotFoundException
+    {
+        File artifactFile = toFile( reference );
+        File repoDir = artifactFile.getParentFile();
+
+        if ( !repoDir.exists() )
+        {
+            throw new ContentNotFoundException(
+                "Unable to get related artifacts using a non-existant directory: " + repoDir.getAbsolutePath() );
+        }
+
+        if ( !repoDir.isDirectory() )
+        {
+            throw new ContentNotFoundException(
+                "Unable to get related artifacts using a non-directory: " + repoDir.getAbsolutePath() );
+        }
+
+        Set<ArtifactReference> foundArtifacts = new HashSet<ArtifactReference>();
+
+        // First gather up the versions found as artifacts in the managed repository.
+        File projectParentDir = repoDir.getParentFile();
+        File typeDirs[] = projectParentDir.listFiles();
+        for ( File typeDir : typeDirs )
+        {
+            if ( !typeDir.isDirectory() )
+            {
+                // Skip it, we only care about directories.
+                continue;
+            }
+
+            if ( !typeDir.getName().endsWith( "s" ) )
+            {
+                // Skip it, we only care about directories that end in "s".
+            }
+
+            getRelatedArtifacts( typeDir, reference, foundArtifacts );
+        }
+
+        return foundArtifacts;
+    }
+
+    public String getRepoRoot()
+    {
+        return repository.getLocation();
+    }
+
+    public ManagedRepository getRepository()
+    {
+        return repository;
+    }
+
+    public Set<String> getVersions( ProjectReference reference )
+        throws ContentNotFoundException
+    {
+        File groupDir = new File( repository.getLocation(), reference.getGroupId() );
+
+        if ( !groupDir.exists() )
+        {
+            throw new ContentNotFoundException(
+                "Unable to get versions using a non-existant groupId directory: " + groupDir.getAbsolutePath() );
+        }
+
+        if ( !groupDir.isDirectory() )
+        {
+            throw new ContentNotFoundException(
+                "Unable to get versions using a non-directory: " + groupDir.getAbsolutePath() );
+        }
+
+        Set<String> foundVersions = new HashSet<String>();
+
+        // First gather up the versions found as artifacts in the managed repository.
+        File typeDirs[] = groupDir.listFiles();
+        for ( File typeDir : typeDirs )
+        {
+            if ( !typeDir.isDirectory() )
+            {
+                // Skip it, we only care about directories.
+                continue;
+            }
+
+            if ( !typeDir.getName().endsWith( "s" ) )
+            {
+                // Skip it, we only care about directories that end in "s".
+            }
+
+            getProjectVersions( typeDir, reference, foundVersions );
+        }
+
+        return foundVersions;
+    }
+
+    public Set<String> getVersions( VersionedReference reference )
+        throws ContentNotFoundException
+    {
+        File groupDir = new File( repository.getLocation(), reference.getGroupId() );
+
+        if ( !groupDir.exists() )
+        {
+            throw new ContentNotFoundException(
+                "Unable to get versions using a non-existant groupId directory: " + groupDir.getAbsolutePath() );
+        }
+
+        if ( !groupDir.isDirectory() )
+        {
+            throw new ContentNotFoundException(
+                "Unable to get versions using a non-directory: " + groupDir.getAbsolutePath() );
+        }
+
+        Set<String> foundVersions = new HashSet<String>();
+
+        // First gather up the versions found as artifacts in the managed repository.
+        File typeDirs[] = groupDir.listFiles();
+        for ( File typeDir : typeDirs )
+        {
+            if ( !typeDir.isDirectory() )
+            {
+                // Skip it, we only care about directories.
+                continue;
+            }
+
+            if ( !typeDir.getName().endsWith( "s" ) )
+            {
+                // Skip it, we only care about directories that end in "s".
+            }
+
+            getVersionedVersions( typeDir, reference, foundVersions );
+        }
+
+        return foundVersions;
+    }
+
+    public boolean hasContent( ArtifactReference reference )
+    {
+        File artifactFile = toFile( reference );
+        return artifactFile.exists() && artifactFile.isFile();
+    }
+
+    public boolean hasContent( ProjectReference reference )
+    {
+        try
+        {
+            Set<String> versions = getVersions( reference );
+            return CollectionUtils.isNotEmpty( versions );
+        }
+        catch ( ContentNotFoundException e )
+        {
+            return false;
+        }
+    }
+
+    public boolean hasContent( VersionedReference reference )
+    {
+        try
+        {
+            Set<String> versions = getVersions( reference );
+            return CollectionUtils.isNotEmpty( versions );
+        }
+        catch ( ContentNotFoundException e )
+        {
+            return false;
+        }
+    }
+
+    public void setRepository( ManagedRepository repository )
+    {
+        this.repository = repository;
+    }
+
+    /**
+     * Convert a path to an artifact reference.
+     *
+     * @param path the path to convert. (relative or full location path)
+     * @throws org.apache.archiva.repository.layout.LayoutException if the path cannot be converted to an artifact reference.
+     */
+    @Override
+    public ArtifactReference toArtifactReference( String path )
+        throws LayoutException
+    {
+        if ( ( path != null ) && path.startsWith( repository.getLocation() ) )
+        {
+            return super.toArtifactReference( path.substring( repository.getLocation().length() ) );
+        }
+
+        return super.toArtifactReference( path );
+    }
+
+    public File toFile( ArchivaArtifact reference )
+    {
+        return new File( repository.getLocation(), toPath( reference ) );
+    }
+
+    public File toFile( ArtifactReference reference )
+    {
+        return new File( repository.getLocation(), toPath( reference ) );
+    }
+
+    public String toMetadataPath( ProjectReference reference )
+    {
+        // No metadata present in legacy repository.
+        return null;
+    }
+
+    public String toMetadataPath( VersionedReference reference )
+    {
+        // No metadata present in legacy repository.
+        return null;
+    }
+
+    private void getProjectVersions( File typeDir, ProjectReference reference, Set<String> foundVersions )
+    {
+        File repoFiles[] = typeDir.listFiles();
+        for ( File repoFile : repoFiles )
+        {
+            if ( repoFile.isDirectory() )
+            {
+                // Skip it. it's a directory.
+                continue;
+            }
+
+            String relativePath = PathUtil.getRelative( repository.getLocation(), repoFile );
+
+            if ( filetypes.matchesArtifactPattern( relativePath ) )
+            {
+                try
+                {
+                    ArtifactReference artifact = toArtifactReference( relativePath );
+                    if ( StringUtils.equals( artifact.getArtifactId(), reference.getArtifactId() ) )
+                    {
+                        foundVersions.add( artifact.getVersion() );
+                    }
+                }
+                catch ( LayoutException e )
+                {
+                    /* don't fail the process if there is a bad artifact within the directory. */
+                }
+            }
+        }
+    }
+
+    private void getRelatedArtifacts( File typeDir, ArtifactReference reference, Set<ArtifactReference> foundArtifacts )
+    {
+        File repoFiles[] = typeDir.listFiles();
+        for ( int i = 0; i < repoFiles.length; i++ )
+        {
+            if ( repoFiles[i].isDirectory() )
+            {
+                // Skip it. it's a directory.
+                continue;
+            }
+
+            String relativePath = PathUtil.getRelative( repository.getLocation(), repoFiles[i] );
+
+            if ( filetypes.matchesArtifactPattern( relativePath ) )
+            {
+                try
+                {
+                    ArtifactReference artifact = toArtifactReference( relativePath );
+                    if ( StringUtils.equals( artifact.getArtifactId(), reference.getArtifactId() )
+                        && artifact.getVersion().startsWith( reference.getVersion() ) )
+                    {
+                        foundArtifacts.add( artifact );
+                    }
+                }
+                catch ( LayoutException e )
+                {
+                    /* don't fail the process if there is a bad artifact within the directory. */
+                }
+            }
+        }
+    }
+
+    private void getVersionedVersions( File typeDir, VersionedReference reference, Set<String> foundVersions )
+    {
+        File repoFiles[] = typeDir.listFiles();
+        for ( int i = 0; i < repoFiles.length; i++ )
+        {
+            if ( repoFiles[i].isDirectory() )
+            {
+                // Skip it. it's a directory.
+                continue;
+            }
+
+            String relativePath = PathUtil.getRelative( repository.getLocation(), repoFiles[i] );
+
+            if ( filetypes.matchesArtifactPattern( relativePath ) )
+            {
+                try
+                {
+                    ArtifactReference artifact = toArtifactReference( relativePath );
+                    if ( StringUtils.equals( artifact.getArtifactId(), reference.getArtifactId() )
+                        && artifact.getVersion().startsWith( reference.getVersion() ) )
+                    {
+                        foundVersions.add( artifact.getVersion() );
+                    }
+                }
+                catch ( LayoutException e )
+                {
+                    /* don't fail the process if there is a bad artifact within the directory. */
+                }
+            }
+        }
+    }
+
+    public void setFileTypes( FileTypes fileTypes )
+    {
+        this.filetypes = fileTypes;
+    }
+
+    public void deleteArtifact( ArtifactReference artifactReference )
+        throws ContentNotFoundException
+    {
+        // TODO implements for legacy ??
+    }
+
+    public void deleteGroupId( String groupId )
+        throws ContentNotFoundException
+    {
+        // TODO implements for legacy ??
+    }
+}

Propchange: archiva/trunk/archiva-modules/plugins/maven2-repository/src/main/java/org/apache/archiva/repository/content/legacy/ManagedLegacyRepositoryContent.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: archiva/trunk/archiva-modules/plugins/maven2-repository/src/main/java/org/apache/archiva/repository/content/legacy/ManagedLegacyRepositoryContent.java
------------------------------------------------------------------------------
    svn:keywords = Author Date Id Revision

Added: archiva/trunk/archiva-modules/plugins/maven2-repository/src/main/java/org/apache/archiva/repository/content/legacy/RemoteLegacyRepositoryContent.java
URL: http://svn.apache.org/viewvc/archiva/trunk/archiva-modules/plugins/maven2-repository/src/main/java/org/apache/archiva/repository/content/legacy/RemoteLegacyRepositoryContent.java?rev=1403491&view=auto
==============================================================================
--- archiva/trunk/archiva-modules/plugins/maven2-repository/src/main/java/org/apache/archiva/repository/content/legacy/RemoteLegacyRepositoryContent.java (added)
+++ archiva/trunk/archiva-modules/plugins/maven2-repository/src/main/java/org/apache/archiva/repository/content/legacy/RemoteLegacyRepositoryContent.java Mon Oct 29 20:42:12 2012
@@ -0,0 +1,88 @@
+package org.apache.archiva.repository.content.legacy;
+
+/*
+ * 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.apache.archiva.admin.model.beans.RemoteRepository;
+import org.apache.archiva.model.ArtifactReference;
+import org.apache.archiva.model.RepositoryURL;
+import org.apache.archiva.repository.RemoteRepositoryContent;
+import org.apache.archiva.repository.content.legacy.AbstractLegacyRepositoryContent;
+import org.apache.archiva.repository.layout.LayoutException;
+import org.springframework.context.annotation.Scope;
+import org.springframework.stereotype.Service;
+
+/**
+ * RemoteLegacyRepositoryContent
+ *
+ *
+ * @todo no need to be a component once legacy path parser is not
+ */
+@Service( "remoteRepositoryContent#legacy" )
+@Scope( "prototype" )
+public class RemoteLegacyRepositoryContent
+    extends AbstractLegacyRepositoryContent
+    implements RemoteRepositoryContent
+{
+    private RemoteRepository repository;
+
+    public String getId()
+    {
+        return repository.getId();
+    }
+
+    public RemoteRepository getRepository()
+    {
+        return repository;
+    }
+
+    public RepositoryURL getURL()
+    {
+        return new RepositoryURL( repository.getUrl() );
+    }
+
+    public void setRepository( RemoteRepository repository )
+    {
+        this.repository = repository;
+    }
+
+    /**
+     * Convert a path to an artifact reference.
+     *
+     * @param path the path to convert. (relative or full url path)
+     * @throws org.apache.archiva.repository.layout.LayoutException if the path cannot be converted to an artifact reference.
+     */
+    @Override
+    public ArtifactReference toArtifactReference( String path )
+        throws LayoutException
+    {
+        if ( path.startsWith( repository.getUrl() ) )
+        {
+            return super.toArtifactReference( path.substring( repository.getUrl().length() ) );
+        }
+
+        return super.toArtifactReference( path );
+    }
+
+    public RepositoryURL toURL( ArtifactReference reference )
+    {
+        String url = repository.getUrl() + toPath( reference );
+        return new RepositoryURL( url );
+    }
+}

Propchange: archiva/trunk/archiva-modules/plugins/maven2-repository/src/main/java/org/apache/archiva/repository/content/legacy/RemoteLegacyRepositoryContent.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: archiva/trunk/archiva-modules/plugins/maven2-repository/src/main/java/org/apache/archiva/repository/content/legacy/RemoteLegacyRepositoryContent.java
------------------------------------------------------------------------------
    svn:keywords = Author Date Id Revision

Added: archiva/trunk/archiva-modules/plugins/maven2-repository/src/main/java/org/apache/archiva/repository/content/maven2/AbstractDefaultRepositoryContent.java
URL: http://svn.apache.org/viewvc/archiva/trunk/archiva-modules/plugins/maven2-repository/src/main/java/org/apache/archiva/repository/content/maven2/AbstractDefaultRepositoryContent.java?rev=1403491&view=auto
==============================================================================
--- archiva/trunk/archiva-modules/plugins/maven2-repository/src/main/java/org/apache/archiva/repository/content/maven2/AbstractDefaultRepositoryContent.java (added)
+++ archiva/trunk/archiva-modules/plugins/maven2-repository/src/main/java/org/apache/archiva/repository/content/maven2/AbstractDefaultRepositoryContent.java Mon Oct 29 20:42:12 2012
@@ -0,0 +1,183 @@
+package org.apache.archiva.repository.content.maven2;
+
+/*
+ * 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.apache.archiva.common.utils.VersionUtil;
+import org.apache.archiva.metadata.repository.storage.RepositoryPathTranslator;
+import org.apache.archiva.metadata.repository.storage.maven2.ArtifactMappingProvider;
+import org.apache.archiva.metadata.repository.storage.maven2.Maven2RepositoryPathTranslator;
+import org.apache.archiva.model.ArchivaArtifact;
+import org.apache.archiva.model.ArtifactReference;
+import org.apache.archiva.model.ProjectReference;
+import org.apache.archiva.model.VersionedReference;
+import org.apache.archiva.repository.content.PathParser;
+import org.apache.archiva.repository.layout.LayoutException;
+import org.apache.commons.lang.StringUtils;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import javax.annotation.PostConstruct;
+import javax.inject.Inject;
+import java.util.List;
+
+/**
+ * AbstractDefaultRepositoryContent - common methods for working with default (maven 2) layout.
+ */
+public abstract class AbstractDefaultRepositoryContent
+{
+    protected Logger log = LoggerFactory.getLogger( getClass() );
+
+    public static final String MAVEN_METADATA = "maven-metadata.xml";
+
+    protected static final char PATH_SEPARATOR = '/';
+
+    protected static final char GROUP_SEPARATOR = '.';
+
+    protected static final char ARTIFACT_SEPARATOR = '-';
+
+    private RepositoryPathTranslator pathTranslator = new Maven2RepositoryPathTranslator();
+
+    private PathParser defaultPathParser = new DefaultPathParser();
+
+    /**
+     *
+     */
+    @Inject
+    protected List<? extends ArtifactMappingProvider> artifactMappingProviders;
+
+    @PostConstruct
+    protected void initialize()
+    {
+        // no op
+    }
+
+    public ArtifactReference toArtifactReference( String path )
+        throws LayoutException
+    {
+        return defaultPathParser.toArtifactReference( path );
+    }
+
+    public String toMetadataPath( ProjectReference reference )
+    {
+        StringBuilder path = new StringBuilder();
+
+        path.append( formatAsDirectory( reference.getGroupId() ) ).append( PATH_SEPARATOR );
+        path.append( reference.getArtifactId() ).append( PATH_SEPARATOR );
+        path.append( MAVEN_METADATA );
+
+        return path.toString();
+    }
+
+    public String toMetadataPath( VersionedReference reference )
+    {
+        StringBuilder path = new StringBuilder();
+
+        path.append( formatAsDirectory( reference.getGroupId() ) ).append( PATH_SEPARATOR );
+        path.append( reference.getArtifactId() ).append( PATH_SEPARATOR );
+        if ( reference.getVersion() != null )
+        {
+            // add the version only if it is present
+            path.append( VersionUtil.getBaseVersion( reference.getVersion() ) ).append( PATH_SEPARATOR );
+        }
+        path.append( MAVEN_METADATA );
+
+        return path.toString();
+    }
+
+    public String toPath( ArchivaArtifact reference )
+    {
+        if ( reference == null )
+        {
+            throw new IllegalArgumentException( "ArchivaArtifact cannot be null" );
+        }
+
+        String baseVersion = VersionUtil.getBaseVersion( reference.getVersion() );
+        return toPath( reference.getGroupId(), reference.getArtifactId(), baseVersion, reference.getVersion(),
+                       reference.getClassifier(), reference.getType() );
+    }
+
+    public String toPath( ArtifactReference reference )
+    {
+        if ( reference == null )
+        {
+            throw new IllegalArgumentException( "Artifact reference cannot be null" );
+        }
+        if ( reference.getVersion() != null )
+        {
+            String baseVersion = VersionUtil.getBaseVersion( reference.getVersion() );
+            return toPath( reference.getGroupId(), reference.getArtifactId(), baseVersion, reference.getVersion(),
+                           reference.getClassifier(), reference.getType() );
+        }
+        return toPath( reference.getGroupId(), reference.getArtifactId(), null, null,
+                       reference.getClassifier(), reference.getType() );
+    }
+
+    private String formatAsDirectory( String directory )
+    {
+        return directory.replace( GROUP_SEPARATOR, PATH_SEPARATOR );
+    }
+
+    private String toPath( String groupId, String artifactId, String baseVersion, String version, String classifier,
+                           String type )
+    {
+        if ( baseVersion != null )
+        {
+            return pathTranslator.toPath( groupId, artifactId, baseVersion,
+                                          constructId( artifactId, version, classifier, type ) );
+        }
+        else
+        {
+            return pathTranslator.toPath( groupId, artifactId );
+        }
+    }
+
+    // TODO: move into the Maven Artifact facet when refactoring away the caller - the caller will need to have access
+    //       to the facet or filename (for the original ID)
+    private String constructId( String artifactId, String version, String classifier, String type )
+    {
+        String ext = null;
+        for ( ArtifactMappingProvider provider : artifactMappingProviders )
+        {
+            ext = provider.mapTypeToExtension( type );
+            if ( ext != null )
+            {
+                break;
+            }
+        }
+        if ( ext == null )
+        {
+            ext = type;
+        }
+
+        StringBuilder id = new StringBuilder();
+        if ( ( version != null ) && ( type != null ) )
+        {
+            id.append( artifactId ).append( ARTIFACT_SEPARATOR ).append( version );
+
+            if ( StringUtils.isNotBlank( classifier ) )
+            {
+                id.append( ARTIFACT_SEPARATOR ).append( classifier );
+            }
+
+            id.append( "." ).append( ext );
+        }
+        return id.toString();
+    }
+}

Propchange: archiva/trunk/archiva-modules/plugins/maven2-repository/src/main/java/org/apache/archiva/repository/content/maven2/AbstractDefaultRepositoryContent.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: archiva/trunk/archiva-modules/plugins/maven2-repository/src/main/java/org/apache/archiva/repository/content/maven2/AbstractDefaultRepositoryContent.java
------------------------------------------------------------------------------
    svn:keywords = Author Date Id Revision

Added: archiva/trunk/archiva-modules/plugins/maven2-repository/src/main/java/org/apache/archiva/repository/content/maven2/ArtifactExtensionMapping.java
URL: http://svn.apache.org/viewvc/archiva/trunk/archiva-modules/plugins/maven2-repository/src/main/java/org/apache/archiva/repository/content/maven2/ArtifactExtensionMapping.java?rev=1403491&view=auto
==============================================================================
--- archiva/trunk/archiva-modules/plugins/maven2-repository/src/main/java/org/apache/archiva/repository/content/maven2/ArtifactExtensionMapping.java (added)
+++ archiva/trunk/archiva-modules/plugins/maven2-repository/src/main/java/org/apache/archiva/repository/content/maven2/ArtifactExtensionMapping.java Mon Oct 29 20:42:12 2012
@@ -0,0 +1,78 @@
+package org.apache.archiva.repository.content.maven2;
+
+/*
+ * 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.apache.archiva.metadata.repository.storage.maven2.ArtifactMappingProvider;
+import org.apache.archiva.metadata.repository.storage.maven2.DefaultArtifactMappingProvider;
+
+/**
+ * ArtifactExtensionMapping
+ *
+ *
+ */
+public class ArtifactExtensionMapping
+{
+    public static final String MAVEN_ONE_PLUGIN = "maven-one-plugin";
+
+    // TODO: now only used in Maven 1, we should be using M1 specific mappings
+    private static final ArtifactMappingProvider mapping = new DefaultArtifactMappingProvider();
+
+    public static String getExtension( String type )
+    {
+        String ext = mapping.mapTypeToExtension( type );
+
+        if ( ext == null )
+        {
+            ext = type;
+        }
+
+        return ext;
+    }
+
+    public static String mapExtensionAndClassifierToType( String classifier, String extension )
+    {
+        return mapExtensionAndClassifierToType( classifier, extension, extension );
+    }
+
+    public static String mapExtensionAndClassifierToType( String classifier, String extension,
+                                                           String defaultExtension )
+    {
+        String value = mapping.mapClassifierAndExtensionToType( classifier, extension );
+        if ( value == null )
+        {
+            // TODO: Maven 1 plugin
+            String value1 = null;
+            if ( "tar.gz".equals( extension ) )
+            {
+                value1 = "distribution-tgz";
+            }
+            else  if ( "tar.bz2".equals( extension ) )
+            {
+                value1 = "distribution-bzip";
+            }
+            else  if ( "zip".equals( extension ) )
+            {
+                value1 = "distribution-zip";
+            }
+            value = value1;
+        }
+        return value != null ? value : defaultExtension;
+    }
+}

Propchange: archiva/trunk/archiva-modules/plugins/maven2-repository/src/main/java/org/apache/archiva/repository/content/maven2/ArtifactExtensionMapping.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: archiva/trunk/archiva-modules/plugins/maven2-repository/src/main/java/org/apache/archiva/repository/content/maven2/ArtifactExtensionMapping.java
------------------------------------------------------------------------------
    svn:keywords = Author Date Id Revision

Added: archiva/trunk/archiva-modules/plugins/maven2-repository/src/main/java/org/apache/archiva/repository/content/maven2/DefaultPathParser.java
URL: http://svn.apache.org/viewvc/archiva/trunk/archiva-modules/plugins/maven2-repository/src/main/java/org/apache/archiva/repository/content/maven2/DefaultPathParser.java?rev=1403491&view=auto
==============================================================================
--- archiva/trunk/archiva-modules/plugins/maven2-repository/src/main/java/org/apache/archiva/repository/content/maven2/DefaultPathParser.java (added)
+++ archiva/trunk/archiva-modules/plugins/maven2-repository/src/main/java/org/apache/archiva/repository/content/maven2/DefaultPathParser.java Mon Oct 29 20:42:12 2012
@@ -0,0 +1,90 @@
+package org.apache.archiva.repository.content.maven2;
+
+/*
+ * 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.apache.archiva.metadata.model.ArtifactMetadata;
+import org.apache.archiva.metadata.model.maven2.MavenArtifactFacet;
+import org.apache.archiva.metadata.repository.storage.RepositoryPathTranslator;
+import org.apache.archiva.metadata.repository.storage.maven2.ArtifactMappingProvider;
+import org.apache.archiva.metadata.repository.storage.maven2.DefaultArtifactMappingProvider;
+import org.apache.archiva.metadata.repository.storage.maven2.Maven2RepositoryPathTranslator;
+import org.apache.archiva.model.ArtifactReference;
+import org.apache.archiva.repository.content.PathParser;
+import org.apache.archiva.repository.layout.LayoutException;
+import org.apache.commons.lang.StringUtils;
+import org.springframework.stereotype.Service;
+
+import java.util.Collections;
+
+/**
+ * DefaultPathParser is a parser for maven 2 (default layout) paths to ArtifactReference.
+ *
+ * TODO: remove in favour of path translator, this is just delegating for the most part, but won't accommodate other
+ * extensions like NPanday
+ *
+ *
+ */
+@Service( "pathParser#default" )
+public class DefaultPathParser
+    implements PathParser
+{
+    private static final String INVALID_ARTIFACT_PATH = "Invalid path to Artifact: ";
+
+    private RepositoryPathTranslator pathTranslator = new Maven2RepositoryPathTranslator(
+        Collections.<ArtifactMappingProvider>singletonList( new DefaultArtifactMappingProvider() ) );
+
+    /**
+     * {@inheritDoc}
+     *
+     * @see org.apache.archiva.repository.content.PathParser#toArtifactReference(String)
+     */
+    public ArtifactReference toArtifactReference( String path )
+        throws LayoutException
+    {
+        if ( StringUtils.isBlank( path ) )
+        {
+            throw new LayoutException( "Unable to convert blank path." );
+        }
+
+        ArtifactMetadata metadata;
+        try
+        {
+            metadata = pathTranslator.getArtifactForPath( null, path );
+        }
+        catch ( IllegalArgumentException e )
+        {
+            throw new LayoutException( e.getMessage(), e );
+        }
+
+        ArtifactReference artifact = new ArtifactReference();
+        artifact.setGroupId( metadata.getNamespace() );
+        artifact.setArtifactId( metadata.getProject() );
+        artifact.setVersion( metadata.getVersion() );
+        MavenArtifactFacet facet = (MavenArtifactFacet) metadata.getFacet( MavenArtifactFacet.FACET_ID );
+        if ( facet != null )
+        {
+            artifact.setClassifier( facet.getClassifier() );
+            artifact.setType( facet.getType() );
+        }
+
+        return artifact;
+    }
+
+}

Propchange: archiva/trunk/archiva-modules/plugins/maven2-repository/src/main/java/org/apache/archiva/repository/content/maven2/DefaultPathParser.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: archiva/trunk/archiva-modules/plugins/maven2-repository/src/main/java/org/apache/archiva/repository/content/maven2/DefaultPathParser.java
------------------------------------------------------------------------------
    svn:keywords = Author Date Id Revision

Added: archiva/trunk/archiva-modules/plugins/maven2-repository/src/main/java/org/apache/archiva/repository/content/maven2/FilenameParser.java
URL: http://svn.apache.org/viewvc/archiva/trunk/archiva-modules/plugins/maven2-repository/src/main/java/org/apache/archiva/repository/content/maven2/FilenameParser.java?rev=1403491&view=auto
==============================================================================
--- archiva/trunk/archiva-modules/plugins/maven2-repository/src/main/java/org/apache/archiva/repository/content/maven2/FilenameParser.java (added)
+++ archiva/trunk/archiva-modules/plugins/maven2-repository/src/main/java/org/apache/archiva/repository/content/maven2/FilenameParser.java Mon Oct 29 20:42:12 2012
@@ -0,0 +1,259 @@
+package org.apache.archiva.repository.content.maven2;
+
+/*
+ * 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.apache.archiva.common.utils.VersionUtil;
+
+import java.util.regex.Matcher;
+import java.util.regex.Pattern;
+
+/**
+ * Generic Filename Parser for use with layout routines.
+ *
+ *
+ */
+public class FilenameParser
+{
+    private String name;
+
+    private String extension;
+
+    private int offset;
+
+    private static final Pattern mavenPluginPattern = Pattern.compile( "(maven-.*-plugin)|(.*-maven-plugin)" );
+
+    private static final Pattern extensionPattern =
+        Pattern.compile( "(\\.tar\\.gz$)|(\\.tar\\.bz2$)|(\\.[\\-a-z0-9]*$)", Pattern.CASE_INSENSITIVE );
+
+    private static final Pattern SNAPSHOT_PATTERN = Pattern.compile( "^([0-9]{8}\\.[0-9]{6}-[0-9]+)(.*)$" );
+
+    private static final Pattern section = Pattern.compile( "([^-]*)" );
+
+    private Matcher matcher;
+
+    public FilenameParser( String filename )
+    {
+        this.name = filename;
+
+        Matcher mat = extensionPattern.matcher( name );
+        if ( mat.find() )
+        {
+            extension = filename.substring( mat.start() + 1 );
+            name = name.substring( 0, name.length() - extension.length() - 1 );
+        }
+
+        matcher = section.matcher( name );
+
+        reset();
+    }
+
+    public void reset()
+    {
+        offset = 0;
+    }
+
+    public String next()
+    {
+        // Past the end of the string.
+        if ( offset > name.length() )
+        {
+            return null;
+        }
+
+        // Return the next section.
+        if ( matcher.find( offset ) )
+        {
+            // Return found section.
+            offset = matcher.end() + 1;
+            return matcher.group();
+        }
+
+        // Nothing to return.
+        return null;
+    }
+
+    protected String expect( String expected )
+    {
+        String value = null;
+
+        if ( name.startsWith( expected, offset ) )
+        {
+            value = expected;
+        }
+        else if ( VersionUtil.isGenericSnapshot( expected ) )
+        {
+            String version = name.substring( offset );
+
+            // check it starts with the same version up to the snapshot part
+            int leadingLength = expected.length() - 9;
+            if ( leadingLength > 0 && version.startsWith( expected.substring( 0, leadingLength ) ) &&
+                version.length() > leadingLength )
+            {
+                // If we expect a non-generic snapshot - look for the timestamp
+                Matcher m = SNAPSHOT_PATTERN.matcher( version.substring( leadingLength + 1 ) );
+                if ( m.matches() )
+                {
+                    value = version.substring( 0, leadingLength + 1 ) + m.group( 1 );
+                }
+            }
+        }
+
+        if ( value != null )
+        {
+            // Potential hit. check for '.' or '-' at end of expected.
+            int seperatorOffset = offset + value.length();
+
+            // Test for "out of bounds" first. 
+            if ( seperatorOffset >= name.length() )
+            {
+                offset = name.length();
+                return value;
+            }
+
+            // Test for seperator char.
+            char seperatorChar = name.charAt( seperatorOffset );
+            if ( ( seperatorChar == '-' ) || ( seperatorChar == '.' ) )
+            {
+                offset = seperatorOffset + 1;
+                return value;
+            }
+        }
+
+        return null;
+    }
+
+    /**
+     * Get the current seperator character.
+     *
+     * @return the seperator character (either '.' or '-'), or 0 if no seperator character available.
+     */
+    protected char seperator()
+    {
+        // Past the end of the string?
+        if ( offset >= name.length() )
+        {
+            return 0;
+        }
+
+        // Before the start of the string?
+        if ( offset <= 0 )
+        {
+            return 0;
+        }
+
+        return name.charAt( offset - 1 );
+    }
+
+    protected String getName()
+    {
+        return name;
+    }
+
+    public String getExtension()
+    {
+        return extension;
+    }
+
+    public String remaining()
+    {
+        if ( offset >= name.length() )
+        {
+            return null;
+        }
+
+        String end = name.substring( offset );
+        offset = name.length();
+        return end;
+    }
+
+    public String nextNonVersion()
+    {
+        boolean done = false;
+
+        StringBuilder ver = new StringBuilder();
+
+        // Any text upto the end of a special case is considered non-version. 
+        Matcher specialMat = mavenPluginPattern.matcher( name );
+        if ( specialMat.find() )
+        {
+            ver.append( name.substring( offset, specialMat.end() ) );
+            offset = specialMat.end() + 1;
+        }
+
+        while ( !done )
+        {
+            int initialOffset = offset;
+            String section = next();
+            if ( section == null )
+            {
+                done = true;
+            }
+            else if ( !VersionUtil.isVersion( section ) )
+            {
+                if ( ver.length() > 0 )
+                {
+                    ver.append( '-' );
+                }
+                ver.append( section );
+            }
+            else
+            {
+                offset = initialOffset;
+                done = true;
+            }
+        }
+
+        return ver.toString();
+    }
+
+    protected String nextVersion()
+    {
+        boolean done = false;
+
+        StringBuilder ver = new StringBuilder();
+
+        while ( !done )
+        {
+            int initialOffset = offset;
+            String section = next();
+            if ( section == null )
+            {
+                done = true;
+            }
+            else if ( VersionUtil.isVersion( section ) )
+            {
+                if ( ver.length() > 0 )
+                {
+                    ver.append( '-' );
+                }
+                ver.append( section );
+            }
+            else
+            {
+                offset = initialOffset;
+                done = true;
+            }
+        }
+
+        return ver.toString();
+    }
+
+
+}

Propchange: archiva/trunk/archiva-modules/plugins/maven2-repository/src/main/java/org/apache/archiva/repository/content/maven2/FilenameParser.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: archiva/trunk/archiva-modules/plugins/maven2-repository/src/main/java/org/apache/archiva/repository/content/maven2/FilenameParser.java
------------------------------------------------------------------------------
    svn:keywords = Author Date Id Revision



Mime
View raw message