+++ /dev/null
-package org.apache.maven.archiva.common.utils;
-
-/*
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements. See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership. The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing,
- * software distributed under the License is distributed on an
- * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- * KIND, either express or implied. See the License for the
- * specific language governing permissions and limitations
- * under the License.
- */
-
-
-/**
- * RepositoryURL - Mutable (and protocol forgiving) URL object.
- *
- * @author <a href="mailto:joakim@erdfelt.com">Joakim Erdfelt</a>
- * @version $Id$
- */
-public class RepositoryURL
-{
- private String url;
-
- private String protocol;
-
- private String host;
-
- private String port;
-
- private String username;
-
- private String password;
-
- private String path;
-
- public RepositoryURL( String url )
- {
- this.url = url;
-
- // .\ Parse the URL \.____________________________________________
-
- int pos;
-
- pos = url.indexOf( "://" );
- if ( pos == ( -1 ) )
- {
- throw new IllegalArgumentException( "Invalid URL, unable to parse protocol:// from " + url );
- }
-
- protocol = url.substring( 0, pos );
-
- // attempt to find the start of the 'path'
- pos = url.indexOf( "/", protocol.length() + 3 );
-
- // no path specified - ex "http://localhost"
- if ( pos == ( -1 ) )
- {
- // set pos to end of string. (needed for 'middle section')
- pos = url.length();
- // default path
- path = "/";
- }
- else
- {
- // get actual path.
- path = url.substring( pos );
- }
-
- // get the middle section ( username : password @ hostname : port )
- String middle = url.substring( protocol.length() + 3, pos );
-
- pos = middle.indexOf( '@' );
-
- // we have an authentication section.
- if ( pos > 0 )
- {
- String authentication = middle.substring( 0, pos );
- middle = middle.substring( pos + 1 ); // lop off authentication for host:port search
-
- pos = authentication.indexOf( ':' );
-
- // we have a password.
- if ( pos > 0 )
- {
- username = authentication.substring( 0, pos );
- password = authentication.substring( pos + 1 );
- }
- else
- {
- username = authentication;
- }
- }
-
- pos = middle.indexOf( ':' );
-
- // we have a defined port
- if ( pos > 0 )
- {
- host = middle.substring( 0, pos );
- port = middle.substring( pos + 1 );
- }
- else
- {
- host = middle;
- }
- }
-
- public String toString()
- {
- return url;
- }
-
- public String getUsername()
- {
- return username;
- }
-
- public String getPassword()
- {
- return password;
- }
-
- public String getHost()
- {
- return host;
- }
-
- public String getPath()
- {
- return path;
- }
-
- public String getPort()
- {
- return port;
- }
-
- public String getProtocol()
- {
- return protocol;
- }
-
- public String getUrl()
- {
- return url;
- }
-}
* 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;
/* .\ 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 \.____________________________________________________________ */
/* .\ 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;
}
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;
/* .\ Archiva Repository \.____________________________________________________________ */
- public ArchivaRepository createRepository( String id, String url )
+ public ArchivaRepositoryModel createRepository( String id, String url )
{
- ArchivaRepository repo;
+ ArchivaRepositoryModel repo;
try
{
}
catch ( ArchivaDatabaseException e )
{
- repo = new ArchivaRepository();
+ repo = new ArchivaRepositoryModel();
repo.setId( id );
repo.setUrl( url );
}
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 );
/* .\ 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
{
}
catch ( ArchivaDatabaseException e )
{
- artifact = new ArchivaArtifact();
+ artifact = new ArchivaArtifactModel();
artifact.setContentKey( repoContent );
artifact.setClassifier( classifier );
artifact.setType( type );
return artifact;
}
- public ArchivaArtifact getArtifact( RepositoryContent repoContent, String classifier, String type )
+ public ArchivaArtifactModel getArtifact( RepositoryContent repoContent, String classifier, String type )
throws ObjectNotFoundException, ArchivaDatabaseException
{
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
+++ /dev/null
-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." );
- }
- }
-}
+++ /dev/null
-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.archiva.common.utils.RepositoryURL;
-import org.apache.maven.artifact.repository.ArtifactRepositoryPolicy;
-import org.apache.maven.artifact.repository.layout.ArtifactRepositoryLayout;
-
-/**
- * AbstractArchivaRepository
- *
- * @author <a href="mailto:joakim@erdfelt.com">Joakim Erdfelt</a>
- * @version $Id$
- */
-public abstract class AbstractArchivaRepository
-{
- protected ArtifactRepositoryLayout layout;
-
- protected ArtifactRepositoryPolicy releases;
-
- protected ArtifactRepositoryPolicy snapshots;
-
- 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 AbstractArchivaRepository( String id, String name, String url, ArtifactRepositoryLayout layout )
- {
- setId( id );
- setName( name );
- setUrl( url );
- setLayout( layout );
- }
-
- public abstract void setUrl( String url );
-
- public abstract String getUrl();
-
- public abstract void setName( String name );
-
- public abstract void setId( String id );
-
- public boolean isBlacklisted()
- {
- return blacklisted;
- }
-
- public void setBlacklisted( boolean blacklisted )
- {
- this.blacklisted = blacklisted;
- }
-
- public ArtifactRepositoryLayout getLayout()
- {
- return layout;
- }
-
- public void setLayout( ArtifactRepositoryLayout layout )
- {
- this.layout = layout;
- }
-
- public ArtifactRepositoryPolicy getReleases()
- {
- return releases;
- }
-
- public void setReleases( ArtifactRepositoryPolicy releases )
- {
- this.releases = releases;
- }
-
- public ArtifactRepositoryPolicy getSnapshots()
- {
- return snapshots;
- }
-
- public void setSnapshots( ArtifactRepositoryPolicy snapshots )
- {
- this.snapshots = snapshots;
- }
-
- public boolean isRemote()
- {
- return !getRepositoryURL().getProtocol().equals( "file" );
- }
-
- public boolean isManaged()
- {
- return getRepositoryURL().getProtocol().equals( "file" );
- }
-
- public RepositoryURL getRepositoryURL()
- {
- return new RepositoryURL( getUrl() );
- }
-}
<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>
</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">
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 );
</codeSegment>
</codeSegments>
</class>
- <class>
- <name>ArchivaArtifact</name>
+ <class stash.storable="true"
+ jpox.table="ARTIFACTS">
+ <name>ArchivaArtifactModel</name>
<version>1.0.0+</version>
<fields>
<field>
</field>
</fields>
</class>
- <class>
+ <class stash.storable="true"
+ jpox.table="REPOSITORY_METADATAS">
<name>ArchivaRepositoryMetadata</name>
<version>1.0.0+</version>
<fields>
</field>
</fields>
</class>
- <class>
+ <class stash.storable="true"
+ jpox.table="HEALTH_PROBLEMS">
<name>HealthProblem</name>
<version>1.0.0+</version>
<fields>
</field>
</fields>
</class>
- <class>
+ <class stash.storable="true"
+ jpox.table="HEALTH_ARTIFACTS">
<name>ArchivaArtifactHealth</name>
<version>1.0.0+</version>
<fields>
<version>1.0.0+</version>
<required>true</required>
<association>
- <type>ArchivaArtifact</type>
+ <type>ArchivaArtifactModel</type>
<multiplicity>1</multiplicity>
</association>
<description>
</field>
</fields>
</class>
- <class>
+ <class stash.storable="true"
+ jpox.table="HEALTH_REPOSITORY_METADATAS">
<name>ArchivaRepositoryMetadataHealth</name>
<version>1.0.0+</version>
<fields>
</field>
</fields>
</class>
- <class>
+ <class stash.storable="true"
+ jpox.table="REPOSITORY_STATS">
<name>RepositoryContentStatistics</name>
<version>1.0.0+</version>
<fields>
<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>
--- /dev/null
+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;
+ }
+
+}
--- /dev/null
+package org.apache.maven.archiva.repository;
+
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+import org.apache.maven.archiva.model.ArchivaRepositoryModel;
+import org.apache.maven.artifact.repository.ArtifactRepositoryPolicy;
+
+/**
+ * ArchivaRepository
+ *
+ * @author <a href="mailto:joakim@erdfelt.com">Joakim Erdfelt</a>
+ * @version $Id$
+ */
+public class ArchivaRepository
+{
+ protected ArtifactRepositoryPolicy releases;
+
+ protected ArtifactRepositoryPolicy snapshots;
+
+ private ArchivaRepositoryModel model;
+
+ private RepositoryURL url;
+
+ protected boolean blacklisted;
+
+ /**
+ * Construct a Repository.
+ *
+ * @param id the unique identifier for this repository.
+ * @param name the name for this repository.
+ * @param url the base URL for this repository (this should point to the top level URL for the entire repository)
+ * @param layout the layout technique for this repository.
+ */
+ public ArchivaRepository( String id, String name, String url )
+ {
+ model = new ArchivaRepositoryModel();
+
+ model.setId( id );
+ model.setName( name );
+ setUrl( new RepositoryURL( url ) );
+ }
+
+ /**
+ * Construct a Repository.
+ *
+ * @param id the unique identifier for this repository.
+ * @param name the name for this repository.
+ * @param url the base URL for this repository (this should point to the top level URL for the entire repository)
+ * @param layout the layout technique for this repository.
+ */
+ public ArchivaRepository( ArchivaRepositoryModel model )
+ {
+ this.model = model;
+
+ this.url = new RepositoryURL( model.getUrl() );
+ }
+
+ public String getId()
+ {
+ return model.getId();
+ }
+
+ public void setUrl( RepositoryURL url )
+ {
+ this.url = url;
+ model.setUrl( url.getUrl() );
+ }
+
+ public RepositoryURL getUrl()
+ {
+ return this.url;
+ }
+
+ public ArchivaRepositoryModel getModel()
+ {
+ return this.model;
+ }
+
+ public boolean isBlacklisted()
+ {
+ return blacklisted;
+ }
+
+ public void setBlacklisted( boolean blacklisted )
+ {
+ this.blacklisted = blacklisted;
+ }
+
+ public ArtifactRepositoryPolicy getReleases()
+ {
+ return releases;
+ }
+
+ public void setReleases( ArtifactRepositoryPolicy releases )
+ {
+ this.releases = releases;
+ }
+
+ public ArtifactRepositoryPolicy getSnapshots()
+ {
+ return snapshots;
+ }
+
+ public void setSnapshots( ArtifactRepositoryPolicy snapshots )
+ {
+ this.snapshots = snapshots;
+ }
+
+ public boolean isRemote()
+ {
+ return this.url.getProtocol().equals( "file" );
+ }
+
+ public boolean isManaged()
+ {
+ return this.url.getProtocol().equals( "file" );
+ }
+}
--- /dev/null
+package org.apache.maven.archiva.repository;
+
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+
+/**
+ * RepositoryURL - Mutable (and protocol forgiving) URL object.
+ *
+ * @author <a href="mailto:joakim@erdfelt.com">Joakim Erdfelt</a>
+ * @version $Id$
+ */
+public class RepositoryURL
+{
+ private String url;
+
+ private String protocol;
+
+ private String host;
+
+ private String port;
+
+ private String username;
+
+ private String password;
+
+ private String path;
+
+ public RepositoryURL( String url )
+ {
+ this.url = url;
+
+ // .\ Parse the URL \.____________________________________________
+
+ int pos;
+
+ pos = url.indexOf( "://" );
+ if ( pos == ( -1 ) )
+ {
+ throw new IllegalArgumentException( "Invalid URL, unable to parse protocol:// from " + url );
+ }
+
+ protocol = url.substring( 0, pos );
+
+ // attempt to find the start of the 'path'
+ pos = url.indexOf( "/", protocol.length() + 3 );
+
+ // no path specified - ex "http://localhost"
+ if ( pos == ( -1 ) )
+ {
+ // set pos to end of string. (needed for 'middle section')
+ pos = url.length();
+ // default path
+ path = "/";
+ }
+ else
+ {
+ // get actual path.
+ path = url.substring( pos );
+ }
+
+ // get the middle section ( username : password @ hostname : port )
+ String middle = url.substring( protocol.length() + 3, pos );
+
+ pos = middle.indexOf( '@' );
+
+ // we have an authentication section.
+ if ( pos > 0 )
+ {
+ String authentication = middle.substring( 0, pos );
+ middle = middle.substring( pos + 1 ); // lop off authentication for host:port search
+
+ pos = authentication.indexOf( ':' );
+
+ // we have a password.
+ if ( pos > 0 )
+ {
+ username = authentication.substring( 0, pos );
+ password = authentication.substring( pos + 1 );
+ }
+ else
+ {
+ username = authentication;
+ }
+ }
+
+ pos = middle.indexOf( ':' );
+
+ // we have a defined port
+ if ( pos > 0 )
+ {
+ host = middle.substring( 0, pos );
+ port = middle.substring( pos + 1 );
+ }
+ else
+ {
+ host = middle;
+ }
+ }
+
+ public String toString()
+ {
+ return url;
+ }
+
+ public String getUsername()
+ {
+ return username;
+ }
+
+ public String getPassword()
+ {
+ return password;
+ }
+
+ public String getHost()
+ {
+ return host;
+ }
+
+ public String getPath()
+ {
+ return path;
+ }
+
+ public String getPort()
+ {
+ return port;
+ }
+
+ public String getProtocol()
+ {
+ return protocol;
+ }
+
+ public String getUrl()
+ {
+ return url;
+ }
+}
* under the License.
*/
-import org.apache.maven.archiva.model.ArchivaRepository;
+import org.apache.maven.archiva.repository.ArchivaRepository;
import java.util.List;
--- /dev/null
+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 );
+}
--- /dev/null
+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;
+ }
+}
--- /dev/null
+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 );
+ }
+}
--- /dev/null
+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();
+ }
+}
--- /dev/null
+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 );
+}
* 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$
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 );
}
--- /dev/null
+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." );
+ }
+ }
+ }
+}
--- /dev/null
+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;
+ }
+}
--- /dev/null
+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." );
+ }
+ }
+ }
+}
--- /dev/null
+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;
+ }
+
+}
* 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;
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() )
{
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;
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();
}
{
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() )
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();
}
* under the License.
*/
-import org.apache.maven.archiva.common.utils.RepositoryURL;
import java.net.MalformedURLException;
--- /dev/null
+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() );
+ }
+
+}
--- /dev/null
+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" );
+ }
+}
--- /dev/null
+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 ) );
+ }
+}