maven-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From pg...@apache.org
Subject svn commit: r1004461 - in /maven/plugins/trunk/maven-antrun-plugin/src: it/task-encoding-test/ it/task-encoding-test/pom.xml main/java/org/apache/maven/plugin/antrun/AntRunMojo.java
Date Mon, 04 Oct 2010 22:22:31 GMT
Author: pgier
Date: Mon Oct  4 22:22:30 2010
New Revision: 1004461

URL: http://svn.apache.org/viewvc?rev=1004461&view=rev
Log:
[MANTRUN-155] Set encoding for generated Ant build.  Patch from Anders Hammar with some minor
changes.

Added:
    maven/plugins/trunk/maven-antrun-plugin/src/it/task-encoding-test/
    maven/plugins/trunk/maven-antrun-plugin/src/it/task-encoding-test/pom.xml   (with props)
Modified:
    maven/plugins/trunk/maven-antrun-plugin/src/main/java/org/apache/maven/plugin/antrun/AntRunMojo.java

Added: maven/plugins/trunk/maven-antrun-plugin/src/it/task-encoding-test/pom.xml
URL: http://svn.apache.org/viewvc/maven/plugins/trunk/maven-antrun-plugin/src/it/task-encoding-test/pom.xml?rev=1004461&view=auto
==============================================================================
--- maven/plugins/trunk/maven-antrun-plugin/src/it/task-encoding-test/pom.xml (added)
+++ maven/plugins/trunk/maven-antrun-plugin/src/it/task-encoding-test/pom.xml Mon Oct  4 22:22:30
2010
@@ -0,0 +1,61 @@
+<?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.plugins.antrun</groupId>
+  <artifactId>mantrun-155</artifactId>
+  <version>1.0-SNAPSHOT</version>
+  <packaging>pom</packaging>
+
+  <name>mantrun-155</name>
+
+  <properties>
+    <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
+  </properties>
+
+  <build>
+    <plugins>
+      <plugin>
+        <groupId>org.apache.maven.plugins</groupId>
+        <artifactId>maven-antrun-plugin</artifactId>
+        <version>@pom.version@</version>
+        <executions>
+          <execution>
+            <id>antrun</id>
+            <phase>test</phase>
+            <goals>
+              <goal>run</goal>
+            </goals>
+            <configuration>
+              <tasks>
+                <!-- non-ASCII chars: ÅÄÖ -->
+                <echo message="non-ASCII chars: ÅÄÖ" />
+              </tasks>
+            </configuration>
+          </execution>
+        </executions>
+      </plugin>
+    </plugins>
+  </build>
+</project>

Propchange: maven/plugins/trunk/maven-antrun-plugin/src/it/task-encoding-test/pom.xml
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: maven/plugins/trunk/maven-antrun-plugin/src/it/task-encoding-test/pom.xml
------------------------------------------------------------------------------
    svn:keywords = Author Date Id Revision

Modified: maven/plugins/trunk/maven-antrun-plugin/src/main/java/org/apache/maven/plugin/antrun/AntRunMojo.java
URL: http://svn.apache.org/viewvc/maven/plugins/trunk/maven-antrun-plugin/src/main/java/org/apache/maven/plugin/antrun/AntRunMojo.java?rev=1004461&r1=1004460&r2=1004461&view=diff
==============================================================================
--- maven/plugins/trunk/maven-antrun-plugin/src/main/java/org/apache/maven/plugin/antrun/AntRunMojo.java
(original)
+++ maven/plugins/trunk/maven-antrun-plugin/src/main/java/org/apache/maven/plugin/antrun/AntRunMojo.java
Mon Oct  4 22:22:30 2010
@@ -82,6 +82,11 @@ public class AntRunMojo
     public final static String DEFAULT_ANT_TARGET_NAME = "main";
 
     /**
+     * The default encoding to use for the generated Ant build.
+     */
+    public final static String DEFAULT_ANT_BUILD_ENCODING = "UTF-8";
+
+    /**
      * The name used for the ant target
      */
     private String antTargetName;
@@ -452,6 +457,12 @@ public class AntRunMojo
     private File writeTargetToProjectFile()
         throws IOException, PlexusConfigurationException
     {
+        String encoding = project.getProperties().getProperty( "project.build.sourceEncoding"
);
+        if ( encoding == null )
+        {
+            encoding = DEFAULT_ANT_BUILD_ENCODING;
+        }
+        
         // Have to use an XML writer because in Maven 2.x the PlexusConfig toString() method
loses XML attributes
         StringWriter writer = new StringWriter();
         AntrunXmlPlexusConfigurationWriter xmlWriter = new AntrunXmlPlexusConfigurationWriter();
@@ -477,6 +488,8 @@ public class AntRunMojo
             xmlns = "xmlns:" + customTaskPrefix + "=\"" + TASK_URI + "\""; 
         }
         
+        final String xmlHeader = "<?xml version=\"1.0\" encoding=\"" + encoding + "\"
?>\n";
+        antProjectConfig.insert( 0, xmlHeader );
         final String projectOpen = "<project name=\"maven-antrun-\" default=\"" + antTargetName
+ "\" " + xmlns +" >\n";
         int index = antProjectConfig.indexOf( "<target" );
         antProjectConfig.insert( index, projectOpen );
@@ -489,7 +502,7 @@ public class AntRunMojo
         File buildFile = new File( project.getBuild().getDirectory(), "/antrun/" + fileName
);
 
         buildFile.getParentFile().mkdirs();
-        FileUtils.fileWrite( buildFile.getAbsolutePath(), antProjectConfig.toString() );
+        FileUtils.fileWrite( buildFile.getAbsolutePath(), encoding, antProjectConfig.toString()
);
         return buildFile;
     }
 



Mime
View raw message