[MRM-1359] remove maven1 code

This commit is contained in:
Olivier Lamy 2015-02-12 22:27:49 +11:00
parent e16894724f
commit edbc2b762e
28 changed files with 0 additions and 1602 deletions

View File

@ -1,129 +0,0 @@
package org.apache.archiva.repository.content.legacy;
/*
* 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.archiva.model.ArchivaArtifact;
import org.apache.archiva.model.ArtifactReference;
import org.apache.archiva.repository.content.PathParser;
import org.apache.archiva.repository.content.maven2.ArtifactExtensionMapping;
import org.apache.archiva.repository.layout.LayoutException;
import org.apache.commons.lang.StringUtils;
import javax.inject.Inject;
import javax.inject.Named;
import java.util.HashMap;
import java.util.Map;
/**
* AbstractLegacyRepositoryContent
*
*
*/
public abstract class AbstractLegacyRepositoryContent
{
private static final String PATH_SEPARATOR = "/";
private static final Map<String, String> typeToDirectoryMap;
static
{
typeToDirectoryMap = new HashMap<>( 5 );
typeToDirectoryMap.put( "ejb-client", "ejb" );
typeToDirectoryMap.put( ArtifactExtensionMapping.MAVEN_ONE_PLUGIN, "plugin" );
typeToDirectoryMap.put( "distribution-tgz", "distribution" );
typeToDirectoryMap.put( "distribution-zip", "distribution" );
typeToDirectoryMap.put( "javadoc", "javadoc.jar" );
}
/**
*
*/
@Inject
@Named( "pathParser#legacy" )
private PathParser legacyPathParser;
public ArtifactReference toArtifactReference( String path )
throws LayoutException
{
return legacyPathParser.toArtifactReference( path );
}
public String toPath( ArchivaArtifact reference )
{
if ( reference == null )
{
throw new IllegalArgumentException( "Artifact reference cannot be null" );
}
return toPath( reference.getGroupId(), reference.getArtifactId(), reference.getVersion(),
reference.getClassifier(), reference.getType() );
}
public String toPath( ArtifactReference reference )
{
if ( reference == null )
{
throw new IllegalArgumentException( "Artifact reference cannot be null" );
}
return toPath( reference.getGroupId(), reference.getArtifactId(), reference.getVersion(),
reference.getClassifier(), reference.getType() );
}
private String toPath( String groupId, String artifactId, String version, String classifier, String type )
{
StringBuilder path = new StringBuilder();
path.append( groupId ).append( PATH_SEPARATOR );
path.append( getDirectory( type ) ).append( PATH_SEPARATOR );
if ( version != null )
{
path.append( artifactId ).append( '-' ).append( version );
if ( StringUtils.isNotBlank( classifier ) )
{
path.append( '-' ).append( classifier );
}
path.append( '.' ).append( ArtifactExtensionMapping.getExtension( type ) );
}
return path.toString();
}
private String getDirectory( String type )
{
String dirname = typeToDirectoryMap.get( type );
if ( dirname != null )
{
return dirname + "s";
}
// Default process.
return type + "s";
}
public void setLegacyPathParser( PathParser parser )
{
this.legacyPathParser = parser;
}
}

View File

@ -1,216 +0,0 @@
package org.apache.archiva.repository.content.legacy;
/*
* 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.archiva.configuration.ArchivaConfiguration;
import org.apache.archiva.configuration.LegacyArtifactPath;
import org.apache.archiva.model.ArtifactReference;
import org.apache.archiva.repository.content.ArtifactClassifierMapping;
import org.apache.archiva.repository.content.PathParser;
import org.apache.archiva.repository.content.maven2.ArtifactExtensionMapping;
import org.apache.archiva.repository.content.maven2.FilenameParser;
import org.apache.archiva.repository.layout.LayoutException;
import org.apache.commons.lang.StringUtils;
import java.util.Collection;
/**
* LegacyPathParser is a parser for maven 1 (legacy layout) paths to
* ArtifactReference.
*
*
*/
public class LegacyPathParser
implements PathParser
{
private static final String INVALID_ARTIFACT_PATH = "Invalid path to Artifact: ";
protected ArchivaConfiguration configuration;
public LegacyPathParser( ArchivaConfiguration configuration )
{
this.configuration = configuration;
}
/**
* {@inheritDoc}
*
* @see org.apache.archiva.repository.content.PathParser#toArtifactReference(String)
*/
@Override
public ArtifactReference toArtifactReference( String path )
throws LayoutException
{
ArtifactReference artifact = new ArtifactReference();
// First, look if a custom resolution rule has been set for this artifact
Collection<LegacyArtifactPath> legacy = configuration.getConfiguration().getLegacyArtifactPaths();
for ( LegacyArtifactPath legacyPath : legacy )
{
if ( legacyPath.match( path ) )
{
artifact.setGroupId( legacyPath.getGroupId() );
artifact.setArtifactId( legacyPath.getArtifactId() );
artifact.setClassifier( legacyPath.getClassifier() );
artifact.setVersion( legacyPath.getVersion() );
artifact.setType( legacyPath.getType() );
return artifact;
}
}
String normalizedPath = StringUtils.replace( path, "\\", "/" );
String pathParts[] = StringUtils.split( normalizedPath, '/' );
/* Always 3 parts. (Never more or less)
*
* path = "commons-lang/jars/commons-lang-2.1.jar"
* path[0] = "commons-lang"; // The Group ID
* path[1] = "jars"; // The Directory Type
* path[2] = "commons-lang-2.1.jar"; // The Filename.
*/
if ( pathParts.length != 3 )
{
// Illegal Path Parts Length.
throw new LayoutException( INVALID_ARTIFACT_PATH
+ "legacy paths should only have 3 parts [groupId]/[type]s/[artifactId]-[version].[type], found "
+ pathParts.length + " instead." );
}
// The Group ID.
artifact.setGroupId( pathParts[0] );
// The Expected Type.
String expectedType = pathParts[1];
// Sanity Check: expectedType should end in "s".
if ( !expectedType.endsWith( "s" ) )
{
throw new LayoutException( INVALID_ARTIFACT_PATH
+ "legacy paths should have an expected type ending in [s] in the second part of the path." );
}
// The Filename.
String filename = pathParts[2];
FilenameParser parser = new FilenameParser( filename );
artifact.setArtifactId( parser.nextNonVersion() );
// Sanity Check: does it have an artifact id?
if ( StringUtils.isEmpty( artifact.getArtifactId() ) )
{
// Special Case: The filename might start with a version id (like "test-arch-1.0.jar").
int idx = filename.indexOf( '-' );
if ( idx > 0 )
{
parser.reset();
// Take the first section regardless of content.
String artifactId = parser.next();
// Is there anything more that is considered not a version id?
String moreArtifactId = parser.nextNonVersion();
if ( StringUtils.isNotBlank( moreArtifactId ) )
{
artifact.setArtifactId( artifactId + "-" + moreArtifactId );
}
else
{
artifact.setArtifactId( artifactId );
}
}
// Sanity Check: still no artifact id?
if ( StringUtils.isEmpty( artifact.getArtifactId() ) )
{
throw new LayoutException( INVALID_ARTIFACT_PATH + "no artifact id present." );
}
}
artifact.setVersion( parser.remaining() );
// Sanity Check: does it have a version?
if ( StringUtils.isEmpty( artifact.getVersion() ) )
{
// Special Case: use last section of artifactId as version.
String artifactId = artifact.getArtifactId();
int idx = artifactId.lastIndexOf( '-' );
if ( idx > 0 )
{
artifact.setVersion( artifactId.substring( idx + 1 ) );
artifact.setArtifactId( artifactId.substring( 0, idx ) );
}
else
{
throw new LayoutException( INVALID_ARTIFACT_PATH + "no version found." );
}
}
String classifier = ArtifactClassifierMapping.getClassifier( expectedType );
if ( classifier != null )
{
String version = artifact.getVersion();
if ( !version.endsWith( "-" + classifier ) )
{
throw new LayoutException(
INVALID_ARTIFACT_PATH + expectedType + " artifacts must use the classifier " + classifier );
}
version = version.substring( 0, version.length() - classifier.length() - 1 );
artifact.setVersion( version );
artifact.setClassifier( classifier );
}
String extension = parser.getExtension();
// Set Type
String defaultExtension = expectedType.substring( 0, expectedType.length() - 1 );
artifact.setType(
ArtifactExtensionMapping.mapExtensionAndClassifierToType( classifier, extension, defaultExtension ) );
// Sanity Check: does it have an extension?
if ( StringUtils.isEmpty( artifact.getType() ) )
{
throw new LayoutException( INVALID_ARTIFACT_PATH + "no extension found." );
}
// Special Case with Maven Plugins
if ( StringUtils.equals( "jar", extension ) && StringUtils.equals( "plugins", expectedType ) )
{
artifact.setType( ArtifactExtensionMapping.MAVEN_ONE_PLUGIN );
}
else
{
// Sanity Check: does extension match pathType on path?
String expectedExtension = ArtifactExtensionMapping.getExtension( artifact.getType() );
if ( !expectedExtension.equals( extension ) )
{
throw new LayoutException(
INVALID_ARTIFACT_PATH + "mismatch on extension [" + extension + "] and layout specified type ["
+ artifact.getType() + "] (which maps to extension: [" + expectedExtension + "]) on path ["
+ path + "]" );
}
}
return artifact;
}
}

View File

@ -1,498 +0,0 @@
package org.apache.archiva.repository.content.legacy;
/*
* 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.archiva.admin.model.beans.ManagedRepository;
import org.apache.archiva.common.utils.PathUtil;
import org.apache.archiva.configuration.FileTypes;
import org.apache.archiva.model.ArchivaArtifact;
import org.apache.archiva.model.ArtifactReference;
import org.apache.archiva.model.ProjectReference;
import org.apache.archiva.model.VersionedReference;
import org.apache.archiva.repository.ContentNotFoundException;
import org.apache.archiva.repository.ManagedRepositoryContent;
import org.apache.archiva.repository.RepositoryException;
import org.apache.archiva.repository.layout.LayoutException;
import org.apache.commons.collections.CollectionUtils;
import org.apache.commons.lang.StringUtils;
import org.springframework.context.annotation.Scope;
import org.springframework.stereotype.Service;
import javax.inject.Inject;
import java.io.File;
import java.util.HashSet;
import java.util.Set;
/**
* ManagedLegacyRepositoryContent
*
*
* TODO no need to be a component when filetypes, legacy path parser is not
*/
@Service( "managedRepositoryContent#legacy" )
@Scope( "prototype" )
public class ManagedLegacyRepositoryContent
extends AbstractLegacyRepositoryContent
implements ManagedRepositoryContent
{
/**
*
*/
@Inject
private FileTypes filetypes;
private ManagedRepository repository;
@Override
public void deleteVersion( VersionedReference reference )
throws ContentNotFoundException
{
File groupDir = new File( repository.getLocation(), reference.getGroupId() );
if ( !groupDir.exists() )
{
throw new ContentNotFoundException(
"Unable to get versions using a non-existant groupId directory: " + groupDir.getAbsolutePath() );
}
if ( !groupDir.isDirectory() )
{
throw new ContentNotFoundException(
"Unable to get versions using a non-directory: " + groupDir.getAbsolutePath() );
}
// First gather up the versions found as artifacts in the managed repository.
File typeDirs[] = groupDir.listFiles();
for ( File typeDir : typeDirs )
{
if ( !typeDir.isDirectory() )
{
// Skip it, we only care about directories.
continue;
}
if ( !typeDir.getName().endsWith( "s" ) )
{
// Skip it, we only care about directories that end in "s".
}
deleteVersions( typeDir, reference );
}
}
private void deleteVersions( File typeDir, VersionedReference reference )
{
File repoFiles[] = typeDir.listFiles();
for ( File repoFile : repoFiles )
{
if ( repoFile.isDirectory() )
{
// Skip it. it's a directory.
continue;
}
String relativePath = PathUtil.getRelative( repository.getLocation(), repoFile );
if ( filetypes.matchesArtifactPattern( relativePath ) )
{
try
{
ArtifactReference artifact = toArtifactReference( relativePath );
if ( StringUtils.equals( artifact.getArtifactId(), reference.getArtifactId() )
&& StringUtils.equals( artifact.getVersion(), reference.getVersion() ) )
{
repoFile.delete();
deleteSupportFiles( repoFile );
}
}
catch ( LayoutException e )
{
/* don't fail the process if there is a bad artifact within the directory. */
}
}
}
}
@Override
public void deleteProject( String namespace, String projectId )
throws RepositoryException
{
// TODO implements ??
}
private void deleteSupportFiles( File repoFile )
{
deleteSupportFile( repoFile, ".sha1" );
deleteSupportFile( repoFile, ".md5" );
deleteSupportFile( repoFile, ".asc" );
deleteSupportFile( repoFile, ".gpg" );
}
private void deleteSupportFile( File repoFile, String supportExtension )
{
File supportFile = new File( repoFile.getAbsolutePath() + supportExtension );
if ( supportFile.exists() && supportFile.isFile() )
{
supportFile.delete();
}
}
@Override
public String getId()
{
return repository.getId();
}
@Override
public Set<ArtifactReference> getRelatedArtifacts( ArtifactReference reference )
throws ContentNotFoundException
{
File artifactFile = toFile( reference );
File repoDir = artifactFile.getParentFile();
if ( !repoDir.exists() )
{
throw new ContentNotFoundException(
"Unable to get related artifacts using a non-existant directory: " + repoDir.getAbsolutePath() );
}
if ( !repoDir.isDirectory() )
{
throw new ContentNotFoundException(
"Unable to get related artifacts using a non-directory: " + repoDir.getAbsolutePath() );
}
Set<ArtifactReference> foundArtifacts = new HashSet<ArtifactReference>();
// First gather up the versions found as artifacts in the managed repository.
File projectParentDir = repoDir.getParentFile();
File typeDirs[] = projectParentDir.listFiles();
for ( File typeDir : typeDirs )
{
if ( !typeDir.isDirectory() )
{
// Skip it, we only care about directories.
continue;
}
if ( !typeDir.getName().endsWith( "s" ) )
{
// Skip it, we only care about directories that end in "s".
}
getRelatedArtifacts( typeDir, reference, foundArtifacts );
}
return foundArtifacts;
}
@Override
public String getRepoRoot()
{
return repository.getLocation();
}
@Override
public ManagedRepository getRepository()
{
return repository;
}
@Override
public Set<String> getVersions( ProjectReference reference )
throws ContentNotFoundException
{
File groupDir = new File( repository.getLocation(), reference.getGroupId() );
if ( !groupDir.exists() )
{
throw new ContentNotFoundException(
"Unable to get versions using a non-existant groupId directory: " + groupDir.getAbsolutePath() );
}
if ( !groupDir.isDirectory() )
{
throw new ContentNotFoundException(
"Unable to get versions using a non-directory: " + groupDir.getAbsolutePath() );
}
Set<String> foundVersions = new HashSet<String>();
// First gather up the versions found as artifacts in the managed repository.
File typeDirs[] = groupDir.listFiles();
for ( File typeDir : typeDirs )
{
if ( !typeDir.isDirectory() )
{
// Skip it, we only care about directories.
continue;
}
if ( !typeDir.getName().endsWith( "s" ) )
{
// Skip it, we only care about directories that end in "s".
}
getProjectVersions( typeDir, reference, foundVersions );
}
return foundVersions;
}
@Override
public Set<String> getVersions( VersionedReference reference )
throws ContentNotFoundException
{
File groupDir = new File( repository.getLocation(), reference.getGroupId() );
if ( !groupDir.exists() )
{
throw new ContentNotFoundException(
"Unable to get versions using a non-existant groupId directory: " + groupDir.getAbsolutePath() );
}
if ( !groupDir.isDirectory() )
{
throw new ContentNotFoundException(
"Unable to get versions using a non-directory: " + groupDir.getAbsolutePath() );
}
Set<String> foundVersions = new HashSet<String>();
// First gather up the versions found as artifacts in the managed repository.
File typeDirs[] = groupDir.listFiles();
for ( File typeDir : typeDirs )
{
if ( !typeDir.isDirectory() )
{
// Skip it, we only care about directories.
continue;
}
if ( !typeDir.getName().endsWith( "s" ) )
{
// Skip it, we only care about directories that end in "s".
}
getVersionedVersions( typeDir, reference, foundVersions );
}
return foundVersions;
}
@Override
public boolean hasContent( ArtifactReference reference )
{
File artifactFile = toFile( reference );
return artifactFile.exists() && artifactFile.isFile();
}
@Override
public boolean hasContent( ProjectReference reference )
{
try
{
Set<String> versions = getVersions( reference );
return CollectionUtils.isNotEmpty( versions );
}
catch ( ContentNotFoundException e )
{
return false;
}
}
@Override
public boolean hasContent( VersionedReference reference )
{
try
{
Set<String> versions = getVersions( reference );
return CollectionUtils.isNotEmpty( versions );
}
catch ( ContentNotFoundException e )
{
return false;
}
}
@Override
public void setRepository( ManagedRepository repository )
{
this.repository = repository;
}
/**
* Convert a path to an artifact reference.
*
* @param path the path to convert. (relative or full location path)
* @throws org.apache.archiva.repository.layout.LayoutException if the path cannot be converted to an artifact reference.
*/
@Override
public ArtifactReference toArtifactReference( String path )
throws LayoutException
{
if ( ( path != null ) && path.startsWith( repository.getLocation() ) )
{
return super.toArtifactReference( path.substring( repository.getLocation().length() ) );
}
return super.toArtifactReference( path );
}
@Override
public File toFile( ArchivaArtifact reference )
{
return new File( repository.getLocation(), toPath( reference ) );
}
@Override
public File toFile( ArtifactReference reference )
{
return new File( repository.getLocation(), toPath( reference ) );
}
@Override
public String toMetadataPath( ProjectReference reference )
{
// No metadata present in legacy repository.
return null;
}
@Override
public String toMetadataPath( VersionedReference reference )
{
// No metadata present in legacy repository.
return null;
}
private void getProjectVersions( File typeDir, ProjectReference reference, Set<String> foundVersions )
{
File repoFiles[] = typeDir.listFiles();
for ( File repoFile : repoFiles )
{
if ( repoFile.isDirectory() )
{
// Skip it. it's a directory.
continue;
}
String relativePath = PathUtil.getRelative( repository.getLocation(), repoFile );
if ( filetypes.matchesArtifactPattern( relativePath ) )
{
try
{
ArtifactReference artifact = toArtifactReference( relativePath );
if ( StringUtils.equals( artifact.getArtifactId(), reference.getArtifactId() ) )
{
foundVersions.add( artifact.getVersion() );
}
}
catch ( LayoutException e )
{
/* don't fail the process if there is a bad artifact within the directory. */
}
}
}
}
private void getRelatedArtifacts( File typeDir, ArtifactReference reference, Set<ArtifactReference> foundArtifacts )
{
File repoFiles[] = typeDir.listFiles();
for ( int i = 0; i < repoFiles.length; i++ )
{
if ( repoFiles[i].isDirectory() )
{
// Skip it. it's a directory.
continue;
}
String relativePath = PathUtil.getRelative( repository.getLocation(), repoFiles[i] );
if ( filetypes.matchesArtifactPattern( relativePath ) )
{
try
{
ArtifactReference artifact = toArtifactReference( relativePath );
if ( StringUtils.equals( artifact.getArtifactId(), reference.getArtifactId() )
&& artifact.getVersion().startsWith( reference.getVersion() ) )
{
foundArtifacts.add( artifact );
}
}
catch ( LayoutException e )
{
/* don't fail the process if there is a bad artifact within the directory. */
}
}
}
}
private void getVersionedVersions( File typeDir, VersionedReference reference, Set<String> foundVersions )
{
File repoFiles[] = typeDir.listFiles();
for ( int i = 0; i < repoFiles.length; i++ )
{
if ( repoFiles[i].isDirectory() )
{
// Skip it. it's a directory.
continue;
}
String relativePath = PathUtil.getRelative( repository.getLocation(), repoFiles[i] );
if ( filetypes.matchesArtifactPattern( relativePath ) )
{
try
{
ArtifactReference artifact = toArtifactReference( relativePath );
if ( StringUtils.equals( artifact.getArtifactId(), reference.getArtifactId() )
&& artifact.getVersion().startsWith( reference.getVersion() ) )
{
foundVersions.add( artifact.getVersion() );
}
}
catch ( LayoutException e )
{
/* don't fail the process if there is a bad artifact within the directory. */
}
}
}
}
public void setFileTypes( FileTypes fileTypes )
{
this.filetypes = fileTypes;
}
@Override
public void deleteArtifact( ArtifactReference artifactReference )
throws ContentNotFoundException
{
// TODO implements for legacy ??
}
@Override
public void deleteGroupId( String groupId )
throws ContentNotFoundException
{
// TODO implements for legacy ??
}
}

View File

@ -1,93 +0,0 @@
package org.apache.archiva.repository.content.legacy;
/*
* 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.archiva.admin.model.beans.RemoteRepository;
import org.apache.archiva.model.ArtifactReference;
import org.apache.archiva.model.RepositoryURL;
import org.apache.archiva.repository.RemoteRepositoryContent;
import org.apache.archiva.repository.content.legacy.AbstractLegacyRepositoryContent;
import org.apache.archiva.repository.layout.LayoutException;
import org.springframework.context.annotation.Scope;
import org.springframework.stereotype.Service;
/**
* RemoteLegacyRepositoryContent
*
*
* TODO no need to be a component once legacy path parser is not
*/
@Service( "remoteRepositoryContent#legacy" )
@Scope( "prototype" )
public class RemoteLegacyRepositoryContent
extends AbstractLegacyRepositoryContent
implements RemoteRepositoryContent
{
private RemoteRepository repository;
@Override
public String getId()
{
return repository.getId();
}
@Override
public RemoteRepository getRepository()
{
return repository;
}
@Override
public RepositoryURL getURL()
{
return new RepositoryURL( repository.getUrl() );
}
@Override
public void setRepository( RemoteRepository repository )
{
this.repository = repository;
}
/**
* Convert a path to an artifact reference.
*
* @param path the path to convert. (relative or full url path)
* @throws org.apache.archiva.repository.layout.LayoutException if the path cannot be converted to an artifact reference.
*/
@Override
public ArtifactReference toArtifactReference( String path )
throws LayoutException
{
if ( path.startsWith( repository.getUrl() ) )
{
return super.toArtifactReference( path.substring( repository.getUrl().length() ) );
}
return super.toArtifactReference( path );
}
@Override
public RepositoryURL toURL( ArtifactReference reference )
{
String url = repository.getUrl() + toPath( reference );
return new RepositoryURL( url );
}
}

View File

@ -1,99 +0,0 @@
package org.apache.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.archiva.admin.model.beans.ManagedRepository;
import org.apache.archiva.admin.model.beans.RemoteRepository;
import org.junit.Rule;
import org.junit.rules.TestName;
import org.junit.runner.RunWith;
import org.springframework.context.ApplicationContext;
import org.springframework.test.context.ContextConfiguration;
import java.io.File;
import javax.inject.Inject;
import org.apache.archiva.test.utils.ArchivaSpringJUnit4ClassRunner;
/**
* AbstractRepositoryLayerTestCase
*
*
*/
@RunWith( ArchivaSpringJUnit4ClassRunner.class )
@ContextConfiguration( { "classpath*:/META-INF/spring-context.xml", "classpath:/spring-context-no-mock-conf.xml" } )
public abstract class AbstractRepositoryLayerTestCase
{
@Rule
public TestName name = new TestName();
@Inject
protected ApplicationContext applicationContext;
protected ManagedRepository createRepository( String id, String name, File location )
{
ManagedRepository repo = new ManagedRepository();
repo.setId( id );
repo.setName( name );
repo.setLocation( location.getAbsolutePath() );
return repo;
}
protected RemoteRepository createRemoteRepository( String id, String name, String url )
{
RemoteRepository repo = new RemoteRepository();
repo.setId( id );
repo.setName( name );
repo.setUrl( url );
return repo;
}
protected ManagedRepositoryContent createManagedRepositoryContent( String id, String name, File location,
String layout )
throws Exception
{
ManagedRepository repo = new ManagedRepository();
repo.setId( id );
repo.setName( name );
repo.setLocation( location.getAbsolutePath() );
repo.setLayout( layout );
ManagedRepositoryContent repoContent =
applicationContext.getBean( "managedRepositoryContent#" + layout, ManagedRepositoryContent.class );
repoContent.setRepository( repo );
return repoContent;
}
protected RemoteRepositoryContent createRemoteRepositoryContent( String id, String name, String url, String layout )
throws Exception
{
RemoteRepository repo = new RemoteRepository();
repo.setId( id );
repo.setName( name );
repo.setUrl( url );
repo.setLayout( layout );
RemoteRepositoryContent repoContent =
applicationContext.getBean( "remoteRepositoryContent#" + layout, RemoteRepositoryContent.class );
repoContent.setRepository( repo );
return repoContent;
}
}

View File

@ -1,497 +0,0 @@
package org.apache.archiva.repository.content.legacy;
/*
* 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.archiva.configuration.ArchivaConfiguration;
import org.apache.archiva.configuration.LegacyArtifactPath;
import org.apache.archiva.model.ArtifactReference;
import org.apache.archiva.repository.layout.LayoutException;
import org.apache.archiva.test.utils.ArchivaSpringJUnit4ClassRunner;
import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.springframework.test.context.ContextConfiguration;
import javax.inject.Inject;
import javax.inject.Named;
import static org.junit.Assert.*;
/**
* LegacyPathParserTest
*
*
*/
@RunWith ( ArchivaSpringJUnit4ClassRunner.class )
@ContextConfiguration ( { "classpath*:/META-INF/spring-context.xml", "classpath:/spring-context-no-mock-conf.xml" } )
public class LegacyPathParserTest
{
private LegacyPathParser parser;
@Inject
@Named( "archivaConfiguration#default" )
ArchivaConfiguration config;
/**
* Configure the ArchivaConfiguration
* {@inheritDoc}
*/
@Before
public void setUp()
throws Exception
{
parser = new LegacyPathParser( config );
LegacyArtifactPath jaxen = new LegacyArtifactPath();
jaxen.setPath( "jaxen/jars/jaxen-1.0-FCS-full.jar" );
jaxen.setArtifact( "jaxen:jaxen:1.0-FCS:full:jar" );
config.getConfiguration().addLegacyArtifactPath( jaxen );
parser.configuration = config;
}
@Test
public void testBadPathArtifactIdMissingA()
{
assertBadPath( "groupId/jars/-1.0.jar", "artifactId is missing" );
}
@Test
public void testBadPathArtifactIdMissingB()
{
assertBadPath( "groupId/jars/1.0.jar", "artifactId is missing" );
}
@Test
public void testBadPathMissingType()
{
assertBadPath( "invalid/invalid/1/invalid-1", "missing type" );
}
@Test
public void testBadPathTooShort()
{
// NEW
assertBadPath( "invalid/invalid-1.0.jar", "path is too short" );
}
@Test
public void testBadPathWrongPackageExtension()
{
assertBadPath( "org.apache.maven.test/jars/artifactId-1.0.war", "wrong package extension" );
}
/**
* [MRM-481] Artifact requests with a .xml.zip extension fail with a 404 Error
*/
@Test
public void testGoodButDualExtensions()
throws LayoutException
{
String groupId = "org.project";
String artifactId = "example-presentation";
String version = "3.2.xml";
String type = "distribution-zip";
String path = "org.project/zips/example-presentation-3.2.xml.zip";
assertLayout( path, groupId, artifactId, version, null, type );
}
/**
* [MRM-432] Oddball version spec.
* Example of an oddball / unusual version spec.
*
* @throws org.apache.archiva.repository.layout.LayoutException
*/
@Test
public void testGoodButOddVersionSpecGanymedSsh2()
throws LayoutException
{
String groupId = "ch.ethz.ganymed";
String artifactId = "ganymed-ssh2";
String version = "build210";
String type = "jar";
String path = "ch.ethz.ganymed/jars/ganymed-ssh2-build210.jar";
assertLayout( path, groupId, artifactId, version, null, type );
}
/**
* [MRM-432] Oddball version spec.
* Example of an oddball / unusual version spec.
*
* @throws org.apache.archiva.repository.layout.LayoutException
*/
@Test
public void testGoodButOddVersionSpecJavaxComm()
throws LayoutException
{
String groupId = "javax";
String artifactId = "comm";
String version = "3.0-u1";
String type = "jar";
String path = "javax/jars/comm-3.0-u1.jar";
assertLayout( path, groupId, artifactId, version, null, type );
}
/**
* [MRM-432] Oddball version spec.
* Example of an oddball / unusual version spec.
*
* @throws org.apache.archiva.repository.layout.LayoutException
*/
@Test
public void testGoodButOddVersionSpecJavaxPersistence()
throws LayoutException
{
String groupId = "javax.persistence";
String artifactId = "ejb";
String version = "3.0-public_review";
String type = "jar";
String path = "javax.persistence/jars/ejb-3.0-public_review.jar";
/*
* The version id of "public_review" can cause problems. is it part of
* the version spec? or the classifier?
*/
assertLayout( path, groupId, artifactId, version, null, type );
}
@Test
public void testGoodCommonsLang()
throws LayoutException
{
String groupId = "commons-lang";
String artifactId = "commons-lang";
String version = "2.1";
String type = "jar";
String path = "commons-lang/jars/commons-lang-2.1.jar";
assertLayout( path, groupId, artifactId, version, null, type );
}
@Test
public void testGoodDerby()
throws LayoutException
{
String groupId = "org.apache.derby";
String artifactId = "derby";
String version = "10.2.2.0";
String type = "jar";
String path = "org.apache.derby/jars/derby-10.2.2.0.jar";
assertLayout( path, groupId, artifactId, version, null, type );
}
/**
* Test the ejb-client type spec.
* Type specs are not a 1 to 1 map to the extension.
* This tests that effect.
* @throws org.apache.archiva.repository.layout.LayoutException
*/
/* TODO: Re-enabled in the future.
public void testGoodFooEjbClient()
throws LayoutException
{
String groupId = "com.foo";
String artifactId = "foo-client";
String version = "1.0";
String type = "ejb"; // oddball type-spec (should result in jar extension)
String path = "com.foo/ejbs/foo-client-1.0.jar";
assertLayout( path, groupId, artifactId, version, classifier, type );
}
*/
/**
* Test the classifier.
*
* @throws org.apache.archiva.repository.layout.LayoutException
*/
@Test
public void testGoodFooLibJavadoc()
throws LayoutException
{
String groupId = "com.foo.lib";
String artifactId = "foo-lib";
String version = "2.1-alpha-1";
String type = "javadoc";
String classifier = "javadoc";
String path = "com.foo.lib/javadoc.jars/foo-lib-2.1-alpha-1-javadoc.jar";
assertLayout( path, groupId, artifactId, version, classifier, type );
assertLayout( "com.foo.lib/javadocs/foo-lib-2.1-alpha-1-javadoc.jar", "com.foo.lib", "foo-lib", "2.1-alpha-1",
"javadoc", "javadoc" );
}
/**
* Test the classifier, and java-source type spec.
*
* @throws org.apache.archiva.repository.layout.LayoutException
*/
@Test
public void testGoodFooLibSources()
throws LayoutException
{
String groupId = "com.foo.lib";
String artifactId = "foo-lib";
String version = "2.1-alpha-1";
String type = "java-source"; // oddball type-spec (should result in jar extension)
String classifier = "sources";
String path = "com.foo.lib/java-sources/foo-lib-2.1-alpha-1-sources.jar";
assertLayout( path, groupId, artifactId, version, classifier, type );
}
/**
* Test the classifier, and java-source type spec.
*
* @throws org.apache.archiva.repository.layout.LayoutException
*/
@Test
public void testBadClassifierFooLibSources()
throws LayoutException
{
assertBadPath( "com.foo.lib/java-sources/foo-lib-2.1-alpha-1.jar", "missing required classifier" );
assertBadPath( "com.foo.lib/java-sources/foo-lib-2.1-alpha-1-javadoc.jar", "incorrect classifier" );
assertBadPath( "com.foo.lib/java-sources/foo-lib-2.1-alpha-1-other.jar", "incorrect classifier" );
}
/**
* Test the classifier, and java-source type spec.
*
* @throws org.apache.archiva.repository.layout.LayoutException
*/
@Test
public void testGoodFooLibTestSources()
throws LayoutException
{
String groupId = "com.foo.lib";
String artifactId = "foo-lib";
String version = "2.1-alpha-1-test-sources";
String type = "jar";
String classifier = null; // we can't parse this type of classifier in legacy format
String path = "com.foo.lib/jars/foo-lib-2.1-alpha-1-test-sources.jar";
assertLayout( path, groupId, artifactId, version, classifier, type );
}
@Test
public void testGoodFooTool()
throws LayoutException
{
String groupId = "com.foo";
String artifactId = "foo-tool";
String version = "1.0";
String type = "jar";
String path = "com.foo/jars/foo-tool-1.0.jar";
assertLayout( path, groupId, artifactId, version, null, type );
}
@Test
public void testGoodGeronimoEjbSpec()
throws LayoutException
{
String groupId = "org.apache.geronimo.specs";
String artifactId = "geronimo-ejb_2.1_spec";
String version = "1.0.1";
String type = "jar";
String path = "org.apache.geronimo.specs/jars/geronimo-ejb_2.1_spec-1.0.1.jar";
assertLayout( path, groupId, artifactId, version, null, type );
}
@Test
public void testGoodLdapClientsPom()
throws LayoutException
{
String groupId = "directory-clients";
String artifactId = "ldap-clients";
String version = "0.9.1-SNAPSHOT";
String type = "pom";
String path = "directory-clients/poms/ldap-clients-0.9.1-SNAPSHOT.pom";
assertLayout( path, groupId, artifactId, version, null, type );
}
/**
* A timestamped versioned artifact, should reside in a SNAPSHOT baseversion directory.
*
* @throws org.apache.archiva.repository.layout.LayoutException
*/
@Test
public void testGoodSnapshotMavenTest()
throws LayoutException
{
String groupId = "org.apache.archiva.test";
String artifactId = "redonkulous";
String version = "3.1-beta-1-20050831.101112-42";
String type = "jar";
String path = "org.apache.archiva.test/jars/redonkulous-3.1-beta-1-20050831.101112-42.jar";
assertLayout( path, groupId, artifactId, version, null, type );
}
/**
* [MRM-519] version identifiers within filename cause misidentification of version.
* Example uses "test" in artifact Id, which is also part of the versionKeyword list.
*/
@Test
public void testGoodVersionKeywordInArtifactId()
throws LayoutException
{
String groupId = "maven";
String artifactId = "maven-test-plugin";
String version = "1.8.2";
String type = "pom";
String path = "maven/poms/maven-test-plugin-1.8.2.pom";
assertLayout( path, groupId, artifactId, version, null, type );
}
/**
* [MRM-562] Artifact type "maven-plugin" is not detected correctly in .toArtifactReference() methods.
* Example uses "test" in artifact Id, which is also part of the versionKeyword list.
*/
@Test
public void testGoodDetectPluginMavenTest()
throws LayoutException
{
String groupId = "maven";
String artifactId = "maven-test-plugin";
String version = "1.8.2";
String type = "maven-one-plugin";
String path = "maven/plugins/maven-test-plugin-1.8.2.jar";
assertLayout( path, groupId, artifactId, version, null, type );
}
/**
* [MRM-562] Artifact type "maven-plugin" is not detected correctly in .toArtifactReference() methods.
*/
@Test
public void testGoodDetectPluginAvalonMeta()
throws LayoutException
{
String groupId = "avalon-meta";
String artifactId = "avalon-meta-plugin";
String version = "1.1";
String type = "maven-one-plugin";
String path = "avalon-meta/plugins/avalon-meta-plugin-1.1.jar";
assertLayout( path, groupId, artifactId, version, null, type );
}
/**
* [MRM-562] Artifact type "maven-plugin" is not detected correctly in .toArtifactReference() methods.
*/
@Test
public void testGoodDetectPluginCactusMaven()
throws LayoutException
{
String groupId = "cactus";
String artifactId = "cactus-maven";
String version = "1.7dev-20040815";
String type = "maven-one-plugin";
String path = "cactus/plugins/cactus-maven-1.7dev-20040815.jar";
assertLayout( path, groupId, artifactId, version, null, type );
}
/**
* [MRM-562] Artifact type "maven-plugin" is not detected correctly in .toArtifactReference() methods.
*/
@Test
public void testGoodDetectPluginGeronimoPackaging()
throws LayoutException
{
String groupId = "geronimo";
String artifactId = "geronimo-packaging-plugin";
String version = "1.0.1";
String type = "maven-one-plugin";
String path = "geronimo/plugins/geronimo-packaging-plugin-1.0.1.jar";
assertLayout( path, groupId, artifactId, version, null, type );
}
/**
* [MRM-594] add some hook in LegacyPathParser to allow exceptions in artifact resolution
*
* @since 1.1
*/
@Test
public void testCustomExceptionsInArtifactResolution()
throws LayoutException
{
String groupId = "jaxen";
String artifactId = "jaxen";
String version = "1.0-FCS";
String type = "jar";
String classifier = "full";
String path = "jaxen/jars/jaxen-1.0-FCS-full.jar";
assertLayout( path, groupId, artifactId, version, classifier, type );
}
/**
* Perform a path to artifact reference lookup, and verify the results.
*/
private void assertLayout( String path, String groupId, String artifactId, String version, String classifier,
String type )
throws LayoutException
{
// Path to Artifact Reference.
ArtifactReference testReference = parser.toArtifactReference( path );
assertArtifactReference( testReference, groupId, artifactId, version, classifier, type );
}
private void assertArtifactReference( ArtifactReference actualReference, String groupId, String artifactId,
String version, String classifier, String type )
{
String expectedId =
"ArtifactReference - " + groupId + ":" + artifactId + ":" + version + ":" + classifier + ":" + type;
assertNotNull( expectedId + " - Should not be null.", actualReference );
assertEquals( expectedId + " - Group ID", groupId, actualReference.getGroupId() );
assertEquals( expectedId + " - Artifact ID", artifactId, actualReference.getArtifactId() );
assertEquals( expectedId + " - Version ID", version, actualReference.getVersion() );
assertEquals( expectedId + " - classifier", classifier, actualReference.getClassifier() );
assertEquals( expectedId + " - Type", type, actualReference.getType() );
}
protected void assertBadPath( String path, String reason )
{
try
{
parser.toArtifactReference( path );
fail(
"Should have thrown a LayoutException on the invalid path [" + path + "] because of [" + reason + "]" );
}
catch ( LayoutException e )
{
/* expected path */
}
}
}

View File

@ -1 +0,0 @@
not a real CVS root - for testing exclusions

View File

@ -1,52 +0,0 @@
<?xml version="1.0" encoding="UTF-8"?>
<project>
<extend>../../project.xml</extend>
<pomVersion>3</pomVersion>
<groupId>maven</groupId>
<id>wagon-ssh</id>
<artifactId>wagon-ssh</artifactId>
<name>Wagon SSH provider</name>
<currentVersion>1.0-SNAPSHOT</currentVersion>
<description></description>
<shortDescription>Wagon Provider for protocols from SSH2 family based on JSCH</shortDescription>
<package>org.apache.maven.wagon.providers.ssh</package>
<inceptionYear>2003</inceptionYear>
<url>http://maven.apache.org/wagon/wagon-providers/ssh</url>
<issueTrackingUrl>http://jira.codehaus.org/BrowseProject.jspa?id=10319</issueTrackingUrl>
<siteDirectory>/www/maven.apache.org/wagon/wagon-providers/ssh</siteDirectory>
<repository>
<connection>scm:cvs:pserver:anoncvs@cvs.apache.org:/home/cvspublic:maven-wagon/wagon-providers/ssh</connection>
<url>http://cvs.apache.org/viewcvs/maven-wagon/wagon-providers/ssh/</url>
</repository>
<developers>
<developer>
<name>Michal Maczka</name>
<id>michal</id>
<email>michal.maczka@dimatics.com</email>
<organization>Dimatics</organization>
<roles>
<role>Creator</role>
<role>Developer</role>
<role>Release Manager</role>
</roles>
</developer>
</developers>
<dependencies>
<dependency>
<groupId>maven</groupId>
<artifactId>wagon-api</artifactId>
<version>0.9-SNAPSHOT</version>
<type>jar</type>
</dependency>
<dependency>
<groupId>jsch</groupId>
<artifactId>jsch</artifactId>
<version>0.1.14</version>
<type>jar</type>
</dependency>
</dependencies>
</project>

View File

@ -1,15 +0,0 @@
<project>
<pomVersion>3</pomVersion>
<groupId>org.apache.maven</groupId>
<artifactId>maven-model-v3</artifactId>
<name>Maven Model v3</name>
<currentVersion>2.0</currentVersion>
<description>Maven Model v3</description>
<dependencies>
<dependency>
<groupId>org.codehaus.plexus</groupId>
<artifactId>plexus-utils</artifactId>
<version>1.0.4</version>
</dependency>
</dependencies>
</project>