From 58a8f57588896f4c0111750af148aa844a08ed16 Mon Sep 17 00:00:00 2001 From: Herve Boutemy Date: Sun, 9 Nov 2014 23:26:29 +0000 Subject: [PATCH] [MPLUGIN-279] use default properties when no configuration in m-compiler-p git-svn-id: https://svn.apache.org/repos/asf/maven/plugin-tools/trunk@1637762 13f79535-47bb-0310-9956-ffa450edef68 --- .../invoker.properties | 18 ++++ .../plugin-info-jdk-default-property/pom.xml | 87 +++++++++++++++++++ .../maven/plugins/issues/plugin/MyMojo.java | 81 +++++++++++++++++ .../src/site/site.xml | 30 +++++++ .../verify.groovy | 27 ++++++ .../maven/plugin/plugin/PluginReport.java | 12 ++- 6 files changed, 252 insertions(+), 3 deletions(-) create mode 100644 maven-plugin-plugin/src/it/plugin-info-jdk-default-property/invoker.properties create mode 100644 maven-plugin-plugin/src/it/plugin-info-jdk-default-property/pom.xml create mode 100644 maven-plugin-plugin/src/it/plugin-info-jdk-default-property/src/main/java/org/apache/maven/plugins/issues/plugin/MyMojo.java create mode 100644 maven-plugin-plugin/src/it/plugin-info-jdk-default-property/src/site/site.xml create mode 100644 maven-plugin-plugin/src/it/plugin-info-jdk-default-property/verify.groovy diff --git a/maven-plugin-plugin/src/it/plugin-info-jdk-default-property/invoker.properties b/maven-plugin-plugin/src/it/plugin-info-jdk-default-property/invoker.properties new file mode 100644 index 0000000..abdde0d --- /dev/null +++ b/maven-plugin-plugin/src/it/plugin-info-jdk-default-property/invoker.properties @@ -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.goals = clean site -DskipTests diff --git a/maven-plugin-plugin/src/it/plugin-info-jdk-default-property/pom.xml b/maven-plugin-plugin/src/it/plugin-info-jdk-default-property/pom.xml new file mode 100644 index 0000000..5b94a65 --- /dev/null +++ b/maven-plugin-plugin/src/it/plugin-info-jdk-default-property/pom.xml @@ -0,0 +1,87 @@ + + + + + + 4.0.0 + + org.apache.maven.its + jdk-default-property + 1.0-SNAPSHOT + maven-plugin + + + UTF-8 + 1.5 + ${maven.compiler.source} + + + + + org.apache.maven + maven-plugin-api + 2.0 + + + + + + + + org.apache.maven.plugins + maven-compiler-plugin + 2.3.2 + + + + org.apache.maven.plugins + maven-plugin-plugin + @project.version@ + + + org.apache.maven.plugins + maven-site-plugin + @sitePluginVersion@ + + + + + + + + + org.apache.maven.plugins + maven-project-info-reports-plugin + 2.4 + + + org.apache.maven.plugins + maven-plugin-plugin + @project.version@ + + + + 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-default-property/src/main/java/org/apache/maven/plugins/issues/plugin/MyMojo.java new file mode 100644 index 0000000..3f2d827 --- /dev/null +++ b/maven-plugin-plugin/src/it/plugin-info-jdk-default-property/src/main/java/org/apache/maven/plugins/issues/plugin/MyMojo.java @@ -0,0 +1,81 @@ +package org.apache.maven.plugins.issues.plugin; + +/* + * Copyright 2001-2005 The Apache Software Foundation. + * + * 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 + * + * 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/src/site/site.xml b/maven-plugin-plugin/src/it/plugin-info-jdk-default-property/src/site/site.xml new file mode 100644 index 0000000..3c125b5 --- /dev/null +++ b/maven-plugin-plugin/src/it/plugin-info-jdk-default-property/src/site/site.xml @@ -0,0 +1,30 @@ + + + + + + + + + + + + diff --git a/maven-plugin-plugin/src/it/plugin-info-jdk-default-property/verify.groovy b/maven-plugin-plugin/src/it/plugin-info-jdk-default-property/verify.groovy new file mode 100644 index 0000000..7a02709 --- /dev/null +++ b/maven-plugin-plugin/src/it/plugin-info-jdk-default-property/verify.groovy @@ -0,0 +1,27 @@ + +/* + * 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. + */ +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' ); + +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 65042e9..cb4785b 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 @@ -54,6 +54,7 @@ import java.util.Iterator; import java.util.List; import java.util.Locale; import java.util.Map; +import java.util.Properties; import java.util.ResourceBundle; import java.util.Set; @@ -667,11 +668,13 @@ public class PluginReport String jdk = requirements.getJdk(); if ( jdk == null ) { - jdk = discoverJdkRequirementFromPlugins( project.getBuild().getPluginsAsMap() ); + jdk = discoverJdkRequirementFromPlugins( project.getBuild().getPluginsAsMap(), project.getProperties() ); } if ( jdk == null && project.getPluginManagement() != null ) { - jdk = discoverJdkRequirementFromPlugins( project.getPluginManagement().getPluginsAsMap() ); + jdk = + discoverJdkRequirementFromPlugins( project.getPluginManagement().getPluginsAsMap(), + project.getProperties() ); } if ( jdk == null ) { @@ -685,7 +688,7 @@ public class PluginReport * @param pluginsAsMap could be null * @return the value of the target in the configuration of maven-compiler-plugin. */ - private static String discoverJdkRequirementFromPlugins( Map pluginsAsMap ) + private static String discoverJdkRequirementFromPlugins( Map pluginsAsMap, Properties props ) { if ( pluginsAsMap == null ) { @@ -704,6 +707,9 @@ public class PluginReport Object value = entry.getValue(); Xpp3Dom pluginConf = null; + // default value + jdk = props.getProperty( "maven.compiler.target" ); + backupJdk = "Default version for maven-compiler-plugin"; if ( value instanceof Plugin ) {