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();
}
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;
}
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);
}
}
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;
}
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;
}
Aggregations