This is an automated email from the ASF dual-hosted git repository.
gnodet pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/maven-plugin-tools.git
The following commit(s) were added to refs/heads/master by this push:
new b1bc1c6e [MPLUGIN-390] Do not overwrite generate files with no content
change (#67)
b1bc1c6e is described below
commit b1bc1c6e4d3068462593c749fc27253805f396b7
Author: Guillaume Nodet <[email protected]>
AuthorDate: Tue Oct 11 14:12:59 2022 +0200
[MPLUGIN-390] Do not overwrite generate files with no content change (#67)
---
.../src/it/mplugin-390/invoker.properties | 19 ++++
maven-plugin-plugin/src/it/mplugin-390/pom.xml | 114 +++++++++++++++++++++
.../org/apache/maven/plugin/coreit/FirstMojo.java | 53 ++++++++++
.../src/it/mplugin-390/verify.groovy | 29 ++++++
.../generator/PluginDescriptorGenerator.java | 10 +-
.../plugin/generator/PluginHelpGenerator.java | 9 +-
.../plugin/generator/PluginXdocGenerator.java | 4 +-
7 files changed, 227 insertions(+), 11 deletions(-)
diff --git a/maven-plugin-plugin/src/it/mplugin-390/invoker.properties
b/maven-plugin-plugin/src/it/mplugin-390/invoker.properties
new file mode 100644
index 00000000..f8ed77e2
--- /dev/null
+++ b/maven-plugin-plugin/src/it/mplugin-390/invoker.properties
@@ -0,0 +1,19 @@
+# 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.1 = process-classes
+invoker.goals.2 = process-classes
diff --git a/maven-plugin-plugin/src/it/mplugin-390/pom.xml
b/maven-plugin-plugin/src/it/mplugin-390/pom.xml
new file mode 100644
index 00000000..75ed4247
--- /dev/null
+++ b/maven-plugin-plugin/src/it/mplugin-390/pom.xml
@@ -0,0 +1,114 @@
+<?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/xsd/maven-4.0.0.xsd">
+ <modelVersion>4.0.0</modelVersion>
+
+ <groupId>org.apache.maven.its.mplugin-390</groupId>
+ <artifactId>mplugin-390</artifactId>
+ <version>1.0-SNAPSHOT</version>
+ <packaging>maven-plugin</packaging>
+
+ <name>Maven Integration Test :: mplugin-390</name>
+ <description>
+ Test plugin-plugin, plugin.xml descriptor - shouldn't contain dependencies
in provided scope
+ </description>
+
+ <properties>
+ <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
+ </properties>
+
+ <dependencies>
+ <dependency>
+ <groupId>org.apache.maven</groupId>
+ <artifactId>maven-plugin-api</artifactId>
+ <version>@mavenVersion@</version>
+ <scope>provided</scope>
+ </dependency>
+ <dependency>
+ <groupId>org.apache.maven.plugin-tools</groupId>
+ <artifactId>maven-plugin-annotations</artifactId>
+ <version>@project.version@</version>
+ <scope>provided</scope>
+ </dependency>
+
+ <!-- dependency in compile scope -->
+ <dependency>
+ <groupId>org.apache.commons</groupId>
+ <artifactId>commons-math3</artifactId>
+ <version>3.6.1</version>
+ </dependency>
+
+ <!-- dependency in runtime scope -->
+ <dependency>
+ <groupId>org.apache.commons</groupId>
+ <artifactId>commons-rng-client-api</artifactId>
+ <version>1.4</version>
+ <scope>runtime</scope>
+ </dependency>
+
+ </dependencies>
+
+ <build>
+ <pluginManagement>
+ <plugins>
+ <plugin>
+ <groupId>org.apache.maven.plugins</groupId>
+ <artifactId>maven-compiler-plugin</artifactId>
+ <version>3.8.1</version>
+ <configuration>
+ <source>1.8</source>
+ <target>1.8</target>
+ </configuration>
+ </plugin>
+ </plugins>
+ </pluginManagement>
+
+ <plugins>
+ <plugin>
+ <groupId>org.apache.maven.plugins</groupId>
+ <artifactId>maven-antrun-plugin</artifactId>
+ <version>3.0.0</version>
+ <executions>
+ <execution>
+ <id>touch</id>
+ <phase>generate-resources</phase>
+ <goals>
+ <goal>run</goal>
+ </goals>
+ <configuration>
+ <target>
+ <touch file="${project.build.directory}/touch.txt"/>
+ <sleep milliseconds="100"/>
+ </target>
+ </configuration>
+ </execution>
+ </executions>
+ </plugin>
+ <plugin>
+ <groupId>org.apache.maven.plugins</groupId>
+ <artifactId>maven-plugin-plugin</artifactId>
+ <version>@project.version@</version>
+ </plugin>
+ </plugins>
+
+ </build>
+</project>
diff --git
a/maven-plugin-plugin/src/it/mplugin-390/src/main/java/org/apache/maven/plugin/coreit/FirstMojo.java
b/maven-plugin-plugin/src/it/mplugin-390/src/main/java/org/apache/maven/plugin/coreit/FirstMojo.java
new file mode 100644
index 00000000..b8f7f62c
--- /dev/null
+++
b/maven-plugin-plugin/src/it/mplugin-390/src/main/java/org/apache/maven/plugin/coreit/FirstMojo.java
@@ -0,0 +1,53 @@
+package org.apache.maven.plugin.coreit;
+
+/*
+ * 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 org.apache.maven.plugins.annotations.Component;
+import org.apache.maven.plugins.annotations.ResolutionScope;
+import org.apache.maven.plugins.annotations.Execute;
+import org.apache.maven.plugins.annotations.LifecyclePhase;
+import org.apache.maven.plugins.annotations.Mojo;
+import org.apache.maven.plugins.annotations.Parameter;
+
+/**
+ * Touches a test file.
+ *
+ * @since 1.2
+ */
+@Mojo( name = "first", requiresDependencyResolution = ResolutionScope.TEST,
defaultPhase = LifecyclePhase.INTEGRATION_TEST )
+public class FirstMojo
+ extends AbstractMojo
+{
+
+ /**
+ * @since 0.1
+ * @deprecated As of 0.2
+ */
+ @Parameter( alias = "alias" )
+ private String aliasedParam;
+
+ public void execute()
+ throws MojoExecutionException
+ {
+ // nothing
+ }
+}
diff --git a/maven-plugin-plugin/src/it/mplugin-390/verify.groovy
b/maven-plugin-plugin/src/it/mplugin-390/verify.groovy
new file mode 100644
index 00000000..000ea824
--- /dev/null
+++ b/maven-plugin-plugin/src/it/mplugin-390/verify.groovy
@@ -0,0 +1,29 @@
+/*
+ * 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.
+ */
+
+File descriptorFile = new File( basedir,
"target/classes/META-INF/maven/plugin.xml" );
+assert descriptorFile.isFile()
+
+File touchFile = new File( basedir, "target/touch.txt" );
+assert touchFile.isFile()
+
+// the touch file should be newer than the descriptor
+assert touchFile.lastModified() > descriptorFile.lastModified()
+
+return true;
diff --git
a/maven-plugin-tools-generators/src/main/java/org/apache/maven/tools/plugin/generator/PluginDescriptorGenerator.java
b/maven-plugin-tools-generators/src/main/java/org/apache/maven/tools/plugin/generator/PluginDescriptorGenerator.java
index 70581131..cfa41389 100644
---
a/maven-plugin-tools-generators/src/main/java/org/apache/maven/tools/plugin/generator/PluginDescriptorGenerator.java
+++
b/maven-plugin-tools-generators/src/main/java/org/apache/maven/tools/plugin/generator/PluginDescriptorGenerator.java
@@ -20,7 +20,6 @@ package org.apache.maven.tools.plugin.generator;
*/
import java.io.File;
-import java.io.FileOutputStream;
import java.io.IOException;
import java.io.OutputStreamWriter;
import java.io.Writer;
@@ -39,6 +38,7 @@ import org.apache.maven.tools.plugin.ExtendedMojoDescriptor;
import org.apache.maven.tools.plugin.PluginToolsRequest;
import org.apache.maven.tools.plugin.util.PluginUtils;
import org.codehaus.plexus.util.StringUtils;
+import org.codehaus.plexus.util.io.CachingOutputStream;
import org.codehaus.plexus.util.xml.PrettyPrintXMLWriter;
import org.codehaus.plexus.util.xml.XMLWriter;
@@ -89,16 +89,12 @@ public class PluginDescriptorGenerator
{
PluginDescriptor pluginDescriptor = request.getPluginDescriptor();
- if ( destinationFile.exists() )
- {
- destinationFile.delete();
- }
- else if ( !destinationFile.getParentFile().exists() )
+ if ( !destinationFile.getParentFile().exists() )
{
destinationFile.getParentFile().mkdirs();
}
- try ( Writer writer = new OutputStreamWriter( new FileOutputStream(
destinationFile ), UTF_8 ) )
+ try ( Writer writer = new OutputStreamWriter( new CachingOutputStream(
destinationFile ), UTF_8 ) )
{
XMLWriter w = new PrettyPrintXMLWriter( writer, UTF_8.name(), null
);
diff --git
a/maven-plugin-tools-generators/src/main/java/org/apache/maven/tools/plugin/generator/PluginHelpGenerator.java
b/maven-plugin-tools-generators/src/main/java/org/apache/maven/tools/plugin/generator/PluginHelpGenerator.java
index 9149712c..79ef6cba 100644
---
a/maven-plugin-tools-generators/src/main/java/org/apache/maven/tools/plugin/generator/PluginHelpGenerator.java
+++
b/maven-plugin-tools-generators/src/main/java/org/apache/maven/tools/plugin/generator/PluginHelpGenerator.java
@@ -23,15 +23,17 @@ import java.io.File;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
+import java.io.OutputStreamWriter;
import java.io.StringWriter;
+import java.io.Writer;
import org.apache.maven.project.MavenProject;
import org.apache.velocity.VelocityContext;
import org.codehaus.plexus.logging.AbstractLogEnabled;
import org.codehaus.plexus.logging.Logger;
import org.codehaus.plexus.logging.console.ConsoleLogger;
-import org.codehaus.plexus.util.FileUtils;
import org.codehaus.plexus.util.StringUtils;
+import org.codehaus.plexus.util.io.CachingOutputStream;
import org.codehaus.plexus.velocity.VelocityComponent;
import static java.nio.charset.StandardCharsets.UTF_8;
@@ -84,7 +86,10 @@ public class PluginHelpGenerator
String helpClassSources =
getHelpClassSources( getPluginHelpPath( mavenProject ) );
- FileUtils.fileWrite( helpClass, UTF_8.name(), helpClassSources );
+ try ( Writer w = new OutputStreamWriter( new CachingOutputStream(
helpClass ), UTF_8 ) )
+ {
+ w.write( helpClassSources );
+ }
}
catch ( IOException e )
{
diff --git
a/maven-plugin-tools-generators/src/main/java/org/apache/maven/tools/plugin/generator/PluginXdocGenerator.java
b/maven-plugin-tools-generators/src/main/java/org/apache/maven/tools/plugin/generator/PluginXdocGenerator.java
index c17ec595..481dc5a0 100644
---
a/maven-plugin-tools-generators/src/main/java/org/apache/maven/tools/plugin/generator/PluginXdocGenerator.java
+++
b/maven-plugin-tools-generators/src/main/java/org/apache/maven/tools/plugin/generator/PluginXdocGenerator.java
@@ -27,11 +27,11 @@ import org.apache.maven.project.MavenProject;
import org.apache.maven.tools.plugin.ExtendedMojoDescriptor;
import org.apache.maven.tools.plugin.PluginToolsRequest;
import org.codehaus.plexus.util.StringUtils;
+import org.codehaus.plexus.util.io.CachingOutputStream;
import org.codehaus.plexus.util.xml.PrettyPrintXMLWriter;
import org.codehaus.plexus.util.xml.XMLWriter;
import java.io.File;
-import java.io.FileOutputStream;
import java.io.IOException;
import java.io.OutputStreamWriter;
import java.io.PrintWriter;
@@ -133,7 +133,7 @@ public class PluginXdocGenerator
throws IOException
{
File outputFile = new File( destinationDirectory, getMojoFilename(
mojoDescriptor, "xml" ) );
- try ( Writer writer = new OutputStreamWriter( new FileOutputStream(
outputFile ), UTF_8 ) )
+ try ( Writer writer = new OutputStreamWriter( new CachingOutputStream(
outputFile ), UTF_8 ) )
{
XMLWriter w = new PrettyPrintXMLWriter( new PrintWriter( writer ),
UTF_8.name(), null );
writeBody( mojoDescriptor, w );