From d25d6452aeaa5c31e7d21b336a1c731eab9ea3d2 Mon Sep 17 00:00:00 2001 From: Brett Porter Date: Thu, 20 Mar 2008 12:21:49 +0000 Subject: [PATCH] [MNG-734] fix plugin-level metadata handling git-svn-id: https://svn.apache.org/repos/asf/maven/archiva/branches@639260 13f79535-47bb-0310-9956-ffa450edef68 --- .../src/main/mdo/archiva-base.xml | 53 ++++ .../archiva/proxy/MetadataTransferTest.java | 267 +++++++++++++++++- .../get-not-on-remotes/maven-metadata.xml | 29 ++ .../get-on-local-on-remote/maven-metadata.xml | 34 +++ .../get-on-multiple-repos/maven-metadata.xml | 29 ++ .../get-project-metadata/maven-metadata.xml | 29 ++ .../get-default-layout/maven-metadata.xml | 29 ++ .../get-found-in-proxy/maven-metadata.xml | 29 ++ .../get-on-local-on-remote/maven-metadata.xml | 34 +++ .../get-on-multiple-repos/maven-metadata.xml | 34 +++ .../get-default-layout/maven-metadata.xml | 29 ++ .../get-on-multiple-repos/maven-metadata.xml | 34 +++ .../repository/metadata/MetadataTools.java | 90 +++--- .../metadata/RepositoryMetadataReader.java | 10 + .../metadata/RepositoryMetadataWriter.java | 16 +- .../metadata/MetadataToolsTest.java | 30 +- ...ositoryServletProxiedMetadataTestCase.java | 29 +- .../RepositoryServletNoProxyMetadataTest.java | 19 +- .../RepositoryServletNoProxyTest.java | 19 +- ...ryServletProxiedMetadataLocalOnlyTest.java | 20 ++ ...yServletProxiedMetadataRemoteOnlyTest.java | 24 ++ 21 files changed, 824 insertions(+), 63 deletions(-) create mode 100644 archiva-1.0.x/archiva-base/archiva-proxy/src/test/repositories/managed/org/apache/maven/test/groups/get-not-on-remotes/maven-metadata.xml create mode 100644 archiva-1.0.x/archiva-base/archiva-proxy/src/test/repositories/managed/org/apache/maven/test/groups/get-on-local-on-remote/maven-metadata.xml create mode 100644 archiva-1.0.x/archiva-base/archiva-proxy/src/test/repositories/managed/org/apache/maven/test/groups/get-on-multiple-repos/maven-metadata.xml create mode 100644 archiva-1.0.x/archiva-base/archiva-proxy/src/test/repositories/managed/org/apache/maven/test/groups/get-project-metadata/maven-metadata.xml create mode 100644 archiva-1.0.x/archiva-base/archiva-proxy/src/test/repositories/proxied1/org/apache/maven/test/groups/get-default-layout/maven-metadata.xml create mode 100644 archiva-1.0.x/archiva-base/archiva-proxy/src/test/repositories/proxied1/org/apache/maven/test/groups/get-found-in-proxy/maven-metadata.xml create mode 100644 archiva-1.0.x/archiva-base/archiva-proxy/src/test/repositories/proxied1/org/apache/maven/test/groups/get-on-local-on-remote/maven-metadata.xml create mode 100644 archiva-1.0.x/archiva-base/archiva-proxy/src/test/repositories/proxied1/org/apache/maven/test/groups/get-on-multiple-repos/maven-metadata.xml create mode 100644 archiva-1.0.x/archiva-base/archiva-proxy/src/test/repositories/proxied2/org/apache/maven/test/groups/get-default-layout/maven-metadata.xml create mode 100644 archiva-1.0.x/archiva-base/archiva-proxy/src/test/repositories/proxied2/org/apache/maven/test/groups/get-on-multiple-repos/maven-metadata.xml diff --git a/archiva-1.0.x/archiva-base/archiva-model/src/main/mdo/archiva-base.xml b/archiva-1.0.x/archiva-base/archiva-model/src/main/mdo/archiva-base.xml index 663cc4f71..e4286f737 100644 --- a/archiva-1.0.x/archiva-base/archiva-model/src/main/mdo/archiva-base.xml +++ b/archiva-1.0.x/archiva-base/archiva-model/src/main/mdo/archiva-base.xml @@ -640,6 +640,20 @@ 1 + + plugins + false + 1.0.0+ + false + + The available plugins. + + + Plugin + * + + availableVersions false @@ -766,6 +780,45 @@ + + Plugin + The Plugin + 1.0.0+ + + + prefix + String + false + true + + The prefix for a plugin + + + + artifactId + String + true + true + + The artifactId for a plugin + + + + name + String + false + true + + The name for a plugin + + + + + + + + org.apache.maven.test.groups.get-not-on-remotes + + + plugin5 + plugin5-maven-plugin + The plugin5 Plugin + + + diff --git a/archiva-1.0.x/archiva-base/archiva-proxy/src/test/repositories/managed/org/apache/maven/test/groups/get-on-local-on-remote/maven-metadata.xml b/archiva-1.0.x/archiva-base/archiva-proxy/src/test/repositories/managed/org/apache/maven/test/groups/get-on-local-on-remote/maven-metadata.xml new file mode 100644 index 000000000..14196bdc1 --- /dev/null +++ b/archiva-1.0.x/archiva-base/archiva-proxy/src/test/repositories/managed/org/apache/maven/test/groups/get-on-local-on-remote/maven-metadata.xml @@ -0,0 +1,34 @@ + + + + org.apache.maven.test.groups.get-on-local-on-remote + + + plugin6 + plugin6-maven-plugin + The plugin6 Plugin + + + plugin7 + plugin7-maven-plugin + The plugin7 Plugin + + + diff --git a/archiva-1.0.x/archiva-base/archiva-proxy/src/test/repositories/managed/org/apache/maven/test/groups/get-on-multiple-repos/maven-metadata.xml b/archiva-1.0.x/archiva-base/archiva-proxy/src/test/repositories/managed/org/apache/maven/test/groups/get-on-multiple-repos/maven-metadata.xml new file mode 100644 index 000000000..a04428913 --- /dev/null +++ b/archiva-1.0.x/archiva-base/archiva-proxy/src/test/repositories/managed/org/apache/maven/test/groups/get-on-multiple-repos/maven-metadata.xml @@ -0,0 +1,29 @@ + + + + org.apache.maven.test.groups.get-on-multiple-repos + + + plugin1 + plugin1-maven-plugin + The plugin1 Plugin + + + diff --git a/archiva-1.0.x/archiva-base/archiva-proxy/src/test/repositories/managed/org/apache/maven/test/groups/get-project-metadata/maven-metadata.xml b/archiva-1.0.x/archiva-base/archiva-proxy/src/test/repositories/managed/org/apache/maven/test/groups/get-project-metadata/maven-metadata.xml new file mode 100644 index 000000000..e0829c112 --- /dev/null +++ b/archiva-1.0.x/archiva-base/archiva-proxy/src/test/repositories/managed/org/apache/maven/test/groups/get-project-metadata/maven-metadata.xml @@ -0,0 +1,29 @@ + + + + org.apache.maven.test.groups.get-project-metadata + + + plugin1 + plugin1-maven-plugin + The plugin1 Plugin + + + diff --git a/archiva-1.0.x/archiva-base/archiva-proxy/src/test/repositories/proxied1/org/apache/maven/test/groups/get-default-layout/maven-metadata.xml b/archiva-1.0.x/archiva-base/archiva-proxy/src/test/repositories/proxied1/org/apache/maven/test/groups/get-default-layout/maven-metadata.xml new file mode 100644 index 000000000..9f6bf9239 --- /dev/null +++ b/archiva-1.0.x/archiva-base/archiva-proxy/src/test/repositories/proxied1/org/apache/maven/test/groups/get-default-layout/maven-metadata.xml @@ -0,0 +1,29 @@ + + + + org.apache.maven.test.groups.get-default-layout + + + plugin1 + plugin1-maven-plugin + The plugin1 Plugin + + + diff --git a/archiva-1.0.x/archiva-base/archiva-proxy/src/test/repositories/proxied1/org/apache/maven/test/groups/get-found-in-proxy/maven-metadata.xml b/archiva-1.0.x/archiva-base/archiva-proxy/src/test/repositories/proxied1/org/apache/maven/test/groups/get-found-in-proxy/maven-metadata.xml new file mode 100644 index 000000000..90102867a --- /dev/null +++ b/archiva-1.0.x/archiva-base/archiva-proxy/src/test/repositories/proxied1/org/apache/maven/test/groups/get-found-in-proxy/maven-metadata.xml @@ -0,0 +1,29 @@ + + + + org.apache.maven.test.groups.get-found-in-proxy + + + plugin3 + plugin3-maven-plugin + The plugin3 Plugin + + + diff --git a/archiva-1.0.x/archiva-base/archiva-proxy/src/test/repositories/proxied1/org/apache/maven/test/groups/get-on-local-on-remote/maven-metadata.xml b/archiva-1.0.x/archiva-base/archiva-proxy/src/test/repositories/proxied1/org/apache/maven/test/groups/get-on-local-on-remote/maven-metadata.xml new file mode 100644 index 000000000..23f12bbf1 --- /dev/null +++ b/archiva-1.0.x/archiva-base/archiva-proxy/src/test/repositories/proxied1/org/apache/maven/test/groups/get-on-local-on-remote/maven-metadata.xml @@ -0,0 +1,34 @@ + + + + org.apache.maven.test.groups.get-on-local-on-remote + + + plugin7 + plugin7-maven-plugin + The plugin7 Plugin + + + plugin4 + plugin4-maven-plugin + The plugin4 Plugin + + + diff --git a/archiva-1.0.x/archiva-base/archiva-proxy/src/test/repositories/proxied1/org/apache/maven/test/groups/get-on-multiple-repos/maven-metadata.xml b/archiva-1.0.x/archiva-base/archiva-proxy/src/test/repositories/proxied1/org/apache/maven/test/groups/get-on-multiple-repos/maven-metadata.xml new file mode 100644 index 000000000..3abe069e7 --- /dev/null +++ b/archiva-1.0.x/archiva-base/archiva-proxy/src/test/repositories/proxied1/org/apache/maven/test/groups/get-on-multiple-repos/maven-metadata.xml @@ -0,0 +1,34 @@ + + + + org.apache.maven.test.groups.get-on-multiple-repos + + + plugin1 + plugin1-maven-plugin + The plugin1 Plugin + + + plugin4 + plugin4-maven-plugin + The plugin4 Plugin + + + diff --git a/archiva-1.0.x/archiva-base/archiva-proxy/src/test/repositories/proxied2/org/apache/maven/test/groups/get-default-layout/maven-metadata.xml b/archiva-1.0.x/archiva-base/archiva-proxy/src/test/repositories/proxied2/org/apache/maven/test/groups/get-default-layout/maven-metadata.xml new file mode 100644 index 000000000..41109859e --- /dev/null +++ b/archiva-1.0.x/archiva-base/archiva-proxy/src/test/repositories/proxied2/org/apache/maven/test/groups/get-default-layout/maven-metadata.xml @@ -0,0 +1,29 @@ + + + + org.apache.maven.test.groups.get-default-layout + + + plugin2 + plugin2-maven-plugin + The plugin2 Plugin + + + diff --git a/archiva-1.0.x/archiva-base/archiva-proxy/src/test/repositories/proxied2/org/apache/maven/test/groups/get-on-multiple-repos/maven-metadata.xml b/archiva-1.0.x/archiva-base/archiva-proxy/src/test/repositories/proxied2/org/apache/maven/test/groups/get-on-multiple-repos/maven-metadata.xml new file mode 100644 index 000000000..b7db006fe --- /dev/null +++ b/archiva-1.0.x/archiva-base/archiva-proxy/src/test/repositories/proxied2/org/apache/maven/test/groups/get-on-multiple-repos/maven-metadata.xml @@ -0,0 +1,34 @@ + + + + org.apache.maven.test.groups.get-on-multiple-repos + + + plugin1 + plugin1-maven-plugin + The plugin1 Plugin + + + plugin2 + plugin2-maven-plugin + The plugin2 Plugin + + + diff --git a/archiva-1.0.x/archiva-base/archiva-repository-layer/src/main/java/org/apache/maven/archiva/repository/metadata/MetadataTools.java b/archiva-1.0.x/archiva-base/archiva-repository-layer/src/main/java/org/apache/maven/archiva/repository/metadata/MetadataTools.java index 960f3d798..35af14277 100644 --- a/archiva-1.0.x/archiva-base/archiva-repository-layer/src/main/java/org/apache/maven/archiva/repository/metadata/MetadataTools.java +++ b/archiva-1.0.x/archiva-base/archiva-repository-layer/src/main/java/org/apache/maven/archiva/repository/metadata/MetadataTools.java @@ -30,6 +30,7 @@ import org.apache.maven.archiva.configuration.FileTypes; import org.apache.maven.archiva.configuration.ProxyConnectorConfiguration; import org.apache.maven.archiva.model.ArchivaRepositoryMetadata; import org.apache.maven.archiva.model.ArtifactReference; +import org.apache.maven.archiva.model.Plugin; import org.apache.maven.archiva.model.ProjectReference; import org.apache.maven.archiva.model.SnapshotVersion; import org.apache.maven.archiva.model.VersionedReference; @@ -56,6 +57,7 @@ import java.util.Date; import java.util.HashMap; import java.util.HashSet; import java.util.Iterator; +import java.util.LinkedHashSet; import java.util.List; import java.util.Map; import java.util.Set; @@ -394,14 +396,16 @@ public class MetadataTools } /** - * Update the metadata to represent the all versions of - * the provided groupId:artifactId project reference, + * Update the metadata to represent the all versions/plugins of + * the provided groupId:artifactId project or group reference, * based off of information present in the repository, * the maven-metadata.xml files, and the proxy/repository specific * metadata file contents. * + * We must treat this as a group or a project metadata file as there is no way to know in advance + * * @param managedRepository the managed repository where the metadata is kept. - * @param reference the versioned referencfe to update. + * @param reference the reference to update. * @throws LayoutException * @throws RepositoryMetadataException * @throws IOException @@ -421,6 +425,19 @@ public class MetadataTools // Gather up all versions found in the managed repository. Set allVersions = managedRepository.getVersions( reference ); + // Gather up all plugins found in the managed repository. + // TODO: do we know this information instead? +// Set allPlugins = managedRepository.getPlugins( reference ); + Set allPlugins; + if ( metadataFile.exists() ) + { + allPlugins = new LinkedHashSet( RepositoryMetadataReader.read( metadataFile ).getPlugins() ); + } + else + { + allPlugins = new LinkedHashSet(); + } + // Does this repository have a set of remote proxied repositories? Set proxiedRepoIds = this.proxies.get( managedRepository.getId() ); @@ -436,6 +453,7 @@ public class MetadataTools if ( proxyMetadata != null ) { allVersions.addAll( proxyMetadata.getAvailableVersions() ); + allPlugins.addAll( proxyMetadata.getPlugins() ); long proxyLastUpdated = getLastUpdated( proxyMetadata ); lastUpdated = Math.max( lastUpdated, proxyLastUpdated ); @@ -443,47 +461,55 @@ public class MetadataTools } } - if ( allVersions.size() == 0 ) + if ( !allVersions.isEmpty() ) { - throw new IOException( "No versions found for reference." ); - } - - // Sort the versions - List sortedVersions = new ArrayList( allVersions ); - Collections.sort( sortedVersions, VersionComparator.getInstance() ); + // Sort the versions + List sortedVersions = new ArrayList( allVersions ); + Collections.sort( sortedVersions, VersionComparator.getInstance() ); - // Split the versions into released and snapshots. - List releasedVersions = new ArrayList(); - List snapshotVersions = new ArrayList(); + // Split the versions into released and snapshots. + List releasedVersions = new ArrayList(); + List snapshotVersions = new ArrayList(); - for ( String version : sortedVersions ) - { - if ( VersionUtil.isSnapshot( version ) ) + for ( String version : sortedVersions ) { - snapshotVersions.add( version ); + if ( VersionUtil.isSnapshot( version ) ) + { + snapshotVersions.add( version ); + } + else + { + releasedVersions.add( version ); + } } - else + + Collections.sort( releasedVersions, VersionComparator.getInstance() ); + Collections.sort( snapshotVersions, VersionComparator.getInstance() ); + + String latestVersion = sortedVersions.get( sortedVersions.size() - 1 ); + String releaseVersion = null; + + if ( CollectionUtils.isNotEmpty( releasedVersions ) ) { - releasedVersions.add( version ); + releaseVersion = releasedVersions.get( releasedVersions.size() - 1 ); } - } - - Collections.sort( releasedVersions, VersionComparator.getInstance() ); - Collections.sort( snapshotVersions, VersionComparator.getInstance() ); - String latestVersion = sortedVersions.get( sortedVersions.size() - 1 ); - String releaseVersion = null; + // Add the versions to the metadata model. + metadata.setAvailableVersions( sortedVersions ); - if ( CollectionUtils.isNotEmpty( releasedVersions ) ) - { - releaseVersion = releasedVersions.get( releasedVersions.size() - 1 ); + metadata.setLatestVersion( latestVersion ); + metadata.setReleasedVersion( releaseVersion ); } + else + { + // Add the plugins to the metadata model. + metadata.setPlugins( new ArrayList( allPlugins ) ); - // Add the versions to the metadata model. - metadata.setAvailableVersions( sortedVersions ); + // artifact ID was actually the last part of the group + metadata.setGroupId( metadata.getGroupId() + "." + metadata.getArtifactId() ); + metadata.setArtifactId( null ); + } - metadata.setLatestVersion( latestVersion ); - metadata.setReleasedVersion( releaseVersion ); if ( lastUpdated > 0 ) { metadata.setLastUpdatedTimestamp( toLastUpdatedDate( lastUpdated ) ); diff --git a/archiva-1.0.x/archiva-base/archiva-repository-layer/src/main/java/org/apache/maven/archiva/repository/metadata/RepositoryMetadataReader.java b/archiva-1.0.x/archiva-base/archiva-repository-layer/src/main/java/org/apache/maven/archiva/repository/metadata/RepositoryMetadataReader.java index 5d24df835..1e18caf86 100644 --- a/archiva-1.0.x/archiva-base/archiva-repository-layer/src/main/java/org/apache/maven/archiva/repository/metadata/RepositoryMetadataReader.java +++ b/archiva-1.0.x/archiva-base/archiva-repository-layer/src/main/java/org/apache/maven/archiva/repository/metadata/RepositoryMetadataReader.java @@ -21,6 +21,7 @@ package org.apache.maven.archiva.repository.metadata; import org.apache.commons.lang.math.NumberUtils; import org.apache.maven.archiva.model.ArchivaRepositoryMetadata; +import org.apache.maven.archiva.model.Plugin; import org.apache.maven.archiva.model.SnapshotVersion; import org.apache.maven.archiva.xml.XMLException; import org.apache.maven.archiva.xml.XMLReader; @@ -78,6 +79,15 @@ public class RepositoryMetadataReader metadata.setSnapshotVersion( snapshot ); } + for ( Element plugin : xml.getElementList( "//metadata/plugins/plugin" ) ) + { + Plugin p = new Plugin(); + p.setPrefix( plugin.elementTextTrim( "prefix" ) ); + p.setArtifactId( plugin.elementTextTrim( "artifactId" ) ); + p.setName( plugin.elementTextTrim( "name" ) ); + metadata.addPlugin( p ); + } + return metadata; } catch ( XMLException e ) diff --git a/archiva-1.0.x/archiva-base/archiva-repository-layer/src/main/java/org/apache/maven/archiva/repository/metadata/RepositoryMetadataWriter.java b/archiva-1.0.x/archiva-base/archiva-repository-layer/src/main/java/org/apache/maven/archiva/repository/metadata/RepositoryMetadataWriter.java index fb99fb235..9b0d1b283 100644 --- a/archiva-1.0.x/archiva-base/archiva-repository-layer/src/main/java/org/apache/maven/archiva/repository/metadata/RepositoryMetadataWriter.java +++ b/archiva-1.0.x/archiva-base/archiva-repository-layer/src/main/java/org/apache/maven/archiva/repository/metadata/RepositoryMetadataWriter.java @@ -23,6 +23,7 @@ import org.apache.commons.collections.CollectionUtils; import org.apache.commons.io.IOUtils; import org.apache.commons.lang.StringUtils; import org.apache.maven.archiva.model.ArchivaRepositoryMetadata; +import org.apache.maven.archiva.model.Plugin; import org.apache.maven.archiva.xml.XMLException; import org.apache.maven.archiva.xml.XMLWriter; import org.dom4j.Document; @@ -34,6 +35,7 @@ import java.io.FileWriter; import java.io.IOException; import java.io.Writer; import java.util.Iterator; +import java.util.List; /** * RepositoryMetadataWriter @@ -73,9 +75,21 @@ public class RepositoryMetadataWriter doc.setRootElement( root ); root.addElement( "groupId" ).setText( metadata.getGroupId() ); - root.addElement( "artifactId" ).setText( metadata.getArtifactId() ); + addOptionalElementText( root, "artifactId", metadata.getArtifactId() ); addOptionalElementText( root, "version", metadata.getVersion() ); + if ( CollectionUtils.isNotEmpty( metadata.getPlugins() ) ) + { + Element plugins = root.addElement( "plugins" ); + for ( Plugin plugin : (List)metadata.getPlugins() ) + { + Element p = plugins.addElement( "plugin" ); + p.addElement( "prefix" ).setText( plugin.getPrefix() ); + p.addElement( "artifactId" ).setText( plugin.getArtifactId() ); + addOptionalElementText( p, "name", plugin.getName() ); + } + } + if ( CollectionUtils.isNotEmpty( metadata.getAvailableVersions() ) || StringUtils.isNotBlank( metadata.getReleasedVersion() ) || StringUtils.isNotBlank( metadata.getLatestVersion() ) diff --git a/archiva-1.0.x/archiva-base/archiva-repository-layer/src/test/java/org/apache/maven/archiva/repository/metadata/MetadataToolsTest.java b/archiva-1.0.x/archiva-base/archiva-repository-layer/src/test/java/org/apache/maven/archiva/repository/metadata/MetadataToolsTest.java index 223238da2..892cbe748 100644 --- a/archiva-1.0.x/archiva-base/archiva-repository-layer/src/test/java/org/apache/maven/archiva/repository/metadata/MetadataToolsTest.java +++ b/archiva-1.0.x/archiva-base/archiva-repository-layer/src/test/java/org/apache/maven/archiva/repository/metadata/MetadataToolsTest.java @@ -37,6 +37,7 @@ import org.custommonkey.xmlunit.DetailedDiff; import org.custommonkey.xmlunit.Diff; import org.xml.sax.SAXException; +import javax.xml.parsers.ParserConfigurationException; import java.io.File; import java.io.IOException; import java.util.ArrayList; @@ -44,8 +45,6 @@ import java.util.Collections; import java.util.List; import java.util.Set; -import javax.xml.parsers.ParserConfigurationException; - /** * MetadataToolsTest * @@ -114,19 +113,20 @@ public class MetadataToolsTest assertMetadataPath( "commons-lang/commons-lang/maven-metadata-central.xml", convertedName ); } - public void testUpdateProjectBadArtifact() - throws Exception - { - try - { - assertUpdatedProjectMetadata( "bad_artifact", null ); - fail( "Should have thrown an IOException on a bad artifact." ); - } - catch ( IOException e ) - { - // Expected path - } - } + // TODO: replace with group tests +// public void testUpdateProjectBadArtifact() +// throws Exception +// { +// try +// { +// assertUpdatedProjectMetadata( "bad_artifact", null ); +// fail( "Should have thrown an IOException on a bad artifact." ); +// } +// catch ( IOException e ) +// { +// // Expected path +// } +// } public void testUpdateProjectMissingMultipleVersions() throws Exception diff --git a/archiva-1.0.x/archiva-web/archiva-webapp/src/test/java/org/apache/maven/archiva/web/repository/AbstractRepositoryServletProxiedMetadataTestCase.java b/archiva-1.0.x/archiva-web/archiva-webapp/src/test/java/org/apache/maven/archiva/web/repository/AbstractRepositoryServletProxiedMetadataTestCase.java index 1ad6e20fc..b35de9fdc 100644 --- a/archiva-1.0.x/archiva-web/archiva-webapp/src/test/java/org/apache/maven/archiva/web/repository/AbstractRepositoryServletProxiedMetadataTestCase.java +++ b/archiva-1.0.x/archiva-web/archiva-webapp/src/test/java/org/apache/maven/archiva/web/repository/AbstractRepositoryServletProxiedMetadataTestCase.java @@ -23,7 +23,6 @@ import com.meterware.httpunit.GetMethodWebRequest; import com.meterware.httpunit.HttpUnitOptions; import com.meterware.httpunit.WebRequest; import com.meterware.httpunit.WebResponse; - import org.apache.commons.lang.ArrayUtils; import org.apache.commons.lang.StringUtils; import org.custommonkey.xmlunit.DetailedDiff; @@ -145,6 +144,34 @@ public abstract class AbstractRepositoryServletProxiedMetadataTestCase return buf.toString(); } + protected String createGroupMetadata( String groupId, String[] plugins ) + { + StringBuffer buf = new StringBuffer(); + + buf.append( "\n\n" ); + buf.append( "\n" ); + buf.append( " " ).append( groupId ).append( "\n" ); + + boolean hasPlugins = !ArrayUtils.isEmpty( plugins ); + + if ( hasPlugins ) + { + buf.append( " \n" ); + for ( String plugin : plugins ) + { + buf.append( " \n" ); + buf.append( " " ).append( plugin ).append( "\n" ); + buf.append( " " ).append( plugin + "-maven-plugin" ).append( "\n" ); + buf.append( " " ).append( "The " + plugin + " Plugin" ).append( "\n" ); + buf.append( " \n" ); + } + buf.append( " \n" ); + } + buf.append( "" ); + + return buf.toString(); + } + protected void setupPrivateSnapshotsRemoteRepo() throws Exception { diff --git a/archiva-1.0.x/archiva-web/archiva-webapp/src/test/java/org/apache/maven/archiva/web/repository/RepositoryServletNoProxyMetadataTest.java b/archiva-1.0.x/archiva-web/archiva-webapp/src/test/java/org/apache/maven/archiva/web/repository/RepositoryServletNoProxyMetadataTest.java index 2db6fa32e..15df75479 100644 --- a/archiva-1.0.x/archiva-web/archiva-webapp/src/test/java/org/apache/maven/archiva/web/repository/RepositoryServletNoProxyMetadataTest.java +++ b/archiva-1.0.x/archiva-web/archiva-webapp/src/test/java/org/apache/maven/archiva/web/repository/RepositoryServletNoProxyMetadataTest.java @@ -22,7 +22,6 @@ package org.apache.maven.archiva.web.repository; import com.meterware.httpunit.GetMethodWebRequest; import com.meterware.httpunit.WebRequest; import com.meterware.httpunit.WebResponse; - import org.apache.commons.io.FileUtils; import java.io.File; @@ -72,6 +71,24 @@ public class RepositoryServletNoProxyMetadataTest assertEquals( "Expected file contents", expectedMetadataContents, response.getText() ); } + public void testGetGroupMetadataDefaultLayout() + throws Exception + { + String commonsLangMetadata = "commons-lang/maven-metadata.xml"; + String expectedMetadataContents = "metadata-for-commons-lang-group"; + + File checksumFile = new File( repoRootInternal, commonsLangMetadata ); + checksumFile.getParentFile().mkdirs(); + + FileUtils.writeStringToFile( checksumFile, expectedMetadataContents, null ); + + WebRequest request = new GetMethodWebRequest( "http://machine.com/repository/internal/" + commonsLangMetadata ); + WebResponse response = sc.getResponse( request ); + assertResponseOK( response ); + + assertEquals( "Expected file contents", expectedMetadataContents, response.getText() ); + } + public void testGetSnapshotVersionMetadataDefaultLayout() throws Exception { diff --git a/archiva-1.0.x/archiva-web/archiva-webapp/src/test/java/org/apache/maven/archiva/web/repository/RepositoryServletNoProxyTest.java b/archiva-1.0.x/archiva-web/archiva-webapp/src/test/java/org/apache/maven/archiva/web/repository/RepositoryServletNoProxyTest.java index 4e01fe487..3222c01b3 100644 --- a/archiva-1.0.x/archiva-web/archiva-webapp/src/test/java/org/apache/maven/archiva/web/repository/RepositoryServletNoProxyTest.java +++ b/archiva-1.0.x/archiva-web/archiva-webapp/src/test/java/org/apache/maven/archiva/web/repository/RepositoryServletNoProxyTest.java @@ -22,7 +22,6 @@ package org.apache.maven.archiva.web.repository; import com.meterware.httpunit.GetMethodWebRequest; import com.meterware.httpunit.WebRequest; import com.meterware.httpunit.WebResponse; - import org.apache.commons.io.FileUtils; import java.io.File; @@ -107,6 +106,24 @@ public class RepositoryServletNoProxyTest assertEquals( "Expected file contents", expectedMetadataContents, response.getText() ); } + public void testGetNoProxyGroupMetadataDefaultLayout() + throws Exception + { + String commonsLangMetadata = "commons-lang/maven-metadata.xml"; + String expectedMetadataContents = "dummy-group-metadata"; + + File metadataFile = new File( repoRootInternal, commonsLangMetadata ); + metadataFile.getParentFile().mkdirs(); + + FileUtils.writeStringToFile( metadataFile, expectedMetadataContents, null ); + + WebRequest request = new GetMethodWebRequest( "http://machine.com/repository/internal/" + commonsLangMetadata ); + WebResponse response = sc.getResponse( request ); + assertResponseOK( response ); + + assertEquals( "Expected file contents", expectedMetadataContents, response.getText() ); + } + public void testGetNoProxyArtifactDefaultLayout() throws Exception { diff --git a/archiva-1.0.x/archiva-web/archiva-webapp/src/test/java/org/apache/maven/archiva/web/repository/RepositoryServletProxiedMetadataLocalOnlyTest.java b/archiva-1.0.x/archiva-web/archiva-webapp/src/test/java/org/apache/maven/archiva/web/repository/RepositoryServletProxiedMetadataLocalOnlyTest.java index c04fbf0f8..883f38252 100644 --- a/archiva-1.0.x/archiva-web/archiva-webapp/src/test/java/org/apache/maven/archiva/web/repository/RepositoryServletProxiedMetadataLocalOnlyTest.java +++ b/archiva-1.0.x/archiva-web/archiva-webapp/src/test/java/org/apache/maven/archiva/web/repository/RepositoryServletProxiedMetadataLocalOnlyTest.java @@ -95,4 +95,24 @@ public class RepositoryServletProxiedMetadataLocalOnlyTest // --- Verification assertExpectedMetadata( expectedMetadata, actualMetadata ); } + + public void testGetProxiedGroupMetadataLocalOnly() + throws Exception + { + // --- Setup + setupSnapshotsRemoteRepo(); + setupPrivateSnapshotsRemoteRepo(); + setupCleanInternalRepo(); + + String path = "org/apache/archiva/maven-metadata.xml"; + String expectedMetadata = createGroupMetadata( "org.apache.archiva", new String[] { "archivatest-maven-plugin" } ); + + populateRepo( repoRootInternal, path, expectedMetadata ); + + // --- Execution + String actualMetadata = requestMetadataOK( path ); + + // --- Verification + assertExpectedMetadata( expectedMetadata, actualMetadata ); + } } diff --git a/archiva-1.0.x/archiva-web/archiva-webapp/src/test/java/org/apache/maven/archiva/web/repository/RepositoryServletProxiedMetadataRemoteOnlyTest.java b/archiva-1.0.x/archiva-web/archiva-webapp/src/test/java/org/apache/maven/archiva/web/repository/RepositoryServletProxiedMetadataRemoteOnlyTest.java index 63eaf2416..f7db72da9 100644 --- a/archiva-1.0.x/archiva-web/archiva-webapp/src/test/java/org/apache/maven/archiva/web/repository/RepositoryServletProxiedMetadataRemoteOnlyTest.java +++ b/archiva-1.0.x/archiva-web/archiva-webapp/src/test/java/org/apache/maven/archiva/web/repository/RepositoryServletProxiedMetadataRemoteOnlyTest.java @@ -139,4 +139,28 @@ public class RepositoryServletProxiedMetadataRemoteOnlyTest // --- Verification assertExpectedMetadata( expectedMetadata, actualMetadata ); } + + public void testGetProxiedGroupMetadataRemoteOnly() + throws Exception + { + // --- Setup + setupSnapshotsRemoteRepo(); + setupPrivateSnapshotsRemoteRepo(); + setupCleanInternalRepo(); + + String path = "org/apache/archiva/maven-metadata.xml"; + String expectedMetadata = createGroupMetadata( "org.apache.archiva", new String[] { "archivatest-maven-plugin" } ); + + File managedFile = populateRepo( remoteSnapshots, path, expectedMetadata ); + + setupConnector( REPOID_INTERNAL, remoteSnapshots ); + setupConnector( REPOID_INTERNAL, remotePrivateSnapshots ); + saveConfiguration(); + + // --- Execution + String actualMetadata = requestMetadataOK( path ); + + // --- Verification + assertExpectedMetadata( expectedMetadata, actualMetadata ); + } } -- 2.39.5