Skip to content
Snippets Groups Projects
Commit 524e032c authored by david_williams's avatar david_williams
Browse files

improve signing

parent 3e2e3d83
No related branches found
No related tags found
No related merge requests found
package org.eclipse.wtp.releng.tools; package org.eclipse.wtp.releng.tools;
import java.io.File; 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.IOException;
import java.io.InputStream;
import java.io.ObjectInputStream.GetField;
import java.util.Arrays;
import java.util.Enumeration; import java.util.Enumeration;
import java.util.jar.JarEntry;
import java.util.jar.JarFile;
import java.util.zip.ZipEntry; import java.util.zip.ZipEntry;
import java.util.zip.ZipFile; import java.util.zip.ZipFile;
import java.util.zip.ZipInputStream;
import org.apache.tools.ant.BuildException; import org.apache.tools.ant.BuildException;
import org.apache.tools.ant.Project;
import org.apache.tools.ant.Task; import org.apache.tools.ant.Task;
public class UpdatePackPropertiesFile extends 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 archiveFilename;
private String packFileTemplate; private String packFileTemplate;
private FilenameFilter jarFileFilter = new JarFileFilter();
public void execute() throws BuildException { public void execute() throws BuildException {
boolean invalidProperties = false; boolean invalidProperties = false;
...@@ -30,6 +53,7 @@ public class UpdatePackPropertiesFile extends Task { ...@@ -30,6 +53,7 @@ public class UpdatePackPropertiesFile extends Task {
ZipFile archiveFile = null; ZipFile archiveFile = null;
try { try {
archiveFile = new ZipFile(getArchiveFilename()); archiveFile = new ZipFile(getArchiveFilename());
archiveFile.close();
} }
catch (IOException e) { catch (IOException e) {
invalidProperties = true; invalidProperties = true;
...@@ -43,15 +67,101 @@ public class UpdatePackPropertiesFile extends Task { ...@@ -43,15 +67,101 @@ public class UpdatePackPropertiesFile extends Task {
if (invalidProperties) { if (invalidProperties) {
throw new BuildException("The properties for this task are not valid. See log for more details"); throw new BuildException("The properties for this task are not valid. See log for more details");
} }
Enumeration allEntries = archiveFile.entries();
// comma seperated list
while (allEntries.hasMoreElements()) { String signedJarNames = null;
ZipEntry zipentry = (ZipEntry) allEntries.nextElement(); try {
log(zipentry.getName()); 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() { public String getArchiveFilename() {
return archiveFilename; return archiveFilename;
} }
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment