You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@archiva.apache.org by jo...@apache.org on 2007/10/10 11:47:28 UTC

svn commit: r583412 [4/8] - in /maven/archiva/trunk: archiva-base/archiva-configuration/src/main/java/org/apache/maven/archiva/configuration/ archiva-base/archiva-configuration/src/main/java/org/apache/maven/archiva/configuration/functors/ archiva-base...

Added: maven/archiva/trunk/archiva-base/archiva-repository-layer/src/main/java/org/apache/maven/archiva/repository/content/DefaultPathParser.java
URL: http://svn.apache.org/viewvc/maven/archiva/trunk/archiva-base/archiva-repository-layer/src/main/java/org/apache/maven/archiva/repository/content/DefaultPathParser.java?rev=583412&view=auto
==============================================================================
--- maven/archiva/trunk/archiva-base/archiva-repository-layer/src/main/java/org/apache/maven/archiva/repository/content/DefaultPathParser.java (added)
+++ maven/archiva/trunk/archiva-base/archiva-repository-layer/src/main/java/org/apache/maven/archiva/repository/content/DefaultPathParser.java Wed Oct 10 02:47:20 2007
@@ -0,0 +1,184 @@
+package org.apache.maven.archiva.repository.content;
+
+/*
+ * 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.commons.lang.StringUtils;
+import org.apache.maven.archiva.common.utils.VersionUtil;
+import org.apache.maven.archiva.model.ArtifactReference;
+import org.apache.maven.archiva.repository.layout.LayoutException;
+
+/**
+ * DefaultPathParser is a parser for maven 2 (default layout) paths to ArtifactReference. 
+ *
+ * @author <a href="mailto:joakime@apache.org">Joakim Erdfelt</a>
+ * @version $Id$
+ * 
+ * @plexus.component role="org.apache.maven.archiva.repository.content.DefaultPathParser"
+ */
+public class DefaultPathParser
+{
+    private static final String INVALID_ARTIFACT_PATH = "Invalid path to Artifact: ";
+
+    /**
+     * Convert a path to an ArtifactReference. 
+     * 
+     * @param path
+     * @return
+     * @throws LayoutException
+     */
+    protected static ArtifactReference toArtifactReference( String path )
+        throws LayoutException
+    {
+        if ( StringUtils.isBlank( path ) )
+        {
+            throw new LayoutException( "Unable to convert blank path." );
+        }
+
+        ArtifactReference artifact = new ArtifactReference();
+
+        String normalizedPath = StringUtils.replace( path, "\\", "/" );
+        String pathParts[] = StringUtils.split( normalizedPath, '/' );
+
+        /* Minimum parts.
+         *
+         *   path = "commons-lang/commons-lang/2.1/commons-lang-2.1.jar"
+         *   path[0] = "commons-lang";        // The Group ID
+         *   path[1] = "commons-lang";        // The Artifact ID
+         *   path[2] = "2.1";                 // The Version
+         *   path[3] = "commons-lang-2.1.jar" // The filename.
+         */
+
+        if ( pathParts.length < 4 )
+        {
+            // Illegal Path Parts Length.
+            throw new LayoutException( "Not enough parts to the path [" + path
+                + "] to construct an ArchivaArtifact from. (Requires at least 4 parts)" );
+        }
+
+        // Maven 2.x path.
+        int partCount = pathParts.length;
+        int filenamePos = partCount - 1;
+        int baseVersionPos = partCount - 2;
+        int artifactIdPos = partCount - 3;
+        int groupIdPos = partCount - 4;
+
+        // Second to last is the baseVersion (the directory version)
+        String baseVersion = pathParts[baseVersionPos];
+
+        // Third to last is the artifact Id.
+        artifact.setArtifactId( pathParts[artifactIdPos] );
+
+        // Remaining pieces are the groupId.
+        for ( int i = 0; i <= groupIdPos; i++ )
+        {
+            if ( i == 0 )
+            {
+                artifact.setGroupId( pathParts[i] );
+            }
+            else
+            {
+                artifact.setGroupId( artifact.getGroupId() + "." + pathParts[i] );
+            }
+        }
+
+        try
+        {
+            // Last part is the filename
+            String filename = pathParts[filenamePos];
+
+            // Now we need to parse the filename to get the artifact version Id.
+            if ( StringUtils.isBlank( filename ) )
+            {
+                throw new IllegalArgumentException( INVALID_ARTIFACT_PATH + "Unable to split blank filename." );
+            }
+
+            FilenameParser parser = new FilenameParser( filename );
+
+            // Expect the filename to start with the artifactId.
+            artifact.setArtifactId( parser.expect( artifact.getArtifactId() ) );
+
+            if ( artifact.getArtifactId() == null )
+            {
+                throw new LayoutException( INVALID_ARTIFACT_PATH + "filename format is invalid, "
+                    + "should start with artifactId as stated in path." );
+            }
+
+            // Process the version.
+            artifact.setVersion( parser.expect( baseVersion ) );
+
+            if ( artifact.getVersion() == null )
+            {
+                // We working with a snapshot?
+                if ( VersionUtil.isSnapshot( baseVersion ) )
+                {
+                    artifact.setVersion( parser.nextVersion() );
+                    if ( !VersionUtil.isUniqueSnapshot( artifact.getVersion() ) )
+                    {
+                        throw new LayoutException( INVALID_ARTIFACT_PATH + "filename format is invalid,"
+                            + "expected timestamp format in filename." );
+                    }
+                }
+                else
+                {
+                    throw new LayoutException( INVALID_ARTIFACT_PATH + "filename format is invalid, "
+                        + "expected version as stated in path." );
+                }
+            }
+
+            // Do we have a classifier?
+            artifact.setClassifier( parser.remaining() );
+
+            // Set the type.
+            artifact.setType( ArtifactExtensionMapping.guessTypeFromFilename( filename ) );
+
+            artifact.setType( ArtifactExtensionMapping.guessTypeFromFilename( filename ) );
+        }
+        catch ( LayoutException e )
+        {
+            throw e;
+        }
+
+        // Sanity Checks.
+
+        // Do we have a snapshot version?
+        if ( VersionUtil.isSnapshot( artifact.getVersion() ) )
+        {
+            // Rules are different for SNAPSHOTS
+            if ( !VersionUtil.isGenericSnapshot( baseVersion ) )
+            {
+                String filenameBaseVersion = VersionUtil.getBaseVersion( artifact.getVersion() );
+                throw new LayoutException( "Invalid snapshot artifact location, version directory should be "
+                    + filenameBaseVersion );
+            }
+        }
+        else
+        {
+            // Non SNAPSHOT rules.
+            // Do we pass the simple test?
+            if ( !StringUtils.equals( baseVersion, artifact.getVersion() ) )
+            {
+                throw new LayoutException( "Invalid artifact: version declared in directory path does"
+                    + " not match what was found in the artifact filename." );
+            }
+        }
+
+        return artifact;
+    }
+}

Propchange: maven/archiva/trunk/archiva-base/archiva-repository-layer/src/main/java/org/apache/maven/archiva/repository/content/DefaultPathParser.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: maven/archiva/trunk/archiva-base/archiva-repository-layer/src/main/java/org/apache/maven/archiva/repository/content/DefaultPathParser.java
------------------------------------------------------------------------------
    svn:keywords = "Author Date Id Revision"

Propchange: maven/archiva/trunk/archiva-base/archiva-repository-layer/src/main/java/org/apache/maven/archiva/repository/content/DefaultPathParser.java
------------------------------------------------------------------------------
    svn:mime-type = text/plain

Added: maven/archiva/trunk/archiva-base/archiva-repository-layer/src/main/java/org/apache/maven/archiva/repository/content/FilenameParser.java
URL: http://svn.apache.org/viewvc/maven/archiva/trunk/archiva-base/archiva-repository-layer/src/main/java/org/apache/maven/archiva/repository/content/FilenameParser.java?rev=583412&view=auto
==============================================================================
--- maven/archiva/trunk/archiva-base/archiva-repository-layer/src/main/java/org/apache/maven/archiva/repository/content/FilenameParser.java (added)
+++ maven/archiva/trunk/archiva-base/archiva-repository-layer/src/main/java/org/apache/maven/archiva/repository/content/FilenameParser.java Wed Oct 10 02:47:20 2007
@@ -0,0 +1,210 @@
+package org.apache.maven.archiva.repository.content;
+
+/*
+ * 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.maven.archiva.common.utils.VersionUtil;
+
+import java.util.regex.Matcher;
+import java.util.regex.Pattern;
+
+/**
+ * Generic Filename Parser for use with layout routines.
+ *
+ * @author <a href="mailto:joakime@apache.org">Joakim Erdfelt</a>
+ * @version $Id$
+ */
+public class FilenameParser
+{
+    private String name;
+
+    private String extension;
+
+    private int offset;
+
+    private static final Pattern specialCases = Pattern.compile( "(maven-.*-plugin)|(maven-plugin)" );
+
+    private static final Pattern extensionPattern = Pattern.compile( "(.tar.gz$)|(.tar.bz2$)|(.[a-z0-9]{1,4}$)",
+                                                                     Pattern.CASE_INSENSITIVE );
+
+    private static final Pattern section = Pattern.compile( "([^-]*)" );
+
+    private Matcher matcher;
+
+    protected 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();
+    }
+
+    protected void reset()
+    {
+        offset = 0;
+    }
+
+    protected 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 )
+    {
+        if ( name.startsWith( expected, offset ) )
+        {
+            // Potential hit. check for '.' or '-' at end of expected.
+            int seperatorOffset = offset + expected.length();
+
+            // Test for "out of bounds" first. 
+            if ( seperatorOffset >= name.length() )
+            {
+                offset = name.length();
+                return expected;
+            }
+
+            // Test for seperator char.
+            char seperatorChar = name.charAt( seperatorOffset );
+            if ( ( seperatorChar == '-' ) || ( seperatorChar == '.' ) )
+            {
+                offset = seperatorOffset + 1;
+                return expected;
+            }
+        }
+
+        return null;
+    }
+
+    protected String getName()
+    {
+        return name;
+    }
+
+    protected String getExtension()
+    {
+        return extension;
+    }
+
+    protected String remaining()
+    {
+        if ( offset >= name.length() )
+        {
+            return null;
+        }
+
+        String end = name.substring( offset );
+        offset = name.length();
+        return end;
+    }
+
+    protected String nextNonVersion()
+    {
+        boolean done = false;
+
+        StringBuffer ver = new StringBuffer();
+
+        // Any text upto the end of a special case is considered non-version. 
+        Matcher specialMat = specialCases.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;
+
+        StringBuffer ver = new StringBuffer();
+
+        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: maven/archiva/trunk/archiva-base/archiva-repository-layer/src/main/java/org/apache/maven/archiva/repository/content/FilenameParser.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: maven/archiva/trunk/archiva-base/archiva-repository-layer/src/main/java/org/apache/maven/archiva/repository/content/FilenameParser.java
------------------------------------------------------------------------------
    svn:keywords = "Author Date Id Revision"

Propchange: maven/archiva/trunk/archiva-base/archiva-repository-layer/src/main/java/org/apache/maven/archiva/repository/content/FilenameParser.java
------------------------------------------------------------------------------
    svn:mime-type = text/plain

Added: maven/archiva/trunk/archiva-base/archiva-repository-layer/src/main/java/org/apache/maven/archiva/repository/content/LegacyPathParser.java
URL: http://svn.apache.org/viewvc/maven/archiva/trunk/archiva-base/archiva-repository-layer/src/main/java/org/apache/maven/archiva/repository/content/LegacyPathParser.java?rev=583412&view=auto
==============================================================================
--- maven/archiva/trunk/archiva-base/archiva-repository-layer/src/main/java/org/apache/maven/archiva/repository/content/LegacyPathParser.java (added)
+++ maven/archiva/trunk/archiva-base/archiva-repository-layer/src/main/java/org/apache/maven/archiva/repository/content/LegacyPathParser.java Wed Oct 10 02:47:20 2007
@@ -0,0 +1,153 @@
+package org.apache.maven.archiva.repository.content;
+
+/*
+ * 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.commons.lang.StringUtils;
+import org.apache.maven.archiva.model.ArtifactReference;
+import org.apache.maven.archiva.repository.layout.LayoutException;
+
+/**
+ * LegacyPathParser is a parser for maven 1 (legacy layout) paths to ArtifactReference. 
+ *
+ * @author <a href="mailto:joakime@apache.org">Joakim Erdfelt</a>
+ * @version $Id$
+ */
+public class LegacyPathParser
+{
+    private static final String INVALID_ARTIFACT_PATH = "Invalid path to Artifact: ";
+
+    protected static ArtifactReference toArtifactReference( String path )
+        throws LayoutException
+    {
+        ArtifactReference artifact = new ArtifactReference();
+
+        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." );
+            }
+        }
+
+        artifact.setType( ArtifactExtensionMapping.guessTypeFromFilename( filename ) );
+
+        // Sanity Check: does it have an extension?
+        if ( StringUtils.isEmpty( artifact.getType() ) )
+        {
+            throw new LayoutException( INVALID_ARTIFACT_PATH + "no extension found." );
+        }
+
+        String trimPathType = expectedType.substring( 0, expectedType.length() - 1 );
+
+        // Sanity Check: does extension match pathType on path?
+        String expectedExtension = ArtifactExtensionMapping.getExtension( trimPathType );
+        String actualExtension = parser.getExtension();
+
+        if ( !expectedExtension.equals( actualExtension ) )
+        {
+            throw new LayoutException( INVALID_ARTIFACT_PATH + "mismatch on extension [" + actualExtension
+                + "] and layout specified type [" + expectedType + "] (which maps to extension: [" + expectedExtension
+                + "]) on path [" + path + "]" );
+        }
+
+        return artifact;
+    }
+}

Propchange: maven/archiva/trunk/archiva-base/archiva-repository-layer/src/main/java/org/apache/maven/archiva/repository/content/LegacyPathParser.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: maven/archiva/trunk/archiva-base/archiva-repository-layer/src/main/java/org/apache/maven/archiva/repository/content/LegacyPathParser.java
------------------------------------------------------------------------------
    svn:keywords = "Author Date Id Revision"

Propchange: maven/archiva/trunk/archiva-base/archiva-repository-layer/src/main/java/org/apache/maven/archiva/repository/content/LegacyPathParser.java
------------------------------------------------------------------------------
    svn:mime-type = text/plain

Added: maven/archiva/trunk/archiva-base/archiva-repository-layer/src/main/java/org/apache/maven/archiva/repository/content/ManagedDefaultRepositoryContent.java
URL: http://svn.apache.org/viewvc/maven/archiva/trunk/archiva-base/archiva-repository-layer/src/main/java/org/apache/maven/archiva/repository/content/ManagedDefaultRepositoryContent.java?rev=583412&view=auto
==============================================================================
--- maven/archiva/trunk/archiva-base/archiva-repository-layer/src/main/java/org/apache/maven/archiva/repository/content/ManagedDefaultRepositoryContent.java (added)
+++ maven/archiva/trunk/archiva-base/archiva-repository-layer/src/main/java/org/apache/maven/archiva/repository/content/ManagedDefaultRepositoryContent.java Wed Oct 10 02:47:20 2007
@@ -0,0 +1,438 @@
+package org.apache.maven.archiva.repository.content;
+
+/*
+ * 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.commons.io.FileUtils;
+import org.apache.maven.archiva.common.utils.PathUtil;
+import org.apache.maven.archiva.configuration.FileTypes;
+import org.apache.maven.archiva.configuration.ManagedRepositoryConfiguration;
+import org.apache.maven.archiva.model.ArtifactReference;
+import org.apache.maven.archiva.model.ProjectReference;
+import org.apache.maven.archiva.model.VersionedReference;
+import org.apache.maven.archiva.repository.ContentNotFoundException;
+import org.apache.maven.archiva.repository.ManagedRepositoryContent;
+import org.apache.maven.archiva.repository.layout.LayoutException;
+import org.codehaus.plexus.personality.plexus.lifecycle.phase.Initializable;
+import org.codehaus.plexus.personality.plexus.lifecycle.phase.InitializationException;
+import org.codehaus.plexus.util.SelectorUtils;
+
+import java.io.File;
+import java.io.IOException;
+import java.util.ArrayList;
+import java.util.HashSet;
+import java.util.Iterator;
+import java.util.List;
+import java.util.Set;
+
+/**
+ * ManagedDefaultRepositoryContent 
+ *
+ * @author <a href="mailto:joakime@apache.org">Joakim Erdfelt</a>
+ * @version $Id$
+ * 
+ * @plexus.component 
+ *      role="org.apache.maven.archiva.repository.ManagedRepositoryContent"
+ *      role-hint="default"
+ *      instantiation-strategy="per-lookup"
+ */
+public class ManagedDefaultRepositoryContent
+    extends AbstractDefaultRepositoryContent
+    implements ManagedRepositoryContent, Initializable
+{
+    /**
+     * @plexus.requirement
+     */
+    private FileTypes filetypes;
+
+    private ManagedRepositoryConfiguration repository;
+
+    private List<String> artifactPatterns;
+
+    public void deleteVersion( VersionedReference reference )
+        throws ContentNotFoundException
+    {
+        String path = toMetadataPath( reference );
+        File projectPath = new File( getRepoRoot(), path );
+        
+        File projectDir = projectPath.getParentFile();
+        if( projectDir.exists() && projectDir.isDirectory() )
+        {
+            try
+            {
+                FileUtils.deleteDirectory( projectDir );
+            }
+            catch ( IOException e )
+            {
+                // TODO: log this somewhere?
+            }
+        }
+    }
+
+    public String getId()
+    {
+        return repository.getId();
+    }
+
+    public Set<ArtifactReference> getRelatedArtifacts( ArtifactReference reference )
+        throws ContentNotFoundException, LayoutException
+    {
+        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 repoFiles[] = repoDir.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 ( matchesArtifactPattern( relativePath ) )
+            {
+                ArtifactReference artifact = toArtifactReference( relativePath );
+                
+                // Test for related, groupId / artifactId / version must match.
+                if ( artifact.getGroupId().equals( reference.getGroupId() )
+                    && artifact.getArtifactId().equals( reference.getArtifactId() )
+                    && artifact.getVersion().equals( reference.getVersion() ) )
+                {
+                    foundArtifacts.add( artifact );
+                }
+            }
+        }
+
+        return foundArtifacts;
+    }
+
+    public String getRepoRoot()
+    {
+        return repository.getLocation();
+    }
+
+    public ManagedRepositoryConfiguration getRepository()
+    {
+        return repository;
+    }
+
+    /**
+     * Gather the Available Versions (on disk) for a specific Project Reference, based on filesystem
+     * information.
+     *
+     * @return the Set of available versions, based on the project reference.
+     * @throws LayoutException 
+     * @throws LayoutException
+     */
+    public Set<String> getVersions( ProjectReference reference )
+        throws ContentNotFoundException, LayoutException
+    {
+        String path = toMetadataPath( reference );
+
+        int idx = path.lastIndexOf( '/' );
+        if ( idx > 0 )
+        {
+            path = path.substring( 0, idx );
+        }
+
+        File repoDir = new File( repository.getLocation(), path );
+
+        if ( !repoDir.exists() )
+        {
+            throw new ContentNotFoundException( "Unable to get Versions on a non-existant directory: "
+                + repoDir.getAbsolutePath() );
+        }
+
+        if ( !repoDir.isDirectory() )
+        {
+            throw new ContentNotFoundException( "Unable to get Versions on a non-directory: "
+                + repoDir.getAbsolutePath() );
+        }
+
+        Set<String> foundVersions = new HashSet<String>();
+        VersionedReference versionRef = new VersionedReference();
+        versionRef.setGroupId( reference.getGroupId() );
+        versionRef.setArtifactId( reference.getArtifactId() );
+
+        File repoFiles[] = repoDir.listFiles();
+        for ( int i = 0; i < repoFiles.length; i++ )
+        {
+            if ( !repoFiles[i].isDirectory() )
+            {
+                // Skip it. not a directory.
+                continue;
+            }
+
+            // Test if dir has an artifact, which proves to us that it is a valid version directory.
+            String version = repoFiles[i].getName();
+            versionRef.setVersion( version );
+
+            if ( hasArtifact( versionRef ) )
+            {
+                // Found an artifact, must be a valid version.
+                foundVersions.add( version );
+            }
+        }
+
+        return foundVersions;
+    }
+
+    public Set<String> getVersions( VersionedReference reference )
+        throws ContentNotFoundException, LayoutException
+    {
+        String path = toMetadataPath( reference );
+
+        int idx = path.lastIndexOf( '/' );
+        if ( idx > 0 )
+        {
+            path = path.substring( 0, idx );
+        }
+
+        File repoDir = new File( repository.getLocation(), path );
+
+        if ( !repoDir.exists() )
+        {
+            throw new ContentNotFoundException( "Unable to get versions on a non-existant directory: "
+                + repoDir.getAbsolutePath() );
+        }
+
+        if ( !repoDir.isDirectory() )
+        {
+            throw new ContentNotFoundException( "Unable to get versions on a non-directory: "
+                + repoDir.getAbsolutePath() );
+        }
+
+        Set<String> foundVersions = new HashSet<String>();
+
+        // First gather up the versions found as artifacts in the managed repository.
+        File repoFiles[] = repoDir.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 ( matchesArtifactPattern( relativePath ) )
+            {
+                ArtifactReference artifact = toArtifactReference( relativePath );
+
+                foundVersions.add( artifact.getVersion() );
+            }
+        }
+
+        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 !versions.isEmpty();
+        }
+        catch ( ContentNotFoundException e )
+        {
+            return false;
+        }
+        catch ( LayoutException e )
+        {
+            return false;
+        }
+    }
+
+    public boolean hasContent( VersionedReference reference )
+    {
+        try
+        {
+            return ( getFirstArtifact( reference ) != null );
+        }
+        catch ( IOException e )
+        {
+            return false;
+        }
+        catch ( LayoutException e )
+        {
+            return false;
+        }
+    }
+
+    public void initialize()
+        throws InitializationException
+    {
+        this.artifactPatterns = new ArrayList<String>();
+        initVariables();
+    }
+
+    public void setRepository( ManagedRepositoryConfiguration repository )
+    {
+        this.repository = repository;
+    }
+
+    /**
+     * Convert a path to an artifact reference.
+     * 
+     * @param path the path to convert. (relative or full location path)
+     * @throws 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( ArtifactReference reference )
+    {
+        return new File( repository.getLocation(), toPath( reference ) );
+    }
+
+    /**
+     * Get the first Artifact found in the provided VersionedReference location.
+     *
+     * @param managedRepository the repository to search within.
+     * @param reference         the reference to the versioned reference to search within
+     * @return the ArtifactReference to the first artifact located within the versioned reference. or null if
+     *         no artifact was found within the versioned reference.
+     * @throws IOException     if the versioned reference is invalid (example: doesn't exist, or isn't a directory)
+     * @throws LayoutException
+     */
+    private ArtifactReference getFirstArtifact( VersionedReference reference )
+        throws LayoutException, IOException
+    {
+        String path = toMetadataPath( reference );
+
+        int idx = path.lastIndexOf( '/' );
+        if ( idx > 0 )
+        {
+            path = path.substring( 0, idx );
+        }
+
+        File repoDir = new File( repository.getLocation(), path );
+
+        if ( !repoDir.exists() )
+        {
+            throw new IOException( "Unable to gather the list of snapshot versions on a non-existant directory: "
+                + repoDir.getAbsolutePath() );
+        }
+
+        if ( !repoDir.isDirectory() )
+        {
+            throw new IOException( "Unable to gather the list of snapshot versions on a non-directory: "
+                + repoDir.getAbsolutePath() );
+        }
+
+        File repoFiles[] = repoDir.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 ( matchesArtifactPattern( relativePath ) )
+            {
+                ArtifactReference artifact = toArtifactReference( relativePath );
+
+                return artifact;
+            }
+        }
+
+        // No artifact was found.
+        return null;
+    }
+
+    private boolean hasArtifact( VersionedReference reference )
+        throws LayoutException
+    {
+        try
+        {
+            return ( getFirstArtifact( reference ) != null );
+        }
+        catch ( IOException e )
+        {
+            return false;
+        }
+    }
+
+    private void initVariables()
+    {
+        synchronized ( this.artifactPatterns )
+        {
+            this.artifactPatterns.clear();
+
+            this.artifactPatterns.addAll( filetypes.getFileTypePatterns( FileTypes.ARTIFACTS ) );
+        }
+    }
+
+    private boolean matchesArtifactPattern( String relativePath )
+    {
+        // Correct the slash pattern.
+        relativePath = relativePath.replace( '\\', '/' );
+
+        Iterator<String> it = this.artifactPatterns.iterator();
+        while ( it.hasNext() )
+        {
+            String pattern = it.next();
+
+            if ( SelectorUtils.matchPath( pattern, relativePath, false ) )
+            {
+                // Found match
+                return true;
+            }
+        }
+
+        // No match.
+        return false;
+    }
+}

Propchange: maven/archiva/trunk/archiva-base/archiva-repository-layer/src/main/java/org/apache/maven/archiva/repository/content/ManagedDefaultRepositoryContent.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: maven/archiva/trunk/archiva-base/archiva-repository-layer/src/main/java/org/apache/maven/archiva/repository/content/ManagedDefaultRepositoryContent.java
------------------------------------------------------------------------------
    svn:keywords = "Author Date Id Revision"

Propchange: maven/archiva/trunk/archiva-base/archiva-repository-layer/src/main/java/org/apache/maven/archiva/repository/content/ManagedDefaultRepositoryContent.java
------------------------------------------------------------------------------
    svn:mime-type = text/plain

Added: maven/archiva/trunk/archiva-base/archiva-repository-layer/src/main/java/org/apache/maven/archiva/repository/content/ManagedLegacyRepositoryContent.java
URL: http://svn.apache.org/viewvc/maven/archiva/trunk/archiva-base/archiva-repository-layer/src/main/java/org/apache/maven/archiva/repository/content/ManagedLegacyRepositoryContent.java?rev=583412&view=auto
==============================================================================
--- maven/archiva/trunk/archiva-base/archiva-repository-layer/src/main/java/org/apache/maven/archiva/repository/content/ManagedLegacyRepositoryContent.java (added)
+++ maven/archiva/trunk/archiva-base/archiva-repository-layer/src/main/java/org/apache/maven/archiva/repository/content/ManagedLegacyRepositoryContent.java Wed Oct 10 02:47:20 2007
@@ -0,0 +1,495 @@
+package org.apache.maven.archiva.repository.content;
+
+/*
+ * 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.commons.collections.CollectionUtils;
+import org.apache.commons.lang.StringUtils;
+import org.apache.maven.archiva.common.utils.PathUtil;
+import org.apache.maven.archiva.configuration.FileTypes;
+import org.apache.maven.archiva.configuration.ManagedRepositoryConfiguration;
+import org.apache.maven.archiva.model.ArtifactReference;
+import org.apache.maven.archiva.model.ProjectReference;
+import org.apache.maven.archiva.model.VersionedReference;
+import org.apache.maven.archiva.repository.ContentNotFoundException;
+import org.apache.maven.archiva.repository.ManagedRepositoryContent;
+import org.apache.maven.archiva.repository.layout.LayoutException;
+import org.codehaus.plexus.personality.plexus.lifecycle.phase.Initializable;
+import org.codehaus.plexus.personality.plexus.lifecycle.phase.InitializationException;
+import org.codehaus.plexus.util.SelectorUtils;
+
+import java.io.File;
+import java.util.ArrayList;
+import java.util.HashSet;
+import java.util.Iterator;
+import java.util.List;
+import java.util.Set;
+
+/**
+ * ManagedLegacyRepositoryContent 
+ *
+ * @author <a href="mailto:joakime@apache.org">Joakim Erdfelt</a>
+ * @version $Id$
+ * 
+ * @plexus.component 
+ *      role="org.apache.maven.archiva.repository.ManagedRepositoryContent"
+ *      role-hint="legacy"
+ *      instantiation-strategy="per-lookup"
+ */
+public class ManagedLegacyRepositoryContent
+    extends AbstractLegacyRepositoryContent
+    implements ManagedRepositoryContent, Initializable
+{
+    /**
+     * @plexus.requirement
+     */
+    private FileTypes filetypes;
+
+    private ManagedRepositoryConfiguration repository;
+
+    private List<String> artifactPatterns;
+
+    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 ( 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. */
+                }
+            }
+        }
+    }
+
+    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, LayoutException
+    {
+        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 ManagedRepositoryConfiguration 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 initialize()
+        throws InitializationException
+    {
+        this.artifactPatterns = new ArrayList<String>();
+        initVariables();
+    }
+
+    public void setRepository( ManagedRepositoryConfiguration repository )
+    {
+        this.repository = repository;
+    }
+
+    /**
+     * Convert a path to an artifact reference.
+     * 
+     * @param path the path to convert. (relative or full location path)
+     * @throws 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( 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 ( 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 ( 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 ( 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. */
+                }
+            }
+        }
+    }
+
+    private void initVariables()
+    {
+        synchronized ( this.artifactPatterns )
+        {
+            this.artifactPatterns.clear();
+
+            this.artifactPatterns.addAll( filetypes.getFileTypePatterns( FileTypes.ARTIFACTS ) );
+        }
+    }
+
+    private boolean matchesArtifactPattern( String relativePath )
+    {
+        // Correct the slash pattern.
+        relativePath = relativePath.replace( '\\', '/' );
+
+        Iterator<String> it = this.artifactPatterns.iterator();
+        while ( it.hasNext() )
+        {
+            String pattern = it.next();
+
+            if ( SelectorUtils.matchPath( pattern, relativePath, false ) )
+            {
+                // Found match
+                return true;
+            }
+        }
+
+        // No match.
+        return false;
+    }
+}

Propchange: maven/archiva/trunk/archiva-base/archiva-repository-layer/src/main/java/org/apache/maven/archiva/repository/content/ManagedLegacyRepositoryContent.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: maven/archiva/trunk/archiva-base/archiva-repository-layer/src/main/java/org/apache/maven/archiva/repository/content/ManagedLegacyRepositoryContent.java
------------------------------------------------------------------------------
    svn:keywords = "Author Date Id Revision"

Propchange: maven/archiva/trunk/archiva-base/archiva-repository-layer/src/main/java/org/apache/maven/archiva/repository/content/ManagedLegacyRepositoryContent.java
------------------------------------------------------------------------------
    svn:mime-type = text/plain

Added: maven/archiva/trunk/archiva-base/archiva-repository-layer/src/main/java/org/apache/maven/archiva/repository/content/RemoteDefaultRepositoryContent.java
URL: http://svn.apache.org/viewvc/maven/archiva/trunk/archiva-base/archiva-repository-layer/src/main/java/org/apache/maven/archiva/repository/content/RemoteDefaultRepositoryContent.java?rev=583412&view=auto
==============================================================================
--- maven/archiva/trunk/archiva-base/archiva-repository-layer/src/main/java/org/apache/maven/archiva/repository/content/RemoteDefaultRepositoryContent.java (added)
+++ maven/archiva/trunk/archiva-base/archiva-repository-layer/src/main/java/org/apache/maven/archiva/repository/content/RemoteDefaultRepositoryContent.java Wed Oct 10 02:47:20 2007
@@ -0,0 +1,88 @@
+package org.apache.maven.archiva.repository.content;
+
+/*
+ * 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.maven.archiva.configuration.RemoteRepositoryConfiguration;
+import org.apache.maven.archiva.model.ArtifactReference;
+import org.apache.maven.archiva.model.RepositoryURL;
+import org.apache.maven.archiva.repository.RemoteRepositoryContent;
+import org.apache.maven.archiva.repository.layout.LayoutException;
+
+/**
+ * RemoteDefaultRepositoryContent 
+ *
+ * @author <a href="mailto:joakime@apache.org">Joakim Erdfelt</a>
+ * @version $Id$
+ * 
+ * @plexus.component 
+ *      role="org.apache.maven.archiva.repository.RemoteRepositoryContent"
+ *      role-hint="default"
+ *      instantiation-strategy="per-lookup"
+ */
+public class RemoteDefaultRepositoryContent
+    extends AbstractDefaultRepositoryContent
+    implements RemoteRepositoryContent
+{
+    private RemoteRepositoryConfiguration repository;
+
+    public String getId()
+    {
+        return repository.getId();
+    }
+
+    public RemoteRepositoryConfiguration getRepository()
+    {
+        return repository;
+    }
+
+    public RepositoryURL getURL()
+    {
+        return new RepositoryURL( repository.getUrl() );
+    }
+
+    public void setRepository( RemoteRepositoryConfiguration repository )
+    {
+        this.repository = repository;
+    }
+
+    /**
+     * Convert a path to an artifact reference.
+     * 
+     * @param path the path to convert. (relative or full url path)
+     * @throws 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.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: maven/archiva/trunk/archiva-base/archiva-repository-layer/src/main/java/org/apache/maven/archiva/repository/content/RemoteDefaultRepositoryContent.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: maven/archiva/trunk/archiva-base/archiva-repository-layer/src/main/java/org/apache/maven/archiva/repository/content/RemoteDefaultRepositoryContent.java
------------------------------------------------------------------------------
    svn:keywords = "Author Date Id Revision"

Propchange: maven/archiva/trunk/archiva-base/archiva-repository-layer/src/main/java/org/apache/maven/archiva/repository/content/RemoteDefaultRepositoryContent.java
------------------------------------------------------------------------------
    svn:mime-type = text/plain

Added: maven/archiva/trunk/archiva-base/archiva-repository-layer/src/main/java/org/apache/maven/archiva/repository/content/RemoteLegacyRepositoryContent.java
URL: http://svn.apache.org/viewvc/maven/archiva/trunk/archiva-base/archiva-repository-layer/src/main/java/org/apache/maven/archiva/repository/content/RemoteLegacyRepositoryContent.java?rev=583412&view=auto
==============================================================================
--- maven/archiva/trunk/archiva-base/archiva-repository-layer/src/main/java/org/apache/maven/archiva/repository/content/RemoteLegacyRepositoryContent.java (added)
+++ maven/archiva/trunk/archiva-base/archiva-repository-layer/src/main/java/org/apache/maven/archiva/repository/content/RemoteLegacyRepositoryContent.java Wed Oct 10 02:47:20 2007
@@ -0,0 +1,88 @@
+package org.apache.maven.archiva.repository.content;
+
+/*
+ * 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.maven.archiva.configuration.RemoteRepositoryConfiguration;
+import org.apache.maven.archiva.model.ArtifactReference;
+import org.apache.maven.archiva.model.RepositoryURL;
+import org.apache.maven.archiva.repository.RemoteRepositoryContent;
+import org.apache.maven.archiva.repository.layout.LayoutException;
+
+/**
+ * RemoteLegacyRepositoryContent 
+ *
+ * @author <a href="mailto:joakime@apache.org">Joakim Erdfelt</a>
+ * @version $Id$
+ * 
+ * @plexus.component 
+ *      role="org.apache.maven.archiva.repository.RemoteRepositoryContent"
+ *      role-hint="legacy"
+ *      instantiation-strategy="per-lookup"
+ */
+public class RemoteLegacyRepositoryContent
+    extends AbstractLegacyRepositoryContent
+    implements RemoteRepositoryContent
+{
+    private RemoteRepositoryConfiguration repository;
+
+    public String getId()
+    {
+        return repository.getId();
+    }
+
+    public RemoteRepositoryConfiguration getRepository()
+    {
+        return repository;
+    }
+
+    public RepositoryURL getURL()
+    {
+        return new RepositoryURL( repository.getUrl() );
+    }
+
+    public void setRepository( RemoteRepositoryConfiguration repository )
+    {
+        this.repository = repository;
+    }
+
+    /**
+     * Convert a path to an artifact reference.
+     * 
+     * @param path the path to convert. (relative or full url path)
+     * @throws 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: maven/archiva/trunk/archiva-base/archiva-repository-layer/src/main/java/org/apache/maven/archiva/repository/content/RemoteLegacyRepositoryContent.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: maven/archiva/trunk/archiva-base/archiva-repository-layer/src/main/java/org/apache/maven/archiva/repository/content/RemoteLegacyRepositoryContent.java
------------------------------------------------------------------------------
    svn:keywords = "Author Date Id Revision"

Propchange: maven/archiva/trunk/archiva-base/archiva-repository-layer/src/main/java/org/apache/maven/archiva/repository/content/RemoteLegacyRepositoryContent.java
------------------------------------------------------------------------------
    svn:mime-type = text/plain

Added: maven/archiva/trunk/archiva-base/archiva-repository-layer/src/main/java/org/apache/maven/archiva/repository/content/RepositoryRequest.java
URL: http://svn.apache.org/viewvc/maven/archiva/trunk/archiva-base/archiva-repository-layer/src/main/java/org/apache/maven/archiva/repository/content/RepositoryRequest.java?rev=583412&view=auto
==============================================================================
--- maven/archiva/trunk/archiva-base/archiva-repository-layer/src/main/java/org/apache/maven/archiva/repository/content/RepositoryRequest.java (added)
+++ maven/archiva/trunk/archiva-base/archiva-repository-layer/src/main/java/org/apache/maven/archiva/repository/content/RepositoryRequest.java Wed Oct 10 02:47:20 2007
@@ -0,0 +1,146 @@
+package org.apache.maven.archiva.repository.content;
+
+/*
+ * 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.commons.lang.StringUtils;
+import org.apache.maven.archiva.configuration.ArchivaConfiguration;
+import org.apache.maven.archiva.configuration.FileTypes;
+import org.apache.maven.archiva.model.ArtifactReference;
+import org.apache.maven.archiva.repository.layout.LayoutException;
+import org.codehaus.plexus.personality.plexus.lifecycle.phase.Initializable;
+import org.codehaus.plexus.personality.plexus.lifecycle.phase.InitializationException;
+import org.codehaus.plexus.registry.Registry;
+import org.codehaus.plexus.registry.RegistryListener;
+import org.codehaus.plexus.util.SelectorUtils;
+
+import java.util.ArrayList;
+import java.util.Iterator;
+import java.util.List;
+
+/**
+ * RepositoryRequest is used to determine the type of request that is incoming, and convert it to an appropriate
+ * ArtifactReference.  
+ *
+ * @author <a href="mailto:joakime@apache.org">Joakim Erdfelt</a>
+ * @version $Id$
+ * 
+ * @plexus.component 
+ *      role="org.apache.maven.archiva.repository.content.RepositoryRequest"
+ */
+public class RepositoryRequest
+    implements RegistryListener, Initializable
+{
+    /**
+     * @plexus.requirement
+     */
+    private FileTypes filetypes;
+
+    /**
+     * @plexus.requirement
+     */
+    private ArchivaConfiguration archivaConfiguration;
+
+    private List<String> artifactPatterns;
+
+    /**
+     * Test path to see if it is an artifact being requested (or not).
+     * 
+     * @param requestedPath the path to test.
+     * @return true if it is an artifact being requested.
+     */
+    public boolean isArtifact( String requestedPath )
+    {
+        // Correct the slash pattern.
+        String relativePath = requestedPath.replace( '\\', '/' );
+
+        Iterator<String> it = this.artifactPatterns.iterator();
+        while ( it.hasNext() )
+        {
+            String pattern = it.next();
+
+            if ( SelectorUtils.matchPath( pattern, relativePath, false ) )
+            {
+                // Found match
+                return true;
+            }
+        }
+
+        // No match.
+        return false;
+    }
+
+    /**
+     * Takes an incoming requested path (in "/" format) and gleans the layout
+     * and ArtifactReference appropriate for that content.
+     * 
+     * @param requestedPath the relative path to the content.
+     * @return the ArtifactReference for the requestedPath.
+     * @throws LayoutException if the request path is not layout valid. 
+     */
+    public ArtifactReference toArtifactReference( String requestedPath )
+        throws LayoutException
+    {
+        String pathParts[] = StringUtils.splitPreserveAllTokens( requestedPath, '/' );
+
+        if ( pathParts.length > 3 )
+        {
+            return DefaultPathParser.toArtifactReference( requestedPath );
+        }
+        else if ( pathParts.length == 3 )
+        {
+            return LegacyPathParser.toArtifactReference( requestedPath );
+        }
+        else
+        {
+            throw new LayoutException( "Not a valid request path layout, too short." );
+        }
+    }
+
+    public void initialize()
+        throws InitializationException
+    {
+        this.artifactPatterns = new ArrayList<String>();
+        initVariables();
+        this.archivaConfiguration.addChangeListener( this );
+    }
+
+    private void initVariables()
+    {
+        synchronized ( this.artifactPatterns )
+        {
+            this.artifactPatterns.clear();
+            this.artifactPatterns.addAll( filetypes.getFileTypePatterns( FileTypes.ARTIFACTS ) );
+        }
+    }
+
+    public void afterConfigurationChange( Registry registry, String propertyName, Object propertyValue )
+    {
+        if ( propertyName.contains( "fileType" ) )
+        {
+            initVariables();
+        }
+    }
+
+    public void beforeConfigurationChange( Registry registry, String propertyName, Object propertyValue )
+    {
+        /* nothing to do */
+
+    }
+}

Propchange: maven/archiva/trunk/archiva-base/archiva-repository-layer/src/main/java/org/apache/maven/archiva/repository/content/RepositoryRequest.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: maven/archiva/trunk/archiva-base/archiva-repository-layer/src/main/java/org/apache/maven/archiva/repository/content/RepositoryRequest.java
------------------------------------------------------------------------------
    svn:keywords = "Author Date Id Revision"

Propchange: maven/archiva/trunk/archiva-base/archiva-repository-layer/src/main/java/org/apache/maven/archiva/repository/content/RepositoryRequest.java
------------------------------------------------------------------------------
    svn:mime-type = text/plain

Modified: maven/archiva/trunk/archiva-base/archiva-repository-layer/src/main/java/org/apache/maven/archiva/repository/layout/DefaultBidirectionalRepositoryLayout.java
URL: http://svn.apache.org/viewvc/maven/archiva/trunk/archiva-base/archiva-repository-layer/src/main/java/org/apache/maven/archiva/repository/layout/DefaultBidirectionalRepositoryLayout.java?rev=583412&r1=583411&r2=583412&view=diff
==============================================================================
--- maven/archiva/trunk/archiva-base/archiva-repository-layer/src/main/java/org/apache/maven/archiva/repository/layout/DefaultBidirectionalRepositoryLayout.java (original)
+++ maven/archiva/trunk/archiva-base/archiva-repository-layer/src/main/java/org/apache/maven/archiva/repository/layout/DefaultBidirectionalRepositoryLayout.java Wed Oct 10 02:47:20 2007
@@ -23,7 +23,7 @@
 import org.apache.maven.archiva.common.utils.VersionUtil;
 import org.apache.maven.archiva.model.ArchivaArtifact;
 import org.apache.maven.archiva.model.ArtifactReference;
-import org.apache.maven.archiva.repository.content.DefaultArtifactExtensionMapping;
+import org.apache.maven.archiva.repository.content.ArtifactExtensionMapping;
 
 /**
  * DefaultBidirectionalRepositoryLayout - the layout mechanism for use by Maven 2.x repositories.
@@ -65,8 +65,6 @@
 
     private static final char ARTIFACT_SEPARATOR = '-';
 
-    private DefaultArtifactExtensionMapping extensionMapper = new DefaultArtifactExtensionMapping();
-
     public String getId()
     {
         return "default";
@@ -147,7 +145,7 @@
                     path.append( ARTIFACT_SEPARATOR ).append( classifier );
                 }
 
-                path.append( GROUP_SEPARATOR ).append( extensionMapper.getExtension( type ) );
+                path.append( GROUP_SEPARATOR ).append( ArtifactExtensionMapping.getExtension( type ) );
             }
         }
 
@@ -244,7 +242,7 @@
                 }
             }
 
-            prefs.type = extensionMapper.getType( filename );
+            prefs.type = ArtifactExtensionMapping.guessTypeFromFilename( filename );
         }
         catch ( LayoutException e )
         {

Modified: maven/archiva/trunk/archiva-base/archiva-repository-layer/src/main/java/org/apache/maven/archiva/repository/layout/LegacyBidirectionalRepositoryLayout.java
URL: http://svn.apache.org/viewvc/maven/archiva/trunk/archiva-base/archiva-repository-layer/src/main/java/org/apache/maven/archiva/repository/layout/LegacyBidirectionalRepositoryLayout.java?rev=583412&r1=583411&r2=583412&view=diff
==============================================================================
--- maven/archiva/trunk/archiva-base/archiva-repository-layer/src/main/java/org/apache/maven/archiva/repository/layout/LegacyBidirectionalRepositoryLayout.java (original)
+++ maven/archiva/trunk/archiva-base/archiva-repository-layer/src/main/java/org/apache/maven/archiva/repository/layout/LegacyBidirectionalRepositoryLayout.java Wed Oct 10 02:47:20 2007
@@ -22,7 +22,7 @@
 import org.apache.commons.lang.StringUtils;
 import org.apache.maven.archiva.model.ArchivaArtifact;
 import org.apache.maven.archiva.model.ArtifactReference;
-import org.apache.maven.archiva.repository.content.LegacyArtifactExtensionMapping;
+import org.apache.maven.archiva.repository.content.ArtifactExtensionMapping;
 
 import java.util.HashMap;
 import java.util.Map;
@@ -43,8 +43,6 @@
 
     private static final String PATH_SEPARATOR = "/";
 
-    private LegacyArtifactExtensionMapping extensionMapper = new LegacyArtifactExtensionMapping();
-
     private Map typeToDirectoryMap;
 
     public LegacyBidirectionalRepositoryLayout()
@@ -88,7 +86,7 @@
                 path.append( '-' ).append( classifier );
             }
 
-            path.append( '.' ).append( extensionMapper.getExtension( type ) );
+            path.append( '.' ).append( ArtifactExtensionMapping.getExtension( type ) );
         }
 
         return path.toString();
@@ -169,7 +167,7 @@
         prefs.fileParts = RepositoryLayoutUtils.splitFilename( filename, null );
 
         String trimPathType = prefs.pathType.substring( 0, prefs.pathType.length() - 1 );
-        prefs.type = extensionMapper.getType( trimPathType, filename );
+        prefs.type = ArtifactExtensionMapping.guessTypeFromFilename( filename );
 
         // Sanity Check: does it have an extension?
         if ( StringUtils.isEmpty( prefs.fileParts.extension ) )
@@ -185,7 +183,7 @@
         }
 
         // Sanity Check: does extension match pathType on path?
-        String expectedExtension = extensionMapper.getExtension( trimPathType );
+        String expectedExtension = ArtifactExtensionMapping.getExtension( trimPathType );
         String actualExtension = prefs.fileParts.extension;
 
         if ( !expectedExtension.equals( actualExtension ) )