use of java.util.jar.JarFile in project jetty.project by eclipse.
the class MetaInfConfiguration method getTlds.
/**
* Find all .tld files in the given jar.
*
* @param uri the uri to jar file
* @return the collection of tlds as url references
* @throws IOException if unable to scan the jar file
*/
public Collection<URL> getTlds(URI uri) throws IOException {
HashSet<URL> tlds = new HashSet<URL>();
String jarUri = uriJarPrefix(uri, "!/");
URL url = new URL(jarUri);
JarURLConnection jarConn = (JarURLConnection) url.openConnection();
jarConn.setUseCaches(Resource.getDefaultUseCaches());
JarFile jarFile = jarConn.getJarFile();
Enumeration<JarEntry> entries = jarFile.entries();
while (entries.hasMoreElements()) {
JarEntry e = entries.nextElement();
String name = e.getName();
if (name.startsWith("META-INF") && name.endsWith(".tld")) {
tlds.add(new URL(jarUri + name));
}
}
if (!Resource.getDefaultUseCaches())
jarFile.close();
return tlds;
}
use of java.util.jar.JarFile in project buck by facebook.
the class AndroidAarIntegrationTest method testBuildAndroidAar.
@Test
public void testBuildAndroidAar() throws IOException {
ProjectWorkspace workspace = TestDataHelper.createProjectWorkspaceForScenario(this, "android_aar_build/caseA", tmp);
workspace.setUp();
String target = "//:app";
workspace.runBuckBuild(target).assertSuccess();
Path aar = workspace.getPath(BuildTargets.getGenPath(filesystem, BuildTargetFactory.newInstance(target), AndroidAar.AAR_FORMAT));
ZipInspector zipInspector = new ZipInspector(aar);
zipInspector.assertFileExists("AndroidManifest.xml");
zipInspector.assertFileExists("classes.jar");
zipInspector.assertFileExists("R.txt");
zipInspector.assertFileExists("assets/a.txt");
zipInspector.assertFileExists("assets/b.txt");
zipInspector.assertFileExists("res/raw/helloworld.txt");
zipInspector.assertFileExists("res/values/values.xml");
zipInspector.assertFileContents("res/values/values.xml", workspace.getFileContents("res/values/A.xml").trim());
Path contents = tmp.getRoot().resolve("aar-contents");
Unzip.extractZipFile(aar, contents, Unzip.ExistingFileMode.OVERWRITE);
try (JarFile classes = new JarFile(contents.resolve("classes.jar").toFile())) {
assertThat(classes.getJarEntry("com/example/HelloWorld.class"), Matchers.notNullValue());
}
}
use of java.util.jar.JarFile in project jetty.project by eclipse.
the class JarFileResource method exists.
/* ------------------------------------------------------------ */
/**
* Returns true if the represented resource exists.
*/
@Override
public boolean exists() {
if (_exists)
return true;
if (_urlString.endsWith("!/")) {
String file_url = _urlString.substring(4, _urlString.length() - 2);
try {
return newResource(file_url).exists();
} catch (Exception e) {
LOG.ignore(e);
return false;
}
}
boolean check = checkConnection();
// Is this a root URL?
if (_jarUrl != null && _path == null) {
// Then if it exists it is a directory
_directory = check;
return true;
} else {
// Can we find a file for it?
boolean close_jar_file = false;
JarFile jar_file = null;
if (check)
// Yes
jar_file = _jarFile;
else {
// No - so lets look if the root entry exists.
try {
JarURLConnection c = (JarURLConnection) ((new URL(_jarUrl)).openConnection());
c.setUseCaches(getUseCaches());
jar_file = c.getJarFile();
close_jar_file = !getUseCaches();
} catch (Exception e) {
LOG.ignore(e);
}
}
// Do we need to look more closely?
if (jar_file != null && _entry == null && !_directory) {
// OK - we have a JarFile, lets look for the entry
JarEntry entry = jar_file.getJarEntry(_path);
if (entry == null) {
// the entry does not exist
_exists = false;
} else if (entry.isDirectory()) {
_directory = true;
_entry = entry;
} else {
// Let's confirm is a file
JarEntry directory = jar_file.getJarEntry(_path + '/');
if (directory != null) {
_directory = true;
_entry = directory;
} else {
// OK is a file
_directory = false;
_entry = entry;
}
}
}
if (close_jar_file && jar_file != null) {
try {
jar_file.close();
} catch (IOException ioe) {
LOG.ignore(ioe);
}
}
}
_exists = (_directory || _entry != null);
return _exists;
}
use of java.util.jar.JarFile in project storm by apache.
the class Utils method extractDirFromJarImpl.
public void extractDirFromJarImpl(String jarpath, String dir, File destdir) {
try (JarFile jarFile = new JarFile(jarpath)) {
Enumeration<JarEntry> jarEnums = jarFile.entries();
while (jarEnums.hasMoreElements()) {
JarEntry entry = jarEnums.nextElement();
if (!entry.isDirectory() && entry.getName().startsWith(dir)) {
File aFile = new File(destdir, entry.getName());
aFile.getParentFile().mkdirs();
try (FileOutputStream out = new FileOutputStream(aFile);
InputStream in = jarFile.getInputStream(entry)) {
IOUtils.copy(in, out);
}
}
}
} catch (IOException e) {
LOG.info("Could not extract {} from {}", dir, jarpath);
}
}
use of java.util.jar.JarFile in project enumerable by hraberg.
the class LambdaCompiler method compilieJar.
void compilieJar(File jar) throws Exception {
try {
JarFile jarFile = new JarFile(jar);
if (jarFile.getEntry(AOT_COMPILED_MARKER) != null) {
out.println(jar + " is already compiled, skipping.");
return;
}
File tempDir = unjar(jarFile);
File aotCompiledMarker = new File(tempDir, AOT_COMPILED_MARKER);
aotCompiledMarker.getParentFile().mkdir();
aotCompiledMarker.createNewFile();
ensureCreated(aotCompiledMarker);
compileDirectory(tempDir);
debug("writing generated lambdas in " + jar);
writeGeneratedLambdas(tempDir);
File newJar = jar(tempDir);
File bak = new File(jar.getAbsolutePath() + ".bak");
rename(jar, bak);
ensureCreated(bak);
rename(newJar, jar);
ensureCreated(jar);
delete(bak);
delete(tempDir);
} catch (Exception e) {
throw uncheck(e);
}
}
Aggregations