Skip to content

Commit

Permalink
Archivists vs. generics
Browse files Browse the repository at this point in the history
Signed-off-by: David Matějček <david.matejcek@omnifish.ee>
  • Loading branch information
dmatej committed Sep 18, 2022
1 parent 45f02a0 commit 585f5ea
Show file tree
Hide file tree
Showing 18 changed files with 216 additions and 129 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -161,25 +161,21 @@ private ReadableArchive createArchive(final ClassLoader loader,
}


private AppClientArchivist getArchivist(final ReadableArchive clientRA,
final ClassLoader classLoader) throws IOException {
private AppClientArchivist getArchivist(final ReadableArchive clientRA, final ClassLoader classLoader)
throws IOException {
if (archivist == null) {
ArchivistFactory af = Util.getArchivistFactory();
/*
* Get the archivist by type rather than by archive to avoid
* having to set the URI to some fake URI that the archivist
* factory would understand.
*/
archivist = completeInit((AppClientArchivist)
af.getArchivist(DOLUtils.carType()));
archivist = af.getArchivist(DOLUtils.carType());
archivist.setAnnotationProcessingRequested(true);
}
return archivist;
}

private AppClientArchivist completeInit(final AppClientArchivist arch) {
arch.setAnnotationProcessingRequested(true);
return arch;
}

@Override
public void validateDescriptor() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ static UndeployedLaunchable newUndeployedLaunchable(
* will often allow an app client or an EAR archive to be detected
* automatically.
*/
Archivist archivist = af.getArchivist("car", classLoader);
Archivist<?> archivist = af.getArchivist("car", classLoader);
if (archivist == null) {
throw new UserError(localStrings.get("appclient.invalidArchive",
ra.getURI().toASCIIString()));
Expand Down Expand Up @@ -268,7 +268,7 @@ private AppClientArchivist completeInit(final AppClientArchivist arch) {
private AppClientArchivist getArchivist(final ClassLoader classLoader) throws IOException {
if (archivist == null) {
ArchivistFactory af = Util.getArchivistFactory();
archivist = completeInit((AppClientArchivist) af.getArchivist("car"));
archivist = completeInit(af.getArchivist("car"));
}
archivist.setClassLoader(classLoader);
return archivist;
Expand Down

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
Expand Up @@ -134,16 +134,16 @@ public List<ConfigurationDeploymentDescriptorFile> getConfigurationDDFiles() {
return confDDFiles;
}


/**
* @return a default BundleDescriptor for this archivist
*/
@Override
public ApplicationClientDescriptor getDefaultBundleDescriptor() {
ApplicationClientDescriptor appClientDesc =
new ApplicationClientDescriptor();
return appClientDesc;
return new ApplicationClientDescriptor();
}


/**
* validates the DOL Objects associated with this archivist, usually
* it requires that a class loader being set on this archivist or passed
Expand Down Expand Up @@ -171,7 +171,7 @@ public void validate(ClassLoader aClassLoader) {
*/
@Override
protected void postStandardDDsRead(ApplicationClientDescriptor descriptor, ReadableArchive archive,
Map<ExtensionsArchivist, RootDeploymentDescriptor> extensions)
Map<ExtensionsArchivist<?>, RootDeploymentDescriptor> extensions)
throws IOException {
super.postStandardDDsRead(descriptor, archive, extensions);
// look for MAIN_CLASS
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
import com.sun.enterprise.deployment.Application;
import com.sun.enterprise.deployment.BundleDescriptor;
import com.sun.enterprise.deployment.EarType;
import com.sun.enterprise.deployment.EjbBundleDescriptor;
import com.sun.enterprise.deployment.WebBundleDescriptor;
import com.sun.enterprise.deployment.annotation.introspection.EjbComponentAnnotationScanner;
import com.sun.enterprise.deployment.io.ApplicationDeploymentDescriptorFile;
Expand Down Expand Up @@ -61,6 +62,8 @@
import org.jvnet.hk2.annotations.Service;
import org.xml.sax.SAXException;

import static com.sun.enterprise.deployment.util.DOLUtils.ejbType;

/**
* This class is responsible for handling application archive files
*
Expand Down Expand Up @@ -108,18 +111,18 @@ protected void writeContents(ReadableArchive in, WritableArchive out) throws IOE
}

// any files already written to the output should never be rewritten
for (Enumeration alreadyWritten = out.entries(); alreadyWritten.hasMoreElements();) {
String elementName = (String) alreadyWritten.nextElement();
for (Enumeration<String> alreadyWritten = out.entries(); alreadyWritten.hasMoreElements();) {
String elementName = alreadyWritten.nextElement();
filesToSkip.add(elementName);
}

// write this application .ear file contents...
for (ModuleDescriptor aModule : descriptor.getModules()) {
Archivist subArchivist = archivistFactory.get().getArchivist(aModule.getModuleType());
for (ModuleDescriptor<BundleDescriptor> aModule : descriptor.getModules()) {
Archivist<BundleDescriptor> subArchivist = archivistFactory.get().getArchivist(aModule.getModuleType());
subArchivist.initializeContext(this);
subArchivist.setModuleDescriptor(aModule);
if (DOLUtils.getDefaultLogger().isLoggable(Level.FINE)) {
DOLUtils.getDefaultLogger().info("Write " + aModule.getArchiveUri() + " with " + subArchivist);
DOLUtils.getDefaultLogger().fine("Write " + aModule.getArchiveUri() + " with " + subArchivist);
}

// Create a new jar file inside the application .ear
Expand Down Expand Up @@ -336,13 +339,13 @@ else if ((!directory && name.endsWith(".rar"))
}

//Section EE.8.4.2.1.d.ii
Archivist ejbArchivist = archivistFactory.get().getArchivist(DOLUtils.ejbType());
Archivist<EjbBundleDescriptor> ejbArchivist = archivistFactory.get().getArchivist(ejbType());
if (ejbArchivist.hasStandardDeploymentDescriptor(subArchive)
|| ejbArchivist.hasRuntimeDeploymentDescriptor(subArchive)) {

ModuleDescriptor<BundleDescriptor> md = new ModuleDescriptor<>();
md.setArchiveUri(uri);
md.setModuleType(DOLUtils.ejbType());
md.setModuleType(ejbType());
app.addModule(md);
continue;
}
Expand Down Expand Up @@ -381,7 +384,7 @@ else if ((!directory && name.endsWith(".rar"))
//Section EE.8.4.2.1.d.ii, alas EJB
ModuleDescriptor<BundleDescriptor> md = new ModuleDescriptor<>();
md.setArchiveUri(uri);
md.setModuleType(DOLUtils.ejbType());
md.setModuleType(ejbType());
app.addModule(md);
}
/*
Expand Down Expand Up @@ -522,27 +525,23 @@ public boolean accept(File dir, String name) {
* @param appArchive containing the sub modules files.
* @return true if everything went fine
*/
public boolean readModulesDescriptors(Application app, ReadableArchive appArchive)
public <T extends BundleDescriptor> boolean readModulesDescriptors(Application app, ReadableArchive appArchive)
throws IOException, SAXException {
List<ModuleDescriptor> nonexistentModules = new ArrayList<>();

List<ModuleDescriptor> sortedModules = sortModules(app);

for (ModuleDescriptor aModule : sortedModules) {
List<ModuleDescriptor<BundleDescriptor>> nonexistentModules = new ArrayList<>();
List<ModuleDescriptor<BundleDescriptor>> sortedModules = sortModules(app);
for (ModuleDescriptor<BundleDescriptor> aModule : sortedModules) {
if (aModule.getArchiveUri().contains(" ")) {
throw new IllegalArgumentException(localStrings.getLocalString("enterprise.deployment.unsupporturi",
"Unsupported module URI {0}, it contains space(s)", new Object[] {aModule.getArchiveUri()}));
}
if (DOLUtils.getDefaultLogger().isLoggable(Level.FINE)) {
DOLUtils.getDefaultLogger().fine("Opening sub-module " + aModule);
}
Archivist newArchivist = archivistFactory.get().getArchivist(aModule.getModuleType());
DOLUtils.getDefaultLogger().log(Level.FINE, "Opening sub-module {0}", aModule);
Archivist<T> newArchivist = archivistFactory.get().getArchivist(aModule.getModuleType());
newArchivist.initializeContext(this);
newArchivist.setRuntimeXMLValidation(this.getRuntimeXMLValidation());
newArchivist.setRuntimeXMLValidationLevel(this.getRuntimeXMLValidationLevel());
newArchivist.setAnnotationProcessingRequested(annotationProcessingRequested);

BundleDescriptor bundleDescriptor = null;
T bundleDescriptor = null;
try (ReadableArchive embeddedArchive = appArchive.getSubArchive(aModule.getArchiveUri())) {
if (embeddedArchive == null) {
throw new IllegalArgumentException(localStrings.getLocalString("enterprise.deployment.nosuchmodule",
Expand All @@ -564,20 +563,18 @@ public boolean readModulesDescriptors(Application app, ReadableArchive appArchiv
if (appArchive.getURI() != null) {
ddFile.setErrorReportingString(appArchive.getURI().getSchemeSpecificPart());
}
bundleDescriptor = (BundleDescriptor) ddFile.read(is);
bundleDescriptor = (T) ddFile.read(is);
bundleDescriptor.setApplication(app);
}

// TODO : JD need to be revisited for EAR files with Alternative descriptors,
// what does it mean for sub components.
Map<ExtensionsArchivist, RootDeploymentDescriptor> extensions = new HashMap<>();
List<ExtensionsArchivist> extensionsArchivists = newArchivist.getExtensionArchivists();
Map<ExtensionsArchivist<?>, RootDeploymentDescriptor> extensions = new HashMap<>();
List<ExtensionsArchivist<?>> extensionsArchivists = newArchivist.getExtensionArchivists();
if (extensionsArchivists != null) {
for (ExtensionsArchivist extension : extensionsArchivists) {
Object rdd = extension.open(newArchivist, embeddedArchive, bundleDescriptor);
if (rdd instanceof RootDeploymentDescriptor) {
extensions.put(extension, (RootDeploymentDescriptor) rdd);
}
for (ExtensionsArchivist<?> extension : extensionsArchivists) {
RootDeploymentDescriptor rdd = extension.open(newArchivist, embeddedArchive, bundleDescriptor);
extensions.put(extension, rdd);
}
}
newArchivist.postStandardDDsRead(bundleDescriptor, embeddedArchive, extensions);
Expand All @@ -589,7 +586,7 @@ public boolean readModulesDescriptors(Application app, ReadableArchive appArchiv
DOLUtils.readAlternativeRuntimeDescriptor(appArchive, embeddedArchive, newArchivist, bundleDescriptor,
aModule.getAlternateDescriptor());
// read extensions runtime deployment descriptors if any
for (Map.Entry<ExtensionsArchivist, RootDeploymentDescriptor> extension : extensions.entrySet()) {
for (Map.Entry<ExtensionsArchivist<?>, RootDeploymentDescriptor> extension : extensions.entrySet()) {
// after standard DD and annotations are processed
// we should have an extension descriptor now
if (extension.getValue() != null) {
Expand Down Expand Up @@ -624,16 +621,16 @@ public boolean readModulesDescriptors(Application app, ReadableArchive appArchiv
}
// now remove all the non-existent modules from app so these modules
// don't get processed further
for (ModuleDescriptor nonexistentModule : nonexistentModules) {
for (ModuleDescriptor<BundleDescriptor> nonexistentModule : nonexistentModules) {
app.removeModule(nonexistentModule);
}
return true;
}

private List<ModuleDescriptor> sortModules(Application app) {
List<ModuleDescriptor> sortedModules = new ArrayList<>();
private List<ModuleDescriptor<BundleDescriptor>> sortModules(Application app) {
List<ModuleDescriptor<BundleDescriptor>> sortedModules = new ArrayList<>();
sortedModules.addAll(app.getModuleDescriptorsByType(DOLUtils.rarType()));
sortedModules.addAll(app.getModuleDescriptorsByType(DOLUtils.ejbType()));
sortedModules.addAll(app.getModuleDescriptorsByType(ejbType()));
sortedModules.addAll(app.getModuleDescriptorsByType(DOLUtils.warType()));
sortedModules.addAll(app.getModuleDescriptorsByType(DOLUtils.carType()));
return sortedModules;
Expand All @@ -655,17 +652,17 @@ public void readRuntimeDeploymentDescriptor(ReadableArchive archive, Application

if (descriptor != null) {
// each modules first...
for (ModuleDescriptor md : descriptor.getModules()) {
Archivist archivist = archivistFactory.get().getArchivist(md.getModuleType());
for (ModuleDescriptor<BundleDescriptor> md : descriptor.getModules()) {
Archivist<BundleDescriptor> archivist = archivistFactory.get().getArchivist(md.getModuleType());
archivist.initializeContext(this);
archivist.setRuntimeXMLValidation(this.getRuntimeXMLValidation());
archivist.setRuntimeXMLValidationLevel(this.getRuntimeXMLValidationLevel());
try (ReadableArchive subArchive = archive.getSubArchive(md.getArchiveUri())) {
if (md.getAlternateDescriptor() == null) {
archivist.readRuntimeDeploymentDescriptor(subArchive, (BundleDescriptor) md.getDescriptor());
archivist.readRuntimeDeploymentDescriptor(subArchive, md.getDescriptor());
} else {
DOLUtils.readAlternativeRuntimeDescriptor(archive, subArchive, archivist,
(BundleDescriptor) md.getDescriptor(), md.getAlternateDescriptor());
md.getDescriptor(), md.getAlternateDescriptor());
}
}
}
Expand Down Expand Up @@ -734,10 +731,10 @@ public boolean performOptionalPkgDependenciesCheck(ReadableArchive archive) thro
}

boolean returnValue = true;
for (ModuleDescriptor md : descriptor.getModules()) {
for (ModuleDescriptor<BundleDescriptor> md : descriptor.getModules()) {
try (ReadableArchive sub = archive.getSubArchive(md.getArchiveUri())) {
if (sub != null) {
Archivist subArchivist = archivistFactory.get().getArchivist(md.getModuleType());
Archivist<?> subArchivist = archivistFactory.get().getArchivist(md.getModuleType());
if (!subArchivist.performOptionalPkgDependenciesCheck(sub)) {
returnValue = false;
}
Expand Down Expand Up @@ -782,11 +779,11 @@ public void copyInto(Application a, ReadableArchive source, WritableArchive targ
public void copyInto(Application a, ReadableArchive source, WritableArchive target, boolean overwriteManifest)
throws IOException {
Set<String> entriesToSkip = new HashSet<>();
for (ModuleDescriptor aModule : a.getModules()) {
for (ModuleDescriptor<?> aModule : a.getModules()) {
entriesToSkip.add(aModule.getArchiveUri());
try (ReadableArchive subSource = source.getSubArchive(aModule.getArchiveUri())) {
WritableArchive subTarget = target.createSubArchive(aModule.getArchiveUri());
Archivist newArchivist = archivistFactory.get().getArchivist(aModule.getModuleType());
Archivist<?> newArchivist = archivistFactory.get().getArchivist(aModule.getModuleType());
try (ReadableArchive subArchive = archiveFactory.openArchive(subTarget.getURI())) {
subSource.setParentArchive(subArchive);
newArchivist.copyInto(subSource, subTarget, overwriteManifest);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -345,7 +345,7 @@ public T open(File file) throws IOException, SAXException {
* @param extensions map of extension archivists
*/
protected void postStandardDDsRead(T descriptor, ReadableArchive archive,
Map<ExtensionsArchivist, RootDeploymentDescriptor> extensions) throws IOException {
Map<ExtensionsArchivist<?>, RootDeploymentDescriptor> extensions) throws IOException {
}


Expand Down Expand Up @@ -400,9 +400,9 @@ private T readDeploymentDescriptors(ReadableArchive descriptorArchive,

private T readRestDeploymentDescriptors(T descriptor, ReadableArchive descriptorArchive,
ReadableArchive contentArchive, Application app) throws IOException, SAXException {
Map<ExtensionsArchivist, RootDeploymentDescriptor> extensions = new HashMap<>();
Map<ExtensionsArchivist<?>, RootDeploymentDescriptor> extensions = new HashMap<>();
if (extensionsArchivists != null) {
for (ExtensionsArchivist extension : extensionsArchivists) {
for (ExtensionsArchivist<?> extension : extensionsArchivists) {
Object o = extension.open(this, descriptorArchive, descriptor);
if (o instanceof RootDeploymentDescriptor) {
if (o != descriptor) {
Expand All @@ -426,7 +426,7 @@ private T readRestDeploymentDescriptors(T descriptor, ReadableArchive descriptor
readRuntimeDeploymentDescriptor(descriptorArchive, descriptor);

// read extensions runtime deployment descriptors if any
for (Map.Entry<ExtensionsArchivist, RootDeploymentDescriptor> extension : extensions.entrySet()) {
for (Map.Entry<ExtensionsArchivist<?>, RootDeploymentDescriptor> extension : extensions.entrySet()) {
// after standard DD and annotations are processed, we should
// an extension descriptor now
if (extension.getValue() != null) {
Expand All @@ -444,13 +444,13 @@ private T readRestDeploymentDescriptors(T descriptor, ReadableArchive descriptor
* Read all Jakarta EE annotations
*/
protected void readAnnotations(ReadableArchive archive, T descriptor,
Map<ExtensionsArchivist, RootDeploymentDescriptor> extensions) throws IOException {
Map<ExtensionsArchivist<?>, RootDeploymentDescriptor> extensions) throws IOException {
readAnnotations(archive, descriptor, extensions, null);
}


protected void readAnnotations(ReadableArchive archive, T descriptor,
Map<ExtensionsArchivist, RootDeploymentDescriptor> extensions, ModuleScanner scanner) throws IOException {
Map<ExtensionsArchivist<?>, RootDeploymentDescriptor> extensions, ModuleScanner scanner) throws IOException {
try {
boolean processAnnotationForMainDescriptor = isProcessAnnotation(descriptor);
ProcessingResult result = null;
Expand All @@ -463,7 +463,7 @@ protected void readAnnotations(ReadableArchive archive, T descriptor,
}

// process extensions annotations if any
for (Map.Entry<ExtensionsArchivist, RootDeploymentDescriptor> extension : extensions.entrySet()) {
for (Map.Entry<ExtensionsArchivist<?>, RootDeploymentDescriptor> extension : extensions.entrySet()) {
try {
if (extension.getValue() == null) {
// extension descriptor is not present
Expand Down

0 comments on commit 585f5ea

Please sign in to comment.