Skip to content

Commit 3d6b27c

Browse files
ofarganckhmarbaise
authored andcommitted
[MCOMPILER 366] - Warning about automodules should provide the list of offending libraries
- Collected filename based automodules detected and added to the log message. - Updated unit tests accordingly. - Added new integration test with 2 modules. - Make unit/integration tests Java 12 compatible
1 parent d8bfa28 commit 3d6b27c

File tree

9 files changed

+194
-23
lines changed

9 files changed

+194
-23
lines changed
+18
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
# Licensed to the Apache Software Foundation (ASF) under one
2+
# or more contributor license agreements. See the NOTICE file
3+
# distributed with this work for additional information
4+
# regarding copyright ownership. The ASF licenses this file
5+
# to you under the Apache License, Version 2.0 (the
6+
# "License"); you may not use this file except in compliance
7+
# with the License. You may obtain a copy of the License at
8+
#
9+
# http://www.apache.org/licenses/LICENSE-2.0
10+
#
11+
# Unless required by applicable law or agreed to in writing,
12+
# software distributed under the License is distributed on an
13+
# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
14+
# KIND, either express or implied. See the License for the
15+
# specific language governing permissions and limitations
16+
# under the License.
17+
18+
invoker.java.version = 9+

src/it/MCOMPILER-366/pom.xml

+61
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
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+
21+
<project xmlns="http://maven.apache.org/POM/4.0.0"
22+
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
23+
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
24+
<modelVersion>4.0.0</modelVersion>
25+
26+
<groupId>org.apache.maven.plugins.compiler.it</groupId>
27+
<artifactId>mcompiler-366</artifactId>
28+
<version>1.0-SNAPSHOT</version>
29+
30+
<properties>
31+
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
32+
</properties>
33+
34+
<build>
35+
<pluginManagement>
36+
<plugins>
37+
<plugin>
38+
<groupId>org.apache.maven.plugins</groupId>
39+
<artifactId>maven-compiler-plugin</artifactId>
40+
<version>@project.version@</version>
41+
<configuration>
42+
<release>9</release>
43+
</configuration>
44+
</plugin>
45+
</plugins>
46+
</pluginManagement>
47+
</build>
48+
49+
<dependencies>
50+
<dependency>
51+
<groupId>org.codehaus.plexus</groupId>
52+
<artifactId>plexus-utils</artifactId>
53+
<version>2.0.4</version>
54+
</dependency>
55+
<dependency>
56+
<groupId>org.codehaus.plexus</groupId>
57+
<artifactId>plexus-resources</artifactId>
58+
<version>1.1.0</version>
59+
</dependency>
60+
</dependencies>
61+
</project>
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
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+
module lib
20+
{
21+
requires plexus.utils;
22+
requires plexus.resources;
23+
exports org.maven.test;
24+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
package org.maven.test;
2+
3+
/*
4+
* Licensed to the Apache Software Foundation (ASF) under one
5+
* or more contributor license agreements. See the NOTICE file
6+
* distributed with this work for additional information
7+
* regarding copyright ownership. The ASF licenses this file
8+
* to you under the Apache License, Version 2.0 (the
9+
* "License"); you may not use this file except in compliance
10+
* with the License. You may obtain a copy of the License at
11+
*
12+
* http://www.apache.org/licenses/LICENSE-2.0
13+
*
14+
* Unless required by applicable law or agreed to in writing,
15+
* software distributed under the License is distributed on an
16+
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
17+
* KIND, either express or implied. See the License for the
18+
* specific language governing permissions and limitations
19+
* under the License.
20+
*/
21+
22+
import org.codehaus.plexus.util.StringUtils;
23+
import org.codehaus.plexus.resource.ResourceManager;
24+
25+
public class Main {
26+
27+
/**
28+
* @param args
29+
*/
30+
public static void main(String[] args) {
31+
System.out.println( StringUtils.concatenate( args ) );
32+
ResourceManager manager = null;
33+
}
34+
}

src/it/MCOMPILER-366/verify.groovy

+22
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
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+
20+
buildLog = new File( basedir, 'build.log' ).text;
21+
22+
assert buildLog.contains("[WARNING] * Required filename-based automodules detected: [plexus-utils-2.0.4.jar, plexus-resources-1.1.0.jar]. Please don't publish this project to a public artifact repository! *");

src/it/automodules-application/verify.groovy

+1-1
Original file line numberDiff line numberDiff line change
@@ -19,4 +19,4 @@
1919

2020
buildLog = new File( basedir, 'build.log' ).text;
2121

22-
assert buildLog.contains("[INFO] Required filename-based automodules detected. Please don't publish this project to a public artifact repository!");
22+
assert buildLog.contains("[INFO] Required filename-based automodules detected: [plexus-utils-2.0.4.jar]. Please don't publish this project to a public artifact repository!");

src/it/automodules-library/verify.groovy

+1-1
Original file line numberDiff line numberDiff line change
@@ -19,4 +19,4 @@
1919

2020
buildLog = new File( basedir, 'build.log' ).text;
2121

22-
assert buildLog.contains("[WARNING] * Required filename-based automodules detected. Please don't publish this project to a public artifact repository! *");
22+
assert buildLog.contains("[WARNING] * Required filename-based automodules detected: [plexus-utils-2.0.4.jar]. Please don't publish this project to a public artifact repository! *");

src/it/automodules-transitive-module/verify.groovy

+1-1
Original file line numberDiff line numberDiff line change
@@ -19,4 +19,4 @@
1919

2020
buildLog = new File( basedir, 'build.log' ).text;
2121

22-
assert buildLog.contains("[WARNING] * Required filename-based automodules detected. Please don't publish this project to a public artifact repository! *");
22+
assert buildLog.contains("[WARNING] * Required filename-based automodules detected: [plexus-utils-2.0.4.jar]. Please don't publish this project to a public artifact repository! *");

src/main/java/org/apache/maven/plugin/compiler/CompilerMojo.java

+32-20
Original file line numberDiff line numberDiff line change
@@ -250,26 +250,7 @@ protected void preparePaths( Set<File> sourceFiles )
250250

251251
JavaModuleDescriptor moduleDescriptor = resolvePathsResult.getMainModuleDescriptor();
252252

253-
for ( Map.Entry<File, ModuleNameSource> entry : resolvePathsResult.getModulepathElements().entrySet() )
254-
{
255-
if ( ModuleNameSource.FILENAME.equals( entry.getValue() ) )
256-
{
257-
final String message = "Required filename-based automodules detected. "
258-
+ "Please don't publish this project to a public artifact repository!";
259-
260-
if ( moduleDescriptor.exports().isEmpty() )
261-
{
262-
// application
263-
getLog().info( message );
264-
}
265-
else
266-
{
267-
// library
268-
writeBoxedWarning( message );
269-
}
270-
break;
271-
}
272-
}
253+
detectFilenameBasedAutomodules( resolvePathsResult, moduleDescriptor );
273254

274255
for ( Map.Entry<File, JavaModuleDescriptor> entry : resolvePathsResult.getPathElements().entrySet() )
275256
{
@@ -324,6 +305,37 @@ protected void preparePaths( Set<File> sourceFiles )
324305
modulepathElements = Collections.emptyList();
325306
}
326307
}
308+
309+
private void detectFilenameBasedAutomodules( final ResolvePathsResult<File> resolvePathsResult,
310+
final JavaModuleDescriptor moduleDescriptor )
311+
{
312+
List<String> automodulesDetected = new ArrayList<>();
313+
for ( Entry<File, ModuleNameSource> entry : resolvePathsResult.getModulepathElements().entrySet() )
314+
{
315+
if ( ModuleNameSource.FILENAME.equals( entry.getValue() ) )
316+
{
317+
automodulesDetected.add( entry.getKey().getName() );
318+
}
319+
}
320+
321+
if ( !automodulesDetected.isEmpty() )
322+
{
323+
final String message = "Required filename-based automodules detected: "
324+
+ automodulesDetected + ". "
325+
+ "Please don't publish this project to a public artifact repository!";
326+
327+
if ( moduleDescriptor.exports().isEmpty() )
328+
{
329+
// application
330+
getLog().info( message );
331+
}
332+
else
333+
{
334+
// library
335+
writeBoxedWarning( message );
336+
}
337+
}
338+
}
327339

328340
private List<File> getCompileClasspathElements( MavenProject project )
329341
{

0 commit comments

Comments
 (0)