Package com.sun.enterprise.deployment.deploy.shared

Examples of com.sun.enterprise.deployment.deploy.shared.OutputJarArchive


     * @throws java.io.IOException
     */
    private static void createJar(String sourcePath, String destinationPath)
            throws IOException {
        FileArchive source = new FileArchive();
        OutputJarArchive destination = new OutputJarArchive();
        try {
            source.open(sourcePath);
            destination.create(destinationPath);
            for (Enumeration entries = source.entries();
                 entries.hasMoreElements();) {
                String entry = String.class.cast(entries.nextElement());
                InputStream is = null;
                OutputStream os = null;
                try {
                    is = source.getEntry(entry);
                    os = destination.putNextEntry(entry);
                    ArchivistUtils.copyWithoutClose(is, os);
                } finally {
                    if (is != null) is.close();
                    if (os != null) destination.closeEntry();
                }
            }
        } finally {
            source.close();
            destination.close();
        }
    }
View Full Code Here


    }
   
    private void createJar(String sourcePath, String destinationPath)
    throws IOException {
        FileArchive source = new FileArchive();
        OutputJarArchive destination = new OutputJarArchive();
        try {
            source.open(sourcePath);
            Enumeration entries = source.entries();
            destination.create(destinationPath);
            while(entries.hasMoreElements()) {
                String entry = String.class.cast(entries.nextElement());
                InputStream is = null;
                OutputStream os = null;
                try {
                    is = source.getEntry(entry);
                    os = destination.putNextEntry(entry);
                    ArchivistUtils.copyWithoutClose(is, os);
                } finally {
                    if (is != null) is.close();
                    if (os != null) destination.closeEntry();
                }
            }
        } finally {
            source.close();
            destination.close();
        }
    }
View Full Code Here

                continue;
            }
            earName=earName+".ear";
            try {
                JarArchiveFactory jaf = new JarArchiveFactory();
                OutputJarArchive targetJar = (OutputJarArchive)jaf.createArchive(new File(targetDir, earName).getAbsolutePath());
                FileArchiveFactory faf = new FileArchiveFactory();
                FileArchive farc = (FileArchive)faf.openArchive((new File(srcDir, earDirName)).getAbsolutePath());
                Enumeration e = farc.entries();
                String lastModuleProcessed = "";
                while(e.hasMoreElements()) {
                    String s = (String)e.nextElement();
                    String moduleDir;
                    try {
                        moduleDir = s.substring(0, s.lastIndexOf('_')+4);
                    } catch (StringIndexOutOfBoundsException sob) {
                        moduleDir = "";
                    }
                   
                    FileInputStream fis = null;
                    OutputStream out = null;
                    try {
                        if (moduleDir.endsWith("_jar") || moduleDir.endsWith("_war") || moduleDir.endsWith("_rar")) {
                            if(lastModuleProcessed.equals(moduleDir)) {
                                continue;
                            }
                            File jar = processModule(EAR_DIR, earDirName, moduleDir);
                            lastModuleProcessed = moduleDir;
                            out = targetJar.putNextEntry(jar.getName());
                            fis = new FileInputStream(jar);
                        } else {
                            if (!s.endsWith("Client.jar")) { // don't include *Client.jars generated by server
                                out = targetJar.putNextEntry(s);
                                fis = new FileInputStream(new File(new File(srcDir, earDirName), s));
                            } else {
                                continue;
                            }
                           
                        }
                       
                        while(fis.available() > 0) {
                            int ix = fis.read();
                            out.write(ix);
                        }
                       
                    } catch(java.util.zip.ZipException z) {
                        logger.warning(stringManager.getString("upgrade.deployment.zipExceptionMsg")+z.getMessage());
                    } catch (IOException ioe) {
                        logger.severe(stringManager.getString("upgrade.deployment.ioExceptionMsg")+ioe.getMessage());
                    }
                    targetJar.closeEntry();
                }
                targetJar.close();
                //start - Added for 6396486
                // Build the parameters to be passed to the deploy command
                String jarPath = new File(targetJar.getArchiveUri()).getAbsolutePath();   
                String fileName = new File(jarPath).getName();
                String moduleName = fileName.substring(0, fileName.lastIndexOf('.'));
                ArrayList parameters = upgradeUtils.buildAppDeploymentParameters(moduleName);

                //Added for CR 6480041
View Full Code Here

            }
            //temp = File.createTempFile(moduleName, suffix);
            File tempJar = new File(targetDir, moduleName + suffix);
            String path = tempJar.getAbsolutePath();
            //temp.delete();
            OutputJarArchive targetModule = (OutputJarArchive)jaf.createArchive(path);
            logger.fine(stringManager.getString("upgrade.deployment.addingInfoMsg") + targetModule.getArchiveUri());
            e = farc.entries();
            while(e.hasMoreElements()) {
                String entry = (String)e.nextElement();
                InputStream in = farc.getEntry(entry);
                if (entry.equals("WEB-INF/web.xml")) {
                    InputStream fixedDescriptor = fixWebServiceDescriptor(farc);
                    if(fixedDescriptor != null) {
                        in = fixedDescriptor;
                    }
                }
            //start RFE 6389864
                if(entry.equals("WEB-INF/sun-web.xml")) {
                    checkDescriptors(farc, "sun-web.xml", "WEB-INF");
                        }
                if(entry.equals("META-INF/sun-ejb-jar.xml")) {
                    checkDescriptors(farc, "sun-ejb-jar.xml", "META-INF");
                }
    //end RFE 6389864
                OutputStream out = null;
                try {
                    out = targetModule.putNextEntry(entry);
                    int i = in.read();
                    while (i > -1) {
                        out.write(i);
                        i = in.read();
                    }
                } catch(java.util.zip.ZipException z) {
                    logger.warning(stringManager.getString("upgrade.deployment.zipExceptionMsg")+z.getMessage());
                }catch (IOException ioe) {
                    logger.severe(stringManager.getString("upgrade.deployment.ioExceptionMsg")+ioe.getMessage());
                }
                finally {
                    targetModule.closeEntry();
                    if (in != null) in.close();
                    //if (out != null) out.close();
                }

            }
            InputStream in = farc.getEntry(JarFile.MANIFEST_NAME);
            OutputStream out = null;
            try {
                  if(in != null){
                    out = targetModule.putNextEntry(JarFile.MANIFEST_NAME);
                    int i = in.read();
                    while (i > -1) {
                        out.write(i);
                        i = in.read();
                    }
                  }
            } catch(java.util.zip.ZipException z) {
                logger.warning(stringManager.getString("upgrade.deployment.zipExceptionMsg")+z.getMessage());
            }catch (IOException ioe) {
                logger.severe(stringManager.getString("upgrade.deployment.ioExceptionMsg")+ioe.getMessage());
            }finally {
                    targetModule.closeEntry();
                    targetModule.close();
                    if (in != null) in.close();
                   // if (out != null) out.close();
                }
            return tempJar;
        } catch(IOException ex) {
View Full Code Here

    public static final void createClientJar(
        DeploymentRequest request, File clientJar, ZipItem[] clientStubs,
        String clientJarChoice) throws IASDeploymentException {
        try {        
            // client jar naming convension is <app-name>Client.jar
            OutputJarArchive target = new OutputJarArchive();
            target.create(clientJar.getAbsolutePath());
           
            RootDeploymentDescriptor descriptor;
            if (request.getDescriptor().isVirtual()) {
                descriptor = request.getDescriptor().getStandaloneBundleDescriptor();
            } else {
                descriptor = request.getDescriptor();
            }
           
            AbstractArchive source = new FileArchive();
            ((FileArchive) source).open(request.getDeployedDirectory().getAbsolutePath());
            PEDeploymentFactoryImpl pe = new PEDeploymentFactoryImpl();
            Properties props = getPropertiesForClientJarMaker(
                CLIENT_JAR_CHOICES.getClientJarChoice(clientJarChoice),
                request, descriptor);
            ClientJarMaker jarMaker = pe.getClientJarMaker(props);

            // copy xml files from generated directory archive to original
            // directory archive so the created client jar contain
            // processed xml files.
            if (FileUtils.safeIsDirectory(
                request.getGeneratedXMLDirectory())) {
                AbstractArchive source2 = new FileArchive();
                ((FileArchive) source2).open(
                    request.getGeneratedXMLDirectory().getAbsolutePath());
                jarMaker.create(descriptor, source, source2, target, clientStubs,
                    null);
                source2.close();
            } else {
                jarMaker.create(descriptor, source, target, clientStubs,null);
            }
            source.close();
            target.close();
        } catch(Exception e) {
            IASDeploymentException newE = new IASDeploymentException();
            newE.initCause(e);
            throw newE;
        }
View Full Code Here

     * if the classPathElement is for a submodule; null otherwise
     */
    File JAROfExpandedSubmodule(final URI candidateSubmoduleURI) throws IOException {
        ReadableArchive source = new FileArchive();
        source.open(dc().getSource().getParentArchive().getURI().resolve(expandedDirURI(candidateSubmoduleURI)));
        OutputJarArchive target = new OutputJarArchive();
        target.create(dc().getScratchDir("xml").toURI().resolve(candidateSubmoduleURI));
        /*
         * Copy the manifest explicitly because the ReadableArchive
         * entries() method omits it.
         */
        Manifest mf = source.getManifest();
        OutputStream os = target.putNextEntry(JarFile.MANIFEST_NAME);
        mf.write(os);
        target.closeEntry();
        copyArchive(source, target, Collections.EMPTY_SET);
        target.close();
        return new File(target.getURI());
    }
View Full Code Here

    }
   
    protected abstract void copyFileToTopLevelJAR(final OutputJarArchive clientFacadeArchive, final File f, final String path) throws IOException;
   
    protected final void generateAppClientFacade() throws IOException, URISyntaxException {
        OutputJarArchive facadeArchive = new OutputJarArchive();
        /*
         * Make sure the directory subtree to contain the facade exists.  If the
         * client URI within the EAR contains a directory then that directory
         * probably does not exist in the generated dir for this app...not yet
         * anyway...it is about to exist.
         */
        final File facadeFile = new File(facadeServerURI(dc));
        if ( ! facadeFile.getParentFile().exists()) {
            if ( ! facadeFile.getParentFile().mkdirs()) {
                final String msg = logger.getResourceBundle().getString("enterprise.deployment.appclient.errormkdirs");
                throw new IOException(MessageFormat.format(msg, facadeFile.getAbsolutePath()));
            }
        }
        facadeArchive.create(facadeServerURI(dc));
        ReadableArchive source = dc.getSource();
        Manifest sourceManifest = source.getManifest();
        if (sourceManifest == null) {
            final String msg = logger.getResourceBundle().getString("enterprise.deployment.appclient.noManifest");
            throw new IOException(MessageFormat.format(msg, source.getURI().toASCIIString()));
        }
        Manifest facadeManifest = facadeArchive.getManifest();
        initGeneratedManifest(sourceManifest, facadeManifest,
                facadeClassPath(), PUScanTargets(), application);
        /*
         * If the developer's app client JAR contains a splash screen, copy
         * it from the original JAR to the facade so the Java launcher can
         * display it when the app client is launched.
         */
        final Attributes srcMainAttrs = sourceManifest.getMainAttributes();
        if (srcMainAttrs == null) {
            final String msg = logger.getResourceBundle().getString("enterprise.deployment.appclient.noMainAttrs");
            throw new IOException(MessageFormat.format(msg, source.getURI().toASCIIString()));
        }
        String splash = srcMainAttrs.getValue(AppClientDeployer.SPLASH_SCREEN_IMAGE);
        if (splash != null) {
            copy(source, facadeArchive, splash);
        }
        /*
         * Write the manifest to the facade.
         */
        OutputStream os = facadeArchive.putNextEntry(JarFile.MANIFEST_NAME);
        facadeManifest.write(os);
        facadeArchive.closeEntry();
        /*
         * Write the updated descriptors to the facade.
         */
        writeUpdatedDescriptors(source, facadeArchive, appClientDesc);

        /*
         * Because of how persistence units are discovered and added to the
         * app client DOL object when the archivist reads the descriptor file,
         * add any META-INF/persistence.xml file from the developer's client
         * to the client facade.  (The generated descriptor and the
         * persistence.xml files need to be in the same archive.)
         */
        copyPersistenceUnitXML(source, facadeArchive);

        copyMainClass(facadeArchive);
       
        addTopLevelContentToClientFacade(facadeArchive);
       
        facadeArchive.close();
    }
View Full Code Here

        return appClientUserURI(dc()).toASCIIString();
    }
    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();
    }
View Full Code Here

     * if the classPathElement is for a submodule; null otherwise
     */
    File JAROfExpandedSubmodule(final URI candidateSubmoduleURI) throws IOException {
        ReadableArchive source = new FileArchive();
        source.open(dc().getSource().getParentArchive().getURI().resolve(expandedDirURI(candidateSubmoduleURI)));
        OutputJarArchive target = new OutputJarArchive();
        target.create(dc().getScratchDir("xml").toURI().resolve(candidateSubmoduleURI));
        /*
         * Copy the manifest explicitly because the ReadableArchive
         * entries() method omits it.
         */
        Manifest mf = source.getManifest();
        OutputStream os = target.putNextEntry(JarFile.MANIFEST_NAME);
        mf.write(os);
        target.closeEntry();
        copyArchive(source, target, Collections.EMPTY_SET);
        target.close();
        return new File(target.getURI());
    }
View Full Code Here

        generateAppClientFacade();
    }


    protected final void generateAppClientFacade() throws IOException, URISyntaxException {
        OutputJarArchive facadeArchive = new OutputJarArchive();
        /*
         * Make sure the directory subtree to contain the facade exists.  If the
         * client URI within the EAR contains a directory then that directory
         * probably does not exist in the generated dir for this app...not yet
         * anyway...it is about to exist.
         */
        final File facadeFile = new File(facadeServerURI(dc));
        if ( ! facadeFile.getParentFile().exists()) {
            if ( ! facadeFile.getParentFile().mkdirs()) {
                final String msg = logger.getResourceBundle().getString("enterprise.deployment.appclient.errormkdirs");
                throw new IOException(MessageFormat.format(msg, facadeFile.getAbsolutePath()));
            }
        }
        facadeArchive.create(facadeServerURI(dc));
        ReadableArchive source = dc.getSource();
        Manifest sourceManifest = source.getManifest();
        if (sourceManifest == null) {
            final String msg = logger.getResourceBundle().getString("enterprise.deployment.appclient.noManifest");
            throw new IOException(MessageFormat.format(msg, source.getURI().toASCIIString()));
        }
        Manifest facadeManifest = facadeArchive.getManifest();
        initGeneratedManifest(sourceManifest, facadeManifest,
                facadeClassPath(), PUScanTargets(), application);
        /*
         * If the developer's app client JAR contains a splash screen, copy
         * it from the original JAR to the facade so the Java launcher can
         * display it when the app client is launched.
         */
        final Attributes srcMainAttrs = sourceManifest.getMainAttributes();
        if (srcMainAttrs == null) {
            final String msg = logger.getResourceBundle().getString("enterprise.deployment.appclient.noMainAttrs");
            throw new IOException(MessageFormat.format(msg, source.getURI().toASCIIString()));
        }
        String splash = srcMainAttrs.getValue(AppClientDeployer.SPLASH_SCREEN_IMAGE);
        if (splash != null) {
            copy(source, facadeArchive, splash);
        }
        /*
         * Write the manifest to the facade.
         */
        OutputStream os = facadeArchive.putNextEntry(JarFile.MANIFEST_NAME);
        facadeManifest.write(os);
        facadeArchive.closeEntry();
        /*
         * Write the updated descriptors to the facade.
         */
        writeUpdatedDescriptors(source, facadeArchive, appClientDesc);

        /*
         * Because of how persistence units are discovered and added to the
         * app client DOL object when the archivist reads the descriptor file,
         * add any META-INF/persistence.xml file from the developer's client
         * to the client facade.  (The generated descriptor and the
         * persistence.xml files need to be in the same archive.)
         */
        copyPersistenceUnitXML(source, facadeArchive);

        copyMainClass(facadeArchive);

        facadeArchive.close();
    }
View Full Code Here

TOP

Related Classes of com.sun.enterprise.deployment.deploy.shared.OutputJarArchive

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.