Package com.sun.enterprise.deploy.shared

Examples of com.sun.enterprise.deploy.shared.FileArchive


        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()}));
View Full Code Here


     * @param fileID The archive file name
     * @param result where to place the result
     */
    public static void testFileExistence(String uri, String fileName, String fileID, Result result) {
       
       FileArchive arch=null;
//       ZipEntry ze=null;
       JarFile jarFile=null;
      
       if (fileName == null || fileName.length()==0) {
      result.notApplicable(smh.getLocalString
              ("com.sun.enterprise.tools.verifier.tests.VerifierTest.fileexistence.notApplicable",
                 "No {0} defined in deployment descriptors",
                 new Object[] {fileID}));                       
            return;
        }
//        if (file==null){
            try{
                arch = new FileArchive();
                arch.open(URI.create(uri));
            }catch(Exception e){}  
//        }else{
//            try {
//                jarFile = new JarFile(file);
//            } catch (java.io.IOException ioe) {
//                Verifier.debug(ioe);
//                result.failed(smh.getLocalString
//                        ("com.sun.enterprise.tools.verifier.tests.VerifierTest.fileexistence.failed",
//                         "Error:  {0} [ {1} ] not found in the archive",
//                         new Object[] {fileID, fileName}));     
//                         return;
//             }
//         }
        try{
//            if (file!=null){
//            ze = jarFile.getEntry(fileName);
//            if (ze == null) {
//                result.failed(smh.getLocalString
//                    ("com.sun.enterprise.tools.verifier.tests.VerifierTest.fileexistence.failed",
//                    "Error: {0} [ {1} ] not found in the archive",
//                    new Object[] {fileID, fileName}));                          
//            }else{
//                result.passed(smh.getLocalString
//                ("com.sun.enterprise.tools.verifier.tests.VerifierTest.fileexistence.passed",
//                "{0} [ {1} ] found in the archive",
//                new Object[] {fileID, fileName}));                          
//            }
//        }
//        else{
            File urif = new File(new File(arch.getURI()), fileName);
            if(urif.exists()){
                result.passed(smh.getLocalString
                ("com.sun.enterprise.tools.verifier.tests.VerifierTest.fileexistence.passed",
                "{0} [ {1} ] found in the archive",
                new Object[] {fileID, fileName}));                          
View Full Code Here

                new Object[]{descriptor.getName()});
        String schemaVersion = getSchemaVersion(descriptor);
        context.setSchemaVersion(schemaVersion);
        context.setJavaEEVersion(verifierFrameworkContext.getJavaEEVersion());
        context.setComponentNameConstructor(getComponentNameConstructor(descriptor));
        FileArchive moduleArchive = new FileArchive();
        moduleArchive.open(getAbstractArchiveUri(descriptor));
        context.setModuleArchive(moduleArchive);
        ResultManager resultManager = verifierFrameworkContext.getResultManager();
        for (int i = 0; i < test.size(); i++) {
            TestInformation ti = (TestInformation) test.elementAt(i);
            String minVersion = ti.getMinimumVersion();
View Full Code Here

            uri = archBase;
        } else {
            uri = archBase + File.separator +
                FileUtils.makeFriendlyFilename(moduleDesc.getArchiveUri());
        }
        FileArchive arch = new FileArchive();
        arch.open(uri);
        InputStream is = arch.getEntry(location);
        try {
        // is can be null if wrong location of tld is specified in web.xml
            if (is == null)
                throw new IOException(smh.getLocalString
                        (getClass().getName() + ".exception1", // NOI18N
View Full Code Here

            uri = archBase;
        } else {
            uri = archBase + File.separator +
                    FileUtils.makeFriendlyFilename(moduleDesc.getArchiveUri());
        }
        FileArchive arch = new FileArchive();
        arch.open(URI.create(uri));
        InputStream is = arch.getEntry(facesConfigFileName);
        InputSource source = new InputSource(is);
        try {
            facesConfigDocument = builder.parse(source);
        } finally {
            try{
View Full Code Here

    protected abstract String[] getDDString();

    protected InputStream getInputStreamFromAbstractArchive(String uri,
                                                            String ddName)
            throws IOException {
        FileArchive arch = new FileArchive();
        arch.open(new File(uri).toURI());
        InputStream deploymentEntry = arch.getEntry(ddName);
        return deploymentEntry;
    }
View Full Code Here

        try {
//             if (f == null) {
              String uri = getAbstractArchiveUri(descriptor);
//              try {
                 FileArchive arch = new FileArchive();
                 arch.open(uri);
                 deploymentEntry = arch.getEntry(wsdlUri);
//              }catch (IOException e) { throw e;}
//             }
//             else {
//
//               jarFile = new JarFile(f);
View Full Code Here

        InputStream deploymentEntry=null;
        String uri = null;

  try {
                uri = getAbstractArchiveUri(descriptor);
                 FileArchive arch = new FileArchive();
                 arch.open(uri);
                 deploymentEntry = arch.getEntry(DescriptorConstants.EJB_DD_ENTRY);

      if (deploymentEntry != null) {
    BufferedReader in = new BufferedReader(new InputStreamReader(deploymentEntry));
    String s = in.readLine();
    boolean foundDOCTYPE = false, foundPubid = false, foundURL = false;
View Full Code Here

                    /*
                     * Delete the repository directory as an archive to allow
                     * any special processing (such as stale file handling)
                     * to run.
                     */
                    final FileArchive arch = DeploymentUtils.openAsFileArchive(reposDir, archiveFactory);
                    arch.delete();
                }
            }

            if (!DeploymentUtils.isDomainTarget(target) && enabled) {
                // try to disable the enabled version, if exist
                try {
                    versioningService.handleDisable(name,target, report, context.getSubject());
                } catch (VersioningSyntaxException e) {
                    report.failure(logger, e.getMessage());
                    return;
                }
            }

            File source = new File(archive.getURI().getSchemeSpecificPart());
            boolean isDirectoryDeployed = true;
            if (!source.isDirectory()) {
                isDirectoryDeployed = false;
                expansionDir = new File(domain.getApplicationRoot(), VersioningUtils.getRepositoryName(name));
                path = expansionDir;
            } else {
                // test if a version is already directory deployed from this dir
                String versionFromSameDir =
                        versioningService.getVersionFromSameDir(source);
                if (!force && versionFromSameDir != null) {
                    report.failure(logger,
                            VersioningUtils.LOCALSTRINGS.getLocalString(
                                "versioning.deployment.dual.inplace",
                                "GlassFish do not support versioning for directory deployment when using the same directory. The directory {0} is already assigned to the version {1}.",
                                source.getPath(),
                                versionFromSameDir));
                    return;
                }
            }

            // create the parent class loader
            deploymentContext =
                    deployment.getBuilder(logger, this, report).
                            source(archive).archiveHandler(archiveHandler).build(initialContext);
            if (tracing!=null) {
                tracing.addMark(DeploymentTracing.Mark.CONTEXT_CREATED);
                deploymentContext.addModuleMetaData(tracing);
            }

            // reset the properties (might be null) set by the deployers when undeploying.
            if (undeployProps!=null) {
                deploymentContext.getAppProps().putAll(undeployProps);
            }

            if (properties != null || property != null) {
                // if one of them is not null, let's merge them
                // to properties so we don't need to always
                // check for both
                if (properties == null) {
                    properties = new Properties();
                }
                if (property != null) {
                    properties.putAll(property);
                }
            }

            if (properties != null) {
                deploymentContext.getAppProps().putAll(properties);
                validateDeploymentProperties(properties, deploymentContext);
            }

            // clean up any generated files
            deploymentContext.clean();

            Properties appProps = deploymentContext.getAppProps();
            /*
             * If the app's location is within the domain's directory then
             * express it in the config as ${com.sun.aas.instanceRootURI}/rest-of-path
             * so users can relocate the entire installation without having
             * to modify the app locations.  Leave the location alone if
             * it does not fall within the domain directory.
             */
            String appLocation = DeploymentUtils.relativizeWithinDomainIfPossible( deploymentContext.getSource().getURI());
           
            appProps.setProperty(ServerTags.LOCATION, appLocation);
            // set to default "user", deployers can override it
            // during processing
            appProps.setProperty(ServerTags.OBJECT_TYPE, "user");
            if (contextroot!=null) {
                appProps.setProperty(ServerTags.CONTEXT_ROOT, contextroot);
            }
            appProps.setProperty(ServerTags.DIRECTORY_DEPLOYED, String.valueOf(isDirectoryDeployed));
            if (type == null) {
                type = archiveHandler.getArchiveType();
            }
            appProps.setProperty(Application.ARCHIVE_TYPE_PROP_NAME, type);

            savedAppConfig.store(appProps);

            deploymentContext.addTransientAppMetaData(DeploymentProperties.PREVIOUS_TARGETS, previousTargets);
            deploymentContext.addTransientAppMetaData(DeploymentProperties.PREVIOUS_VIRTUAL_SERVERS, previousVirtualServers);
            deploymentContext.addTransientAppMetaData(DeploymentProperties.PREVIOUS_ENABLED_ATTRIBUTES, previousEnabledAttributes);

            Transaction t = deployment.prepareAppConfigChanges(deploymentContext);
            if (tracing!=null) {
                tracing.addMark(DeploymentTracing.Mark.DEPLOY);
            }
            ApplicationInfo appInfo;
            appInfo = deployment.deploy(deploymentContext);

            /*
             * Various deployers might have added to the downloadable or
             * generated artifacts.  Extract them and, if the command succeeded,
             * persist both into the app properties (which will be recorded
             * in domain.xml).
             */
            final Artifacts downloadableArtifacts =
                    DeploymentUtils.downloadableArtifacts(deploymentContext);
            final Artifacts generatedArtifacts =
                    DeploymentUtils.generatedArtifacts(deploymentContext);
           
            if (report.getActionExitCode()==ActionReport.ExitCode.SUCCESS) {
                try {
                    moveAppFilesToPermanentLocation(
                            deploymentContext, logger);
                    recordFileLocations(appProps);

                    downloadableArtifacts.record(appProps);
                    generatedArtifacts.record(appProps);

                    // register application information in domain.xml
                    deployment.registerAppInDomainXML(appInfo, deploymentContext, t);
                    if (tracing!=null) {
                        tracing.addMark(DeploymentTracing.Mark.REGISTRATION);
                    }
                    if (retrieve != null) {
                        retrieveArtifacts(context, downloadableArtifacts.getArtifacts(), retrieve, false, name);
                    }
                    suppInfo.setDeploymentContext(deploymentContext);
                    //Fix for issue 14442
                    //We want to report the worst subreport value.
                    ActionReport.ExitCode worstExitCode = ExitCode.SUCCESS;
                    for (ActionReport subReport : report.getSubActionsReport()) {
                        ActionReport.ExitCode actionExitCode = subReport.getActionExitCode();

                        if ( actionExitCode.isWorse(worstExitCode) ){
                           worstExitCode = actionExitCode;
                       }
                    }
                    report.setActionExitCode(worstExitCode);
                    report.setResultType(String.class, name);

                } catch (Exception e) {
                    // roll back the deployment and re-throw the exception
                    deployment.undeploy(name, deploymentContext);
                    deploymentContext.clean();
                    throw e;
                }
            }
        } catch(Throwable e) {
            report.setActionExitCode(ActionReport.ExitCode.FAILURE);
            report.setMessage(e.getMessage());
            report.setFailureCause(e);
        } finally {
            events.unregister(this);
            try {
                archive.close();
            } catch(IOException e) {
                logger.log(Level.FINE, localStrings.getLocalString(
                        "errClosingArtifact",
                        "Error while closing deployable artifact : ",
                        path.getAbsolutePath()), e);
            }
           
            if (report.getActionExitCode().equals(ActionReport.ExitCode.SUCCESS)) {
                // Set the app name in the result so that embedded deployer can retrieve it.
                report.setResultType(String.class, name);
                report.setMessage(localStrings.getLocalString("deploy.command.success","Application deployed with name {0}", name));

                logger.info(localStrings.getLocalString(
                        "deploy.done",
                        "Deployment of {0} done is {1} ms",
                        name,
                        timing.elapsed()));
            } else if (report.getActionExitCode().equals(ActionReport.ExitCode.FAILURE)) {
                String errorMessage = report.getMessage();
                Throwable cause = report.getFailureCause();
                if (cause != null) {
                    String causeMessage = cause.getMessage();
                    if (causeMessage != null &&
                        !causeMessage.equals(errorMessage)) {
                        errorMessage = errorMessage + " : " + cause.getMessage();
                    }
                    logger.log(Level.SEVERE, errorMessage, cause.getCause());
                }
                report.setMessage(localStrings.getLocalString("deploy.errDuringDepl", "Error occur during deployment: {0}.", errorMessage));
                // reset the failure cause so command framework will not try
                // to print the same message again
                report.setFailureCause(null);
                if (expansionDir!=null) {
                    final FileArchive arch;
                        try {
                            /*
                             * Open and then delete the expansion directory as
                             * a file archive so stale file handling can run.
                             */
                            arch = DeploymentUtils.openAsFileArchive(expansionDir, archiveFactory);
                            arch.delete();
                        } catch (IOException ex) {
                            final String msg = localStrings.getLocalString(
                                    "deploy.errDelRepos",
                                    "Error deleting repository directory {0}",
                                    expansionDir.getAbsolutePath());
View Full Code Here

                    /*
                     * Delete the repository directory as an archive to allow
                     * any special processing (such as stale file handling)
                     * to run.
                     */
                    final FileArchive arch = DeploymentUtils.openAsFileArchive(reposDir, archiveFactory);
                    arch.delete();
                }
            }

            if (!DeploymentUtils.isDomainTarget(target) && enabled) {
                // try to disable the enabled version, if exist
                try {
                    versioningService.handleDisable(name,target, report, context.getSubject());
                } catch (VersioningSyntaxException e) {
                    report.failure(logger, e.getMessage());
                    return;
                }
            }

            File source = new File(archive.getURI().getSchemeSpecificPart());
            boolean isDirectoryDeployed = true;
            if (!source.isDirectory()) {
                isDirectoryDeployed = false;
                expansionDir = new File(domain.getApplicationRoot(), VersioningUtils.getRepositoryName(name));
                path = expansionDir;
            } else {
                // test if a version is already directory deployed from this dir
                String versionFromSameDir =
                        versioningService.getVersionFromSameDir(source);
                if (!force && versionFromSameDir != null) {
                    report.failure(logger,
                            VersioningUtils.LOCALSTRINGS.getLocalString(
                                "versioning.deployment.dual.inplace",
                                "GlassFish do not support versioning for directory deployment when using the same directory. The directory {0} is already assigned to the version {1}.",
                                source.getPath(),
                                versionFromSameDir));
                    return;
                }
            }

            // create the parent class loader
            deploymentContext =
                    deployment.getBuilder(logger, this, report).
                            source(initialContext.getSource()).archiveHandler(archiveHandler).build(initialContext);
            if (tracing!=null) {
                tracing.addMark(DeploymentTracing.Mark.CONTEXT_CREATED);
                deploymentContext.addModuleMetaData(tracing);
            }

            // reset the properties (might be null) set by the deployers when undeploying.
            if (undeployProps!=null) {
                deploymentContext.getAppProps().putAll(undeployProps);
            }

            if (properties != null || property != null) {
                // if one of them is not null, let's merge them
                // to properties so we don't need to always
                // check for both
                if (properties == null) {
                    properties = new Properties();
                }
                if (property != null) {
                    properties.putAll(property);
                }
            }

            if (properties != null) {
                deploymentContext.getAppProps().putAll(properties);
                validateDeploymentProperties(properties, deploymentContext);
            }

            // clean up any generated files
            deploymentContext.clean();

            Properties appProps = deploymentContext.getAppProps();
            /*
             * If the app's location is within the domain's directory then
             * express it in the config as ${com.sun.aas.instanceRootURI}/rest-of-path
             * so users can relocate the entire installation without having
             * to modify the app locations.  Leave the location alone if
             * it does not fall within the domain directory.
             */
            String appLocation = DeploymentUtils.relativizeWithinDomainIfPossible( deploymentContext.getSource().getURI());
           
            appProps.setProperty(ServerTags.LOCATION, appLocation);
            // set to default "user", deployers can override it
            // during processing
            appProps.setProperty(ServerTags.OBJECT_TYPE, "user");
            if (contextroot!=null) {
                appProps.setProperty(ServerTags.CONTEXT_ROOT, contextroot);
            }
            appProps.setProperty(ServerTags.DIRECTORY_DEPLOYED, String.valueOf(isDirectoryDeployed));
            if (type == null) {
                type = archiveHandler.getArchiveType();
            }
            appProps.setProperty(Application.ARCHIVE_TYPE_PROP_NAME, type);

            savedAppConfig.store(appProps);

            deploymentContext.addTransientAppMetaData(DeploymentProperties.PREVIOUS_TARGETS, previousTargets);
            deploymentContext.addTransientAppMetaData(DeploymentProperties.PREVIOUS_VIRTUAL_SERVERS, previousVirtualServers);
            deploymentContext.addTransientAppMetaData(DeploymentProperties.PREVIOUS_ENABLED_ATTRIBUTES, previousEnabledAttributes);

            Transaction t = deployment.prepareAppConfigChanges(deploymentContext);
            if (tracing!=null) {
                tracing.addMark(DeploymentTracing.Mark.DEPLOY);
            }
            ApplicationInfo appInfo;
            appInfo = deployment.deploy(deploymentContext);

            /*
             * Various deployers might have added to the downloadable or
             * generated artifacts.  Extract them and, if the command succeeded,
             * persist both into the app properties (which will be recorded
             * in domain.xml).
             */
            final Artifacts downloadableArtifacts =
                    DeploymentUtils.downloadableArtifacts(deploymentContext);
            final Artifacts generatedArtifacts =
                    DeploymentUtils.generatedArtifacts(deploymentContext);
           
            if (report.getActionExitCode()==ActionReport.ExitCode.SUCCESS) {
                try {
                    moveAppFilesToPermanentLocation(
                            deploymentContext, logger);
                    recordFileLocations(appProps);

                    downloadableArtifacts.record(appProps);
                    generatedArtifacts.record(appProps);

                    // register application information in domain.xml
                    deployment.registerAppInDomainXML(appInfo, deploymentContext, t);
                    if (tracing!=null) {
                        tracing.addMark(DeploymentTracing.Mark.REGISTRATION);
                    }
                    if (retrieve != null) {
                        retrieveArtifacts(context, downloadableArtifacts.getArtifacts(), retrieve, false, name);
                    }
                    suppInfo.setDeploymentContext(deploymentContext);
                    //Fix for issue 14442
                    //We want to report the worst subreport value.
                    ActionReport.ExitCode worstExitCode = ExitCode.SUCCESS;
                    for (ActionReport subReport : report.getSubActionsReport()) {
                        ActionReport.ExitCode actionExitCode = subReport.getActionExitCode();

                        if ( actionExitCode.isWorse(worstExitCode) ){
                           worstExitCode = actionExitCode;
                       }
                    }
                    report.setActionExitCode(worstExitCode);
                    report.setResultType(String.class, name);

                } catch (Exception e) {
                    // roll back the deployment and re-throw the exception
                    deployment.undeploy(name, deploymentContext);
                    deploymentContext.clean();
                    throw e;
                }
            }
        } catch(Throwable e) {
            report.setActionExitCode(ActionReport.ExitCode.FAILURE);
            report.setMessage(e.getMessage());
            report.setFailureCause(e);
        } finally {
            events.unregister(this);
            try {
                archive.close();
            } catch(IOException e) {
                logger.log(Level.FINE, localStrings.getLocalString(
                        "errClosingArtifact",
                        "Error while closing deployable artifact : ",
                        path.getAbsolutePath()), e);
            }
           
            if (report.getActionExitCode().equals(ActionReport.ExitCode.SUCCESS)) {
                // Set the app name in the result so that embedded deployer can retrieve it.
                report.setResultType(String.class, name);
                report.setMessage(localStrings.getLocalString("deploy.command.success","Application deployed with name {0}", name));

                logger.info(localStrings.getLocalString(
                        "deploy.done",
                        "Deployment of {0} done is {1} ms",
                        name,
                        timing.elapsed()));
            } else if (report.getActionExitCode().equals(ActionReport.ExitCode.FAILURE)) {
                String errorMessage = report.getMessage();
                Throwable cause = report.getFailureCause();
                if (cause != null) {
                    String causeMessage = cause.getMessage();
                    if (causeMessage != null &&
                        !causeMessage.equals(errorMessage)) {
                        errorMessage = errorMessage + " : " + cause.getMessage();
                    }
                    logger.log(Level.SEVERE, errorMessage, cause.getCause());
                }
                report.setMessage(localStrings.getLocalString("deploy.errDuringDepl", "Error occur during deployment: {0}.", errorMessage));
                // reset the failure cause so command framework will not try
                // to print the same message again
                report.setFailureCause(null);
                if (expansionDir!=null) {
                    final FileArchive arch;
                        try {
                            /*
                             * Open and then delete the expansion directory as
                             * a file archive so stale file handling can run.
                             */
                            arch = DeploymentUtils.openAsFileArchive(expansionDir, archiveFactory);
                            arch.delete();
                        } catch (IOException ex) {
                            final String msg = localStrings.getLocalString(
                                    "deploy.errDelRepos",
                                    "Error deleting repository directory {0}",
                                    expansionDir.getAbsolutePath());
View Full Code Here

TOP

Related Classes of com.sun.enterprise.deploy.shared.FileArchive

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.