Bug 476225: Add property to specify input and output directories

Now it's possible to specify the directories:
- where the SVGs are taken from
- where the PNGs are written to
- where the GIFs (for the galleries) are located

Change-Id: I902a73a4e09197f32b0cbd2fa6c82afdbc0e5698
Signed-off-by: Matthias Becker <ma.becker@sap.com>
diff --git a/bundles/org.eclipse.ui.images.renderer/README.md b/bundles/org.eclipse.ui.images.renderer/README.md
index f7dc7fc..0c15d0f 100644
--- a/bundles/org.eclipse.ui.images.renderer/README.md
+++ b/bundles/org.eclipse.ui.images.renderer/README.md
@@ -25,6 +25,8 @@
 
 eclipse.svg.scale - an integer that is used to scale output images (e.g. 2 will render a 16x16 svg at 32x32)
 eclipse.svg.renderthreads - an integer that specifies how many threads to use simultaneously while rendering
+eclipse.svg.sourcedirectory - a string that specifies the directory name where the SVGs are taken from (defaults to "eclipse-svg")
+eclipse.svg.targetdirectory - a string that specifies the directory name where the PNGs are written to (defaults to "eclipse-png")
 
 Once the icon sets have been rendered, you can create galleries for evaluation and feedback with the gallery mojo:
 
@@ -32,6 +34,11 @@
 
 This will create a set of galleries and gif comparisons comprised of the newly rendered icons, located in the target/ output directory.
 
+Supported runtime arguments :
+
+eclipse.svg.pngdirectory - a string that specifies the directory name where the PNGs are taken from (defaults to "eclipse-png")
+eclipse.svg.gifdirectory - a string that specifies the directory name where the GIFs are taken from (defaults to "eclipse-gif")
+
 License
 -------
 
diff --git a/bundles/org.eclipse.ui.images.renderer/src/main/java/org/eclipse/ui/images/renderer/GalleryMojo.java b/bundles/org.eclipse.ui.images.renderer/src/main/java/org/eclipse/ui/images/renderer/GalleryMojo.java
index 09f706d..cd0e0ec 100644
--- a/bundles/org.eclipse.ui.images.renderer/src/main/java/org/eclipse/ui/images/renderer/GalleryMojo.java
+++ b/bundles/org.eclipse.ui.images.renderer/src/main/java/org/eclipse/ui/images/renderer/GalleryMojo.java
@@ -44,23 +44,43 @@
  */
 public class GalleryMojo extends AbstractMojo {
 
-	/** Maven logger */
+    /** Maven logger */
     Log log;
 
     /** Used for finding gif files by extension. */
     public static final String GIF_EXT = ".gif";
+    
+    /** Used to specify the directory name where the SVGs are taken from. */
+    public static final String PNG_DIR = "eclipse.svg.pngdirectory";
 
-	/**
-	 * <p>Mojo takes rendered images and generates various galleries for
-	 * testing and evaluation.</p>
-	 */
+    /** Used to specify the directory name where the SVGs are taken from. */
+    public static final String GIF_DIR = "eclipse.svg.gifdirectory"; 
+
+    /**
+     * <p>Mojo takes rendered images and generates various galleries for
+     * testing and evaluation.</p>
+     */
     public void execute() throws MojoExecutionException, MojoFailureException {
         log = getLog();
-        
-        File iconDirectoryRoot = new File("eclipse-png/");
+
+        // Defaults to "eclipse-png"
+        String pngDir = "eclipse-png";
+        String pngDirProp = System.getProperty(PNG_DIR);
+        if (pngDirProp != null) {
+            pngDir = pngDirProp;
+        }
+
+        // Defaults to "eclipse-gif"
+        String gifDir = "eclipse-gif";
+        String gifDirProp = System.getProperty(GIF_DIR);
+        if (gifDirProp != null) {
+            gifDir = gifDirProp;
+        }
+
+        File iconDirectoryRoot = new File(pngDir + "/");
 
         Map<String, List<IconEntry>> galleryIconSets = new HashMap<>();
-        
+
         // Search each subdir in the root dir for svg icons
         for (File file : iconDirectoryRoot.listFiles()) {
             if(!file.isDirectory()) {
@@ -69,7 +89,7 @@
 
             List<IconEntry> icons = new ArrayList<>();
             IconGatherer.gatherIcons(icons, "png", file, file, iconDirectoryRoot, false);
-            
+
             galleryIconSets.put(file.getName(), icons);
         }
 
@@ -77,33 +97,35 @@
         File galleryDir = new File(mavenTargetDir, "gallery/");
         File gifCompare = new File(galleryDir, "gifcompare/");
         File master = new File(galleryDir, "master/");
-        
+
         if(galleryDir.exists()) {
-        	galleryDir.delete();
+            galleryDir.delete();
         }
 
-    	galleryDir.mkdirs();
-    	gifCompare.mkdirs();
-    	master.mkdirs();
-    	
-        renderGalleries(galleryDir, gifCompare, master, galleryIconSets, 16, 800);
+        galleryDir.mkdirs();
+        gifCompare.mkdirs();
+        master.mkdirs();
+
+        renderGalleries(galleryDir, gifCompare, master, galleryIconSets, 16, 800, pngDir, gifDir);
     }
-    
+
     /**
      * <p>Renders each icon set into a gallery image for reviewing and showing off
      * icons, and then composes them into a master gallery image.</p>
-     * 
+     *
      * @param rasterizer
      * @param galleryDir
-     * @param gifCompare 
-     * @param master 
+     * @param gifCompare
+     * @param master
      * @param iconSize
      * @param width
+     * @param pngDir
+     * @param gifDir
      */
-    public void renderGalleries(File galleryDir,  File gifCompare, File master, Map<String, List<IconEntry>> iconSets, int iconSize, int width) {
+    public void renderGalleries(File galleryDir,  File gifCompare, File master, Map<String, List<IconEntry>> iconSets, int iconSize, int width, String pngDir, String gifDir) {
         // Render each icon set and a master list
         List<IconEntry> masterList = new ArrayList<>();
-        
+
         for (Entry<String, List<IconEntry>> entry : iconSets.entrySet()) {
             String key = entry.getKey();
             List<IconEntry> value = entry.getValue();
@@ -112,36 +134,38 @@
 
             log.info("Creating gallery for: " + key);
             renderGallery(galleryDir, key, value, iconSize, width, 3);
-            renderGifCompareGallery(gifCompare, key, value, iconSize, width, 6);
+            renderGifCompareGallery(gifCompare, key, value, iconSize, width, 6, pngDir, gifDir);
         }
 
         // Render the master image
         log.info("Rendering master icon gallery...");
         renderMasterGallery(galleryDir, master, "-gallery.png", iconSize, iconSize + width, true);
         renderMasterGallery(galleryDir, master, "-gallery.png", iconSize, iconSize + width, false);
-        
+
         // Master gif compare
         //renderMasterGallery(outputDir, "-gifcompare.png", iconSize, iconSize + width, false);
     }
 
-	/**
+    /**
      * <p>Renders comparison images, the new png/svg icons vs old gifs.</p>
-     * 
+     *
      * @param outputDir
      * @param key
      * @param icons
      * @param iconSize
      * @param width
      * @param margin
+     * @param pngDir
+     * @param gifDir
      */
-    private void renderGifCompareGallery(File outputDir, String key, List<IconEntry> icons, int iconSize, int width, int margin) {
-    	int leftColumnWidth = 300;
-    	int textHeaderHeight = 31;
+    private void renderGifCompareGallery(File outputDir, String key, List<IconEntry> icons, int iconSize, int width, int margin, String pngDir, String gifDir) {
+        int leftColumnWidth = 300;
+        int textHeaderHeight = 31;
         int outputSize = iconSize;
         int widthTotal = (outputSize * 4) + (margin * 6) + leftColumnWidth;
-        
+
         int rowHeight = iconSize + (margin * 2);
-        
+
         // Compute the height and add some room for the text header (31 px)
         int height = (icons.size() * rowHeight) + textHeaderHeight;
 
@@ -182,42 +206,42 @@
             if (entry.inputPath == null) {
                 continue;
             }
-            
+
             try {
                 BufferedImage pngImage = ImageIO.read(entry.inputPath);
 
                 // Munge the gif path
                 File gifLocalPath = new File(entry.inputPath.getParentFile(), entry.nameBase + GIF_EXT);
                 String absoluteLocalPath = gifLocalPath.getAbsolutePath();
-                String gifAbsPath = absoluteLocalPath.replaceFirst("eclipse-png", "eclipse-gif");
+                String gifAbsPath = absoluteLocalPath.replaceFirst(pngDir, gifDir);
                 File gifPath = new File(gifAbsPath);
 
-            	log.debug("Search for GIF...");
-            	log.debug("Entry path: " + entry.inputPath.getAbsolutePath());
-            	log.debug("GIF path: " + gifPath.getAbsolutePath());
-            	
+                log.debug("Search for GIF...");
+                log.debug("Entry path: " + entry.inputPath.getAbsolutePath());
+                log.debug("GIF path: " + gifPath.getAbsolutePath());
+
                 BufferedImage gifImage = null;
-                
+
                 if(gifPath.exists()) {
-                	gifImage = ImageIO.read(gifPath);
+                    gifImage = ImageIO.read(gifPath);
                 } else {
-                	log.debug("GIF not found: " + gifPath.getAbsolutePath());
+                    log.debug("GIF not found: " + gifPath.getAbsolutePath());
                 }
-                
+
                 g.drawString(entry.nameBase, 5, y + (margin * 3));
 
                 g.drawLine(0, y, widthTotal, y);
-                
+
                 if(gifImage != null) {
-                	g.drawImage(gifImage, leftColumnWidth, y + margin, null);
+                    g.drawImage(gifImage, leftColumnWidth, y + margin, null);
                 }
-                
+
                 g.drawImage(pngImage, second, y + margin, null);
-                
+
                 if(gifImage != null) {
-                	g.drawImage(gifImage, second + margin + iconSize + 30, y + margin, null);
+                    g.drawImage(gifImage, second + margin + iconSize + 30, y + margin, null);
                 }
-                
+
                 g.drawImage(pngImage, second + (margin * 2) + (iconSize * 2) + 30, y + margin, null);
 
                 y += iconSize + margin * 2;
@@ -230,18 +254,18 @@
 
         try {
             // Write the gallery image to disk
-        	String outputName = key + "-" + iconSize + "-gifcompare.png";
+            String outputName = key + "-" + iconSize + "-gifcompare.png";
             ImageIO.write(bi, "PNG", new File(outputDir, outputName));
         } catch (IOException e) {
             e.printStackTrace();
             log.error("Error writing gif comparison gallery: " + e.getMessage());
         }
     }
-    
-    
+
+
     /**
      * <p>Renders an icon set into a grid within an image.</p>
-     * 
+     *
      * @param outputRoot
      * @param key
      * @param icons
@@ -287,7 +311,7 @@
                     log.error("Undefined gallery image for : " + def.nameBase);
                     continue;
                 }
-                
+
                 BufferedImage iconImage = ImageIO.read(def.inputPath);
                 BufferedImage sizedImage = resampleOp.filter(iconImage, null);
 
@@ -308,7 +332,7 @@
 
         try {
             // Write the gallery image to disk
-        	String outputName = key + "-" + iconSize + "-gallery.png";
+            String outputName = key + "-" + iconSize + "-gallery.png";
             ImageIO.write(bi, "PNG", new File(outputRoot, outputName));
         } catch (IOException e) {
             log.error("Error writing icon: " + e.getMessage());
diff --git a/bundles/org.eclipse.ui.images.renderer/src/main/java/org/eclipse/ui/images/renderer/RenderMojo.java b/bundles/org.eclipse.ui.images.renderer/src/main/java/org/eclipse/ui/images/renderer/RenderMojo.java
index d2c563a..362614e 100644
--- a/bundles/org.eclipse.ui.images.renderer/src/main/java/org/eclipse/ui/images/renderer/RenderMojo.java
+++ b/bundles/org.eclipse.ui.images.renderer/src/main/java/org/eclipse/ui/images/renderer/RenderMojo.java
@@ -68,6 +68,12 @@
     /** Used to specify the number of render threads when rasterizing icons. */
     public static final String RENDERTHREADS = "eclipse.svg.renderthreads";
 
+    /** Used to specify the directory name where the SVGs are taken from. */
+    public static final String SOURCE_DIR = "eclipse.svg.sourcedirectory";
+
+    /** Used to specify the directory name where the PNGs are saved to. */
+    public static final String TARGET_DIR = "eclipse.svg.targetdirectory";
+
     /** A list of directories with svg sources to rasterize. */
     private List<IconEntry> icons;
 
@@ -326,7 +332,7 @@
             // Create the callable and add it to the task pool
             Callable<Object> runnable = new Callable<Object>() {
                 @Override
-				public Object call() throws Exception {
+                public Object call() throws Exception {
                     // The jhlabs filters are not thread safe, so provide one set per thread
                     GrayscaleFilter grayFilter = new GrayscaleFilter();
 
@@ -503,6 +509,20 @@
             }
         }
 
+        // Defaults to "eclipse-svg"
+        String sourceDir = "eclipse-svg";
+        String sourceDirProp = System.getProperty(SOURCE_DIR);
+        if (sourceDirProp != null) {
+            sourceDir = sourceDirProp;
+        }
+
+        // Defaults to "eclipse-png"
+        String targetDir = "eclipse-png";
+        String targetDirProp = System.getProperty(TARGET_DIR);
+        if (targetDirProp != null) {
+            targetDir = targetDirProp;
+        }
+
         // Track the time it takes to render the entire set
         long totalStartTime = System.currentTimeMillis();
 
@@ -511,8 +531,8 @@
 
         String workingDirectory = System.getProperty("user.dir");
 
-        File outputDir = new File(workingDirectory + (iconScale == 1 ? "/eclipse-png/" : "/eclipse-png-highdpi/"));
-        File iconDirectoryRoot = new File("eclipse-svg/");
+        File outputDir = new File(workingDirectory + (iconScale == 1 ? "/" + targetDir + "/" : "/" + targetDir + "-highdpi/"));
+        File iconDirectoryRoot = new File(sourceDir + "/");
 
         // Search each subdir in the root dir for svg icons
         for (File file : iconDirectoryRoot.listFiles()) {