use of java.util.jar.Attributes in project cxf by apache.
the class ProcessorTestBase method getClassPath.
protected String getClassPath() throws URISyntaxException, IOException {
ClassLoader loader = getClass().getClassLoader();
StringBuilder classPath = new StringBuilder();
if (loader instanceof URLClassLoader) {
for (URL url : ((URLClassLoader) loader).getURLs()) {
File file = new File(url.toURI());
String filename = file.getAbsolutePath();
if (filename.indexOf("junit") == -1) {
classPath.append(filename);
classPath.append(System.getProperty("path.separator"));
}
if (filename.indexOf("surefirebooter") != -1) {
// surefire 2.4 uses a MANIFEST classpath that javac doesn't like
try (JarFile jar = new JarFile(filename)) {
Attributes attr = jar.getManifest().getMainAttributes();
if (attr != null) {
String cp = attr.getValue("Class-Path");
while (cp != null) {
String fileName = cp;
int idx = fileName.indexOf(' ');
if (idx != -1) {
fileName = fileName.substring(0, idx);
cp = cp.substring(idx + 1).trim();
} else {
cp = null;
}
URI uri = new URI(fileName);
File f2 = new File(uri);
if (f2.exists()) {
classPath.append(f2.getAbsolutePath());
classPath.append(System.getProperty("path.separator"));
}
}
}
}
}
}
}
return classPath.toString();
}
use of java.util.jar.Attributes in project hale by halestudio.
the class SwingRCPPlugin method start.
/**
* @see AbstractUIPlugin#start(BundleContext)
*/
@Override
public void start(BundleContext context) throws Exception {
super.start(context);
plugin = this;
Enumeration<URL> manifestFiles = context.getBundle().findEntries("META-INF", "MANIFEST.MF", false);
while (manifestFiles.hasMoreElements()) {
URL manifestFile = manifestFiles.nextElement();
Manifest manifest = new Manifest(manifestFile.openStream());
Attributes attributes = manifest.getMainAttributes();
String value = attributes.getValue(LOOK_AND_FEEL);
if (value != null) {
setCustomLookAndFeel(value.trim());
return;
}
}
}
use of java.util.jar.Attributes in project nifi by apache.
the class NarUnpacker method unpackNars.
public static ExtensionMapping unpackNars(final NiFiProperties props, final Bundle systemBundle) {
final List<Path> narLibraryDirs = props.getNarLibraryDirectories();
final File frameworkWorkingDir = props.getFrameworkWorkingDirectory();
final File extensionsWorkingDir = props.getExtensionsWorkingDirectory();
final File docsWorkingDir = props.getComponentDocumentationWorkingDirectory();
final Map<File, BundleCoordinate> unpackedNars = new HashMap<>();
try {
File unpackedFramework = null;
final Set<File> unpackedExtensions = new HashSet<>();
final List<File> narFiles = new ArrayList<>();
// make sure the nar directories are there and accessible
FileUtils.ensureDirectoryExistAndCanReadAndWrite(frameworkWorkingDir);
FileUtils.ensureDirectoryExistAndCanReadAndWrite(extensionsWorkingDir);
FileUtils.ensureDirectoryExistAndCanReadAndWrite(docsWorkingDir);
for (Path narLibraryDir : narLibraryDirs) {
File narDir = narLibraryDir.toFile();
// Test if the source NARs can be read
FileUtils.ensureDirectoryExistAndCanRead(narDir);
File[] dirFiles = narDir.listFiles(NAR_FILTER);
if (dirFiles != null) {
List<File> fileList = Arrays.asList(dirFiles);
narFiles.addAll(fileList);
}
}
if (!narFiles.isEmpty()) {
final long startTime = System.nanoTime();
logger.info("Expanding " + narFiles.size() + " NAR files with all processors...");
for (File narFile : narFiles) {
logger.debug("Expanding NAR file: " + narFile.getAbsolutePath());
// get the manifest for this nar
try (final JarFile nar = new JarFile(narFile)) {
final Manifest manifest = nar.getManifest();
// lookup the nar id
final Attributes attributes = manifest.getMainAttributes();
final String groupId = attributes.getValue(NarManifestEntry.NAR_GROUP.getManifestName());
final String narId = attributes.getValue(NarManifestEntry.NAR_ID.getManifestName());
final String version = attributes.getValue(NarManifestEntry.NAR_VERSION.getManifestName());
// determine if this is the framework
if (NarClassLoaders.FRAMEWORK_NAR_ID.equals(narId)) {
if (unpackedFramework != null) {
throw new IllegalStateException("Multiple framework NARs discovered. Only one framework is permitted.");
}
// unpack the framework nar
unpackedFramework = unpackNar(narFile, frameworkWorkingDir);
} else {
final File unpackedExtension = unpackNar(narFile, extensionsWorkingDir);
// record the current bundle
unpackedNars.put(unpackedExtension, new BundleCoordinate(groupId, narId, version));
// unpack the extension nar
unpackedExtensions.add(unpackedExtension);
}
}
}
// ensure we've found the framework nar
if (unpackedFramework == null) {
throw new IllegalStateException("No framework NAR found.");
} else if (!unpackedFramework.canRead()) {
throw new IllegalStateException("Framework NAR cannot be read.");
}
// Determine if any nars no longer exist and delete their working directories. This happens
// if a new version of a nar is dropped into the lib dir. ensure no old framework are present
final File[] frameworkWorkingDirContents = frameworkWorkingDir.listFiles();
if (frameworkWorkingDirContents != null) {
for (final File unpackedNar : frameworkWorkingDirContents) {
if (!unpackedFramework.equals(unpackedNar)) {
FileUtils.deleteFile(unpackedNar, true);
}
}
}
// ensure no old extensions are present
final File[] extensionsWorkingDirContents = extensionsWorkingDir.listFiles();
if (extensionsWorkingDirContents != null) {
for (final File unpackedNar : extensionsWorkingDirContents) {
if (!unpackedExtensions.contains(unpackedNar)) {
FileUtils.deleteFile(unpackedNar, true);
}
}
}
final long duration = System.nanoTime() - startTime;
logger.info("NAR loading process took " + duration + " nanoseconds " + "(" + (int) TimeUnit.SECONDS.convert(duration, TimeUnit.NANOSECONDS) + " seconds).");
}
// attempt to delete any docs files that exist so that any components that have been removed
// will no longer have entries in the docs folder
final File[] docsFiles = docsWorkingDir.listFiles();
if (docsFiles != null) {
for (final File file : docsFiles) {
FileUtils.deleteFile(file, true);
}
}
final ExtensionMapping extensionMapping = new ExtensionMapping();
mapExtensions(unpackedNars, docsWorkingDir, extensionMapping);
// unpack docs for the system bundle which will catch any JARs directly in the lib directory that might have docs
unpackBundleDocs(docsWorkingDir, extensionMapping, systemBundle.getBundleDetails().getCoordinate(), systemBundle.getBundleDetails().getWorkingDirectory());
return extensionMapping;
} catch (IOException e) {
logger.warn("Unable to load NAR library bundles due to " + e + " Will proceed without loading any further Nar bundles");
if (logger.isDebugEnabled()) {
logger.warn("", e);
}
}
return null;
}
use of java.util.jar.Attributes in project sofa-ark by alipay.
the class HandleArchiveStage method transformPluginArchive.
private Plugin transformPluginArchive(PluginArchive pluginArchive) throws Exception {
PluginModel plugin = new PluginModel();
Attributes manifestMainAttributes = pluginArchive.getManifest().getMainAttributes();
return plugin.setPluginName(manifestMainAttributes.getValue(PLUGIN_NAME_ATTRIBUTE)).setGroupId(manifestMainAttributes.getValue(GROUP_ID_ATTRIBUTE)).setArtifactId(manifestMainAttributes.getValue(ARTIFACT_ID_ATTRIBUTE)).setVersion(manifestMainAttributes.getValue(PLUGIN_VERSION_ATTRIBUTE)).setPriority(Integer.valueOf(manifestMainAttributes.getValue(PRIORITY_ATTRIBUTE))).setPluginActivator(manifestMainAttributes.getValue(ACTIVATOR_ATTRIBUTE)).setClassPath(pluginArchive.getUrls()).setExportClasses(new HashSet<>(Arrays.asList(filterEmptyString(manifestMainAttributes.getValue(EXPORT_CLASSES_ATTRIBUTE))))).setExportPackages(new HashSet<>(Arrays.asList(filterEmptyString(manifestMainAttributes.getValue(EXPORT_PACKAGES_ATTRIBUTE))))).setImportClasses(new HashSet<>(Arrays.asList(filterEmptyString(manifestMainAttributes.getValue(IMPORT_CLASSES_ATTRIBUTE))))).setImportPackages(new HashSet<>(Arrays.asList(filterEmptyString(manifestMainAttributes.getValue(IMPORT_PACKAGES_ATTRIBUTE))))).setExportIndex(pluginArchive.getExportIndex()).setPluginClassLoader(new PluginClassLoader(plugin.getPluginName(), plugin.getClassPath())).setPluginContext(new PluginContextImpl(plugin));
}
use of java.util.jar.Attributes in project questdb by bluestreak01.
the class BootstrapMain method getVersion.
private static String getVersion() throws IOException {
Enumeration<URL> resources = BootstrapMain.class.getClassLoader().getResources("META-INF/MANIFEST.MF");
while (resources.hasMoreElements()) {
try (InputStream is = resources.nextElement().openStream()) {
Manifest manifest = new Manifest(is);
Attributes attributes = manifest.getMainAttributes();
if ("org.questdb".equals(attributes.getValue("Implementation-Vendor-Id"))) {
return manifest.getMainAttributes().getValue("Implementation-Version");
}
}
}
return "[DEVELOPMENT]";
}
Aggregations