Java Code Examples for java.util.jar.Attributes.Name

The following are top voted examples for showing how to use java.util.jar.Attributes.Name. These examples are extracted from open source projects. You can vote up the examples you like and your votes will be used in our system to generate more good examples.
Example 1
Project: tomcat7   File: WebappClassLoaderBase.java   View source code 6 votes vote down vote up
/**
 * Returns true if the specified package name is sealed according to the
 * given manifest.
 */
protected boolean isPackageSealed(String name, Manifest man) {

    String path = name.replace('.', '/') + '/';
    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 2
Project: lams   File: WebappClassLoader.java   View source code 6 votes vote down vote up
/**
 * Returns true if the specified package name is sealed according to the
 * given manifest.
 */
protected boolean isPackageSealed(String name, Manifest man) {

    String path = name.replace('.', '/') + '/';
    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 3
Project: javaide   File: URLClassPath.java   View source code 6 votes vote down vote up
URL[] getClassPath() throws IOException {
    if (index != null) {
        return null;
    }

    if (metaIndex != null) {
        return null;
    }

    ensureOpen();
    parseExtensionsDependencies();
    if (SharedSecrets.javaUtilJarAccess().jarFileHasClassPathAttribute(jar)) { // Only get manifest when necessary
        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 4
Project: OpenJSharp   File: URLClassPath.java   View source code 6 votes vote down vote up
URL[] getClassPath() throws IOException {
    if (index != null) {
        return null;
    }

    if (metaIndex != null) {
        return null;
    }

    ensureOpen();
    parseExtensionsDependencies();

    if (SharedSecrets.javaUtilJarAccess().jarFileHasClassPathAttribute(jar)) { // Only get manifest when necessary
        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 5
Project: jerrydog   File: WebappClassLoader.java   View source code 6 votes vote down vote up
/**
 * Returns true if the specified package name is sealed according to the
 * given manifest.
 */
protected boolean isPackageSealed(String name, Manifest man) {

    String path = name + "/";
    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 6
Project: Agent   File: Agent.java   View source code 6 votes vote down vote up
public static File createAgent(Class<?> agent, Class<?>... resources) throws IOException {
    File jarFile = File.createTempFile("agent", ".jar");
    jarFile.deleteOnExit();
    Manifest manifest = new Manifest();
    Attributes mainAttributes = manifest.getMainAttributes();
    mainAttributes.put(Name.MANIFEST_VERSION, "1.0");
    mainAttributes.put(new Name("Agent-Class"), agent.getName());
    mainAttributes.put(new Name("Can-Retransform-Classes"), "true");
    mainAttributes.put(new Name("Can-Redefine-Classes"), "true");
    JarOutputStream jos = new JarOutputStream(new FileOutputStream(jarFile), manifest);
    jos.putNextEntry(new JarEntry(agent.getName().replace('.', '/') + ".class"));
    jos.write(getBytesFromStream(agent.getClassLoader().getResourceAsStream(unqualify(agent))));
    jos.closeEntry();
    for (Class<?> clazz : resources) {
        String name = unqualify(clazz);
        jos.putNextEntry(new JarEntry(name));
        jos.write(getBytesFromStream(clazz.getClassLoader().getResourceAsStream(name)));
        jos.closeEntry();
    }

    jos.close();
    return jarFile;
}
 
Example 7
Project: apache-tomcat-7.0.73-with-comment   File: WebappClassLoaderBase.java   View source code 6 votes vote down vote up
/**
 * Returns true if the specified package name is sealed according to the
 * given manifest.
 */
protected boolean isPackageSealed(String name, Manifest man) {

    String path = name.replace('.', '/') + '/';
    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 8
Project: jdk8u-jdk   File: URLClassPath.java   View source code 6 votes vote down vote up
URL[] getClassPath() throws IOException {
    if (index != null) {
        return null;
    }

    if (metaIndex != null) {
        return null;
    }

    ensureOpen();
    parseExtensionsDependencies();

    if (SharedSecrets.javaUtilJarAccess().jarFileHasClassPathAttribute(jar)) { // Only get manifest when necessary
        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 9
Project: openjdk-jdk10   File: URLClassPath.java   View source code 6 votes vote down vote up
@Override
URL[] getClassPath() throws IOException {
    if (index != null) {
        return null;
    }

    ensureOpen();

    // Only get manifest when necessary
    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 10
Project: lazycat   File: WebappClassLoaderBase.java   View source code 6 votes vote down vote up
/**
 * Returns true if the specified package name is sealed according to the
 * given manifest.
 */
protected boolean isPackageSealed(String name, Manifest man) {

	String path = name.replace('.', '/') + '/';
	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 11
Project: openjdk9   File: URLClassPath.java   View source code 6 votes vote down vote up
URL[] getClassPath() throws IOException {
    if (index != null) {
        return null;
    }

    ensureOpen();

    // Only get manifest when necessary
    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 12
Project: turing   File: CloseableURLClassLoader.java   View source code 6 votes vote down vote up
private void checkForSealedPackage(Package pkg, String packageName, Manifest manifest, URL jarFileURL) {
	if (pkg.isSealed() && !pkg.isSealed(jarFileURL))
		throw new SecurityException("The package '" + packageName + "' was previously loaded and is already sealed."); //$NON-NLS-1$ //$NON-NLS-2$

	String entryPath = packageName.replace('.', '/') + "/"; //$NON-NLS-1$
	Attributes entryAttributes = manifest.getAttributes(entryPath);
	String sealed = null;
	if (entryAttributes != null)
		sealed = entryAttributes.getValue(Name.SEALED);

	if (sealed == null) {
		Attributes mainAttributes = manifest.getMainAttributes();
		if (mainAttributes != null)
			sealed = mainAttributes.getValue(Name.SEALED);
	}
	if (Boolean.valueOf(sealed).booleanValue())
		throw new SecurityException("The package '" + packageName + "' was previously loaded unsealed. Cannot seal package."); //$NON-NLS-1$ //$NON-NLS-2$
}
 
Example 13
Project: jdk8u_jdk   File: URLClassPath.java   View source code 6 votes vote down vote up
URL[] getClassPath() throws IOException {
    if (index != null) {
        return null;
    }

    if (metaIndex != null) {
        return null;
    }

    ensureOpen();
    parseExtensionsDependencies();

    if (SharedSecrets.javaUtilJarAccess().jarFileHasClassPathAttribute(jar)) { // Only get manifest when necessary
        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 14
Project: lookaside_java-1.8.0-openjdk   File: URLClassPath.java   View source code 6 votes vote down vote up
URL[] getClassPath() throws IOException {
    if (index != null) {
        return null;
    }

    if (metaIndex != null) {
        return null;
    }

    ensureOpen();
    parseExtensionsDependencies();

    if (SharedSecrets.javaUtilJarAccess().jarFileHasClassPathAttribute(jar)) { // Only get manifest when necessary
        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 15
Project: javify   File: JarUtils.java   View source code 6 votes vote down vote up
/**
 * Pedantic method that requires the next attribute in the Manifest to be the
 * "Manifest-Version". This follows the Manifest spec closely but reject some
 * jar Manifest files out in the wild.
 */
private static void readVersionInfo(Attributes attr, BufferedReader br)
    throws IOException
{
  String version_header = Name.MANIFEST_VERSION.toString();
  try
    {
      String value = expectHeader(version_header, br);
      attr.putValue(MANIFEST_VERSION, value);
    }
  catch (IOException ioe)
    {
      throw new JarException("Manifest should start with a " + version_header
                             + ": " + ioe.getMessage());
    }
}
 
Example 16
Project: jvm-stm   File: JarUtils.java   View source code 6 votes vote down vote up
/**
 * Pedantic method that requires the next attribute in the Manifest to be the
 * "Manifest-Version". This follows the Manifest spec closely but reject some
 * jar Manifest files out in the wild.
 */
private static void readVersionInfo(Attributes attr, BufferedReader br)
    throws IOException
{
  String version_header = Name.MANIFEST_VERSION.toString();
  try
    {
      String value = expectHeader(version_header, br);
      attr.putValue(MANIFEST_VERSION, value);
    }
  catch (IOException ioe)
    {
      throw new JarException("Manifest should start with a " + version_header
                             + ": " + ioe.getMessage());
    }
}
 
Example 17
Project: infobip-open-jdk-8   File: URLClassPath.java   View source code 6 votes vote down vote up
URL[] getClassPath() throws IOException {
    if (index != null) {
        return null;
    }

    if (metaIndex != null) {
        return null;
    }

    ensureOpen();
    parseExtensionsDependencies();

    if (SharedSecrets.javaUtilJarAccess().jarFileHasClassPathAttribute(jar)) { // Only get manifest when necessary
        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 18
Project: jdk8u-dev-jdk   File: URLClassPath.java   View source code 6 votes vote down vote up
URL[] getClassPath() throws IOException {
    if (index != null) {
        return null;
    }

    if (metaIndex != null) {
        return null;
    }

    ensureOpen();
    parseExtensionsDependencies();

    if (SharedSecrets.javaUtilJarAccess().jarFileHasClassPathAttribute(jar)) { // Only get manifest when necessary
        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 19
Project: Lucee   File: ManifestUtil.java   View source code 6 votes vote down vote up
private static void printSection(StringBuilder sb, Attributes attrs, int maxLineSize, Set<String> ignore) {
	Iterator<Entry<Object, Object>> it = attrs.entrySet().iterator();
	Entry<Object, Object> e;
	String name;
	String value;
	while(it.hasNext()){
		e = it.next();
		name=((Name)e.getKey()).toString();
		value=(String)e.getValue();
		if(StringUtil.isEmpty(value)) continue;
		//aprint.e("Export-Package:"+name+":"+("Export-Package".equals(name)));
		if("Import-Package".equals(name) || "Export-Package".equals(name) || "Require-Bundle".equals(name)) {
			value=splitByComma(value);
			
		}
		else if(value.length()>maxLineSize) value=split(value,maxLineSize);
		
		if(ignore!=null && ignore.contains(name)) continue;
		add(sb,name,value,null);
	}
}
 
Example 20
Project: jdk7-jdk   File: URLClassPath.java   View source code 6 votes vote down vote up
URL[] getClassPath() throws IOException {
    if (index != null) {
        return null;
    }

    if (metaIndex != null) {
        return null;
    }

    ensureOpen();
    parseExtensionsDependencies();
    if (SharedSecrets.javaUtilJarAccess().jarFileHasClassPathAttribute(jar)) { // Only get manifest when necessary
        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 21
Project: openjdk-source-code-learn   File: URLClassPath.java   View source code 6 votes vote down vote up
URL[] getClassPath() throws IOException {
    if (index != null) {
        return null;
    }

    if (metaIndex != null) {
        return null;
    }

    ensureOpen();
    parseExtensionsDependencies();
    if (SharedSecrets.javaUtilJarAccess().jarFileHasClassPathAttribute(jar)) { // Only get manifest when necessary
        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 22
Project: WeatherDataCollector   File: WeatherDataCollector.java   View source code 6 votes vote down vote up
/**
 * Method print all available information from the jar's manifest file. 
 */
private static void logApplicationMetadata() {
	LOG.trace("logApplicationMetadata()");
	InputStream manifestStream;
	String logMessage;
	//
	logMessage = "Application started";
	manifestStream = Thread.currentThread().getContextClassLoader().getResourceAsStream("META-INF/MANIFEST.MF");
	try {
		final Manifest manifest = new Manifest(manifestStream);
		final Attributes attributes = manifest.getMainAttributes();
		final Set<Object> keys = attributes.keySet();
		for (final Object object : keys) {
			if (object instanceof Name) {
				final Name key = (Name) object;
				logMessage += String.format("\n\t\t%s: %s",key,attributes.getValue(key));
			}
		}
		// add heap information
		logMessage += "\n\t\t" + heapSizeInformation();
	}
	catch(final IOException ex) {
		LOG.warn("Error while reading manifest file from application jar file: " + ex.getMessage());
	}
	LOG.info(logMessage);
}
 
Example 23
Project: wso2-commons-vfs   File: VFSClassLoader.java   View source code 6 votes vote down vote up
/**
 * Reads attributes for the package and defines it.
 */
private Package definePackage(final String name,
                              final Resource res)
    throws FileSystemException
{
    // TODO - check for MANIFEST_ATTRIBUTES capability first
    final String specTitle = res.getPackageAttribute(Name.SPECIFICATION_TITLE);
    final String specVendor = res.getPackageAttribute(Attributes.Name.SPECIFICATION_VENDOR);
    final String specVersion = res.getPackageAttribute(Name.SPECIFICATION_VERSION);
    final String implTitle = res.getPackageAttribute(Name.IMPLEMENTATION_TITLE);
    final String implVendor = res.getPackageAttribute(Name.IMPLEMENTATION_VENDOR);
    final String implVersion = res.getPackageAttribute(Name.IMPLEMENTATION_VERSION);

    final URL sealBase;
    if (isSealed(res))
    {
        sealBase = res.getCodeSourceURL();
    }
    else
    {
        sealBase = null;
    }

    return definePackage(name, specTitle, specVersion, specVendor,
        implTitle, implVersion, implVendor, sealBase);
}
 
Example 24
Project: class-guard   File: WebappClassLoader.java   View source code 6 votes vote down vote up
/**
 * Returns true if the specified package name is sealed according to the
 * given manifest.
 */
protected boolean isPackageSealed(String name, Manifest man) {

    String path = name.replace('.', '/') + '/';
    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 25
Project: OLD-OpenJDK8   File: URLClassPath.java   View source code 6 votes vote down vote up
URL[] getClassPath() throws IOException {
    if (index != null) {
        return null;
    }

    if (metaIndex != null) {
        return null;
    }

    ensureOpen();
    parseExtensionsDependencies();

    if (SharedSecrets.javaUtilJarAccess().jarFileHasClassPathAttribute(jar)) { // Only get manifest when necessary
        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 26
Project: jmockit1   File: ClassLoadingAndJREMocksTest.java   View source code 6 votes vote down vote up
String readMainClassAndFileNamesFromJar(File file, List<String> containedFileNames) throws IOException {
   JarFile jarFile = new JarFile(file);

   Manifest manifest = jarFile.getManifest();
   Attributes mainAttributes = manifest.getMainAttributes();
   String mainClassName = mainAttributes.getValue(Name.MAIN_CLASS);

   Enumeration<JarEntry> jarEntries = jarFile.entries();

   while (jarEntries.hasMoreElements()) {
      JarEntry jarEntry = jarEntries.nextElement();
      containedFileNames.add(jarEntry.getName());
   }

   return mainClassName;
}
 
Example 27
Project: jmockit1   File: ClassLoadingAndJREMocksTest.java   View source code 6 votes vote down vote up
@Test
public void mockJavaUtilJarClasses(
   @Mocked final JarFile mockFile, @Mocked final Manifest mockManifest, @Mocked final Attributes mockAttributes,
   @Mocked final Enumeration<JarEntry> mockEntries, @Mocked final JarEntry mockEntry
) throws Exception {
   File testFile = new File("test.jar");
   final String mainClassName = "test.Main";

   new Expectations() {{
      mockFile.getManifest(); result = mockManifest;
      mockManifest.getMainAttributes(); result = mockAttributes;
      mockAttributes.getValue(Name.MAIN_CLASS); result = mainClassName;
      mockFile.entries(); result = mockEntries;

      mockEntries.hasMoreElements(); returns(true, true, false);
      mockEntries.nextElement(); result = mockEntry;
      mockEntry.getName(); returns("test/Main$Inner.class", "test/Main.class");
   }};

   List<String> fileNames = new ArrayList<String>();
   String mainClassFromJar = readMainClassAndFileNamesFromJar(testFile, fileNames);

   assertEquals(mainClassName, mainClassFromJar);
   assertEquals(asList("test/Main$Inner.class", "test/Main.class"), fileNames);
}
 
Example 28
Project: JamVM-PH   File: JarUtils.java   View source code 6 votes vote down vote up
/**
 * Pedantic method that requires the next attribute in the Manifest to be the
 * "Manifest-Version". This follows the Manifest spec closely but reject some
 * jar Manifest files out in the wild.
 */
private static void readVersionInfo(Attributes attr, BufferedReader br)
    throws IOException
{
  String version_header = Name.MANIFEST_VERSION.toString();
  try
    {
      String value = expectHeader(version_header, br);
      attr.putValue(MANIFEST_VERSION, value);
    }
  catch (IOException ioe)
    {
      throw new JarException("Manifest should start with a " + version_header
                             + ": " + ioe.getMessage());
    }
}
 
Example 29
Project: apache-tomcat-7.0.57   File: WebappClassLoader.java   View source code 6 votes vote down vote up
/**
 * Returns true if the specified package name is sealed according to the
 * given manifest.
 */
protected boolean isPackageSealed(String name, Manifest man) {

    String path = name.replace('.', '/') + '/';
    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 30
Project: apache-tomcat-7.0.57   File: WebappClassLoader.java   View source code 6 votes vote down vote up
/**
 * Returns true if the specified package name is sealed according to the
 * given manifest.
 */
protected boolean isPackageSealed(String name, Manifest man) {

    String path = name.replace('.', '/') + '/';
    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 31
Project: openjdk-jdk7u-jdk   File: URLClassPath.java   View source code 6 votes vote down vote up
URL[] getClassPath() throws IOException {
    if (index != null) {
        return null;
    }

    if (metaIndex != null) {
        return null;
    }

    ensureOpen();
    parseExtensionsDependencies();
    if (SharedSecrets.javaUtilJarAccess().jarFileHasClassPathAttribute(jar)) { // Only get manifest when necessary
        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 32
Project: HowTomcatWorks   File: WebappClassLoader.java   View source code 6 votes vote down vote up
/**
 * Returns true if the specified package name is sealed according to the
 * given manifest.
 */
protected boolean isPackageSealed(String name, Manifest man) {

    String path = name + "/";
    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 33
Project: classpath   File: JarUtils.java   View source code 6 votes vote down vote up
/**
 * Pedantic method that requires the next attribute in the Manifest to be the
 * "Manifest-Version". This follows the Manifest spec closely but reject some
 * jar Manifest files out in the wild.
 */
private static void readVersionInfo(Attributes attr, BufferedReader br)
    throws IOException
{
  String version_header = Name.MANIFEST_VERSION.toString();
  try
    {
      String value = expectHeader(version_header, br);
      attr.putValue(MANIFEST_VERSION, value);
    }
  catch (IOException ioe)
    {
      throw new JarException("Manifest should start with a " + version_header
                             + ": " + ioe.getMessage());
    }
}
 
Example 34
Project: openjdk-icedtea7   File: URLClassPath.java   View source code 6 votes vote down vote up
URL[] getClassPath() throws IOException {
    if (index != null) {
        return null;
    }

    if (metaIndex != null) {
        return null;
    }

    ensureOpen();
    parseExtensionsDependencies();
    if (SharedSecrets.javaUtilJarAccess().jarFileHasClassPathAttribute(jar)) { // Only get manifest when necessary
        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 35
Project: WBSAirback   File: WebappClassLoader.java   View source code 6 votes vote down vote up
/**
 * Returns true if the specified package name is sealed according to the
 * given manifest.
 */
protected boolean isPackageSealed(String name, Manifest man) {

    String path = name.replace('.', '/') + '/';
    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 36
Project: pdi-vfs   File: VFSClassLoader.java   View source code 6 votes vote down vote up
/**
 * Reads attributes for the package and defines it.
 */
private Package definePackage(final String name,
                              final Resource res)
    throws FileSystemException
{
    // TODO - check for MANIFEST_ATTRIBUTES capability first
    final String specTitle = res.getPackageAttribute(Name.SPECIFICATION_TITLE);
    final String specVendor = res.getPackageAttribute(Attributes.Name.SPECIFICATION_VENDOR);
    final String specVersion = res.getPackageAttribute(Name.SPECIFICATION_VERSION);
    final String implTitle = res.getPackageAttribute(Name.IMPLEMENTATION_TITLE);
    final String implVendor = res.getPackageAttribute(Name.IMPLEMENTATION_VENDOR);
    final String implVersion = res.getPackageAttribute(Name.IMPLEMENTATION_VERSION);

    final URL sealBase;
    if (isSealed(res))
    {
        sealBase = res.getCodeSourceURL();
    }
    else
    {
        sealBase = null;
    }

    return definePackage(name, specTitle, specVersion, specVendor,
        implTitle, implVersion, implVendor, sealBase);
}
 
Example 37
Project: ant_modular   File: ManifestModuleLoader.java   View source code 6 votes vote down vote up
/**
 * <p>Loads metadata of the module with a given path, not necessarily normalised.
 * If the module metadata cannot be loaded then a {@link ModuleNotLoadedException}
 * is thrown.</p>
 * 
 * <p>Refer to the {@link ManifestModuleLoader class description} for the details about
 * how metadata is stored for a module.</p>
 * 
 * @param path the module path. It is a path relative to the Ant project base directory.
 *      This path is allowed to be a non-normalised module path but must be not {@code null}.
 * 
 * @return a {@link afc.ant.modular.ModuleInfo} object that is initialised
 *      with the module path, dependencies and attributes. It is never {@code null}
 *      and is initialised with the {@link #normalisePath(String) normalised module path}.
 * 
 * @throws NullPointerException if <em>path</em> is {@code null}.
 * @throws ModuleNotLoadedException if the module meta information cannot be loaded.
 */
public ModuleInfo loadModule(final String path) throws ModuleNotLoadedException
{
    final Attributes attributes = readManifestBuildSection(path);
    final ModuleInfo moduleInfo = new ModuleInfo(path, this);
    
    /* Both addDependencies and addClasspathAttributes remove the dependencies
     * they process from the list of the attributes.
     * 
     * Dependencies must be processed first to ensure that the attribute "Depends"
     * is removed before the classpath attributes are processed. The latter can
     * contain the name "Depends" in some form which must be ignored.
     */
    addDependencies(attributes, moduleInfo);
    addClasspathAttributes(attributes, moduleInfo);
    
    // Merging the remaining attributes without modification.
    for (final Map.Entry<Object, Object> entry : attributes.entrySet()) {
        final Name key = (Name) entry.getKey();
        moduleInfo.addAttribute(key.toString(), entry.getValue());
    }
    return moduleInfo;
}
 
Example 38
Project: RhinoScriptEngine   File: RhinoScriptEngineFactory.java   View source code 6 votes vote down vote up
private static synchronized String getEngineVersionFromJar() {
    if (engineVersion == null) {
        URL url = RhinoScriptEngineFactory.class.getResource("/org/mozilla/javascript/Context.class");
        if (url != null && "jar".equals(url.getProtocol())) {
            try {
                JarURLConnection connection = (JarURLConnection) url.openConnection();
                Manifest manifest = connection.getJarFile().getManifest();
                Attributes attributes = manifest.getMainAttributes();
                if (attributes.containsKey(Name.IMPLEMENTATION_VERSION)) {
                    engineVersion = attributes.getValue(Name.IMPLEMENTATION_VERSION);
                }
            } catch (IOException ex) {
            }
        }
        if (engineVersion == null) {
            engineVersion = "Unknown";
        }
    }
    return engineVersion;
}
 
Example 39
Project: caoutchouc   File: CaoutchoucClassLoader.java   View source code 5 votes vote down vote up
private boolean isSealed(final String path, final Manifest manifest) {
    Attributes attributes = manifest.getAttributes(path);
    String sealed = null;
    if(attributes != null) {
        sealed = attributes.getValue(Name.SEALED);
    }

    if(sealed == null) {
        attributes = manifest.getMainAttributes();
        if(attributes != null) {
            sealed = attributes.getValue(Name.SEALED);
        }
    }
    return "true".equalsIgnoreCase(sealed);
}
 
Example 40
Project: incubator-netbeans   File: ShorterPaths.java   View source code 5 votes vote down vote up
private String copyExtraLib(File file) throws IOException {
    if (extraLibsDir == null || !extraLibsDir.isDirectory() || !file.isFile()) {
        return null;
    }
    File copy = new File(extraLibsDir, file.getName());
    boolean wasCopied = copyMissing(file, copy);
    // copy Class-Path extensions if available
    if (wasCopied && file.getName().endsWith(".jar")) {
        String cp;
        try {
            try (JarFile jf = new JarFile(file)) {
                Manifest manifest = jf.getManifest();
                cp = manifest != null ? manifest.getMainAttributes().getValue(Name.CLASS_PATH) : null;
            }
        } catch (IOException x) {
            log("Could not parse " + file + " for Class-Path", Project.MSG_WARN);
            cp = null;
        }
        if (cp != null) {
            for (String ext : cp.split(" ")) {
                // copy CP extension with relative path to keep link dependency from manifest
                copyMissing(new File(file.getParentFile(), ext), new File(extraLibsDir, ext));
            }
        }
    }
    return copy.getName();
}