Skip to content

Commit af402d5

Browse files
ruhan1jdcasey
authored andcommitted
Generate metadata for a group containing Maven plugins artifacts (#1207)
1 parent a7cbf21 commit af402d5

3 files changed

Lines changed: 149 additions & 0 deletions

File tree

addons/pkg-maven/common/src/main/java/org/commonjava/indy/pkg/maven/content/MavenMetadataGenerator.java

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
import org.apache.commons.io.IOUtils;
1919
import org.apache.commons.lang.StringUtils;
2020
import org.apache.maven.artifact.repository.metadata.Metadata;
21+
import org.apache.maven.artifact.repository.metadata.Plugin;
2122
import org.apache.maven.artifact.repository.metadata.Versioning;
2223
import org.apache.maven.artifact.repository.metadata.io.xpp3.MetadataXpp3Reader;
2324
import org.apache.maven.artifact.repository.metadata.io.xpp3.MetadataXpp3Writer;
@@ -597,7 +598,12 @@ private Metadata generateGroupMetadata( final Group group, final List<ArtifactSt
597598
if ( versions != null && !versions.isEmpty() )
598599
{
599600
merger.sortVersions( master );
601+
return master;
602+
}
600603

604+
List<Plugin> plugins = master.getPlugins();
605+
if ( plugins != null && !plugins.isEmpty() )
606+
{
601607
return master;
602608
}
603609

Lines changed: 137 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,137 @@
1+
/**
2+
* Copyright (C) 2011-2018 Red Hat, Inc. (https://github.com/Commonjava/indy)
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
package org.commonjava.indy.pkg.maven.content;
17+
18+
import org.apache.commons.io.IOUtils;
19+
import org.commonjava.indy.ftest.core.AbstractIndyFunctionalTest;
20+
import org.commonjava.indy.model.core.Group;
21+
import org.commonjava.indy.model.core.RemoteRepository;
22+
import org.commonjava.test.http.expect.ExpectationServer;
23+
import org.junit.Rule;
24+
import org.junit.Test;
25+
26+
import java.io.InputStream;
27+
28+
import static org.commonjava.indy.pkg.maven.model.MavenPackageTypeDescriptor.MAVEN_PKG_KEY;
29+
import static org.hamcrest.MatcherAssert.assertThat;
30+
import static org.hamcrest.core.IsNull.notNullValue;
31+
32+
/**
33+
* <b>GIVEN:</b>
34+
* GroupId: o.a.maven.plugins
35+
* ArtifactId: maven-antrun-plugin
36+
*
37+
* <li>
38+
* Remote repo A contains paths and content for:
39+
*
40+
* org/foo/plugins/my-plugin/1.0/my-plugin-1.0.pom
41+
* org/foo/plugins/my-plugin/maven-metadata.xml
42+
* org/foo/plugins/maven-metadata.xml
43+
* </li>
44+
* <li>Group G contains A</li>
45+
*
46+
* <br/>
47+
* <b>WHEN:</b>
48+
* <ul>
49+
* <li>Path org/foo/plugins/maven-metadata.xml is requested from A</li>
50+
* <li>Path org/foo/plugins/maven-metadata.xml is requested from G</li>
51+
* </ul>
52+
*
53+
* <br/>
54+
* <b>THEN:</b>
55+
* <ul>
56+
* <li>Indy can get plugins maven-metadata.xml from A and G</li>
57+
* </ul>
58+
*/
59+
public class GroupMetadataForRemoteTest
60+
extends AbstractIndyFunctionalTest
61+
{
62+
@Rule
63+
public ExpectationServer server = new ExpectationServer( "repos" );
64+
65+
private final String REMOTE = "remote-A";
66+
67+
private final String GROUP = "group-G";
68+
69+
private final String pomPath = "org/foo/plugins/my-plugin/1.0/my-plugin-1.0.pom";
70+
71+
private final String metadataPath = "org/foo/plugins/my-plugin/maven-metadata.xml";
72+
73+
private final String metadataPluginsPath = "org/foo/plugins/maven-metadata.xml";
74+
75+
/* @formatter:off */
76+
final String metadataContent = "<metadata>"
77+
+ " <groupId>org.foo.plugins</groupId>"
78+
+ " <artifactId>my-plugin</artifactId>"
79+
+ " <versioning>"
80+
+ " <latest>1.0</latest>"
81+
+ " <release>1.0</release>"
82+
+ " <versions>"
83+
+ " <version>1.0</version>"
84+
+ " </versions>"
85+
+ " </versioning>"
86+
+ "</metadata>";
87+
88+
private final String pomContent = "<project>"
89+
+ " <modelVersion>4.0.0</modelVersion>"
90+
+ " <groupId>org.foo.plugins</groupId>"
91+
+ " <artifactId>my-plugin</artifactId>"
92+
+ " <version>1.0</version>"
93+
+ "</project>";
94+
95+
final String metadataPluginsContent = "<metadata>"
96+
+ "<plugins>"
97+
+ " <plugin>"
98+
+ " <name>My Plugin</name>"
99+
+ " <prefix>mp</prefix>"
100+
+ " <artifactId>my-plugin</artifactId>"
101+
+ " </plugin>"
102+
+ "</plugins>"
103+
+ "</metadata>";
104+
105+
/* @formatter:on */
106+
107+
@Test
108+
public void run() throws Exception
109+
{
110+
server.expect( server.formatUrl( REMOTE, pomPath ), 200, pomContent );
111+
server.expect( server.formatUrl( REMOTE, metadataPath ), 200, metadataContent );
112+
server.expect( server.formatUrl( REMOTE, metadataPluginsPath ), 200, metadataPluginsContent );
113+
114+
RemoteRepository remote1 = new RemoteRepository( MAVEN_PKG_KEY, REMOTE, server.formatUrl( REMOTE ) );
115+
remote1 = client.stores().create( remote1, "remote A", RemoteRepository.class );
116+
117+
Group g = new Group( MAVEN_PKG_KEY, GROUP, remote1.getKey() );
118+
g = client.stores().create( g, "Create group G", Group.class );
119+
120+
/*// Get meta from remote
121+
try (final InputStream stream = client.content().get( remote1.getKey(), metadataPluginsPath ))
122+
{
123+
assertThat( stream, notNullValue() );
124+
String meta = IOUtils.toString( stream );
125+
logger.debug( "Remote A meta >>>>\n" + meta );
126+
}*/
127+
128+
// Get meta from group
129+
try (final InputStream stream = client.content().get( g.getKey(), metadataPluginsPath ))
130+
{
131+
assertThat( stream, notNullValue() );
132+
String meta = IOUtils.toString( stream );
133+
logger.debug( "Group meta >>>>\n" + meta );
134+
}
135+
136+
}
137+
}

pom.xml

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -939,6 +939,12 @@
939939
<groupId>org.infinispan</groupId>
940940
<artifactId>infinispan-cachestore-jdbc</artifactId>
941941
<version>${infinispanVersion}</version>
942+
<exclusions>
943+
<exclusion>
944+
<groupId>org.jboss.slf4j</groupId>
945+
<artifactId>slf4j-jboss-logging</artifactId>
946+
</exclusion>
947+
</exclusions>
942948
</dependency>
943949
<dependency>
944950
<groupId>org.infinispan</groupId>

0 commit comments

Comments
 (0)