You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@ant.apache.org by gi...@apache.org on 2018/11/14 21:33:34 UTC

[1/2] ant git commit: Change an attribute name and explain why

Repository: ant
Updated Branches:
  refs/heads/master 39e5e40e3 -> e208ad936


Change an attribute name and explain why

Project: http://git-wip-us.apache.org/repos/asf/ant/repo
Commit: http://git-wip-us.apache.org/repos/asf/ant/commit/570ca183
Tree: http://git-wip-us.apache.org/repos/asf/ant/tree/570ca183
Diff: http://git-wip-us.apache.org/repos/asf/ant/diff/570ca183

Branch: refs/heads/master
Commit: 570ca18375c7562948c35d1c04a96e17aef25ebd
Parents: 39e5e40
Author: Gintas Grigelionis <gi...@apache.org>
Authored: Wed Nov 14 22:30:18 2018 +0100
Committer: Gintas Grigelionis <gi...@apache.org>
Committed: Wed Nov 14 22:30:18 2018 +0100

----------------------------------------------------------------------
 manual/Tasks/imageio.html                       | 11 +++--
 .../taskdefs/optional/image/ImageIOTask.java    | 49 ++++++++++++++------
 2 files changed, 44 insertions(+), 16 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/ant/blob/570ca183/manual/Tasks/imageio.html
----------------------------------------------------------------------
diff --git a/manual/Tasks/imageio.html b/manual/Tasks/imageio.html
index cce503c..65d6815 100644
--- a/manual/Tasks/imageio.html
+++ b/manual/Tasks/imageio.html
@@ -29,7 +29,12 @@
 <p>Applies a chain of image operations on a set of files.</p>
 <p>Uses AWT and ImageIO; replaces <a href="image.html">image</a> task for Java 9+. The task can be
 used with Java 8 as well, see parameter table for limitations.</p>
-
+<p><strong>Note</strong>: this task tries to stay as close as possible to syntax and semantics
+of <code>image</code> task. However, it uses <var>format</var> attribute rather
+than <var>encoding</var> attribute, because the latter is a misnomer: almost all tasks use similar
+attributes for character encodings in files, file names or other strings. Also,
+when <var>format</var> is not specified, its value is defined by the format of the first processed
+image file.</p>
 <h5>Overview of used datatypes</h5>
 <svg xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" fill-opacity="1"
      color-rendering="auto" color-interpolation="auto" text-rendering="auto" stroke="black"
@@ -390,12 +395,12 @@ used with Java 8 as well, see parameter table for limitations.</p>
     <td>Yes, unless nested fileset is used</td>
   </tr>
   <tr>
-    <td>encoding</td>
+    <td>format</td>
     <td>Image format.<br/>Valid (case insensitive)
       are: <q>bmp</q>, <q>gif</q>, <q>jpeg</q>, <q>jpg</q>, <q>png</q>, <q>tif</q>, <q>tiff</q>, <q>wbmp</q>
       (Java 8 VM lacks support for TIFF, which can be provided
       by <a href="../install.html#librarydependencies">external libraries</a>).</td>
-    <td>No; defaults to the format of the first original file</td>
+    <td>No; defaults to the format of the (first) original file</td>
   </tr>
   <tr>
     <td>overwrite</td>

http://git-wip-us.apache.org/repos/asf/ant/blob/570ca183/src/main/org/apache/tools/ant/taskdefs/optional/image/ImageIOTask.java
----------------------------------------------------------------------
diff --git a/src/main/org/apache/tools/ant/taskdefs/optional/image/ImageIOTask.java b/src/main/org/apache/tools/ant/taskdefs/optional/image/ImageIOTask.java
index 5e4289c..ce25c38 100644
--- a/src/main/org/apache/tools/ant/taskdefs/optional/image/ImageIOTask.java
+++ b/src/main/org/apache/tools/ant/taskdefs/optional/image/ImageIOTask.java
@@ -20,6 +20,7 @@ package org.apache.tools.ant.taskdefs.optional.image;
 import org.apache.tools.ant.BuildException;
 import org.apache.tools.ant.Project;
 import org.apache.tools.ant.taskdefs.MatchingTask;
+import org.apache.tools.ant.types.EnumeratedAttribute;
 import org.apache.tools.ant.types.FileSet;
 import org.apache.tools.ant.types.Mapper;
 import org.apache.tools.ant.types.optional.imageio.Draw;
@@ -59,7 +60,7 @@ public class ImageIOTask extends MatchingTask {
     private File srcDir = null;
     private File destDir = null;
 
-    private String format;
+    private ImageFormat outputFormat;
 
     private boolean garbageCollect = false;
 
@@ -93,11 +94,11 @@ public class ImageIOTask extends MatchingTask {
     }
 
     /**
-     * Set the image format.
-     * @param encoding the String image format.
+     * Set the output image format.
+     * @param format an ImageFormat.
      */
-    public void setEncoding(String encoding) {
-        format = encoding;
+    public void setFormat(ImageFormat format) {
+        outputFormat = format;
     }
 
     /**
@@ -281,8 +282,8 @@ public class ImageIOTask extends MatchingTask {
                 return;
             }
             ImageReader reader = readers.next();
-            if (format == null) {
-                format = reader.getFormatName();
+            if (outputFormat == null) {
+                outputFormat = new ImageFormat(reader.getFormatName());
             }
             reader.setInput(input);
 
@@ -308,7 +309,7 @@ public class ImageIOTask extends MatchingTask {
                 newFile.delete();
             }
 
-            if (!ImageIO.write(image, format, newFile)) {
+            if (!ImageIO.write(image, outputFormat.getValue(), newFile)) {
                 log("Failed to save the transformed file");
             }
         } catch (IOException | RuntimeException err) {
@@ -378,11 +379,33 @@ public class ImageIOTask extends MatchingTask {
         if (srcDir == null && destDir == null) {
             throw new BuildException("Specify the destDir, or the srcDir.");
         }
-        if (format != null && !Arrays.asList(ImageIO.getReaderFormatNames()).contains(format)) {
-            throw new BuildException("Unknown image format '" + format + "'"
-                + System.lineSeparator() + "Use any of "
-                    + Arrays.stream(ImageIO.getReaderFormatNames()).sorted()
-                    .collect(Collectors.joining(", ")));
+    }
+
+    /**
+     * defines acceptable image formats.
+     */
+    public static class ImageFormat extends EnumeratedAttribute {
+
+        private static final String[] VALUES = ImageIO.getReaderFormatNames();
+
+        /**
+         * Constructor
+         */
+        public ImageFormat() {
+        }
+
+        /**
+         * Constructor using a string.
+         * @param value the value of the attribute
+         */
+        public ImageFormat(String value) {
+            setValue(value);
+        }
+
+        /** {@inheritDoc}. */
+        @Override
+        public String[] getValues() {
+            return VALUES;
         }
     }
 }


[2/2] ant git commit: Implement ArcType as suggested

Posted by gi...@apache.org.
Implement ArcType as suggested

Project: http://git-wip-us.apache.org/repos/asf/ant/repo
Commit: http://git-wip-us.apache.org/repos/asf/ant/commit/e208ad93
Tree: http://git-wip-us.apache.org/repos/asf/ant/tree/e208ad93
Diff: http://git-wip-us.apache.org/repos/asf/ant/diff/e208ad93

Branch: refs/heads/master
Commit: e208ad936016e871412d19848ea15db54f8e8b52
Parents: 570ca18
Author: Gintas Grigelionis <gi...@apache.org>
Authored: Wed Nov 14 22:32:21 2018 +0100
Committer: Gintas Grigelionis <gi...@apache.org>
Committed: Wed Nov 14 22:32:21 2018 +0100

----------------------------------------------------------------------
 .../tools/ant/types/optional/imageio/Arc.java   | 65 ++++++++++++++++----
 1 file changed, 52 insertions(+), 13 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/ant/blob/e208ad93/src/main/org/apache/tools/ant/types/optional/imageio/Arc.java
----------------------------------------------------------------------
diff --git a/src/main/org/apache/tools/ant/types/optional/imageio/Arc.java b/src/main/org/apache/tools/ant/types/optional/imageio/Arc.java
index 0fdbaf7..be79317 100644
--- a/src/main/org/apache/tools/ant/types/optional/imageio/Arc.java
+++ b/src/main/org/apache/tools/ant/types/optional/imageio/Arc.java
@@ -17,10 +17,14 @@
  */
 package org.apache.tools.ant.types.optional.imageio;
 
+import org.apache.tools.ant.types.EnumeratedAttribute;
+
 import java.awt.BasicStroke;
 import java.awt.Graphics2D;
 import java.awt.geom.Arc2D;
 import java.awt.image.BufferedImage;
+import java.util.ArrayList;
+import java.util.List;
 
 /**
  * Draw an arc.
@@ -28,7 +32,7 @@ import java.awt.image.BufferedImage;
 public class Arc extends BasicShape implements DrawOperation {
     private int start = 0;
     private int stop = 0;
-    private int type = Arc2D.OPEN;
+    private ArcType type = ArcType.getDefault();
 
     /**
      * Set the start of the arc.
@@ -48,17 +52,10 @@ public class Arc extends BasicShape implements DrawOperation {
 
     /**
      * Set the type of arc.
-     * @param strType the type to use - open, pie or chord.
-     * @todo refactor using an EnumeratedAttribute
+     * @param arcType the type to use - open, pie or chord.
      */
-    public void setType(String strType) {
-        if ("open".equalsIgnoreCase(strType)) {
-            type = Arc2D.OPEN;
-        } else if ("pie".equalsIgnoreCase(strType)) {
-            type = Arc2D.PIE;
-        } else if ("chord".equalsIgnoreCase(strType)) {
-            type = Arc2D.CHORD;
-        }
+    public void setType(ArcType arcType) {
+        type = arcType;
     }
 
     /** {@inheritDoc}. */
@@ -74,13 +71,13 @@ public class Arc extends BasicShape implements DrawOperation {
             graphics.setColor(ColorMapper.getColorByName(stroke));
             graphics.setStroke(bStroke);
             graphics.draw(new Arc2D.Double(strokeWidth, strokeWidth, width,
-                height, start, stop, type));
+                height, start, stop, type.getIndex()));
         }
 
         if (!"transparent".equalsIgnoreCase(fill)) {
             graphics.setColor(ColorMapper.getColorByName(fill));
             graphics.fill(new Arc2D.Double(strokeWidth, strokeWidth,
-                width, height, start, stop, type));
+                width, height, start, stop, type.getIndex()));
         }
 
         for (ImageOperation instr : instructions) {
@@ -94,4 +91,46 @@ public class Arc extends BasicShape implements DrawOperation {
         }
         return bi;
     }
+
+    public static class ArcType extends EnumeratedAttribute {
+
+        private static final List<String> VALUES = new ArrayList<>();
+
+        static {
+            VALUES.add(Arc2D.OPEN, "open");
+            VALUES.add(Arc2D.CHORD, "chord");
+            VALUES.add(Arc2D.PIE, "pie");
+        }
+
+        /**
+         * Constructor
+         */
+        public ArcType() {
+        }
+
+        /**
+         * Constructor using a string.
+         * @param value the value of the attribute
+         */
+        public ArcType(String value) {
+            setValue(value);
+        }
+
+        /**
+         * Get the default ArcType value.
+         * @return the default value.
+         */
+        public static ArcType getDefault() {
+            return new ArcType(VALUES.get(0));
+        }
+
+        /**
+         * @see EnumeratedAttribute#getValues()
+         * {@inheritDoc}.
+         */
+        @Override
+        public String[] getValues() {
+            return VALUES.toArray(new String[0]);
+        }
+    }
 }