You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@maven.apache.org by hb...@apache.org on 2017/12/20 09:27:28 UTC

[maven-ant-plugin] 19/48: [MANT-36] Use correct file encoding when writing build files

This is an automated email from the ASF dual-hosted git repository.

hboutemy pushed a commit to annotated tag maven-ant-plugin-2.1
in repository https://gitbox.apache.org/repos/asf/maven-ant-plugin.git

commit 43be7874f1db76b2379115639377f0efeb2e08e1
Author: Benjamin Bentmann <be...@apache.org>
AuthorDate: Fri Mar 21 16:18:35 2008 +0000

    [MANT-36] Use correct file encoding when writing build files
    
    git-svn-id: https://svn.apache.org/repos/asf/maven/plugins/trunk/maven-ant-plugin@639695 13f79535-47bb-0310-9956-ffa450edef68
---
 pom.xml                                            |  6 +--
 src/it/encoding-it/goals.txt                       |  2 +
 src/it/encoding-it/pom.xml                         | 43 ++++++++++++++++++++++
 src/it/encoding-it/verify.bsh                      | 30 +++++++++++++++
 .../apache/maven/plugin/ant/AntBuildWriter.java    | 20 +++++++---
 5 files changed, 91 insertions(+), 10 deletions(-)

diff --git a/pom.xml b/pom.xml
index 0e8a758..29f505c 100644
--- a/pom.xml
+++ b/pom.xml
@@ -203,14 +203,12 @@ under the License.
           <plugin>
             <groupId>org.apache.maven.plugins</groupId>
             <artifactId>maven-invoker-plugin</artifactId>
-            <version>1.0</version>
+            <version>1.1</version>
             <configuration>
               <debug>true</debug>
               <projectsDirectory>src/it</projectsDirectory>
               <pomIncludes>
-                <pomInclude>ear-it/pom.xml</pomInclude>
-                <pomInclude>webapp-it/pom.xml</pomInclude>
-                <pomInclude>plugin-it/pom.xml</pomInclude>
+                <pomInclude>*/pom.xml</pomInclude>
               </pomIncludes>
               <postBuildHookScript>verify.bsh</postBuildHookScript>
               <goals>
diff --git a/src/it/encoding-it/goals.txt b/src/it/encoding-it/goals.txt
new file mode 100644
index 0000000..16cd63b
--- /dev/null
+++ b/src/it/encoding-it/goals.txt
@@ -0,0 +1,2 @@
+ant:ant
+initialize
diff --git a/src/it/encoding-it/pom.xml b/src/it/encoding-it/pom.xml
new file mode 100644
index 0000000..5a1afc4
--- /dev/null
+++ b/src/it/encoding-it/pom.xml
@@ -0,0 +1,43 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<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/maven-v4_0_0.xsd">
+  <modelVersion>4.0.0</modelVersion>
+
+  <groupId>org.apache.maven.plugins.maven-ant-plugin.it</groupId>
+  <artifactId>encoding-it</artifactId>
+  <version>1.0-SNAPSHOT</version>
+
+  <build>
+    <!-- some non-ascii characters here -->
+    <finalName>encoding-it-&#x00E4;&#x00F6;&#x00FC;&#x00DF;</finalName>
+    <plugins>
+      <plugin>
+        <groupId>org.apache.maven.plugins</groupId>
+        <artifactId>maven-ant-plugin</artifactId>
+        <version>2.1-SNAPSHOT</version>
+      </plugin>
+      <plugin>
+        <groupId>org.apache.maven.plugins</groupId>
+        <artifactId>maven-antrun-plugin</artifactId>
+        <version>1.1</version>
+        <executions>
+          <execution>
+            <phase>initialize</phase>
+            <configuration>
+              <tasks>
+                <!-- delete the properties file to prevent fallback, we want only stuff from the XML file -->
+                <delete file="${basedir}/maven-build.properties"/>
+                <ant dir="${basedir}" antfile="${basedir}/build.xml" target="package" />
+              </tasks>
+            </configuration>
+            <goals>
+              <goal>run</goal>
+            </goals>
+          </execution>
+        </executions>
+      </plugin>
+    </plugins>
+  </build>
+
+</project>
diff --git a/src/it/encoding-it/verify.bsh b/src/it/encoding-it/verify.bsh
new file mode 100644
index 0000000..d4f9d86
--- /dev/null
+++ b/src/it/encoding-it/verify.bsh
@@ -0,0 +1,30 @@
+import java.io.*;
+import java.util.*;
+
+try
+{
+    File targetDir = new File( basedir, "target" );
+    File[] files = targetDir.listFiles();
+    for ( int i = 0; i < files.length; i++ )
+    {
+        File file = files[i];
+        if ( file.getName().toLowerCase( Locale.ENGLISH ).endsWith( ".jar" ) )
+        {
+            if ( file.getName().indexOf( '?' ) >= 0 )
+            {
+                System.err.println( "JAR file name contains corrupted characters: " + file );
+                return false;
+            }
+            return true;
+        }
+    }
+    System.err.println( "Could not find generated JAR file" );
+    return false;
+}
+catch( Throwable t )
+{
+    t.printStackTrace();
+    return false;
+}
+
+return true;
diff --git a/src/main/java/org/apache/maven/plugin/ant/AntBuildWriter.java b/src/main/java/org/apache/maven/plugin/ant/AntBuildWriter.java
index c111fcb..1011dc8 100644
--- a/src/main/java/org/apache/maven/plugin/ant/AntBuildWriter.java
+++ b/src/main/java/org/apache/maven/plugin/ant/AntBuildWriter.java
@@ -21,8 +21,8 @@ package org.apache.maven.plugin.ant;
 
 import java.io.File;
 import java.io.FileOutputStream;
-import java.io.FileWriter;
 import java.io.IOException;
+import java.io.OutputStreamWriter;
 import java.util.Collections;
 import java.util.Iterator;
 import java.util.List;
@@ -232,9 +232,13 @@ public class AntBuildWriter
         throws IOException
     {
         // TODO: parameter
-        FileWriter w = new FileWriter( new File( project.getBasedir(), DEFAULT_MAVEN_BUILD_FILENAME ) );
+        File outputFile = new File( project.getBasedir(), DEFAULT_MAVEN_BUILD_FILENAME );
 
-        XMLWriter writer = new PrettyPrintXMLWriter( w, StringUtils.repeat( " ", DEFAULT_INDENTATION_SIZE ), "UTF-8",
+        String encoding = "UTF-8";
+
+        OutputStreamWriter w = new OutputStreamWriter( new FileOutputStream( outputFile ), encoding );
+
+        XMLWriter writer = new PrettyPrintXMLWriter( w, StringUtils.repeat( " ", DEFAULT_INDENTATION_SIZE ), encoding,
                                                      null );
 
         // ----------------------------------------------------------------------
@@ -322,14 +326,18 @@ public class AntBuildWriter
     private void writeBuildXml()
         throws IOException
     {
-        if ( new File( project.getBasedir(), DEFAULT_BUILD_FILENAME ).exists() && !overwrite )
+        File outputFile = new File( project.getBasedir(), DEFAULT_BUILD_FILENAME );
+
+        if ( outputFile.exists() && !overwrite )
         {
             return;
         }
 
-        FileWriter w = new FileWriter( new File( project.getBasedir(), DEFAULT_BUILD_FILENAME ) );
+        String encoding = "UTF-8";
+
+        OutputStreamWriter w = new OutputStreamWriter( new FileOutputStream( outputFile ), encoding );
 
-        XMLWriter writer = new PrettyPrintXMLWriter( w, StringUtils.repeat( " ", DEFAULT_INDENTATION_SIZE ), "UTF-8",
+        XMLWriter writer = new PrettyPrintXMLWriter( w, StringUtils.repeat( " ", DEFAULT_INDENTATION_SIZE ), encoding,
                                                      null );
 
         // ----------------------------------------------------------------------

-- 
To stop receiving notification emails like this one, please contact
"commits@maven.apache.org" <co...@maven.apache.org>.