Skip to content

Commit

Permalink
[MCOMPILER 366] - Warning about automodules should provide the list o…
Browse files Browse the repository at this point in the history
…f 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
  • Loading branch information
ofarganc authored and khmarbaise committed Mar 23, 2019
1 parent d8bfa28 commit 3d6b27c
Show file tree
Hide file tree
Showing 9 changed files with 194 additions and 23 deletions.
18 changes: 18 additions & 0 deletions src/it/MCOMPILER-366/invoker.properties
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
# 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.

invoker.java.version = 9+
61 changes: 61 additions & 0 deletions src/it/MCOMPILER-366/pom.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
<?xml version="1.0" encoding="UTF-8"?>
<!--
~ 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.
-->

<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">
<modelVersion>4.0.0</modelVersion>

<groupId>org.apache.maven.plugins.compiler.it</groupId>
<artifactId>mcompiler-366</artifactId>
<version>1.0-SNAPSHOT</version>

<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
</properties>

<build>
<pluginManagement>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>@project.version@</version>
<configuration>
<release>9</release>
</configuration>
</plugin>
</plugins>
</pluginManagement>
</build>

<dependencies>
<dependency>
<groupId>org.codehaus.plexus</groupId>
<artifactId>plexus-utils</artifactId>
<version>2.0.4</version>
</dependency>
<dependency>
<groupId>org.codehaus.plexus</groupId>
<artifactId>plexus-resources</artifactId>
<version>1.1.0</version>
</dependency>
</dependencies>
</project>
24 changes: 24 additions & 0 deletions src/it/MCOMPILER-366/src/main/java/module-info.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
/*
* 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.
*/
module lib
{
requires plexus.utils;
requires plexus.resources;
exports org.maven.test;
}
34 changes: 34 additions & 0 deletions src/it/MCOMPILER-366/src/main/java/org/maven/test/Main.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
package org.maven.test;

/*
* 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.
*/

import org.codehaus.plexus.util.StringUtils;
import org.codehaus.plexus.resource.ResourceManager;

public class Main {

/**
* @param args
*/
public static void main(String[] args) {
System.out.println( StringUtils.concatenate( args ) );
ResourceManager manager = null;
}
}
22 changes: 22 additions & 0 deletions src/it/MCOMPILER-366/verify.groovy
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
/*
* 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.
*/

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

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! *");
2 changes: 1 addition & 1 deletion src/it/automodules-application/verify.groovy
Original file line number Diff line number Diff line change
Expand Up @@ -19,4 +19,4 @@

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

assert buildLog.contains("[INFO] Required filename-based automodules detected. Please don't publish this project to a public artifact repository!");
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!");
2 changes: 1 addition & 1 deletion src/it/automodules-library/verify.groovy
Original file line number Diff line number Diff line change
Expand Up @@ -19,4 +19,4 @@

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

assert buildLog.contains("[WARNING] * Required filename-based automodules detected. Please don't publish this project to a public artifact repository! *");
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! *");
2 changes: 1 addition & 1 deletion src/it/automodules-transitive-module/verify.groovy
Original file line number Diff line number Diff line change
Expand Up @@ -19,4 +19,4 @@

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

assert buildLog.contains("[WARNING] * Required filename-based automodules detected. Please don't publish this project to a public artifact repository! *");
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! *");
52 changes: 32 additions & 20 deletions src/main/java/org/apache/maven/plugin/compiler/CompilerMojo.java
Original file line number Diff line number Diff line change
Expand Up @@ -250,26 +250,7 @@ protected void preparePaths( Set<File> sourceFiles )

JavaModuleDescriptor moduleDescriptor = resolvePathsResult.getMainModuleDescriptor();

for ( Map.Entry<File, ModuleNameSource> entry : resolvePathsResult.getModulepathElements().entrySet() )
{
if ( ModuleNameSource.FILENAME.equals( entry.getValue() ) )
{
final String message = "Required filename-based automodules detected. "
+ "Please don't publish this project to a public artifact repository!";

if ( moduleDescriptor.exports().isEmpty() )
{
// application
getLog().info( message );
}
else
{
// library
writeBoxedWarning( message );
}
break;
}
}
detectFilenameBasedAutomodules( resolvePathsResult, moduleDescriptor );

for ( Map.Entry<File, JavaModuleDescriptor> entry : resolvePathsResult.getPathElements().entrySet() )
{
Expand Down Expand Up @@ -324,6 +305,37 @@ protected void preparePaths( Set<File> sourceFiles )
modulepathElements = Collections.emptyList();
}
}

private void detectFilenameBasedAutomodules( final ResolvePathsResult<File> resolvePathsResult,
final JavaModuleDescriptor moduleDescriptor )
{
List<String> automodulesDetected = new ArrayList<>();
for ( Entry<File, ModuleNameSource> entry : resolvePathsResult.getModulepathElements().entrySet() )
{
if ( ModuleNameSource.FILENAME.equals( entry.getValue() ) )
{
automodulesDetected.add( entry.getKey().getName() );
}
}

if ( !automodulesDetected.isEmpty() )
{
final String message = "Required filename-based automodules detected: "
+ automodulesDetected + ". "
+ "Please don't publish this project to a public artifact repository!";

if ( moduleDescriptor.exports().isEmpty() )
{
// application
getLog().info( message );
}
else
{
// library
writeBoxedWarning( message );
}
}
}

private List<File> getCompileClasspathElements( MavenProject project )
{
Expand Down

0 comments on commit 3d6b27c

Please sign in to comment.