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 2020/06/12 10:59:29 UTC
[maven-gpg-plugin] branch stabilize updated: Apply deleteOnExit
after file creation
This is an automated email from the ASF dual-hosted git repository.
rfscholte pushed a commit to branch stabilize
in repository https://gitbox.apache.org/repos/asf/maven-gpg-plugin.git
The following commit(s) were added to refs/heads/stabilize by this push:
new b30e52a Apply deleteOnExit after file creation
b30e52a is described below
commit b30e52abb9ca0b48f8c6e70d174c63b60ee8b1bc
Author: rfscholte <rf...@apache.org>
AuthorDate: Fri Jun 12 12:59:22 2020 +0200
Apply deleteOnExit after file creation
---
.../maven/plugins/gpg/SignAndDeployFileMojo.java | 23 +++++++++++++---------
1 file changed, 14 insertions(+), 9 deletions(-)
diff --git a/src/main/java/org/apache/maven/plugins/gpg/SignAndDeployFileMojo.java b/src/main/java/org/apache/maven/plugins/gpg/SignAndDeployFileMojo.java
index b7bc314..75e2ab2 100644
--- a/src/main/java/org/apache/maven/plugins/gpg/SignAndDeployFileMojo.java
+++ b/src/main/java/org/apache/maven/plugins/gpg/SignAndDeployFileMojo.java
@@ -22,8 +22,10 @@ package org.apache.maven.plugins.gpg;
import java.io.File;
import java.io.FileNotFoundException;
import java.io.IOException;
+import java.io.OutputStream;
import java.io.Reader;
-import java.io.Writer;
+import java.nio.file.Files;
+import java.nio.file.Path;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
@@ -61,7 +63,6 @@ import org.apache.maven.shared.transfer.artifact.deploy.ArtifactDeployerExceptio
import org.codehaus.plexus.util.FileUtils;
import org.codehaus.plexus.util.ReaderFactory;
import org.codehaus.plexus.util.StringUtils;
-import org.codehaus.plexus.util.WriterFactory;
import org.codehaus.plexus.util.xml.pull.XmlPullParserException;
/**
@@ -551,18 +552,22 @@ public class SignAndDeployFileMojo
throws MojoExecutionException
{
Model model = generateModel();
-
try
{
- File tempFile = File.createTempFile( "mvndeploy", ".pom" );
- tempFile.deleteOnExit();
-
- try ( Writer fw = WriterFactory.newXmlWriter( tempFile ) )
+ Path tempFile = Files.createTempFile( "mvndeploy", ".pom" );
+ try ( OutputStream out = Files.newOutputStream( tempFile ) )
{
- new MavenXpp3Writer().write( fw, model );
+ new MavenXpp3Writer().write( out, model );
}
+ catch ( IOException e )
+ {
+ throw new MojoExecutionException( "Error writing temporary pom file: " + e.getMessage(), e );
+ }
+
+ File generatedPom = tempFile.toFile();
+ generatedPom.deleteOnExit();
- return tempFile;
+ return generatedPom;
}
catch ( IOException e )
{