use of org.glassfish.api.deployment.archive.ReadableArchive in project Payara by payara.
the class SnifferManagerImpl method getSniffers.
/**
* Returns a collection of sniffers that recognized some parts of the
* passed archive as components their container handle.
*
* If no sniffer recognize the passed archive, an empty collection is
* returned.
*
* @param context the deployment context
* @return possibly empty collection of sniffers that handle the passed
* archive.
*/
public Collection<Sniffer> getSniffers(DeploymentContext context) {
ReadableArchive archive = context.getSource();
ArchiveHandler handler = context.getArchiveHandler();
List<URI> uris = handler.getClassPathURIs(archive);
Types types = context.getTransientAppMetaData(Types.class.getName(), Types.class);
return getSniffers(context, uris, types);
}
use of org.glassfish.api.deployment.archive.ReadableArchive in project Payara by payara.
the class UpgradeStartup method processModule.
// repackage a module and return it as a jar file
private File processModule(File moduleDir, String targetParentDir, String suffix) throws IOException {
String moduleName = moduleDir.getName();
// sub module in ear case
if (moduleName.endsWith("_jar") || moduleName.endsWith("_war") || moduleName.endsWith("_rar")) {
suffix = "." + moduleName.substring(moduleName.length() - 3);
moduleName = moduleName.substring(0, moduleName.lastIndexOf('_'));
}
ReadableArchive source = archiveFactory.openArchive(moduleDir);
File tempJar = new File(targetParentDir, moduleName + suffix);
if (tempJar.exists()) {
boolean isDeleted = tempJar.delete();
if (!isDeleted) {
logger.log(Level.WARNING, "Error in deleting file " + tempJar.getAbsolutePath());
}
}
WritableArchive target = archiveFactory.createArchive("jar", tempJar);
Enumeration<String> e = source.entries();
while (e.hasMoreElements()) {
String entryName = e.nextElement();
if (isSigFile(entryName)) {
logger.log(Level.INFO, "Excluding signature file: " + entryName + " from repackaged module: " + moduleName + "\n");
continue;
}
InputStream sis = source.getEntry(entryName);
if (sis != null) {
InputStream is = new BufferedInputStream(sis);
OutputStream os = null;
try {
os = target.putNextEntry(entryName);
FileUtils.copy(is, os, source.getEntrySize(entryName));
} finally {
if (os != null) {
target.closeEntry();
}
is.close();
}
}
}
// last is manifest if existing.
Manifest m = source.getManifest();
if (m != null) {
processManifest(m, moduleName);
OutputStream os = target.putNextEntry(JarFile.MANIFEST_NAME);
m.write(os);
target.closeEntry();
}
source.close();
target.close();
return tempJar;
}
use of org.glassfish.api.deployment.archive.ReadableArchive in project Payara by payara.
the class MicroProfileSniffer method handles.
@Override
public boolean handles(DeploymentContext context) {
final ReadableArchive archive = context.getSource();
final String archivePath = archive.getURI().getPath();
// Ignore system applications
if (archivePath.contains("glassfish/lib/install")) {
return false;
}
if (archivePath.contains("h2db/bin")) {
return false;
}
if (archivePath.contains("mq/lib")) {
return false;
}
return handles(archive);
}
use of org.glassfish.api.deployment.archive.ReadableArchive in project Payara by payara.
the class ACCPersistenceArchivist method addOtherNondeployedScanTargets.
private void addOtherNondeployedScanTargets(final ReadableArchive clientArchive, final ApplicationClientDescriptor acDescr, final Map<String, ReadableArchive> candidates) {
/*
* The archive is a non-deployed one. We know from an earlier check
* that this is not a stand-alone app client, so we can use the
* app client archive's parent archive to get to the containing EAR for
* use in a subarchive scanner.
*/
final ReadableArchive earArchive = clientArchive.getParentArchive();
EARBasedPersistenceHelper.addLibraryAndTopLevelCandidates(earArchive, acDescr.getApplication(), true, candidates);
}
use of org.glassfish.api.deployment.archive.ReadableArchive in project Payara by payara.
the class ApplicationArchivist method getApplicationFromIntrospection.
/**
* This method introspect an ear file and populate the Application object. We follow the Java EE platform specification,
* Section EE.8.4.2 to determine the type of the modules included in this application.
*
* @param archive
* the archive representing the application root
* @param directory
* whether this is a directory deployment
*/
private Application getApplicationFromIntrospection(ReadableArchive archive, boolean directory) {
// archive is a directory
String appRoot = archive.getURI().getSchemeSpecificPart();
if (appRoot.endsWith(File.separator)) {
appRoot = appRoot.substring(0, appRoot.length() - 1);
}
Application app = Application.createApplication();
app.setLoadedFromApplicationXml(false);
app.setVirtual(false);
// name of the file without its extension
String appName = appRoot.substring(appRoot.lastIndexOf(File.separatorChar) + 1);
app.setName(appName);
List<ReadableArchive> unknowns = new ArrayList<>();
File[] files = getEligibleEntries(new File(appRoot), directory);
for (File subModule : files) {
ReadableArchive subArchive = null;
try {
try {
subArchive = archiveFactory.openArchive(subModule);
} catch (IOException ex) {
logger.log(Level.WARNING, ex.getMessage());
}
// for archive deployment, we check the sub archives by its
// file extension; for directory deployment, we check the sub
// directories by its name. We are now supporting directory
// names with both "_suffix" and ".suffix".
// Section EE.8.4.2.1.a
String name = subModule.getName();
String uri = deriveArchiveUri(appRoot, subModule, directory);
if ((!directory && name.endsWith(".war")) || (directory && (name.endsWith("_war") || name.endsWith(".war")))) {
ModuleDescriptor<BundleDescriptor> md = new ModuleDescriptor<>();
md.setArchiveUri(uri);
md.setModuleType(DOLUtils.warType());
// the context root will be set later after
// we process the sub modules
app.addModule(md);
} else // Section EE.8.4.2.1.b
if ((!directory && name.endsWith(".rar")) || (directory && (name.endsWith("_rar") || name.endsWith(".rar")))) {
ModuleDescriptor<BundleDescriptor> md = new ModuleDescriptor<>();
md.setArchiveUri(uri);
md.setModuleType(DOLUtils.rarType());
app.addModule(md);
} else if ((!directory && name.endsWith(".jar")) || (directory && (name.endsWith("_jar") || name.endsWith(".jar")))) {
try {
// Section EE.8.4.2.1.d.i
AppClientArchivist acArchivist = new AppClientArchivist();
if (acArchivist.hasStandardDeploymentDescriptor(subArchive) || acArchivist.hasRuntimeDeploymentDescriptor(subArchive) || acArchivist.getMainClassName(subArchive.getManifest()) != null) {
ModuleDescriptor<BundleDescriptor> md = new ModuleDescriptor<>();
md.setArchiveUri(uri);
md.setModuleType(DOLUtils.carType());
md.setManifest(subArchive.getManifest());
app.addModule(md);
continue;
}
// Section EE.8.4.2.1.d.ii
Archivist ejbArchivist = archivistFactory.get().getArchivist(DOLUtils.ejbType());
if (ejbArchivist.hasStandardDeploymentDescriptor(subArchive) || ejbArchivist.hasRuntimeDeploymentDescriptor(subArchive)) {
ModuleDescriptor<BundleDescriptor> md = new ModuleDescriptor<>();
md.setArchiveUri(uri);
md.setModuleType(DOLUtils.ejbType());
app.addModule(md);
continue;
}
} catch (IOException ex) {
logger.log(Level.WARNING, ex.getMessage());
}
// Still could not decide between an ejb and a library
unknowns.add(subArchive);
// Prevent this unknown archive from being closed in the
// finally block, because the same object will be used in
// the block below where unknowns are checked one more time.
subArchive = null;
} else {
// ignored
}
} finally {
if (subArchive != null) {
try {
subArchive.close();
} catch (IOException ioe) {
logger.log(Level.WARNING, localStrings.getLocalString("enterprise.deployment.errorClosingSubArch", "Error closing subarchive {0}", new Object[] { subModule.getAbsolutePath() }), ioe);
}
}
}
}
if (unknowns.size() > 0) {
AnnotationDetector detector = new AnnotationDetector(new EjbComponentAnnotationScanner());
for (int i = 0; i < unknowns.size(); i++) {
File jarFile = new File(unknowns.get(i).getURI().getSchemeSpecificPart());
try {
if (detector.hasAnnotationInArchive(unknowns.get(i))) {
String uri = deriveArchiveUri(appRoot, jarFile, directory);
// Section EE.8.4.2.1.d.ii, alas EJB
ModuleDescriptor<BundleDescriptor> md = new ModuleDescriptor<>();
md.setArchiveUri(uri);
md.setModuleType(DOLUtils.ejbType());
app.addModule(md);
}
/*
* The subarchive was opened by the anno detector. Close it.
*/
unknowns.get(i).close();
} catch (IOException ex) {
logger.log(Level.WARNING, ex.getMessage());
}
}
}
return app;
}
Aggregations