We are signing a lot of jar files in our build. At the moment it takes between 60-80% of the total build time, changing it from 15 min to 45+ min. We are therefore very interested in speeding up the signing process by parallelizing it.

All jars are in one folder, and right now our script looks something like this:

<property name="jars.dir" location="......" />
<signJar ...paswords etc... />
  <fileset dir="${jars.dir}" includes="**/*.jar" />
</signJar>

I can't trivially use the parallel tag, since all jars are in one folder, so we need some other way to make it parallel. The build will be running on many different computers and servers, so it is important that the solution is flexible enough to handle a varying number of cores.

Hope some of you can help. Thanks :)

有帮助吗?

解决方案

You can use the for task to iterate over your fileset of jars and then sign each jar with a call to the signJar task. The for task has also a parallel option and properties for controlling concurrency.

其他提示

FWIW, here's a macro I use to sign and pack JARs for webstart. This adds the required manifest attributes and normalizes the JAR for signing by repacking it.

This macro works just fine when invoked from within a parallel <for> loop.

You'll need to tweak the <signjar> task with your key info.

<!-- Macro for JAR signing and pack200 -->
<macrodef name="sign-and-pack">
    <attribute name="jar"/>
    <sequential>
        <echo message="Signing and packing @{jar}..."/>

        <!-- Kill any existing signatures and delete existing manifest -->
        <exec executable="zip" logError="true" failonerror="false">
            <arg value="-d"/>
            <arg value="--quiet"/>
            <arg value="@{jar}"/>
            <arg value="META-INF/MANIFEST.MF"/>
            <arg value="META-INF/*.SF"/>
            <arg value="META-INF/*.DSA"/>
            <arg value="META-INF/*.RSA"/>
        </exec>

        <!-- Rebuild manifest with the required attributes -->
        <jar update="true" file="@{jar}">
            <manifest>
                <attribute name="Application-Name" value="${webstart.app.name}"/>
                <attribute name="Permissions" value="all-permissions"/>
                <attribute name="Codebase" value="*"/>
                <attribute name="Trusted-Only" value="true"/>
            </manifest>
        </jar>

        <!-- Pack and unpack JAR to normalize it -->
        <exec executable="pack200" logError="true" failonerror="true">
            <arg value="--quiet"/>
            <arg value="--repack"/>
            <arg value="@{jar}"/>
        </exec>

        <!-- Sign JAR -->
        <signjar keystore="mykeystore.p12" storetype="pkcs12" storepass="secret123" jar="@{jar}"
          alias="my key alias"/>

        <!-- Compress JAR -->
        <exec executable="pack200" logError="true" failonerror="true">
            <arg value="--quiet"/>
            <arg value="--modification-time=latest"/>
            <arg value="@{jar}.pack.gz"/>
            <arg value="@{jar}"/>
        </exec>
    </sequential>
</macrodef>
许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top