Search in sources :

Example 16 with FileArchive

use of com.sun.enterprise.deploy.shared.FileArchive in project Payara by payara.

the class AppClientArchiveClassesLoadable method check.

public Result check(ApplicationClientDescriptor descriptor) {
    Result result = getInitializedResult();
    ComponentNameConstructor compName = getVerifierContext().getComponentNameConstructor();
    String archiveUri = getAbstractArchiveUri(descriptor);
    boolean allPassed = true;
    FileArchive arch = null;
    Enumeration entries = null;
    ClosureCompiler closureCompiler = getVerifierContext().getClosureCompiler();
    try {
        String uri = getAbstractArchiveUri(descriptor);
        arch = new FileArchive();
        arch.open(uri);
        entries = arch.entries();
        arch.close();
    } catch (Exception e) {
        e.printStackTrace();
        result.failed(smh.getLocalString(getClass().getName() + ".exception", "Error: [ {0} ] exception while loading the archive [ {1} ].", new Object[] { e, descriptor.getName() }));
        return result;
    }
    Object entry;
    while (entries.hasMoreElements()) {
        String name = null;
        entry = entries.nextElement();
        name = (String) entry;
        // look for entries with .class extension
        if (name.endsWith(".class")) {
            String className = name.substring(0, name.length() - ".class".length()).replace('/', '.');
            boolean status = closureCompiler.buildClosure(className);
            allPassed = status && allPassed;
        }
    }
    if (allPassed) {
        result.setStatus(Result.PASSED);
        addGoodDetails(result, compName);
        result.passed(smh.getLocalString(getClass().getName() + ".passed", "All the classes are loadable within [ {0} ] without any linkage error.", new Object[] { archiveUri }));
    // result.addGoodDetails(closureCompiler.toString());
    } else {
        result.setStatus(Result.FAILED);
        addErrorDetails(result, compName);
        result.addErrorDetails(ArchiveClassesLoadableHelper.getFailedResult(closureCompiler));
        result.addErrorDetails(smh.getLocalString("com.sun.enterprise.tools.verifier.tests.loadableError", "Please either bundle the above mentioned classes in the application " + "or use optional packaging support for them."));
    }
    return result;
}
Also used : Enumeration(java.util.Enumeration) FileArchive(com.sun.enterprise.deploy.shared.FileArchive) ClosureCompiler(com.sun.enterprise.tools.verifier.apiscan.classfile.ClosureCompiler) ComponentNameConstructor(com.sun.enterprise.tools.verifier.tests.ComponentNameConstructor) Result(com.sun.enterprise.tools.verifier.Result)

Example 17 with FileArchive

use of com.sun.enterprise.deploy.shared.FileArchive in project Payara by payara.

the class ModuleExploder method explodeModule.

public static void explodeModule(Archive source, File directory, boolean preserveManifest) throws IOException, DeploymentException {
    File explodedManifest = null;
    File preservedManifestFromArchive = null;
    FileArchive target = new FileArchive();
    target.create(directory.toURI());
    explodeJar(new File(source.getURI()), directory);
    if (preserveManifest) {
        explodedManifest = new File(directory, java.util.jar.JarFile.MANIFEST_NAME);
        if (explodedManifest.exists()) {
            /* Rename the manifest so it can be restored later. */
            preservedManifestFromArchive = new File(directory, PRESERVED_MANIFEST_NAME);
            if (!explodedManifest.renameTo(preservedManifestFromArchive)) {
                throw new RuntimeException(localStrings.getString("enterprise.deployment.backend.error_saving_manifest", new Object[] { explodedManifest.getAbsolutePath(), preservedManifestFromArchive.getAbsolutePath() }));
            }
        }
    }
    // require access to the manifest file of each .jar file.
    for (Enumeration itr = source.entries(); itr.hasMoreElements(); ) {
        String fileName = (String) itr.nextElement();
        /*
              *Expand the file only if it is a jar and only if it does not lie in WEB-INF/lib.
              */
        if (fileName.toLowerCase(Locale.US).endsWith(".jar") && (!fileName.replace('\\', '/').toUpperCase(Locale.getDefault()).startsWith(WEB_INF_PREFIX))) {
            try {
                File f = new File(directory, fileName);
                ZipFile zip = new ZipFile(f, directory);
                zip.explode();
            } catch (ZipFileException e) {
                IOException ioe = new IOException(e.getMessage());
                ioe.initCause(e);
                throw ioe;
            }
        }
    }
    /*
          *If the archive's manifest was renamed to protect it from being overwritten by manifests from
          *jar files, then rename it back.  Delete an existing manifest file first if needed.
          */
    if (preservedManifestFromArchive != null) {
        if (explodedManifest.exists()) {
            if (!explodedManifest.delete()) {
                throw new RuntimeException(localStrings.getString("enterprise.deployment.backend.error_deleting_manifest", new Object[] { explodedManifest.getAbsolutePath(), preservedManifestFromArchive.getAbsolutePath() }));
            }
        }
        if (!preservedManifestFromArchive.renameTo(explodedManifest)) {
            throw new RuntimeException(localStrings.getString("enterprise.deployment.backend.error_restoring_manifest", new Object[] { preservedManifestFromArchive.getAbsolutePath(), explodedManifest.getAbsolutePath() }));
        }
    }
    source.close();
    target.close();
}
Also used : Enumeration(java.util.Enumeration) ZipFile(com.sun.enterprise.util.zip.ZipFile) ZipFileException(com.sun.enterprise.util.zip.ZipFileException) FileArchive(com.sun.enterprise.deploy.shared.FileArchive) JarFile(java.util.jar.JarFile) ZipFile(com.sun.enterprise.util.zip.ZipFile)

Example 18 with FileArchive

use of com.sun.enterprise.deploy.shared.FileArchive in project Payara by payara.

the class ClassFileAppClientInfo method massageDescriptor.

@Override
protected void massageDescriptor() throws IOException, AnnotationProcessorException {
    ApplicationClientDescriptor appClient = getDescriptor();
    appClient.setMainClassName(classFileFromCommandLine);
    appClient.getModuleDescriptor().setStandalone(true);
    FileArchive fa = new FileArchive();
    fa.open(new File(classFileFromCommandLine).toURI());
    new AppClientArchivist().processAnnotations(appClient, fa);
}
Also used : FileArchive(com.sun.enterprise.deploy.shared.FileArchive) ApplicationClientDescriptor(com.sun.enterprise.deployment.ApplicationClientDescriptor) AppClientArchivist(com.sun.enterprise.deployment.archivist.AppClientArchivist) File(java.io.File)

Example 19 with FileArchive

use of com.sun.enterprise.deploy.shared.FileArchive in project Payara by payara.

the class ConnectorsUtil method getInstalledLibrariesFromManifest.

public static List<URI> getInstalledLibrariesFromManifest(String moduleDirectory, ServerEnvironment env) throws ConnectorRuntimeException {
    // this method will be called during system-rar creation.
    // Though there are code paths that will call this method for creation of rars during recovery / via
    // API exposed for GUI, they will not call this method as non-system rars are always started during server startup
    // system-rars can specify only EXTENSTION_LIST in MANIFEST.MF and do not have a way to use --libraries option.
    // So, satisfying system-rars alone as of now.
    List<URI> libURIs = new ArrayList<URI>();
    if (moduleDirectory != null) {
        try {
            File module = new File(moduleDirectory);
            if (module.exists()) {
                FileArchive fileArchive = new FileArchive();
                // directory where rar is exploded
                fileArchive.open(module.toURI());
                Set<String> extensionList = InstalledLibrariesResolver.getInstalledLibraries(fileArchive);
                URL[] extensionListLibraries = ASClassLoaderUtil.getLibrariesAsURLs(extensionList, env);
                for (URL url : extensionListLibraries) {
                    libURIs.add(url.toURI());
                    if (_logger.isLoggable(Level.FINEST)) {
                        _logger.log(Level.FINEST, "adding URL [ " + url + " ] to installedLibraries");
                    }
                }
            }
        } catch (IOException ioe) {
            ConnectorRuntimeException cre = new ConnectorRuntimeException(ioe.getMessage());
            cre.initCause(ioe);
            throw cre;
        } catch (URISyntaxException e) {
            ConnectorRuntimeException cre = new ConnectorRuntimeException(e.getMessage());
            cre.initCause(e);
            throw cre;
        }
    }
    return libURIs;
}
Also used : FileArchive(com.sun.enterprise.deploy.shared.FileArchive) URISyntaxException(java.net.URISyntaxException) URI(java.net.URI) URL(java.net.URL)

Example 20 with FileArchive

use of com.sun.enterprise.deploy.shared.FileArchive in project Payara by payara.

the class WSDLFileCheck method check.

/**
 * @param descriptor the WebServices  descriptor
 * @return <code>Result</code> the results for this assertion
 */
public Result check(WebServiceEndpoint descriptor) {
    Result result = getInitializedResult();
    ComponentNameConstructor compName = getVerifierContext().getComponentNameConstructor();
    // boolean pass = true;
    // File f = Verifier.getArchiveFile(descriptor.getBundleDescriptor().
    // getModuleDescriptor().getArchiveUri());
    // JarFile jarFile = null;
    InputStream deploymentEntry = null;
    // wsdl file
    String wsdlUri = descriptor.getWebService().getWsdlFileUri();
    try {
        // if (f == null) {
        String uri = getAbstractArchiveUri(descriptor);
        // try {
        FileArchive arch = new FileArchive();
        arch.open(uri);
        deploymentEntry = arch.getEntry(wsdlUri);
        // }
        if (deploymentEntry == null) {
            // result.fail,
            result.addErrorDetails(smh.getLocalString("tests.componentNameConstructor", "For [ {0} ]", new Object[] { compName.toString() }));
            result.failed(smh.getLocalString(getClass().getName() + ".failed", "WSDL file does not exist in the archive at uri [{0}].", new Object[] { wsdlUri }));
        // pass = false;
        } else {
            // result.pass
            result.addGoodDetails(smh.getLocalString("tests.componentNameConstructor", "For [ {0} ]", new Object[] { compName.toString() }));
            result.passed(smh.getLocalString(getClass().getName() + ".passed", "WSDL file exists in the archive at uri [{0}].", new Object[] { wsdlUri }));
        }
    } catch (Exception e) {
        // result.fail
        result.addErrorDetails(smh.getLocalString("com.sun.enterprise.tools.verifier.tests.webservices.Error", "Error: Unexpected error occurred [ {0} ]", new Object[] { e.getMessage() }));
    // pass = false;
    } finally {
        try {
            if (deploymentEntry != null)
                deploymentEntry.close();
        } catch (IOException e) {
        }
    }
    return result;
}
Also used : FileArchive(com.sun.enterprise.deploy.shared.FileArchive)

Aggregations

FileArchive (com.sun.enterprise.deploy.shared.FileArchive)46 File (java.io.File)11 IOException (java.io.IOException)7 InputStream (java.io.InputStream)6 URI (java.net.URI)5 JarFile (java.util.jar.JarFile)5 Result (com.sun.enterprise.tools.verifier.Result)4 ComponentNameConstructor (com.sun.enterprise.tools.verifier.tests.ComponentNameConstructor)4 Enumeration (java.util.Enumeration)4 ApplicationClientDescriptor (com.sun.enterprise.deployment.ApplicationClientDescriptor)3 URISyntaxException (java.net.URISyntaxException)3 Manifest (java.util.jar.Manifest)3 SAXParseException (org.xml.sax.SAXParseException)3 ConnectorRuntimeException (com.sun.appserv.connectors.internal.api.ConnectorRuntimeException)2 AppClientArchivist (com.sun.enterprise.deployment.archivist.AppClientArchivist)2 InputJarArchive (com.sun.enterprise.deployment.deploy.shared.InputJarArchive)2 MultiReadableArchive (com.sun.enterprise.deployment.deploy.shared.MultiReadableArchive)2 ClosureCompiler (com.sun.enterprise.tools.verifier.apiscan.classfile.ClosureCompiler)2 URL (java.net.URL)2 Attributes (java.util.jar.Attributes)2