Author: kevj
Date: Sat Oct 16 07:11:43 2010
New Revision: 1023199

URL: http://svn.apache.org/viewvc?rev=1023199&view=rev
Log:
-add addMin property for when you want to rename your minified files to 
file.min.js

Modified:
    ant/sandbox/antlibs/minify/trunk/src/etc/testcases/compress.xml
    
ant/sandbox/antlibs/minify/trunk/src/main/org/apache/ant/js/minify/YUICompressorTask.java

Modified: ant/sandbox/antlibs/minify/trunk/src/etc/testcases/compress.xml
URL: 
http://svn.apache.org/viewvc/ant/sandbox/antlibs/minify/trunk/src/etc/testcases/compress.xml?rev=1023199&r1=1023198&r2=1023199&view=diff
==============================================================================
--- ant/sandbox/antlibs/minify/trunk/src/etc/testcases/compress.xml (original)
+++ ant/sandbox/antlibs/minify/trunk/src/etc/testcases/compress.xml Sat Oct 16 
07:11:43 2010
@@ -55,10 +55,17 @@
            <include name="*.css"/>
          </fileset>
        </minify:yui.css>
+
+    <!-- rename to .min.js -->
+    <minify:yui.compressor verbose="false" outputPath="${outputPath}" 
linebreak="80" addMin="true" type="js">
+      <fileset dir="${testscript.dir}">
+               <include name="*.js"/>
+         </fileset>
+    </minify:yui.compressor>
+
   </target>
 
   <target name="cleanup">
-    <delete file="${output}"/>
        <delete dir="${outputPath}"/>
   </target>
 </project>
\ No newline at end of file

Modified: 
ant/sandbox/antlibs/minify/trunk/src/main/org/apache/ant/js/minify/YUICompressorTask.java
URL: 
http://svn.apache.org/viewvc/ant/sandbox/antlibs/minify/trunk/src/main/org/apache/ant/js/minify/YUICompressorTask.java?rev=1023199&r1=1023198&r2=1023199&view=diff
==============================================================================
--- 
ant/sandbox/antlibs/minify/trunk/src/main/org/apache/ant/js/minify/YUICompressorTask.java
 (original)
+++ 
ant/sandbox/antlibs/minify/trunk/src/main/org/apache/ant/js/minify/YUICompressorTask.java
 Sat Oct 16 07:11:43 2010
@@ -55,6 +55,7 @@ public class YUICompressorTask extends T
        private String lineBreak;
        private boolean preserveSemi;
        private boolean disableOptimization;
+    private boolean addMin;
        private String charset;
        private String outputPath;
        private List inputResources = new ArrayList();
@@ -79,6 +80,9 @@ public class YUICompressorTask extends T
                if(null == type || "".equals(type)) {
                        throw new BuildException("Type property must be 
specified <js|css>");
                }
+        if(!"js".equals(type) && !"css".equals(type)) {
+            throw new BuildException("Type property must be specified 
<js|css>");            
+        }
                if(null == charset || "".equals(charset)) {
                        setCharset("UTF-8");
                        log("Charset not set; using [UTF-8]");
@@ -131,11 +135,23 @@ public class YUICompressorTask extends T
 
        private Writer getWriter(FileResource f) throws IOException {
                Writer out;
+        String outputName = f.getName();
+        // convert filename from file.js to file.min.js or file.css to 
file.min.css
+        if(addMin) {
+            int fileExtensionPos = outputName.lastIndexOf(".");
+            String name = outputName.substring(0,fileExtensionPos);
+            String extension = outputName.substring(fileExtensionPos, 
outputName.length());
+            outputName = name + ".min" + extension;
+            log("\naddMin set, renaming to : " + outputName);
+        }
+
+        // set outputPath to be the same as the input path for f
+        if(null == getOutputPath() || "".equals(getOutputPath().trim())) {
+            this.outputPath = f.getBaseDir().getAbsolutePath();
+        }
                out = new OutputStreamWriter(
-                               null != getOutputPath() && 
getOutputPath().trim() != "" ?
-                                               new 
FileOutputStream(getOutputPath() + File.separator + f.getFile().getName()) :
-                                               f.getOutputStream()
-                               );
+                   new FileOutputStream(getOutputPath() + File.separator + 
outputName)
+               );
                return out;
        }
        
@@ -191,6 +207,14 @@ public class YUICompressorTask extends T
                this.nomunge = nomunge;
        }
 
+    public boolean isAddMin() {
+        return addMin;
+    }
+
+    public void setAddMin(boolean min) {
+        this.addMin = min;
+    }
+
        public String getType() {
                return type;
        }


Reply via email to