use of java.util.jar.JarInputStream in project bnd by bndtools.
the class JarTest method testNewLine.
public static void testNewLine() throws Exception {
Jar jar = new Jar("dot");
Manifest manifest = new Manifest();
jar.setManifest(manifest);
String value = "Test\nTest\nTest\nTest";
String expectedValue = "Test Test Test Test";
manifest.getMainAttributes().putValue(Constants.BUNDLE_DESCRIPTION, value);
ByteArrayOutputStream bout = new ByteArrayOutputStream();
jar.write(bout);
JarInputStream jin = new JarInputStream(new ByteArrayInputStream(bout.toByteArray()));
Manifest m = jin.getManifest();
assertNotNull(m);
String parsedValue = m.getMainAttributes().getValue(Constants.BUNDLE_DESCRIPTION);
assertEquals(expectedValue, parsedValue);
}
use of java.util.jar.JarInputStream in project bndtools by bndtools.
the class BndContainerSourceManager method getSourceBundle.
private static File getSourceBundle(IPath path, Map<String, String> props) {
Workspace bndWorkspace;
try {
bndWorkspace = Central.getWorkspace();
if (bndWorkspace == null) {
return null;
}
} catch (final Exception e) {
return null;
}
IPath bundlePath = path;
IWorkspace workspace = ResourcesPlugin.getWorkspace();
IWorkspaceRoot root = workspace.getRoot();
IResource resource = root.findMember(path);
if (resource != null) {
bundlePath = resource.getLocation();
}
try (JarInputStream jarStream = new JarInputStream(IO.stream(bundlePath.toFile()), false)) {
Manifest manifest = jarStream.getManifest();
if (manifest == null) {
return null;
}
Domain domain = Domain.domain(manifest);
Entry<String, Attrs> bsnAttrs = domain.getBundleSymbolicName();
if (bsnAttrs == null) {
return null;
}
String bsn = bsnAttrs.getKey();
String version = domain.getBundleVersion();
if (version == null) {
version = props.get("version");
}
for (RepositoryPlugin repo : RepositoryUtils.listRepositories(true)) {
if (repo == null) {
continue;
}
if (repo instanceof WorkspaceRepository) {
continue;
}
File sourceBundle = repo.get(bsn + ".source", new Version(version), props);
if (sourceBundle != null) {
return sourceBundle;
}
}
} catch (final Exception e) {
// Ignore, something went wrong, or we could not find the source bundle
}
return null;
}
use of java.util.jar.JarInputStream in project geode by apache.
the class DeployedJar method registerFunctions.
/**
* Scan the JAR file and attempt to register any function classes found.
*/
public synchronized void registerFunctions() throws ClassNotFoundException {
final boolean isDebugEnabled = logger.isDebugEnabled();
if (isDebugEnabled) {
logger.debug("Registering functions with DeployedJar: {}", this);
}
ByteArrayInputStream byteArrayInputStream = new ByteArrayInputStream(this.getJarContent());
JarInputStream jarInputStream = null;
try {
List<String> functionClasses = findFunctionsInThisJar();
jarInputStream = new JarInputStream(byteArrayInputStream);
JarEntry jarEntry = jarInputStream.getNextJarEntry();
while (jarEntry != null) {
if (jarEntry.getName().endsWith(".class")) {
final String className = PATTERN_SLASH.matcher(jarEntry.getName()).replaceAll("\\.").substring(0, jarEntry.getName().length() - 6);
if (functionClasses.contains(className)) {
if (isDebugEnabled) {
logger.debug("Attempting to load class: {}, from JAR file: {}", jarEntry.getName(), this.file.getAbsolutePath());
}
try {
Class<?> clazz = ClassPathLoader.getLatest().forName(className);
Collection<Function> registerableFunctions = getRegisterableFunctionsFromClass(clazz);
for (Function function : registerableFunctions) {
FunctionService.registerFunction(function);
if (isDebugEnabled) {
logger.debug("Registering function class: {}, from JAR file: {}", className, this.file.getAbsolutePath());
}
this.registeredFunctions.add(function);
}
} catch (ClassNotFoundException | NoClassDefFoundError cnfex) {
logger.error("Unable to load all classes from JAR file: {}", this.file.getAbsolutePath(), cnfex);
throw cnfex;
}
} else {
if (isDebugEnabled) {
logger.debug("No functions found in class: {}, from JAR file: {}", jarEntry.getName(), this.file.getAbsolutePath());
}
}
}
jarEntry = jarInputStream.getNextJarEntry();
}
} catch (IOException ioex) {
logger.error("Exception when trying to read class from ByteArrayInputStream", ioex);
} finally {
if (jarInputStream != null) {
try {
jarInputStream.close();
} catch (IOException ioex) {
logger.error("Exception attempting to close JAR input stream", ioex);
}
}
}
}
use of java.util.jar.JarInputStream in project geode by apache.
the class DeployedJar method hasValidJarContent.
/**
* Peek into the JAR data and make sure that it is valid JAR content.
*
* @param inputStream InputStream containing data to be validated.
* @return True if the data has JAR content, false otherwise
*/
private static boolean hasValidJarContent(final InputStream inputStream) {
JarInputStream jarInputStream = null;
boolean valid = false;
try {
jarInputStream = new JarInputStream(inputStream);
valid = jarInputStream.getNextJarEntry() != null;
} catch (IOException ignore) {
// Ignore this exception and just return false
} finally {
try {
jarInputStream.close();
} catch (IOException ignored) {
// Ignore this exception and just return result
}
}
return valid;
}
use of java.util.jar.JarInputStream in project processdash by dtuma.
the class CustomProcessPublisher method openStartingJar.
private JarInputStream openStartingJar(String scriptStartingJar) throws IOException {
if (scriptStartingJar == null || scriptStartingJar.length() == 0)
return null;
byte[] contents = getRawFileBytes(scriptStartingJar);
if (contents == null)
return null;
ByteArrayInputStream bytesIn = new ByteArrayInputStream(contents);
return new JarInputStream(bytesIn);
}
Aggregations