[MRM-493] some cleanup before fixing merging of plugin metadata

git-svn-id: https://svn.apache.org/repos/asf/maven/archiva/trunk@575135 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
Brett Porter 2007-09-13 01:15:16 +00:00
parent cd957318dc
commit 7c2f63c4f5
2 changed files with 95 additions and 142 deletions

View File

@ -56,19 +56,16 @@ import java.util.Set;
import java.util.regex.Matcher;
/**
* MetadataTools
* MetadataTools
*
* @author <a href="mailto:joakime@apache.org">Joakim Erdfelt</a>
* @version $Id$
*
* @plexus.component role="org.apache.maven.archiva.repository.metadata.MetadataTools"
* @todo use the maven-repository-metadata classes instead for merging
*/
public class MetadataTools
implements RegistryListener, Initializable
{
/**
* Static Logger. So what? Try and prove to me that IoC monitors are better.
*/
private static Logger log = LoggerFactory.getLogger( MetadataTools.class );
public static final String MAVEN_METADATA = "maven-metadata.xml";
@ -96,7 +93,7 @@ public class MetadataTools
private Map<String, Set<String>> proxies;
private static final char NUMS[] = new char[] { '0', '1', '2', '3', '4', '5', '6', '7', '8', '9' };
private static final char NUMS[] = new char[]{'0', '1', '2', '3', '4', '5', '6', '7', '8', '9'};
public void afterConfigurationChange( Registry registry, String propertyName, Object propertyValue )
{
@ -114,9 +111,9 @@ public class MetadataTools
/**
* Gather the Available Versions (on disk) for a specific Project Reference, based on filesystem
* information.
*
*
* @return the Set of available versions, based on the project reference.
* @throws LayoutException
* @throws LayoutException
*/
public Set<String> gatherAvailableVersions( ArchivaRepository managedRepository, ProjectReference reference )
throws LayoutException, IOException
@ -133,14 +130,14 @@ public class MetadataTools
if ( !repoDir.exists() )
{
throw new IOException( "Unable to calculate Available Local Versions on a non-existant directory: "
+ repoDir.getAbsolutePath() );
throw new IOException( "Unable to calculate Available Local Versions on a non-existant directory: " +
repoDir.getAbsolutePath() );
}
if ( !repoDir.isDirectory() )
{
throw new IOException( "Unable to calculate Available Local Versions on a non-directory: "
+ repoDir.getAbsolutePath() );
throw new IOException(
"Unable to calculate Available Local Versions on a non-directory: " + repoDir.getAbsolutePath() );
}
Set<String> foundVersions = new HashSet<String>();
@ -185,14 +182,14 @@ public class MetadataTools
}
/**
* Get the first Artifact found in the provided VersionedReference location.
*
* Get the first Artifact found in the provided VersionedReference location.
*
* @param managedRepository the repository to search within.
* @param reference the reference to the versioned reference to search within
* @param reference the reference to the versioned reference to search within
* @return the ArtifactReference to the first artifact located within the versioned reference. or null if
* no artifact was found within the versioned reference.
* @throws IOException if the versioned reference is invalid (example: doesn't exist, or isn't a directory)
* @throws LayoutException
* @throws IOException if the versioned reference is invalid (example: doesn't exist, or isn't a directory)
* @throws LayoutException
*/
public ArtifactReference getFirstArtifact( ArchivaRepository managedRepository, VersionedReference reference )
throws LayoutException, IOException
@ -210,14 +207,14 @@ public class MetadataTools
if ( !repoDir.exists() )
{
throw new IOException( "Unable to gather the list of snapshot versions on a non-existant directory: "
+ repoDir.getAbsolutePath() );
throw new IOException( "Unable to gather the list of snapshot versions on a non-existant directory: " +
repoDir.getAbsolutePath() );
}
if ( !repoDir.isDirectory() )
{
throw new IOException( "Unable to gather the list of snapshot versions on a non-directory: "
+ repoDir.getAbsolutePath() );
throw new IOException(
"Unable to gather the list of snapshot versions on a non-directory: " + repoDir.getAbsolutePath() );
}
File repoFiles[] = repoDir.listFiles();
@ -245,9 +242,9 @@ public class MetadataTools
/**
* Gather the set of snapshot versions found in a particular versioned reference.
*
*
* @return the Set of snapshot artifact versions found.
* @throws LayoutException
* @throws LayoutException
*/
public Set<String> gatherSnapshotVersions( ArchivaRepository managedRepository, VersionedReference reference )
throws LayoutException, IOException
@ -265,14 +262,14 @@ public class MetadataTools
if ( !repoDir.exists() )
{
throw new IOException( "Unable to gather the list of snapshot versions on a non-existant directory: "
+ repoDir.getAbsolutePath() );
throw new IOException( "Unable to gather the list of snapshot versions on a non-existant directory: " +
repoDir.getAbsolutePath() );
}
if ( !repoDir.isDirectory() )
{
throw new IOException( "Unable to gather the list of snapshot versions on a non-directory: "
+ repoDir.getAbsolutePath() );
throw new IOException(
"Unable to gather the list of snapshot versions on a non-directory: " + repoDir.getAbsolutePath() );
}
Set<String> foundVersions = new HashSet<String>();
@ -344,8 +341,8 @@ public class MetadataTools
}
/**
* Take a path to a maven-metadata.xml, and attempt to translate it to a VersionedReference.
*
* Take a path to a maven-metadata.xml, and attempt to translate it to a VersionedReference.
*
* @param path
* @return
*/
@ -372,7 +369,7 @@ public class MetadataTools
{
// Scary check, but without it, all paths are version references;
throw new RepositoryMetadataException(
"Not a versioned reference, as version id on path has no number in it." );
"Not a versioned reference, as version id on path has no number in it." );
}
reference.setArtifactId( pathParts[artifactIdOffset] );
@ -482,11 +479,10 @@ public class MetadataTools
}
/**
* Adjusts a path for a metadata.xml file to its repository specific path.
*
* Adjusts a path for a metadata.xml file to its repository specific path.
*
* @param repository the repository to base new path off of.
* @param path the path to the metadata.xml file to adjust the name of.
*
* @param path the path to the metadata.xml file to adjust the name of.
* @return the newly adjusted path reference to the repository specific metadata path.
*/
public String getRepositorySpecificName( ArchivaRepository repository, String path )
@ -495,11 +491,10 @@ public class MetadataTools
}
/**
* Adjusts a path for a metadata.xml file to its repository specific path.
*
* Adjusts a path for a metadata.xml file to its repository specific path.
*
* @param proxyId the repository id to base new path off of.
* @param path the path to the metadata.xml file to adjust the name of.
*
* @param path the path to the metadata.xml file to adjust the name of.
* @return the newly adjusted path reference to the repository specific metadata path.
*/
public String getRepositorySpecificName( String proxyId, String path )
@ -528,8 +523,8 @@ public class MetadataTools
configuration.addChangeListener( this );
}
public ArchivaRepositoryMetadata readProxyMetadata( ArchivaRepository managedRepository,
ProjectReference reference, String proxyId )
public ArchivaRepositoryMetadata readProxyMetadata( ArchivaRepository managedRepository, ProjectReference reference,
String proxyId )
{
String metadataPath = getRepositorySpecificName( proxyId, toPath( reference ) );
File metadataFile = new File( managedRepository.getUrl().getPath(), metadataPath );
@ -567,17 +562,17 @@ public class MetadataTools
}
/**
* Update the metadata to represent the all versions of
* Update the metadata to represent the all versions of
* the provided groupId:artifactId project reference,
* based off of information present in the repository,
* the maven-metadata.xml files, and the proxy/repository specific
* metadata file contents.
*
* metadata file contents.
*
* @param managedRepository the managed repository where the metadata is kept.
* @param reference the versioned referencfe to update.
* @throws LayoutException
* @throws RepositoryMetadataException
* @throws IOException
* @param reference the versioned referencfe to update.
* @throws LayoutException
* @throws RepositoryMetadataException
* @throws IOException
*/
public void updateMetadata( ArchivaRepository managedRepository, ProjectReference reference )
throws LayoutException, RepositoryMetadataException, IOException
@ -632,17 +627,17 @@ public class MetadataTools
/**
* Update the metadata based on the following rules.
*
* 1) If this is a SNAPSHOT reference, then utilize the proxy/repository specific
* metadata files to represent the current / latest SNAPSHOT available.
* 2) If this is a RELEASE reference, and the metadata file does not exist, then
* create the metadata file with contents required of the VersionedReference
*
* <p/>
* 1) If this is a SNAPSHOT reference, then utilize the proxy/repository specific
* metadata files to represent the current / latest SNAPSHOT available.
* 2) If this is a RELEASE reference, and the metadata file does not exist, then
* create the metadata file with contents required of the VersionedReference
*
* @param managedRepository the managed repository where the metadata is kept.
* @param reference the versioned reference to update
* @throws LayoutException
* @throws RepositoryMetadataException
* @throws IOException
* @param reference the versioned reference to update
* @throws LayoutException
* @throws RepositoryMetadataException
* @throws IOException
*/
public void updateMetadata( ArchivaRepository managedRepository, VersionedReference reference )
throws LayoutException, RepositoryMetadataException, IOException
@ -724,8 +719,8 @@ public class MetadataTools
}
else
{
throw new RepositoryMetadataException( "Unable to process snapshot version <" + latestVersion
+ "> reference <" + reference + ">" );
throw new RepositoryMetadataException(
"Unable to process snapshot version <" + latestVersion + "> reference <" + reference + ">" );
}
}
else

View File

@ -25,10 +25,7 @@ import org.apache.maven.archiva.configuration.ProxyConnectorConfiguration;
import org.apache.maven.archiva.model.ArchivaRepository;
import org.apache.maven.archiva.model.ProjectReference;
import org.apache.maven.archiva.model.VersionedReference;
import org.apache.maven.archiva.policies.CachedFailuresPolicy;
import org.apache.maven.archiva.policies.ChecksumPolicy;
import org.apache.maven.archiva.policies.ReleasesPolicy;
import org.apache.maven.archiva.policies.SnapshotsPolicy;
import org.apache.maven.archiva.policies.DownloadPolicy;
import org.apache.maven.archiva.repository.layout.LayoutException;
import org.codehaus.plexus.PlexusTestCase;
import org.custommonkey.xmlunit.DetailedDiff;
@ -36,17 +33,17 @@ import org.custommonkey.xmlunit.Diff;
import org.custommonkey.xmlunit.XMLAssert;
import org.xml.sax.SAXException;
import javax.xml.parsers.ParserConfigurationException;
import java.io.File;
import java.io.IOException;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.List;
import java.util.Set;
import javax.xml.parsers.ParserConfigurationException;
/**
* MetadataToolsTest
* MetadataToolsTest
*
* @author <a href="mailto:joakime@apache.org">Joakim Erdfelt</a>
* @version $Id$
@ -61,44 +58,35 @@ public class MetadataToolsTest
public void testGatherAvailableVersionsBadArtifact()
throws Exception
{
assertAvailableVersions( "bad_artifact", new String[] {} );
assertAvailableVersions( "bad_artifact", Collections.EMPTY_LIST );
}
public void testGatherAvailableVersionsMissingMultipleVersions()
throws Exception
{
assertAvailableVersions( "missing_metadata_b", new String[] {
"1.0",
"1.0.1",
"2.0",
"2.0.1",
"2.0-20070821-dev" } );
assertAvailableVersions( "missing_metadata_b",
Arrays.asList( "1.0", "1.0.1", "2.0", "2.0.1", "2.0-20070821-dev" ) );
}
public void testGatherAvailableVersionsSimpleYetIncomplete()
throws Exception
{
assertAvailableVersions( "incomplete_metadata_a", new String[] { "1.0" } );
assertAvailableVersions( "incomplete_metadata_a", Collections.singletonList( "1.0" ) );
}
public void testGatherAvailableVersionsSimpleYetMissing()
throws Exception
{
assertAvailableVersions( "missing_metadata_a", new String[] { "1.0" } );
assertAvailableVersions( "missing_metadata_a", Collections.singletonList( "1.0" ) );
}
public void testGatherSnapshotVersionsA()
throws Exception
{
assertSnapshotVersions( "snap_shots_a", "1.0-alpha-11-SNAPSHOT", new String[] {
"1.0-alpha-11-SNAPSHOT",
"1.0-alpha-11-20070221.194724-2",
"1.0-alpha-11-20070302.212723-3",
"1.0-alpha-11-20070303.152828-4",
"1.0-alpha-11-20070305.215149-5",
"1.0-alpha-11-20070307.170909-6",
"1.0-alpha-11-20070314.211405-9",
"1.0-alpha-11-20070316.175232-11" } );
assertSnapshotVersions( "snap_shots_a", "1.0-alpha-11-SNAPSHOT", new String[]{"1.0-alpha-11-SNAPSHOT",
"1.0-alpha-11-20070221.194724-2", "1.0-alpha-11-20070302.212723-3", "1.0-alpha-11-20070303.152828-4",
"1.0-alpha-11-20070305.215149-5", "1.0-alpha-11-20070307.170909-6", "1.0-alpha-11-20070314.211405-9",
"1.0-alpha-11-20070316.175232-11"} );
}
public void testGatherSnapshotVersionsAWithProxies()
@ -110,16 +98,11 @@ public class MetadataToolsTest
createProxyConnector( "test-repo", "internal-snapshots" );
createProxyConnector( "test-repo", "snapshots.codehaus.org" );
assertSnapshotVersions( "snap_shots_a", "1.0-alpha-11-SNAPSHOT", new String[] {
"1.0-alpha-11-SNAPSHOT",
"1.0-alpha-11-20070221.194724-2",
"1.0-alpha-11-20070302.212723-3",
"1.0-alpha-11-20070303.152828-4",
"1.0-alpha-11-20070305.215149-5",
"1.0-alpha-11-20070307.170909-6",
"1.0-alpha-11-20070314.211405-9",
assertSnapshotVersions( "snap_shots_a", "1.0-alpha-11-SNAPSHOT", new String[]{"1.0-alpha-11-SNAPSHOT",
"1.0-alpha-11-20070221.194724-2", "1.0-alpha-11-20070302.212723-3", "1.0-alpha-11-20070303.152828-4",
"1.0-alpha-11-20070305.215149-5", "1.0-alpha-11-20070307.170909-6", "1.0-alpha-11-20070314.211405-9",
"1.0-alpha-11-20070315.033030-10" /* Arrives in via snapshots.codehaus.org proxy */,
"1.0-alpha-11-20070316.175232-11" } );
"1.0-alpha-11-20070316.175232-11"} );
}
public void testGetRepositorySpecificName()
@ -127,12 +110,11 @@ public class MetadataToolsTest
ArchivaRepository repoJavaNet = new ArchivaRepository( "maven2-repository.dev.java.net",
"Java.net Repository for Maven 2",
"http://download.java.net/maven/2/" );
ArchivaRepository repoCentral = new ArchivaRepository( "central", "Central Global Repository",
"http://repo1.maven.org/maven2/" );
ArchivaRepository repoCentral =
new ArchivaRepository( "central", "Central Global Repository", "http://repo1.maven.org/maven2/" );
String convertedName;
convertedName = tools.getRepositorySpecificName( repoJavaNet, "commons-lang/commons-lang/maven-metadata.xml" );
String convertedName =
tools.getRepositorySpecificName( repoJavaNet, "commons-lang/commons-lang/maven-metadata.xml" );
assertMetadataPath( "commons-lang/commons-lang/maven-metadata-maven2-repository.dev.java.net.xml",
convertedName );
@ -157,12 +139,8 @@ public class MetadataToolsTest
public void testUpdateProjectMissingMultipleVersions()
throws Exception
{
assertUpdatedProjectMetadata( "missing_metadata_b", new String[] {
"1.0",
"1.0.1",
"2.0",
"2.0.1",
"2.0-20070821-dev" } );
assertUpdatedProjectMetadata( "missing_metadata_b",
new String[]{"1.0", "1.0.1", "2.0", "2.0.1", "2.0-20070821-dev"} );
}
public void testUpdateProjectMissingMultipleVersionsWithProxies()
@ -174,30 +152,22 @@ public class MetadataToolsTest
createProxyConnector( "test-repo", "central" );
createProxyConnector( "test-repo", "java.net" );
assertUpdatedProjectMetadata( "proxied_multi", new String[] {
"1.0-spec" /* in java.net */,
"1.0" /* in managed, and central */,
"1.0.1" /* in central */,
"1.1" /* in managed */,
"2.0-proposal-beta" /* in java.net */,
"2.0-spec" /* in java.net */,
"2.0" /* in central, and java.net */,
"2.0.1" /* in java.net */,
"2.1" /* in managed */,
"3.0" /* in central */,
"3.1" /* in central */} );
assertUpdatedProjectMetadata( "proxied_multi", new String[]{"1.0-spec" /* in java.net */, "1.0"
/* in managed, and central */, "1.0.1" /* in central */, "1.1" /* in managed */, "2.0-proposal-beta"
/* in java.net */, "2.0-spec" /* in java.net */, "2.0" /* in central, and java.net */, "2.0.1"
/* in java.net */, "2.1" /* in managed */, "3.0" /* in central */, "3.1" /* in central */} );
}
public void testUpdateProjectSimpleYetIncomplete()
throws Exception
{
assertUpdatedProjectMetadata( "incomplete_metadata_a", new String[] { "1.0" } );
assertUpdatedProjectMetadata( "incomplete_metadata_a", new String[]{"1.0"} );
}
public void testUpdateProjectSimpleYetMissing()
throws Exception
{
assertUpdatedProjectMetadata( "missing_metadata_a", new String[] { "1.0" } );
assertUpdatedProjectMetadata( "missing_metadata_a", new String[]{"1.0"} );
}
public void testUpdateVersionSimple10()
@ -334,7 +304,7 @@ public class MetadataToolsTest
assertEquals( "VersionedReference.version", version, reference.getVersion() );
}
private void assertAvailableVersions( String artifactId, String[] expectedVersions )
private void assertAvailableVersions( String artifactId, List<String> expectedVersions )
throws Exception
{
File repoRootDir = new File( "src/test/repositories/metadata-repository" );
@ -354,13 +324,7 @@ public class MetadataToolsTest
Collections.sort( testedVersions, new VersionComparator() );
// Test the expected array of versions, to the actual tested versions
assertEquals( "Assert Available Versions: length/size", expectedVersions.length, testedVersions.size() );
for ( int i = 0; i < expectedVersions.length; i++ )
{
String actualVersion = (String) testedVersions.get( i );
assertEquals( "Available Versions[" + i + "]", expectedVersions[i], actualVersion );
}
assertEquals( "available versions", expectedVersions, testedVersions );
}
private void assertSnapshotVersions( String artifactId, String version, String[] expectedVersions )
@ -388,7 +352,7 @@ public class MetadataToolsTest
for ( int i = 0; i < expectedVersions.length; i++ )
{
String actualVersion = (String) testedVersions.get( i );
String actualVersion = testedVersions.get( i );
assertEquals( "Snapshot Versions[" + i + "]", expectedVersions[i], actualVersion );
}
}
@ -421,7 +385,7 @@ public class MetadataToolsTest
assertEquals( "Repository Specific Metadata Path", expected, actual );
}
private void assertUpdatedProjectMetadata( String artifactId, String expectedVersions[] )
private void assertUpdatedProjectMetadata( String artifactId, String[] expectedVersions )
throws IOException, LayoutException, RepositoryMetadataException, SAXException, ParserConfigurationException
{
ArchivaRepository testRepo = createTestRepo();
@ -433,7 +397,7 @@ public class MetadataToolsTest
tools.updateMetadata( testRepo, reference );
StringBuffer buf = new StringBuffer();
StringBuilder buf = new StringBuilder();
buf.append( "<metadata>\n" );
buf.append( " <groupId>" ).append( reference.getGroupId() ).append( "</groupId>\n" );
buf.append( " <artifactId>" ).append( reference.getArtifactId() ).append( "</artifactId>\n" );
@ -468,7 +432,7 @@ public class MetadataToolsTest
tools.updateMetadata( testRepo, reference );
StringBuffer buf = new StringBuffer();
StringBuilder buf = new StringBuilder();
buf.append( "<metadata>\n" );
buf.append( " <groupId>" ).append( reference.getGroupId() ).append( "</groupId>\n" );
buf.append( " <artifactId>" ).append( reference.getArtifactId() ).append( "</artifactId>\n" );
@ -492,7 +456,7 @@ public class MetadataToolsTest
tools.updateMetadata( testRepo, reference );
StringBuffer buf = new StringBuffer();
StringBuilder buf = new StringBuilder();
buf.append( "<metadata>\n" );
buf.append( " <groupId>" ).append( reference.getGroupId() ).append( "</groupId>\n" );
buf.append( " <artifactId>" ).append( reference.getArtifactId() ).append( "</artifactId>\n" );
@ -513,18 +477,13 @@ public class MetadataToolsTest
private void createProxyConnector( String sourceRepoId, String targetRepoId )
{
String checksumPolicy = ChecksumPolicy.IGNORED;
String releasePolicy = ReleasesPolicy.IGNORED;
String snapshotPolicy = SnapshotsPolicy.IGNORED;
String cacheFailuresPolicy = CachedFailuresPolicy.IGNORED;
ProxyConnectorConfiguration connectorConfig = new ProxyConnectorConfiguration();
connectorConfig.setSourceRepoId( sourceRepoId );
connectorConfig.setTargetRepoId( targetRepoId );
connectorConfig.addPolicy( ProxyConnectorConfiguration.POLICY_CHECKSUM, checksumPolicy );
connectorConfig.addPolicy( ProxyConnectorConfiguration.POLICY_RELEASES, releasePolicy );
connectorConfig.addPolicy( ProxyConnectorConfiguration.POLICY_SNAPSHOTS, snapshotPolicy );
connectorConfig.addPolicy( ProxyConnectorConfiguration.POLICY_CACHE_FAILURES, cacheFailuresPolicy );
connectorConfig.addPolicy( ProxyConnectorConfiguration.POLICY_CHECKSUM, DownloadPolicy.IGNORED );
connectorConfig.addPolicy( ProxyConnectorConfiguration.POLICY_RELEASES, DownloadPolicy.IGNORED );
connectorConfig.addPolicy( ProxyConnectorConfiguration.POLICY_SNAPSHOTS, DownloadPolicy.IGNORED );
connectorConfig.addPolicy( ProxyConnectorConfiguration.POLICY_CACHE_FAILURES, DownloadPolicy.IGNORED );
int count = config.getConfiguration().getProxyConnectors().size();
config.getConfiguration().addProxyConnector( connectorConfig );
@ -552,9 +511,8 @@ public class MetadataToolsTest
repoRoot.mkdirs();
String repoRootURL = PathUtil.toUrl( repoRoot );
ArchivaRepository repo = new ArchivaRepository( "test-repo", "Test Repository: " + getName(), repoRootURL );
return repo;
return new ArchivaRepository( "test-repo", "Test Repository: " + getName(), repoRootURL );
}
private void prepTestRepo( ArchivaRepository repo, ProjectReference reference )