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
This commit is contained in:
Joakim Erdfelt 2007-03-15 22:44:49 +00:00
parent 7a5f50c9f6
commit f5da042413
25 changed files with 1184 additions and 239 deletions

View File

@ -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 /*<ArchivaRepository>*/getRepositories()
public List /*<ArchivaRepositoryModel>*/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 /*<ArchivaArtifact>*/queryArtifacts( Constraint constraint )
public List /*<ArchivaArtifactModel>*/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;
}

View File

@ -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

View File

@ -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 <a href="mailto:joakim@erdfelt.com">Joakim Erdfelt</a>
* @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." );
}
}
}

View File

@ -20,15 +20,15 @@
<name>Repositories</name>
<version>1.0.0+</version>
<association>
<type>ArchivaRepository</type>
<type>ArchivaRepositoryModel</type>
<multiplicity>*</multiplicity>
</association>
</field>
</fields>
</class>
<class stash.storable="true">
<superClass>AbstractArchivaRepository</superClass>
<name>ArchivaRepository</name>
<class stash.storable="true"
jpox.table="REPOSITORIES">
<name>ArchivaRepositoryModel</name>
<version>1.0.0+</version>
<fields>
<field>
@ -106,6 +106,7 @@
</fields>
</class>
<class stash.storable="true"
jpox.table="REPOSITORY_CONTENT_KEYS"
jpox.use-identifiers-as-primary-key="true"
jpox.identity-type="application"
jpox.identity-class="RepositoryContentKey">
@ -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 @@
</codeSegment>
</codeSegments>
</class>
<class>
<name>ArchivaArtifact</name>
<class stash.storable="true"
jpox.table="ARTIFACTS">
<name>ArchivaArtifactModel</name>
<version>1.0.0+</version>
<fields>
<field>
@ -226,7 +228,8 @@
</field>
</fields>
</class>
<class>
<class stash.storable="true"
jpox.table="REPOSITORY_METADATAS">
<name>ArchivaRepositoryMetadata</name>
<version>1.0.0+</version>
<fields>
@ -268,7 +271,8 @@
</field>
</fields>
</class>
<class>
<class stash.storable="true"
jpox.table="HEALTH_PROBLEMS">
<name>HealthProblem</name>
<version>1.0.0+</version>
<fields>
@ -304,7 +308,8 @@
</field>
</fields>
</class>
<class>
<class stash.storable="true"
jpox.table="HEALTH_ARTIFACTS">
<name>ArchivaArtifactHealth</name>
<version>1.0.0+</version>
<fields>
@ -314,7 +319,7 @@
<version>1.0.0+</version>
<required>true</required>
<association>
<type>ArchivaArtifact</type>
<type>ArchivaArtifactModel</type>
<multiplicity>1</multiplicity>
</association>
<description>
@ -336,7 +341,8 @@
</field>
</fields>
</class>
<class>
<class stash.storable="true"
jpox.table="HEALTH_REPOSITORY_METADATAS">
<name>ArchivaRepositoryMetadataHealth</name>
<version>1.0.0+</version>
<fields>
@ -368,7 +374,8 @@
</field>
</fields>
</class>
<class>
<class stash.storable="true"
jpox.table="REPOSITORY_STATS">
<name>RepositoryContentStatistics</name>
<version>1.0.0+</version>
<fields>

View File

@ -30,10 +30,6 @@
<artifactId>archiva-repository-layer</artifactId>
<name>Archiva Repository Interface Layer</name>
<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>

View File

@ -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;
}
}

View File

@ -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 <a href="mailto:joakim@erdfelt.com">Joakim Erdfelt</a>
* @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,21 +65,33 @@ 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;
this.url = new RepositoryURL( model.getUrl() );
}
public abstract void setUrl( String url );
public String getId()
{
return model.getId();
}
public abstract String getUrl();
public void setUrl( RepositoryURL url )
{
this.url = url;
model.setUrl( url.getUrl() );
}
public abstract void setName( String name );
public RepositoryURL getUrl()
{
return this.url;
}
public abstract void setId( String id );
public ArchivaRepositoryModel getModel()
{
return this.model;
}
public boolean isBlacklisted()
{
@ -78,16 +103,6 @@ public abstract class AbstractArchivaRepository
this.blacklisted = blacklisted;
}
public ArtifactRepositoryLayout getLayout()
{
return layout;
}
public void setLayout( ArtifactRepositoryLayout layout )
{
this.layout = layout;
}
public ArtifactRepositoryPolicy getReleases()
{
return releases;
@ -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" );
}
}

View File

@ -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

View File

@ -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;

View File

@ -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 );
}

View File

@ -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;
}
}

View File

@ -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 );
}
}

View File

@ -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();
}
}

View File

@ -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 );
}

View File

@ -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 );
}

View File

@ -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." );
}
}
}
}

View File

@ -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;
}
}

View File

@ -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." );
}
}
}
}

View File

@ -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;
}
}

View File

@ -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() )
{

View File

@ -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();
}

View File

@ -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;

View File

@ -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() );
}
}

View File

@ -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" );
}
}

View File

@ -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 ) );
}
}