Search in sources :

Example 71 with ReadableArchive

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

the class FileArchiveTest method createAndPopulateSubarchive.

private ReadableArchive createAndPopulateSubarchive(final WritableArchive parent, final String subarchiveName, final Set<String> entryNames) throws Exception {
    final WritableArchive result = parent.createSubArchive(subarchiveName);
    for (String entryName : entryNames) {
        result.putNextEntry(entryName);
        result.closeEntry();
    }
    result.close();
    final ReadableArchive readableParent = archiveFactory.openArchive(parent.getURI());
    return readableParent.getSubArchive(subarchiveName);
}
Also used : ReadableArchive(org.glassfish.api.deployment.archive.ReadableArchive) WritableArchive(org.glassfish.api.deployment.archive.WritableArchive)

Example 72 with ReadableArchive

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

the class InputJarArchiveTest method testNestedNonDirEntryNames.

@Test
public void testNestedNonDirEntryNames() {
    try {
        System.out.println("nested non-directory entry names in InputJarArchive");
        final ReadableArchive arch = getArchiveForTest();
        ReadableArchive subArchive = arch.getSubArchive(NESTED_JAR_ENTRY_NAME);
        final Set<String> returnedNames = new HashSet<String>(setFromEnumeration(subArchive.entries()));
        assertEquals("Returned nested non-directories do not match expected", testSubArchiveNonDirEntryNames(), returnedNames);
        retireArchive(arch);
    } catch (IOException ex) {
        ex.printStackTrace(System.out);
        fail("Error during test");
    }
}
Also used : IOException(java.io.IOException) ReadableArchive(org.glassfish.api.deployment.archive.ReadableArchive) HashSet(java.util.HashSet) Test(org.junit.Test)

Example 73 with ReadableArchive

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

the class DeploymentUtils method getManifestLibraries.

/**
 * Returns the URLs of libraries referenced in the manifest
 * @param archive
 * @param manifest
 * @return
 */
private static List<URL> getManifestLibraries(ReadableArchive archive, Manifest manifest) {
    String appRootPath = null;
    ReadableArchive parentArchive = archive.getParentArchive();
    if (parentArchive != null) {
        appRootPath = (new File(parentArchive.getURI())).getPath();
    } else {
        try {
            appRootPath = (new File(archive.getURI().getPath())).getParent();
        } catch (Exception e) {
        // ignore, this is the jar inside jar case
        }
    }
    // add libraries referenced through manifest
    return ASClassLoaderUtil.getManifestClassPathAsURLs(manifest, appRootPath);
}
Also used : ReadableArchive(org.glassfish.api.deployment.archive.ReadableArchive) JarFile(java.util.jar.JarFile) File(java.io.File) URISyntaxException(java.net.URISyntaxException) IOException(java.io.IOException)

Example 74 with ReadableArchive

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

the class ApplicationLifecycle method getExternalLibraries.

private List<ReadableArchive> getExternalLibraries(ReadableArchive source, Boolean skipScanExternalLibProp) throws IOException {
    List<ReadableArchive> externalLibArchives = new ArrayList<>();
    if (skipScanExternalLibProp) {
        // return an empty list here
        return Collections.emptyList();
    }
    List<URI> externalLibs = DeploymentUtils.getExternalLibraries(source);
    for (URI externalLib : externalLibs) {
        externalLibArchives.add(archiveFactory.openArchive(new File(externalLib.getPath())));
    }
    return externalLibArchives;
}
Also used : ReadableArchive(org.glassfish.api.deployment.archive.ReadableArchive) URI(java.net.URI) File(java.io.File)

Example 75 with ReadableArchive

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

the class ApplicationLifecycle method enable.

@Override
public ExtendedDeploymentContext enable(String target, Application app, ApplicationRef appRef, ActionReport report, Logger logger) throws Exception {
    ReadableArchive archive = null;
    try {
        DeployCommandParameters commandParams = app.getDeployParameters(appRef);
        // if the application is already loaded, do not load again
        ApplicationInfo appInfo = appRegistry.get(commandParams.name);
        if (appInfo != null && appInfo.isLoaded()) {
            return null;
        }
        commandParams.origin = DeployCommandParameters.Origin.load;
        commandParams.command = DeployCommandParameters.Command.enable;
        commandParams.target = target;
        commandParams.enabled = Boolean.TRUE;
        Properties contextProps = app.getDeployProperties();
        Map<String, Properties> modulePropsMap = app.getModulePropertiesMap();
        ApplicationConfigInfo savedAppConfig = new ApplicationConfigInfo(app);
        URI uri = new URI(app.getLocation());
        File file = new File(uri);
        if (!file.exists()) {
            throw new Exception(localStrings.getLocalString("fnf", "File not found {0}", file.getAbsolutePath()));
        }
        archive = archiveFactory.openArchive(file);
        final ExtendedDeploymentContext deploymentContext = getBuilder(logger, commandParams, report).source(archive).build();
        Properties appProps = deploymentContext.getAppProps();
        appProps.putAll(contextProps);
        savedAppConfig.store(appProps);
        if (modulePropsMap != null) {
            deploymentContext.setModulePropsMap(modulePropsMap);
        }
        deploy(getSniffersFromApp(app), deploymentContext);
        return deploymentContext;
    } finally {
        try {
            if (archive != null) {
                archive.close();
            }
        } catch (IOException ioe) {
        // ignore
        }
    }
}
Also used : DeployCommandParameters(org.glassfish.api.deployment.DeployCommandParameters) ApplicationConfigInfo(org.glassfish.deployment.common.ApplicationConfigInfo) ApplicationInfo(org.glassfish.internal.data.ApplicationInfo) IOException(java.io.IOException) ReadableArchive(org.glassfish.api.deployment.archive.ReadableArchive) DeploymentProperties(org.glassfish.deployment.common.DeploymentProperties) ExtendedDeploymentContext(org.glassfish.internal.deployment.ExtendedDeploymentContext) URI(java.net.URI) File(java.io.File) MultiException(org.glassfish.hk2.api.MultiException) DeploymentException(org.glassfish.deployment.common.DeploymentException) IOException(java.io.IOException) PropertyVetoException(java.beans.PropertyVetoException) RetryableException(org.jvnet.hk2.config.RetryableException) VersioningSyntaxException(org.glassfish.deployment.versioning.VersioningSyntaxException)

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