use of java.util.jar.Manifest in project elasticsearch by elastic.
the class JarHellTests method testBadJDKVersionInJar.
public void testBadJDKVersionInJar() throws Exception {
Path dir = createTempDir();
Manifest manifest = new Manifest();
Attributes attributes = manifest.getMainAttributes();
attributes.put(Attributes.Name.MANIFEST_VERSION, "1.0.0");
attributes.put(new Attributes.Name("X-Compile-Target-JDK"), "bogus");
URL[] jars = { makeJar(dir, "foo.jar", manifest, "Foo.class") };
try {
JarHell.checkJarHell(jars);
fail("did not get expected exception");
} catch (IllegalStateException e) {
assertTrue(e.getMessage().equals("version string must be a sequence of nonnegative decimal integers separated by \".\"'s and may have leading zeros but was bogus"));
}
}
use of java.util.jar.Manifest in project elasticsearch by elastic.
the class JarHellTests method testRequiredJDKVersionIsOK.
public void testRequiredJDKVersionIsOK() throws Exception {
Path dir = createTempDir();
Manifest manifest = new Manifest();
Attributes attributes = manifest.getMainAttributes();
attributes.put(Attributes.Name.MANIFEST_VERSION, "1.0.0");
attributes.put(new Attributes.Name("X-Compile-Target-JDK"), "1.7");
URL[] jars = { makeJar(dir, "foo.jar", manifest, "Foo.class") };
JarHell.checkJarHell(jars);
}
use of java.util.jar.Manifest in project elasticsearch by elastic.
the class JarHellTests method testGoodESVersionInJar.
/** make sure if a plugin is compiled against the same ES version, it works */
public void testGoodESVersionInJar() throws Exception {
Path dir = createTempDir();
Manifest manifest = new Manifest();
Attributes attributes = manifest.getMainAttributes();
attributes.put(Attributes.Name.MANIFEST_VERSION, "1.0.0");
attributes.put(new Attributes.Name("X-Compile-Elasticsearch-Version"), Version.CURRENT.toString());
URL[] jars = { makeJar(dir, "foo.jar", manifest, "Foo.class") };
JarHell.checkJarHell(jars);
}
use of java.util.jar.Manifest in project elasticsearch by elastic.
the class JarHellTests method testBadESVersionInJar.
/** make sure if a plugin is compiled against a different ES version, it fails */
public void testBadESVersionInJar() throws Exception {
Path dir = createTempDir();
Manifest manifest = new Manifest();
Attributes attributes = manifest.getMainAttributes();
attributes.put(Attributes.Name.MANIFEST_VERSION, "1.0.0");
attributes.put(new Attributes.Name("X-Compile-Elasticsearch-Version"), "1.0-bogus");
URL[] jars = { makeJar(dir, "foo.jar", manifest, "Foo.class") };
try {
JarHell.checkJarHell(jars);
fail("did not get expected exception");
} catch (IllegalStateException e) {
assertTrue(e.getMessage().contains("requires Elasticsearch 1.0-bogus"));
}
}
use of java.util.jar.Manifest in project jetty.project by eclipse.
the class SelectiveJarResource method copyTo.
/**
* @see org.eclipse.jetty.util.resource.JarResource#copyTo(java.io.File)
*/
@Override
public void copyTo(File directory) throws IOException {
if (_includes == null)
_includes = DEFAULT_INCLUDES;
if (_excludes == null)
_excludes = DEFAULT_EXCLUDES;
//parts of the jar file are copied
if (!exists())
return;
String urlString = this.getURL().toExternalForm().trim();
int endOfJarUrl = urlString.indexOf("!/");
int startOfJarUrl = (endOfJarUrl >= 0 ? 4 : 0);
if (endOfJarUrl < 0)
throw new IOException("Not a valid jar url: " + urlString);
URL jarFileURL = new URL(urlString.substring(startOfJarUrl, endOfJarUrl));
try (InputStream is = jarFileURL.openConnection().getInputStream();
JarInputStream jin = new JarInputStream(is)) {
JarEntry entry;
while ((entry = jin.getNextJarEntry()) != null) {
String entryName = entry.getName();
LOG.debug("Looking at " + entryName);
String dotCheck = entryName.replace('\\', '/');
dotCheck = URIUtil.canonicalPath(dotCheck);
if (dotCheck == null) {
LOG.info("Invalid entry: " + entryName);
continue;
}
File file = new File(directory, entryName);
if (entry.isDirectory()) {
if (isIncluded(entryName)) {
if (!isExcluded(entryName)) {
// Make directory
if (!file.exists())
file.mkdirs();
} else
LOG.debug("{} dir is excluded", entryName);
} else
LOG.debug("{} dir is NOT included", entryName);
} else {
//entry is a file, is it included?
if (isIncluded(entryName)) {
if (!isExcluded(entryName)) {
// make directory (some jars don't list dirs)
File dir = new File(file.getParent());
if (!dir.exists())
dir.mkdirs();
// Make file
try (OutputStream fout = new FileOutputStream(file)) {
IO.copy(jin, fout);
}
// touch the file.
if (entry.getTime() >= 0)
file.setLastModified(entry.getTime());
} else
LOG.debug("{} file is excluded", entryName);
} else
LOG.debug("{} file is NOT included", entryName);
}
}
Manifest manifest = jin.getManifest();
if (manifest != null) {
if (isIncluded("META-INF") && !isExcluded("META-INF")) {
File metaInf = new File(directory, "META-INF");
metaInf.mkdir();
File f = new File(metaInf, "MANIFEST.MF");
try (OutputStream fout = new FileOutputStream(f)) {
manifest.write(fout);
}
}
}
}
}
Aggregations