Java Code Examples for java.util.jar.Attributes

The following code examples are extracted from open source projects. You can click to vote up the examples that are useful to you.

Example 1

From project ant4eclipse, under directory /org.ant4eclipse.lib.pde/src/org/ant4eclipse/lib/pde/internal/model/pluginproject/.

Source file: BundleDescriptionLoader.java

  22 
vote

/** 
 * <p> </p>
 * @param manifest
 * @return
 */
@SuppressWarnings("rawtypes") private static Properties convertManifest(Manifest manifest){
  Attributes attributes=manifest.getMainAttributes();
  Iterator iter=attributes.keySet().iterator();
  Properties result=new Properties();
  while (iter.hasNext()) {
    Attributes.Name key=(Attributes.Name)iter.next();
    result.put(key.toString(),attributes.get(key));
  }
  return result;
}
 

Example 2

From project artimate, under directory /artimate-demo/src/main/java/com/jdotsoft/jarloader/.

Source file: JarClassLoader.java

  22 
vote

/** 
 * Returns the name of the jar file main class, or null if no "Main-Class" manifest attributes was defined.
 * @return Main class declared in JAR's manifest.
 */
public String getManifestMainClass(){
  Attributes attr=null;
  if (isLaunchedFromJar()) {
    try {
      Manifest m=lstJarFile.get(0).jarFile.getManifest();
      attr=m.getMainAttributes();
    }
 catch (    IOException e) {
    }
  }
  return (attr == null ? null : attr.getValue(Attributes.Name.MAIN_CLASS));
}
 

Example 3

From project backend-update-center2, under directory /src/test/java/.

Source file: HPIResolver.java

  22 
vote

public void resolveHPI(String groupId,String artifactId,String version) throws Exception {
  System.out.format("Resolving HPI %s:%s:%s\n",groupId,artifactId,version);
  MavenRepositoryImpl mavenRepository=DefaultMavenRepositoryBuilder.createStandardInstance();
  HPI plugin=mavenRepository.findPlugin(groupId,artifactId,version);
  MavenArtifact mavenArtifact=new MavenArtifact(mavenRepository,plugin.artifact);
  Manifest manifest=mavenArtifact.getManifest();
  Attributes mainAttributes=manifest.getMainAttributes();
  List<Attributes.Name> attributeNames=sortAttributes(mainAttributes);
  for (  Object entry : attributeNames) {
    System.out.println(entry + ":" + mainAttributes.get(entry));
  }
}
 

Example 4

From project bundlemaker, under directory /main/org.bundlemaker.core.osgi/src/org/bundlemaker/core/osgi/utils/.

Source file: ManifestUtils.java

  22 
vote

/** 
 * <p> </p>
 * @param manifestContents
 * @return
 */
public static Manifest toManifest(ManifestContents manifestContents){
  Manifest manifest=new Manifest();
  for (  Entry<String,String> entry : manifestContents.getMainAttributes().entrySet()) {
    manifest.getMainAttributes().putValue(entry.getKey(),entry.getValue());
  }
  for (  String sectionName : manifestContents.getSectionNames()) {
    Attributes attributes=new Attributes();
    for (    Entry<String,String> entry : manifestContents.getAttributesForSection(sectionName).entrySet()) {
      attributes.putValue(entry.getKey(),entry.getValue());
    }
    manifest.getEntries().put(sectionName,attributes);
  }
  return manifest;
}
 

Example 5

From project caustic, under directory /applet/src/net/microscraper/client/applet/.

Source file: MicroScraperApplet.java

  22 
vote

public String manifest(String key){
  try {
    String className=MicroScraperApplet.class.getSimpleName() + ".class";
    String classPath=MicroScraperApplet.class.getResource(className).toString();
    String manifestPath=classPath.substring(0,classPath.lastIndexOf("!") + 1) + "/META-INF/MANIFEST.MF";
    Manifest manifest=new Manifest(new URL(manifestPath).openStream());
    Attributes attr=manifest.getMainAttributes();
    return (String)attr.getValue(key);
  }
 catch (  Throwable e) {
    e.printStackTrace();
    return "Error obtaining " + key + " from manifest: "+ e.toString();
  }
}
 

Example 6

From project community-plugins, under directory /deployit-cli-plugins/dar-manifest-exporter/src/main/java/ext/deployit/community/cli/manifestexport/dar/.

Source file: ManifestBuilder.java

  22 
vote

private static Attributes toAttributes(Map<String,String> values){
  Attributes attributes=new Attributes(values.size());
  for (  Entry<String,String> value : values.entrySet()) {
    attributes.putValue(value.getKey(),value.getValue());
  }
  return attributes;
}
 

Example 7

From project core_4, under directory /impl/src/main/java/org/richfaces/.

Source file: VersionBean.java

  22 
vote

private void initializePropertiesFromManifest(Manifest manifest){
  containsDataFromManifest=true;
  Attributes attributes=manifest.getMainAttributes();
  implementationVendor=getAttributeValueOrDefault(attributes,"Implementation-Vendor");
  implementationVersion=getAttributeValueOrDefault(attributes,"Implementation-Version");
  implementationTitle=getAttributeValueOrDefault(attributes,"Implementation-Title");
  scmTimestamp=getAttributeValueOrDefault(attributes,"SCM-Timestamp");
}
 

Example 8

From project descriptors, under directory /impl-base/src/main/java/org/jboss/shrinkwrap/descriptor/impl/base/spec/se/manifest/.

Source file: ManifestAppletDefImpl.java

  22 
vote

public ManifestAppletDefImpl(String descriptorName,ManifestModel manifest,String appletName){
  super(descriptorName,manifest);
  this.appletName=appletName;
  Attributes mainAttributes=manifest.getMainAttributes();
  String extensionListValue=(mainAttributes.containsKey(Name.EXTENSION_LIST) ? String.valueOf(mainAttributes.get(Name.EXTENSION_LIST)) + " " + appletName : appletName);
  manifest.getMainAttributes().put(Name.EXTENSION_LIST,extensionListValue);
}
 

Example 9

From project droolsjbpm-build-distribution, under directory /drools-osgi-bundles/org.drools.osgi.test/src/test/java/org/drools/osgi/test/utils/.

Source file: EclipseArtifactFinder.java

  22 
vote

private void addPlugin(Set<Plugin> plugins,Resource resource,Manifest man,boolean isExploded){
  Attributes attrs=man.getMainAttributes();
  String symbolicName=attrs.getValue(Constants.BUNDLE_SYMBOLICNAME);
  if (symbolicName != null) {
    symbolicName=symbolicName.replace("singleton:=true","");
    symbolicName=symbolicName.trim().replace(";","");
    String version=attrs.getValue(Constants.BUNDLE_VERSION);
    if (symbolicName != null && version != null)     plugins.add(new Plugin(symbolicName,version,resource,isExploded));
  }
}
 

Example 10

From project eclipse.pde.build, under directory /org.eclipse.pde.build/src_ant/org/eclipse/pde/internal/build/tasks/.

Source file: ManifestModifier.java

  22 
vote

private void changeValue(String key,String value){
  Attributes attributes=manifest.getMainAttributes();
  if (attributes.containsKey(key) && attributes.getValue(key).equals(value))   return;
  contentChanged=true;
  attributes.put(new Attributes.Name(key),value);
}
 

Example 11

From project gedcom5-conversion, under directory /src/test/java/org/gedcomx/tools/.

Source file: Gedcom2GedcomxTest.java

  22 
vote

private static void printEntry(Object jarEntry) throws IOException {
  JarEntry entry=(JarEntry)jarEntry;
  String name=entry.getName();
  long size=entry.getSize();
  long compressedSize=entry.getCompressedSize();
  Attributes attributes=entry.getAttributes();
  System.out.print(name + "\t" + size+ "\t"+ compressedSize+ "\t");
  printAttributes(attributes);
}
 

Example 12

From project Gemini-Blueprint, under directory /test-support/src/main/java/org/eclipse/gemini/blueprint/test/.

Source file: AbstractOnTheFlyBundleCreatorTests.java

  22 
vote

/** 
 * Creates the default manifest in case none if found on the disk. By default, the imports are synthetised based on the test class bytecode.
 * @return default manifest for the jar created on the fly
 */
protected Manifest createDefaultManifest(){
  Manifest manifest=new Manifest();
  Attributes attrs=manifest.getMainAttributes();
  attrs.put(Attributes.Name.MANIFEST_VERSION,"1.0");
  attrs.putValue(Constants.BUNDLE_MANIFESTVERSION,"2");
  String description=getName() + "-" + getClass().getName();
  attrs.putValue(Constants.BUNDLE_NAME,"TestBundle-" + description);
  attrs.putValue(Constants.BUNDLE_SYMBOLICNAME,"TestBundle-" + description);
  attrs.putValue(Constants.BUNDLE_DESCRIPTION,"on-the-fly test bundle");
  attrs.putValue(Constants.BUNDLE_ACTIVATOR,JUnitTestActivator.class.getName());
  addImportPackage(manifest);
  if (logger.isDebugEnabled())   logger.debug("Created manifest:" + manifest.getMainAttributes().entrySet());
  return manifest;
}
 

Example 13

From project gemini.web.gemini-web-container, under directory /org.eclipse.gemini.web.core/src/main/java/org/eclipse/gemini/web/internal/url/.

Source file: WebBundleUrlStreamHandlerService.java

  22 
vote

private static Manifest toManifest(Dictionary<String,String> headers){
  Manifest manifest=new Manifest();
  Attributes attributes=manifest.getMainAttributes();
  Enumeration<String> names=headers.keys();
  while (names.hasMoreElements()) {
    String name=names.nextElement();
    String value=headers.get(name);
    attributes.putValue(name,value);
  }
  return manifest;
}
 

Example 14

From project geronimo-xbean, under directory /xbean-bundleutils/src/main/java/org/apache/xbean/osgi/bundle/util/.

Source file: BundleDescription.java

  22 
vote

private static Map<String,String> manifestToMap(Manifest manifest){
  Attributes attributes=manifest.getMainAttributes();
  Map<String,String> headers=new HashMap<String,String>();
  for (  Map.Entry<Object,Object> entry : attributes.entrySet()) {
    String key=entry.getKey().toString();
    String value=entry.getValue().toString();
    headers.put(key,value);
  }
  return headers;
}
 

Example 15

From project jbosgi, under directory /testsuite/performance/src/test/java/org/jboss/osgi/test/performance/bundle/arq/.

Source file: TestBundleProviderImpl.java

  22 
vote

private InputStream getVersionBasedBundle(String prefix,String version) throws IOException, FileNotFoundException {
  File exploded=getRawBundleDir(prefix);
  Manifest mf=new Manifest(new FileInputStream(new File(exploded,"META-INF/MANIFEST.MF")));
  Attributes attrs=mf.getMainAttributes();
  for (  Map.Entry<Object,Object> entry : new HashSet<Map.Entry<Object,Object>>(attrs.entrySet())) {
    String newVal=entry.getValue().toString().replaceAll(BundleTestBase.VERSION_UNDEFINED,version);
    attrs.put(entry.getKey(),newVal);
  }
  return jar(exploded,mf);
}
 

Example 16

From project jbosgi-metadata, under directory /src/main/java/org/jboss/osgi/metadata/.

Source file: OSGiMetaDataBuilder.java

  22 
vote

public static OSGiMetaData load(Properties props){
  if (props == null)   throw MESSAGES.illegalArgumentNull("props");
  Manifest manifest=new Manifest();
  Attributes mainAttributes=manifest.getMainAttributes();
  for (  Object key : props.keySet()) {
    Attributes.Name name=new Attributes.Name((String)key);
    mainAttributes.put(name,props.get(key));
  }
  return load(manifest);
}
 

Example 17

From project jbosgi-vfs, under directory /vfs30/src/test/java/org/jboss/test/osgi/vfs30/.

Source file: SimpleVFS30TestCase.java

  22 
vote

@Test public void testStreamURLAccess() throws Exception {
  VirtualFile virtualFile=AbstractVFS.toVirtualFile(file.toURI());
  try {
    URL streamURL=virtualFile.getStreamURL();
    JarInputStream jarIn=new JarInputStream(streamURL.openStream());
    Manifest manifest=jarIn.getManifest();
    Attributes attributes=manifest.getMainAttributes();
    String symbolicName=attributes.getValue(Constants.BUNDLE_SYMBOLICNAME);
    assertEquals("example-simple",symbolicName);
  }
  finally {
    virtualFile.close();
  }
}
 

Example 18

From project jboss-vfs, under directory /src/test/java/org/jboss/test/vfs/.

Source file: FileVFSUnitTestCase.java

  22 
vote

public void testFindResourceUnpackedJar() throws Exception {
  VirtualFile testdir=getVirtualFile("/vfs/test");
  VirtualFile jar=testdir.getChild("unpacked-outer.jar");
  assertTrue("unpacked-outer.jar != null",jar != null);
  VirtualFile metaInf=jar.getChild("META-INF/MANIFEST.MF");
  assertTrue("META-INF/MANIFEST.MF != null",metaInf != null);
  InputStream mfIS=metaInf.openStream();
  assertTrue("META-INF/MANIFEST.MF.openStream != null",mfIS != null);
  Manifest mf=new Manifest(mfIS);
  Attributes mainAttrs=mf.getMainAttributes();
  String version=mainAttrs.getValue(Attributes.Name.SPECIFICATION_VERSION);
  assertEquals("1.0.0.GA",version);
  mfIS.close();
}
 

Example 19

From project jumpnevolve, under directory /src/com/jdotsoft/jarloader/.

Source file: JarClassLoader.java

  22 
vote

/** 
 * Returns the name of the jar file main class, or null if no "Main-Class" manifest attributes was defined.
 * @return main class declared in JAR's manifest
 */
public String getManifestMainClass(){
  Attributes attr=null;
  if (isLaunchedFromJar()) {
    try {
      Manifest m=this.lstJarFile.get(0).getManifest();
      attr=m.getMainAttributes();
    }
 catch (    IOException e) {
    }
  }
  return (attr == null ? null : attr.getValue(Attributes.Name.MAIN_CLASS));
}
 

Example 20

From project maven-deployit-plugin, under directory /maven-deployit-plugin/src/main/java/com/xebialabs/deployit/maven/packager/.

Source file: ManifestPackager.java

  22 
vote

protected void addMiddlewareResource(MiddlewareResource mr){
  getLog().info(" add mddleware resource : " + mr.getConfigurationName());
  final Map<String,Attributes> entries=manifest.getEntries();
  final Attributes attributes=new Attributes();
  attributes.putValue("CI-Type",mr.getType());
  for (  Map.Entry<String,String> entry : mr.getProperties().entrySet()) {
    attributes.putValue("CI-" + entry.getKey(),entry.getValue());
  }
  entries.put(mr.getEntryKey(),attributes);
}
 

Example 21

From project maven-shared, under directory /maven-shared-jar/src/main/java/org/apache/maven/shared/jar/identification/exposers/.

Source file: ManifestExposer.java

  22 
vote

public void expose(JarIdentification identification,JarAnalyzer jarAnalyzer){
  Manifest manifest=jarAnalyzer.getJarData().getManifest();
  if (manifest != null) {
    addManifestAttributeValues(manifest.getMainAttributes(),identification);
    Map entries=manifest.getEntries();
    Iterator itentries=entries.entrySet().iterator();
    while (itentries.hasNext()) {
      Map.Entry entry=(Map.Entry)itentries.next();
      Attributes attribs=(Attributes)entry.getValue();
      addManifestAttributeValues(attribs,identification);
    }
  }
}
 

Example 22

From project org.ops4j.pax.construct, under directory /maven-pax-plugin/src/main/java/org/ops4j/pax/construct/util/.

Source file: PomUtils.java

  22 
vote

/** 
 * @param manifest jar manifest, possibly null
 * @return true if this is an OSGi bundle artifact, otherwise false
 */
private static boolean isBundleArtifact(Manifest manifest){
  if (null == manifest) {
    return false;
  }
  Attributes mainAttributes=manifest.getMainAttributes();
  return mainAttributes.getValue("Bundle-SymbolicName") != null || mainAttributes.getValue("Bundle-Name") != null;
}
 

Example 23

From project org.ops4j.pax.url, under directory /pax-url-dir/src/test/java/org/ops4j/pax/url/dir/internal/.

Source file: FunctionalTest.java

  22 
vote

public static void dumpToConsole(InputStream in,int expecedEntries) throws IOException {
  JarInputStream jin=new JarInputStream(in);
  String[] s=readToc(jin);
  assertEquals(expecedEntries,s.length);
  Manifest man=jin.getManifest();
  assertNotNull(man);
  Attributes attributes=man.getMainAttributes();
  for (  Object key : attributes.keySet()) {
    String v=attributes.getValue((Attributes.Name)key);
    assertNotNull(key);
    assertNotNull(v);
    System.out.println(key + "=" + v);
  }
}
 

Example 24

From project plexus-archiver, under directory /src/main/java/org/codehaus/plexus/archiver/jar/.

Source file: Manifest.java

  22 
vote

/** 
 * Add a section to the manifest
 * @param section the manifest section to be added
 * @throws ManifestException if the secti0on is not valid.
 */
public void addConfiguredSection(Section section) throws ManifestException {
  String sectionName=section.getName();
  if (sectionName == null) {
    throw new ManifestException("Sections must have a name");
  }
  Attributes attributes=getOrCreateAttributes(sectionName);
  for (  String s : section.attributes.keySet()) {
    Attribute attribute=section.getAttribute(s);
    attributes.putValue(attribute.getName(),attribute.getValue());
  }
}
 

Example 25

From project recommenders, under directory /plugins/org.eclipse.recommenders.utils/src/org/eclipse/recommenders/utils/archive/.

Source file: OsgiManifestJarIdExtractor.java

  22 
vote

@Override public void extract(final JarFile jarFile) throws IOException {
  final Manifest manifest=jarFile.getManifest();
  if (manifest != null) {
    final Attributes attributes=manifest.getMainAttributes();
    setName(attributes.getValue(BUNDLE_NAME));
    final String version=attributes.getValue(BUNDLE_VERSION);
    if (version != null) {
      setVersion(parser.parse(version));
    }
  }
}
 

Example 26

From project rundeck, under directory /core/src/main/java/com/dtolabs/rundeck/core/plugins/.

Source file: JarPluginProviderLoader.java

  22 
vote

/** 
 * Get the declared list of provider classnames for the file
 */
public String[] getClassnames(){
  final Attributes attributes=getMainAttributes();
  if (null == attributes) {
    return null;
  }
  final String value=attributes.getValue(RUNDECK_PLUGIN_CLASSNAMES);
  if (null == value) {
    return null;
  }
  return value.split(",");
}
 

Example 27

From project Sparkweave, under directory /spark-weave/src/main/java/at/sti2/spark/launcher/.

Source file: JarClassLoader.java

  22 
vote

/** 
 * Returns the name of the jar file main class, or null if no "Main-Class" manifest attributes was defined.
 * @return Main class declared in JAR's manifest.
 */
public String getManifestMainClass(){
  Attributes attr=null;
  if (isLaunchedFromJar()) {
    try {
      Manifest m=lstJarFile.get(0).jarFile.getManifest();
      attr=m.getMainAttributes();
    }
 catch (    IOException e) {
    }
  }
  return (attr == null ? null : attr.getValue(Attributes.Name.MAIN_CLASS));
}
 

Example 28

From project tycho, under directory /tycho-its/src/test/java/org/eclipse/tycho/test/TYCHO285EclipseSourceBundles/.

Source file: TYCHO285EclipseSourceBundlesTest.java

  22 
vote

@Test public void testEclipseSourceBundleManifestAttributes() throws Exception {
  Verifier verifier=getVerifier("/TYCHO285EclipseSourceBundles");
  verifier.executeGoal("integration-test");
  verifier.verifyErrorFreeLog();
  File sourceJarFile=new File(verifier.getBasedir(),"target/bundle-1.2.3-SNAPSHOT-sources.jar");
  Assert.assertTrue(sourceJarFile.exists());
  Manifest manifest=new JarFile(sourceJarFile).getManifest();
  Assert.assertNotNull(manifest);
  Attributes mainAttributes=manifest.getMainAttributes();
  Assert.assertEquals("bundle.source",mainAttributes.getValue("Bundle-SymbolicName"));
  Assert.assertEquals("1.2.3.TAGNAME",mainAttributes.getValue("Bundle-Version"));
  Assert.assertEquals("bundle;version=\"1.2.3.TAGNAME\";roots:=\".\"",mainAttributes.getValue("Eclipse-SourceBundle"));
}
 

Example 29

From project usergrid-stack, under directory /launcher/src/main/java/com/jdotsoft/jarloader/.

Source file: JarClassLoader.java

  22 
vote

/** 
 * Returns the name of the jar file main class, or null if no "Main-Class" manifest attributes was defined.
 * @return Main class declared in JAR's manifest.
 */
public String getManifestMainClass(){
  Attributes attr=null;
  if (isLaunchedFromJar()) {
    try {
      Manifest m=lstJarFile.get(0).jarFile.getManifest();
      attr=m.getMainAttributes();
    }
 catch (    IOException e) {
    }
  }
  return (attr == null ? null : attr.getValue(Attributes.Name.MAIN_CLASS));
}
 

Example 30

From project virgo.kernel, under directory /org.eclipse.virgo.kernel.artifact/src/test/java/org/eclipse/virgo/kernel/artifact/bundle/.

Source file: BundleBridgeTests.java

  22 
vote

@Test public void testBuildDictionary() throws ArtifactGenerationException, IOException {
  File testFile=new File(System.getProperty("user.home") + "/virgo-build-cache/ivy-cache/repository/org.eclipse.virgo.mirrored/javax.servlet/3.0.0.v201112011016/javax.servlet-3.0.0.v201112011016.jar");
  ArtifactDescriptor inputArtefact=BUNDLE_BRIDGE.generateArtifactDescriptor(testFile);
  Dictionary<String,String> dictionary=BundleBridge.convertToDictionary(inputArtefact);
  JarFile testJar=new JarFile(testFile);
  Attributes attributes=testJar.getManifest().getMainAttributes();
  testJar.close();
  assertEquals("Failed to match regenerated " + Constants.BUNDLE_SYMBOLICNAME,dictionary.get(Constants.BUNDLE_SYMBOLICNAME),attributes.getValue(Constants.BUNDLE_SYMBOLICNAME));
  assertEquals("Failed to match regenerated " + Constants.BUNDLE_VERSION,dictionary.get(Constants.BUNDLE_VERSION),attributes.getValue(Constants.BUNDLE_VERSION));
  assertEquals("Failed to match regenerated " + BUNDLE_MANIFEST_VERSION_HEADER_NAME,dictionary.get(BUNDLE_MANIFEST_VERSION_HEADER_NAME),attributes.getValue(BUNDLE_MANIFEST_VERSION_HEADER_NAME));
  assertEquals("Failed to match regenerated " + BUNDLE_NAME_HEADER_NAME,dictionary.get(BUNDLE_NAME_HEADER_NAME),attributes.getValue(BUNDLE_NAME_HEADER_NAME));
}
 

Example 31

From project virgo.util, under directory /org.eclipse.virgo.util.parser.manifest/src/test/java/org/eclipse/virgo/util/parser/manifest/internal/.

Source file: ManifestLexerTests.java

  22 
vote

/** 
 * Investigating special character behaviour.
 * @throws Exception for IO errors, for example 
 */
public void testSpecialCharacters() throws Exception {
  String twoByteUtf8="Export-Package: sch\u00f6n\n\n";
  byte[] twoByteUtf8data=twoByteUtf8.getBytes("UTF-8");
  assertEquals(twoByteUtf8.length() + 1,twoByteUtf8data.length);
  String s="Export-Package: c\u00f6m\n\n";
  ByteArrayInputStream is=new ByteArrayInputStream(s.getBytes("UTF-8"));
  Attributes attrs=new Manifest(is).getMainAttributes();
  String exports=attrs.getValue("Export-Package");
  assertEquals("c\u00f6m",exports);
}
 

Example 32

From project virgo.web, under directory /org.eclipse.virgo.web.war.deployer/src/main/java/org/eclipse/virgo/web/war/deployer/.

Source file: WARDeployer.java

  22 
vote

private final Manifest toManifest(Dictionary<String,String> headers){
  Manifest manifest=new Manifest();
  Attributes attributes=manifest.getMainAttributes();
  Enumeration<String> names=headers.keys();
  while (names.hasMoreElements()) {
    String name=names.nextElement();
    String value=headers.get(name);
    attributes.putValue(name,value);
  }
  return manifest;
}
 

Example 33

From project xwiki-commons, under directory /xwiki-commons-core/xwiki-commons-classloader/xwiki-commons-classloader-api/src/main/java/org/xwiki/classloader/.

Source file: URIClassLoader.java

  22 
vote

/** 
 * returns true if the specified package name is sealed according to the given manifest.
 */
private boolean isSealed(String name,Manifest man){
  String path=name.replace('.','/').concat("/");
  Attributes attr=man.getAttributes(path);
  String sealed=null;
  if (attr != null) {
    sealed=attr.getValue(Name.SEALED);
  }
  if (sealed == null) {
    if ((attr=man.getMainAttributes()) != null) {
      sealed=attr.getValue(Name.SEALED);
    }
  }
  return "true".equalsIgnoreCase(sealed);
}
 

Example 34

From project android_build, under directory /tools/signapk/.

Source file: SignApk.java

  21 
vote

/** 
 * Add the SHA1 of every file to the manifest, creating it if necessary. 
 */
private static Manifest addDigestsToManifest(JarFile jar) throws IOException, GeneralSecurityException {
  Manifest input=jar.getManifest();
  Manifest output=new Manifest();
  Attributes main=output.getMainAttributes();
  if (input != null) {
    main.putAll(input.getMainAttributes());
  }
 else {
    main.putValue("Manifest-Version","1.0");
    main.putValue("Created-By","1.0 (Android SignApk)");
  }
  BASE64Encoder base64=new BASE64Encoder();
  MessageDigest md=MessageDigest.getInstance("SHA1");
  byte[] buffer=new byte[4096];
  int num;
  TreeMap<String,JarEntry> byName=new TreeMap<String,JarEntry>();
  for (Enumeration<JarEntry> e=jar.entries(); e.hasMoreElements(); ) {
    JarEntry entry=e.nextElement();
    byName.put(entry.getName(),entry);
  }
  for (  JarEntry entry : byName.values()) {
    String name=entry.getName();
    if (!entry.isDirectory() && !name.equals(JarFile.MANIFEST_NAME) && !name.equals(CERT_SF_NAME)&& !name.equals(CERT_RSA_NAME)&& (stripPattern == null || !stripPattern.matcher(name).matches())) {
      InputStream data=jar.getInputStream(entry);
      while ((num=data.read(buffer)) > 0) {
        md.update(buffer,0,num);
      }
      Attributes attr=null;
      if (input != null)       attr=input.getAttributes(name);
      attr=attr != null ? new Attributes(attr) : new Attributes();
      attr.putValue("SHA1-Digest",base64.encode(md.digest()));
      output.getEntries().put(name,attr);
    }
  }
  return output;
}
 

Example 35

From project arkadiko, under directory /src/com/liferay/arkadiko/util/.

Source file: AKFrameworkFactory.java

  21 
vote

public static Bundle getBundle(BundleContext bundleContext,File bundleFile) throws IOException {
  JarFile jarFile=new JarFile(bundleFile);
  Manifest manifest=jarFile.getManifest();
  jarFile.close();
  Attributes attributes=manifest.getMainAttributes();
  String bundleSymbolicNameAttribute=attributes.getValue(Constants.BUNDLE_SYMBOLICNAME);
  Map<String,Map<String,String>> bundleSymbolicNamesMap=OSGiHeader.parseHeader(bundleSymbolicNameAttribute);
  Set<String> bundleSymbolicNamesSet=bundleSymbolicNamesMap.keySet();
  Iterator<String> bundleSymbolicNamesIterator=bundleSymbolicNamesSet.iterator();
  String bundleSymbolicName=bundleSymbolicNamesIterator.next();
  String bundleVersionAttribute=attributes.getValue(Constants.BUNDLE_VERSION);
  Version bundleVersion=Version.parseVersion(bundleVersionAttribute);
  for (  Bundle bundle : bundleContext.getBundles()) {
    Version curBundleVersion=Version.parseVersion(bundle.getVersion().toString());
    if (bundleSymbolicName.equals(bundle.getSymbolicName()) && bundleVersion.equals(curBundleVersion)) {
      return bundle;
    }
  }
  return null;
}
 

Example 36

From project arquillian-container-osgi, under directory /container-common/src/main/java/org/jboss/arquillian/container/osgi/.

Source file: AbstractOSGiApplicationArchiveProcessor.java

  21 
vote

private void enhanceApplicationArchive(Archive<?> appArchive,TestClass testClass,Manifest manifest){
  if (ClassContainer.class.isAssignableFrom(appArchive.getClass()) == false)   throw new IllegalArgumentException("ClassContainer expected: " + appArchive);
  Class<?> javaClass=testClass.getJavaClass();
  String path=javaClass.getName().replace('.','/') + ".class";
  if (appArchive.contains(path) == false)   ((ClassContainer<?>)appArchive).addClass(javaClass);
  final OSGiManifestBuilder builder=OSGiManifestBuilder.newInstance();
  Attributes attributes=manifest.getMainAttributes();
  for (  Entry<Object,Object> entry : attributes.entrySet()) {
    String key=entry.getKey().toString();
    String value=(String)entry.getValue();
    if (key.equals("Manifest-Version"))     continue;
    if (key.equals(Constants.IMPORT_PACKAGE)) {
      String[] imports=value.split(",");
      builder.addImportPackages(imports);
      continue;
    }
    if (key.equals(Constants.EXPORT_PACKAGE)) {
      String[] exports=value.split(",");
      builder.addExportPackages(exports);
      continue;
    }
    builder.addManifestHeader(key,value);
  }
  builder.addExportPackages(javaClass);
  addImportsForClass(builder,javaClass);
  builder.addImportPackages("org.jboss.arquillian.container.test.api","org.jboss.arquillian.junit","org.jboss.arquillian.osgi","org.jboss.arquillian.test.api");
  builder.addImportPackages("org.jboss.shrinkwrap.api","org.jboss.shrinkwrap.api.asset","org.jboss.shrinkwrap.api.spec");
  builder.addImportPackages("org.junit","org.junit.runner","javax.inject","org.osgi.framework");
  appArchive.delete(ArchivePaths.create(JarFile.MANIFEST_NAME));
  appArchive.add(new Asset(){
    public InputStream openStream(){
      return builder.openStream();
    }
  }
,JarFile.MANIFEST_NAME);
}
 

Example 37

From project bndtools, under directory /bndtools.core/src/bndtools/wizards/workspace/.

Source file: AddFilesToRepositoryWizardPage.java

  21 
vote

void analyseFile(File file){
  Jar jar=null;
  try {
    jar=new Jar(file);
    Attributes attribs=jar.getManifest().getMainAttributes();
    String bsn=attribs.getValue(Constants.BUNDLE_SYMBOLICNAME);
    String version=attribs.getValue(Constants.BUNDLE_VERSION);
    bsnMap.put(file,Pair.newInstance(bsn,version));
  }
 catch (  Exception e) {
    logger.logError("Error reading JAR file content",e);
  }
 finally {
    if (jar != null)     jar.close();
  }
}
 

Example 38

From project Cafe, under directory /webapp/src/org/openqa/selenium/internal/.

Source file: BuildInfo.java

  21 
vote

private static Properties loadBuildProperties(){
  Properties properties=new Properties();
  Manifest manifest=null;
  try {
    URL url=BuildInfo.class.getProtectionDomain().getCodeSource().getLocation();
    File file=new File(url.toURI());
    JarFile jar=new JarFile(file);
    manifest=jar.getManifest();
  }
 catch (  NullPointerException ignored) {
  }
catch (  URISyntaxException ignored) {
  }
catch (  IOException ignored) {
  }
catch (  IllegalArgumentException ignored) {
  }
  if (manifest == null) {
    return properties;
  }
  try {
    Attributes attributes=manifest.getAttributes("Build-Info");
    Set<Entry<Object,Object>> entries=attributes.entrySet();
    for (    Entry<Object,Object> e : entries) {
      properties.put(String.valueOf(e.getKey()),String.valueOf(e.getValue()));
    }
  }
 catch (  NullPointerException e) {
  }
  return properties;
}
 

Example 39

From project ceylon-runtime, under directory /impl/src/main/java/ceylon/modules/jboss/repository/.

Source file: SourceResourceLoader.java

  21 
vote

public PackageSpec getPackageSpec(String name) throws IOException {
  final PackageSpec spec=new PackageSpec();
  final Manifest manifest=this.manifest;
  if (manifest == null) {
    return spec;
  }
  final Attributes mainAttribute=manifest.getAttributes(name);
  final Attributes entryAttribute=manifest.getAttributes(name);
  spec.setSpecTitle(getDefinedAttribute(Attributes.Name.SPECIFICATION_TITLE,entryAttribute,mainAttribute));
  spec.setSpecVersion(getDefinedAttribute(Attributes.Name.SPECIFICATION_VERSION,entryAttribute,mainAttribute));
  spec.setSpecVendor(getDefinedAttribute(Attributes.Name.SPECIFICATION_VENDOR,entryAttribute,mainAttribute));
  spec.setImplTitle(getDefinedAttribute(Attributes.Name.IMPLEMENTATION_TITLE,entryAttribute,mainAttribute));
  spec.setImplVersion(getDefinedAttribute(Attributes.Name.IMPLEMENTATION_VERSION,entryAttribute,mainAttribute));
  spec.setImplVendor(getDefinedAttribute(Attributes.Name.IMPLEMENTATION_VENDOR,entryAttribute,mainAttribute));
  if (Boolean.parseBoolean(getDefinedAttribute(Attributes.Name.SEALED,entryAttribute,mainAttribute))) {
    spec.setSealBase(classesRoot.toURI().toURL());
  }
  return spec;
}
 

Example 40

From project Clotho-Core, under directory /ClothoApps/SequenceChecker/src/jaligner/util/.

Source file: Commons.java

  21 
vote

/** 
 * Gets the build teimstamp from the jar manifest
 * @return build timestamp
 */
private static String getManifestBuildTimestamp(){
  JarURLConnection connection=null;
  JarFile jarFile=null;
  URL url=Commons.class.getClassLoader().getResource("jaligner");
  try {
    connection=(JarURLConnection)url.openConnection();
    jarFile=connection.getJarFile();
    Manifest manifest=jarFile.getManifest();
    Attributes attributes=manifest.getMainAttributes();
    Attributes.Name name=new Attributes.Name(BUILD_TIMESTAMP);
    return attributes.getValue(name);
  }
 catch (  Exception e) {
    String message="Failed getting the current release info: " + e.getMessage();
    logger.log(Level.WARNING,message);
  }
  return null;
}
 

Example 41

From project cogroo4, under directory /lang/pt_br/cogroo-addon/src/org/cogroo/addon/.

Source file: CentralRegistrationClass.java

  21 
vote

private static String getRegistrationClasses(){
  CentralRegistrationClass c=new CentralRegistrationClass();
  String name=c.getClass().getCanonicalName().replace('.','/').concat(".class");
  try {
    Enumeration<URL> urlEnum=c.getClass().getClassLoader().getResources("META-INF/MANIFEST.MF");
    while (urlEnum.hasMoreElements()) {
      URL url=urlEnum.nextElement();
      String file=url.getFile();
      JarURLConnection jarConnection=(JarURLConnection)url.openConnection();
      Manifest mf=jarConnection.getManifest();
      Attributes attrs=(Attributes)mf.getAttributes(name);
      if (attrs != null) {
        String classes=attrs.getValue("RegistrationClasses");
        return classes;
      }
    }
  }
 catch (  IOException ex) {
    ex.printStackTrace();
  }
  return "";
}
 

Example 42

From project dolphin, under directory /texcel/compile/sun/misc/.

Source file: URLClassPath.java

  21 
vote

URL[] getClassPath() throws IOException {
  if (index != null) {
    return null;
  }
  if (metaIndex != null) {
    return null;
  }
  ensureOpen();
  parseExtensionsDependencies();
  if (SharedSecrets.javaUtilJarAccess().jarFileHasClassPathAttribute(jar)) {
    Manifest man=jar.getManifest();
    if (man != null) {
      Attributes attr=man.getMainAttributes();
      if (attr != null) {
        String value=attr.getValue(Name.CLASS_PATH);
        if (value != null) {
          return parseClassPath(csu,value);
        }
      }
    }
  }
  return null;
}
 

Example 43

From project Eclipse, under directory /com.mobilesorcery.sdk.builder.java/src/com/mobilesorcery/sdk/builder/java/.

Source file: JavaPackager2.java

  21 
vote

private Manifest getManifest(IBuildVariant variant,File jar,String appName,String vendorName,IApplicationPermissions permissions,Version version,boolean isJad) throws IOException {
  IProfile profile=variant.getProfile();
  boolean isCLDC_10=profile != null && Boolean.TRUE.equals(profile.getProperties().get("MA_PROF_SUPPORT_CLDC_10"));
  Manifest result=new Manifest();
  Attributes mainAttr=result.getMainAttributes();
  if (!isJad) {
    mainAttr.putValue("Manifest-Version","1.0");
  }
  mainAttr.putValue("MIDlet-Vendor",vendorName);
  mainAttr.putValue("MIDlet-Name",appName);
  mainAttr.putValue("MIDlet-1",appName + ", " + appName+ ".png"+ ", MAMidlet");
  String[] midletPermissions=getMIDletPermissions(permissions,false);
  String[] midletOptPermissions=getMIDletPermissions(permissions,true);
  if (midletPermissions.length > 0) {
    mainAttr.putValue("MIDlet-Permissions",Util.join(midletPermissions,", "));
  }
  if (midletOptPermissions.length > 0) {
    mainAttr.putValue("MIDlet-Permissions-Opt",Util.join(midletOptPermissions,", "));
  }
  mainAttr.putValue("MIDlet-Version",version.asCanonicalString(Version.MICRO));
  mainAttr.putValue("MicroEdition-Configuration",isCLDC_10 ? "CLDC-1.0" : "CLDC-1.1");
  mainAttr.putValue("MicroEdition-Profile","MIDP-2.0");
  if (isJad) {
    long jarSize=jar.length();
    String jarName=jar.getName();
    mainAttr.putValue("MIDlet-Jar-Size",Long.toString(jarSize));
    mainAttr.putValue("MIDlet-Jar-URL",jarName);
  }
  return result;
}
 

Example 44

From project glg2d, under directory /src/test/java/glg2d/misc/.

Source file: InstrumentPaint.java

  21 
vote

/** 
 * I hacked this together with duct tape and wire hangers, along with help from these two sites: <a href= "http://sleeplessinslc.blogspot.com/2008/09/java-instrumentation-with-jdk-16x-class.html" >http://sleeplessinslc.blogspot.com/2008/09/java-instrumentation-with-jdk- 16x-class.html</a> and <a href= "http://sleeplessinslc.blogspot.com/2008/07/java-instrumentation.html" >http://sleeplessinslc.blogspot.com/2008/07/java-instrumentation.html</a>.
 */
private static void instrument0() throws Exception {
  File jarFile=File.createTempFile("agent",".jar");
  jarFile.deleteOnExit();
  Manifest manifest=new Manifest();
  Attributes mainAttributes=manifest.getMainAttributes();
  mainAttributes.put(Attributes.Name.MANIFEST_VERSION,"1.0");
  mainAttributes.put(new Attributes.Name("Agent-Class"),InstrumentPaint.class.getName());
  mainAttributes.put(new Attributes.Name("Can-Retransform-Classes"),"true");
  mainAttributes.put(new Attributes.Name("Can-Redefine-Classes"),"true");
  JarOutputStream jos=new JarOutputStream(new FileOutputStream(jarFile),manifest);
  JarEntry agent=new JarEntry(InstrumentPaint.class.getName().replace('.','/') + ".class");
  jos.putNextEntry(agent);
  CtClass ctClass=ClassPool.getDefault().get(InstrumentPaint.class.getName());
  jos.write(ctClass.toBytecode());
  jos.closeEntry();
  JarEntry snip=new JarEntry("instrumentation.snip");
  jos.putNextEntry(snip);
  jos.write(getInstrumentationCode().getBytes());
  jos.closeEntry();
  jos.close();
  String name=ManagementFactory.getRuntimeMXBean().getName();
  VirtualMachine vm=VirtualMachine.attach(name.substring(0,name.indexOf('@')));
  vm.loadAgent(jarFile.getAbsolutePath());
  vm.detach();
}
 

Example 45

From project ios-driver, under directory /server/src/main/java/org/uiautomation/ios/server/utils/.

Source file: BuildInfo.java

  21 
vote

private static Properties loadBuildProperties(){
  Properties properties=new Properties();
  try {
    Manifest manifest=null;
    URL url=BuildInfo.class.getProtectionDomain().getCodeSource().getLocation();
    File file=new File(url.toURI());
    JarFile jar=new JarFile(file);
    manifest=jar.getManifest();
    Attributes attributes=manifest.getMainAttributes();
    Set<Entry<Object,Object>> entries=attributes.entrySet();
    for (    Entry<Object,Object> e : entries) {
      properties.put(String.valueOf(e.getKey()),String.valueOf(e.getValue()));
    }
  }
 catch (  Exception e) {
  }
  return properties;
}
 

Example 46

From project jbosgi-framework, under directory /core/src/main/java/org/jboss/osgi/framework/spi/.

Source file: VirtualFileResourceLoader.java

  21 
vote

@Override public PackageSpec getPackageSpec(String name) throws IOException {
  PackageSpec spec=new PackageSpec();
  Manifest manifest=VFSUtils.getManifest(virtualFile);
  if (manifest == null) {
    return spec;
  }
  Attributes mainAttribute=manifest.getAttributes(name);
  Attributes entryAttribute=manifest.getAttributes(name);
  spec.setSpecTitle(getDefinedAttribute(Attributes.Name.SPECIFICATION_TITLE,entryAttribute,mainAttribute));
  spec.setSpecVersion(getDefinedAttribute(Attributes.Name.SPECIFICATION_VERSION,entryAttribute,mainAttribute));
  spec.setSpecVendor(getDefinedAttribute(Attributes.Name.SPECIFICATION_VENDOR,entryAttribute,mainAttribute));
  spec.setImplTitle(getDefinedAttribute(Attributes.Name.IMPLEMENTATION_TITLE,entryAttribute,mainAttribute));
  spec.setImplVersion(getDefinedAttribute(Attributes.Name.IMPLEMENTATION_VERSION,entryAttribute,mainAttribute));
  spec.setImplVendor(getDefinedAttribute(Attributes.Name.IMPLEMENTATION_VENDOR,entryAttribute,mainAttribute));
  if (Boolean.parseBoolean(getDefinedAttribute(Attributes.Name.SEALED,entryAttribute,mainAttribute))) {
    spec.setSealBase(virtualFile.toURL());
  }
  return spec;
}
 

Example 47

From project jboss-modules, under directory /src/main/java/org/jboss/modules/.

Source file: AbstractResourceLoader.java

  21 
vote

/** 
 * Convenience method to get a package specification from a  {@code Manifest}.
 * @param name the (dot-separated) package name
 * @param manifest the {@code Manifest} instance
 * @param rootUrl the code source URL
 * @return the package specification
 */
protected static PackageSpec getPackageSpec(final String name,final Manifest manifest,final URL rootUrl){
  final PackageSpec spec=new PackageSpec();
  if (manifest == null) {
    return null;
  }
  final Attributes mainAttribute=manifest.getMainAttributes();
  final String path=name.replace('.','/').concat("/");
  final Attributes entryAttribute=manifest.getAttributes(path);
  spec.setSpecTitle(getDefinedAttribute(Attributes.Name.SPECIFICATION_TITLE,entryAttribute,mainAttribute));
  spec.setSpecVersion(getDefinedAttribute(Attributes.Name.SPECIFICATION_VERSION,entryAttribute,mainAttribute));
  spec.setSpecVendor(getDefinedAttribute(Attributes.Name.SPECIFICATION_VENDOR,entryAttribute,mainAttribute));
  spec.setImplTitle(getDefinedAttribute(Attributes.Name.IMPLEMENTATION_TITLE,entryAttribute,mainAttribute));
  spec.setImplVersion(getDefinedAttribute(Attributes.Name.IMPLEMENTATION_VERSION,entryAttribute,mainAttribute));
  spec.setImplVendor(getDefinedAttribute(Attributes.Name.IMPLEMENTATION_VENDOR,entryAttribute,mainAttribute));
  if (Boolean.parseBoolean(getDefinedAttribute(Attributes.Name.SEALED,entryAttribute,mainAttribute))) {
    spec.setSealBase(rootUrl);
  }
  return spec;
}
 

Example 48

From project m2eclipse-tycho, under directory /org.sonatype.tycho.m2e/src/org/sonatype/tycho/m2e/internal/.

Source file: OsgiBundleProjectConfigurator.java

  21 
vote

private Map<ArtifactKey,String> getBundleClasspathMap(IMavenProjectFacade facade) throws CoreException {
  Map<ArtifactKey,String> result=new LinkedHashMap<ArtifactKey,String>();
  IFile mfFile=PDEProjectHelper.getBundleManifest(facade.getProject());
  if (mfFile != null && mfFile.isAccessible()) {
    try {
      InputStream is=mfFile.getContents();
      try {
        Manifest mf=new Manifest(is);
        Attributes attrs=mf.getMainAttributes();
        String value=attrs.getValue(EMBEDDED_ARTIFACTS);
        if (value != null) {
          for (          ManifestElement me : ManifestElement.parseHeader(EMBEDDED_ARTIFACTS,value)) {
            String path=me.getValue();
            String g=me.getAttribute("g");
            String a=me.getAttribute("a");
            String v=me.getAttribute("v");
            String c=me.getAttribute("c");
            if (g != null && a != null && v != null && path != null) {
              result.put(new ArtifactKey(g,a,v,c),path);
            }
 else {
              log.debug("Malformd Include-Artifacts element paht={};g={};a={};v={};c={}",new Object[]{path,g,a,v,c});
            }
          }
        }
      }
  finally {
        is.close();
      }
    }
 catch (    Exception e) {
      log.warn("Count not read generated bundle manifest of project {}",facade.getProject().getName(),e);
    }
  }
  return result;
}
 

Example 49

From project maple-ide, under directory /build/windows/launcher/launch4j/src/net/sf/launch4j/formimpl/.

Source file: ClassPathFormImpl.java

  21 
vote

public void actionPerformed(ActionEvent e){
  try {
    _fileChooser.setFileFilter(_filter);
    _fileChooser.setSelectedFile(new File(""));
    if (_fileChooser.showOpenDialog(MainFrame.getInstance()) == JFileChooser.APPROVE_OPTION) {
      JarFile jar=new JarFile(_fileChooser.getSelectedFile());
      if (jar.getManifest() == null) {
        jar.close();
        MainFrame.getInstance().info(Messages.getString("noManifest"));
        return;
      }
      Attributes attr=jar.getManifest().getMainAttributes();
      String mainClass=(String)attr.getValue("Main-Class");
      String classPath=(String)attr.getValue("Class-Path");
      jar.close();
      _mainclassField.setText(mainClass != null ? mainClass : "");
      DefaultListModel model=new DefaultListModel();
      if (classPath != null) {
        String[] paths=classPath.split(" ");
        for (int i=0; i < paths.length; i++) {
          model.addElement(paths[i]);
        }
      }
      _classpathList.setModel(model);
    }
  }
 catch (  IOException ex) {
    MainFrame.getInstance().warn(ex.getMessage());
  }
}
 

Example 50

From project mobilis, under directory /MobilisServer/src/de/tudresden/inf/rn/mobilis/server/deployment/helper/.

Source file: FileHelper.java

  21 
vote

/** 
 * Gets queries a value of the manifest of a jar file by a specific key.
 * @param jarFile the jar file which should be queried
 * @param key the key of the value in the manifest file
 * @return the value which was found by the key
 */
public static String getJarManifestValue(File jarFile,String key){
  String value=null;
  try {
    if (jarFile.exists()) {
      JarFile jarfile=new JarFile(jarFile.getAbsoluteFile());
      Manifest manifest=jarfile.getManifest();
      Attributes attrs=(Attributes)manifest.getMainAttributes();
      value=attrs.getValue(key);
      jarfile.close();
    }
  }
 catch (  IOException e) {
    e.printStackTrace();
  }
  return value;
}
 

Example 51

From project mvnplugins, under directory /maven-uberize-plugin/src/main/java/org/fusesource/mvnplugins/uberize/transformer/.

Source file: ManifestEditor.java

  21 
vote

public void process(Uberizer uberizer,File workDir,TreeMap<String,UberEntry> uberEntries) throws IOException {
  Manifest manifest;
  final UberEntry uberEntry=uberEntries.get(MANIFEST_PATH);
  if (uberEntry != null && uberEntry.getSources().size() > 0) {
    FileInputStream is=new FileInputStream(uberEntry.getSources().get(0));
    try {
      manifest=new Manifest(is);
    }
  finally {
      IOUtil.close(is);
    }
  }
 else {
    manifest=new Manifest();
  }
  Attributes attributes=manifest.getMainAttributes();
  if (mainClass != null) {
    attributes.put(Attributes.Name.MAIN_CLASS,mainClass);
  }
  if (manifestEntries != null) {
    for (Iterator i=manifestEntries.keySet().iterator(); i.hasNext(); ) {
      String key=(String)i.next();
      attributes.put(new Attributes.Name(key),manifestEntries.get(key));
    }
  }
  File targetFile=DefaultUberizer.prepareFile(workDir,MANIFEST_PATH);
  FileOutputStream os=new FileOutputStream(targetFile);
  try {
    manifest.write(os);
  }
  finally {
    IOUtil.close(os);
  }
  UberEntry modEntry=new UberEntry(MANIFEST_PATH,uberEntry).addSource(targetFile);
  uberEntries.put(MANIFEST_PATH,modEntry);
}
 

Example 52

From project nexus-p2-repository-plugin, under directory /src/main/java/org/sonatype/nexus/plugins/p2/repository/internal/.

Source file: JarsEventsInspector.java

  21 
vote

static boolean isABundle(final File file){
  if (file == null) {
    return false;
  }
  JarFile jarFile=null;
  try {
    jarFile=new JarFile(file);
    final Manifest manifest=jarFile.getManifest();
    final Attributes mainAttributes=manifest.getMainAttributes();
    return mainAttributes.getValue("Bundle-SymbolicName") != null;
  }
 catch (  final Exception e) {
    return false;
  }
 finally {
    if (jarFile != null) {
      try {
        jarFile.close();
      }
 catch (      final Exception ignored) {
      }
    }
  }
}
 

Example 53

From project nuxeo-tycho-osgi, under directory /nuxeo-runtime/nuxeo-runtime-deploy/src/main/java/org/nuxeo/runtime/deployment/preprocessor/.

Source file: DeploymentPreprocessor.java

  21 
vote

protected String getSymbolicName(File file) throws Exception {
  Manifest mf=JarUtils.getManifest(file);
  if (mf != null) {
    Attributes attrs=mf.getMainAttributes();
    String id=attrs.getValue("Bundle-SymbolicName");
    if (id != null) {
      int p=id.indexOf(';');
      if (p > -1) {
        id=id.substring(0,p);
      }
      return id;
    }
  }
  return null;
}
 

Example 54

From project org.openscada.aurora, under directory /org.openscada.pde.maven.target/src/com/inavare/maven/platform/.

Source file: LocalMavenRepostory.java

  21 
vote

private boolean isBundle(final File file){
  if (!file.getName().toLowerCase().endsWith(".jar")) {
    return false;
  }
  JarFile jarFile=null;
  try {
    jarFile=new JarFile(file);
    final Manifest m=jarFile.getManifest();
    if (m == null) {
      return false;
    }
    final Attributes a=m.getMainAttributes();
    final Object o=a.getValue("Bundle-SymbolicName");
    return o != null;
  }
 catch (  IOException e) {
    return false;
  }
 finally {
    if (jarFile != null) {
      try {
        jarFile.close();
      }
 catch (      IOException e) {
        Activator.getDefault().getLog().log(new Status(Status.ERROR,Activator.PLUGIN_ID,"Failed to close jar file",e));
      }
    }
  }
}
 

Example 55

From project org.ops4j.pax.tinybundles, under directory /src/main/java/org/ops4j/pax/tinybundles/core/intern/.

Source file: TinyBundleImpl.java

  21 
vote

/** 
 * {@inheritDoc}
 */
public TinyBundle read(InputStream in){
  if (in != null) {
    try {
      Handle handle=m_store.store(in);
      JarInputStream jarOut=new JarInputStream(m_store.load(handle));
      Manifest manifest=jarOut.getManifest();
      Attributes att=manifest.getMainAttributes();
      for (      Object o : att.keySet()) {
        String k=o.toString();
        String v=att.getValue(k);
        set(k,v);
      }
      JarEntry entry=null;
      while ((entry=jarOut.getNextJarEntry()) != null) {
        add(entry.getName(),jarOut);
      }
    }
 catch (    IOException e) {
      throw new RuntimeException("Problem loading bundle.",e);
    }
  }
  return this;
}
 

Example 56

From project RemoteApplications, under directory /src/test/java/org/robotframework/remoteapplications/launch/jnlp/.

Source file: JarImplSpec.java

  21 
vote

public void getsMainClass() throws Exception {
  final Manifest manifest=mock(Manifest.class);
  final Attributes mainAttributes=mock(Attributes.class);
  final String mainClass="com.acme.Foo";
  checking(new Expectations(){
{
      one(jarFile).getManifest();
      will(returnValue(manifest));
      one(manifest).getMainAttributes();
      will(returnValue(mainAttributes));
      one(mainAttributes).getValue("Main-Class");
      will(returnValue(mainClass));
    }
  }
);
  specify(context.getMainClass(),mainClass);
}
 

Example 57

From project RomRaider, under directory /3rdparty/launch4j/src/net/sf/launch4j/formimpl/.

Source file: ClassPathFormImpl.java

  21 
vote

public void actionPerformed(ActionEvent e){
  try {
    _fileChooser.setFileFilter(_filter);
    _fileChooser.setSelectedFile(new File(""));
    if (_fileChooser.showOpenDialog(MainFrame.getInstance()) == JFileChooser.APPROVE_OPTION) {
      JarFile jar=new JarFile(_fileChooser.getSelectedFile());
      if (jar.getManifest() == null) {
        jar.close();
        MainFrame.getInstance().info(Messages.getString("noManifest"));
        return;
      }
      Attributes attr=jar.getManifest().getMainAttributes();
      String mainClass=(String)attr.getValue("Main-Class");
      String classPath=(String)attr.getValue("Class-Path");
      jar.close();
      _mainclassField.setText(mainClass != null ? mainClass : "");
      DefaultListModel model=new DefaultListModel();
      if (classPath != null) {
        String[] paths=classPath.split(" ");
        for (int i=0; i < paths.length; i++) {
          model.addElement(paths[i]);
        }
      }
      _classpathList.setModel(model);
    }
  }
 catch (  IOException ex) {
    MainFrame.getInstance().warn(ex.getMessage());
  }
}
 

Example 58

From project sandbox, under directory /xoo/src/main/java/org/xwiki/xoo/.

Source file: RegistrationHandler.java

  21 
vote

/** 
 * @return the classes which really are service implementation classes
 */
private static String getRegistrationClasses(){
  RegistrationHandler c=new RegistrationHandler();
  String name=c.getClass().getCanonicalName().replace('.','/').concat(".class");
  try {
    Enumeration<URL> urlEnum=c.getClass().getClassLoader().getResources("META-INF/MANIFEST.MF");
    while (urlEnum.hasMoreElements()) {
      URL url=urlEnum.nextElement();
      JarURLConnection jarConnection=(JarURLConnection)url.openConnection();
      Manifest mf=jarConnection.getManifest();
      Attributes attrs=(Attributes)mf.getAttributes(name);
      if (attrs != null) {
        String classes=attrs.getValue("RegistrationClasses");
        return classes;
      }
    }
  }
 catch (  IOException ex) {
    ex.printStackTrace();
  }
  return "";
}
 

Example 59

From project SPREAD, under directory /release/tools/launch4j/src/net/sf/launch4j/formimpl/.

Source file: ClassPathFormImpl.java

  21 
vote

public void actionPerformed(ActionEvent e){
  try {
    _fileChooser.setFileFilter(_filter);
    _fileChooser.setSelectedFile(new File(""));
    if (_fileChooser.showOpenDialog(MainFrame.getInstance()) == JFileChooser.APPROVE_OPTION) {
      JarFile jar=new JarFile(_fileChooser.getSelectedFile());
      if (jar.getManifest() == null) {
        jar.close();
        MainFrame.getInstance().info(Messages.getString("noManifest"));
        return;
      }
      Attributes attr=jar.getManifest().getMainAttributes();
      String mainClass=(String)attr.getValue("Main-Class");
      String classPath=(String)attr.getValue("Class-Path");
      jar.close();
      _mainclassField.setText(mainClass != null ? mainClass : "");
      DefaultListModel model=new DefaultListModel();
      if (classPath != null) {
        String[] paths=classPath.split(" ");
        for (int i=0; i < paths.length; i++) {
          model.addElement(paths[i]);
        }
      }
      _classpathList.setModel(model);
    }
  }
 catch (  IOException ex) {
    MainFrame.getInstance().warn(ex.getMessage());
  }
}
 

Example 60

From project tattletale, under directory /src/main/java/org/jboss/tattletale/analyzers/.

Source file: AbstractScanner.java

  21 
vote

/** 
 * Returns the version as a String once read from the manifest.
 * @param manifest - the manifest obtained from the JarFile
 * @return - the version as a String.
 */
protected String versionFromManifest(Manifest manifest){
  Attributes mainAttributes=manifest.getMainAttributes();
  String version=mainAttributes.getValue("Specification-Version");
  if (version == null) {
    version=mainAttributes.getValue("Implementation-Version");
  }
  if (version == null) {
    version=mainAttributes.getValue("Version");
  }
  if (version == null && manifest.getEntries() != null) {
    Iterator ait=manifest.getEntries().values().iterator();
    while (version == null && ait.hasNext()) {
      Attributes attributes=(Attributes)ait.next();
      version=attributes.getValue("Specification-Version");
      if (version == null) {
        version=attributes.getValue("Implementation-Version");
      }
      if (version == null) {
        version=attributes.getValue("Version");
      }
    }
  }
  return version;
}
 

Example 61

From project thinklab, under directory /plugins/org.integratedmodelling.thinklab.http/src/org/integratedmodelling/thinklab/http/utils/.

Source file: JarUtils.java

  21 
vote

private static void test(String checkDir,String outputPath,String manifestVerion,String mainClass,String classPath){
  try {
    System.out.println(checkDir);
    String strBaseFolder=checkDir + "/";
    iBaseFolderLength=strBaseFolder.length();
    fos=new FileOutputStream(outputPath);
    Manifest manifest=new Manifest();
    Attributes manifestAttr=manifest.getMainAttributes();
    if (manifestVerion != null) {
      manifestAttr.putValue("Manifest-Version",manifestVerion);
      if (mainClass != null) {
        manifestAttr.putValue("Main-Class",mainClass);
      }
      if (classPath != null) {
        manifestAttr.putValue("Class-Path",classPath);
      }
    }
    java.util.Set entries=manifestAttr.entrySet();
    for (java.util.Iterator i=entries.iterator(); i.hasNext(); ) {
      System.out.println("Manifest attribute:>> " + i.next().toString());
    }
    jos=new JarOutputStream(fos,manifest);
    System.out.println(strBaseFolder);
    checkDirectory(checkDir);
    jos.flush();
    jos.close();
    fos.close();
  }
 catch (  IOException e) {
    e.printStackTrace();
  }
}
 

Example 62

From project tiles, under directory /tiles-extras/src/main/java/org/apache/tiles/extras/module/.

Source file: ModularTilesInitializer.java

  21 
vote

/** 
 * Load all the initializers from manifest files.
 * @param applicationContext The application context.
 */
private void loadInitializers(ApplicationContext applicationContext){
  initializers=new ArrayList<TilesInitializer>();
  try {
    Collection<ApplicationResource> resources=applicationContext.getResources("classpath*:META-INF/MANIFEST.MF");
    ApplicationResource mainResource=applicationContext.getResource("/META-INF/MANIFEST.MF");
    if (mainResource != null) {
      resources.add(mainResource);
    }
    for (    ApplicationResource resource : resources) {
      InputStream stream=resource.getInputStream();
      try {
        Manifest manifest=new Manifest(stream);
        Attributes attributes=manifest.getMainAttributes();
        if (attributes != null) {
          String initializerName=attributes.getValue("Tiles-Initializer");
          if (initializerName != null) {
            TilesInitializer initializer=(TilesInitializer)ClassUtil.instantiate(initializerName);
            initializers.add(initializer);
          }
        }
      }
  finally {
        stream.close();
      }
    }
  }
 catch (  IOException e) {
    throw new DefinitionsFactoryException("Error getting manifest files",e);
  }
}
 

Example 63

From project tycho.extras, under directory /tycho-custom-bundle-plugin/src/main/java/org/eclipse/tycho/extras/custombundle/.

Source file: CustomBundleMojo.java

  21 
vote

private File updateManifest() throws FileNotFoundException, IOException, MojoExecutionException {
  File mfile=new File(bundleLocation,"META-INF/MANIFEST.MF");
  InputStream is=new FileInputStream(mfile);
  Manifest mf;
  try {
    mf=new Manifest(is);
  }
  finally {
    is.close();
  }
  Attributes attributes=mf.getMainAttributes();
  if (attributes.getValue(Name.MANIFEST_VERSION) == null) {
    attributes.put(Name.MANIFEST_VERSION,"1.0");
  }
  ReactorProject reactorProject=DefaultReactorProject.adapt(project);
  attributes.putValue("Bundle-Version",reactorProject.getExpandedVersion());
  mfile=new File(project.getBuild().getDirectory(),classifier + "-MANIFEST.MF");
  mfile.getParentFile().mkdirs();
  BufferedOutputStream os=new BufferedOutputStream(new FileOutputStream(mfile));
  try {
    mf.write(os);
  }
  finally {
    os.close();
  }
  return mfile;
}
 

Example 64

From project apb, under directory /modules/apb-base/src/apb/tasks/.

Source file: JarTask.java

  19 
vote

private JarTask(@NotNull File jarFile,@NotNull List<FileSet> sources){
  this.jarFile=jarFile;
  this.sources=sources;
  services=Collections.emptyMap();
  manifest=new Manifest();
  manifest.getMainAttributes().put(Attributes.Name.MANIFEST_VERSION,"1.0");
  manifest.getMainAttributes().putValue("Created-By","APB");
}
 

Example 65

From project incubator-deltaspike, under directory /deltaspike/core/api/src/main/java/org/apache/deltaspike/core/util/.

Source file: ClassUtils.java

  19 
vote

/** 
 * Reads the version of the jar which contains the given class
 * @param targetClass class within the jar
 * @return version-string which has been found in the manifest or null if there is no version information available
 */
public static String getJarVersion(Class targetClass){
  String manifestFileLocation=getManifestFileLocationOfClass(targetClass);
  try {
    return new Manifest(new URL(manifestFileLocation).openStream()).getMainAttributes().getValue(Attributes.Name.IMPLEMENTATION_VERSION);
  }
 catch (  Exception e) {
    return null;
  }
}
 

Example 66

From project karaf, under directory /deployer/wrap/src/main/java/org/apache/karaf/deployer/wrap/.

Source file: WrapDeploymentListener.java

  19 
vote

public boolean canHandle(File artifact){
  try {
    if (!artifact.getPath().endsWith(".jar")) {
      return false;
    }
    JarFile jar=new JarFile(artifact);
    try {
      Manifest manifest=jar.getManifest();
      if (manifest != null && manifest.getMainAttributes().getValue(new Attributes.Name("Bundle-SymbolicName")) != null && manifest.getMainAttributes().getValue(new Attributes.Name("Bundle-Version")) != null) {
        return false;
      }
      return true;
    }
  finally {
      jar.close();
    }
  }
 catch (  Exception e) {
    return false;
  }
}
 

Example 67

From project myfaces-extcdi, under directory /core/api/src/main/java/org/apache/myfaces/extensions/cdi/core/api/util/.

Source file: ClassUtils.java

  19 
vote

/** 
 * Reads the version of the jar which contains the given class
 * @param targetClass class within the jar
 * @return version-string which has been found in the manifest or null if there is no version information available
 */
public static String getJarVersion(Class targetClass){
  String manifestFileLocation=getManifestFileLocationOfClass(targetClass);
  try {
    return new Manifest(new URL(manifestFileLocation).openStream()).getMainAttributes().getValue(Attributes.Name.IMPLEMENTATION_VERSION);
  }
 catch (  Exception e) {
    return null;
  }
}