Commit 23d7f5b5 authored by Matt Tucker's avatar Matt Tucker Committed by matt

Added Pack200 support to plugins (JM-860).

git-svn-id: http://svn.igniterealtime.org/svn/repos/wildfire/trunk@5598 b35dd754-fafc-0310-a699-88a17e54d16e
parent 56adf696
......@@ -1101,10 +1101,28 @@
</then>
</if>
<!-- Some JAR files don't work well through Pack200. When that's the case, they should
be manually added to this list.
-->
<property name="pack200.excludes" value="gnujaxp.jar,mail.jar,activation.jar,bouncycastle.jar"/>
<for param="jar">
<path>
<fileset dir="${plugin.dev.dest.dir}/@{plugin}/target/lib" includes="*.jar" excludes="${pack200.excludes}"/>
</path>
<sequential>
<delete file="@{jar}.pack" />
<pack200 src="@{jar}"
destfile="@{jar}.pack"
gzipoutput="false"
/>
</sequential>
</for>
<!-- Copy everything else to Wildfire's plugin dir -->
<copy todir="${plugin.dev.dest.dir}/@{plugin}/jar" overwrite="true" >
<fileset dir="${plugin.dev.dest.dir}/@{plugin}/target">
<include name="lib/*.jar"/>
<include name="lib/*.pack"/>
<include name="web/WEB-INF/web.xml"/>
<include name="web/WEB-INF/web-custom.xml"/>
</fileset>
......@@ -1123,6 +1141,11 @@
</fileset>
</copy>
<!-- Excluded pack files need to be copied over as well -->
<copy todir="${plugin.dev.dest.dir}/@{plugin}/jar/lib" overwrite="true" >
<fileset dir="${plugin.dev.dest.dir}/@{plugin}/target/lib" includes="${pack200.excludes}"/>
</copy>
<!-- Jar the plugin -->
<jar jarfile="${plugin.dest.dir}/@{plugin}.jar">
<fileset dir="${plugin.dev.dest.dir}/@{plugin}/jar"/>
......
......@@ -30,6 +30,8 @@ import java.util.concurrent.ScheduledThreadPoolExecutor;
import java.util.concurrent.TimeUnit;
import java.util.jar.JarEntry;
import java.util.jar.JarFile;
import java.util.jar.JarOutputStream;
import java.util.jar.Pack200;
import java.util.zip.ZipFile;
/**
......@@ -939,16 +941,72 @@ public class PluginManager {
}
}
zipFile.close();
// The lib directory of the plugin may contain Pack200 versions of the JAR
// file. If so, unpack them.
unpackArchives(new File(dir, "lib"));
}
catch (Exception e) {
Log.error(e);
}
}
/**
* Converts any pack files in a directory into standard JAR files. Each
* pack file will be deleted after being converted to a JAR. If no
* pack files are found, this method does nothing.
*
* @param libDir the directory containing pack files.
*/
private void unpackArchives(File libDir) {
// Get a list of all packed files in the lib directory.
File [] packedFiles = libDir.listFiles(new FilenameFilter() {
public boolean accept(File dir, String name) {
return name.endsWith(".pack");
}
});
if (packedFiles == null) {
// Do nothing since no .pack files were found
return;
}
// Unpack each.
for (File packedFile : packedFiles) {
try {
String jarName = packedFile.getName().substring(0,
packedFile.getName().length() - ".pack".length());
// Delete JAR file with same name if it exists (could be due to upgrade
// from old Wildfire release).
File jarFile = new File(libDir, jarName);
if (jarFile.exists()) {
jarFile.delete();
}
InputStream in = new BufferedInputStream(new FileInputStream(packedFile));
JarOutputStream out = new JarOutputStream(new BufferedOutputStream(
new FileOutputStream(new File(libDir, jarName))));
Pack200.Unpacker unpacker = Pack200.newUnpacker();
// Call the unpacker
unpacker.unpack(in, out);
in.close();
out.close();
packedFile.delete();
}
catch (Exception e) {
Log.error(e);
}
}
}
/**
* Deletes a directory.
*
* @param dir the directory to delete.
* @return true if the directory was deleted.
*/
public boolean deleteDir(File dir) {
private boolean deleteDir(File dir) {
if (dir.isDirectory()) {
String[] childDirs = dir.list();
// Always try to delete JAR files first since that's what will
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment