ant-notifications mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From bode...@apache.org
Subject svn commit: r1181872 - in /ant/antlibs/compress/trunk/src: main/org/apache/ant/compress/antlib.xml main/org/apache/ant/compress/taskdefs/Pack200Normalize.java tests/antunit/pack200normalize-test.xml
Date Tue, 11 Oct 2011 16:21:43 GMT
Author: bodewig
Date: Tue Oct 11 16:21:43 2011
New Revision: 1181872

URL: http://svn.apache.org/viewvc?rev=1181872&view=rev
Log:
task that 'normalizes' jars for use with pack200

Added:
    ant/antlibs/compress/trunk/src/main/org/apache/ant/compress/taskdefs/Pack200Normalize.java
  (with props)
    ant/antlibs/compress/trunk/src/tests/antunit/pack200normalize-test.xml   (with props)
Modified:
    ant/antlibs/compress/trunk/src/main/org/apache/ant/compress/antlib.xml

Modified: ant/antlibs/compress/trunk/src/main/org/apache/ant/compress/antlib.xml
URL: http://svn.apache.org/viewvc/ant/antlibs/compress/trunk/src/main/org/apache/ant/compress/antlib.xml?rev=1181872&r1=1181871&r2=1181872&view=diff
==============================================================================
--- ant/antlibs/compress/trunk/src/main/org/apache/ant/compress/antlib.xml (original)
+++ ant/antlibs/compress/trunk/src/main/org/apache/ant/compress/antlib.xml Tue Oct 11 16:21:43
2011
@@ -76,6 +76,10 @@
      name="pack200"
      classname="org.apache.ant.compress.taskdefs.Pack200"
      />
+  <taskdef
+     name="pack200normalize"
+     classname="org.apache.ant.compress.taskdefs.Pack200Normalize"
+     />
 
   <typedef
      name="arentry"

Added: ant/antlibs/compress/trunk/src/main/org/apache/ant/compress/taskdefs/Pack200Normalize.java
URL: http://svn.apache.org/viewvc/ant/antlibs/compress/trunk/src/main/org/apache/ant/compress/taskdefs/Pack200Normalize.java?rev=1181872&view=auto
==============================================================================
--- ant/antlibs/compress/trunk/src/main/org/apache/ant/compress/taskdefs/Pack200Normalize.java
(added)
+++ ant/antlibs/compress/trunk/src/main/org/apache/ant/compress/taskdefs/Pack200Normalize.java
Tue Oct 11 16:21:43 2011
@@ -0,0 +1,106 @@
+/*
+ *  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.
+ *
+ */
+
+package org.apache.ant.compress.taskdefs;
+
+import java.io.File;
+import java.io.IOException;
+import java.util.HashMap;
+import java.util.Map;
+import org.apache.commons.compress.compressors.pack200.Pack200Utils;
+import org.apache.tools.ant.BuildException;
+import org.apache.tools.ant.Project;
+import org.apache.tools.ant.Task;
+import org.apache.tools.ant.types.Environment;
+
+/**
+ * Task to "normalize" a JAR archive so that a signature applied to it
+ * will still be valid after a pack200/unpack200 cycle.
+ *
+ * <p>As stated in <a
+ * href="http://download.oracle.com/javase/1.5.0/docs/api/java/util/jar/Pack200.Packer.html">Pack200.Packer's</a>
+ * javadocs applying a Pack200 compression to a JAR archive will in
+ * general make its sigantures invalid.  In order to prepare a JAR for
+ * signing it should be "normalized" by packing and unpacking it.
+ * This is what this task does.</p>
+ * @since Apache Compress Antlib 1.1
+ */
+public class Pack200Normalize extends Task {
+    private File src, dest;
+    private boolean force = false;
+    private Map/*<String, String>*/ properties = new HashMap();
+
+    /**
+     * The JAR archive to normalize.
+     */
+    public void setSrcFile(File s) {
+        src = s;
+    }
+
+    /**
+     * The destination archive.
+     */
+    public void setDestFile(File d) {
+        dest = d;
+    }
+
+    /**
+     * Whether to force normalization of the archive even if the
+     * destination is up-to-date.
+     *
+     * <p>You must set this to true if you don't specify a destFile or
+     * the archive will never get normalized.</p>
+     */
+    public void setForce(boolean b) {
+        force = b;
+    }
+
+    /**
+     * Sets a property for the Pack200 packer.
+     */
+    public void addConfiguredProperty(Environment.Variable prop) {
+        prop.validate();
+        properties.put(prop.getKey(), prop.getValue());
+    }
+
+    public void execute() {
+        if (src == null) {
+            throw new BuildException("srcFile attribute is required");
+        }
+        if (force ||
+            (dest != null && dest.lastModified() <= src.lastModified())) {
+            if (dest != null) {
+                log("Normalizing " + src + " to " + dest + ".");
+            } else {
+                log("Normalizing " + src + ".");
+            }
+            try {
+                Pack200Utils.normalize(src, dest, properties);
+            } catch (IOException ex) {
+                throw new BuildException("Caught an error normalizing "
+                                         + src, ex);
+            }
+        } else if (dest != null) {
+            log(src + " not normalized as " + dest + " is up-to-date.",
+                Project.MSG_VERBOSE);
+        } else {
+            log(src + " not normalized as force attribute is false.",
+                Project.MSG_VERBOSE);
+        }
+    }
+}
\ No newline at end of file

Propchange: ant/antlibs/compress/trunk/src/main/org/apache/ant/compress/taskdefs/Pack200Normalize.java
------------------------------------------------------------------------------
    svn:eol-style = native

Added: ant/antlibs/compress/trunk/src/tests/antunit/pack200normalize-test.xml
URL: http://svn.apache.org/viewvc/ant/antlibs/compress/trunk/src/tests/antunit/pack200normalize-test.xml?rev=1181872&view=auto
==============================================================================
--- ant/antlibs/compress/trunk/src/tests/antunit/pack200normalize-test.xml (added)
+++ ant/antlibs/compress/trunk/src/tests/antunit/pack200normalize-test.xml Tue Oct 11 16:21:43
2011
@@ -0,0 +1,55 @@
+<?xml version="1.0"?>
+<!--
+  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 default="antunit"
+         xmlns:au="antlib:org.apache.ant.antunit"
+         xmlns:cmp="antlib:org.apache.ant.compress">
+
+  <import file="antunit-base.xml" />
+
+  <target name="setUp">
+    <mkdir dir="${output}" />
+    <jar destfile="${output}/foo.jar">
+      <file file="${ant.file}"/>
+    </jar>
+  </target>
+
+  <target name="testSrcfileIsRequired">
+    <au:expectfailure>
+      <cmp:pack200normalize/>
+    </au:expectfailure>
+  </target>
+
+  <target name="testNormalizeSelfWithoutForceDoesntDoAnything">
+    <cmp:pack200normalize srcfile="${output}/foo.jar"/>
+    <au:assertLogContains
+        text=" not normalized as force attribute is false."
+        level="verbose"/>
+  </target>
+
+  <target name="testNormalizeDoesntDoAnythingWhenTargetIsUpToDate" depends="setUp">
+    <touch file="${output}/bar.jar"/>
+    <cmp:pack200normalize srcfile="${output}/foo.jar"
+                          destfile="${output}/bar.jar"/>
+    <au:assertLogContains
+        text=" not normalized as "
+        level="verbose"/>
+    <au:assertLogContains
+        text="bar.jar is up-to-date."
+        level="verbose"/>
+  </target>
+</project>
\ No newline at end of file

Propchange: ant/antlibs/compress/trunk/src/tests/antunit/pack200normalize-test.xml
------------------------------------------------------------------------------
    svn:eol-style = native



Mime
View raw message