You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@maven.apache.org by rf...@apache.org on 2015/02/07 13:45:55 UTC
svn commit: r1658054 - in /maven/plugins/trunk/maven-jdeps-plugin: ./
src/it/unsupported-api_main/ src/it/unsupported-api_test/
src/it/unsupported-api_test/src/main/
src/it/unsupported-api_test/src/main/java/
src/main/java/org/apache/maven/plugin/jdeps...
Author: rfscholte
Date: Sat Feb 7 12:45:54 2015
New Revision: 1658054
URL: http://svn.apache.org/r1658054
Log:
Introduce JDepsConsumer to analyze the output
Added:
maven/plugins/trunk/maven-jdeps-plugin/src/it/unsupported-api_main/verify.groovy
maven/plugins/trunk/maven-jdeps-plugin/src/it/unsupported-api_test/src/main/
maven/plugins/trunk/maven-jdeps-plugin/src/it/unsupported-api_test/src/main/java/
maven/plugins/trunk/maven-jdeps-plugin/src/it/unsupported-api_test/src/main/java/Main.java
maven/plugins/trunk/maven-jdeps-plugin/src/it/unsupported-api_test/verify.groovy
maven/plugins/trunk/maven-jdeps-plugin/src/main/java/org/apache/maven/plugin/jdeps/consumers/
maven/plugins/trunk/maven-jdeps-plugin/src/main/java/org/apache/maven/plugin/jdeps/consumers/JDepsConsumer.java
maven/plugins/trunk/maven-jdeps-plugin/src/test/
maven/plugins/trunk/maven-jdeps-plugin/src/test/java/
maven/plugins/trunk/maven-jdeps-plugin/src/test/java/org/
maven/plugins/trunk/maven-jdeps-plugin/src/test/java/org/apache/
maven/plugins/trunk/maven-jdeps-plugin/src/test/java/org/apache/maven/
maven/plugins/trunk/maven-jdeps-plugin/src/test/java/org/apache/maven/plugin/
maven/plugins/trunk/maven-jdeps-plugin/src/test/java/org/apache/maven/plugin/jdeps/
maven/plugins/trunk/maven-jdeps-plugin/src/test/java/org/apache/maven/plugin/jdeps/consumers/
maven/plugins/trunk/maven-jdeps-plugin/src/test/java/org/apache/maven/plugin/jdeps/consumers/JDepsConsumerTest.java
Modified:
maven/plugins/trunk/maven-jdeps-plugin/pom.xml
maven/plugins/trunk/maven-jdeps-plugin/src/it/unsupported-api_test/pom.xml
maven/plugins/trunk/maven-jdeps-plugin/src/main/java/org/apache/maven/plugin/jdeps/AbstractJDepsMojo.java
Modified: maven/plugins/trunk/maven-jdeps-plugin/pom.xml
URL: http://svn.apache.org/viewvc/maven/plugins/trunk/maven-jdeps-plugin/pom.xml?rev=1658054&r1=1658053&r2=1658054&view=diff
==============================================================================
--- maven/plugins/trunk/maven-jdeps-plugin/pom.xml (original)
+++ maven/plugins/trunk/maven-jdeps-plugin/pom.xml Sat Feb 7 12:45:54 2015
@@ -78,5 +78,13 @@ under the License.
<artifactId>commons-lang</artifactId>
<version>2.4</version>
</dependency>
+
+ <!-- TEST -->
+ <dependency>
+ <groupId>junit</groupId>
+ <artifactId>junit</artifactId>
+ <version>4.11</version>
+ <scope>test</scope>
+ </dependency>
</dependencies>
</project>
\ No newline at end of file
Added: maven/plugins/trunk/maven-jdeps-plugin/src/it/unsupported-api_main/verify.groovy
URL: http://svn.apache.org/viewvc/maven/plugins/trunk/maven-jdeps-plugin/src/it/unsupported-api_main/verify.groovy?rev=1658054&view=auto
==============================================================================
--- maven/plugins/trunk/maven-jdeps-plugin/src/it/unsupported-api_main/verify.groovy (added)
+++ maven/plugins/trunk/maven-jdeps-plugin/src/it/unsupported-api_main/verify.groovy Sat Feb 7 12:45:54 2015
@@ -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.
+ */
+
+def LS = System.getProperty("line.separator")
+
+def buildLog = new File( basedir, 'build.log' )
+assert buildLog.text.contains( "Found offending packages:${LS} sun.misc -> JDK internal API (java.base)" );
\ No newline at end of file
Modified: maven/plugins/trunk/maven-jdeps-plugin/src/it/unsupported-api_test/pom.xml
URL: http://svn.apache.org/viewvc/maven/plugins/trunk/maven-jdeps-plugin/src/it/unsupported-api_test/pom.xml?rev=1658054&r1=1658053&r2=1658054&view=diff
==============================================================================
--- maven/plugins/trunk/maven-jdeps-plugin/src/it/unsupported-api_test/pom.xml (original)
+++ maven/plugins/trunk/maven-jdeps-plugin/src/it/unsupported-api_test/pom.xml Sat Feb 7 12:45:54 2015
@@ -41,6 +41,7 @@ under the License.
<executions>
<execution>
<goals>
+ <goal>jdkinternals</goal>
<goal>test-jdkinternals</goal>
</goals>
</execution>
Added: maven/plugins/trunk/maven-jdeps-plugin/src/it/unsupported-api_test/src/main/java/Main.java
URL: http://svn.apache.org/viewvc/maven/plugins/trunk/maven-jdeps-plugin/src/it/unsupported-api_test/src/main/java/Main.java?rev=1658054&view=auto
==============================================================================
--- maven/plugins/trunk/maven-jdeps-plugin/src/it/unsupported-api_test/src/main/java/Main.java (added)
+++ maven/plugins/trunk/maven-jdeps-plugin/src/it/unsupported-api_test/src/main/java/Main.java Sat Feb 7 12:45:54 2015
@@ -0,0 +1,28 @@
+/*
+ * 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.
+ */
+
+public class Main
+{
+
+ public static void main( String[] args )
+ {
+ System.out.println( "Hello world!" );
+ }
+
+}
Added: maven/plugins/trunk/maven-jdeps-plugin/src/it/unsupported-api_test/verify.groovy
URL: http://svn.apache.org/viewvc/maven/plugins/trunk/maven-jdeps-plugin/src/it/unsupported-api_test/verify.groovy?rev=1658054&view=auto
==============================================================================
--- maven/plugins/trunk/maven-jdeps-plugin/src/it/unsupported-api_test/verify.groovy (added)
+++ maven/plugins/trunk/maven-jdeps-plugin/src/it/unsupported-api_test/verify.groovy Sat Feb 7 12:45:54 2015
@@ -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.
+ */
+
+def LS = System.getProperty("line.separator")
+
+def buildLog = new File( basedir, 'build.log' )
+assert buildLog.text.contains( "Found offending packages:${LS} sun.misc -> JDK internal API (java.base)" );
\ No newline at end of file
Modified: maven/plugins/trunk/maven-jdeps-plugin/src/main/java/org/apache/maven/plugin/jdeps/AbstractJDepsMojo.java
URL: http://svn.apache.org/viewvc/maven/plugins/trunk/maven-jdeps-plugin/src/main/java/org/apache/maven/plugin/jdeps/AbstractJDepsMojo.java?rev=1658054&r1=1658053&r2=1658054&view=diff
==============================================================================
--- maven/plugins/trunk/maven-jdeps-plugin/src/main/java/org/apache/maven/plugin/jdeps/AbstractJDepsMojo.java (original)
+++ maven/plugins/trunk/maven-jdeps-plugin/src/main/java/org/apache/maven/plugin/jdeps/AbstractJDepsMojo.java Sat Feb 7 12:45:54 2015
@@ -21,6 +21,7 @@ package org.apache.maven.plugin.jdeps;
import java.io.File;
import java.io.IOException;
+import java.util.Map;
import java.util.Properties;
import java.util.StringTokenizer;
@@ -30,6 +31,7 @@ import org.apache.maven.execution.MavenS
import org.apache.maven.plugin.AbstractMojo;
import org.apache.maven.plugin.MojoExecutionException;
import org.apache.maven.plugin.MojoFailureException;
+import org.apache.maven.plugin.jdeps.consumers.JDepsConsumer;
import org.apache.maven.plugins.annotations.Component;
import org.apache.maven.plugins.annotations.Parameter;
import org.apache.maven.project.MavenProject;
@@ -127,6 +129,12 @@ public abstract class AbstractJDepsMojo
public void execute()
throws MojoExecutionException, MojoFailureException
{
+ if ( !new File( getClassesDirectory() ).exists() )
+ {
+ getLog().debug( "No classes to analyze" );
+ return;
+ }
+
String jExecutable;
try
{
@@ -144,7 +152,23 @@ public abstract class AbstractJDepsMojo
addJDepsOptions( cmd );
addJDepsClasses( cmd );
- executeJavadocCommandLine( cmd, outputDirectory );
+ JDepsConsumer consumer = new JDepsConsumer();
+ executeJavadocCommandLine( cmd, outputDirectory, consumer );
+
+ // @ TODO if there will be more goals, this should be pushed down to AbstractJDKInternals
+ if ( consumer.getOffendingPackages().size() > 0 )
+ {
+ final String ls = System.getProperty( "line.separator" );
+
+ StringBuilder msg = new StringBuilder();
+ msg.append( "Found offending packages:" ).append( ls );
+ for ( Map.Entry<String, String> offendingPackage : consumer.getOffendingPackages().entrySet() )
+ {
+ msg.append( ' ' ).append( offendingPackage.getKey() )
+ .append( " -> " ).append( offendingPackage.getValue() ).append( ls );
+ }
+ throw new MojoExecutionException( msg.toString() );
+ }
}
protected void addJDepsOptions( Commandline cmd )
@@ -223,7 +247,7 @@ public abstract class AbstractJDepsMojo
cmd.createArg().setValue( "-R" );
}
- cmd.createArg().setValue( "-version" );
+ // cmd.createArg().setValue( "-version" );
}
protected void addJDepsClasses( Commandline cmd )
@@ -322,7 +346,9 @@ public abstract class AbstractJDepsMojo
return jdepsExe.getAbsolutePath();
}
- private void executeJavadocCommandLine( Commandline cmd, File javadocOutputDirectory ) throws MojoExecutionException
+ private void executeJavadocCommandLine( Commandline cmd, File jOutputDirectory,
+ CommandLineUtils.StringStreamConsumer consumer )
+ throws MojoExecutionException
{
if ( getLog().isDebugEnabled() )
{
@@ -330,8 +356,18 @@ public abstract class AbstractJDepsMojo
getLog().debug( CommandLineUtils.toString( cmd.getCommandline() ).replaceAll( "'", "" ) );
}
+
CommandLineUtils.StringStreamConsumer err = new CommandLineUtils.StringStreamConsumer();
- CommandLineUtils.StringStreamConsumer out = new CommandLineUtils.StringStreamConsumer();
+ CommandLineUtils.StringStreamConsumer out;
+ if ( consumer != null )
+ {
+ out = consumer;
+ }
+ else
+ {
+ out = new CommandLineUtils.StringStreamConsumer();
+ }
+
try
{
int exitCode = CommandLineUtils.executeCommandLine( cmd, out, err );
Added: maven/plugins/trunk/maven-jdeps-plugin/src/main/java/org/apache/maven/plugin/jdeps/consumers/JDepsConsumer.java
URL: http://svn.apache.org/viewvc/maven/plugins/trunk/maven-jdeps-plugin/src/main/java/org/apache/maven/plugin/jdeps/consumers/JDepsConsumer.java?rev=1658054&view=auto
==============================================================================
--- maven/plugins/trunk/maven-jdeps-plugin/src/main/java/org/apache/maven/plugin/jdeps/consumers/JDepsConsumer.java (added)
+++ maven/plugins/trunk/maven-jdeps-plugin/src/main/java/org/apache/maven/plugin/jdeps/consumers/JDepsConsumer.java Sat Feb 7 12:45:54 2015
@@ -0,0 +1,60 @@
+package org.apache.maven.plugin.jdeps.consumers;
+
+/*
+ * 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 java.util.HashMap;
+import java.util.Map;
+import java.util.regex.Matcher;
+import java.util.regex.Pattern;
+
+import org.codehaus.plexus.util.cli.CommandLineUtils;
+import org.codehaus.plexus.util.cli.StreamConsumer;
+
+/**
+ * Consumes the output of the jdeps tool
+ *
+ * @author Robert Scholte
+ *
+ */
+public class JDepsConsumer
+ extends CommandLineUtils.StringStreamConsumer
+ implements StreamConsumer
+{
+
+ private static final Pattern JDKINTERNALAPI = Pattern.compile( "\\s+->\\s([a-z\\.]+)\\s+(\\S.*)" );
+
+ private Map<String, String> offendingPackages = new HashMap<String, String>();
+
+ public void consumeLine( String line )
+ {
+ super.consumeLine( line );
+
+ Matcher matcher = JDKINTERNALAPI.matcher( line );
+ if ( matcher.matches() )
+ {
+ offendingPackages.put( matcher.group( 1 ), matcher.group( 2 ) );
+ }
+ }
+
+ public Map<String, String> getOffendingPackages()
+ {
+ return offendingPackages;
+ }
+}
Added: maven/plugins/trunk/maven-jdeps-plugin/src/test/java/org/apache/maven/plugin/jdeps/consumers/JDepsConsumerTest.java
URL: http://svn.apache.org/viewvc/maven/plugins/trunk/maven-jdeps-plugin/src/test/java/org/apache/maven/plugin/jdeps/consumers/JDepsConsumerTest.java?rev=1658054&view=auto
==============================================================================
--- maven/plugins/trunk/maven-jdeps-plugin/src/test/java/org/apache/maven/plugin/jdeps/consumers/JDepsConsumerTest.java (added)
+++ maven/plugins/trunk/maven-jdeps-plugin/src/test/java/org/apache/maven/plugin/jdeps/consumers/JDepsConsumerTest.java Sat Feb 7 12:45:54 2015
@@ -0,0 +1,47 @@
+package org.apache.maven.plugin.jdeps.consumers;
+
+/*
+ * 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 static org.junit.Assert.*;
+
+import org.apache.maven.plugin.jdeps.consumers.JDepsConsumer;
+import org.junit.Test;
+
+public class JDepsConsumerTest
+{
+
+ private JDepsConsumer consumer;
+
+ @Test
+ public void testJDKInterAPI()
+ {
+
+ consumer = new JDepsConsumer();
+ consumer.consumeLine( "test-classes -> java.base" );
+ consumer.consumeLine( " <unnamed> (test-classes)" );
+ consumer.consumeLine( " -> java.io " );
+ consumer.consumeLine( " -> java.lang " );
+ consumer.consumeLine( " -> sun.misc JDK internal API (java.base)" );
+
+ assertEquals( 1, consumer.getOffendingPackages().size() );
+ assertEquals( "JDK internal API (java.base)", consumer.getOffendingPackages().get( "sun.misc" ) );
+ }
+
+}