From 524e032cf9d40e2f34526d527fe27666a89c3297 Mon Sep 17 00:00:00 2001 From: david_williams <david_williams> Date: Mon, 9 Feb 2009 06:04:40 +0000 Subject: [PATCH] improve signing --- .../tools/UpdatePackPropertiesFile.java | 122 +++++++++++++++++- 1 file changed, 116 insertions(+), 6 deletions(-) diff --git a/plugins/org.eclipse.wtp.releng.tools/src/org/eclipse/wtp/releng/tools/UpdatePackPropertiesFile.java b/plugins/org.eclipse.wtp.releng.tools/src/org/eclipse/wtp/releng/tools/UpdatePackPropertiesFile.java index 800fd8975..9c9366e84 100644 --- a/plugins/org.eclipse.wtp.releng.tools/src/org/eclipse/wtp/releng/tools/UpdatePackPropertiesFile.java +++ b/plugins/org.eclipse.wtp.releng.tools/src/org/eclipse/wtp/releng/tools/UpdatePackPropertiesFile.java @@ -1,20 +1,43 @@ package org.eclipse.wtp.releng.tools; import java.io.File; +import java.io.FileInputStream; +import java.io.FileNotFoundException; +import java.io.FileOutputStream; +import java.io.FilenameFilter; import java.io.IOException; +import java.io.InputStream; +import java.io.ObjectInputStream.GetField; +import java.util.Arrays; import java.util.Enumeration; +import java.util.jar.JarEntry; +import java.util.jar.JarFile; import java.util.zip.ZipEntry; import java.util.zip.ZipFile; +import java.util.zip.ZipInputStream; import org.apache.tools.ant.BuildException; +import org.apache.tools.ant.Project; import org.apache.tools.ant.Task; public class UpdatePackPropertiesFile extends Task { + static class JarFileFilter implements FilenameFilter { + + public boolean accept(File dir, String name) { + if (name.endsWith(".jar")) { + return true; + } + return false; + } + + } + private String archiveFilename; private String packFileTemplate; - + private FilenameFilter jarFileFilter = new JarFileFilter(); + public void execute() throws BuildException { boolean invalidProperties = false; @@ -30,6 +53,7 @@ public class UpdatePackPropertiesFile extends Task { ZipFile archiveFile = null; try { archiveFile = new ZipFile(getArchiveFilename()); + archiveFile.close(); } catch (IOException e) { invalidProperties = true; @@ -43,15 +67,101 @@ public class UpdatePackPropertiesFile extends Task { if (invalidProperties) { throw new BuildException("The properties for this task are not valid. See log for more details"); } - Enumeration allEntries = archiveFile.entries(); - - while (allEntries.hasMoreElements()) { - ZipEntry zipentry = (ZipEntry) allEntries.nextElement(); - log(zipentry.getName()); + + // comma seperated list + String signedJarNames = null; + try { + signedJarNames = getSignedJarNames(); + } + catch (IOException e) { + throw new BuildException(e); } + + log(signedJarNames); } + private String getSignedJarNames() throws IOException { + String result = ""; + String tempdir = System.getProperty("java.io.tmpdir"); + + if ( !(tempdir.endsWith("/") || tempdir.endsWith("\\")) ) + tempdir = tempdir + System.getProperty("file.separator"); + + String zipfilename = getArchiveFilename(); + String destinationdirectory = tempdir + zipfilename; + extractZipStream(destinationdirectory, zipfilename); + + // we avoid short recursing since we know structure + File featureDestDir = new File(destinationdirectory + "/eclipse/features/"); + String [] jars = featureDestDir.list(jarFileFilter); + File bundlesDestDir = new File(destinationdirectory + "/eclipse/plugins/"); + String [] bundlejars = bundlesDestDir.list(jarFileFilter); + + result = checkIfJarsSigned(result, jars); + result = checkIfJarsSigned(result, bundlejars); + + return result; + } + + private String checkIfJarsSigned(String currentresults, String[] jars) throws IOException { + for (int i = 0; i < jars.length; i++) { + String jarname = jars[i]; + JarFile jarFile = new JarFile(jarname); + Enumeration jarentries = jarFile.entries(); + while (jarentries.hasMoreElements()) { + JarEntry jarentry = (JarEntry) jarentries.nextElement(); + String entryname = jarentry.getName(); + log(entryname);// Project.MSG_DEBUG + if (entryname.endsWith("ECLIPSE.SF") || entryname.endsWith("ECLIPSF.SF")) { + currentresults = currentresults + jarname + ","; + break; + } + } + } + return currentresults; + } + + private void extractZipStream(String destinationdirectory, String zipfilename) throws IOException { + + byte[] buf = new byte[1024]; + ZipInputStream zipinputstream = null; + ZipEntry zipentry; + zipinputstream = new ZipInputStream( + new FileInputStream(zipfilename)); + + zipentry = zipinputstream.getNextEntry(); + while (zipentry != null) + { + //for each entry to be extracted + String entryName = zipentry.getName(); + System.out.println("entryname "+entryName); + int n; + FileOutputStream fileoutputstream; + File newFile = new File(entryName); + String directory = newFile.getParent(); + + if(directory == null) + { + if(newFile.isDirectory()) + break; + } + + fileoutputstream = new FileOutputStream( + destinationdirectory+entryName); + + while ((n = zipinputstream.read(buf, 0, 1024)) > -1) + fileoutputstream.write(buf, 0, n); + + fileoutputstream.close(); + zipinputstream.closeEntry(); + zipentry = zipinputstream.getNextEntry(); + + }//while + + zipinputstream.close(); + } + public String getArchiveFilename() { return archiveFilename; } -- GitLab