From f5da04241399259534e7a02cdabc8bf3c5e7d66d Mon Sep 17 00:00:00 2001 From: Joakim Erdfelt Date: Thu, 15 Mar 2007 22:44:49 +0000 Subject: [PATCH] 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 --- .../maven/archiva/database/ArchivaDAO.java | 24 +-- .../archiva/database/jdo/JdoArchivaDAO.java | 37 ++-- .../model/AbstractArchivaArtifact.java | 139 --------------- archiva-model/src/main/mdo/archiva.xml | 33 ++-- archiva-repository-layer/pom.xml | 4 - .../archiva/repository/ArchivaArtifact.java | 165 ++++++++++++++++++ .../archiva/repository/ArchivaRepository.java | 78 +++++---- .../archiva/repository}/RepositoryURL.java | 2 +- .../connector/RepositoryConnector.java | 2 +- .../archiva/repository/consumer/Consumer.java | 91 ++++++++++ .../consumer/ConsumerException.java | 52 ++++++ .../repository/consumer/ConsumerFactory.java | 70 ++++++++ .../AbstractArtifactExtensionMapping.java | 58 ++++++ .../content/ArtifactExtensionMapping.java | 36 ++++ .../BidirectionalRepositoryLayout.java | 23 ++- .../DefaultArtifactExtensionMapping.java | 76 ++++++++ .../DefaultBidirectionalRepositoryLayout.java | 78 +++++++++ .../LegacyArtifactExtensionMapping.java | 76 ++++++++ .../LegacyBidirectionalRepositoryLayout.java | 101 +++++++++++ .../repository/scanner/RepositoryScanner.java | 8 +- .../scanner/RepositoryScannerInstance.java | 11 +- .../archiva/repository/RepositoryURLTest.java | 1 - ...BidirectionalRepositoryLayoutTestCase.java | 93 ++++++++++ ...aultBidirectionalRepositoryLayoutTest.java | 96 ++++++++++ ...gacyBidirectionalRepositoryLayoutTest.java | 69 ++++++++ 25 files changed, 1184 insertions(+), 239 deletions(-) delete mode 100644 archiva-model/src/main/java/org/apache/maven/archiva/model/AbstractArchivaArtifact.java create mode 100644 archiva-repository-layer/src/main/java/org/apache/maven/archiva/repository/ArchivaArtifact.java rename archiva-model/src/main/java/org/apache/maven/archiva/model/AbstractArchivaRepository.java => archiva-repository-layer/src/main/java/org/apache/maven/archiva/repository/ArchivaRepository.java (61%) rename {archiva-common/src/main/java/org/apache/maven/archiva/common/utils => archiva-repository-layer/src/main/java/org/apache/maven/archiva/repository}/RepositoryURL.java (98%) create mode 100644 archiva-repository-layer/src/main/java/org/apache/maven/archiva/repository/consumer/Consumer.java create mode 100644 archiva-repository-layer/src/main/java/org/apache/maven/archiva/repository/consumer/ConsumerException.java create mode 100644 archiva-repository-layer/src/main/java/org/apache/maven/archiva/repository/consumer/ConsumerFactory.java create mode 100644 archiva-repository-layer/src/main/java/org/apache/maven/archiva/repository/content/AbstractArtifactExtensionMapping.java create mode 100644 archiva-repository-layer/src/main/java/org/apache/maven/archiva/repository/content/ArtifactExtensionMapping.java create mode 100644 archiva-repository-layer/src/main/java/org/apache/maven/archiva/repository/content/DefaultArtifactExtensionMapping.java create mode 100644 archiva-repository-layer/src/main/java/org/apache/maven/archiva/repository/content/DefaultBidirectionalRepositoryLayout.java create mode 100644 archiva-repository-layer/src/main/java/org/apache/maven/archiva/repository/content/LegacyArtifactExtensionMapping.java create mode 100644 archiva-repository-layer/src/main/java/org/apache/maven/archiva/repository/content/LegacyBidirectionalRepositoryLayout.java create mode 100644 archiva-repository-layer/src/test/java/org/apache/maven/archiva/repository/content/AbstractBidirectionalRepositoryLayoutTestCase.java create mode 100644 archiva-repository-layer/src/test/java/org/apache/maven/archiva/repository/content/DefaultBidirectionalRepositoryLayoutTest.java create mode 100644 archiva-repository-layer/src/test/java/org/apache/maven/archiva/repository/content/LegacyBidirectionalRepositoryLayoutTest.java diff --git a/archiva-database/src/main/java/org/apache/maven/archiva/database/ArchivaDAO.java b/archiva-database/src/main/java/org/apache/maven/archiva/database/ArchivaDAO.java index ef56ad1b1..5dbd6bfe8 100644 --- a/archiva-database/src/main/java/org/apache/maven/archiva/database/ArchivaDAO.java +++ b/archiva-database/src/main/java/org/apache/maven/archiva/database/ArchivaDAO.java @@ -19,8 +19,8 @@ package org.apache.maven.archiva.database; * under the License. */ -import org.apache.maven.archiva.model.ArchivaArtifact; -import org.apache.maven.archiva.model.ArchivaRepository; +import org.apache.maven.archiva.model.ArchivaArtifactModel; +import org.apache.maven.archiva.model.ArchivaRepositoryModel; import org.apache.maven.archiva.model.RepositoryContent; import java.util.List; @@ -56,21 +56,21 @@ public interface ArchivaDAO /* .\ Archiva Repository \.____________________________________________________________ */ - public ArchivaRepository createRepository( String id, String url ); + public ArchivaRepositoryModel createRepository( String id, String url ); - public List /**/getRepositories() + public List /**/getRepositories() throws ObjectNotFoundException, ArchivaDatabaseException; - public ArchivaRepository getRepository( String id ) + public ArchivaRepositoryModel getRepository( String id ) throws ObjectNotFoundException, ArchivaDatabaseException; public List queryRepository( Constraint constraint ) throws ObjectNotFoundException, ArchivaDatabaseException; - public ArchivaRepository saveRepository( ArchivaRepository repository ) + public ArchivaRepositoryModel saveRepository( ArchivaRepositoryModel repository ) throws ArchivaDatabaseException; - public void deleteRepository( ArchivaRepository repository ) + public void deleteRepository( ArchivaRepositoryModel repository ) throws ArchivaDatabaseException; /* .\ Repository Content \.____________________________________________________________ */ @@ -93,18 +93,18 @@ public interface ArchivaDAO /* .\ Archiva Artifact \. _____________________________________________________________ */ - public ArchivaArtifact createArtifact( RepositoryContent repoContent, String classifier, String type ); + public ArchivaArtifactModel createArtifact( RepositoryContent repoContent, String classifier, String type ); - public ArchivaArtifact getArtifact( RepositoryContent repoContent, String classifier, String type ) + public ArchivaArtifactModel getArtifact( RepositoryContent repoContent, String classifier, String type ) throws ObjectNotFoundException, ArchivaDatabaseException; - public List /**/queryArtifacts( Constraint constraint ) + public List /**/queryArtifacts( Constraint constraint ) throws ObjectNotFoundException, ArchivaDatabaseException; - public ArchivaArtifact saveArtifact( ArchivaArtifact artifact ) + public ArchivaArtifactModel saveArtifact( ArchivaArtifactModel artifact ) throws ArchivaDatabaseException; - public void deleteArtifact( ArchivaArtifact artifact ) + public void deleteArtifact( ArchivaArtifactModel artifact ) throws ArchivaDatabaseException; } diff --git a/archiva-database/src/main/java/org/apache/maven/archiva/database/jdo/JdoArchivaDAO.java b/archiva-database/src/main/java/org/apache/maven/archiva/database/jdo/JdoArchivaDAO.java index 00af94585..92f48abb4 100644 --- a/archiva-database/src/main/java/org/apache/maven/archiva/database/jdo/JdoArchivaDAO.java +++ b/archiva-database/src/main/java/org/apache/maven/archiva/database/jdo/JdoArchivaDAO.java @@ -4,9 +4,8 @@ import org.apache.maven.archiva.database.ArchivaDAO; import org.apache.maven.archiva.database.ArchivaDatabaseException; import org.apache.maven.archiva.database.Constraint; import org.apache.maven.archiva.database.ObjectNotFoundException; -import org.apache.maven.archiva.database.constraints.ArchivaRepositoryByUrlConstraint; -import org.apache.maven.archiva.model.ArchivaArtifact; -import org.apache.maven.archiva.model.ArchivaRepository; +import org.apache.maven.archiva.model.ArchivaArtifactModel; +import org.apache.maven.archiva.model.ArchivaRepositoryModel; import org.apache.maven.archiva.model.RepositoryContent; import org.apache.maven.archiva.model.RepositoryContentKey; import org.codehaus.plexus.logging.AbstractLogEnabled; @@ -33,9 +32,9 @@ public class JdoArchivaDAO /* .\ Archiva Repository \.____________________________________________________________ */ - public ArchivaRepository createRepository( String id, String url ) + public ArchivaRepositoryModel createRepository( String id, String url ) { - ArchivaRepository repo; + ArchivaRepositoryModel repo; try { @@ -43,7 +42,7 @@ public class JdoArchivaDAO } catch ( ArchivaDatabaseException e ) { - repo = new ArchivaRepository(); + repo = new ArchivaRepositoryModel(); repo.setId( id ); repo.setUrl( url ); } @@ -54,27 +53,27 @@ public class JdoArchivaDAO public List getRepositories() throws ObjectNotFoundException, ArchivaDatabaseException { - return jdo.getAllObjects( ArchivaRepository.class ); + return jdo.getAllObjects( ArchivaRepositoryModel.class ); } - public ArchivaRepository getRepository( String id ) + public ArchivaRepositoryModel getRepository( String id ) throws ObjectNotFoundException, ArchivaDatabaseException { - return (ArchivaRepository) jdo.getObjectById( ArchivaRepository.class, id, null ); + return (ArchivaRepositoryModel) jdo.getObjectById( ArchivaRepositoryModel.class, id, null ); } public List queryRepository( Constraint constraint ) throws ObjectNotFoundException, ArchivaDatabaseException { - return jdo.getAllObjects( ArchivaRepository.class, constraint ); + return jdo.getAllObjects( ArchivaRepositoryModel.class, constraint ); } - public ArchivaRepository saveRepository( ArchivaRepository repository ) + public ArchivaRepositoryModel saveRepository( ArchivaRepositoryModel repository ) { - return (ArchivaRepository) jdo.saveObject( repository ); + return (ArchivaRepositoryModel) jdo.saveObject( repository ); } - public void deleteRepository( ArchivaRepository repository ) + public void deleteRepository( ArchivaRepositoryModel repository ) throws ArchivaDatabaseException { jdo.removeObject( repository ); @@ -132,9 +131,9 @@ public class JdoArchivaDAO /* .\ Archiva Artifact \. _____________________________________________________________ */ - public ArchivaArtifact createArtifact( RepositoryContent repoContent, String classifier, String type ) + public ArchivaArtifactModel createArtifact( RepositoryContent repoContent, String classifier, String type ) { - ArchivaArtifact artifact; + ArchivaArtifactModel artifact; try { @@ -142,7 +141,7 @@ public class JdoArchivaDAO } catch ( ArchivaDatabaseException e ) { - artifact = new ArchivaArtifact(); + artifact = new ArchivaArtifactModel(); artifact.setContentKey( repoContent ); artifact.setClassifier( classifier ); artifact.setType( type ); @@ -151,7 +150,7 @@ public class JdoArchivaDAO return artifact; } - public ArchivaArtifact getArtifact( RepositoryContent repoContent, String classifier, String type ) + public ArchivaArtifactModel getArtifact( RepositoryContent repoContent, String classifier, String type ) throws ObjectNotFoundException, ArchivaDatabaseException { @@ -165,14 +164,14 @@ public class JdoArchivaDAO return null; } - public ArchivaArtifact saveArtifact( ArchivaArtifact artifact ) + public ArchivaArtifactModel saveArtifact( ArchivaArtifactModel artifact ) throws ArchivaDatabaseException { // TODO Auto-generated method stub return null; } - public void deleteArtifact( ArchivaArtifact artifact ) + public void deleteArtifact( ArchivaArtifactModel artifact ) throws ArchivaDatabaseException { // TODO Auto-generated method stub diff --git a/archiva-model/src/main/java/org/apache/maven/archiva/model/AbstractArchivaArtifact.java b/archiva-model/src/main/java/org/apache/maven/archiva/model/AbstractArchivaArtifact.java deleted file mode 100644 index df9d773f2..000000000 --- a/archiva-model/src/main/java/org/apache/maven/archiva/model/AbstractArchivaArtifact.java +++ /dev/null @@ -1,139 +0,0 @@ -package org.apache.maven.archiva.model; - -/* - * 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.artifact.InvalidArtifactRTException; -import org.apache.maven.artifact.repository.ArtifactRepository; -import org.codehaus.plexus.util.StringUtils; - -import java.util.Map; - -/** - * ArchivaArtifact - * - * @author Joakim Erdfelt - * @version $Id$ - */ -public abstract class AbstractArchivaArtifact -{ - private String classifier; - - private RepositoryContent key; - - private String type; - - public AbstractArchivaArtifact( ArchivaRepository repository, String groupId, String artifactId, String version, String classifier, String type ) - { - this.key = new RepositoryContent( repository, groupId, artifactId, version ); - - this.classifier = classifier; - - this.type = type; - - validateIdentity(); - } - - public String getClassifier() - { - return classifier; - } - - public RepositoryContent getRepositoryContent() - { - return key; - } - - public String getType() - { - return type; - } - - public boolean hasClassifier() - { - return StringUtils.isNotEmpty( classifier ); - } - - public void setRepositoryContent( RepositoryContent key ) - { - this.key = key; - } - - public String toString() - { - StringBuffer sb = new StringBuffer(); - if ( key.getGroupId() != null ) - { - sb.append( key.getGroupId() ); - sb.append( ":" ); - } - appendArtifactTypeClassifierString( sb ); - sb.append( ":" ); - if ( key.getVersion() != null ) - { - sb.append( key.getVersion() ); - } - - return sb.toString(); - } - - private void appendArtifactTypeClassifierString( StringBuffer sb ) - { - sb.append( key.getArtifactId() ); - sb.append( ":" ); - sb.append( getType() ); - if ( hasClassifier() ) - { - sb.append( ":" ); - sb.append( getClassifier() ); - } - } - - protected boolean empty( String value ) - { - return value == null || value.trim().length() < 1; - } - - protected void validateIdentity() - { - if ( empty( key.getGroupId() ) ) - { - throw new InvalidArtifactRTException( key.getGroupId(), key.getArtifactId(), key.getVersion(), type, - "The groupId cannot be empty." ); - } - - if ( key.getArtifactId() == null ) - { - throw new InvalidArtifactRTException( key.getGroupId(), key.getArtifactId(), key.getVersion(), type, - "The artifactId cannot be empty." ); - } - - if ( type == null ) - { - throw new InvalidArtifactRTException( key.getGroupId(), key.getArtifactId(), key.getVersion(), type, - "The type cannot be empty." ); - } - - if ( key.getVersion() == null ) - { - throw new InvalidArtifactRTException( key.getGroupId(), key.getArtifactId(), key.getVersion(), type, - "The version cannot be empty." ); - } - } -} diff --git a/archiva-model/src/main/mdo/archiva.xml b/archiva-model/src/main/mdo/archiva.xml index 1caa7850d..b9b93f244 100644 --- a/archiva-model/src/main/mdo/archiva.xml +++ b/archiva-model/src/main/mdo/archiva.xml @@ -20,15 +20,15 @@ Repositories 1.0.0+ - ArchivaRepository + ArchivaRepositoryModel * - - AbstractArchivaRepository - ArchivaRepository + + ArchivaRepositoryModel 1.0.0+ @@ -106,6 +106,7 @@ @@ -176,7 +177,7 @@ this.setVersion( version ); } - public RepositoryContent( ArchivaRepository repository, String groupId, String artifactId, String version ) + public RepositoryContent( ArchivaRepositoryModel repository, String groupId, String artifactId, String version ) { this.setRepositoryId( repository.getId() ); this.setGroupId( groupId ); @@ -187,8 +188,9 @@ - - ArchivaArtifact + + ArchivaArtifactModel 1.0.0+ @@ -226,7 +228,8 @@ - + ArchivaRepositoryMetadata 1.0.0+ @@ -268,7 +271,8 @@ - + HealthProblem 1.0.0+ @@ -304,7 +308,8 @@ - + ArchivaArtifactHealth 1.0.0+ @@ -314,7 +319,7 @@ 1.0.0+ true - ArchivaArtifact + ArchivaArtifactModel 1 @@ -336,7 +341,8 @@ - + ArchivaRepositoryMetadataHealth 1.0.0+ @@ -368,7 +374,8 @@ - + RepositoryContentStatistics 1.0.0+ 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 @@ -30,10 +30,6 @@ archiva-repository-layer Archiva Repository Interface Layer - - org.apache.maven.archiva - archiva-consumer-api - org.apache.maven.archiva archiva-common 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 Joakim Erdfelt + * @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-model/src/main/java/org/apache/maven/archiva/model/AbstractArchivaRepository.java b/archiva-repository-layer/src/main/java/org/apache/maven/archiva/repository/ArchivaRepository.java similarity index 61% rename from archiva-model/src/main/java/org/apache/maven/archiva/model/AbstractArchivaRepository.java rename to archiva-repository-layer/src/main/java/org/apache/maven/archiva/repository/ArchivaRepository.java index 347f68d47..c1fb4f0fe 100644 --- a/archiva-model/src/main/java/org/apache/maven/archiva/model/AbstractArchivaRepository.java +++ b/archiva-repository-layer/src/main/java/org/apache/maven/archiva/repository/ArchivaRepository.java @@ -1,4 +1,4 @@ -package org.apache.maven.archiva.model; +package org.apache.maven.archiva.repository; /* * Licensed to the Apache Software Foundation (ASF) under one @@ -19,29 +19,42 @@ package org.apache.maven.archiva.model; * under the License. */ -import org.apache.maven.archiva.common.utils.RepositoryURL; +import org.apache.maven.archiva.model.ArchivaRepositoryModel; import org.apache.maven.artifact.repository.ArtifactRepositoryPolicy; -import org.apache.maven.artifact.repository.layout.ArtifactRepositoryLayout; /** - * AbstractArchivaRepository + * ArchivaRepository * * @author Joakim Erdfelt * @version $Id$ */ -public abstract class AbstractArchivaRepository +public class ArchivaRepository { - protected ArtifactRepositoryLayout layout; - protected ArtifactRepositoryPolicy releases; protected ArtifactRepositoryPolicy snapshots; + private ArchivaRepositoryModel model; + + private RepositoryURL url; + protected boolean blacklisted; - public AbstractArchivaRepository() + /** + * 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 ) ); } /** @@ -52,40 +65,42 @@ public abstract class AbstractArchivaRepository * @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 AbstractArchivaRepository( String id, String name, String url, ArtifactRepositoryLayout layout ) + public ArchivaRepository( ArchivaRepositoryModel model ) { - setId( id ); - setName( name ); - setUrl( url ); - setLayout( layout ); - } + this.model = model; - public abstract void setUrl( String url ); - - public abstract String getUrl(); + this.url = new RepositoryURL( model.getUrl() ); + } - public abstract void setName( String name ); + public String getId() + { + return model.getId(); + } - public abstract void setId( String id ); + public void setUrl( RepositoryURL url ) + { + this.url = url; + model.setUrl( url.getUrl() ); + } - public boolean isBlacklisted() + public RepositoryURL getUrl() { - return blacklisted; + return this.url; } - public void setBlacklisted( boolean blacklisted ) + public ArchivaRepositoryModel getModel() { - this.blacklisted = blacklisted; + return this.model; } - public ArtifactRepositoryLayout getLayout() + public boolean isBlacklisted() { - return layout; + return blacklisted; } - public void setLayout( ArtifactRepositoryLayout layout ) + public void setBlacklisted( boolean blacklisted ) { - this.layout = layout; + this.blacklisted = blacklisted; } public ArtifactRepositoryPolicy getReleases() @@ -110,16 +125,11 @@ public abstract class AbstractArchivaRepository public boolean isRemote() { - return !getRepositoryURL().getProtocol().equals( "file" ); + return this.url.getProtocol().equals( "file" ); } public boolean isManaged() { - return getRepositoryURL().getProtocol().equals( "file" ); - } - - public RepositoryURL getRepositoryURL() - { - return new RepositoryURL( getUrl() ); + return this.url.getProtocol().equals( "file" ); } } diff --git a/archiva-common/src/main/java/org/apache/maven/archiva/common/utils/RepositoryURL.java b/archiva-repository-layer/src/main/java/org/apache/maven/archiva/repository/RepositoryURL.java similarity index 98% rename from archiva-common/src/main/java/org/apache/maven/archiva/common/utils/RepositoryURL.java rename to archiva-repository-layer/src/main/java/org/apache/maven/archiva/repository/RepositoryURL.java index 5ad550e6e..13ed57fc9 100644 --- a/archiva-common/src/main/java/org/apache/maven/archiva/common/utils/RepositoryURL.java +++ b/archiva-repository-layer/src/main/java/org/apache/maven/archiva/repository/RepositoryURL.java @@ -1,4 +1,4 @@ -package org.apache.maven.archiva.common.utils; +package org.apache.maven.archiva.repository; /* * Licensed to the Apache Software Foundation (ASF) under one 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 Joakim Erdfelt + * @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 Joakim Erdfelt + * @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 Joakim Erdfelt + * @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 Joakim Erdfelt + * @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 Joakim Erdfelt + * @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 Joakim Erdfelt * @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 Joakim Erdfelt + * @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 Joakim Erdfelt + * @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 Joakim Erdfelt + * @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 Joakim Erdfelt + * @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 Joakim Erdfelt + * @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 Joakim Erdfelt + * @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 Joakim Erdfelt + * @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 ) ); + } +} -- 2.39.5