Search in sources :

Example 26 with ReadableArchive

use of org.glassfish.api.deployment.archive.ReadableArchive in project Payara by payara.

the class StandaloneAppClientDeployerHelper method copyOriginalAppClientJAR.

protected void copyOriginalAppClientJAR(final DeploymentContext dc) throws IOException {
    ReadableArchive originalSource = ((ExtendedDeploymentContext) dc).getOriginalSource();
    originalSource.open(originalSource.getURI());
    OutputJarArchive target = new OutputJarArchive();
    target.create(appClientServerURI(dc));
    /*
         * Copy the manifest explicitly because ReadableArchive.entries()
         * excludes the manifest.
         */
    Manifest originalManifest = originalSource.getManifest();
    OutputStream os = target.putNextEntry(JarFile.MANIFEST_NAME);
    originalManifest.write(os);
    target.closeEntry();
    copyArchive(originalSource, target, Collections.EMPTY_SET);
    target.close();
    originalSource.close();
}
Also used : OutputJarArchive(com.sun.enterprise.deployment.deploy.shared.OutputJarArchive) OutputStream(java.io.OutputStream) ReadableArchive(org.glassfish.api.deployment.archive.ReadableArchive) ExtendedDeploymentContext(org.glassfish.internal.deployment.ExtendedDeploymentContext) Manifest(java.util.jar.Manifest)

Example 27 with ReadableArchive

use of org.glassfish.api.deployment.archive.ReadableArchive in project Payara by payara.

the class MainClassLaunchable method getDescriptor.

public ApplicationClientDescriptor getDescriptor(final URLClassLoader loader) throws IOException, SAXParseException {
    /*
         * There is no developer-provided descriptor possible so just
         * use a default one.
         */
    if (acDesc == null) {
        ReadableArchive tempArchive = null;
        final ACCClassLoader tempLoader = AccessController.doPrivileged(new PrivilegedAction<ACCClassLoader>() {

            @Override
            public ACCClassLoader run() {
                return new ACCClassLoader(loader.getURLs(), loader.getParent());
            }
        });
        tempArchive = createArchive(tempLoader, mainClass);
        final AppClientArchivist acArchivist = getArchivist(tempArchive, tempLoader);
        archivist.setClassLoader(tempLoader);
        archivist.setDescriptor(acDesc);
        archivist.setAnnotationProcessingRequested(true);
        acDesc = acArchivist.open(tempArchive);
        Application.createVirtualApplication(null, acDesc.getModuleDescriptor());
        acDesc.getApplication().setAppName(appNameFromMainClass(mainClass));
        this.classLoader = loader;
    }
    return acDesc;
}
Also used : AppClientArchivist(com.sun.enterprise.deployment.archivist.AppClientArchivist) ReadableArchive(org.glassfish.api.deployment.archive.ReadableArchive)

Example 28 with ReadableArchive

use of org.glassfish.api.deployment.archive.ReadableArchive in project Payara by payara.

the class SunDeploymentManager method deploy.

/**
 * Deploy the specified module to the list of targets.
 * The deployment plan archive can be null.
 *
 * @param targetList the targets to which to deploy the module
 * @param moduleArchive the archive file to be deployed
 * @param deploymentPlan the (optional) deployment plan file
 * @param options set by the caller to override and augment any settings made here
 * @return ProgressObject to communicate progress and results of the deployment
 * @throws IllegalStateException if the DeploymentManager has disconnected
 * @throws IOException if there are problems opening the archive files
 */
private ProgressObject deploy(Target[] targetList, File moduleArchive, File deploymentPlan, Properties options) throws IllegalStateException {
    /*
         *Create archives for the module file and, if present, the deployment plan file, and
         *then delegate to the variant of deploy that accepts archives as arguments.
         */
    ReadableArchive appArchive = null;
    ReadableArchive planArchive = null;
    ArchiveFactory archiveFactory = getArchiveFactory();
    try {
        appArchive = archiveFactory.openArchive(moduleArchive);
        if (deploymentPlan != null && deploymentPlan.length() != 0) {
            planArchive = archiveFactory.openArchive(deploymentPlan);
            if (planArchive == null) {
                throw new IllegalArgumentException(localStrings.getLocalString("enterprise.deployapi.spi.noarchivisthandlesplan", "No archivist is able to handle the deployment plan {0}", new Object[] { deploymentPlan.getAbsolutePath() }));
            }
        }
        ProgressObject po = deploy(targetList, appArchive, planArchive, options);
        return po;
    } catch (Exception se) {
        String msg = localStrings.getLocalString("enterprise.deployapi.spi.errpreparearchfile", "Could not prepare archives for module and/or deployment plan files");
        IllegalArgumentException ex = new IllegalArgumentException(msg);
        ex.initCause(se);
        return prepareErrorProgressObject(CommandType.DISTRIBUTE, ex);
    } finally {
        closeArchives(CommandType.DISTRIBUTE, appArchive, moduleArchive.getAbsolutePath(), planArchive, (deploymentPlan != null) ? deploymentPlan.getAbsolutePath() : null);
    }
}
Also used : ArchiveFactory(com.sun.enterprise.deploy.shared.ArchiveFactory) DeployableObject(javax.enterprise.deploy.model.DeployableObject) ProgressObject(javax.enterprise.deploy.spi.status.ProgressObject) ReadableArchive(org.glassfish.api.deployment.archive.ReadableArchive) ProgressObject(javax.enterprise.deploy.spi.status.ProgressObject) DConfigBeanVersionUnsupportedException(javax.enterprise.deploy.spi.exceptions.DConfigBeanVersionUnsupportedException) TargetException(javax.enterprise.deploy.spi.exceptions.TargetException) MalformedURLException(java.net.MalformedURLException) IOException(java.io.IOException) InvalidModuleException(javax.enterprise.deploy.spi.exceptions.InvalidModuleException)

Example 29 with ReadableArchive

use of org.glassfish.api.deployment.archive.ReadableArchive in project Payara by payara.

the class JPASniffer method scanForPURootsInLibDir.

protected boolean scanForPURootsInLibDir(ReadableArchive parentArchive, String libLocation) {
    boolean puRootPresent = false;
    if (libLocation != null && !libLocation.isEmpty()) {
        // if an application disables lib dir by specifying <library-directory></library-directory>, do not attempt to scan lib dir
        Enumeration<String> entries = parentArchive.entries(libLocation);
        while (entries.hasMoreElements() && !puRootPresent) {
            String entryName = entries.nextElement();
            if (// a jar in lib dir
            entryName.endsWith(JAR_SUFFIX) && entryName.indexOf(SEPERATOR_CHAR, libLocation.length() + 1) == -1) {
                // && not WEB-INf/lib/foo/bar.jar
                try {
                    ReadableArchive jarInLib = parentArchive.getSubArchive(entryName);
                    if (jarInLib != null) {
                        puRootPresent = isEntryPresent(jarInLib, META_INF_PERSISTENCE_XML);
                        jarInLib.close();
                    }
                } catch (IOException e) {
                // Something went wrong while reading the jar. Do not attempt to scan it
                }
            // catch
            }
        // if (entryName.endsWith(JAR_SUFFIX))
        }
    // while
    }
    return puRootPresent;
}
Also used : IOException(java.io.IOException) ReadableArchive(org.glassfish.api.deployment.archive.ReadableArchive)

Example 30 with ReadableArchive

use of org.glassfish.api.deployment.archive.ReadableArchive in project Payara by payara.

the class ACCPersistenceArchivist method open.

@Override
public Object open(Archivist main, ReadableArchive archive, RootDeploymentDescriptor descriptor) throws IOException, SAXParseException {
    if (deplLogger.isLoggable(Level.FINE)) {
        deplLogger.logp(Level.FINE, "ACCPersistencerArchivist", "readPersistenceDeploymentDescriptors", "archive = {0}", archive.getURI());
    }
    final Map<String, ReadableArchive> candidatePersistenceArchives = new HashMap<>();
    /*
         * The descriptor had better be an ApplicationClientDescriptor!
         */
    if (!(descriptor instanceof ApplicationClientDescriptor)) {
        return null;
    }
    final ApplicationClientDescriptor acDescr = ApplicationClientDescriptor.class.cast(descriptor);
    try {
        final Manifest mf = archive.getManifest();
        final Attributes mainAttrs = mf.getMainAttributes();
        /*
             * We must scan the app client archive itself.  
             */
        URI clientURI = clientURI(archive, acDescr);
        candidatePersistenceArchives.put(clientURI.toASCIIString(), archive);
        /*
             * If this app client 
             * was deployed as part of an EAR then scan any library JARs and, if the
             * client was also deployed or launched in v2-compatibility mode, any
             * top-level JARs in the EAR.
             * 
             * Exactly how we do this depends on whether this is a deployed client
             * (which will reside in a client download directory) or a non-deployed
             * one (which will reside either as a stand-alone client or within an
             * EAR).
             */
        if (isDeployed(mainAttrs)) {
            if (!isDeployedClientAlsoStandAlone(mainAttrs)) {
                addOtherDeployedScanTargets(archive, mainAttrs, candidatePersistenceArchives);
            }
        } else if (!isStandAlone(acDescr)) {
            addOtherNondeployedScanTargets(archive, acDescr, candidatePersistenceArchives);
        }
        for (Map.Entry<String, ReadableArchive> pathToArchiveEntry : candidatePersistenceArchives.entrySet()) {
            readPersistenceDeploymentDescriptor(main, pathToArchiveEntry.getValue(), pathToArchiveEntry.getKey(), descriptor);
        }
    } finally {
        for (Map.Entry<String, ReadableArchive> pathToArchiveEntry : candidatePersistenceArchives.entrySet()) {
        // pathToArchiveEntry.getValue().close();
        }
    }
    return null;
}
Also used : HashMap(java.util.HashMap) Attributes(java.util.jar.Attributes) ApplicationClientDescriptor(com.sun.enterprise.deployment.ApplicationClientDescriptor) ReadableArchive(org.glassfish.api.deployment.archive.ReadableArchive) MultiReadableArchive(com.sun.enterprise.deployment.deploy.shared.MultiReadableArchive) Manifest(java.util.jar.Manifest) URI(java.net.URI) HashMap(java.util.HashMap) Map(java.util.Map)

Aggregations

ReadableArchive (org.glassfish.api.deployment.archive.ReadableArchive)97 IOException (java.io.IOException)46 File (java.io.File)28 URI (java.net.URI)18 ActionReport (org.glassfish.api.ActionReport)17 ExtendedDeploymentContext (org.glassfish.internal.deployment.ExtendedDeploymentContext)14 DeployCommandParameters (org.glassfish.api.deployment.DeployCommandParameters)12 WritableArchive (org.glassfish.api.deployment.archive.WritableArchive)12 Application (com.sun.enterprise.deployment.Application)10 JarFile (java.util.jar.JarFile)10 ArchiveHandler (org.glassfish.api.deployment.archive.ArchiveHandler)10 ApplicationInfo (org.glassfish.internal.data.ApplicationInfo)10 ArrayList (java.util.ArrayList)9 ModuleDescriptor (org.glassfish.deployment.common.ModuleDescriptor)9 ConfigurationDeploymentDescriptorFile (com.sun.enterprise.deployment.io.ConfigurationDeploymentDescriptorFile)8 Logger (java.util.logging.Logger)8 DeploymentDescriptorFile (com.sun.enterprise.deployment.io.DeploymentDescriptorFile)7 Manifest (java.util.jar.Manifest)7 HashSet (java.util.HashSet)6 HashMap (java.util.HashMap)5