mirror of https://github.com/apache/archiva.git
Remove unused classes.
git-svn-id: https://svn.apache.org/repos/asf/maven/archiva/trunk@585588 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
parent
37b716926d
commit
0427f685c7
|
@ -1,106 +0,0 @@
|
|||
package org.apache.maven.archiva.repository.layout;
|
||||
|
||||
/*
|
||||
* 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.ArchivaArtifact;
|
||||
import org.apache.maven.archiva.model.ArtifactReference;
|
||||
import org.apache.maven.archiva.model.VersionedReference;
|
||||
import org.apache.maven.archiva.repository.ManagedRepositoryContent;
|
||||
import org.apache.maven.archiva.repository.RemoteRepositoryContent;
|
||||
import org.apache.maven.archiva.repository.RepositoryContentFactory;
|
||||
import org.apache.maven.archiva.repository.content.RepositoryRequest;
|
||||
|
||||
/**
|
||||
* BidirectionalRepositoryLayout - Similar in scope to ArtifactRepositoryLayout, but does
|
||||
* the both the Path to Artifact, and Artifact to Path conversions.
|
||||
*
|
||||
* @author <a href="mailto:joakime@apache.org">Joakim Erdfelt</a>
|
||||
* @version $Id$
|
||||
*
|
||||
* @deprecated use {@link RepositoryContentFactory} instead.
|
||||
*/
|
||||
public interface BidirectionalRepositoryLayout
|
||||
{
|
||||
/**
|
||||
* Get the identifier for this layout.
|
||||
*
|
||||
* @return the identifier for this layout.
|
||||
*
|
||||
* @deprecated use {@link ManagedRepositoryContent#getId()} or {@link RemoteRepositoryContent#getId()} instead.
|
||||
*/
|
||||
public String getId();
|
||||
|
||||
/**
|
||||
* Given a repository relative path, return <code>true</code> if the path is valid
|
||||
* according to the repository layout.
|
||||
*
|
||||
* @deprecated use {@link RepositoryRequest#toArtifactReference(String)} instead.
|
||||
*/
|
||||
public boolean isValidPath( String path );
|
||||
|
||||
/**
|
||||
* Given an ArchivaArtifact, return the relative path to the artifact.
|
||||
*
|
||||
* @param artifact the artifact to use.
|
||||
* @return the relative path to the artifact.
|
||||
*
|
||||
* @deprecated use {@link ManagedRepositoryContent#toPath(ArchivaArtifact)} instead.
|
||||
*/
|
||||
public String toPath( ArchivaArtifact artifact );
|
||||
|
||||
/**
|
||||
* Given an ArtifactReference, return the relative path to the artifact.
|
||||
*
|
||||
* @param reference the artifact reference to use.
|
||||
* @return the relative path to the artifact.
|
||||
*
|
||||
* @deprecated use {@link ManagedRepositoryContent#toPath(ArtifactReference))} or
|
||||
* {@link RemoteRepositoryContent#toPath(ArtifactReference)} instead.
|
||||
*/
|
||||
public String toPath( ArtifactReference reference );
|
||||
|
||||
/**
|
||||
* Given a repository relative path to a filename, return the {@link ArchivaArtifact} object suitable for the path.
|
||||
*
|
||||
* @param path the path relative to the repository base dir for the artifact.
|
||||
* @return the {@link ArchivaArtifact} representing the path. (or null if path cannot be converted to
|
||||
* an {@link ArchivaArtifact})
|
||||
* @throws LayoutException if there was a problem converting the path to an artifact.
|
||||
*
|
||||
* @deprecated use {@link ManagedRepositoryContent#toArtifactReference(String))} or
|
||||
* {@link RemoteRepositoryContent#toArtifactReference(String)} instead.
|
||||
*/
|
||||
public ArchivaArtifact toArtifact( String path )
|
||||
throws LayoutException;
|
||||
|
||||
/**
|
||||
* Given a repository relative path to a filename, return the {@link VersionedReference} object suitable for the path.
|
||||
*
|
||||
* @param path the path relative to the repository base dir for the artifact.
|
||||
* @return the {@link ArtifactReference} representing the path. (or null if path cannot be converted to
|
||||
* a {@link ArtifactReference})
|
||||
* @throws LayoutException if there was a problem converting the path to an artifact.
|
||||
*
|
||||
* @deprecated use {@link ManagedRepositoryContent#toArtifactReference(String))} or
|
||||
* {@link RemoteRepositoryContent#toArtifactReference(String)} instead.
|
||||
*/
|
||||
public ArtifactReference toArtifactReference( String path )
|
||||
throws LayoutException;
|
||||
}
|
|
@ -1,149 +0,0 @@
|
|||
package org.apache.maven.archiva.repository.layout;
|
||||
|
||||
/*
|
||||
* 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.configuration.AbstractRepositoryConfiguration;
|
||||
import org.apache.maven.archiva.configuration.ArchivaConfiguration;
|
||||
import org.apache.maven.archiva.configuration.ConfigurationNames;
|
||||
import org.apache.maven.archiva.model.ArchivaArtifact;
|
||||
import org.apache.maven.archiva.repository.RepositoryContentFactory;
|
||||
import org.apache.maven.archiva.repository.content.RepositoryRequest;
|
||||
import org.codehaus.plexus.logging.AbstractLogEnabled;
|
||||
import org.codehaus.plexus.personality.plexus.lifecycle.phase.Initializable;
|
||||
import org.codehaus.plexus.personality.plexus.lifecycle.phase.InitializationException;
|
||||
import org.codehaus.plexus.registry.Registry;
|
||||
import org.codehaus.plexus.registry.RegistryListener;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.Iterator;
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
* BidirectionalRepositoryLayoutFactory
|
||||
*
|
||||
* @author <a href="mailto:joakime@apache.org">Joakim Erdfelt</a>
|
||||
* @version $Id$
|
||||
*
|
||||
* @deprecated use {@link RepositoryContentFactory} instead.
|
||||
*
|
||||
* @plexus.component role="org.apache.maven.archiva.repository.layout.BidirectionalRepositoryLayoutFactory"
|
||||
*/
|
||||
public class BidirectionalRepositoryLayoutFactory
|
||||
extends AbstractLogEnabled
|
||||
implements RegistryListener, Initializable
|
||||
{
|
||||
/**
|
||||
* @plexus.requirement role="org.apache.maven.archiva.repository.layout.BidirectionalRepositoryLayout"
|
||||
*/
|
||||
private Map layouts;
|
||||
|
||||
/**
|
||||
* @plexus.requirement
|
||||
*/
|
||||
private ArchivaConfiguration configuration;
|
||||
|
||||
private Map repositoryMap = new HashMap();
|
||||
|
||||
/**
|
||||
* @deprecated use {@link RepositoryContentFactory#getManagedRepositoryContent(String)} or
|
||||
* {@link RepositoryContentFactory#getRemoteRepositoryContent(String)} instead.
|
||||
*/
|
||||
public BidirectionalRepositoryLayout getLayout( String type )
|
||||
throws LayoutException
|
||||
{
|
||||
if ( !layouts.containsKey( type ) )
|
||||
{
|
||||
throw new LayoutException(
|
||||
"Layout type [" + type + "] does not exist. " + "Available types [" + layouts.keySet() + "]" );
|
||||
}
|
||||
|
||||
return (BidirectionalRepositoryLayout) layouts.get( type );
|
||||
}
|
||||
|
||||
/**
|
||||
* @deprecated use {@link RepositoryRequest#toArtifactReference(String)} instead.
|
||||
*/
|
||||
public BidirectionalRepositoryLayout getLayoutForPath( String path )
|
||||
throws LayoutException
|
||||
{
|
||||
for ( Iterator iter = layouts.values().iterator(); iter.hasNext(); )
|
||||
{
|
||||
BidirectionalRepositoryLayout layout = (BidirectionalRepositoryLayout) iter.next();
|
||||
if ( layout.isValidPath( path ) )
|
||||
{
|
||||
return layout;
|
||||
}
|
||||
}
|
||||
throw new LayoutException( "No valid layout was found for path [" + path + "]" );
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @deprecated use {@link RepositoryContentFactory#getManagedRepositoryContent(String)} or
|
||||
* {@link RepositoryContentFactory#getRemoteRepositoryContent(String)} instead.
|
||||
*/
|
||||
public BidirectionalRepositoryLayout getLayout( ArchivaArtifact artifact )
|
||||
throws LayoutException
|
||||
{
|
||||
if ( artifact == null )
|
||||
{
|
||||
throw new LayoutException( "Cannot determine layout using a null artifact." );
|
||||
}
|
||||
|
||||
String repoId = artifact.getModel().getRepositoryId();
|
||||
if ( StringUtils.isBlank( repoId ) )
|
||||
{
|
||||
throw new LayoutException( "Cannot determine layout using artifact with no repository id: " + artifact );
|
||||
}
|
||||
|
||||
AbstractRepositoryConfiguration repo = (AbstractRepositoryConfiguration) this.repositoryMap.get( repoId );
|
||||
return getLayout( repo.getLayout() );
|
||||
}
|
||||
|
||||
public void afterConfigurationChange( Registry registry, String propertyName, Object propertyValue )
|
||||
{
|
||||
if ( ConfigurationNames.isManagedRepositories( propertyName ) )
|
||||
{
|
||||
initRepositoryMap();
|
||||
}
|
||||
}
|
||||
|
||||
public void beforeConfigurationChange( Registry registry, String propertyName, Object propertyValue )
|
||||
{
|
||||
/* do nothing */
|
||||
}
|
||||
|
||||
private void initRepositoryMap()
|
||||
{
|
||||
synchronized ( this.repositoryMap )
|
||||
{
|
||||
this.repositoryMap.clear();
|
||||
this.repositoryMap.putAll( configuration.getConfiguration().getManagedRepositoriesAsMap() );
|
||||
}
|
||||
}
|
||||
|
||||
public void initialize()
|
||||
throws InitializationException
|
||||
{
|
||||
initRepositoryMap();
|
||||
configuration.addChangeListener( this );
|
||||
}
|
||||
}
|
|
@ -1,313 +0,0 @@
|
|||
package org.apache.maven.archiva.repository.layout;
|
||||
|
||||
/*
|
||||
* 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.common.utils.VersionUtil;
|
||||
import org.apache.maven.archiva.model.ArchivaArtifact;
|
||||
import org.apache.maven.archiva.model.ArtifactReference;
|
||||
import org.apache.maven.archiva.repository.ManagedRepositoryContent;
|
||||
import org.apache.maven.archiva.repository.RemoteRepositoryContent;
|
||||
import org.apache.maven.archiva.repository.content.ArtifactExtensionMapping;
|
||||
|
||||
/**
|
||||
* DefaultBidirectionalRepositoryLayout - the layout mechanism for use by Maven 2.x repositories.
|
||||
*
|
||||
* @author <a href="mailto:joakime@apache.org">Joakim Erdfelt</a>
|
||||
* @version $Id$
|
||||
* @plexus.component role-hint="default"
|
||||
* @deprecated to not use directly. Use {@link ManagedRepositoryContent} or {@link RemoteRepositoryContent} instead.
|
||||
*/
|
||||
public class DefaultBidirectionalRepositoryLayout
|
||||
implements BidirectionalRepositoryLayout
|
||||
{
|
||||
class PathReferences
|
||||
{
|
||||
public String groupId;
|
||||
|
||||
public String artifactId;
|
||||
|
||||
public String baseVersion;
|
||||
|
||||
public String type;
|
||||
|
||||
public FilenameParts fileParts;
|
||||
|
||||
public void appendGroupId( String part )
|
||||
{
|
||||
if ( groupId == null )
|
||||
{
|
||||
groupId = part;
|
||||
return;
|
||||
}
|
||||
|
||||
groupId += "." + part;
|
||||
}
|
||||
}
|
||||
|
||||
private static final char PATH_SEPARATOR = '/';
|
||||
|
||||
private static final char GROUP_SEPARATOR = '.';
|
||||
|
||||
private static final char ARTIFACT_SEPARATOR = '-';
|
||||
|
||||
public String getId()
|
||||
{
|
||||
return "default";
|
||||
}
|
||||
|
||||
public ArchivaArtifact toArtifact( String path )
|
||||
throws LayoutException
|
||||
{
|
||||
PathReferences pathrefs = toPathReferences( path );
|
||||
|
||||
ArchivaArtifact artifact = new ArchivaArtifact( pathrefs.groupId, pathrefs.artifactId,
|
||||
pathrefs.fileParts.version, pathrefs.fileParts.classifier,
|
||||
pathrefs.type );
|
||||
|
||||
return artifact;
|
||||
}
|
||||
|
||||
public ArtifactReference toArtifactReference( String path )
|
||||
throws LayoutException
|
||||
{
|
||||
PathReferences pathrefs = toPathReferences( path );
|
||||
|
||||
ArtifactReference reference = new ArtifactReference();
|
||||
reference.setGroupId( pathrefs.groupId );
|
||||
reference.setArtifactId( pathrefs.artifactId );
|
||||
reference.setVersion( pathrefs.fileParts.version );
|
||||
reference.setClassifier( pathrefs.fileParts.classifier );
|
||||
reference.setType( pathrefs.type );
|
||||
|
||||
return reference;
|
||||
}
|
||||
|
||||
public String toPath( ArchivaArtifact artifact )
|
||||
{
|
||||
if ( artifact == null )
|
||||
{
|
||||
throw new IllegalArgumentException( "Artifact cannot be null" );
|
||||
}
|
||||
|
||||
return toPath( artifact.getGroupId(), artifact.getArtifactId(), artifact.getBaseVersion(), artifact
|
||||
.getVersion(), artifact.getClassifier(), artifact.getType() );
|
||||
}
|
||||
|
||||
public String toPath( ArtifactReference reference )
|
||||
{
|
||||
if ( reference == null )
|
||||
{
|
||||
throw new IllegalArgumentException( "Artifact reference cannot be null" );
|
||||
}
|
||||
|
||||
String baseVersion = VersionUtil.getBaseVersion( reference.getVersion() );
|
||||
return toPath( reference.getGroupId(), reference.getArtifactId(), baseVersion, reference.getVersion(),
|
||||
reference.getClassifier(), reference.getType() );
|
||||
}
|
||||
|
||||
private String formatAsDirectory( String directory )
|
||||
{
|
||||
return directory.replace( GROUP_SEPARATOR, PATH_SEPARATOR );
|
||||
}
|
||||
|
||||
private String toPath( String groupId, String artifactId, String baseVersion, String version, String classifier,
|
||||
String type )
|
||||
{
|
||||
StringBuffer path = new StringBuffer();
|
||||
|
||||
path.append( formatAsDirectory( groupId ) ).append( PATH_SEPARATOR );
|
||||
path.append( artifactId ).append( PATH_SEPARATOR );
|
||||
|
||||
if ( baseVersion != null )
|
||||
{
|
||||
path.append( baseVersion ).append( PATH_SEPARATOR );
|
||||
if ( ( version != null ) && ( type != null ) )
|
||||
{
|
||||
path.append( artifactId ).append( ARTIFACT_SEPARATOR ).append( version );
|
||||
|
||||
if ( StringUtils.isNotBlank( classifier ) )
|
||||
{
|
||||
path.append( ARTIFACT_SEPARATOR ).append( classifier );
|
||||
}
|
||||
|
||||
path.append( GROUP_SEPARATOR ).append( ArtifactExtensionMapping.getExtension( type ) );
|
||||
}
|
||||
}
|
||||
|
||||
return path.toString();
|
||||
}
|
||||
|
||||
public boolean isValidPath( String path )
|
||||
{
|
||||
try
|
||||
{
|
||||
toPathReferences( path );
|
||||
return true;
|
||||
}
|
||||
catch ( LayoutException e )
|
||||
{
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
private PathReferences toPathReferences( String path )
|
||||
throws LayoutException
|
||||
{
|
||||
if ( StringUtils.isBlank( path ) )
|
||||
{
|
||||
throw new LayoutException( "Unable to convert blank path." );
|
||||
}
|
||||
|
||||
PathReferences prefs = new PathReferences();
|
||||
|
||||
String normalizedPath = StringUtils.replace( path, "\\", "/" );
|
||||
String pathParts[] = StringUtils.split( normalizedPath, '/' );
|
||||
|
||||
/* Minimum parts.
|
||||
*
|
||||
* path = "commons-lang/commons-lang/2.1/commons-lang-2.1.jar"
|
||||
* path[0] = "commons-lang"; // The Group ID
|
||||
* path[1] = "commons-lang"; // The Artifact ID
|
||||
* path[2] = "2.1"; // The Version
|
||||
* path[3] = "commons-lang-2.1.jar" // The filename.
|
||||
*/
|
||||
|
||||
if ( pathParts.length < 4 )
|
||||
{
|
||||
// Illegal Path Parts Length.
|
||||
throw new LayoutException( "Not enough parts to the path [" + path
|
||||
+ "] to construct an ArchivaArtifact from. (Requires at least 4 parts)" );
|
||||
}
|
||||
|
||||
// Maven 2.x path.
|
||||
int partCount = pathParts.length;
|
||||
int filenamePos = partCount - 1;
|
||||
int baseVersionPos = partCount - 2;
|
||||
int artifactIdPos = partCount - 3;
|
||||
int groupIdPos = partCount - 4;
|
||||
|
||||
// Second to last is the baseVersion (the directory version)
|
||||
prefs.baseVersion = pathParts[baseVersionPos];
|
||||
|
||||
// Third to last is the artifact Id.
|
||||
prefs.artifactId = pathParts[artifactIdPos];
|
||||
|
||||
// Remaining pieces are the groupId.
|
||||
for ( int i = 0; i <= groupIdPos; i++ )
|
||||
{
|
||||
prefs.appendGroupId( pathParts[i] );
|
||||
}
|
||||
|
||||
try
|
||||
{
|
||||
// Last part is the filename
|
||||
String filename = pathParts[filenamePos];
|
||||
|
||||
// Now we need to parse the filename to get the artifact version Id.
|
||||
prefs.fileParts = RepositoryLayoutUtils.splitFilename( filename, prefs.artifactId, prefs.baseVersion );
|
||||
|
||||
/* If classifier is discovered, see if it deserves to be.
|
||||
*
|
||||
* Filenames like "comm-3.0-u1.jar" might be identified as having a version of "3.0"
|
||||
* and a classifier of "u1".
|
||||
*
|
||||
* This routine will take the version + classifier and compare it to the prefs.baseVersion and
|
||||
* move the classifierensure that
|
||||
*
|
||||
* javax/comm/3.0-u1/comm-3.0-u1.jar
|
||||
*/
|
||||
if ( StringUtils.isNotBlank( prefs.fileParts.classifier ) )
|
||||
{
|
||||
String conjoinedVersion = prefs.fileParts.version + "-" + prefs.fileParts.classifier;
|
||||
|
||||
if( StringUtils.equals( prefs.baseVersion, conjoinedVersion ) )
|
||||
{
|
||||
prefs.fileParts.version = conjoinedVersion;
|
||||
prefs.fileParts.classifier = null;
|
||||
}
|
||||
}
|
||||
|
||||
prefs.type = ArtifactExtensionMapping.guessTypeFromFilename( filename );
|
||||
}
|
||||
catch ( LayoutException e )
|
||||
{
|
||||
throw e;
|
||||
}
|
||||
|
||||
// Sanity Checks.
|
||||
if ( prefs.fileParts != null )
|
||||
{
|
||||
/* Compare artifact version to path baseversion.
|
||||
*
|
||||
* Version naming in the wild can be strange at times.
|
||||
* Sometimes what is seen as a classifier is actually part of the version id.
|
||||
*
|
||||
* To compensate for this, the path is checked against the artifact.version and
|
||||
* the concatenation of the artifact.version + "-" + artifact.classifier
|
||||
*/
|
||||
String pathVersion = prefs.baseVersion;
|
||||
String artifactVersion = prefs.fileParts.version;
|
||||
|
||||
// Do we have a snapshot version?
|
||||
if ( VersionUtil.isSnapshot( artifactVersion ) )
|
||||
{
|
||||
// Rules are different for SNAPSHOTS
|
||||
if ( !VersionUtil.isGenericSnapshot( pathVersion ) )
|
||||
{
|
||||
String baseVersion = VersionUtil.getBaseVersion( prefs.fileParts.version );
|
||||
throw new LayoutException( "Invalid snapshot artifact location, version directory should be "
|
||||
+ baseVersion );
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
// Non SNAPSHOT rules.
|
||||
// Do we pass the simple test?
|
||||
if ( !StringUtils.equals( pathVersion, artifactVersion ) )
|
||||
{
|
||||
// Do we have a classifier? If so, test the conjoined case.
|
||||
if ( StringUtils.isNotBlank( prefs.fileParts.classifier ) )
|
||||
{
|
||||
String artifactLongVersion = artifactVersion + "-" + prefs.fileParts.classifier;
|
||||
if ( !StringUtils.equals( pathVersion, artifactLongVersion ) )
|
||||
{
|
||||
throw new LayoutException( "Invalid artifact: version declared in directory path does"
|
||||
+ " not match what was found in the artifact filename." );
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
throw new LayoutException( "Invalid artifact: version declared in directory path does"
|
||||
+ " not match what was found in the artifact filename." );
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Test if the artifactId present on the directory path is the same as the artifactId filename.
|
||||
if ( !prefs.artifactId.equals( prefs.fileParts.artifactId ) )
|
||||
{
|
||||
throw new LayoutException( "Invalid artifact Id" );
|
||||
}
|
||||
}
|
||||
|
||||
return prefs;
|
||||
}
|
||||
}
|
|
@ -1,104 +0,0 @@
|
|||
package org.apache.maven.archiva.repository.layout;
|
||||
|
||||
import org.apache.maven.archiva.repository.ManagedRepositoryContent;
|
||||
import org.apache.maven.archiva.repository.RemoteRepositoryContent;
|
||||
|
||||
/*
|
||||
* 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.
|
||||
*/
|
||||
|
||||
/**
|
||||
* FilenameParts - data object for {@link RepositoryLayoutUtils#splitFilename(String, String)} method.
|
||||
*
|
||||
* @author <a href="mailto:joakime@apache.org">Joakim Erdfelt</a>
|
||||
* @version $Id$
|
||||
* @deprecated to not use directly. Use {@link ManagedRepositoryContent} or {@link RemoteRepositoryContent} instead.
|
||||
*/
|
||||
public class FilenameParts
|
||||
{
|
||||
public String artifactId;
|
||||
|
||||
public String version;
|
||||
|
||||
public String classifier;
|
||||
|
||||
public String extension;
|
||||
|
||||
public String toFilename()
|
||||
{
|
||||
StringBuffer sb = new StringBuffer();
|
||||
|
||||
if ( artifactId != null )
|
||||
{
|
||||
sb.append( artifactId );
|
||||
}
|
||||
|
||||
if ( classifier != null )
|
||||
{
|
||||
sb.append( "-" ).append( classifier );
|
||||
}
|
||||
|
||||
if ( version != null )
|
||||
{
|
||||
sb.append( "-" ).append( version );
|
||||
}
|
||||
|
||||
if ( extension != null )
|
||||
{
|
||||
sb.append( "." ).append( extension );
|
||||
}
|
||||
|
||||
return sb.toString();
|
||||
}
|
||||
|
||||
public void appendArtifactId( String piece )
|
||||
{
|
||||
if ( artifactId == null )
|
||||
{
|
||||
artifactId = piece;
|
||||
}
|
||||
else
|
||||
{
|
||||
artifactId += "-" + piece;
|
||||
}
|
||||
}
|
||||
|
||||
public void appendVersion( String piece )
|
||||
{
|
||||
if ( version == null )
|
||||
{
|
||||
version = piece;
|
||||
}
|
||||
else
|
||||
{
|
||||
version += "-" + piece;
|
||||
}
|
||||
}
|
||||
|
||||
public void appendClassifier( String piece )
|
||||
{
|
||||
if ( classifier == null )
|
||||
{
|
||||
classifier = piece;
|
||||
}
|
||||
else
|
||||
{
|
||||
classifier += "-" + piece;
|
||||
}
|
||||
}
|
||||
}
|
|
@ -1,243 +0,0 @@
|
|||
package org.apache.maven.archiva.repository.layout;
|
||||
|
||||
/*
|
||||
* 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.model.ArchivaArtifact;
|
||||
import org.apache.maven.archiva.model.ArtifactReference;
|
||||
import org.apache.maven.archiva.repository.ManagedRepositoryContent;
|
||||
import org.apache.maven.archiva.repository.RemoteRepositoryContent;
|
||||
import org.apache.maven.archiva.repository.content.ArtifactExtensionMapping;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
* LegacyBidirectionalRepositoryLayout - the layout mechanism for use by Maven 1.x repositories.
|
||||
*
|
||||
* @author <a href="mailto:joakime@apache.org">Joakim Erdfelt</a>
|
||||
* @version $Id$
|
||||
* @plexus.component role-hint="legacy"
|
||||
*
|
||||
* @deprecated to not use directly. Use {@link ManagedRepositoryContent} or {@link RemoteRepositoryContent} instead.
|
||||
*/
|
||||
public class LegacyBidirectionalRepositoryLayout
|
||||
implements BidirectionalRepositoryLayout
|
||||
{
|
||||
private static final String DIR_JAVADOC = "javadoc.jars";
|
||||
|
||||
private static final String DIR_JAVA_SOURCE = "java-sources";
|
||||
|
||||
private static final String PATH_SEPARATOR = "/";
|
||||
|
||||
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 toPath( ArchivaArtifact artifact )
|
||||
{
|
||||
return toPath( artifact.getGroupId(), artifact.getArtifactId(), artifact.getVersion(),
|
||||
artifact.getClassifier(), artifact.getType() );
|
||||
}
|
||||
|
||||
public String toPath( ArtifactReference reference )
|
||||
{
|
||||
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 )
|
||||
{
|
||||
StringBuffer path = new StringBuffer();
|
||||
|
||||
path.append( groupId ).append( PATH_SEPARATOR );
|
||||
path.append( getDirectory( classifier, 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 classifier, String type )
|
||||
{
|
||||
// Special Cases involving type + classifier
|
||||
if ( "jar".equals( type ) && StringUtils.isNotBlank( classifier ) )
|
||||
{
|
||||
if ( "sources".equals( classifier ) )
|
||||
{
|
||||
return DIR_JAVA_SOURCE;
|
||||
}
|
||||
|
||||
if ( "javadoc".equals( classifier ) )
|
||||
{
|
||||
return DIR_JAVADOC;
|
||||
}
|
||||
}
|
||||
|
||||
// Special Cases involving only type.
|
||||
String dirname = (String) typeToDirectoryMap.get( type );
|
||||
|
||||
if ( dirname != null )
|
||||
{
|
||||
return dirname + "s";
|
||||
}
|
||||
|
||||
// Default process.
|
||||
return type + "s";
|
||||
}
|
||||
|
||||
class PathReferences
|
||||
{
|
||||
public String groupId;
|
||||
|
||||
public String pathType;
|
||||
|
||||
public String type;
|
||||
|
||||
public FilenameParts fileParts;
|
||||
}
|
||||
|
||||
private PathReferences toPathReferences( String path )
|
||||
throws LayoutException
|
||||
{
|
||||
PathReferences prefs = new PathReferences();
|
||||
|
||||
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 number of parts to the path [" + path
|
||||
+ "] to construct an ArchivaArtifact from. (Required to be 3 parts)" );
|
||||
}
|
||||
|
||||
// The Group ID.
|
||||
prefs.groupId = pathParts[0];
|
||||
|
||||
// The Expected Type.
|
||||
prefs.pathType = pathParts[1];
|
||||
|
||||
// The Filename.
|
||||
String filename = pathParts[2];
|
||||
|
||||
prefs.fileParts = RepositoryLayoutUtils.splitFilename( filename, null );
|
||||
|
||||
String trimPathType = prefs.pathType.substring( 0, prefs.pathType.length() - 1 );
|
||||
prefs.type = ArtifactExtensionMapping.guessTypeFromFilename( filename );
|
||||
|
||||
// Sanity Check: does it have an extension?
|
||||
if ( StringUtils.isEmpty( prefs.fileParts.extension ) )
|
||||
{
|
||||
throw new LayoutException( "Invalid artifact, no extension." );
|
||||
}
|
||||
|
||||
// Sanity Check: pathType should end in "s".
|
||||
if ( !prefs.pathType.toLowerCase().endsWith( "s" ) )
|
||||
{
|
||||
throw new LayoutException( "Invalid path, the type specified in the path <" + prefs.pathType
|
||||
+ "> does not end in the letter <s>." );
|
||||
}
|
||||
|
||||
// Sanity Check: does extension match pathType on path?
|
||||
String expectedExtension = ArtifactExtensionMapping.getExtension( trimPathType );
|
||||
String actualExtension = prefs.fileParts.extension;
|
||||
|
||||
if ( !expectedExtension.equals( actualExtension ) )
|
||||
{
|
||||
throw new LayoutException( "Invalid artifact, mismatch on extension <" + prefs.fileParts.extension
|
||||
+ "> and layout specified type <" + prefs.pathType + "> (which maps to extension: <"
|
||||
+ expectedExtension + ">) on path <" + path + ">" );
|
||||
}
|
||||
|
||||
return prefs;
|
||||
}
|
||||
|
||||
public boolean isValidPath( String path )
|
||||
{
|
||||
try
|
||||
{
|
||||
toPathReferences( path );
|
||||
return true;
|
||||
}
|
||||
catch ( LayoutException e )
|
||||
{
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
public ArchivaArtifact toArtifact( String path )
|
||||
throws LayoutException
|
||||
{
|
||||
PathReferences pathrefs = toPathReferences( path );
|
||||
|
||||
ArchivaArtifact artifact = new ArchivaArtifact( pathrefs.groupId, pathrefs.fileParts.artifactId,
|
||||
pathrefs.fileParts.version, pathrefs.fileParts.classifier,
|
||||
pathrefs.type );
|
||||
|
||||
return artifact;
|
||||
}
|
||||
|
||||
public ArtifactReference toArtifactReference( String path )
|
||||
throws LayoutException
|
||||
{
|
||||
PathReferences pathrefs = toPathReferences( path );
|
||||
|
||||
ArtifactReference reference = new ArtifactReference();
|
||||
|
||||
reference.setGroupId( pathrefs.groupId );
|
||||
reference.setArtifactId( pathrefs.fileParts.artifactId );
|
||||
reference.setVersion( pathrefs.fileParts.version );
|
||||
reference.setClassifier( pathrefs.fileParts.classifier );
|
||||
reference.setType( pathrefs.type );
|
||||
|
||||
return reference;
|
||||
}
|
||||
}
|
|
@ -1,252 +0,0 @@
|
|||
package org.apache.maven.archiva.repository.layout;
|
||||
|
||||
/*
|
||||
* 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.common.utils.VersionUtil;
|
||||
import org.apache.maven.archiva.repository.ManagedRepositoryContent;
|
||||
import org.apache.maven.archiva.repository.RemoteRepositoryContent;
|
||||
import org.apache.maven.archiva.repository.RepositoryContentFactory;
|
||||
|
||||
/**
|
||||
* RepositoryLayoutUtils - utility methods common for most BidirectionalRepositoryLayout implementation.
|
||||
*
|
||||
* @author <a href="mailto:joakime@apache.org">Joakim Erdfelt</a>
|
||||
* @version $Id$
|
||||
*
|
||||
* @deprecated use {@link RepositoryContentFactory} and {@link ManagedRepositoryContent}
|
||||
* or {@link RemoteRepositoryContent} instead.
|
||||
*/
|
||||
public class RepositoryLayoutUtils
|
||||
{
|
||||
/**
|
||||
* Complex 2+ part extensions.
|
||||
* Do not include initial "." character in extension names here.
|
||||
*/
|
||||
private static final String ComplexExtensions[] = new String[] { "tar.gz", "tar.bz2" };
|
||||
|
||||
/**
|
||||
* Filename Parsing Mode - Artifact Id.
|
||||
*/
|
||||
private static final int ARTIFACTID = 1;
|
||||
|
||||
/**
|
||||
* Filename Parsing Mode - Version.
|
||||
*/
|
||||
private static final int VERSION = 2;
|
||||
|
||||
/**
|
||||
* Filename Parsing Mode - Classifier.
|
||||
*/
|
||||
private static final int CLASSIFIER = 3;
|
||||
|
||||
/**
|
||||
* Split the provided filename into 4 String parts. Simply delegate to
|
||||
* splitFilename( filename, possibleArtifactId, possibleVersion ) with no possibleVersion
|
||||
* proposal.
|
||||
*
|
||||
* @param filename the filename to split.
|
||||
* @param possibleArtifactId the optional artifactId to aide in splitting the filename.
|
||||
* (null to allow algorithm to calculate one)
|
||||
* @return the parts of the filename.
|
||||
* @throws LayoutException
|
||||
* @deprecated to not use directly. Use {@link ManagedRepositoryContent} or {@link RemoteRepositoryContent} instead.
|
||||
*/
|
||||
public static FilenameParts splitFilename( String filename, String possibleArtifactId ) throws LayoutException
|
||||
{
|
||||
return splitFilename( filename, possibleArtifactId, null );
|
||||
}
|
||||
|
||||
/**
|
||||
* Split the provided filename into 4 String parts.
|
||||
*
|
||||
* <pre>
|
||||
* String part[] = splitFilename( filename );
|
||||
* artifactId = part[0];
|
||||
* version = part[1];
|
||||
* classifier = part[2];
|
||||
* extension = part[3];
|
||||
* </pre>
|
||||
*
|
||||
* @param filename the filename to split.
|
||||
* @param possibleArtifactId the optional artifactId to aide in splitting the filename.
|
||||
* (null to allow algorithm to calculate one)
|
||||
* @param possibleVersion the optional version to aide in splitting the filename.
|
||||
* (null to allow algorithm to calculate one)
|
||||
* @return the parts of the filename.
|
||||
* @throws LayoutException
|
||||
* @deprecated to not use directly. Use {@link ManagedRepositoryContent} or {@link RemoteRepositoryContent} instead.
|
||||
*/
|
||||
public static FilenameParts splitFilename( String filename, String possibleArtifactId,
|
||||
String possibleVersion ) throws LayoutException
|
||||
{
|
||||
if ( StringUtils.isBlank( filename ) )
|
||||
{
|
||||
throw new IllegalArgumentException( "Unable to split blank filename." );
|
||||
}
|
||||
|
||||
String filestring = filename.trim();
|
||||
|
||||
FilenameParts parts = new FilenameParts();
|
||||
// I like working backwards.
|
||||
|
||||
// Find the extension.
|
||||
|
||||
// Work on multipart extensions first.
|
||||
boolean found = false;
|
||||
|
||||
String lowercaseFilename = filestring.toLowerCase();
|
||||
for ( int i = 0; i < ComplexExtensions.length && !found; i++ )
|
||||
{
|
||||
if ( lowercaseFilename.endsWith( "." + ComplexExtensions[i] ) )
|
||||
{
|
||||
parts.extension = ComplexExtensions[i];
|
||||
filestring = filestring.substring( 0, filestring.length() - ComplexExtensions[i].length() - 1 );
|
||||
found = true;
|
||||
}
|
||||
}
|
||||
|
||||
if ( !found )
|
||||
{
|
||||
// Default to 1 part extension.
|
||||
|
||||
int index = filestring.lastIndexOf( '.' );
|
||||
if ( index <= 0 )
|
||||
{
|
||||
// Bad Filename - No Extension
|
||||
throw new LayoutException( "Unable to determine extension from filename " + filename );
|
||||
}
|
||||
parts.extension = filestring.substring( index + 1 );
|
||||
filestring = filestring.substring( 0, index );
|
||||
}
|
||||
|
||||
// Work on version string.
|
||||
int mode = ARTIFACTID;
|
||||
|
||||
if ( startsWith( filename, possibleArtifactId ) )
|
||||
{
|
||||
parts.artifactId = possibleArtifactId;
|
||||
filestring = filestring.substring( possibleArtifactId.length() + 1 );
|
||||
mode = VERSION;
|
||||
}
|
||||
|
||||
if ( startsWith( filestring, possibleVersion ) )
|
||||
{
|
||||
if ( filestring.length() > possibleVersion.length() )
|
||||
{
|
||||
filestring = filestring.substring( possibleVersion.length() );
|
||||
}
|
||||
else
|
||||
{
|
||||
filestring = "";
|
||||
}
|
||||
parts.version = possibleVersion;
|
||||
mode = CLASSIFIER;
|
||||
}
|
||||
|
||||
String fileParts[] = StringUtils.split( filestring, '-' );
|
||||
|
||||
int versionStart = -1;
|
||||
int versionEnd = -1;
|
||||
for ( int i = 0; i < fileParts.length; i++ )
|
||||
{
|
||||
String part = fileParts[i];
|
||||
|
||||
if ( VersionUtil.isSimpleVersionKeyword( part ) )
|
||||
{
|
||||
// It is a potential version part.
|
||||
if ( versionStart < 0 )
|
||||
{
|
||||
versionStart = i;
|
||||
}
|
||||
|
||||
versionEnd = i;
|
||||
}
|
||||
}
|
||||
|
||||
if ( versionStart < 0 && parts.version == null )
|
||||
{
|
||||
// Assume rest of string is the version Id.
|
||||
|
||||
if ( fileParts.length > 0 )
|
||||
{
|
||||
versionStart = 0;
|
||||
versionEnd = fileParts.length;
|
||||
}
|
||||
else
|
||||
{
|
||||
throw new LayoutException( "Unable to determine version from filename " + filename );
|
||||
}
|
||||
}
|
||||
|
||||
// Gather up the ArtifactID - Version - Classifier pieces found.
|
||||
|
||||
for ( int i = 0; i < fileParts.length; i++ )
|
||||
{
|
||||
String part = fileParts[i];
|
||||
|
||||
if ( ( mode == ARTIFACTID ) && ( i >= versionStart ) )
|
||||
{
|
||||
if ( StringUtils.isBlank( parts.artifactId ) )
|
||||
{
|
||||
throw new LayoutException( "No Artifact Id detected." );
|
||||
}
|
||||
mode = VERSION;
|
||||
}
|
||||
|
||||
switch ( mode )
|
||||
{
|
||||
case ARTIFACTID:
|
||||
parts.appendArtifactId( part );
|
||||
break;
|
||||
case VERSION:
|
||||
parts.appendVersion( part );
|
||||
break;
|
||||
case CLASSIFIER:
|
||||
parts.appendClassifier( part );
|
||||
break;
|
||||
}
|
||||
|
||||
if ( i >= versionEnd )
|
||||
{
|
||||
mode = CLASSIFIER;
|
||||
}
|
||||
}
|
||||
|
||||
return parts;
|
||||
}
|
||||
|
||||
/**
|
||||
* Check if the string starts with the proposed token, with no more char
|
||||
* expeect the '-' separator.
|
||||
* @param string string to test
|
||||
* @param possible proposed startOf
|
||||
* @return true if the possible matches
|
||||
*/
|
||||
private static boolean startsWith( String string, String possible )
|
||||
{
|
||||
if (possible == null)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
int length = possible.length();
|
||||
return string.startsWith( possible ) && ( string.length() == length || string.charAt( length ) == '-' );
|
||||
}
|
||||
}
|
|
@ -1,147 +0,0 @@
|
|||
package org.apache.maven.archiva.repository.layout;
|
||||
|
||||
/*
|
||||
* 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.configuration.ManagedRepositoryConfiguration;
|
||||
import org.apache.maven.archiva.model.ArchivaArtifact;
|
||||
import org.apache.maven.archiva.model.ArtifactReference;
|
||||
import org.apache.maven.archiva.model.ProjectReference;
|
||||
import org.apache.maven.archiva.model.VersionedReference;
|
||||
import org.codehaus.plexus.PlexusTestCase;
|
||||
|
||||
import java.io.File;
|
||||
|
||||
/**
|
||||
* AbstractBidirectionalRepositoryLayoutTestCase
|
||||
*
|
||||
* @author <a href="mailto:joakime@apache.org">Joakim Erdfelt</a>
|
||||
* @version $Id$
|
||||
*/
|
||||
public abstract class AbstractBidirectionalRepositoryLayoutTestCase
|
||||
extends PlexusTestCase
|
||||
{
|
||||
protected ManagedRepositoryConfiguration repository;
|
||||
|
||||
protected void setUp()
|
||||
throws Exception
|
||||
{
|
||||
super.setUp();
|
||||
|
||||
repository = createTestRepository();
|
||||
}
|
||||
|
||||
protected ManagedRepositoryConfiguration createTestRepository()
|
||||
{
|
||||
File targetDir = new File( getBasedir(), "target" );
|
||||
File testRepo = new File( targetDir, "test-repo" );
|
||||
|
||||
if ( !testRepo.exists() )
|
||||
{
|
||||
testRepo.mkdirs();
|
||||
}
|
||||
|
||||
ManagedRepositoryConfiguration repo = new ManagedRepositoryConfiguration();
|
||||
repo.setId( "testRepo" );
|
||||
repo.setName( "Test Repository" );
|
||||
repo.setLocation( testRepo.getAbsolutePath() );
|
||||
return repo;
|
||||
}
|
||||
|
||||
protected ArchivaArtifact createArtifact( String groupId, String artifactId, String version, String classifier,
|
||||
String type )
|
||||
{
|
||||
ArchivaArtifact artifact = new ArchivaArtifact( groupId, artifactId, version, classifier, type );
|
||||
assertNotNull( artifact );
|
||||
artifact.getModel().setRepositoryId( repository.getId() );
|
||||
return artifact;
|
||||
}
|
||||
|
||||
protected void assertArtifact( ArchivaArtifact actualArtifact, String groupId, String artifactId, String version,
|
||||
String classifier, String type )
|
||||
{
|
||||
String expectedId = groupId + ":" + artifactId + ":" + version + ":" + classifier + ":" + type;
|
||||
|
||||
assertNotNull( expectedId + " - Should not be null.", actualArtifact );
|
||||
|
||||
assertEquals( expectedId + " - Group ID", groupId, actualArtifact.getGroupId() );
|
||||
assertEquals( expectedId + " - Artifact ID", artifactId, actualArtifact.getArtifactId() );
|
||||
if ( StringUtils.isNotBlank( classifier ) )
|
||||
{
|
||||
assertEquals( expectedId + " - Classifier", classifier, actualArtifact.getClassifier() );
|
||||
}
|
||||
assertEquals( expectedId + " - Version ID", version, actualArtifact.getVersion() );
|
||||
assertEquals( expectedId + " - Type", type, actualArtifact.getType() );
|
||||
}
|
||||
|
||||
protected 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() );
|
||||
if ( StringUtils.isNotBlank( classifier ) )
|
||||
{
|
||||
assertEquals( expectedId + " - Classifier", classifier, actualReference.getClassifier() );
|
||||
}
|
||||
assertEquals( expectedId + " - Version ID", version, actualReference.getVersion() );
|
||||
assertEquals( expectedId + " - Type", type, actualReference.getType() );
|
||||
}
|
||||
|
||||
protected void assertVersionedReference( VersionedReference actualReference, String groupId, String artifactId,
|
||||
String version )
|
||||
{
|
||||
String expectedId = "VersionedReference - " + groupId + ":" + artifactId + ":" + version;
|
||||
|
||||
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() );
|
||||
}
|
||||
|
||||
protected void assertProjectReference( ProjectReference actualReference, String groupId, String artifactId )
|
||||
{
|
||||
String expectedId = "ProjectReference - " + groupId + ":" + artifactId;
|
||||
|
||||
assertNotNull( expectedId + " - Should not be null.", actualReference );
|
||||
assertEquals( expectedId + " - Group ID", groupId, actualReference.getGroupId() );
|
||||
assertEquals( expectedId + " - Artifact ID", artifactId, actualReference.getArtifactId() );
|
||||
}
|
||||
|
||||
protected void assertSnapshotArtifact( ArchivaArtifact actualArtifact, String groupId, String artifactId,
|
||||
String version, String classifier, String type )
|
||||
{
|
||||
String expectedId = groupId + ":" + artifactId + ":" + version + ":" + classifier + ":" + type;
|
||||
|
||||
assertNotNull( expectedId + " - Should not be null.", actualArtifact );
|
||||
|
||||
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() );
|
||||
}
|
||||
|
||||
}
|
|
@ -1,88 +0,0 @@
|
|||
package org.apache.maven.archiva.repository.layout;
|
||||
|
||||
/*
|
||||
* 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.ArchivaArtifact;
|
||||
|
||||
/**
|
||||
* BidirectionalRepositoryLayoutFactoryTest
|
||||
*
|
||||
* @author <a href="mailto:joakime@apache.org">Joakim Erdfelt</a>
|
||||
* @version $Id$
|
||||
*/
|
||||
public class BidirectionalRepositoryLayoutFactoryTest
|
||||
extends AbstractBidirectionalRepositoryLayoutTestCase
|
||||
{
|
||||
private BidirectionalRepositoryLayoutFactory factory;
|
||||
|
||||
protected void setUp()
|
||||
throws Exception
|
||||
{
|
||||
super.setUp();
|
||||
|
||||
factory = (BidirectionalRepositoryLayoutFactory) lookup( BidirectionalRepositoryLayoutFactory.class.getName() );
|
||||
}
|
||||
|
||||
public void testLayoutDefault()
|
||||
throws LayoutException
|
||||
{
|
||||
BidirectionalRepositoryLayout layout = factory.getLayout( "default" );
|
||||
assertNotNull( "Layout should not be null", layout );
|
||||
|
||||
ArchivaArtifact artifact = createArtifact( "com.foo", "foo-tool", "1.0", "", "jar" );
|
||||
|
||||
assertEquals( "com/foo/foo-tool/1.0/foo-tool-1.0.jar", layout.toPath( artifact ) );
|
||||
}
|
||||
|
||||
public void testLayoutLegacy()
|
||||
throws LayoutException
|
||||
{
|
||||
BidirectionalRepositoryLayout layout = factory.getLayout( "legacy" );
|
||||
assertNotNull( "Layout should not be null", layout );
|
||||
|
||||
ArchivaArtifact artifact = createArtifact( "com.foo", "foo-tool", "1.0", "", "jar" );
|
||||
|
||||
assertEquals( "com.foo/jars/foo-tool-1.0.jar", layout.toPath( artifact ) );
|
||||
}
|
||||
|
||||
public void testLayoutInvalid()
|
||||
{
|
||||
try
|
||||
{
|
||||
factory.getLayout( "-invalid-" );
|
||||
fail( "Should have thrown a LayoutException due to missing layout type." );
|
||||
}
|
||||
catch ( LayoutException e )
|
||||
{
|
||||
/* expected path */
|
||||
}
|
||||
}
|
||||
|
||||
public void testFindLayoutForPath()
|
||||
throws LayoutException
|
||||
{
|
||||
BidirectionalRepositoryLayout layout =
|
||||
factory.getLayoutForPath( "javax/servlet/servlet-api/2.3/servlet-api-2.3.jar" );
|
||||
assertEquals( "default", layout.getId() );
|
||||
|
||||
layout = factory.getLayoutForPath( "javax.servlet/jars/servlet-api-2.3.jar" );
|
||||
assertEquals( "legacy", layout.getId() );
|
||||
}
|
||||
}
|
|
@ -1,410 +0,0 @@
|
|||
package org.apache.maven.archiva.repository.layout;
|
||||
|
||||
/*
|
||||
* 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.ArchivaArtifact;
|
||||
import org.apache.maven.archiva.model.ArtifactReference;
|
||||
|
||||
/**
|
||||
* DefaultBidirectionalRepositoryLayoutTest
|
||||
*
|
||||
* @author <a href="mailto:joakime@apache.org">Joakim Erdfelt</a>
|
||||
* @version $Id$
|
||||
*/
|
||||
public class DefaultBidirectionalRepositoryLayoutTest
|
||||
extends AbstractBidirectionalRepositoryLayoutTestCase
|
||||
{
|
||||
private BidirectionalRepositoryLayout layout;
|
||||
|
||||
public void testBadPathMissingType()
|
||||
{
|
||||
assertBadPath( "invalid/invalid/1/invalid-1", "missing type" );
|
||||
}
|
||||
|
||||
public void testBadPathReleaseInSnapshotDir()
|
||||
{
|
||||
assertBadPath( "invalid/invalid/1.0-SNAPSHOT/invalid-1.0.jar", "non snapshot artifact inside of a snapshot dir" );
|
||||
}
|
||||
|
||||
public void testBadPathTimestampedSnapshotNotInSnapshotDir()
|
||||
{
|
||||
assertBadPath( "invalid/invalid/1.0-20050611.123456-1/invalid-1.0-20050611.123456-1.jar",
|
||||
"Timestamped Snapshot artifact not inside of an Snapshot dir" );
|
||||
}
|
||||
|
||||
public void testBadPathTooShort()
|
||||
{
|
||||
assertBadPath( "invalid/invalid-1.0.jar", "path is too short" );
|
||||
}
|
||||
|
||||
public void testBadPathVersionMismatchA()
|
||||
{
|
||||
assertBadPath( "invalid/invalid/1.0/invalid-2.0.jar", "version mismatch between path and artifact" );
|
||||
}
|
||||
|
||||
public void testBadPathVersionMismatchB()
|
||||
{
|
||||
assertBadPath( "invalid/invalid/1.0/invalid-1.0b.jar", "version mismatch between path and artifact" );
|
||||
}
|
||||
|
||||
public void testBadPathWrongArtifactId()
|
||||
{
|
||||
assertBadPath( "org/apache/maven/test/1.0-SNAPSHOT/wrong-artifactId-1.0-20050611.112233-1.jar",
|
||||
"wrong artifact id" );
|
||||
}
|
||||
|
||||
/**
|
||||
* [MRM-432] Oddball version spec.
|
||||
* Example of an oddball / unusual version spec.
|
||||
* @throws LayoutException
|
||||
*/
|
||||
public void testGoodButOddVersionSpecGanymedSsh2()
|
||||
throws LayoutException
|
||||
{
|
||||
String groupId = "ch.ethz.ganymed";
|
||||
String artifactId = "ganymed-ssh2";
|
||||
String version = "build210";
|
||||
String classifier = null;
|
||||
String type = "jar";
|
||||
String path = "ch/ethz/ganymed/ganymed-ssh2/build210/ganymed-ssh2-build210.jar";
|
||||
|
||||
assertLayout( path, groupId, artifactId, version, classifier, type );
|
||||
}
|
||||
|
||||
/**
|
||||
* [MRM-432] Oddball version spec.
|
||||
* Example of an oddball / unusual version spec.
|
||||
* @throws LayoutException
|
||||
*/
|
||||
public void testGoodButOddVersionSpecJavaxComm()
|
||||
throws LayoutException
|
||||
{
|
||||
String groupId = "javax";
|
||||
String artifactId = "comm";
|
||||
String version = "3.0-u1";
|
||||
String classifier = null;
|
||||
String type = "jar";
|
||||
String path = "javax/comm/3.0-u1/comm-3.0-u1.jar";
|
||||
|
||||
assertLayout( path, groupId, artifactId, version, classifier, type );
|
||||
}
|
||||
|
||||
/**
|
||||
* [MRM-432] Oddball version spec.
|
||||
* Example of an oddball / unusual version spec.
|
||||
* @throws LayoutException
|
||||
*/
|
||||
public void testGoodButOddVersionSpecJavaxPersistence()
|
||||
throws LayoutException
|
||||
{
|
||||
String groupId = "javax.persistence";
|
||||
String artifactId = "ejb";
|
||||
String version = "3.0-public_review";
|
||||
String classifier = null;
|
||||
String type = "jar";
|
||||
String path = "javax/persistence/ejb/3.0-public_review/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?
|
||||
* Since the path spec below shows it in the path, then it is really
|
||||
* part of the version spec.
|
||||
*/
|
||||
|
||||
assertLayout( path, groupId, artifactId, version, classifier, 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.
|
||||
*/
|
||||
public void testGoodVersionKeywordInArtifactId()
|
||||
throws LayoutException
|
||||
{
|
||||
String groupId = "maven";
|
||||
String artifactId = "maven-test-plugin";
|
||||
String version = "1.8.2";
|
||||
String classifier = null;
|
||||
String type = "pom";
|
||||
String path = "maven/maven-test-plugin/1.8.2/maven-test-plugin-1.8.2.pom";
|
||||
|
||||
assertLayout( path, groupId, artifactId, version, classifier, type );
|
||||
}
|
||||
|
||||
/**
|
||||
* [MRM-486] Can not deploy artifact test.maven-arch:test-arch due to "No ArtifactID Detected"
|
||||
*/
|
||||
public void testGoodDashedArtifactId()
|
||||
throws LayoutException
|
||||
{
|
||||
String groupId = "test.maven-arch";
|
||||
String artifactId = "test-arch";
|
||||
String version = "2.0.3-SNAPSHOT";
|
||||
String classifier = null;
|
||||
String type = "pom";
|
||||
String path = "test/maven-arch/test-arch/2.0.3-SNAPSHOT/test-arch-2.0.3-SNAPSHOT.pom";
|
||||
|
||||
assertLayout( path, groupId, artifactId, version, classifier, type );
|
||||
}
|
||||
|
||||
/**
|
||||
* It may seem odd, but this is a valid artifact.
|
||||
*/
|
||||
public void testGoodDotNotationArtifactId()
|
||||
throws LayoutException
|
||||
{
|
||||
String groupId = "com.company.department";
|
||||
String artifactId = "com.company.department";
|
||||
String version = "0.2";
|
||||
String classifier = null;
|
||||
String type = "pom";
|
||||
String path = "com/company/department/com.company.department/0.2/com.company.department-0.2.pom";
|
||||
|
||||
assertLayout( path, groupId, artifactId, version, classifier, type );
|
||||
}
|
||||
|
||||
/**
|
||||
* It may seem odd, but this is a valid artifact.
|
||||
*/
|
||||
public void testGoodDotNotationSameGroupIdAndArtifactId()
|
||||
throws LayoutException
|
||||
{
|
||||
String groupId = "com.company.department";
|
||||
String artifactId = "com.company.department.project";
|
||||
String version = "0.3";
|
||||
String classifier = null;
|
||||
String type = "pom";
|
||||
String path = "com/company/department/com.company.department.project/0.3/com.company.department.project-0.3.pom";
|
||||
|
||||
assertLayout( path, groupId, artifactId, version, classifier, type );
|
||||
}
|
||||
|
||||
public void testGoodComFooTool()
|
||||
throws LayoutException
|
||||
{
|
||||
String groupId = "com.foo";
|
||||
String artifactId = "foo-tool";
|
||||
String version = "1.0";
|
||||
String classifier = null;
|
||||
String type = "jar";
|
||||
String path = "com/foo/foo-tool/1.0/foo-tool-1.0.jar";
|
||||
|
||||
assertLayout( path, groupId, artifactId, version, classifier, type );
|
||||
}
|
||||
|
||||
public void testGoodCommonsLang()
|
||||
throws LayoutException
|
||||
{
|
||||
String groupId = "commons-lang";
|
||||
String artifactId = "commons-lang";
|
||||
String version = "2.1";
|
||||
String classifier = null;
|
||||
String type = "jar";
|
||||
String path = "commons-lang/commons-lang/2.1/commons-lang-2.1.jar";
|
||||
|
||||
assertLayout( path, groupId, artifactId, version, classifier, type );
|
||||
}
|
||||
|
||||
/**
|
||||
* Test the ejb-client type spec.
|
||||
* Type specs are not a 1 to 1 map to the extension.
|
||||
* This tests that effect.
|
||||
* @throws 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 classifier = null;
|
||||
String type = "ejb-client"; // oddball type-spec (should result in jar extension)
|
||||
String path = "com/foo/foo-client/1.0/foo-client-1.0.jar";
|
||||
|
||||
assertLayout( path, groupId, artifactId, version, classifier, type );
|
||||
}
|
||||
*/
|
||||
|
||||
/**
|
||||
* Test the classifier, and java-source type spec.
|
||||
* @throws LayoutException
|
||||
*/
|
||||
public void testGoodFooLibSources()
|
||||
throws LayoutException
|
||||
{
|
||||
String groupId = "com.foo.lib";
|
||||
String artifactId = "foo-lib";
|
||||
String version = "2.1-alpha-1";
|
||||
String classifier = "sources";
|
||||
String type = "java-source"; // oddball type-spec (should result in jar extension)
|
||||
String path = "com/foo/lib/foo-lib/2.1-alpha-1/foo-lib-2.1-alpha-1-sources.jar";
|
||||
|
||||
assertLayout( path, groupId, artifactId, version, classifier, type );
|
||||
}
|
||||
|
||||
/**
|
||||
* A timestamped versioned artifact, should reside in a SNAPSHOT baseversion directory.
|
||||
* @throws LayoutException
|
||||
*/
|
||||
public void testGoodSnapshotMavenTest()
|
||||
throws LayoutException
|
||||
{
|
||||
String groupId = "org.apache.archiva.test";
|
||||
String artifactId = "redonkulous";
|
||||
String version = "3.1-beta-1-20050831.101112-42";
|
||||
String classifier = null;
|
||||
String type = "jar";
|
||||
String path = "org/apache/archiva/test/redonkulous/3.1-beta-1-SNAPSHOT/redonkulous-3.1-beta-1-20050831.101112-42.jar";
|
||||
|
||||
assertLayout( path, groupId, artifactId, version, classifier, type );
|
||||
}
|
||||
|
||||
public void testToArtifactOnEmptyPath()
|
||||
{
|
||||
try
|
||||
{
|
||||
layout.toArtifact( "" );
|
||||
fail( "Should have failed due to empty path." );
|
||||
}
|
||||
catch ( LayoutException e )
|
||||
{
|
||||
/* expected path */
|
||||
}
|
||||
}
|
||||
|
||||
public void testToArtifactOnNullPath()
|
||||
{
|
||||
try
|
||||
{
|
||||
layout.toArtifact( null );
|
||||
fail( "Should have failed due to null path." );
|
||||
}
|
||||
catch ( LayoutException e )
|
||||
{
|
||||
/* expected path */
|
||||
}
|
||||
}
|
||||
|
||||
public void testToArtifactReferenceOnEmptyPath()
|
||||
{
|
||||
try
|
||||
{
|
||||
layout.toArtifactReference( "" );
|
||||
fail( "Should have failed due to empty path." );
|
||||
}
|
||||
catch ( LayoutException e )
|
||||
{
|
||||
/* expected path */
|
||||
}
|
||||
}
|
||||
|
||||
public void testToArtifactReferenceOnNullPath()
|
||||
{
|
||||
try
|
||||
{
|
||||
layout.toArtifactReference( null );
|
||||
fail( "Should have failed due to null path." );
|
||||
}
|
||||
catch ( LayoutException e )
|
||||
{
|
||||
/* expected path */
|
||||
}
|
||||
}
|
||||
|
||||
public void testToPathOnNullArtifactReference()
|
||||
{
|
||||
try
|
||||
{
|
||||
ArtifactReference reference = null;
|
||||
layout.toPath( reference );
|
||||
fail( "Should have failed due to null artifact reference." );
|
||||
}
|
||||
catch ( IllegalArgumentException e )
|
||||
{
|
||||
/* expected path */
|
||||
}
|
||||
}
|
||||
|
||||
public void testToPathOnNullArtifact()
|
||||
{
|
||||
try
|
||||
{
|
||||
ArchivaArtifact artifact = null;
|
||||
layout.toPath( artifact );
|
||||
fail( "Should have failed due to null artifact." );
|
||||
}
|
||||
catch ( IllegalArgumentException e )
|
||||
{
|
||||
/* expected path */
|
||||
}
|
||||
}
|
||||
|
||||
protected void assertBadPath( String path, String reason )
|
||||
{
|
||||
try
|
||||
{
|
||||
layout.toArtifact( path );
|
||||
fail( "Should have thrown a LayoutException on the invalid path [" + path + "] because of [" + reason + "]" );
|
||||
}
|
||||
catch ( LayoutException e )
|
||||
{
|
||||
/* expected path */
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Perform a roundtrip through the layout routines to determine success.
|
||||
*/
|
||||
private void assertLayout( String path, String groupId, String artifactId, String version, String classifier,
|
||||
String type )
|
||||
throws LayoutException
|
||||
{
|
||||
ArchivaArtifact expectedArtifact = createArtifact( groupId, artifactId, version, classifier, type );
|
||||
|
||||
// --- Artifact Tests.
|
||||
// Artifact to Path
|
||||
assertEquals( "Artifact <" + expectedArtifact + "> to path:", path, layout.toPath( expectedArtifact ) );
|
||||
|
||||
// Path to Artifact.
|
||||
ArchivaArtifact testArtifact = layout.toArtifact( path );
|
||||
assertArtifact( testArtifact, groupId, artifactId, version, classifier, type );
|
||||
|
||||
// And back again, using test Artifact from previous step.
|
||||
assertEquals( "Artifact <" + expectedArtifact + "> to path:", path, layout.toPath( testArtifact ) );
|
||||
|
||||
// --- Artifact Reference Tests
|
||||
|
||||
// Path to Artifact Reference.
|
||||
ArtifactReference testReference = layout.toArtifactReference( path );
|
||||
assertArtifactReference( testReference, groupId, artifactId, version, classifier, type );
|
||||
|
||||
// And back again, using test Reference from previous step.
|
||||
assertEquals( "Artifact <" + expectedArtifact + "> to path:", path, layout.toPath( testReference ) );
|
||||
}
|
||||
|
||||
protected void setUp()
|
||||
throws Exception
|
||||
{
|
||||
super.setUp();
|
||||
|
||||
layout = (BidirectionalRepositoryLayout) lookup( BidirectionalRepositoryLayout.class.getName(), "default" );
|
||||
}
|
||||
}
|
|
@ -1,354 +0,0 @@
|
|||
package org.apache.maven.archiva.repository.layout;
|
||||
|
||||
/*
|
||||
* 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.ArchivaArtifact;
|
||||
import org.apache.maven.archiva.model.ArtifactReference;
|
||||
|
||||
/**
|
||||
* LegacyBidirectionalRepositoryLayoutTest
|
||||
*
|
||||
* @author <a href="mailto:joakime@apache.org">Joakim Erdfelt</a>
|
||||
* @version $Id$
|
||||
*/
|
||||
public class LegacyBidirectionalRepositoryLayoutTest
|
||||
extends AbstractBidirectionalRepositoryLayoutTestCase
|
||||
{
|
||||
private BidirectionalRepositoryLayout layout;
|
||||
|
||||
public void testBadPathArtifactIdMissingA()
|
||||
{
|
||||
assertBadPath( "groupId/jars/-1.0.jar", "artifactId is missing" );
|
||||
}
|
||||
|
||||
public void testBadPathArtifactIdMissingB()
|
||||
{
|
||||
assertBadPath( "groupId/jars/1.0.jar", "artifactId is missing" );
|
||||
}
|
||||
|
||||
public void testBadPathMissingType()
|
||||
{
|
||||
assertBadPath( "invalid/invalid/1/invalid-1", "missing type" );
|
||||
}
|
||||
|
||||
public void testBadPathTooShort()
|
||||
{
|
||||
// NEW
|
||||
assertBadPath( "invalid/invalid-1.0.jar", "path is too short" );
|
||||
}
|
||||
|
||||
public void testBadPathWrongPackageExtension()
|
||||
{
|
||||
assertBadPath( "org.apache.maven.test/jars/artifactId-1.0.war", "wrong package extension" );
|
||||
}
|
||||
|
||||
/**
|
||||
* [MRM-432] Oddball version spec.
|
||||
* Example of an oddball / unusual version spec.
|
||||
* @throws LayoutException
|
||||
*/
|
||||
/*
|
||||
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, type );
|
||||
}
|
||||
*/
|
||||
|
||||
/**
|
||||
* [MRM-432] Oddball version spec.
|
||||
* Example of an oddball / unusual version spec.
|
||||
* @throws LayoutException
|
||||
*/
|
||||
/*
|
||||
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, type );
|
||||
}
|
||||
*/
|
||||
|
||||
/**
|
||||
* [MRM-432] Oddball version spec.
|
||||
* Example of an oddball / unusual version spec.
|
||||
* @throws LayoutException
|
||||
*/
|
||||
/*
|
||||
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";
|
||||
|
||||
assertLayout( path, groupId, artifactId, version, 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.
|
||||
*/
|
||||
/*
|
||||
public void testGoodVersionKeywordInArtifactId()
|
||||
throws LayoutException
|
||||
{
|
||||
String groupId = "maven";
|
||||
String artifactId = "maven-test-plugin";
|
||||
String version = "1.8.2";
|
||||
String type = "jar";
|
||||
|
||||
String path = "maven/jars/maven-test-plugin-1.8.2.jar";
|
||||
|
||||
assertLayout( path, groupId, artifactId, version, type );
|
||||
}
|
||||
*/
|
||||
|
||||
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, type );
|
||||
}
|
||||
|
||||
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, type );
|
||||
}
|
||||
|
||||
/**
|
||||
* Test the ejb-client type spec.
|
||||
* Type specs are not a 1 to 1 map to the extension.
|
||||
* This tests that effect.
|
||||
* @throws 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 LayoutException
|
||||
*/
|
||||
/*
|
||||
public void testGoodFooLibJavadoc()
|
||||
throws LayoutException
|
||||
{
|
||||
String groupId = "com.foo.lib";
|
||||
String artifactId = "foo-lib";
|
||||
String version = "2.1-alpha-1-javadoc";
|
||||
String type = "javadoc.jar";
|
||||
String path = "com.foo.lib/javadoc.jars/foo-lib-2.1-alpha-1-javadoc.jar";
|
||||
|
||||
assertLayout( path, groupId, artifactId, version, type );
|
||||
}
|
||||
*/
|
||||
|
||||
/**
|
||||
* Test the classifier, and java-source type spec.
|
||||
* @throws LayoutException
|
||||
*/
|
||||
/*
|
||||
public void testGoodFooLibSources()
|
||||
throws LayoutException
|
||||
{
|
||||
String groupId = "com.foo.lib";
|
||||
String artifactId = "foo-lib";
|
||||
String version = "2.1-alpha-1-sources";
|
||||
String type = "java-source"; // oddball type-spec (should result in jar extension)
|
||||
String path = "com.foo.lib/java-sources/foo-lib-2.1-alpha-1-sources.jar";
|
||||
|
||||
assertLayout( path, groupId, artifactId, version, type );
|
||||
}
|
||||
*/
|
||||
|
||||
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, type );
|
||||
}
|
||||
|
||||
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, type );
|
||||
}
|
||||
|
||||
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, type );
|
||||
}
|
||||
|
||||
/**
|
||||
* A timestamped versioned artifact, should reside in a SNAPSHOT baseversion directory.
|
||||
* @throws LayoutException
|
||||
*/
|
||||
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, type );
|
||||
}
|
||||
|
||||
/**
|
||||
* Perform a roundtrip through the layout routines to determine success.
|
||||
*/
|
||||
private void assertLayout( String path, String groupId, String artifactId, String version, String type )
|
||||
throws LayoutException
|
||||
{
|
||||
ArchivaArtifact expectedArtifact = createArtifact( groupId, artifactId, version, type );
|
||||
|
||||
// --- Artifact Tests.
|
||||
// Artifact to Path
|
||||
assertEquals( "Artifact <" + expectedArtifact + "> to path:", path, layout.toPath( expectedArtifact ) );
|
||||
|
||||
// Path to Artifact.
|
||||
ArchivaArtifact testArtifact = layout.toArtifact( path );
|
||||
assertArtifact( testArtifact, groupId, artifactId, version, type );
|
||||
|
||||
// And back again, using test Artifact from previous step.
|
||||
assertEquals( "Artifact <" + expectedArtifact + "> to path:", path, layout.toPath( testArtifact ) );
|
||||
|
||||
// --- Artifact Reference Tests
|
||||
|
||||
// Path to Artifact Reference.
|
||||
ArtifactReference testReference = layout.toArtifactReference( path );
|
||||
assertArtifactReference( testReference, groupId, artifactId, version, type );
|
||||
|
||||
// And back again, using test Reference from previous step.
|
||||
assertEquals( "Artifact <" + expectedArtifact + "> to path:", path, layout.toPath( testReference ) );
|
||||
}
|
||||
|
||||
protected ArchivaArtifact createArtifact( String groupId, String artifactId, String version, String type )
|
||||
{
|
||||
ArchivaArtifact artifact = new ArchivaArtifact( groupId, artifactId, version, null, type );
|
||||
assertNotNull( artifact );
|
||||
artifact.getModel().setRepositoryId( repository.getId() );
|
||||
return artifact;
|
||||
}
|
||||
|
||||
protected void assertArtifact( ArchivaArtifact actualArtifact, String groupId, String artifactId, String version,
|
||||
String type )
|
||||
{
|
||||
String expectedId = groupId + ":" + artifactId + ":" + version + ":" + type;
|
||||
|
||||
assertNotNull( expectedId + " - Should not be null.", actualArtifact );
|
||||
|
||||
assertEquals( expectedId + " - Group ID", groupId, actualArtifact.getGroupId() );
|
||||
assertEquals( expectedId + " - Artifact ID", artifactId, actualArtifact.getArtifactId() );
|
||||
assertEquals( expectedId + " - Version ID", version, actualArtifact.getVersion() );
|
||||
assertEquals( expectedId + " - Type", type, actualArtifact.getType() );
|
||||
}
|
||||
|
||||
protected void assertArtifactReference( ArtifactReference actualReference, String groupId, String artifactId,
|
||||
String version, String type )
|
||||
{
|
||||
String expectedId = "ArtifactReference - " + groupId + ":" + artifactId + ":" + version + ":" + 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 + " - Type", type, actualReference.getType() );
|
||||
}
|
||||
|
||||
protected void assertBadPath( String path, String reason )
|
||||
{
|
||||
try
|
||||
{
|
||||
layout.toArtifact( path );
|
||||
fail( "Should have thrown a LayoutException on the invalid path [" + path + "] because of [" + reason + "]" );
|
||||
}
|
||||
catch ( LayoutException e )
|
||||
{
|
||||
/* expected path */
|
||||
}
|
||||
}
|
||||
|
||||
protected void setUp()
|
||||
throws Exception
|
||||
{
|
||||
super.setUp();
|
||||
|
||||
layout = (BidirectionalRepositoryLayout) lookup( BidirectionalRepositoryLayout.class.getName(), "legacy" );
|
||||
}
|
||||
|
||||
}
|
Loading…
Reference in New Issue