aboutsummaryrefslogtreecommitdiffstats
path: root/archiva-repository-layer
diff options
context:
space:
mode:
authorJoakim Erdfelt <joakime@apache.org>2007-03-15 22:44:49 +0000
committerJoakim Erdfelt <joakime@apache.org>2007-03-15 22:44:49 +0000
commitf5da04241399259534e7a02cdabc8bf3c5e7d66d (patch)
tree3ec59655fcf9dcb3e0ca4622ef4ce44167ffc806 /archiva-repository-layer
parent7a5f50c9f625ed9fdf291dfc1d7d95a2eebc59ba (diff)
downloadarchiva-f5da04241399259534e7a02cdabc8bf3c5e7d66d.tar.gz
archiva-f5da04241399259534e7a02cdabc8bf3c5e7d66d.zip
Furthor work against BidirectionalLayout
git-svn-id: https://svn.apache.org/repos/asf/maven/archiva/branches/archiva-jpox-database-refactor@518797 13f79535-47bb-0310-9956-ffa450edef68
Diffstat (limited to 'archiva-repository-layer')
-rw-r--r--archiva-repository-layer/pom.xml4
-rw-r--r--archiva-repository-layer/src/main/java/org/apache/maven/archiva/repository/ArchivaArtifact.java165
-rw-r--r--archiva-repository-layer/src/main/java/org/apache/maven/archiva/repository/ArchivaRepository.java135
-rw-r--r--archiva-repository-layer/src/main/java/org/apache/maven/archiva/repository/RepositoryURL.java156
-rw-r--r--archiva-repository-layer/src/main/java/org/apache/maven/archiva/repository/connector/RepositoryConnector.java2
-rw-r--r--archiva-repository-layer/src/main/java/org/apache/maven/archiva/repository/consumer/Consumer.java91
-rw-r--r--archiva-repository-layer/src/main/java/org/apache/maven/archiva/repository/consumer/ConsumerException.java52
-rw-r--r--archiva-repository-layer/src/main/java/org/apache/maven/archiva/repository/consumer/ConsumerFactory.java70
-rw-r--r--archiva-repository-layer/src/main/java/org/apache/maven/archiva/repository/content/AbstractArtifactExtensionMapping.java58
-rw-r--r--archiva-repository-layer/src/main/java/org/apache/maven/archiva/repository/content/ArtifactExtensionMapping.java36
-rw-r--r--archiva-repository-layer/src/main/java/org/apache/maven/archiva/repository/content/BidirectionalRepositoryLayout.java23
-rw-r--r--archiva-repository-layer/src/main/java/org/apache/maven/archiva/repository/content/DefaultArtifactExtensionMapping.java76
-rw-r--r--archiva-repository-layer/src/main/java/org/apache/maven/archiva/repository/content/DefaultBidirectionalRepositoryLayout.java78
-rw-r--r--archiva-repository-layer/src/main/java/org/apache/maven/archiva/repository/content/LegacyArtifactExtensionMapping.java76
-rw-r--r--archiva-repository-layer/src/main/java/org/apache/maven/archiva/repository/content/LegacyBidirectionalRepositoryLayout.java101
-rw-r--r--archiva-repository-layer/src/main/java/org/apache/maven/archiva/repository/scanner/RepositoryScanner.java8
-rw-r--r--archiva-repository-layer/src/main/java/org/apache/maven/archiva/repository/scanner/RepositoryScannerInstance.java11
-rw-r--r--archiva-repository-layer/src/test/java/org/apache/maven/archiva/repository/RepositoryURLTest.java1
-rw-r--r--archiva-repository-layer/src/test/java/org/apache/maven/archiva/repository/content/AbstractBidirectionalRepositoryLayoutTestCase.java93
-rw-r--r--archiva-repository-layer/src/test/java/org/apache/maven/archiva/repository/content/DefaultBidirectionalRepositoryLayoutTest.java96
-rw-r--r--archiva-repository-layer/src/test/java/org/apache/maven/archiva/repository/content/LegacyBidirectionalRepositoryLayoutTest.java69
21 files changed, 1380 insertions, 21 deletions
diff --git a/archiva-repository-layer/pom.xml b/archiva-repository-layer/pom.xml
index b0a50cae9..210563124 100644
--- a/archiva-repository-layer/pom.xml
+++ b/archiva-repository-layer/pom.xml
@@ -32,10 +32,6 @@
<dependencies>
<dependency>
<groupId>org.apache.maven.archiva</groupId>
- <artifactId>archiva-consumer-api</artifactId>
- </dependency>
- <dependency>
- <groupId>org.apache.maven.archiva</groupId>
<artifactId>archiva-common</artifactId>
</dependency>
<dependency>
diff --git a/archiva-repository-layer/src/main/java/org/apache/maven/archiva/repository/ArchivaArtifact.java b/archiva-repository-layer/src/main/java/org/apache/maven/archiva/repository/ArchivaArtifact.java
new file mode 100644
index 000000000..4aa0025b7
--- /dev/null
+++ b/archiva-repository-layer/src/main/java/org/apache/maven/archiva/repository/ArchivaArtifact.java
@@ -0,0 +1,165 @@
+package org.apache.maven.archiva.repository;
+
+/*
+ * 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.model.ArchivaArtifactModel;
+import org.apache.maven.archiva.model.RepositoryContent;
+import org.codehaus.plexus.util.StringUtils;
+
+import java.util.regex.Matcher;
+import java.util.regex.Pattern;
+
+/**
+ * ArchivaArtifact - Mutable artifact object.
+ *
+ * @author <a href="mailto:joakim@erdfelt.com">Joakim Erdfelt</a>
+ * @version $Id$
+ */
+public class ArchivaArtifact
+{
+ private static final String SNAPSHOT_VERSION = "SNAPSHOT";
+
+ private static final Pattern VERSION_FILE_PATTERN = Pattern.compile( "^(.*)-([0-9]{8}\\.[0-9]{6})-([0-9]+)$" );
+
+ private ArchivaArtifactModel model;
+
+ private String baseVersion;
+
+ private boolean snapshot = false;
+
+ public ArchivaArtifact( ArchivaRepository repository, String groupId, String artifactId, String version,
+ String classifier, String type )
+ {
+ if ( empty( groupId ) )
+ {
+ throw new IllegalArgumentException( "Unable to create ArchivaArtifact with empty groupId." );
+ }
+
+ if ( empty( artifactId ) )
+ {
+ throw new IllegalArgumentException( "Unable to create ArchivaArtifact with empty artifactId." );
+ }
+
+ if ( empty( version ) )
+ {
+ throw new IllegalArgumentException( "Unable to create ArchivaArtifact with empty version." );
+ }
+
+ if ( empty( type ) )
+ {
+ throw new IllegalArgumentException( "Unable to create ArchivaArtifact with empty type." );
+ }
+
+ model = new ArchivaArtifactModel();
+
+ model.setContentKey( new RepositoryContent( repository.getModel(), groupId, artifactId, version ) );
+ model.setClassifier( StringUtils.defaultString( classifier ) );
+ model.setType( type );
+
+ // Determine Snapshot Base Version.
+ Matcher m = VERSION_FILE_PATTERN.matcher( version );
+ if ( m.matches() )
+ {
+ this.baseVersion = m.group( 1 ) + "-" + SNAPSHOT_VERSION ;
+ snapshot = true;
+ }
+ else
+ {
+ this.baseVersion = version;
+ snapshot = version.endsWith( SNAPSHOT_VERSION );
+ }
+ }
+
+ public String getGroupId()
+ {
+ return model.getContentKey().getGroupId();
+ }
+
+ public String getArtifactId()
+ {
+ return model.getContentKey().getArtifactId();
+ }
+
+ public String getVersion()
+ {
+ return model.getContentKey().getVersion();
+ }
+
+ public String getBaseVersion()
+ {
+ return baseVersion;
+ }
+
+ public boolean isSnapshot()
+ {
+ return snapshot;
+ }
+
+ public String getClassifier()
+ {
+ return model.getClassifier();
+ }
+
+ public String getType()
+ {
+ return model.getType();
+ }
+
+ public boolean hasClassifier()
+ {
+ return StringUtils.isNotEmpty( model.getClassifier() );
+ }
+
+ public String toString()
+ {
+ StringBuffer sb = new StringBuffer();
+ if ( model.getContentKey().getGroupId() != null )
+ {
+ sb.append( model.getContentKey().getGroupId() );
+ sb.append( ":" );
+ }
+ appendArtifactTypeClassifierString( sb );
+ sb.append( ":" );
+ if ( model.getContentKey().getVersion() != null )
+ {
+ sb.append( model.getContentKey().getVersion() );
+ }
+
+ return sb.toString();
+ }
+
+ private void appendArtifactTypeClassifierString( StringBuffer sb )
+ {
+ sb.append( model.getContentKey().getArtifactId() );
+ sb.append( ":" );
+ sb.append( getType() );
+ if ( hasClassifier() )
+ {
+ sb.append( ":" );
+ sb.append( getClassifier() );
+ }
+ }
+
+ private boolean empty( String value )
+ {
+ return value == null || value.trim().length() < 1;
+ }
+
+}
diff --git a/archiva-repository-layer/src/main/java/org/apache/maven/archiva/repository/ArchivaRepository.java b/archiva-repository-layer/src/main/java/org/apache/maven/archiva/repository/ArchivaRepository.java
new file mode 100644
index 000000000..c1fb4f0fe
--- /dev/null
+++ b/archiva-repository-layer/src/main/java/org/apache/maven/archiva/repository/ArchivaRepository.java
@@ -0,0 +1,135 @@
+package org.apache.maven.archiva.repository;
+
+/*
+ * 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.model.ArchivaRepositoryModel;
+import org.apache.maven.artifact.repository.ArtifactRepositoryPolicy;
+
+/**
+ * ArchivaRepository
+ *
+ * @author <a href="mailto:joakim@erdfelt.com">Joakim Erdfelt</a>
+ * @version $Id$
+ */
+public class ArchivaRepository
+{
+ protected ArtifactRepositoryPolicy releases;
+
+ protected ArtifactRepositoryPolicy snapshots;
+
+ private ArchivaRepositoryModel model;
+
+ private RepositoryURL url;
+
+ protected boolean blacklisted;
+
+ /**
+ * Construct a Repository.
+ *
+ * @param id the unique identifier for this repository.
+ * @param name the name for this repository.
+ * @param url the base URL for this repository (this should point to the top level URL for the entire repository)
+ * @param layout the layout technique for this repository.
+ */
+ public ArchivaRepository( String id, String name, String url )
+ {
+ model = new ArchivaRepositoryModel();
+
+ model.setId( id );
+ model.setName( name );
+ setUrl( new RepositoryURL( url ) );
+ }
+
+ /**
+ * Construct a Repository.
+ *
+ * @param id the unique identifier for this repository.
+ * @param name the name for this repository.
+ * @param url the base URL for this repository (this should point to the top level URL for the entire repository)
+ * @param layout the layout technique for this repository.
+ */
+ public ArchivaRepository( ArchivaRepositoryModel model )
+ {
+ this.model = model;
+
+ this.url = new RepositoryURL( model.getUrl() );
+ }
+
+ public String getId()
+ {
+ return model.getId();
+ }
+
+ public void setUrl( RepositoryURL url )
+ {
+ this.url = url;
+ model.setUrl( url.getUrl() );
+ }
+
+ public RepositoryURL getUrl()
+ {
+ return this.url;
+ }
+
+ public ArchivaRepositoryModel getModel()
+ {
+ return this.model;
+ }
+
+ public boolean isBlacklisted()
+ {
+ return blacklisted;
+ }
+
+ public void setBlacklisted( boolean blacklisted )
+ {
+ this.blacklisted = blacklisted;
+ }
+
+ public ArtifactRepositoryPolicy getReleases()
+ {
+ return releases;
+ }
+
+ public void setReleases( ArtifactRepositoryPolicy releases )
+ {
+ this.releases = releases;
+ }
+
+ public ArtifactRepositoryPolicy getSnapshots()
+ {
+ return snapshots;
+ }
+
+ public void setSnapshots( ArtifactRepositoryPolicy snapshots )
+ {
+ this.snapshots = snapshots;
+ }
+
+ public boolean isRemote()
+ {
+ return this.url.getProtocol().equals( "file" );
+ }
+
+ public boolean isManaged()
+ {
+ return this.url.getProtocol().equals( "file" );
+ }
+}
diff --git a/archiva-repository-layer/src/main/java/org/apache/maven/archiva/repository/RepositoryURL.java b/archiva-repository-layer/src/main/java/org/apache/maven/archiva/repository/RepositoryURL.java
new file mode 100644
index 000000000..13ed57fc9
--- /dev/null
+++ b/archiva-repository-layer/src/main/java/org/apache/maven/archiva/repository/RepositoryURL.java
@@ -0,0 +1,156 @@
+package org.apache.maven.archiva.repository;
+
+/*
+ * 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.
+ */
+
+
+/**
+ * RepositoryURL - Mutable (and protocol forgiving) URL object.
+ *
+ * @author <a href="mailto:joakim@erdfelt.com">Joakim Erdfelt</a>
+ * @version $Id$
+ */
+public class RepositoryURL
+{
+ private String url;
+
+ private String protocol;
+
+ private String host;
+
+ private String port;
+
+ private String username;
+
+ private String password;
+
+ private String path;
+
+ public RepositoryURL( String url )
+ {
+ this.url = url;
+
+ // .\ Parse the URL \.____________________________________________
+
+ int pos;
+
+ pos = url.indexOf( "://" );
+ if ( pos == ( -1 ) )
+ {
+ throw new IllegalArgumentException( "Invalid URL, unable to parse protocol:// from " + url );
+ }
+
+ protocol = url.substring( 0, pos );
+
+ // attempt to find the start of the 'path'
+ pos = url.indexOf( "/", protocol.length() + 3 );
+
+ // no path specified - ex "http://localhost"
+ if ( pos == ( -1 ) )
+ {
+ // set pos to end of string. (needed for 'middle section')
+ pos = url.length();
+ // default path
+ path = "/";
+ }
+ else
+ {
+ // get actual path.
+ path = url.substring( pos );
+ }
+
+ // get the middle section ( username : password @ hostname : port )
+ String middle = url.substring( protocol.length() + 3, pos );
+
+ pos = middle.indexOf( '@' );
+
+ // we have an authentication section.
+ if ( pos > 0 )
+ {
+ String authentication = middle.substring( 0, pos );
+ middle = middle.substring( pos + 1 ); // lop off authentication for host:port search
+
+ pos = authentication.indexOf( ':' );
+
+ // we have a password.
+ if ( pos > 0 )
+ {
+ username = authentication.substring( 0, pos );
+ password = authentication.substring( pos + 1 );
+ }
+ else
+ {
+ username = authentication;
+ }
+ }
+
+ pos = middle.indexOf( ':' );
+
+ // we have a defined port
+ if ( pos > 0 )
+ {
+ host = middle.substring( 0, pos );
+ port = middle.substring( pos + 1 );
+ }
+ else
+ {
+ host = middle;
+ }
+ }
+
+ public String toString()
+ {
+ return url;
+ }
+
+ public String getUsername()
+ {
+ return username;
+ }
+
+ public String getPassword()
+ {
+ return password;
+ }
+
+ public String getHost()
+ {
+ return host;
+ }
+
+ public String getPath()
+ {
+ return path;
+ }
+
+ public String getPort()
+ {
+ return port;
+ }
+
+ public String getProtocol()
+ {
+ return protocol;
+ }
+
+ public String getUrl()
+ {
+ return url;
+ }
+}
diff --git a/archiva-repository-layer/src/main/java/org/apache/maven/archiva/repository/connector/RepositoryConnector.java b/archiva-repository-layer/src/main/java/org/apache/maven/archiva/repository/connector/RepositoryConnector.java
index 3d70058fd..f7adfedac 100644
--- a/archiva-repository-layer/src/main/java/org/apache/maven/archiva/repository/connector/RepositoryConnector.java
+++ b/archiva-repository-layer/src/main/java/org/apache/maven/archiva/repository/connector/RepositoryConnector.java
@@ -19,7 +19,7 @@ package org.apache.maven.archiva.repository.connector;
* under the License.
*/
-import org.apache.maven.archiva.model.ArchivaRepository;
+import org.apache.maven.archiva.repository.ArchivaRepository;
import java.util.List;
diff --git a/archiva-repository-layer/src/main/java/org/apache/maven/archiva/repository/consumer/Consumer.java b/archiva-repository-layer/src/main/java/org/apache/maven/archiva/repository/consumer/Consumer.java
new file mode 100644
index 000000000..66b35a232
--- /dev/null
+++ b/archiva-repository-layer/src/main/java/org/apache/maven/archiva/repository/consumer/Consumer.java
@@ -0,0 +1,91 @@
+package org.apache.maven.archiva.repository.consumer;
+
+/*
+ * 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.BaseFile;
+import org.apache.maven.archiva.repository.ArchivaRepository;
+import org.apache.maven.artifact.repository.ArtifactRepository;
+
+import java.util.List;
+
+/**
+ * DiscovererConsumer
+ *
+ * @author <a href="mailto:joakime@apache.org">Joakim Erdfelt</a>
+ * @version $Id$
+ */
+public interface Consumer
+{
+ public static final String ROLE = Consumer.class.getName();
+
+ /**
+ * This is the human readable name for the discoverer.
+ *
+ * @return the human readable discoverer name.
+ */
+ public String getName();
+
+ /**
+ * This is used to initialize any internals in the consumer before it is used.
+ *
+ * This method is called by the internals of archiva and is not meant to be used by other developers.
+ * This method is called once per repository.
+ *
+ * @param repository the repository to initialize the consumer against.
+ * @return true if the repository is valid for this consumer. false will result in consumer being disabled
+ * for the provided repository.
+ */
+ public boolean init( ArchivaRepository repository );
+
+ /**
+ * Get the List of excluded file patterns for this consumer.
+ *
+ * @return the list of excluded file patterns for this consumer.
+ */
+ public List getExcludePatterns();
+
+ /**
+ * Get the List of included file patterns for this consumer.
+ *
+ * @return the list of included file patterns for this consumer.
+ */
+ public List getIncludePatterns();
+
+ /**
+ * Called by archiva framework to indicate that there is a file suitable for consuming,
+ * This method will only be called if the {@link #init(ArtifactRepository)} and {@link #getExcludePatterns()}
+ * and {@link #getIncludePatterns()} all pass for this consumer.
+ *
+ * @param file the file to process.
+ * @throws ConsumerException if there was a problem processing this file.
+ */
+ public void processFile( BaseFile file ) throws ConsumerException;
+
+ /**
+ * Called by archiva framework to indicate that there has been a problem detected
+ * on a specific file.
+ *
+ * NOTE: It is very possible for 1 file to have more than 1 problem associated with it.
+ *
+ * @param file the file to process.
+ * @param message the message describing the problem.
+ */
+ public void processFileProblem( BaseFile file, String message );
+}
diff --git a/archiva-repository-layer/src/main/java/org/apache/maven/archiva/repository/consumer/ConsumerException.java b/archiva-repository-layer/src/main/java/org/apache/maven/archiva/repository/consumer/ConsumerException.java
new file mode 100644
index 000000000..709be8e6d
--- /dev/null
+++ b/archiva-repository-layer/src/main/java/org/apache/maven/archiva/repository/consumer/ConsumerException.java
@@ -0,0 +1,52 @@
+package org.apache.maven.archiva.repository.consumer;
+
+/*
+ * 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.ArchivaException;
+import org.apache.maven.archiva.common.utils.BaseFile;
+
+/**
+ * ConsumerException - details about the failure of a consumer.
+ *
+ * @author <a href="mailto:joakim@erdfelt.com">Joakim Erdfelt</a>
+ * @version $Id$
+ */
+public class ConsumerException
+ extends ArchivaException
+{
+ private BaseFile file;
+
+ public ConsumerException( BaseFile file, String message, Throwable cause )
+ {
+ super( message, cause );
+ this.file = file;
+ }
+
+ public ConsumerException( BaseFile file, String message )
+ {
+ super( message );
+ this.file = file;
+ }
+
+ public BaseFile getFile()
+ {
+ return file;
+ }
+}
diff --git a/archiva-repository-layer/src/main/java/org/apache/maven/archiva/repository/consumer/ConsumerFactory.java b/archiva-repository-layer/src/main/java/org/apache/maven/archiva/repository/consumer/ConsumerFactory.java
new file mode 100644
index 000000000..00c88064d
--- /dev/null
+++ b/archiva-repository-layer/src/main/java/org/apache/maven/archiva/repository/consumer/ConsumerFactory.java
@@ -0,0 +1,70 @@
+package org.apache.maven.archiva.repository.consumer;
+
+/*
+ * 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.codehaus.plexus.PlexusConstants;
+import org.codehaus.plexus.PlexusContainer;
+import org.codehaus.plexus.context.Context;
+import org.codehaus.plexus.context.ContextException;
+import org.codehaus.plexus.logging.AbstractLogEnabled;
+import org.codehaus.plexus.personality.plexus.lifecycle.phase.Contextualizable;
+
+/**
+ * DiscovererConsumerFactory - factory for consumers.
+ *
+ * @author <a href="mailto:joakim@erdfelt.com">Joakim Erdfelt</a>
+ * @version $Id$
+ * @plexus.component role="org.apache.maven.archiva.common.consumers.ConsumerFactory"
+ */
+public class ConsumerFactory
+ extends AbstractLogEnabled
+ implements Contextualizable
+{
+ public static final String ROLE = ConsumerFactory.class.getName();
+
+ private PlexusContainer container;
+
+ public Consumer createConsumer( String name )
+ throws ConsumerException
+ {
+ getLogger().info( "Attempting to create consumer [" + name + "]" );
+
+ Consumer consumer;
+ try
+ {
+ consumer = (Consumer) container.lookup( Consumer.ROLE, name, container.getLookupRealm() );
+ }
+ catch ( Throwable t )
+ {
+ String emsg = "Unable to create consumer [" + name + "]: " + t.getMessage();
+ getLogger().warn( t.getMessage(), t );
+ throw new ConsumerException( null, emsg, t );
+ }
+
+ getLogger().info( "Created consumer [" + name + "|" + consumer.getName() + "]" );
+ return consumer;
+ }
+
+ public void contextualize( Context context )
+ throws ContextException
+ {
+ container = (PlexusContainer) context.get( PlexusConstants.PLEXUS_KEY );
+ }
+}
diff --git a/archiva-repository-layer/src/main/java/org/apache/maven/archiva/repository/content/AbstractArtifactExtensionMapping.java b/archiva-repository-layer/src/main/java/org/apache/maven/archiva/repository/content/AbstractArtifactExtensionMapping.java
new file mode 100644
index 000000000..dbdfd3bfd
--- /dev/null
+++ b/archiva-repository-layer/src/main/java/org/apache/maven/archiva/repository/content/AbstractArtifactExtensionMapping.java
@@ -0,0 +1,58 @@
+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.repository.ArchivaArtifact;
+
+import java.util.HashMap;
+import java.util.Map;
+
+/**
+ * AbstractArtifactExtensionMapping
+ *
+ * @author <a href="mailto:joakim@erdfelt.com">Joakim Erdfelt</a>
+ * @version $Id$
+ */
+public abstract class AbstractArtifactExtensionMapping implements ArtifactExtensionMapping
+{
+ protected final Map typeToExtensionMap;
+
+ public AbstractArtifactExtensionMapping()
+ {
+ typeToExtensionMap = new HashMap();
+ typeToExtensionMap.put( "ejb-client", "jar" );
+ typeToExtensionMap.put( "ejb", "jar" );
+ typeToExtensionMap.put( "distribution-tgz", "tar.gz" );
+ typeToExtensionMap.put( "distribution-zip", "zip" );
+ typeToExtensionMap.put( "java-source", "jar" );
+ }
+
+ public String getExtension( ArchivaArtifact artifact )
+ {
+ // Try specialized types first.
+ if ( typeToExtensionMap.containsKey( artifact.getType() ) )
+ {
+ return (String) typeToExtensionMap.get( artifact.getType() );
+ }
+
+ // Return type
+ return artifact.getType();
+ }
+}
diff --git a/archiva-repository-layer/src/main/java/org/apache/maven/archiva/repository/content/ArtifactExtensionMapping.java b/archiva-repository-layer/src/main/java/org/apache/maven/archiva/repository/content/ArtifactExtensionMapping.java
new file mode 100644
index 000000000..0f6c990e7
--- /dev/null
+++ b/archiva-repository-layer/src/main/java/org/apache/maven/archiva/repository/content/ArtifactExtensionMapping.java
@@ -0,0 +1,36 @@
+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.repository.ArchivaArtifact;
+
+/**
+ * ArtifactExtensionMapping - Utility to provide the mapping between an Artifact's extension and it's type and
+ * vice versa.
+ *
+ * @author <a href="mailto:joakim@erdfelt.com">Joakim Erdfelt</a>
+ * @version $Id$
+ */
+public interface ArtifactExtensionMapping
+{
+ public String getExtension( ArchivaArtifact artifact );
+
+ public String getType( String filename );
+}
diff --git a/archiva-repository-layer/src/main/java/org/apache/maven/archiva/repository/content/BidirectionalRepositoryLayout.java b/archiva-repository-layer/src/main/java/org/apache/maven/archiva/repository/content/BidirectionalRepositoryLayout.java
index 9f10e3f3f..4e46722f1 100644
--- a/archiva-repository-layer/src/main/java/org/apache/maven/archiva/repository/content/BidirectionalRepositoryLayout.java
+++ b/archiva-repository-layer/src/main/java/org/apache/maven/archiva/repository/content/BidirectionalRepositoryLayout.java
@@ -19,11 +19,11 @@ package org.apache.maven.archiva.repository.content;
* under the License.
*/
-import org.apache.maven.archiva.model.ArchivaArtifact;
+import org.apache.maven.archiva.repository.ArchivaArtifact;
/**
* BidirectionalRepositoryLayout - Similar in scope to ArtifactRepositoryLayout, but does
- * the both the Path to Artifact and Artifact to Path conversions.
+ * the both the Path to Artifact, and Artifact to Path conversions.
*
* @author <a href="mailto:joakim@erdfelt.com">Joakim Erdfelt</a>
* @version $Id$
@@ -31,12 +31,25 @@ import org.apache.maven.archiva.model.ArchivaArtifact;
public interface BidirectionalRepositoryLayout
{
/**
- * Given an ArchivaArtifact
+ * Get the identifier for this layout.
*
- * @param artifact
- * @return
+ * @return the identifier for this layout.
+ */
+ public String getId();
+
+ /**
+ * Given an ArchivaArtifact, return the relative path to the artifact.
+ *
+ * @param artifact the artifact to compute the path of.
+ * @return the relative path to the artifact.
*/
public String pathOf( ArchivaArtifact artifact );
+ /**
+ * Given a repository relative path to a filename, return the ArchivaArtifact object suitable for the path.
+ *
+ * @param path the path relative to the repository base dir for the artifact.
+ * @return the ArchivaArtifact representing the path. (or null if path cannot be converted to an ArchivaArtifact)
+ */
ArchivaArtifact toArtifact( String path );
}
diff --git a/archiva-repository-layer/src/main/java/org/apache/maven/archiva/repository/content/DefaultArtifactExtensionMapping.java b/archiva-repository-layer/src/main/java/org/apache/maven/archiva/repository/content/DefaultArtifactExtensionMapping.java
new file mode 100644
index 000000000..70f036259
--- /dev/null
+++ b/archiva-repository-layer/src/main/java/org/apache/maven/archiva/repository/content/DefaultArtifactExtensionMapping.java
@@ -0,0 +1,76 @@
+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;
+
+/**
+ * DefaultArtifactExtensionMapping - extension mapping for Maven 2.x projects.
+ *
+ * @author <a href="mailto:joakim@erdfelt.com">Joakim Erdfelt</a>
+ * @version $Id$
+ *
+ * @plexus.component role="org.apache.maven.archiva.repository.content.ArtifactExtensionMapping"
+ * role-hint="default"
+ */
+public class DefaultArtifactExtensionMapping extends AbstractArtifactExtensionMapping
+ implements ArtifactExtensionMapping
+{
+ public DefaultArtifactExtensionMapping()
+ {
+ super();
+ }
+
+ public String getType( String filename )
+ {
+ if ( StringUtils.isBlank( filename ) )
+ {
+ return null;
+ }
+
+ String normalizedName = filename.toLowerCase().trim();
+
+ if ( normalizedName.endsWith( ".tar.gz" ) )
+ {
+ return "distribution-tgz";
+ }
+ else if ( normalizedName.endsWith( ".zip" ) )
+ {
+ return "distribution-zip";
+ }
+ else if ( normalizedName.endsWith( "-sources.jar" ) )
+ {
+ return "java-source";
+ }
+ // TODO: handle type for -javadoc.jar ?
+ else
+ {
+ int index = normalizedName.lastIndexOf( '.' );
+ if ( index >= 0 )
+ {
+ return normalizedName.substring( index + 1 );
+ }
+ else
+ {
+ throw new IllegalArgumentException( "Filename " + filename + " does not have an extension." );
+ }
+ }
+ }
+}
diff --git a/archiva-repository-layer/src/main/java/org/apache/maven/archiva/repository/content/DefaultBidirectionalRepositoryLayout.java b/archiva-repository-layer/src/main/java/org/apache/maven/archiva/repository/content/DefaultBidirectionalRepositoryLayout.java
new file mode 100644
index 000000000..a199c1eef
--- /dev/null
+++ b/archiva-repository-layer/src/main/java/org/apache/maven/archiva/repository/content/DefaultBidirectionalRepositoryLayout.java
@@ -0,0 +1,78 @@
+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.repository.ArchivaArtifact;
+
+/**
+ * DefaultBidirectionalRepositoryLayout - the layout mechanism for use by Maven 2.x repositories.
+ *
+ * @author <a href="mailto:joakim@erdfelt.com">Joakim Erdfelt</a>
+ * @version $Id$
+ *
+ * @plexus.component role="org.apache.maven.archiva.repository.content.BidirectionalRepositoryLayout"
+ * role-hint="default"
+ */
+public class DefaultBidirectionalRepositoryLayout implements BidirectionalRepositoryLayout
+{
+ private static final char PATH_SEPARATOR = '/';
+
+ private static final char GROUP_SEPARATOR = '.';
+
+ private static final char ARTIFACT_SEPARATOR = '-';
+
+ private ArtifactExtensionMapping extensionMapper = new DefaultArtifactExtensionMapping();
+
+ public String getId()
+ {
+ return "default";
+ }
+
+ public String pathOf( ArchivaArtifact artifact )
+ {
+ StringBuffer path = new StringBuffer();
+
+ path.append( formatAsDirectory( artifact.getGroupId() ) ).append( PATH_SEPARATOR );
+ path.append( artifact.getArtifactId() ).append( PATH_SEPARATOR );
+ path.append( artifact.getBaseVersion() ).append( PATH_SEPARATOR );
+ path.append( artifact.getArtifactId() ).append( ARTIFACT_SEPARATOR ).append( artifact.getVersion() );
+
+ if ( artifact.hasClassifier() )
+ {
+ path.append( ARTIFACT_SEPARATOR ).append( artifact.getClassifier() );
+ }
+
+ path.append( GROUP_SEPARATOR ).append( extensionMapper.getExtension( artifact ) );
+
+ return path.toString();
+ }
+
+ private String formatAsDirectory( String directory )
+ {
+ return directory.replace( GROUP_SEPARATOR, PATH_SEPARATOR );
+ }
+
+ public ArchivaArtifact toArtifact( String path )
+ {
+
+
+ return null;
+ }
+}
diff --git a/archiva-repository-layer/src/main/java/org/apache/maven/archiva/repository/content/LegacyArtifactExtensionMapping.java b/archiva-repository-layer/src/main/java/org/apache/maven/archiva/repository/content/LegacyArtifactExtensionMapping.java
new file mode 100644
index 000000000..10fd815c8
--- /dev/null
+++ b/archiva-repository-layer/src/main/java/org/apache/maven/archiva/repository/content/LegacyArtifactExtensionMapping.java
@@ -0,0 +1,76 @@
+package org.apache.maven.archiva.repository.content;
+
+import org.apache.commons.lang.StringUtils;
+
+/*
+ * 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.
+ */
+
+/**
+ * LegacyArtifactExtensionMapping
+ *
+ * @author <a href="mailto:joakim@erdfelt.com">Joakim Erdfelt</a>
+ * @version $Id$
+ *
+ * @plexus.component role="org.apache.maven.archiva.repository.content.ArtifactExtensionMapping"
+ * role-hint="legacy"
+ */
+public class LegacyArtifactExtensionMapping extends AbstractArtifactExtensionMapping
+ implements ArtifactExtensionMapping
+{
+ public LegacyArtifactExtensionMapping()
+ {
+ super();
+ }
+
+ public String getType( String filename )
+ {
+ if ( StringUtils.isBlank( filename ) )
+ {
+ return null;
+ }
+
+ String normalizedName = filename.toLowerCase().trim();
+
+ if ( normalizedName.endsWith( ".tar.gz" ) )
+ {
+ return "distribution-tgz";
+ }
+ else if ( normalizedName.endsWith( ".zip" ) )
+ {
+ return "distribution-zip";
+ }
+ else if ( normalizedName.endsWith( "-sources.jar" ) )
+ {
+ return "java-source";
+ }
+ // TODO: handle type for -javadoc.jar ?
+ else
+ {
+ int index = normalizedName.lastIndexOf( '.' );
+ if ( index >= 0 )
+ {
+ return normalizedName.substring( index + 1 );
+ }
+ else
+ {
+ throw new IllegalArgumentException( "Filename " + filename + " does not have an extension." );
+ }
+ }
+ }
+}
diff --git a/archiva-repository-layer/src/main/java/org/apache/maven/archiva/repository/content/LegacyBidirectionalRepositoryLayout.java b/archiva-repository-layer/src/main/java/org/apache/maven/archiva/repository/content/LegacyBidirectionalRepositoryLayout.java
new file mode 100644
index 000000000..a739c9b96
--- /dev/null
+++ b/archiva-repository-layer/src/main/java/org/apache/maven/archiva/repository/content/LegacyBidirectionalRepositoryLayout.java
@@ -0,0 +1,101 @@
+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.repository.ArchivaArtifact;
+
+import java.util.HashMap;
+import java.util.Map;
+
+/**
+ * LegacyBidirectionalRepositoryLayout - the layout mechanism for use by Maven 1.x repositories.
+ *
+ * @author <a href="mailto:joakim@erdfelt.com">Joakim Erdfelt</a>
+ * @version $Id$
+ *
+ * @plexus.component role="org.apache.maven.archiva.repository.content.BidirectionalRepositoryLayout"
+ * role-hint="legacy"
+ */
+public class LegacyBidirectionalRepositoryLayout implements BidirectionalRepositoryLayout
+{
+ private static final String PATH_SEPARATOR = "/";
+
+ private ArtifactExtensionMapping extensionMapper = new LegacyArtifactExtensionMapping();
+
+ private Map typeToDirectoryMap;
+
+ public LegacyBidirectionalRepositoryLayout()
+ {
+ typeToDirectoryMap = new HashMap();
+ typeToDirectoryMap.put( "ejb-client", "ejb" );
+ typeToDirectoryMap.put( "distribution-tgz", "distribution" );
+ typeToDirectoryMap.put( "distribution-zip", "distribution" );
+ }
+
+ public String getId()
+ {
+ return "legacy";
+ }
+
+ public String pathOf( ArchivaArtifact artifact )
+ {
+ StringBuffer path = new StringBuffer();
+
+ path.append( artifact.getGroupId() ).append( PATH_SEPARATOR );
+ path.append( getDirectory( artifact ) ).append( PATH_SEPARATOR );
+ path.append( artifact.getArtifactId() ).append( '-' ).append( artifact.getVersion() );
+
+ if ( artifact.hasClassifier() )
+ {
+ path.append( '-' ).append( artifact.getClassifier() );
+ }
+
+ path.append( '.' ).append( extensionMapper.getExtension( artifact ) );
+
+ return path.toString();
+ }
+
+ private String getDirectory( ArchivaArtifact artifact )
+ {
+ // Special Cases involving classifiers and type.
+ if ( "jar".equals( artifact.getType() ) && "sources".equals( artifact.getClassifier() ) )
+ {
+ return "javadoc.jars";
+ }
+
+ // Special Cases involving only type.
+ String dirname = (String) typeToDirectoryMap.get( artifact.getType() );
+
+ if ( dirname != null )
+ {
+ return dirname + "s";
+ }
+
+ // Default process.
+ return artifact.getType() + "s";
+ }
+
+ public ArchivaArtifact toArtifact( String path )
+ {
+ // TODO Auto-generated method stub
+ return null;
+ }
+
+}
diff --git a/archiva-repository-layer/src/main/java/org/apache/maven/archiva/repository/scanner/RepositoryScanner.java b/archiva-repository-layer/src/main/java/org/apache/maven/archiva/repository/scanner/RepositoryScanner.java
index fab8d1a33..568c07c9c 100644
--- a/archiva-repository-layer/src/main/java/org/apache/maven/archiva/repository/scanner/RepositoryScanner.java
+++ b/archiva-repository-layer/src/main/java/org/apache/maven/archiva/repository/scanner/RepositoryScanner.java
@@ -19,10 +19,10 @@ package org.apache.maven.archiva.repository.scanner;
* under the License.
*/
-import org.apache.maven.archiva.consumers.Consumer;
-import org.apache.maven.archiva.model.ArchivaRepository;
import org.apache.maven.archiva.model.RepositoryContentStatistics;
+import org.apache.maven.archiva.repository.ArchivaRepository;
import org.apache.maven.archiva.repository.RepositoryException;
+import org.apache.maven.archiva.repository.consumer.Consumer;
import org.codehaus.plexus.util.DirectoryWalker;
import org.codehaus.plexus.util.FileUtils;
@@ -103,12 +103,12 @@ public class RepositoryScanner
throw new IllegalArgumentException( "Unable to operate on a null repository." );
}
- if ( !"file".equals( repository.getRepositoryURL().getProtocol() ) )
+ if ( !"file".equals( repository.getUrl().getProtocol() ) )
{
throw new UnsupportedOperationException( "Only filesystem repositories are supported." );
}
- File repositoryBase = new File( repository.getRepositoryURL().getPath() );
+ File repositoryBase = new File( repository.getUrl().getPath() );
if ( !repositoryBase.exists() )
{
diff --git a/archiva-repository-layer/src/main/java/org/apache/maven/archiva/repository/scanner/RepositoryScannerInstance.java b/archiva-repository-layer/src/main/java/org/apache/maven/archiva/repository/scanner/RepositoryScannerInstance.java
index 70554f73d..349618273 100644
--- a/archiva-repository-layer/src/main/java/org/apache/maven/archiva/repository/scanner/RepositoryScannerInstance.java
+++ b/archiva-repository-layer/src/main/java/org/apache/maven/archiva/repository/scanner/RepositoryScannerInstance.java
@@ -21,10 +21,9 @@ package org.apache.maven.archiva.repository.scanner;
import org.apache.commons.lang.SystemUtils;
import org.apache.maven.archiva.common.utils.BaseFile;
-import org.apache.maven.archiva.consumers.Consumer;
-import org.apache.maven.archiva.model.ArchivaRepository;
import org.apache.maven.archiva.model.RepositoryContentStatistics;
-import org.apache.maven.artifact.repository.ArtifactRepository;
+import org.apache.maven.archiva.repository.ArchivaRepository;
+import org.apache.maven.archiva.repository.consumer.Consumer;
import org.codehaus.plexus.util.DirectoryWalkListener;
import org.codehaus.plexus.util.SelectorUtils;
import org.codehaus.plexus.util.StringUtils;
@@ -88,7 +87,7 @@ public class RepositoryScannerInstance implements DirectoryWalkListener
public void directoryWalkStarting( File basedir )
{
- log.info( "Walk Started: [" + this.repository.getId() + "] " + this.repository.getRepositoryURL() );
+ log.info( "Walk Started: [" + this.repository.getId() + "] " + this.repository.getUrl() );
stats.triggerStart();
}
@@ -110,7 +109,7 @@ public class RepositoryScannerInstance implements DirectoryWalkListener
{
stats.increaseNewFileCount();
- BaseFile basefile = new BaseFile( repository.getRepositoryURL().getPath(), file );
+ BaseFile basefile = new BaseFile( repository.getUrl().getPath(), file );
Iterator itConsumers = this.consumers.iterator();
while ( itConsumers.hasNext() )
@@ -144,7 +143,7 @@ public class RepositoryScannerInstance implements DirectoryWalkListener
public void directoryWalkFinished()
{
- log.info( "Walk Finished: [" + this.repository.getId() + "] " + this.repository.getRepositoryURL() );
+ log.info( "Walk Finished: [" + this.repository.getId() + "] " + this.repository.getUrl() );
stats.triggerFinished();
}
diff --git a/archiva-repository-layer/src/test/java/org/apache/maven/archiva/repository/RepositoryURLTest.java b/archiva-repository-layer/src/test/java/org/apache/maven/archiva/repository/RepositoryURLTest.java
index a7aac9513..c91eef8c8 100644
--- a/archiva-repository-layer/src/test/java/org/apache/maven/archiva/repository/RepositoryURLTest.java
+++ b/archiva-repository-layer/src/test/java/org/apache/maven/archiva/repository/RepositoryURLTest.java
@@ -19,7 +19,6 @@ package org.apache.maven.archiva.repository;
* under the License.
*/
-import org.apache.maven.archiva.common.utils.RepositoryURL;
import java.net.MalformedURLException;
diff --git a/archiva-repository-layer/src/test/java/org/apache/maven/archiva/repository/content/AbstractBidirectionalRepositoryLayoutTestCase.java b/archiva-repository-layer/src/test/java/org/apache/maven/archiva/repository/content/AbstractBidirectionalRepositoryLayoutTestCase.java
new file mode 100644
index 000000000..c2eca44af
--- /dev/null
+++ b/archiva-repository-layer/src/test/java/org/apache/maven/archiva/repository/content/AbstractBidirectionalRepositoryLayoutTestCase.java
@@ -0,0 +1,93 @@
+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.repository.ArchivaArtifact;
+import org.apache.maven.archiva.repository.ArchivaRepository;
+import org.codehaus.plexus.PlexusTestCase;
+
+import java.io.File;
+
+/**
+ * AbstractBidirectionalRepositoryLayoutTestCase
+ *
+ * @author <a href="mailto:joakim@erdfelt.com">Joakim Erdfelt</a>
+ * @version $Id$
+ */
+public class AbstractBidirectionalRepositoryLayoutTestCase extends PlexusTestCase
+{
+ protected ArchivaRepository repository;
+
+ protected void setUp() throws Exception
+ {
+ super.setUp();
+
+ repository = createTestRepository();
+ }
+
+ protected ArchivaRepository createTestRepository()
+ {
+ File targetDir = new File( getBasedir(), "target" );
+ File testRepo = new File( targetDir, "test-repo" );
+
+ if ( !testRepo.exists() )
+ {
+ testRepo.mkdirs();
+ }
+
+ String repoUri = "file://" + StringUtils.replace( testRepo.getAbsolutePath(), "\\", "/" ) ;
+
+ ArchivaRepository repo = new ArchivaRepository( "testRepo", "Test Repository", repoUri );
+
+ return repo;
+ }
+
+ protected ArchivaArtifact createArtifact( String groupId, String artifactId, String version, String classifier, String type )
+ {
+ ArchivaArtifact artifact = new ArchivaArtifact( repository, groupId, artifactId, version, classifier, type );
+ assertNotNull( artifact );
+ return artifact;
+ }
+
+ protected void assertArtifact( ArchivaArtifact actualArtifact, String groupId, String artifactId, String version, String classifier, String type )
+ {
+ String expectedId = groupId + ":" + artifactId + ":" + version + ":" + classifier + ":" + type;
+
+ assertEquals( expectedId + " - Group ID", actualArtifact.getGroupId(), groupId );
+ assertEquals( expectedId + " - Artifact ID", actualArtifact.getArtifactId(), artifactId );
+ assertEquals( expectedId + " - Version ID", actualArtifact.getVersion(), version );
+ assertEquals( expectedId + " - Classifier", actualArtifact.getClassifier(), classifier );
+ assertEquals( expectedId + " - Type", actualArtifact.getType(), type );
+ }
+
+ protected void assertSnapshotArtifact( ArchivaArtifact actualArtifact, String groupId, String artifactId, String version, String classifier, String type )
+ {
+ String expectedId = groupId + ":" + artifactId + ":" + version + ":" + classifier + ":" + type;
+
+ assertEquals( expectedId + " - Group ID", actualArtifact.getGroupId(), groupId );
+ assertEquals( expectedId + " - Artifact ID", actualArtifact.getArtifactId(), artifactId );
+ assertEquals( expectedId + " - Version ID", actualArtifact.getVersion(), version );
+ assertEquals( expectedId + " - Classifier", actualArtifact.getClassifier(), classifier );
+ assertEquals( expectedId + " - Type", actualArtifact.getType(), type );
+ assertTrue( expectedId + " - Snapshot", actualArtifact.isSnapshot() );
+ }
+
+}
diff --git a/archiva-repository-layer/src/test/java/org/apache/maven/archiva/repository/content/DefaultBidirectionalRepositoryLayoutTest.java b/archiva-repository-layer/src/test/java/org/apache/maven/archiva/repository/content/DefaultBidirectionalRepositoryLayoutTest.java
new file mode 100644
index 000000000..a2e186fff
--- /dev/null
+++ b/archiva-repository-layer/src/test/java/org/apache/maven/archiva/repository/content/DefaultBidirectionalRepositoryLayoutTest.java
@@ -0,0 +1,96 @@
+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.repository.ArchivaArtifact;
+
+/**
+ * DefaultBidirectionalRepositoryLayoutTest
+ *
+ * @author <a href="mailto:joakim@erdfelt.com">Joakim Erdfelt</a>
+ * @version $Id$
+ */
+public class DefaultBidirectionalRepositoryLayoutTest extends AbstractBidirectionalRepositoryLayoutTestCase
+{
+ private BidirectionalRepositoryLayout layout;
+
+ protected void setUp() throws Exception
+ {
+ super.setUp();
+
+ layout = (BidirectionalRepositoryLayout) lookup( BidirectionalRepositoryLayout.class.getName(), "default" );
+ }
+
+ public void testToPathBasic()
+ {
+ ArchivaArtifact artifact = createArtifact( "com.foo", "foo-tool", "1.0", "", "jar" );
+
+ assertEquals( "com/foo/foo-tool/1.0/foo-tool-1.0.jar", layout.pathOf( artifact ) );
+ }
+
+ public void testToPathEjbClient()
+ {
+ ArchivaArtifact artifact = createArtifact( "com.foo", "foo-client", "1.0", "", "ejb-client" );
+
+ assertEquals( "com/foo/foo-client/1.0/foo-client-1.0.jar", layout.pathOf( artifact ) );
+ }
+
+ public void testToPathWithClassifier()
+ {
+ ArchivaArtifact artifact = createArtifact( "com.foo.lib", "foo-lib", "2.1-alpha-1", "sources", "jar" );
+
+ assertEquals( "com/foo/lib/foo-lib/2.1-alpha-1/foo-lib-2.1-alpha-1-sources.jar", layout.pathOf( artifact ) );
+ }
+
+ public void testToPathUsingUniqueSnapshot()
+ {
+ ArchivaArtifact artifact = createArtifact( "com.foo", "foo-connector", "2.1-20060822.123456-35", "", "jar" );
+
+ assertEquals( "com/foo/foo-connector/2.1-SNAPSHOT/foo-connector-2.1-20060822.123456-35.jar",
+ layout.pathOf( artifact ) );
+ }
+
+ public void testToArtifactBasic()
+ {
+ ArchivaArtifact artifact = layout.toArtifact( "com/foo/foo-tool/1.0/foo-tool-1.0.jar" );
+ assertArtifact( artifact, "com.foo", "foo-tool", "1.0", "", "jar" );
+ }
+
+ public void testToArtifactEjbClient()
+ {
+ ArchivaArtifact artifact = layout.toArtifact( "com/foo/foo-client/1.0/foo-client-1.0.jar" );
+ // The type is correct. as we cannot possibly know this is an ejb client without parsing the pom
+ assertArtifact( artifact, "com.foo", "foo-client", "1.0", "", "jar" );
+ }
+
+ public void testToArtifactWithClassifier()
+ {
+ ArchivaArtifact artifact =
+ layout.toArtifact( "com/foo/lib/foo-lib/2.1-alpha-1/foo-lib-2.1-alpha-1-sources.jar" );
+ assertArtifact( artifact, "com.foo.lib", "foo-lib", "2.1-alpha-1", "sources", "jar" );
+ }
+
+ public void testToArtifactUsingUniqueSnapshot()
+ {
+ ArchivaArtifact artifact =
+ layout.toArtifact( "com/foo/foo-connector/2.1-SNAPSHOT/foo-connector-2.1-20060822.123456-35.jar" );
+ assertSnapshotArtifact( artifact, "com.foo", "foo-connector", "2.1-20060822.123456-35", "", "jar" );
+ }
+}
diff --git a/archiva-repository-layer/src/test/java/org/apache/maven/archiva/repository/content/LegacyBidirectionalRepositoryLayoutTest.java b/archiva-repository-layer/src/test/java/org/apache/maven/archiva/repository/content/LegacyBidirectionalRepositoryLayoutTest.java
new file mode 100644
index 000000000..af61e1e34
--- /dev/null
+++ b/archiva-repository-layer/src/test/java/org/apache/maven/archiva/repository/content/LegacyBidirectionalRepositoryLayoutTest.java
@@ -0,0 +1,69 @@
+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.repository.ArchivaArtifact;
+
+/**
+ * LegacyBidirectionalRepositoryLayoutTest
+ *
+ * @author <a href="mailto:joakim@erdfelt.com">Joakim Erdfelt</a>
+ * @version $Id$
+ */
+public class LegacyBidirectionalRepositoryLayoutTest extends AbstractBidirectionalRepositoryLayoutTestCase
+{
+ private BidirectionalRepositoryLayout layout;
+
+ protected void setUp() throws Exception
+ {
+ super.setUp();
+
+ layout = (BidirectionalRepositoryLayout) lookup( BidirectionalRepositoryLayout.class.getName(), "legacy" );
+ }
+
+ public void testToPathBasic()
+ {
+ ArchivaArtifact artifact = createArtifact( "com.foo", "foo-tool", "1.0", "", "jar" );
+
+ assertEquals( "com.foo/jars/foo-tool-1.0.jar", layout.pathOf( artifact ) );
+ }
+
+ public void testToPathEjbClient()
+ {
+ ArchivaArtifact artifact = createArtifact( "com.foo", "foo-client", "1.0", "", "ejb-client" );
+
+ assertEquals( "com.foo/ejbs/foo-client-1.0.jar", layout.pathOf( artifact ) );
+ }
+
+ public void testToPathWithClassifier()
+ {
+ ArchivaArtifact artifact = createArtifact( "com.foo.lib", "foo-lib", "2.1-alpha-1", "sources", "jar" );
+
+ assertEquals( "com.foo.lib/javadoc.jars/foo-lib-2.1-alpha-1-sources.jar", layout.pathOf( artifact ) );
+ }
+
+ public void testToPathUsingUniqueSnapshot()
+ {
+ ArchivaArtifact artifact = createArtifact( "com.foo", "foo-connector", "2.1-20060822.123456-35", "", "jar" );
+
+ assertEquals( "com.foo/jars/foo-connector-2.1-20060822.123456-35.jar",
+ layout.pathOf( artifact ) );
+ }
+}