aboutsummaryrefslogtreecommitdiffstats
path: root/archiva-modules/archiva-maven
diff options
context:
space:
mode:
authorMartin Stockhammer <martin_s@apache.org>2020-06-17 08:55:04 +0200
committerMartin Stockhammer <martin_s@apache.org>2020-06-17 08:55:04 +0200
commit735a03f2b040a60cd85f5c3cb43257218ab9f26f (patch)
treebf2bfe7782c9e6931590a0feded6c8b57e33b6ea /archiva-modules/archiva-maven
parent1201ef39745d153cd369eb72b80c80a9ecb72553 (diff)
downloadarchiva-735a03f2b040a60cd85f5c3cb43257218ab9f26f.tar.gz
archiva-735a03f2b040a60cd85f5c3cb43257218ab9f26f.zip
API refactoring
Diffstat (limited to 'archiva-modules/archiva-maven')
-rw-r--r--archiva-modules/archiva-maven/archiva-maven-proxy/src/test/java/org/apache/archiva/proxy/MetadataTransferTest.java71
-rw-r--r--archiva-modules/archiva-maven/archiva-maven-repository/src/test/java/org/apache/archiva/repository/maven/metadata/MetadataToolsTest.java140
2 files changed, 78 insertions, 133 deletions
diff --git a/archiva-modules/archiva-maven/archiva-maven-proxy/src/test/java/org/apache/archiva/proxy/MetadataTransferTest.java b/archiva-modules/archiva-maven/archiva-maven-proxy/src/test/java/org/apache/archiva/proxy/MetadataTransferTest.java
index 71b66b9ec..5f72bdcf3 100644
--- a/archiva-modules/archiva-maven/archiva-maven-proxy/src/test/java/org/apache/archiva/proxy/MetadataTransferTest.java
+++ b/archiva-modules/archiva-maven/archiva-maven-proxy/src/test/java/org/apache/archiva/proxy/MetadataTransferTest.java
@@ -24,9 +24,7 @@ import org.apache.archiva.common.utils.VersionUtil;
import org.apache.archiva.configuration.ProxyConnectorConfiguration;
import org.apache.archiva.model.ArchivaRepositoryMetadata;
import org.apache.archiva.model.Plugin;
-import org.apache.archiva.model.ProjectReference;
import org.apache.archiva.model.SnapshotVersion;
-import org.apache.archiva.model.VersionedReference;
import org.apache.archiva.policies.CachedFailuresPolicy;
import org.apache.archiva.policies.ChecksumPolicy;
import org.apache.archiva.policies.ReleasesPolicy;
@@ -34,14 +32,15 @@ import org.apache.archiva.policies.SnapshotsPolicy;
import org.apache.archiva.repository.BaseRepositoryContentLayout;
import org.apache.archiva.repository.content.ContentItem;
import org.apache.archiva.repository.content.DataItem;
+import org.apache.archiva.repository.content.ItemSelector;
import org.apache.archiva.repository.content.Project;
import org.apache.archiva.repository.content.Version;
import org.apache.archiva.repository.content.base.ArchivaItemSelector;
-import org.apache.archiva.repository.metadata.base.MetadataTools;
import org.apache.archiva.repository.metadata.RepositoryMetadataException;
+import org.apache.archiva.repository.metadata.base.MetadataTools;
import org.apache.archiva.repository.metadata.base.RepositoryMetadataWriter;
-import org.apache.archiva.repository.storage.fs.FilesystemStorage;
import org.apache.archiva.repository.storage.StorageAsset;
+import org.apache.archiva.repository.storage.fs.FilesystemStorage;
import org.apache.commons.lang3.StringUtils;
import org.apache.maven.wagon.TransferFailedException;
import org.easymock.EasyMock;
@@ -1009,11 +1008,6 @@ public class MetadataTransferTest
assertNoTempFiles( expectedFile );
}
- private ProjectReference createProjectReference( String path )
- throws RepositoryMetadataException
- {
- return metadataTools.toProjectReference( path );
- }
/**
* Transfer the metadata file, not expected to succeed.
@@ -1067,11 +1061,6 @@ public class MetadataTransferTest
assertNoTempFiles( expectedFile );
}
- private VersionedReference createVersionedReference( String path )
- throws RepositoryMetadataException
- {
- return metadataTools.toVersionedReference( path );
- }
/**
* Transfer the metadata file, not expected to succeed.
@@ -1171,18 +1160,30 @@ public class MetadataTransferTest
Path actualFile = managedDefaultDir.resolve(requestedResource);
assertTrue( "Snapshot Metadata should exist: " + requestedResource, Files.exists(actualFile) );
- ProjectReference actualMetadata = createGroupReference( requestedResource );
+ ItemSelector actualMetadata = createGroupSelector( requestedResource );
assertGroupMetadata( actualFile, actualMetadata, expectedPlugins );
}
- private ProjectReference createGroupReference( String requestedResource )
+ private ItemSelector createProjectSelector(String path) throws RepositoryMetadataException
+ {
+ return metadataTools.toProjectSelector( path );
+ }
+
+ private ItemSelector createVersionedSelector(String path) throws RepositoryMetadataException
+ {
+ return metadataTools.toVersionedSelector( path );
+ }
+
+ private ItemSelector createGroupSelector( String requestedResource )
throws RepositoryMetadataException
{
- ProjectReference projectReference = createProjectReference( requestedResource );
- projectReference.setGroupId( projectReference.getGroupId() + "." + projectReference.getArtifactId() );
- projectReference.setArtifactId( null );
- return projectReference;
+ ItemSelector projectSelector = createProjectSelector( requestedResource );
+ ArchivaItemSelector.Builder projectReference = ArchivaItemSelector.builder( ).withSelector( projectSelector );
+ projectReference.withNamespace( projectSelector.getNamespace() + "." + projectSelector.getProjectId() );
+ projectReference.withArtifactId( null );
+ projectReference.withProjectId( null );
+ return projectReference.build();
}
private void assertRepoGroupMetadataContents( String proxiedRepoId, String requestedResource,
@@ -1194,18 +1195,18 @@ public class MetadataTransferTest
Path actualFile = managedDefaultDir.resolve(proxiedFile);
assertTrue( "Repo Specific Group Metadata should exist: " + requestedResource, Files.exists(actualFile) );
- ProjectReference actualMetadata = createGroupReference( requestedResource );
+ ItemSelector actualMetadata = createGroupSelector( requestedResource );
assertGroupMetadata( actualFile, actualMetadata, expectedPlugins );
}
- private void assertGroupMetadata( Path actualFile, ProjectReference actualMetadata, String expectedPlugins[] )
+ private void assertGroupMetadata( Path actualFile, ItemSelector actualMetadata, String expectedPlugins[] )
throws Exception
{
// Build expected metadata XML
StringWriter expectedMetadataXml = new StringWriter();
ArchivaRepositoryMetadata m = new ArchivaRepositoryMetadata();
- m.setGroupId( actualMetadata.getGroupId() );
+ m.setGroupId( actualMetadata.getNamespace() );
for ( String pluginId : expectedPlugins )
{
@@ -1236,12 +1237,12 @@ public class MetadataTransferTest
Path actualFile = managedDefaultDir.resolve(requestedResource);
assertTrue( Files.exists(actualFile) );
- ProjectReference metadata = createProjectReference( requestedResource );
+ ItemSelector metadata = createProjectSelector( requestedResource );
// Build expected metadata XML
StringWriter expectedMetadataXml = new StringWriter();
ArchivaRepositoryMetadata m = new ArchivaRepositoryMetadata();
- m.setGroupId( metadata.getGroupId() );
+ m.setGroupId( metadata.getNamespace() );
m.setArtifactId( metadata.getArtifactId() );
m.setLatestVersion( latestVersion );
m.setReleasedVersion( releaseVersion );
@@ -1270,12 +1271,12 @@ public class MetadataTransferTest
Path actualFile = managedDefaultDir.resolve(requestedResource);
assertTrue( "Release Metadata should exist: " + requestedResource, Files.exists(actualFile) );
- VersionedReference metadata = createVersionedReference( requestedResource );
+ ItemSelector metadata = createVersionedSelector( requestedResource );
// Build expected metadata XML
StringWriter expectedMetadataXml = new StringWriter();
ArchivaRepositoryMetadata m = new ArchivaRepositoryMetadata();
- m.setGroupId( metadata.getGroupId() );
+ m.setGroupId( metadata.getNamespace() );
m.setArtifactId( metadata.getArtifactId() );
m.setVersion( metadata.getVersion() );
RepositoryMetadataWriter.write( m, expectedMetadataXml );
@@ -1301,7 +1302,7 @@ public class MetadataTransferTest
Path actualFile = managedDefaultDir.resolve(requestedResource);
assertTrue( "Snapshot Metadata should exist: " + requestedResource, Files.exists(actualFile) );
- VersionedReference actualMetadata = createVersionedReference( requestedResource );
+ ItemSelector actualMetadata = createVersionedSelector( requestedResource );
assertSnapshotMetadata( actualFile, actualMetadata, expectedDate, expectedTime, expectedBuildnumber );
}
@@ -1326,19 +1327,19 @@ public class MetadataTransferTest
Path actualFile = managedDefaultDir.resolve(proxiedFile);
assertTrue( "Repo Specific Snapshot Metadata should exist: " + requestedResource, Files.exists(actualFile) );
- VersionedReference actualMetadata = createVersionedReference( requestedResource );
+ ItemSelector actualMetadata = createVersionedSelector( requestedResource );
assertSnapshotMetadata( actualFile, actualMetadata, expectedDate, expectedTime, expectedBuildnumber );
}
- private void assertSnapshotMetadata( Path actualFile, VersionedReference actualMetadata, String expectedDate,
+ private void assertSnapshotMetadata( Path actualFile, ItemSelector actualMetadata, String expectedDate,
String expectedTime, int expectedBuildnumber )
throws RepositoryMetadataException, Exception
{
// Build expected metadata XML
StringWriter expectedMetadataXml = new StringWriter();
ArchivaRepositoryMetadata m = new ArchivaRepositoryMetadata();
- m.setGroupId( actualMetadata.getGroupId() );
+ m.setGroupId( actualMetadata.getNamespace() );
m.setArtifactId( actualMetadata.getArtifactId() );
m.setVersion( VersionUtil.getBaseVersion( actualMetadata.getVersion() ) );
@@ -1376,12 +1377,12 @@ public class MetadataTransferTest
Path actualFile = managedDefaultDir.resolve(proxiedFile);
assertTrue( Files.exists(actualFile) );
- ProjectReference metadata = createProjectReference( requestedResource );
+ ItemSelector metadata = createProjectSelector( requestedResource );
// Build expected metadata XML
StringWriter expectedMetadataXml = new StringWriter();
ArchivaRepositoryMetadata m = new ArchivaRepositoryMetadata();
- m.setGroupId( metadata.getGroupId() );
+ m.setGroupId( metadata.getNamespace() );
m.setArtifactId( metadata.getArtifactId() );
if ( expectedProxyVersions != null )
@@ -1410,12 +1411,12 @@ public class MetadataTransferTest
Path actualFile = managedDefaultDir.resolve(proxiedFile);
assertTrue( "Release metadata for repo should exist: " + actualFile, Files.exists(actualFile) );
- VersionedReference metadata = createVersionedReference( requestedResource );
+ ItemSelector metadata = createVersionedSelector( requestedResource );
// Build expected metadata XML
StringWriter expectedMetadataXml = new StringWriter();
ArchivaRepositoryMetadata m = new ArchivaRepositoryMetadata();
- m.setGroupId( metadata.getGroupId() );
+ m.setGroupId( metadata.getNamespace() );
m.setArtifactId( metadata.getArtifactId() );
m.setVersion( metadata.getVersion() );
RepositoryMetadataWriter.write( m, expectedMetadataXml );
diff --git a/archiva-modules/archiva-maven/archiva-maven-repository/src/test/java/org/apache/archiva/repository/maven/metadata/MetadataToolsTest.java b/archiva-modules/archiva-maven/archiva-maven-repository/src/test/java/org/apache/archiva/repository/maven/metadata/MetadataToolsTest.java
index 437053fd7..c5c38de42 100644
--- a/archiva-modules/archiva-maven/archiva-maven-repository/src/test/java/org/apache/archiva/repository/maven/metadata/MetadataToolsTest.java
+++ b/archiva-modules/archiva-maven/archiva-maven-repository/src/test/java/org/apache/archiva/repository/maven/metadata/MetadataToolsTest.java
@@ -254,22 +254,24 @@ public class MetadataToolsTest
@Test
public void testToPathFromVersionReference()
{
- VersionedReference reference = new VersionedReference();
- reference.setGroupId( "com.foo" );
- reference.setArtifactId( "foo-tool" );
- reference.setVersion( "1.0" );
+ ItemSelector selector = ArchivaItemSelector.builder( )
+ .withNamespace( "com.foo" )
+ .withArtifactId( "foo-tool" )
+ .withProjectId( "foo-tool" )
+ .withVersion( "1.0" ).build( );
- assertEquals( "com/foo/foo-tool/1.0/maven-metadata.xml", tools.toPath( reference ) );
+ assertEquals( "com/foo/foo-tool/1.0/maven-metadata.xml", tools.toPath( selector ) );
}
@Test
public void testToPathFromProjectReference()
{
- ProjectReference reference = new ProjectReference();
- reference.setGroupId( "com.foo" );
- reference.setArtifactId( "foo-tool" );
+ ItemSelector selector = ArchivaItemSelector.builder( )
+ .withNamespace( "com.foo" )
+ .withProjectId( "foo-tool" )
+ .withArtifactId( "foo-tool" ).build( );
- assertEquals( "com/foo/foo-tool/maven-metadata.xml", tools.toPath( reference ) );
+ assertEquals( "com/foo/foo-tool/maven-metadata.xml", tools.toPath( selector ) );
}
@Test
@@ -304,10 +306,10 @@ public class MetadataToolsTest
private void assertProjectReference( String groupId, String artifactId, String path )
throws RepositoryMetadataException
{
- ProjectReference reference = tools.toProjectReference( path );
+ ItemSelector reference = tools.toProjectSelector( path );
assertNotNull( "Reference should not be null.", reference );
- assertEquals( "ProjectReference.groupId", groupId, reference.getGroupId() );
+ assertEquals( "ProjectReference.groupId", groupId, reference.getNamespace() );
assertEquals( "ProjectReference.artifactId", artifactId, reference.getArtifactId() );
}
@@ -362,10 +364,10 @@ public class MetadataToolsTest
private void assertVersionedReference( String groupId, String artifactId, String version, String path )
throws RepositoryMetadataException
{
- VersionedReference reference = tools.toVersionedReference( path );
+ ItemSelector reference = tools.toVersionedSelector( path );
assertNotNull( "Reference should not be null.", reference );
- assertEquals( "VersionedReference.groupId", groupId, reference.getGroupId() );
+ assertEquals( "VersionedReference.groupId", groupId, reference.getNamespace() );
assertEquals( "VersionedReference.artifactId", artifactId, reference.getArtifactId() );
assertEquals( "VersionedReference.version", version, reference.getVersion() );
}
@@ -375,10 +377,11 @@ public class MetadataToolsTest
{
Path repoRootDir = getRepositoryPath( "metadata-repository" );
- VersionedReference reference = new VersionedReference();
- reference.setGroupId( "org.apache.archiva.metadata.tests" );
- reference.setArtifactId( artifactId );
- reference.setVersion( version );
+ ItemSelector reference = ArchivaItemSelector.builder( )
+ .withNamespace( "org.apache.archiva.metadata.tests" )
+ .withArtifactId( artifactId )
+ .withProjectId( artifactId )
+ .withVersion( version ).build( );
MavenManagedRepository repo =
createRepository( "test-repo", "Test Repository: " + name.getMethodName(), repoRootDir );
@@ -424,25 +427,7 @@ public class MetadataToolsTest
}
private void assertMetadata( String expectedMetadata, ManagedRepositoryContent repository,
- ProjectReference reference )
- throws LayoutException, IOException, SAXException, ParserConfigurationException
- {
- Path metadataFile = repository.getRepository().getRoot().getFilePath().resolve(tools.toPath( reference ) );
- String actualMetadata = org.apache.archiva.common.utils.FileUtils.readFileToString( metadataFile, Charset.defaultCharset() );
-
- Diff detailedDiff = DiffBuilder.compare( expectedMetadata ).withTest( actualMetadata ).checkForSimilar().build();
- if ( detailedDiff.hasDifferences() )
- {
- for ( Difference diff : detailedDiff.getDifferences() ) {
- System.out.println( diff );
- }
- // If it isn't similar, dump the difference.
- assertEquals( expectedMetadata, actualMetadata );
- }
- }
-
- private void assertMetadata( String expectedMetadata, ManagedRepositoryContent repository,
- VersionedReference reference )
+ ItemSelector reference )
throws LayoutException, IOException, SAXException, ParserConfigurationException
{
Path metadataFile = repository.getRepository().getRoot().getFilePath().resolve( tools.toPath( reference ) );
@@ -543,62 +528,30 @@ public class MetadataToolsTest
assertProjectMetadata( buf.toString(), testRepo, reference );
}
- private void assertProjectMetadata( ManagedRepositoryContent testRepo, ProjectReference reference,
- String artifactId, String[] expectedVersions, String latestVersion,
- String releaseVersion )
- throws Exception
- {
- 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" );
-
- if ( expectedVersions != null )
- {
- buf.append( " <versioning>\n" );
- if ( latestVersion != null )
- {
- buf.append( " <latest>" ).append( latestVersion ).append( "</latest>\n" );
- }
- if ( releaseVersion != null )
- {
- buf.append( " <release>" ).append( releaseVersion ).append( "</release>\n" );
- }
-
- buf.append( " <versions>\n" );
- for ( int i = 0; i < expectedVersions.length; i++ )
- {
- buf.append( " <version>" ).append( expectedVersions[i] ).append( "</version>\n" );
- }
- buf.append( " </versions>\n" );
- buf.append( " </versioning>\n" );
- }
- buf.append( "</metadata>" );
-
- assertMetadata( buf.toString(), testRepo, reference );
- }
private void assertUpdatedReleaseVersionMetadata( String artifactId, String version )
throws Exception
{
ManagedRepositoryContent testRepo = createTestRepoContent();
- VersionedReference reference = new VersionedReference();
- reference.setGroupId( "org.apache.archiva.metadata.tests" );
- reference.setArtifactId( artifactId );
- reference.setVersion( version );
- prepTestRepo( testRepo, reference );
+ ItemSelector selector = ArchivaItemSelector.builder()
+ .withNamespace( "org.apache.archiva.metadata.tests" )
+ .withProjectId( artifactId )
+ .withArtifactId( artifactId )
+ .withVersion( version ).build();
+
+ prepTestRepo( testRepo, selector );
- tools.updateMetadata( testRepo, reference );
+ tools.updateVersionMetadata( testRepo, selector );
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" );
- buf.append( " <version>" ).append( reference.getVersion() ).append( "</version>\n" );
+ buf.append( " <groupId>" ).append( selector.getNamespace() ).append( "</groupId>\n" );
+ buf.append( " <artifactId>" ).append( selector.getArtifactId() ).append( "</artifactId>\n" );
+ buf.append( " <version>" ).append( selector.getVersion() ).append( "</version>\n" );
buf.append( "</metadata>" );
- assertMetadata( buf.toString(), testRepo, reference );
+ assertMetadata( buf.toString(), testRepo, selector );
}
private void assertUpdatedSnapshotVersionMetadata( String artifactId, String version, String expectedDate,
@@ -606,18 +559,19 @@ public class MetadataToolsTest
throws Exception
{
ManagedRepositoryContent testRepo = createTestRepoContent();
- VersionedReference reference = new VersionedReference();
- reference.setGroupId( "org.apache.archiva.metadata.tests" );
- reference.setArtifactId( artifactId );
- reference.setVersion( version );
+ ItemSelector reference = ArchivaItemSelector.builder()
+ .withNamespace( "org.apache.archiva.metadata.tests" )
+ .withArtifactId( artifactId )
+ .withProjectId( artifactId )
+ .withVersion( version ).build();
prepTestRepo( testRepo, reference );
- tools.updateMetadata( testRepo, reference );
+ tools.updateVersionMetadata( testRepo, reference );
StringBuilder buf = new StringBuilder();
buf.append( "<metadata>\n" );
- buf.append( " <groupId>" ).append( reference.getGroupId() ).append( "</groupId>\n" );
+ buf.append( " <groupId>" ).append( reference.getNamespace() ).append( "</groupId>\n" );
buf.append( " <artifactId>" ).append( reference.getArtifactId() ).append( "</artifactId>\n" );
buf.append( " <version>" ).append( reference.getVersion() ).append( "</version>\n" );
buf.append( " <versioning>\n" );
@@ -719,10 +673,10 @@ public class MetadataToolsTest
FileUtils.copyDirectory( srcDir.toFile(), destDir.toFile() );
}
- private void prepTestRepo( ManagedRepositoryContent repo, ProjectReference reference )
+ private void prepTestRepo( ManagedRepositoryContent repo, ItemSelector reference )
throws IOException
{
- String groupDir = StringUtils.replaceChars( reference.getGroupId(), '.', '/' );
+ String groupDir = StringUtils.replaceChars( reference.getNamespace(), '.', '/' );
String path = groupDir + "/" + reference.getArtifactId();
Path srcRepoDir = getRepositoryPath( "metadata-repository" );
@@ -735,15 +689,5 @@ public class MetadataToolsTest
FileUtils.copyDirectory( srcDir.toFile(), destDir.toFile() );
}
- private void prepTestRepo( ManagedRepositoryContent repo, VersionedReference reference )
- throws IOException
- {
- ProjectReference projectRef = new ProjectReference();
- projectRef.setGroupId( reference.getGroupId() );
- projectRef.setArtifactId( reference.getArtifactId() );
-
- prepTestRepo( repo, projectRef );
- }
-
}