Skip to content

Commit b8c672b

Browse files
committed
[#215] Test for multi release jar sources
Refs: #215, MSOURCES-144
1 parent bd3d302 commit b8c672b

File tree

5 files changed

+228
-0
lines changed

5 files changed

+228
-0
lines changed

src/test/java/org/apache/maven/plugins/source/SourceJarMojoTest.java

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,8 @@
1919
package org.apache.maven.plugins.source;
2020

2121
import java.io.File;
22+
import java.nio.file.Path;
23+
import java.nio.file.Paths;
2224

2325
/**
2426
* @author <a href="mailto:oching@exist.com">Maria Odea Ching</a>
@@ -122,4 +124,17 @@ public void testIncludeMavenDescriptorWhenExplicitlyConfigured() throws Exceptio
122124
}),
123125
"sources");
124126
}
127+
128+
public void testIncludesAdditionSourcesFromMain() throws Exception {
129+
// must include MRJar configuration from the compiler plugin
130+
doTestProjectWithSourceArchive(
131+
"msources-144",
132+
addMavenDescriptor("msources-144", new String[] {
133+
"SomeClass.java",
134+
"META-INF/versions/9/SomeClass.java"
135+
}
136+
),
137+
"sources"
138+
);
139+
}
125140
}
Lines changed: 108 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,108 @@
1+
/*
2+
* Licensed to the Apache Software Foundation (ASF) under one
3+
* or more contributor license agreements. See the NOTICE file
4+
* distributed with this work for additional information
5+
* regarding copyright ownership. The ASF licenses this file
6+
* to you under the Apache License, Version 2.0 (the
7+
* "License"); you may not use this file except in compliance
8+
* with the License. You may obtain a copy of the License at
9+
*
10+
* http://www.apache.org/licenses/LICENSE-2.0
11+
*
12+
* Unless required by applicable law or agreed to in writing,
13+
* software distributed under the License is distributed on an
14+
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15+
* KIND, either express or implied. See the License for the
16+
* specific language governing permissions and limitations
17+
* under the License.
18+
*/
19+
package org.apache.maven.plugins.source.stubs;
20+
21+
import static org.apache.maven.plugins.source.stubs.Project001Stub.readModelFromFile;
22+
23+
import org.apache.maven.model.Build;
24+
import org.apache.maven.model.Model;
25+
import org.apache.maven.model.Resource;
26+
import org.apache.maven.plugin.testing.stubs.MavenProjectStub;
27+
28+
import java.io.File;
29+
import java.util.ArrayList;
30+
import java.util.List;
31+
32+
public class MSources144Stub extends MavenProjectStub {
33+
private Build build;
34+
35+
private List<Resource> resources;
36+
37+
private List<Resource> testResources;
38+
39+
public MSources144Stub() {
40+
Model model;
41+
42+
try {
43+
model = readModelFromFile(new File(getBasedir(), "target/test-classes/unit/msources-144/pom.xml"));
44+
setModel(model);
45+
46+
setFile(new File(getBasedir(), "target/test-classes/unit/msources-144/pom.xml"));
47+
48+
setGroupId(model.getGroupId());
49+
setArtifactId(model.getArtifactId());
50+
setVersion(model.getVersion());
51+
setName(model.getName());
52+
setUrl(model.getUrl());
53+
setPackaging(model.getPackaging());
54+
55+
Build build = new Build();
56+
build.setFinalName(getArtifactId() + "-" + getVersion());
57+
build.setDirectory(getBasedir() + "/target/test/unit/msources-144/target");
58+
59+
setBuild(build);
60+
61+
String basedir = getBasedir().getAbsolutePath();
62+
List<String> compileSourceRoots = new ArrayList<>();
63+
compileSourceRoots.add(basedir + "/target/test-classes/unit/msources-144/src/main/java");
64+
setCompileSourceRoots(compileSourceRoots);
65+
66+
List<String> testCompileSourceRoots = new ArrayList<>();
67+
testCompileSourceRoots.add(basedir + "/target/test-classes/unit/msources-144/src/test/java");
68+
setTestCompileSourceRoots(testCompileSourceRoots);
69+
70+
setResources(model.getBuild().getResources());
71+
setTestResources(model.getBuild().getTestResources());
72+
73+
SourcePluginArtifactStub artifact =
74+
new SourcePluginArtifactStub(getGroupId(), getArtifactId(), getVersion(), getPackaging(), null);
75+
artifact.setArtifactHandler(new DefaultArtifactHandlerStub());
76+
artifact.setType("jar");
77+
artifact.setBaseVersion("1.0-SNAPSHOT");
78+
setArtifact(artifact);
79+
80+
} catch (Exception e) {
81+
e.printStackTrace();
82+
}
83+
}
84+
85+
public Build getBuild() {
86+
return build;
87+
}
88+
89+
public void setBuild(Build build) {
90+
this.build = build;
91+
}
92+
93+
public List<Resource> getResources() {
94+
return resources;
95+
}
96+
97+
public void setResources(List<Resource> resources) {
98+
this.resources = resources;
99+
}
100+
101+
public List<Resource> getTestResources() {
102+
return testResources;
103+
}
104+
105+
public void setTestResources(List<Resource> testResources) {
106+
this.testResources = testResources;
107+
}
108+
}
Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<!--
3+
Licensed to the Apache Software Foundation (ASF) under one
4+
or more contributor license agreements. See the NOTICE file
5+
distributed with this work for additional information
6+
regarding copyright ownership. The ASF licenses this file
7+
to you under the Apache License, Version 2.0 (the
8+
"License"); you may not use this file except in compliance
9+
with the License. You may obtain a copy of the License at
10+
11+
http://www.apache.org/licenses/LICENSE-2.0
12+
13+
Unless required by applicable law or agreed to in writing,
14+
software distributed under the License is distributed on an
15+
"AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16+
KIND, either express or implied. See the License for the
17+
specific language governing permissions and limitations
18+
under the License.
19+
-->
20+
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
21+
<modelVersion>4.0.0</modelVersion>
22+
23+
<groupId>source</groupId>
24+
<artifactId>maven-source-plugin-test-msources-144</artifactId>
25+
<version>99.0</version>
26+
<packaging>jar</packaging>
27+
28+
<build>
29+
<plugins>
30+
<plugin>
31+
<groupId>org.apache.maven.plugins</groupId>
32+
<artifactId>maven-source-plugin</artifactId>
33+
<configuration>
34+
<project implementation="org.apache.maven.plugins.source.stubs.MSources144Stub"/>
35+
<outputDirectory>${basedir}/target/test/unit/msources-144/target</outputDirectory>
36+
<finalName>maven-source-plugin-test-msources-144-99.0</finalName>
37+
</configuration>
38+
</plugin>
39+
<!-- this is just informational why we would expect both sources to be included -->
40+
<plugin>
41+
<groupId>org.apache.maven.plugins</groupId>
42+
<artifactId>maven-compiler-plugin</artifactId>
43+
<executions>
44+
<execution>
45+
<id>compile-java9</id>
46+
<phase>compile</phase>
47+
<goals>
48+
<goal>compile</goal>
49+
</goals>
50+
<configuration>
51+
<compileSourceRoots>
52+
<compileSourceroot>${project.basedir}/src/main/java9</compileSourceroot>
53+
</compileSourceRoots>
54+
<outputDirectory>${project.build.outputDirectory}/META-INF/versions/9</outputDirectory>
55+
</configuration>
56+
</execution>
57+
</executions>
58+
</plugin>
59+
</plugins>
60+
</build>
61+
62+
63+
</project>
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
/*
2+
* Licensed to the Apache Software Foundation (ASF) under one
3+
* or more contributor license agreements. See the NOTICE file
4+
* distributed with this work for additional information
5+
* regarding copyright ownership. The ASF licenses this file
6+
* to you under the Apache License, Version 2.0 (the
7+
* "License"); you may not use this file except in compliance
8+
* with the License. You may obtain a copy of the License at
9+
*
10+
* http://www.apache.org/licenses/LICENSE-2.0
11+
*
12+
* Unless required by applicable law or agreed to in writing,
13+
* software distributed under the License is distributed on an
14+
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15+
* KIND, either express or implied. See the License for the
16+
* specific language governing permissions and limitations
17+
* under the License.
18+
*/
19+
public class SomeClass() {
20+
21+
}
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
/*
2+
* Licensed to the Apache Software Foundation (ASF) under one
3+
* or more contributor license agreements. See the NOTICE file
4+
* distributed with this work for additional information
5+
* regarding copyright ownership. The ASF licenses this file
6+
* to you under the Apache License, Version 2.0 (the
7+
* "License"); you may not use this file except in compliance
8+
* with the License. You may obtain a copy of the License at
9+
*
10+
* http://www.apache.org/licenses/LICENSE-2.0
11+
*
12+
* Unless required by applicable law or agreed to in writing,
13+
* software distributed under the License is distributed on an
14+
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15+
* KIND, either express or implied. See the License for the
16+
* specific language governing permissions and limitations
17+
* under the License.
18+
*/
19+
public class SomeClass {
20+
21+
}

0 commit comments

Comments
 (0)