use of com.sun.enterprise.deployment.deploy.shared.OutputJarArchive 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 com.sun.enterprise.deployment.deploy.shared.OutputJarArchive in project Payara by payara.
the class AppClientDeployerHelper method 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);
addTopLevelContentToClientFacade(facadeArchive);
facadeArchive.close();
}
use of com.sun.enterprise.deployment.deploy.shared.OutputJarArchive in project Payara by payara.
the class AppClientDeployerHelper method JAROfExpandedSubmodule.
/**
* If the specified URI is for an expanded submodule, makes a copy of
* the submodule as a JAR and returns the URI for the copy.
* @param classPathElement
* @return URI to the safe copy of the submodule, relative to the top level
* 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());
}
use of com.sun.enterprise.deployment.deploy.shared.OutputJarArchive in project Payara by payara.
the class ClientJarWriter method createClientJARIfNeeded.
private File createClientJARIfNeeded(final ExtendedDeploymentContext deploymentContext, final String appName) throws IOException {
final ClientArtifactsManager clientArtifactsManager = ClientArtifactsManager.get(deploymentContext);
if (clientArtifactsManager.isEmpty()) {
return null;
}
/*
* Make sure the scratch directories are there.
*/
deploymentContext.prepareScratchDirs();
final String generatedClientJARName = generatedClientJARNameAndType(appName);
final File generatedClientJARFile = new File(deploymentContext.getScratchDir("xml"), generatedClientJARName);
/*
* The app client deployer might have already created the generated JAR
* file. In that case we need to merge its contents with what has been
* registered with the client artifacts manager.
*/
File movedPreexistingFile = null;
if (generatedClientJARFile.exists()) {
try {
movedPreexistingFile = mergeContentsToClientArtifactsManager(generatedClientJARFile, clientArtifactsManager);
} catch (URISyntaxException ex) {
throw new IOException(ex);
}
}
/*
* We need our own copy of the artifacts collection because we might
* need to add the manifest to it if a manifst is not already in the collection.
* The client artifacts manager returns an unalterable collection.
*/
final Collection<Artifacts.FullAndPartURIs> artifacts = new ArrayList<Artifacts.FullAndPartURIs>(clientArtifactsManager.artifacts());
OutputJarArchive generatedClientJAR = new OutputJarArchive();
try {
try {
generatedClientJAR.create(generatedClientJARFile.toURI());
if (!isManifestPresent(artifacts)) {
/*
* Add a simple manifest.
*/
deplLogger.log(Level.FINER, "Adding a simple manifest; one was not already generated");
addManifest(artifacts);
}
copyArtifactsToClientJAR(generatedClientJAR, artifacts);
} finally {
generatedClientJAR.close();
}
} catch (IOException ex) {
if (!generatedClientJARFile.delete()) {
generatedClientJARFile.deleteOnExit();
}
} finally {
if (movedPreexistingFile != null) {
FileUtils.deleteFileNowOrLater(movedPreexistingFile);
}
}
return generatedClientJARFile;
}
Aggregations