IsSignedpublic class IsSigned extends org.apache.tools.ant.types.DataType implements ConditionChecks whether a jarfile is signed: if the name of the
signature is passed, the file is checked for presence of that
particular signature; otherwise the file is checked for the
existence of any signature. |
Fields Summary |
---|
private static final String | SIG_START | private static final String | SIG_END | private static final int | SHORT_SIG_LIMIT | private String | name | private File | file |
Methods Summary |
---|
public boolean | eval()Returns true if the file exists and is signed with
the signature specified, or, if name wasn't
specified, if the file contains a signature.
if (file == null) {
throw new BuildException("The file attribute must be set.");
}
if (file != null && !file.exists()) {
log("The file \"" + file.getAbsolutePath()
+ "\" does not exist.", Project.MSG_VERBOSE);
return false;
}
boolean r = false;
try {
r = isSigned(file, name);
} catch (IOException e) {
log("Got IOException reading file \"" + file.getAbsolutePath()
+ "\"" + e, Project.MSG_WARN);
}
if (r) {
log("File \"" + file.getAbsolutePath() + "\" is signed.",
Project.MSG_VERBOSE);
}
return r;
| public static boolean | isSigned(java.io.File zipFile, java.lang.String name)Returns true if the file exists and is signed with
the signature specified, or, if name wasn't
specified, if the file contains a signature.
ZipFile jarFile = null;
try {
jarFile = new ZipFile(zipFile);
if (null == name) {
Enumeration entries = jarFile.getEntries();
while (entries.hasMoreElements()) {
String eName = ((ZipEntry) entries.nextElement()).getName();
if (eName.startsWith(SIG_START)
&& eName.endsWith(SIG_END)) {
return true;
}
}
return false;
}
boolean shortSig = jarFile.getEntry(SIG_START
+ name.toUpperCase()
+ SIG_END) != null;
boolean longSig = false;
if (name.length() > SHORT_SIG_LIMIT) {
longSig = jarFile.getEntry(
SIG_START
+ name.substring(0, SHORT_SIG_LIMIT).toUpperCase()
+ SIG_END) != null;
}
return shortSig || longSig;
} finally {
ZipFile.closeQuietly(jarFile);
}
| public void | setFile(java.io.File file)The jarfile that is to be tested for the presence
of a signature.
this.file = file;
| public void | setName(java.lang.String name)The signature name to check jarfile for.
this.name = name;
|
|