From 599b468d0de9040c2cc445fc4fa8244791422eeb Mon Sep 17 00:00:00 2001 From: Herve Boutemy Date: Sun, 14 Dec 2014 17:02:53 +0000 Subject: [PATCH] [MPLUGIN-279] added IT with quite complete scenarios and fixed algorithm git-svn-id: https://svn.apache.org/repos/asf/maven/plugin-tools/trunk@1645468 13f79535-47bb-0310-9956-ffa450edef68 --- .../plugin-info-jdk-default-version/pom.xml | 7 ++ .../invoker.properties | 2 +- .../src/it/plugin-info-jdk/plugin/pom.xml | 62 ++++++++++ .../maven/plugins/issues/plugin/MyMojo.java | 25 +++-- .../plugin-info-jdk/pluginManagement/pom.xml | 53 +++++++++ .../maven/plugins/issues/plugin/MyMojo.java | 84 ++++++++++++++ .../pom.xml | 28 +++-- .../property/pom.xml} | 25 +++-- .../maven/plugins/issues/plugin/MyMojo.java | 84 ++++++++++++++ .../it/plugin-info-jdk/requirement/pom.xml | 78 +++++++++++++ .../maven/plugins/issues/plugin/MyMojo.java | 84 ++++++++++++++ .../verify.groovy | 10 +- .../maven/plugin/plugin/PluginReport.java | 106 +++++++++++++++--- 13 files changed, 593 insertions(+), 55 deletions(-) rename maven-plugin-plugin/src/it/{plugin-info-jdk-default-property => plugin-info-jdk}/invoker.properties (95%) create mode 100644 maven-plugin-plugin/src/it/plugin-info-jdk/plugin/pom.xml rename maven-plugin-plugin/src/it/{plugin-info-jdk-default-property => plugin-info-jdk/plugin}/src/main/java/org/apache/maven/plugins/issues/plugin/MyMojo.java (62%) create mode 100644 maven-plugin-plugin/src/it/plugin-info-jdk/pluginManagement/pom.xml create mode 100644 maven-plugin-plugin/src/it/plugin-info-jdk/pluginManagement/src/main/java/org/apache/maven/plugins/issues/plugin/MyMojo.java rename maven-plugin-plugin/src/it/{plugin-info-jdk-default-property => plugin-info-jdk}/pom.xml (84%) rename maven-plugin-plugin/src/it/{plugin-info-jdk-default-property/src/site/site.xml => plugin-info-jdk/property/pom.xml} (53%) create mode 100644 maven-plugin-plugin/src/it/plugin-info-jdk/property/src/main/java/org/apache/maven/plugins/issues/plugin/MyMojo.java create mode 100644 maven-plugin-plugin/src/it/plugin-info-jdk/requirement/pom.xml create mode 100644 maven-plugin-plugin/src/it/plugin-info-jdk/requirement/src/main/java/org/apache/maven/plugins/issues/plugin/MyMojo.java rename maven-plugin-plugin/src/it/{plugin-info-jdk-default-property => plugin-info-jdk}/verify.groovy (65%) diff --git a/maven-plugin-plugin/src/it/plugin-info-jdk-default-version/pom.xml b/maven-plugin-plugin/src/it/plugin-info-jdk-default-version/pom.xml index 5a7c114..2ac9650 100644 --- a/maven-plugin-plugin/src/it/plugin-info-jdk-default-version/pom.xml +++ b/maven-plugin-plugin/src/it/plugin-info-jdk-default-version/pom.xml @@ -74,6 +74,13 @@ under the License. org.apache.maven.plugins maven-project-info-reports-plugin 2.4 + + + + index + + + org.apache.maven.plugins diff --git a/maven-plugin-plugin/src/it/plugin-info-jdk-default-property/invoker.properties b/maven-plugin-plugin/src/it/plugin-info-jdk/invoker.properties similarity index 95% rename from maven-plugin-plugin/src/it/plugin-info-jdk-default-property/invoker.properties rename to maven-plugin-plugin/src/it/plugin-info-jdk/invoker.properties index abdde0d..5cc536a 100644 --- a/maven-plugin-plugin/src/it/plugin-info-jdk-default-property/invoker.properties +++ b/maven-plugin-plugin/src/it/plugin-info-jdk/invoker.properties @@ -15,4 +15,4 @@ # specific language governing permissions and limitations # under the License. -invoker.goals = clean site -DskipTests +invoker.goals = clean site diff --git a/maven-plugin-plugin/src/it/plugin-info-jdk/plugin/pom.xml b/maven-plugin-plugin/src/it/plugin-info-jdk/plugin/pom.xml new file mode 100644 index 0000000..9b2aba1 --- /dev/null +++ b/maven-plugin-plugin/src/it/plugin-info-jdk/plugin/pom.xml @@ -0,0 +1,62 @@ + + + + + + 4.0.0 + + + org.apache.maven.its.plugin-info-jdk + parent + 1.0-SNAPSHOT + + plugin + target bytecode defined by plugin configuration + maven-plugin + + + 1.3 + ${maven.compiler.source} + + + + + + + maven-compiler-plugin + + 1.4 + 1.4 + + + + + + + maven-compiler-plugin + + 1.5 + 1.5 + + + + + diff --git a/maven-plugin-plugin/src/it/plugin-info-jdk-default-property/src/main/java/org/apache/maven/plugins/issues/plugin/MyMojo.java b/maven-plugin-plugin/src/it/plugin-info-jdk/plugin/src/main/java/org/apache/maven/plugins/issues/plugin/MyMojo.java similarity index 62% rename from maven-plugin-plugin/src/it/plugin-info-jdk-default-property/src/main/java/org/apache/maven/plugins/issues/plugin/MyMojo.java rename to maven-plugin-plugin/src/it/plugin-info-jdk/plugin/src/main/java/org/apache/maven/plugins/issues/plugin/MyMojo.java index 3f2d827..ec3f1db 100644 --- a/maven-plugin-plugin/src/it/plugin-info-jdk-default-property/src/main/java/org/apache/maven/plugins/issues/plugin/MyMojo.java +++ b/maven-plugin-plugin/src/it/plugin-info-jdk/plugin/src/main/java/org/apache/maven/plugins/issues/plugin/MyMojo.java @@ -1,19 +1,22 @@ package org.apache.maven.plugins.issues.plugin; /* - * Copyright 2001-2005 The Apache Software Foundation. + * 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 * - * Licensed 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 * - * 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. + * 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.apache.maven.plugin.AbstractMojo; diff --git a/maven-plugin-plugin/src/it/plugin-info-jdk/pluginManagement/pom.xml b/maven-plugin-plugin/src/it/plugin-info-jdk/pluginManagement/pom.xml new file mode 100644 index 0000000..75dd6ec --- /dev/null +++ b/maven-plugin-plugin/src/it/plugin-info-jdk/pluginManagement/pom.xml @@ -0,0 +1,53 @@ + + + + + + 4.0.0 + + + org.apache.maven.its.plugin-info-jdk + parent + 1.0-SNAPSHOT + + pluginManagement + target bytecode defined by pluginManagement configuration + maven-plugin + + + 1.3 + ${maven.compiler.source} + + + + + + + maven-compiler-plugin + + 1.4 + 1.4 + + + + + + diff --git a/maven-plugin-plugin/src/it/plugin-info-jdk/pluginManagement/src/main/java/org/apache/maven/plugins/issues/plugin/MyMojo.java b/maven-plugin-plugin/src/it/plugin-info-jdk/pluginManagement/src/main/java/org/apache/maven/plugins/issues/plugin/MyMojo.java new file mode 100644 index 0000000..ec3f1db --- /dev/null +++ b/maven-plugin-plugin/src/it/plugin-info-jdk/pluginManagement/src/main/java/org/apache/maven/plugins/issues/plugin/MyMojo.java @@ -0,0 +1,84 @@ +package org.apache.maven.plugins.issues.plugin; + +/* + * 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.apache.maven.plugin.AbstractMojo; +import org.apache.maven.plugin.MojoExecutionException; + +import java.io.File; +import java.io.FileWriter; +import java.io.IOException; + +/** + * Goal which touches a timestamp file. + * + * @goal touch + * + * @phase process-sources + */ +public class MyMojo + extends AbstractMojo +{ + /** + * Location of the file. + * @parameter expression="${project.build.directory}" + * @required + */ + private File outputDirectory; + + public void execute() + throws MojoExecutionException + { + File f = outputDirectory; + + if ( !f.exists() ) + { + f.mkdirs(); + } + + File touch = new File( f, "touch.txt" ); + + FileWriter w = null; + try + { + w = new FileWriter( touch ); + + w.write( "touch.txt" ); + } + catch ( IOException e ) + { + throw new MojoExecutionException( "Error creating file " + touch, e ); + } + finally + { + if ( w != null ) + { + try + { + w.close(); + } + catch ( IOException e ) + { + // ignore + } + } + } + } +} diff --git a/maven-plugin-plugin/src/it/plugin-info-jdk-default-property/pom.xml b/maven-plugin-plugin/src/it/plugin-info-jdk/pom.xml similarity index 84% rename from maven-plugin-plugin/src/it/plugin-info-jdk-default-property/pom.xml rename to maven-plugin-plugin/src/it/plugin-info-jdk/pom.xml index 5b94a65..b603114 100644 --- a/maven-plugin-plugin/src/it/plugin-info-jdk-default-property/pom.xml +++ b/maven-plugin-plugin/src/it/plugin-info-jdk/pom.xml @@ -23,15 +23,13 @@ under the License. xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> 4.0.0 - org.apache.maven.its - jdk-default-property + org.apache.maven.its.plugin-info-jdk + parent 1.0-SNAPSHOT - maven-plugin + pom UTF-8 - 1.5 - ${maven.compiler.source} @@ -42,6 +40,13 @@ under the License. + + property + pluginManagement + plugin + requirement + + @@ -49,12 +54,6 @@ under the License. org.apache.maven.plugins maven-compiler-plugin 2.3.2 - org.apache.maven.plugins @@ -76,6 +75,13 @@ under the License. org.apache.maven.plugins maven-project-info-reports-plugin 2.4 + + + + index + + + org.apache.maven.plugins diff --git a/maven-plugin-plugin/src/it/plugin-info-jdk-default-property/src/site/site.xml b/maven-plugin-plugin/src/it/plugin-info-jdk/property/pom.xml similarity index 53% rename from maven-plugin-plugin/src/it/plugin-info-jdk-default-property/src/site/site.xml rename to maven-plugin-plugin/src/it/plugin-info-jdk/property/pom.xml index 3c125b5..aa21b82 100644 --- a/maven-plugin-plugin/src/it/plugin-info-jdk-default-property/src/site/site.xml +++ b/maven-plugin-plugin/src/it/plugin-info-jdk/property/pom.xml @@ -19,12 +19,21 @@ specific language governing permissions and limitations under the License. --> - - - - - - - + + 4.0.0 + + + org.apache.maven.its.plugin-info-jdk + parent + 1.0-SNAPSHOT + + property + target bytecode defined by maven.compiler.target property + maven-plugin + + + 1.3 + ${maven.compiler.source} + diff --git a/maven-plugin-plugin/src/it/plugin-info-jdk/property/src/main/java/org/apache/maven/plugins/issues/plugin/MyMojo.java b/maven-plugin-plugin/src/it/plugin-info-jdk/property/src/main/java/org/apache/maven/plugins/issues/plugin/MyMojo.java new file mode 100644 index 0000000..ec3f1db --- /dev/null +++ b/maven-plugin-plugin/src/it/plugin-info-jdk/property/src/main/java/org/apache/maven/plugins/issues/plugin/MyMojo.java @@ -0,0 +1,84 @@ +package org.apache.maven.plugins.issues.plugin; + +/* + * 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.apache.maven.plugin.AbstractMojo; +import org.apache.maven.plugin.MojoExecutionException; + +import java.io.File; +import java.io.FileWriter; +import java.io.IOException; + +/** + * Goal which touches a timestamp file. + * + * @goal touch + * + * @phase process-sources + */ +public class MyMojo + extends AbstractMojo +{ + /** + * Location of the file. + * @parameter expression="${project.build.directory}" + * @required + */ + private File outputDirectory; + + public void execute() + throws MojoExecutionException + { + File f = outputDirectory; + + if ( !f.exists() ) + { + f.mkdirs(); + } + + File touch = new File( f, "touch.txt" ); + + FileWriter w = null; + try + { + w = new FileWriter( touch ); + + w.write( "touch.txt" ); + } + catch ( IOException e ) + { + throw new MojoExecutionException( "Error creating file " + touch, e ); + } + finally + { + if ( w != null ) + { + try + { + w.close(); + } + catch ( IOException e ) + { + // ignore + } + } + } + } +} diff --git a/maven-plugin-plugin/src/it/plugin-info-jdk/requirement/pom.xml b/maven-plugin-plugin/src/it/plugin-info-jdk/requirement/pom.xml new file mode 100644 index 0000000..5ab103f --- /dev/null +++ b/maven-plugin-plugin/src/it/plugin-info-jdk/requirement/pom.xml @@ -0,0 +1,78 @@ + + + + + + 4.0.0 + + + org.apache.maven.its.plugin-info-jdk + parent + 1.0-SNAPSHOT + + requirement + target bytecode defined by report jdk requirement configuration + maven-plugin + + + 1.3 + ${maven.compiler.source} + + + + + + + org.apache.maven.plugins + maven-compiler-plugin + + 1.4 + 1.4 + + + + + + + org.apache.maven.plugins + maven-compiler-plugin + + 1.5 + 1.5 + + + + + + + + + org.apache.maven.plugins + maven-plugin-plugin + + + 1.8 + + + + + + diff --git a/maven-plugin-plugin/src/it/plugin-info-jdk/requirement/src/main/java/org/apache/maven/plugins/issues/plugin/MyMojo.java b/maven-plugin-plugin/src/it/plugin-info-jdk/requirement/src/main/java/org/apache/maven/plugins/issues/plugin/MyMojo.java new file mode 100644 index 0000000..ec3f1db --- /dev/null +++ b/maven-plugin-plugin/src/it/plugin-info-jdk/requirement/src/main/java/org/apache/maven/plugins/issues/plugin/MyMojo.java @@ -0,0 +1,84 @@ +package org.apache.maven.plugins.issues.plugin; + +/* + * 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.apache.maven.plugin.AbstractMojo; +import org.apache.maven.plugin.MojoExecutionException; + +import java.io.File; +import java.io.FileWriter; +import java.io.IOException; + +/** + * Goal which touches a timestamp file. + * + * @goal touch + * + * @phase process-sources + */ +public class MyMojo + extends AbstractMojo +{ + /** + * Location of the file. + * @parameter expression="${project.build.directory}" + * @required + */ + private File outputDirectory; + + public void execute() + throws MojoExecutionException + { + File f = outputDirectory; + + if ( !f.exists() ) + { + f.mkdirs(); + } + + File touch = new File( f, "touch.txt" ); + + FileWriter w = null; + try + { + w = new FileWriter( touch ); + + w.write( "touch.txt" ); + } + catch ( IOException e ) + { + throw new MojoExecutionException( "Error creating file " + touch, e ); + } + finally + { + if ( w != null ) + { + try + { + w.close(); + } + catch ( IOException e ) + { + // ignore + } + } + } + } +} diff --git a/maven-plugin-plugin/src/it/plugin-info-jdk-default-property/verify.groovy b/maven-plugin-plugin/src/it/plugin-info-jdk/verify.groovy similarity index 65% rename from maven-plugin-plugin/src/it/plugin-info-jdk-default-property/verify.groovy rename to maven-plugin-plugin/src/it/plugin-info-jdk/verify.groovy index 7a02709..2b43714 100644 --- a/maven-plugin-plugin/src/it/plugin-info-jdk-default-property/verify.groovy +++ b/maven-plugin-plugin/src/it/plugin-info-jdk/verify.groovy @@ -1,4 +1,3 @@ - /* * Licensed to the Apache Software Foundation (ASF) under one * or more contributor license agreements. See the NOTICE file @@ -17,11 +16,10 @@ * specific language governing permissions and limitations * under the License. */ -assert new File( basedir, 'target/site' ).exists(); -content = new File( basedir, 'target/site/plugin-info.html' ).text; - -assert content.contains( '1.5' ); -assert !content.contains( 'Default target for maven-compiler-plugin version' ); +assert new File( basedir, 'property/target/site/plugin-info.html' ).text.contains( '1.3' ) +assert new File( basedir, 'pluginManagement/target/site/plugin-info.html' ).text.contains( '1.4' ) +assert new File( basedir, 'plugin/target/site/plugin-info.html' ).text.contains( '1.5' ) +assert new File( basedir, 'requirement/target/site/plugin-info.html' ).text.contains( '1.8' ) return true; \ No newline at end of file diff --git a/maven-plugin-plugin/src/main/java/org/apache/maven/plugin/plugin/PluginReport.java b/maven-plugin-plugin/src/main/java/org/apache/maven/plugin/plugin/PluginReport.java index 6e5ff47..5d904b0 100644 --- a/maven-plugin-plugin/src/main/java/org/apache/maven/plugin/plugin/PluginReport.java +++ b/maven-plugin-plugin/src/main/java/org/apache/maven/plugin/plugin/PluginReport.java @@ -663,10 +663,13 @@ public class PluginReport } /** - * Try to lookup on the org.apache.maven.plugins:maven-compiler-plugin plugin to - * find the value of the target option. - * If not specified, uses the value defined by the user. - * If not specified, uses the value of the system property java.specification.version. + *
    + *
  1. use configured jdk requirement
  2. + *
  3. use target configuration of org.apache.maven.plugins:maven-compiler-plugin
  4. + *
  5. use target configuration of org.apache.maven.plugins:maven-compiler-plugin in + * pluginManagement
  6. + *
  7. use maven.compiler.target property
  8. + *
* * @param project not null * @param requirements not null @@ -675,23 +678,90 @@ public class PluginReport private static String discoverJdkRequirement( MavenProject project, Requirements requirements ) { String jdk = requirements.getJdk(); - if ( jdk == null ) + + if ( jdk != null ) { - jdk = discoverJdkRequirementFromPlugins( project.getBuild().getPluginsAsMap(), - project.getProperties() ); - } - if ( jdk == null && project.getPluginManagement() != null ) - { - jdk = - discoverJdkRequirementFromPlugins( project.getPluginManagement().getPluginsAsMap(), - project.getProperties() ); - } - if ( jdk == null ) - { - jdk = "Unknown"; + return jdk; } - return jdk; + Plugin compiler = getCompilerPlugin( project.getBuild().getPluginsAsMap() ); + + jdk = getTarget( compiler ); + if ( jdk != null ) + { + return jdk; + } + + Plugin compilerManagement = getCompilerPlugin( project.getPluginManagement().getPluginsAsMap() ); + + jdk = getTarget( compilerManagement ); + if ( jdk != null ) + { + return jdk; + } + + // default value + jdk = project.getProperties().getProperty( "maven.compiler.target" ); + if ( jdk != null ) + { + return jdk; + } + + String version = getVersion( compiler ); + + if ( version == null ) + { + version = getVersion( compilerManagement ); + } + + if ( version != null ) + { + return "Default target for maven-compiler-plugin version " + version; + } + + return "Unknown"; + } + + private static Plugin getCompilerPlugin( Map pluginsAsMap ) + { + for ( Map.Entry entry : pluginsAsMap.entrySet() ) + { + if ( entry.getKey().equals( "org.apache.maven.plugins:maven-compiler-plugin" ) ) + { + return (Plugin) entry.getValue(); + } + } + return null; + } + + private static String getTarget( Plugin plugin ) + { + if ( plugin != null ) + { + Xpp3Dom pluginConf = (Xpp3Dom) plugin.getConfiguration(); + + if ( pluginConf != null ) + { + Xpp3Dom target = pluginConf.getChild( "target" ); + + if ( target != null ) + { + return target.getValue(); + } + } + } + + return null; + } + + private static String getVersion( Plugin plugin ) + { + if ( plugin != null ) + { + return plugin.getVersion(); + } + + return null; } /**