<multiplicity>1</multiplicity>
</association>
</field>
+ <field>
+ <name>plugins</name>
+ <identifier>false</identifier>
+ <version>1.0.0+</version>
+ <required>false</required>
+ <description>
+ The available plugins.
+ </description>
+ <association stash.part="true"
+ jpox.join="false">
+ <type>Plugin</type>
+ <multiplicity>*</multiplicity>
+ </association>
+ </field>
<field>
<name>availableVersions</name>
<identifier>false</identifier>
</codeSegments>
</class>
+ <class stash.storable="true"
+ jpox.not-persisted-fields="modelEncoding"
+ jpox.table="REPOSITORY_METADATA_PLUGINS">
+ <name>Plugin</name>
+ <description>The Plugin</description>
+ <version>1.0.0+</version>
+ <fields>
+ <field stash.maxSize="20"
+ jpox.column="PLUGIN_PREFIX">
+ <name>prefix</name>
+ <type>String</type>
+ <identifier>false</identifier>
+ <required>true</required>
+ <description>
+ The prefix for a plugin
+ </description>
+ </field>
+ <field
+ jpox.column="PLUGIN_ARTIFACT_ID">
+ <name>artifactId</name>
+ <type>String</type>
+ <identifier>true</identifier>
+ <required>true</required>
+ <description>
+ The artifactId for a plugin
+ </description>
+ </field>
+ <field jpox.column="PLUGIN_NAME">
+ <name>name</name>
+ <type>String</type>
+ <identifier>false</identifier>
+ <required>true</required>
+ <description>
+ The name for a plugin
+ </description>
+ </field>
+ </fields>
+ </class>
+
<!-- _______________________________________________________________
____ __
import org.apache.commons.lang.StringUtils;
import org.apache.maven.archiva.common.utils.VersionUtil;
import org.apache.maven.archiva.model.ArchivaRepositoryMetadata;
+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;
wagonMockControl.replay();
- assertFetchProject( requestedResource );
+ assertFetchProjectOrGroup( requestedResource );
wagonMockControl.verify();
assertResourceNotFound( requestedResource );
// No proxy setup, nothing fetched, failure expected.
- assertFetchProjectFailed( requestedResource );
+ assertFetchProjectOrGroupFailed( requestedResource );
// No local artifactId, and no fetch, should equal no metadata file downloaded / created / updated.
assertResourceNotFound( requestedResource );
assertResourceExists( requestedResource );
// No proxy setup, nothing fetched from remote, but local exists.
- assertFetchProject( requestedResource );
+ assertFetchProjectOrGroup( requestedResource );
// Nothing fetched. Should only contain contents of what is in the repository.
// A metadata update is not performed in this use case. Local metadata content is only
assertNoRepoMetadata( ID_PROXIED2, requestedResource );
// Two proxies setup, metadata fetched from both remotes.
- assertFetchProject( requestedResource );
+ assertFetchProjectOrGroup( requestedResource );
// Nothing fetched. Should only contain contents of what is in the repository.
assertProjectMetadataContents( requestedResource, new String[] { "1.0", "1.0.1" }, "1.0.1", "1.0.1" );
assertNoRepoMetadata( ID_PROXIED2, requestedResource );
// Two proxies setup, nothing fetched from remotes, local does not exist.
- assertFetchProjectFailed( requestedResource );
+ assertFetchProjectOrGroupFailed( requestedResource );
// Nothing fetched. Nothing should exist.
assertResourceNotFound( requestedResource );
assertNoRepoMetadata( ID_PROXIED1, requestedResource );
// One proxy setup, metadata fetched from remote, local does not exist.
- assertFetchProject( requestedResource );
+ assertFetchProjectOrGroup( requestedResource );
// Remote fetched. Local created/updated.
assertProjectMetadataContents( requestedResource, new String[] { "1.0.5" }, "1.0.5", "1.0.5" );
assertNoRepoMetadata( ID_PROXIED2, requestedResource );
// Two proxies setup, metadata fetched from both remotes.
- assertFetchProject( requestedResource );
+ assertFetchProjectOrGroup( requestedResource );
// metadata fetched from both repos, and merged with local version.
assertProjectMetadataContents( requestedResource, new String[] { "1.0", "1.0.1", "2.0" }, "2.0", "2.0" );
assertNoRepoMetadata( ID_PROXIED2, requestedResource );
// Two proxies setup, metadata fetch from remotes fail (because they dont exist).
- assertFetchProject( requestedResource );
+ assertFetchProjectOrGroup( requestedResource );
// metadata not fetched from both repos, and local version exists.
// Since there was no updated metadata content from a remote/proxy, a metadata update on
assertNoRepoMetadata( ID_PROXIED1, requestedResource );
// One proxy setup, metadata fetched from remote, local exists.
- assertFetchProject( requestedResource );
+ assertFetchProjectOrGroup( requestedResource );
// Remote fetched. Local updated.
assertProjectMetadataContents( requestedResource, new String[] { "1.0.8", "1.0.22", "2.0" }, "2.0", "2.0" );
assertResourceNotFound( requestedResource );
- assertFetchProjectFailed( requestedResource );
+ assertFetchProjectOrGroupFailed( requestedResource );
assertResourceNotFound( requestedResource );
assertNoRepoMetadata( ID_PROXIED1, requestedResource );
assertRepoSnapshotMetadataContents( ID_PROXIED1, requestedResource, "20050831", "101112", 1 );
}
+ public void testGetGroupMetadataNotProxiedNotLocal()
+ throws Exception
+ {
+ // The artifactId "get-default-metadata-nonexistant" does not exist (intentionally).
+ String requestedResource = "org/apache/maven/test/groups/get-default-metadata-nonexistant/maven-metadata.xml";
+ setupTestableManagedRepository( requestedResource );
+
+ assertResourceNotFound( requestedResource );
+
+ // No proxy setup, nothing fetched, failure expected.
+ assertFetchProjectOrGroupFailed( requestedResource );
+
+ // No local artifactId, and no fetch, should equal no metadata file downloaded / created / updated.
+ assertResourceNotFound( requestedResource );
+ }
+
+ public void testGetGroupMetadataNotProxiedOnLocal()
+ throws Exception
+ {
+ // Project metadata that exists and has multiple versions
+ String requestedResource = "org/apache/maven/test/groups/get-project-metadata/maven-metadata.xml";
+ setupTestableManagedRepository( requestedResource );
+
+ assertResourceExists( requestedResource );
+
+ // No proxy setup, nothing fetched from remote, but local exists.
+ assertFetchProjectOrGroup( requestedResource );
+
+ // Nothing fetched. Should only contain contents of what is in the repository.
+ // A metadata update is not performed in this use case. Local metadata content is only
+ // updated via the metadata updater consumer.
+ assertGroupMetadataContents( requestedResource, new String[] { "plugin1" } );
+ }
+
+ public void testGetGroupMetadataProxiedNotLocalMultipleRemotes()
+ throws Exception
+ {
+ // Project metadata that does not exist locally, but has multiple versions in remote repos
+ String requestedResource = "org/apache/maven/test/groups/get-default-layout/maven-metadata.xml";
+ setupTestableManagedRepository( requestedResource );
+
+ // Configure Connector (usually done within archiva.xml configuration)
+ saveConnector( ID_DEFAULT_MANAGED, ID_PROXIED1, ChecksumPolicy.FIX, ReleasesPolicy.ALWAYS,
+ SnapshotsPolicy.ALWAYS, CachedFailuresPolicy.NO );
+ saveConnector( ID_DEFAULT_MANAGED, ID_PROXIED2, ChecksumPolicy.FIX, ReleasesPolicy.ALWAYS,
+ SnapshotsPolicy.ALWAYS, CachedFailuresPolicy.NO );
+
+ assertResourceNotFound( requestedResource );
+ assertNoRepoMetadata( ID_PROXIED1, requestedResource );
+ assertNoRepoMetadata( ID_PROXIED2, requestedResource );
+
+ // Two proxies setup, metadata fetched from both remotes.
+ assertFetchProjectOrGroup( requestedResource );
+
+ // Nothing fetched. Should only contain contents of what is in the repository.
+ assertGroupMetadataContents( requestedResource, new String[] { "plugin2", "plugin1" } );
+ assertRepoGroupMetadataContents( ID_PROXIED1, requestedResource, new String[] { "plugin1" } );
+ assertRepoGroupMetadataContents( ID_PROXIED2, requestedResource, new String[] { "plugin2" } );
+ }
+
+ public void testGetGroupsMetadataProxiedNotLocalNotRemote()
+ throws Exception
+ {
+ // Non-existant project metadata that does not exist locally and doesn't exist on remotes.
+ String requestedResource = "org/apache/maven/test/groups/get-bogus-artifact/maven-metadata.xml";
+ setupTestableManagedRepository( requestedResource );
+
+ // Configure Connector (usually done within archiva.xml configuration)
+ saveConnector( ID_DEFAULT_MANAGED, ID_PROXIED1, ChecksumPolicy.FIX, ReleasesPolicy.ALWAYS,
+ SnapshotsPolicy.ALWAYS, CachedFailuresPolicy.NO );
+ saveConnector( ID_DEFAULT_MANAGED, ID_PROXIED2, ChecksumPolicy.FIX, ReleasesPolicy.ALWAYS,
+ SnapshotsPolicy.ALWAYS, CachedFailuresPolicy.NO );
+
+ assertResourceNotFound( requestedResource );
+ assertNoRepoMetadata( ID_PROXIED1, requestedResource );
+ assertNoRepoMetadata( ID_PROXIED2, requestedResource );
+
+ // Two proxies setup, nothing fetched from remotes, local does not exist.
+ assertFetchProjectOrGroupFailed( requestedResource );
+
+ // Nothing fetched. Nothing should exist.
+ assertResourceNotFound( requestedResource );
+ assertNoRepoMetadata( ID_PROXIED1, requestedResource );
+ assertNoRepoMetadata( ID_PROXIED2, requestedResource );
+ }
+
+ public void testGetGroupMetadataProxiedNotLocalOnRemote()
+ throws Exception
+ {
+ // New project metadata that does not exist locally but exists on remote.
+ String requestedResource = "org/apache/maven/test/groups/get-found-in-proxy/maven-metadata.xml";
+ setupTestableManagedRepository( requestedResource );
+
+ // Configure Connector (usually done within archiva.xml configuration)
+ saveConnector( ID_DEFAULT_MANAGED, ID_PROXIED1, ChecksumPolicy.FIX, ReleasesPolicy.ALWAYS,
+ SnapshotsPolicy.ALWAYS, CachedFailuresPolicy.NO );
+
+ assertResourceNotFound( requestedResource );
+ assertNoRepoMetadata( ID_PROXIED1, requestedResource );
+
+ // One proxy setup, metadata fetched from remote, local does not exist.
+ assertFetchProjectOrGroup( requestedResource );
+
+ // Remote fetched. Local created/updated.
+ assertGroupMetadataContents( requestedResource, new String[] { "plugin3" } );
+ assertRepoGroupMetadataContents( ID_PROXIED1, requestedResource, new String[] { "plugin3" } );
+ }
+
+ public void testGetGroupMetadataProxiedOnLocalMultipleRemote()
+ throws Exception
+ {
+ // Project metadata that exist locally, and has multiple versions in remote repos
+ String requestedResource = "org/apache/maven/test/groups/get-on-multiple-repos/maven-metadata.xml";
+ setupTestableManagedRepository( requestedResource );
+
+ // Configure Connector (usually done within archiva.xml configuration)
+ saveConnector( ID_DEFAULT_MANAGED, ID_PROXIED1, ChecksumPolicy.FIX, ReleasesPolicy.ALWAYS,
+ SnapshotsPolicy.ALWAYS, CachedFailuresPolicy.NO );
+ saveConnector( ID_DEFAULT_MANAGED, ID_PROXIED2, ChecksumPolicy.FIX, ReleasesPolicy.ALWAYS,
+ SnapshotsPolicy.ALWAYS, CachedFailuresPolicy.NO );
+
+ assertGroupMetadataContents( requestedResource, new String[] { "plugin1" } );
+ assertNoRepoMetadata( ID_PROXIED1, requestedResource );
+ assertNoRepoMetadata( ID_PROXIED2, requestedResource );
+
+ // Two proxies setup, metadata fetched from both remotes.
+ assertFetchProjectOrGroup( requestedResource );
+
+ // metadata fetched from both repos, and merged with local version.
+ assertGroupMetadataContents( requestedResource, new String[] { "plugin1", "plugin2", "plugin4" } );
+ assertRepoGroupMetadataContents( ID_PROXIED1, requestedResource, new String[] { "plugin1", "plugin4" } );
+ assertRepoGroupMetadataContents( ID_PROXIED2, requestedResource, new String[] { "plugin1", "plugin2" } );
+ }
+
+ public void testGetGroupMetadataProxiedOnLocalNotRemote()
+ throws Exception
+ {
+ // Project metadata that exist locally, and does not exist in remote repos.
+ String requestedResource = "org/apache/maven/test/groups/get-not-on-remotes/maven-metadata.xml";
+ setupTestableManagedRepository( requestedResource );
+
+ // Configure Connector (usually done within archiva.xml configuration)
+ saveConnector( ID_DEFAULT_MANAGED, ID_PROXIED1, ChecksumPolicy.FIX, ReleasesPolicy.ALWAYS,
+ SnapshotsPolicy.ALWAYS, CachedFailuresPolicy.NO );
+ saveConnector( ID_DEFAULT_MANAGED, ID_PROXIED2, ChecksumPolicy.FIX, ReleasesPolicy.ALWAYS,
+ SnapshotsPolicy.ALWAYS, CachedFailuresPolicy.NO );
+
+ assertGroupMetadataContents( requestedResource, new String[] { "plugin5" } );
+ assertNoRepoMetadata( ID_PROXIED1, requestedResource );
+ assertNoRepoMetadata( ID_PROXIED2, requestedResource );
+
+ // Two proxies setup, metadata fetch from remotes fail (because they dont exist).
+ assertFetchProjectOrGroup( requestedResource );
+
+ // metadata not fetched from both repos, and local version exists.
+ // Since there was no updated metadata content from a remote/proxy, a metadata update on
+ // the local file never ran. Local only updates are performed via the metadata updater consumer.
+ assertGroupMetadataContents( requestedResource, new String[] { "plugin5" } );
+ assertNoRepoMetadata( ID_PROXIED1, requestedResource );
+ assertNoRepoMetadata( ID_PROXIED2, requestedResource );
+ }
+
+ public void testGetGroupMetadataProxiedOnLocalOnRemote()
+ throws Exception
+ {
+ // Project metadata that exist locally and exists on remote.
+ String requestedResource = "org/apache/maven/test/groups/get-on-local-on-remote/maven-metadata.xml";
+ setupTestableManagedRepository( requestedResource );
+
+ // Configure Connector (usually done within archiva.xml configuration)
+ saveConnector( ID_DEFAULT_MANAGED, ID_PROXIED1, ChecksumPolicy.FIX, ReleasesPolicy.ALWAYS,
+ SnapshotsPolicy.ALWAYS, CachedFailuresPolicy.NO );
+
+ assertGroupMetadataContents( requestedResource, new String[] { "plugin6", "plugin7" } );
+ assertNoRepoMetadata( ID_PROXIED1, requestedResource );
+
+ // One proxy setup, metadata fetched from remote, local exists.
+ assertFetchProjectOrGroup( requestedResource );
+
+ // Remote fetched. Local updated.
+ assertGroupMetadataContents( requestedResource, new String[] { "plugin6", "plugin7", "plugin4" } );
+ assertRepoGroupMetadataContents( ID_PROXIED1, requestedResource, new String[] { "plugin7", "plugin4" } );
+ }
+
/**
* Transfer the metadata file.
*
* @param requestedResource the requested resource
* @throws Exception
*/
- private void assertFetchProject( String requestedResource )
+ private void assertFetchProjectOrGroup( String requestedResource )
throws Exception
{
File expectedFile = new File( managedDefaultDir, requestedResource );
* @param requestedResource the requested resource
* @throws Exception
*/
- private void assertFetchProjectFailed( String requestedResource )
+ private void assertFetchProjectOrGroupFailed( String requestedResource )
throws Exception
{
File expectedFile = new File( managedDefaultDir, requestedResource );
assertFalse( "Repo specific metadata should not exist: " + actualFile, actualFile.exists() );
}
+ private void assertGroupMetadataContents( String requestedResource, String expectedPlugins[] )
+ throws Exception
+ {
+ File actualFile = new File( managedDefaultDir, requestedResource );
+ assertTrue( "Snapshot Metadata should exist: " + requestedResource, actualFile.exists() );
+
+ ProjectReference actualMetadata = createGroupReference( requestedResource );
+
+ assertGroupMetadata( actualFile, actualMetadata, expectedPlugins );
+ }
+
+ private ProjectReference createGroupReference( String requestedResource )
+ throws RepositoryMetadataException
+ {
+ ProjectReference projectReference = createProjectReference( requestedResource );
+ projectReference.setGroupId( projectReference.getGroupId() + "." + projectReference.getArtifactId() );
+ projectReference.setArtifactId( null );
+ return projectReference;
+ }
+
+ private void assertRepoGroupMetadataContents( String proxiedRepoId, String requestedResource,
+ String expectedPlugins[] )
+ throws Exception
+ {
+ String proxiedFile = metadataTools.getRepositorySpecificName( proxiedRepoId, requestedResource );
+
+ File actualFile = new File( managedDefaultDir, proxiedFile );
+ assertTrue( "Repo Specific Group Metadata should exist: " + requestedResource, actualFile.exists() );
+
+ ProjectReference actualMetadata = createGroupReference( requestedResource );
+
+ assertGroupMetadata( actualFile, actualMetadata, expectedPlugins );
+ }
+
+ private void assertGroupMetadata( File actualFile, ProjectReference actualMetadata, String expectedPlugins[] )
+ throws Exception
+ {
+ // Build expected metadata XML
+ StringWriter expectedMetadataXml = new StringWriter();
+ ArchivaRepositoryMetadata m = new ArchivaRepositoryMetadata();
+ m.setGroupId( actualMetadata.getGroupId() );
+
+ for ( String pluginId : expectedPlugins )
+ {
+ Plugin p = new Plugin();
+ p.setPrefix( pluginId );
+ p.setArtifactId( pluginId + "-maven-plugin" );
+ p.setName( "The " + pluginId + " Plugin" );
+ m.getPlugins().add( p );
+ }
+
+ m.setModelEncoding( null );
+ RepositoryMetadataWriter.write( m, expectedMetadataXml );
+
+ // Compare the file to the actual contents.
+ assertMetadataEquals( expectedMetadataXml.toString(), actualFile );
+ }
+
/**
* Test for the existance of the requestedResource in the default managed repository, and if it exists,
* does it contain the specified list of expected versions?
--- /dev/null
+<!--
+ ~ 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.
+ -->
+
+<metadata>
+ <groupId>org.apache.maven.test.groups.get-not-on-remotes</groupId>
+ <plugins>
+ <plugin>
+ <prefix>plugin5</prefix>
+ <artifactId>plugin5-maven-plugin</artifactId>
+ <name>The plugin5 Plugin</name>
+ </plugin>
+ </plugins>
+</metadata>
--- /dev/null
+<!--
+ ~ 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.
+ -->
+
+<metadata>
+ <groupId>org.apache.maven.test.groups.get-on-local-on-remote</groupId>
+ <plugins>
+ <plugin>
+ <prefix>plugin6</prefix>
+ <artifactId>plugin6-maven-plugin</artifactId>
+ <name>The plugin6 Plugin</name>
+ </plugin>
+ <plugin>
+ <prefix>plugin7</prefix>
+ <artifactId>plugin7-maven-plugin</artifactId>
+ <name>The plugin7 Plugin</name>
+ </plugin>
+ </plugins>
+</metadata>
--- /dev/null
+<!--
+ ~ 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.
+ -->
+
+<metadata>
+ <groupId>org.apache.maven.test.groups.get-on-multiple-repos</groupId>
+ <plugins>
+ <plugin>
+ <prefix>plugin1</prefix>
+ <artifactId>plugin1-maven-plugin</artifactId>
+ <name>The plugin1 Plugin</name>
+ </plugin>
+ </plugins>
+</metadata>
--- /dev/null
+<!--
+ ~ 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.
+ -->
+
+<metadata>
+ <groupId>org.apache.maven.test.groups.get-project-metadata</groupId>
+ <plugins>
+ <plugin>
+ <prefix>plugin1</prefix>
+ <artifactId>plugin1-maven-plugin</artifactId>
+ <name>The plugin1 Plugin</name>
+ </plugin>
+ </plugins>
+</metadata>
--- /dev/null
+<!--
+ ~ 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.
+ -->
+
+<metadata>
+ <groupId>org.apache.maven.test.groups.get-default-layout</groupId>
+ <plugins>
+ <plugin>
+ <prefix>plugin1</prefix>
+ <artifactId>plugin1-maven-plugin</artifactId>
+ <name>The plugin1 Plugin</name>
+ </plugin>
+ </plugins>
+</metadata>
--- /dev/null
+<!--
+ ~ 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.
+ -->
+
+<metadata>
+ <groupId>org.apache.maven.test.groups.get-found-in-proxy</groupId>
+ <plugins>
+ <plugin>
+ <prefix>plugin3</prefix>
+ <artifactId>plugin3-maven-plugin</artifactId>
+ <name>The plugin3 Plugin</name>
+ </plugin>
+ </plugins>
+</metadata>
--- /dev/null
+<!--
+ ~ 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.
+ -->
+
+<metadata>
+ <groupId>org.apache.maven.test.groups.get-on-local-on-remote</groupId>
+ <plugins>
+ <plugin>
+ <prefix>plugin7</prefix>
+ <artifactId>plugin7-maven-plugin</artifactId>
+ <name>The plugin7 Plugin</name>
+ </plugin>
+ <plugin>
+ <prefix>plugin4</prefix>
+ <artifactId>plugin4-maven-plugin</artifactId>
+ <name>The plugin4 Plugin</name>
+ </plugin>
+ </plugins>
+</metadata>
--- /dev/null
+<!--
+ ~ 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.
+ -->
+
+<metadata>
+ <groupId>org.apache.maven.test.groups.get-on-multiple-repos</groupId>
+ <plugins>
+ <plugin>
+ <prefix>plugin1</prefix>
+ <artifactId>plugin1-maven-plugin</artifactId>
+ <name>The plugin1 Plugin</name>
+ </plugin>
+ <plugin>
+ <prefix>plugin4</prefix>
+ <artifactId>plugin4-maven-plugin</artifactId>
+ <name>The plugin4 Plugin</name>
+ </plugin>
+ </plugins>
+</metadata>
--- /dev/null
+<!--
+ ~ 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.
+ -->
+
+<metadata>
+ <groupId>org.apache.maven.test.groups.get-default-layout</groupId>
+ <plugins>
+ <plugin>
+ <prefix>plugin2</prefix>
+ <artifactId>plugin2-maven-plugin</artifactId>
+ <name>The plugin2 Plugin</name>
+ </plugin>
+ </plugins>
+</metadata>
--- /dev/null
+<!--
+ ~ 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.
+ -->
+
+<metadata>
+ <groupId>org.apache.maven.test.groups.get-on-multiple-repos</groupId>
+ <plugins>
+ <plugin>
+ <prefix>plugin1</prefix>
+ <artifactId>plugin1-maven-plugin</artifactId>
+ <name>The plugin1 Plugin</name>
+ </plugin>
+ <plugin>
+ <prefix>plugin2</prefix>
+ <artifactId>plugin2-maven-plugin</artifactId>
+ <name>The plugin2 Plugin</name>
+ </plugin>
+ </plugins>
+</metadata>
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;
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;
}
/**
- * 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
// Gather up all versions found in the managed repository.
Set<String> allVersions = managedRepository.getVersions( reference );
+ // Gather up all plugins found in the managed repository.
+ // TODO: do we know this information instead?
+// Set<Plugin> allPlugins = managedRepository.getPlugins( reference );
+ Set<Plugin> allPlugins;
+ if ( metadataFile.exists() )
+ {
+ allPlugins = new LinkedHashSet<Plugin>( RepositoryMetadataReader.read( metadataFile ).getPlugins() );
+ }
+ else
+ {
+ allPlugins = new LinkedHashSet<Plugin>();
+ }
+
// Does this repository have a set of remote proxied repositories?
Set<String> proxiedRepoIds = this.proxies.get( managedRepository.getId() );
if ( proxyMetadata != null )
{
allVersions.addAll( proxyMetadata.getAvailableVersions() );
+ allPlugins.addAll( proxyMetadata.getPlugins() );
long proxyLastUpdated = getLastUpdated( proxyMetadata );
lastUpdated = Math.max( lastUpdated, proxyLastUpdated );
}
}
- if ( allVersions.size() == 0 )
+ if ( !allVersions.isEmpty() )
{
- throw new IOException( "No versions found for reference." );
- }
-
- // Sort the versions
- List<String> sortedVersions = new ArrayList<String>( allVersions );
- Collections.sort( sortedVersions, VersionComparator.getInstance() );
+ // Sort the versions
+ List<String> sortedVersions = new ArrayList<String>( allVersions );
+ Collections.sort( sortedVersions, VersionComparator.getInstance() );
- // Split the versions into released and snapshots.
- List<String> releasedVersions = new ArrayList<String>();
- List<String> snapshotVersions = new ArrayList<String>();
+ // Split the versions into released and snapshots.
+ List<String> releasedVersions = new ArrayList<String>();
+ List<String> snapshotVersions = new ArrayList<String>();
- 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<Plugin>( 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 ) );
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;
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 )
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;
import java.io.IOException;
import java.io.Writer;
import java.util.Iterator;
+import java.util.List;
/**
* 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<Plugin>)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() )
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;
import java.util.List;
import java.util.Set;
-import javax.xml.parsers.ParserConfigurationException;
-
/**
* 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
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;
return buf.toString();
}
+ protected String createGroupMetadata( String groupId, String[] plugins )
+ {
+ StringBuffer buf = new StringBuffer();
+
+ buf.append( "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n\n" );
+ buf.append( "<metadata>\n" );
+ buf.append( " <groupId>" ).append( groupId ).append( "</groupId>\n" );
+
+ boolean hasPlugins = !ArrayUtils.isEmpty( plugins );
+
+ if ( hasPlugins )
+ {
+ buf.append( " <plugins>\n" );
+ for ( String plugin : plugins )
+ {
+ buf.append( " <plugin>\n" );
+ buf.append( " <prefix>" ).append( plugin ).append( "</prefix>\n" );
+ buf.append( " <artifactId>" ).append( plugin + "-maven-plugin" ).append( "</artifactId>\n" );
+ buf.append( " <name>" ).append( "The " + plugin + " Plugin" ).append( "</name>\n" );
+ buf.append( " </plugin>\n" );
+ }
+ buf.append( " </plugins>\n" );
+ }
+ buf.append( "</metadata>" );
+
+ return buf.toString();
+ }
+
protected void setupPrivateSnapshotsRemoteRepo()
throws Exception
{
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;
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
{
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;
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
{
// --- 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 );
+ }
}
// --- 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 );
+ }
}