Example usage for java.util.jar JarFile JarFile

List of usage examples for java.util.jar JarFile JarFile

Introduction

In this page you can find the example usage for java.util.jar JarFile JarFile.

Prototype

public JarFile(File file) throws IOException 

Source Link

Document

Creates a new JarFile to read from the specified File object.

Usage

From source file:com.eviware.soapui.DefaultSoapUICore.java

protected void initPlugins() {
    File[] pluginFiles = new File("plugins").listFiles();
    if (pluginFiles != null) {
        for (File pluginFile : pluginFiles) {
            if (!pluginFile.getName().toLowerCase().endsWith("-plugin.jar"))
                continue;

            try {
                log.info("Adding plugin from [" + pluginFile.getAbsolutePath() + "]");

                // add jar to our extension classLoader
                getExtensionClassLoader().addFile(pluginFile);
                JarFile jarFile = new JarFile(pluginFile);

                // look for factories
                JarEntry entry = jarFile.getJarEntry("META-INF/factories.xml");
                if (entry != null)
                    getFactoryRegistry().addConfig(jarFile.getInputStream(entry), extClassLoader);

                // look for listeners
                entry = jarFile.getJarEntry("META-INF/listeners.xml");
                if (entry != null)
                    getListenerRegistry().addConfig(jarFile.getInputStream(entry), extClassLoader);

                // look for actions
                entry = jarFile.getJarEntry("META-INF/actions.xml");
                if (entry != null)
                    getActionRegistry().addConfig(jarFile.getInputStream(entry), extClassLoader);

                // add jar to resource classloader so embedded images can be found with UISupport.loadImageIcon(..)
                UISupport.addResourceClassLoader(new URLClassLoader(new URL[] { pluginFile.toURI().toURL() }));
            } catch (Exception e) {
                SoapUI.logError(e);//from   www  . ja  v a 2  s.  c o  m
            }
        }
    }
}

From source file:de.smartics.maven.plugin.jboss.modules.util.classpath.ClassPathDirectoryListing.java

private List<String> handleJar(final String resourcePath, final URL resourcePathUrl)
        throws IllegalArgumentException {
    try {//from w w  w . j a v a 2  s  .co  m
        final List<String> contents = new ArrayList<String>();

        final int separatorIndex = resourcePathUrl.getPath().indexOf('!');
        final String jarPath = resourcePathUrl.getPath().substring(5, separatorIndex);
        final JarFile jar = new JarFile(URLDecoder.decode(jarPath, "UTF-8"));
        traverseJarEntries(resourcePath, contents, jar);

        return contents;
    } catch (final IOException e) {
        throw new IllegalArgumentException("Read from JAR '" + resourcePath + "'.", e);
    }
}

From source file:com.github.jengelman.gradle.plugins.integration.TestFile.java

public Manifest getManifest() {
    assertIsFile();//from  w  w  w  . j  a v a  2 s  .co  m
    try {
        JarFile jarFile = new JarFile(this);
        try {
            return jarFile.getManifest();
        } finally {
            jarFile.close();
        }
    } catch (IOException e) {
        throw new RuntimeException(e);
    }
}

From source file:org.eclipse.jdt.ls.core.internal.handlers.BundleUtils.java

private static BundleInfo getBundleInfo(String bundleLocation) throws IOException {
    try (JarFile jarFile = new JarFile(bundleLocation)) {
        Manifest manifest = jarFile.getManifest();
        if (manifest != null) {
            Attributes mainAttributes = manifest.getMainAttributes();
            if (mainAttributes != null) {
                String bundleVersion = mainAttributes.getValue(Constants.BUNDLE_VERSION);
                if (StringUtils.isBlank(bundleVersion)) {
                    return null;
                }/*w  w w  .  j a  v  a2s.c  o  m*/
                String symbolicName = mainAttributes.getValue(Constants.BUNDLE_SYMBOLICNAME);
                if (StringUtils.isNotBlank(symbolicName) && symbolicName.indexOf(';') >= 0) {
                    symbolicName = symbolicName.substring(0, symbolicName.indexOf(';'));
                }
                return new BundleInfo(bundleVersion, symbolicName);
            }
        }
    }
    return null;
}

From source file:javadepchecker.Main.java

private static boolean checkPkg(File env) {
    boolean needed = true;
    boolean found = true;
    HashSet<String> pkgs = new HashSet<String>();
    Collection<String> deps = null;

    BufferedReader in = null;//from  w w  w .j ava  2  s  . co m
    try {
        Pattern dep_re = Pattern.compile("^DEPEND=\"([^\"]*)\"$");
        Pattern cp_re = Pattern.compile("^CLASSPATH=\"([^\"]*)\"$");

        String line;
        in = new BufferedReader(new FileReader(env));
        while ((line = in.readLine()) != null) {
            Matcher m = dep_re.matcher(line);
            if (m.matches()) {
                String atoms = m.group(1);
                for (String atom : atoms.split(":")) {
                    String pkg = atom;
                    if (atom.contains("@")) {
                        pkg = atom.split("@")[1];
                    }
                    pkgs.add(pkg);
                }
                continue;
            }
            m = cp_re.matcher(line);
            if (m.matches()) {
                Main classParser = new Main();
                for (String jar : m.group(1).split(":")) {
                    if (jar.endsWith(".jar")) {
                        classParser.processJar(new JarFile(image + jar));
                    }
                }
                deps = classParser.getDeps();
            }
        }

        for (String pkg : pkgs) {
            if (!depNeeded(pkg, deps)) {
                if (needed) {
                    System.out.println("Possibly unneeded dependencies found");
                }
                System.out.println("\t" + pkg);
                needed = false;
            }
        }
        found = depsFound(pkgs, deps);

    } catch (IOException ex) {
        Logger.getLogger(Main.class.getName()).log(Level.SEVERE, null, ex);
    } finally {
        try {
            in.close();
        } catch (IOException ex) {
            Logger.getLogger(Main.class.getName()).log(Level.SEVERE, null, ex);
        }
    }
    return needed && found;
}

From source file:org.apache.tomcat.maven.plugin.tomcat7.run.AbstractStandaloneWarMojo.java

public void execute() throws MojoExecutionException, MojoFailureException {
    if (!"war".equals(project.getPackaging())) {
        throw new MojoFailureException("Pacakaging must be of type war for standalone-war goal.");
    }//from w  ww  .j a  va 2s .  co  m

    File warExecFile = new File(buildDirectory, finalName);
    if (warExecFile.exists()) {
        warExecFile.delete();
    }

    File execWarJar = new File(buildDirectory, finalName);

    FileOutputStream execWarJarOutputStream = null;
    ArchiveOutputStream os = null;
    File tmpPropertiesFile = null;
    File tmpManifestFile = null;
    FileOutputStream tmpPropertiesFileOutputStream = null;
    PrintWriter tmpManifestWriter = null;

    try {
        tmpPropertiesFile = new File(buildDirectory, "war-exec.properties");
        if (tmpPropertiesFile.exists()) {
            tmpPropertiesFile.delete();
        }
        tmpPropertiesFile.getParentFile().mkdirs();

        tmpManifestFile = new File(buildDirectory, "war-exec.manifest");
        if (tmpManifestFile.exists()) {
            tmpManifestFile.delete();
        }
        tmpPropertiesFileOutputStream = new FileOutputStream(tmpPropertiesFile);
        execWarJar.getParentFile().mkdirs();
        execWarJar.createNewFile();
        execWarJarOutputStream = new FileOutputStream(execWarJar);

        tmpManifestWriter = new PrintWriter(tmpManifestFile);

        // store :
        //* wars in the root: foo.war
        //* tomcat jars
        //* file tomcat.standalone.properties with possible values :
        //   * useServerXml=true/false to use directly the one provided
        //   * enableNaming=true/false
        //   * wars=foo.war|contextpath;bar.war  ( |contextpath is optionnal if empty use the war name )
        //   * accessLogValveFormat=
        //   * connectorhttpProtocol: HTTP/1.1 or org.apache.coyote.http11.Http11NioProtocol
        //   * codeSourceContextPath=path parameter, default is project.artifactId
        //* optionnal: conf/ with usual tomcat configuration files
        //* MANIFEST with Main-Class

        Properties properties = new Properties();

        properties.put(Tomcat7Runner.ARCHIVE_GENERATION_TIMESTAMP_KEY,
                Long.toString(System.currentTimeMillis()));
        properties.put(Tomcat7Runner.ENABLE_NAMING_KEY, Boolean.toString(enableNaming));
        properties.put(Tomcat7Runner.ACCESS_LOG_VALVE_FORMAT_KEY, accessLogValveFormat);
        properties.put(Tomcat7Runner.HTTP_PROTOCOL_KEY, connectorHttpProtocol);
        properties.put(Tomcat7Runner.CODE_SOURCE_CONTEXT_PATH, path);

        os = new ArchiveStreamFactory().createArchiveOutputStream(ArchiveStreamFactory.JAR,
                execWarJarOutputStream);

        extractJarToArchive(new JarFile(projectArtifact.getFile()), os, null);

        if (serverXml != null && serverXml.exists()) {
            os.putArchiveEntry(new JarArchiveEntry("conf/server.xml"));
            IOUtils.copy(new FileInputStream(serverXml), os);
            os.closeArchiveEntry();
            properties.put(Tomcat7Runner.USE_SERVER_XML_KEY, Boolean.TRUE.toString());
        } else {
            properties.put(Tomcat7Runner.USE_SERVER_XML_KEY, Boolean.FALSE.toString());
        }

        os.putArchiveEntry(new JarArchiveEntry("conf/web.xml"));
        IOUtils.copy(getClass().getResourceAsStream("/conf/web.xml"), os);
        os.closeArchiveEntry();

        properties.store(tmpPropertiesFileOutputStream, "created by Apache Tomcat Maven plugin");

        tmpPropertiesFileOutputStream.flush();
        tmpPropertiesFileOutputStream.close();

        os.putArchiveEntry(new JarArchiveEntry(Tomcat7RunnerCli.STAND_ALONE_PROPERTIES_FILENAME));
        IOUtils.copy(new FileInputStream(tmpPropertiesFile), os);
        os.closeArchiveEntry();

        // add tomcat classes
        for (Artifact pluginArtifact : pluginArtifacts) {
            if (StringUtils.equals("org.apache.tomcat", pluginArtifact.getGroupId())
                    || StringUtils.equals("org.apache.tomcat.embed", pluginArtifact.getGroupId())
                    || StringUtils.equals("org.eclipse.jdt.core.compiler", pluginArtifact.getGroupId())
                    || StringUtils.equals("commons-cli", pluginArtifact.getArtifactId())
                    || StringUtils.equals("tomcat7-war-runner", pluginArtifact.getArtifactId())) {
                JarFile jarFile = new JarFile(pluginArtifact.getFile());
                extractJarToArchive(jarFile, os, null);
            }
        }

        // add extra dependencies
        if (extraDependencies != null && !extraDependencies.isEmpty()) {
            for (Dependency dependency : extraDependencies) {
                String version = dependency.getVersion();
                if (StringUtils.isEmpty(version)) {
                    version = findArtifactVersion(dependency);
                }

                if (StringUtils.isEmpty(version)) {
                    throw new MojoExecutionException("Dependency '" + dependency.getGroupId() + "':'"
                            + dependency.getArtifactId() + "' does not have version specified");
                }
                // String groupId, String artifactId, String version, String scope, String type
                Artifact artifact = artifactFactory.createArtifact(dependency.getGroupId(),
                        dependency.getArtifactId(), version, dependency.getScope(), dependency.getType());

                artifactResolver.resolve(artifact, this.remoteRepos, this.local);
                JarFile jarFile = new JarFile(artifact.getFile());
                extractJarToArchive(jarFile, os, excludes);
            }
        }

        Manifest manifest = new Manifest();

        Manifest.Attribute mainClassAtt = new Manifest.Attribute();
        mainClassAtt.setName("Main-Class");
        mainClassAtt.setValue(mainClass);
        manifest.addConfiguredAttribute(mainClassAtt);

        manifest.write(tmpManifestWriter);
        tmpManifestWriter.flush();
        tmpManifestWriter.close();

        os.putArchiveEntry(new JarArchiveEntry("META-INF/MANIFEST.MF"));
        IOUtils.copy(new FileInputStream(tmpManifestFile), os);
        os.closeArchiveEntry();

        if (attachArtifact) {
            //MavenProject project, String artifactType, String artifactClassifier, File artifactFile
            projectHelper.attachArtifact(project, attachArtifactClassifierType, attachArtifactClassifier,
                    execWarJar);
        }

        if (extraResources != null) {
            for (ExtraResource extraResource : extraResources) {

                DirectoryScanner directoryScanner = new DirectoryScanner();
                directoryScanner.setBasedir(extraResource.getDirectory());
                directoryScanner.addDefaultExcludes();
                directoryScanner.setExcludes(toStringArray(extraResource.getExcludes()));
                directoryScanner.setIncludes(toStringArray(extraResource.getIncludes()));
                directoryScanner.scan();
                for (String includeFile : directoryScanner.getIncludedFiles()) {
                    getLog().debug("include file:" + includeFile);
                    os.putArchiveEntry(new JarArchiveEntry(includeFile));
                    IOUtils.copy(new FileInputStream(new File(extraResource.getDirectory(), includeFile)), os);
                    os.closeArchiveEntry();
                }
            }
        }

        if (tomcatConfigurationFilesDirectory != null && tomcatConfigurationFilesDirectory.exists()) {
            // Because its the tomcat default dir for configs
            String aConfigOutputDir = "conf/";
            copyDirectoryContentIntoArchive(tomcatConfigurationFilesDirectory, aConfigOutputDir, os);
        }
    } catch (ManifestException e) {
        throw new MojoExecutionException(e.getMessage(), e);
    } catch (IOException e) {
        throw new MojoExecutionException(e.getMessage(), e);
    } catch (ArchiveException e) {
        throw new MojoExecutionException(e.getMessage(), e);
    } catch (ArtifactNotFoundException e) {
        throw new MojoExecutionException(e.getMessage(), e);
    } catch (ArtifactResolutionException e) {
        throw new MojoExecutionException(e.getMessage(), e);
    } finally {
        IOUtils.closeQuietly(os);
        IOUtils.closeQuietly(tmpManifestWriter);
        IOUtils.closeQuietly(execWarJarOutputStream);
        IOUtils.closeQuietly(tmpPropertiesFileOutputStream);
    }

}

From source file:org.apache.tomcat.maven.plugin.tomcat8.run.AbstractStandaloneWarMojo.java

public void execute() throws MojoExecutionException, MojoFailureException {
    if (!"war".equals(project.getPackaging())) {
        throw new MojoFailureException("Pacakaging must be of type war for standalone-war goal.");
    }/*from w  w w . j a  v a 2s.c  o m*/

    File warExecFile = new File(buildDirectory, finalName);
    if (warExecFile.exists()) {
        warExecFile.delete();
    }

    File execWarJar = new File(buildDirectory, finalName);

    FileOutputStream execWarJarOutputStream = null;
    ArchiveOutputStream os = null;
    File tmpPropertiesFile = null;
    File tmpManifestFile = null;
    FileOutputStream tmpPropertiesFileOutputStream = null;
    PrintWriter tmpManifestWriter = null;

    try {
        tmpPropertiesFile = new File(buildDirectory, "war-exec.properties");
        if (tmpPropertiesFile.exists()) {
            tmpPropertiesFile.delete();
        }
        tmpPropertiesFile.getParentFile().mkdirs();

        tmpManifestFile = new File(buildDirectory, "war-exec.manifest");
        if (tmpManifestFile.exists()) {
            tmpManifestFile.delete();
        }
        tmpPropertiesFileOutputStream = new FileOutputStream(tmpPropertiesFile);
        execWarJar.getParentFile().mkdirs();
        execWarJar.createNewFile();
        execWarJarOutputStream = new FileOutputStream(execWarJar);

        tmpManifestWriter = new PrintWriter(tmpManifestFile);

        // store :
        //* wars in the root: foo.war
        //* tomcat jars
        //* file tomcat.standalone.properties with possible values :
        //   * useServerXml=true/false to use directly the one provided
        //   * enableNaming=true/false
        //   * wars=foo.war|contextpath;bar.war  ( |contextpath is optionnal if empty use the war name )
        //   * accessLogValveFormat=
        //   * connectorhttpProtocol: HTTP/1.1 or org.apache.coyote.http11.Http11NioProtocol
        //   * codeSourceContextPath=path parameter, default is project.artifactId
        //* optionnal: conf/ with usual tomcat configuration files
        //* MANIFEST with Main-Class

        Properties properties = new Properties();

        properties.put(Tomcat8Runner.ARCHIVE_GENERATION_TIMESTAMP_KEY,
                Long.toString(System.currentTimeMillis()));
        properties.put(Tomcat8Runner.ENABLE_NAMING_KEY, Boolean.toString(enableNaming));
        properties.put(Tomcat8Runner.ACCESS_LOG_VALVE_FORMAT_KEY, accessLogValveFormat);
        properties.put(Tomcat8Runner.HTTP_PROTOCOL_KEY, connectorHttpProtocol);
        properties.put(Tomcat8Runner.CODE_SOURCE_CONTEXT_PATH, path);

        os = new ArchiveStreamFactory().createArchiveOutputStream(ArchiveStreamFactory.JAR,
                execWarJarOutputStream);

        extractJarToArchive(new JarFile(projectArtifact.getFile()), os, null);

        if (serverXml != null && serverXml.exists()) {
            os.putArchiveEntry(new JarArchiveEntry("conf/server.xml"));
            IOUtils.copy(new FileInputStream(serverXml), os);
            os.closeArchiveEntry();
            properties.put(Tomcat8Runner.USE_SERVER_XML_KEY, Boolean.TRUE.toString());
        } else {
            properties.put(Tomcat8Runner.USE_SERVER_XML_KEY, Boolean.FALSE.toString());
        }

        os.putArchiveEntry(new JarArchiveEntry("conf/web.xml"));
        IOUtils.copy(getClass().getResourceAsStream("/conf/web.xml"), os);
        os.closeArchiveEntry();

        properties.store(tmpPropertiesFileOutputStream, "created by Apache Tomcat Maven plugin");

        tmpPropertiesFileOutputStream.flush();
        tmpPropertiesFileOutputStream.close();

        os.putArchiveEntry(new JarArchiveEntry(Tomcat8RunnerCli.STAND_ALONE_PROPERTIES_FILENAME));
        IOUtils.copy(new FileInputStream(tmpPropertiesFile), os);
        os.closeArchiveEntry();

        // add tomcat classes
        for (Artifact pluginArtifact : pluginArtifacts) {
            if (StringUtils.equals("org.apache.tomcat", pluginArtifact.getGroupId()) //
                    || StringUtils.equals("org.apache.tomcat.embed", pluginArtifact.getGroupId()) //
                    || StringUtils.equals("org.eclipse.jdt.core.compiler", pluginArtifact.getGroupId()) //
                    || StringUtils.equals("commons-cli", pluginArtifact.getArtifactId()) //
                    || StringUtils.equals("tomcat8-war-runner", pluginArtifact.getArtifactId())) {
                JarFile jarFile = new JarFile(pluginArtifact.getFile());
                extractJarToArchive(jarFile, os, null);
            }
        }

        // add extra dependencies
        if (extraDependencies != null && !extraDependencies.isEmpty()) {
            for (Dependency dependency : extraDependencies) {
                String version = dependency.getVersion();
                if (StringUtils.isEmpty(version)) {
                    version = findArtifactVersion(dependency);
                }

                if (StringUtils.isEmpty(version)) {
                    throw new MojoExecutionException("Dependency '" + dependency.getGroupId() + "':'"
                            + dependency.getArtifactId() + "' does not have version specified");
                }
                // String groupId, String artifactId, String version, String scope, String type
                Artifact artifact = artifactFactory.createArtifact(dependency.getGroupId(), //
                        dependency.getArtifactId(), //
                        version, //
                        dependency.getScope(), //
                        dependency.getType());

                artifactResolver.resolve(artifact, this.remoteRepos, this.local);
                JarFile jarFile = new JarFile(artifact.getFile());
                extractJarToArchive(jarFile, os, excludes);
            }
        }

        Manifest manifest = new Manifest();

        Manifest.Attribute mainClassAtt = new Manifest.Attribute();
        mainClassAtt.setName("Main-Class");
        mainClassAtt.setValue(mainClass);
        manifest.addConfiguredAttribute(mainClassAtt);

        manifest.write(tmpManifestWriter);
        tmpManifestWriter.flush();
        tmpManifestWriter.close();

        os.putArchiveEntry(new JarArchiveEntry("META-INF/MANIFEST.MF"));
        IOUtils.copy(new FileInputStream(tmpManifestFile), os);
        os.closeArchiveEntry();

        if (attachArtifact) {
            //MavenProject project, String artifactType, String artifactClassifier, File artifactFile
            projectHelper.attachArtifact(project, attachArtifactClassifierType, attachArtifactClassifier,
                    execWarJar);
        }

        if (extraResources != null) {
            for (ExtraResource extraResource : extraResources) {

                DirectoryScanner directoryScanner = new DirectoryScanner();
                directoryScanner.setBasedir(extraResource.getDirectory());
                directoryScanner.addDefaultExcludes();
                directoryScanner.setExcludes(toStringArray(extraResource.getExcludes()));
                directoryScanner.setIncludes(toStringArray(extraResource.getIncludes()));
                directoryScanner.scan();
                for (String includeFile : directoryScanner.getIncludedFiles()) {
                    getLog().debug("include file:" + includeFile);
                    os.putArchiveEntry(new JarArchiveEntry(includeFile));
                    IOUtils.copy(new FileInputStream(new File(extraResource.getDirectory(), includeFile)), os);
                    os.closeArchiveEntry();
                }
            }
        }

        if (tomcatConfigurationFilesDirectory != null && tomcatConfigurationFilesDirectory.exists()) {
            // Because its the tomcat default dir for configs
            String aConfigOutputDir = "conf/";
            copyDirectoryContentIntoArchive(tomcatConfigurationFilesDirectory, aConfigOutputDir, os);
        }
    } catch (ManifestException e) {
        throw new MojoExecutionException(e.getMessage(), e);
    } catch (IOException e) {
        throw new MojoExecutionException(e.getMessage(), e);
    } catch (ArchiveException e) {
        throw new MojoExecutionException(e.getMessage(), e);
    } catch (ArtifactNotFoundException e) {
        throw new MojoExecutionException(e.getMessage(), e);
    } catch (ArtifactResolutionException e) {
        throw new MojoExecutionException(e.getMessage(), e);
    } finally {
        IOUtils.closeQuietly(os);
        IOUtils.closeQuietly(tmpManifestWriter);
        IOUtils.closeQuietly(execWarJarOutputStream);
        IOUtils.closeQuietly(tmpPropertiesFileOutputStream);
    }

}

From source file:org.ebayopensource.turmeric.eclipse.utils.io.IOUtil.java

/**
 * In the normal jar URLs usage in Windows Java puts a lock on it. And the
 * SOA Tool Handler will create a non locking URL by setting the caching
 * off. There is obviously a performance compromise made here by disabling
 * the cache.//  w  ww.ja  v a 2 s  . c  om
 *
 * @param jarFileUrl the jar file url
 * @param jarEntryPath the jar entry path
 * @return the non locking url
 * @throws IOException Signals that an I/O exception has occurred.
 */
public static URL getNonLockingURL(URL jarFileUrl, String jarEntryPath) throws IOException {
    File file = FileUtils.toFile(jarFileUrl);
    JarFile jarFile;
    jarFile = new JarFile(file);
    JarEntry jarEntry = jarFile.getJarEntry(jarEntryPath);
    if (jarEntry != null) {
        SOAToolFileUrlHandler handler = new SOAToolFileUrlHandler(jarFile, jarEntry);
        URL retUrl = new URL("jar", "", -1,
                new File(jarFile.getName()).toURI().toURL() + "!/" + jarEntry.getName(), handler);
        handler.setExpectedUrl(retUrl);
        return retUrl;

    }
    return null;
}

From source file:com.opengamma.web.WebAbout.java

/**
 * Gets the OpenGamma version.//from  w  ww.ja  va2s. c  o m
 * @return the version, not null
 */
public String getOpenGammaVersion() {
    URL url = ClasspathHelper.forClass(getClass(), getClass().getClassLoader());
    if (url != null && url.toString().contains(".jar")) {
        try {
            final String part = ClasspathHelper.cleanPath(url);
            try (JarFile myJar = new JarFile(part)) {
                final Manifest manifest = myJar.getManifest();
                if (manifest != null) {
                    Attributes attributes = manifest.getMainAttributes();
                    if (attributes != null) {
                        if (attributes.getValue(Attributes.Name.IMPLEMENTATION_VERSION) != null) {
                            return attributes.getValue(Attributes.Name.IMPLEMENTATION_VERSION);
                        }
                        if (attributes.getValue(Attributes.Name.SPECIFICATION_VERSION) != null) {
                            return attributes.getValue(Attributes.Name.SPECIFICATION_VERSION);
                        }
                    }
                }
            }
        } catch (Exception ex) {
            s_logger.warn(ex.getMessage(), ex);
        }
    } else {
        List<AboutDependency> classpath = getClasspath();
        for (AboutDependency depend : classpath) {
            if ("og-web".equals(depend.getArtifactId())) {
                return depend.getVersion();
            }
        }
    }
    return "?";
}

From source file:com.redhat.ceylon.compiler.java.test.cmr.CMRTests.java

@Test
public void testMdlByName() throws IOException {
    List<String> options = new LinkedList<String>();
    options.add("-src");
    options.add(getPackagePath() + "/modules/byName");
    options.addAll(defaultOptions);/*from  w  w  w . j  ava  2s  .  co  m*/
    CeyloncTaskImpl task = getCompilerTask(options, null, Arrays.asList("default", "mod"));
    Boolean ret = task.call();
    assertTrue(ret);

    File carFile = getModuleArchive("default", null);
    assertTrue(carFile.exists());

    JarFile car = new JarFile(carFile);

    ZipEntry moduleClass = car.getEntry("def/Foo.class");
    assertNotNull(moduleClass);
    ZipEntry moduleClassDir = car.getEntry("def/");
    assertNotNull(moduleClassDir);
    assertTrue(moduleClassDir.isDirectory());

    car.close();

    carFile = getModuleArchive("mod", "1");
    assertTrue(carFile.exists());

    car = new JarFile(carFile);

    moduleClass = car.getEntry("mod/$module_.class");
    assertNotNull(moduleClass);
    moduleClassDir = car.getEntry("mod/");
    assertNotNull(moduleClassDir);
    assertTrue(moduleClassDir.isDirectory());

    car.close();
}