use of com.sun.enterprise.deploy.shared.FileArchive in project Payara by payara.
the class AppClientArchiveClassesLoadable method check.
public Result check(ApplicationClientDescriptor descriptor) {
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() }));
return result;
}
Object entry;
while (entries.hasMoreElements()) {
String name = null;
entry = entries.nextElement();
name = (String) entry;
// look for entries with .class extension
if (name.endsWith(".class")) {
String className = name.substring(0, name.length() - ".class".length()).replace('/', '.');
boolean status = closureCompiler.buildClosure(className);
allPassed = status && allPassed;
}
}
if (allPassed) {
result.setStatus(Result.PASSED);
addGoodDetails(result, compName);
result.passed(smh.getLocalString(getClass().getName() + ".passed", "All the classes are loadable within [ {0} ] without any linkage error.", new Object[] { archiveUri }));
// result.addGoodDetails(closureCompiler.toString());
} else {
result.setStatus(Result.FAILED);
addErrorDetails(result, compName);
result.addErrorDetails(ArchiveClassesLoadableHelper.getFailedResult(closureCompiler));
result.addErrorDetails(smh.getLocalString("com.sun.enterprise.tools.verifier.tests.loadableError", "Please either bundle the above mentioned classes in the application " + "or use optional packaging support for them."));
}
return result;
}
use of com.sun.enterprise.deploy.shared.FileArchive in project Payara by payara.
the class ModuleExploder method explodeModule.
public static void explodeModule(Archive source, File directory, boolean preserveManifest) throws IOException, DeploymentException {
File explodedManifest = null;
File preservedManifestFromArchive = null;
FileArchive target = new FileArchive();
target.create(directory.toURI());
explodeJar(new File(source.getURI()), directory);
if (preserveManifest) {
explodedManifest = new File(directory, java.util.jar.JarFile.MANIFEST_NAME);
if (explodedManifest.exists()) {
/* Rename the manifest so it can be restored later. */
preservedManifestFromArchive = new File(directory, PRESERVED_MANIFEST_NAME);
if (!explodedManifest.renameTo(preservedManifestFromArchive)) {
throw new RuntimeException(localStrings.getString("enterprise.deployment.backend.error_saving_manifest", new Object[] { explodedManifest.getAbsolutePath(), preservedManifestFromArchive.getAbsolutePath() }));
}
}
}
// require access to the manifest file of each .jar file.
for (Enumeration itr = source.entries(); itr.hasMoreElements(); ) {
String fileName = (String) itr.nextElement();
/*
*Expand the file only if it is a jar and only if it does not lie in WEB-INF/lib.
*/
if (fileName.toLowerCase(Locale.US).endsWith(".jar") && (!fileName.replace('\\', '/').toUpperCase(Locale.getDefault()).startsWith(WEB_INF_PREFIX))) {
try {
File f = new File(directory, fileName);
ZipFile zip = new ZipFile(f, directory);
zip.explode();
} catch (ZipFileException e) {
IOException ioe = new IOException(e.getMessage());
ioe.initCause(e);
throw ioe;
}
}
}
/*
*If the archive's manifest was renamed to protect it from being overwritten by manifests from
*jar files, then rename it back. Delete an existing manifest file first if needed.
*/
if (preservedManifestFromArchive != null) {
if (explodedManifest.exists()) {
if (!explodedManifest.delete()) {
throw new RuntimeException(localStrings.getString("enterprise.deployment.backend.error_deleting_manifest", new Object[] { explodedManifest.getAbsolutePath(), preservedManifestFromArchive.getAbsolutePath() }));
}
}
if (!preservedManifestFromArchive.renameTo(explodedManifest)) {
throw new RuntimeException(localStrings.getString("enterprise.deployment.backend.error_restoring_manifest", new Object[] { preservedManifestFromArchive.getAbsolutePath(), explodedManifest.getAbsolutePath() }));
}
}
source.close();
target.close();
}
use of com.sun.enterprise.deploy.shared.FileArchive in project Payara by payara.
the class ClassFileAppClientInfo method massageDescriptor.
@Override
protected void massageDescriptor() throws IOException, AnnotationProcessorException {
ApplicationClientDescriptor appClient = getDescriptor();
appClient.setMainClassName(classFileFromCommandLine);
appClient.getModuleDescriptor().setStandalone(true);
FileArchive fa = new FileArchive();
fa.open(new File(classFileFromCommandLine).toURI());
new AppClientArchivist().processAnnotations(appClient, fa);
}
use of com.sun.enterprise.deploy.shared.FileArchive in project Payara by payara.
the class ConnectorsUtil method getInstalledLibrariesFromManifest.
public static List<URI> getInstalledLibrariesFromManifest(String moduleDirectory, ServerEnvironment env) throws ConnectorRuntimeException {
// this method will be called during system-rar creation.
// Though there are code paths that will call this method for creation of rars during recovery / via
// API exposed for GUI, they will not call this method as non-system rars are always started during server startup
// system-rars can specify only EXTENSTION_LIST in MANIFEST.MF and do not have a way to use --libraries option.
// So, satisfying system-rars alone as of now.
List<URI> libURIs = new ArrayList<URI>();
if (moduleDirectory != null) {
try {
File module = new File(moduleDirectory);
if (module.exists()) {
FileArchive fileArchive = new FileArchive();
// directory where rar is exploded
fileArchive.open(module.toURI());
Set<String> extensionList = InstalledLibrariesResolver.getInstalledLibraries(fileArchive);
URL[] extensionListLibraries = ASClassLoaderUtil.getLibrariesAsURLs(extensionList, env);
for (URL url : extensionListLibraries) {
libURIs.add(url.toURI());
if (_logger.isLoggable(Level.FINEST)) {
_logger.log(Level.FINEST, "adding URL [ " + url + " ] to installedLibraries");
}
}
}
} catch (IOException ioe) {
ConnectorRuntimeException cre = new ConnectorRuntimeException(ioe.getMessage());
cre.initCause(ioe);
throw cre;
} catch (URISyntaxException e) {
ConnectorRuntimeException cre = new ConnectorRuntimeException(e.getMessage());
cre.initCause(e);
throw cre;
}
}
return libURIs;
}
use of com.sun.enterprise.deploy.shared.FileArchive in project Payara by payara.
the class WSDLFileCheck method check.
/**
* @param descriptor the WebServices descriptor
* @return <code>Result</code> the results for this assertion
*/
public Result check(WebServiceEndpoint descriptor) {
Result result = getInitializedResult();
ComponentNameConstructor compName = getVerifierContext().getComponentNameConstructor();
// boolean pass = true;
// File f = Verifier.getArchiveFile(descriptor.getBundleDescriptor().
// getModuleDescriptor().getArchiveUri());
// JarFile jarFile = null;
InputStream deploymentEntry = null;
// wsdl file
String wsdlUri = descriptor.getWebService().getWsdlFileUri();
try {
// if (f == null) {
String uri = getAbstractArchiveUri(descriptor);
// try {
FileArchive arch = new FileArchive();
arch.open(uri);
deploymentEntry = arch.getEntry(wsdlUri);
// }
if (deploymentEntry == null) {
// result.fail,
result.addErrorDetails(smh.getLocalString("tests.componentNameConstructor", "For [ {0} ]", new Object[] { compName.toString() }));
result.failed(smh.getLocalString(getClass().getName() + ".failed", "WSDL file does not exist in the archive at uri [{0}].", new Object[] { wsdlUri }));
// pass = false;
} else {
// result.pass
result.addGoodDetails(smh.getLocalString("tests.componentNameConstructor", "For [ {0} ]", new Object[] { compName.toString() }));
result.passed(smh.getLocalString(getClass().getName() + ".passed", "WSDL file exists in the archive at uri [{0}].", new Object[] { wsdlUri }));
}
} catch (Exception e) {
// result.fail
result.addErrorDetails(smh.getLocalString("com.sun.enterprise.tools.verifier.tests.webservices.Error", "Error: Unexpected error occurred [ {0} ]", new Object[] { e.getMessage() }));
// pass = false;
} finally {
try {
if (deploymentEntry != null)
deploymentEntry.close();
} catch (IOException e) {
}
}
return result;
}
Aggregations