Skip to content
This repository was archived by the owner on Nov 15, 2022. It is now read-only.

Commit ff4c148

Browse files
honghzzhangyaminikb
authored andcommitted
Fixes #22098: metadata-complete attribute handling in deployment (#22099)
* Write the metadata-complete with its true value for the application client. With the current set of the changes, the @ManagedMBean annotation will be processed regardless of the metadata-complete attribute value. This will allow the application client container to process the right set of the annotations. * Update the dev test to use the new API to get annotation processor. * When web.xml specifies metadata-complete=true, the web fragments inside this war should have metadata-complete set to true also to allow annotation processing happen as expected. * Update logic to handle EJB in war case: when extension deployment descriptor is not present in the archive, set the metadata-complete attribute of the extension descriptor using the main descriptor so the annotation processing can happen as expected. Clean up on the javadoc comments also. * Fix FindBug issue.
1 parent cc5339a commit ff4c148

File tree

10 files changed

+88
-39
lines changed

10 files changed

+88
-39
lines changed

appserver/deployment/dol/src/main/java/com/sun/enterprise/deployment/BundleDescriptor.java

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1020,18 +1020,14 @@ public boolean isFullAttribute() {
10201020

10211021
/**
10221022
* @ return true for following cases:
1023-
* 1. When the full attribute is true. This attribute only applies to
1024-
* ejb module with schema version equal or later than 3.0;
1025-
web module and schema version equal or later than than 2.5;
1026-
appclient module and schema version equal or later than 5.0.
1027-
* 2. When it's been tagged as "full" when processing annotations.
1028-
* 3. When DD has a version which doesn't allowed annotations.
1023+
* 1. When it's been tagged as "full" when processing annotations.
1024+
* 2. When DD has a version which doesn't allowed annotations.
10291025
* return false otherwise.
10301026
*/
10311027
public boolean isFullFlag() {
1032-
// if the full attribute is true or it's been tagged as full,
1028+
// if it's been tagged as full,
10331029
// return true
1034-
if (fullAttribute == true || fullFlag == true) {
1030+
if (fullFlag == true) {
10351031
return true;
10361032
}
10371033
return isDDWithNoAnnotationAllowed();

appserver/deployment/dol/src/main/java/com/sun/enterprise/deployment/annotation/factory/SJSASFactory.java

Lines changed: 34 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -76,19 +76,33 @@ public class SJSASFactory extends Factory {
7676
private ServiceLocator locator;
7777

7878
private Set<String> annotationClassNames = new HashSet<String>();
79+
private Set<String> annotationClassNamesMetaDataComplete = new HashSet<String>();
7980

81+
// we have two system processors to process annotations:
82+
// one to process all JavaEE annotations when metadata-complete is false,
83+
// another to process a subset of JavaEE annotations when
84+
// metadata-complete is true
8085
private AnnotationProcessorImpl systemProcessor=null;
86+
private AnnotationProcessorImpl systemProcessorMetaDataComplete=null;
8187

82-
public AnnotationProcessor getAnnotationProcessor() {
88+
public AnnotationProcessor getAnnotationProcessor(boolean isMetaDataComplete) {
8389
AnnotationProcessorImpl processor =
8490
Factory.getDefaultAnnotationProcessor();
85-
processor.setDelegate(systemProcessor);
91+
if (!isMetaDataComplete) {
92+
processor.setDelegate(systemProcessor);
93+
} else {
94+
processor.setDelegate(systemProcessorMetaDataComplete);
95+
}
8696
return processor;
8797
}
8898

8999
@SuppressWarnings("unchecked")
90-
public Set<String> getAnnotations() {
91-
return (HashSet<String>)((HashSet<String>)annotationClassNames).clone();
100+
public Set<String> getAnnotations(boolean isMetaDataComplete) {
101+
if (!isMetaDataComplete) {
102+
return (HashSet<String>)((HashSet<String>)annotationClassNames).clone();
103+
} else {
104+
return (HashSet<String>)((HashSet<String>)annotationClassNamesMetaDataComplete).clone();
105+
}
92106
}
93107

94108
private static String getAnnotationHandlerForStringValue(ActiveDescriptor<AnnotationHandler> onMe) {
@@ -102,24 +116,36 @@ private static String getAnnotationHandlerForStringValue(ActiveDescriptor<Annota
102116
@SuppressWarnings({ "unused", "unchecked" })
103117
@PostConstruct
104118
private void postConstruct() {
105-
if (systemProcessor != null) return;
119+
if (systemProcessor != null &&
120+
systemProcessorMetaDataComplete != null) return;
106121

107122
// initialize our system annotation processor...
108123
systemProcessor = new AnnotationProcessorImpl();
124+
systemProcessorMetaDataComplete = new AnnotationProcessorImpl();
109125
for (ActiveDescriptor<?> i : locator.getDescriptors(BuilderHelper.createContractFilter(
110126
AnnotationHandler.class.getName()))) {
111127
ActiveDescriptor<AnnotationHandler> descriptor = (ActiveDescriptor<AnnotationHandler>) i;
112128

113129
String annotationTypeName = getAnnotationHandlerForStringValue(descriptor);
114130
if (annotationTypeName == null) continue;
115-
131+
116132
systemProcessor.pushAnnotationHandler(annotationTypeName, new LazyAnnotationHandler(descriptor));
117133
annotationClassNames.add("L" +
134+
annotationTypeName.
135+
replace('.', '/') + ";");
136+
137+
// In the current set of the annotations processed by the
138+
// deployment layer, the only annotation that should be
139+
// processed even when metadata-complete atribute value is true
140+
// is javax.annotation.ManagedBean. If there are more annotations
141+
// falling in this category in the future, add them to this list
142+
if (annotationTypeName.equals("javax.annotation.ManagedBean")) {
143+
systemProcessorMetaDataComplete.pushAnnotationHandler(annotationTypeName, new LazyAnnotationHandler(descriptor));
144+
annotationClassNamesMetaDataComplete.add("L" +
118145
annotationTypeName.
119146
replace('.', '/') + ";");
147+
}
120148
}
121-
122-
123149
}
124150

125151
private class LazyAnnotationHandler implements AnnotationHandler {

appserver/deployment/dol/src/main/java/com/sun/enterprise/deployment/annotation/impl/AppClientScanner.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,7 @@ public void process(ReadableArchive archive, ApplicationClientDescriptor bundleD
8080
setParser(parser);
8181
doProcess(archive, bundleDesc, classLoader);
8282
completeProcess(bundleDesc, archive);
83-
calculateResults();
83+
calculateResults(bundleDesc);
8484
}
8585

8686
public void process(File archiveFile, ApplicationClientDescriptor bundleDesc, ClassLoader classLoader) throws IOException {

appserver/deployment/dol/src/main/java/com/sun/enterprise/deployment/annotation/impl/ModuleScanner.java

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -132,7 +132,7 @@ public void process(ReadableArchive archiveFile,
132132
setParser(parser);
133133
process(file, bundleDesc, classLoader);
134134
completeProcess(bundleDesc, archiveFile);
135-
calculateResults();
135+
calculateResults(bundleDesc);
136136
}
137137

138138
/**
@@ -150,7 +150,7 @@ protected void completeProcess(T bundleDescr, ReadableArchive archive) throws IO
150150
addLibraryJars(bundleDescr, archive);
151151
}
152152

153-
protected void calculateResults() {
153+
protected void calculateResults(T bundleDesc) {
154154
try {
155155
classParser.awaitTermination();
156156
} catch (InterruptedException e) {
@@ -162,7 +162,12 @@ protected void calculateResults() {
162162
Level logLevel = (System.getProperty("glassfish.deployment.dump.scanning")!=null?Level.INFO:Level.FINE);
163163
boolean shouldLog = deplLogger.isLoggable(logLevel);
164164
ParsingContext context = classParser.getContext();
165-
for (String annotation: defaultScanner.getAnnotations()) {
165+
boolean isFullAttribute = false;
166+
if (bundleDesc instanceof BundleDescriptor) {
167+
isFullAttribute = ((BundleDescriptor)bundleDesc).isFullAttribute();
168+
}
169+
Set<String> annotationsToProcess = defaultScanner.getAnnotations(isFullAttribute);
170+
for (String annotation: annotationsToProcess) {
166171
Type type = context.getTypes().getBy(annotation);
167172

168173
// we never found anyone using that type

appserver/deployment/dol/src/main/java/com/sun/enterprise/deployment/annotation/introspection/DefaultAnnotationScanner.java

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,7 @@ public class DefaultAnnotationScanner implements AnnotationScanner,
6565
SJSASFactory factory;
6666

6767
private Set<String> annotations=null;
68+
private Set<String> annotationsMetaDataComplete=null;
6869

6970
/**
7071
* Test if the passed constant pool string is a reference to
@@ -78,11 +79,20 @@ public boolean isAnnotation(String value) {
7879
}
7980

8081
public void postConstruct() {
81-
annotations = factory.getAnnotations();
82+
annotations = factory.getAnnotations(false);
83+
annotationsMetaDataComplete = factory.getAnnotations(true);
84+
}
85+
86+
public Set<String> getAnnotations(boolean isMetaDataComplete) {
87+
if (!isMetaDataComplete) {
88+
return AbstractAnnotationScanner.constantPoolToFQCN(annotations);
89+
} else {
90+
return AbstractAnnotationScanner.constantPoolToFQCN(annotationsMetaDataComplete);
91+
}
8292
}
8393

8494
@Override
8595
public Set<String> getAnnotations() {
86-
return AbstractAnnotationScanner.constantPoolToFQCN(annotations);
96+
return getAnnotations(false);
8797
}
8898
}

appserver/deployment/dol/src/main/java/com/sun/enterprise/deployment/archivist/Archivist.java

Lines changed: 18 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -474,6 +474,14 @@ protected void readAnnotations(ReadableArchive archive, T descriptor,
474474
RootDeploymentDescriptor o = extension.getKey().getDefaultDescriptor();
475475
if( o != null ) {
476476
o.setModuleDescriptor(descriptor.getModuleDescriptor());
477+
// for the case of extension descriptor not
478+
// present, set the metadata-complete attribute
479+
// value of the extension descriptor using the
480+
// metadata-complete value of main descriptor
481+
if (o instanceof BundleDescriptor) {
482+
boolean isFullMain = descriptor.isFullAttribute();
483+
((BundleDescriptor)o).setFullAttribute(String.valueOf(isFullMain));
484+
}
477485
}
478486
processAnnotations(o, extension.getKey().getScanner(), archive);
479487
if (o!=null && !o.isEmpty()) {
@@ -600,7 +608,12 @@ protected ProcessingResult processAnnotations(RootDeploymentDescriptor bundleDes
600608
"{0} in archive {1} is of version {2}, which cannot support annotations in an application. Please upgrade the deployment descriptor to be a version supported by Java EE 5.0 (or later).",
601609
new Object[]{ddName, archiveName, bundleDesc.getSpecVersion()}));
602610
}
603-
AnnotationProcessor ap = annotationFactory.getAnnotationProcessor();
611+
boolean isFullAttribute = false;
612+
if (bundleDesc instanceof BundleDescriptor) {
613+
isFullAttribute = ((BundleDescriptor)bundleDesc).isFullAttribute();
614+
}
615+
616+
AnnotationProcessor ap = annotationFactory.getAnnotationProcessor(isFullAttribute);
604617
ProcessingContext ctx = ap.createContext();
605618
ctx.setArchive(archive);
606619
if (annotationErrorHandler != null) {
@@ -1677,19 +1690,15 @@ public Object readMetaInfo(ReadableArchive archive) {
16771690
}
16781691

16791692
protected boolean isProcessAnnotation(BundleDescriptor descriptor) {
1680-
// if the system property is set to process annotation for pre-JavaEE5
1681-
// DD, the semantics of isFull flag is: full attribute is set to
1682-
// true in DD. Otherwise the semantics is full attribute set to
1683-
// true or it is pre-JavaEE5 DD.
1693+
// if the system property is set to not process annotation for
1694+
// pre-JavaEE5 DD, check whether the current DD is a pre-JavaEE5 DD.
16841695
boolean isFull = false;
1685-
if (processAnnotationForOldDD) {
1686-
isFull = descriptor.isFullAttribute();
1687-
} else {
1696+
if (!processAnnotationForOldDD) {
16881697
isFull = descriptor.isFullFlag();
16891698
}
16901699

16911700
// only process annotation when these two requirements satisfied:
1692-
// 1. It is not a full deployment descriptor
1701+
// 1. This version of DD should be processed for annotation
16931702
// 2. It is called through dynamic deployment
16941703
return (!isFull && annotationProcessingRequested && classLoader != null);
16951704
}

appserver/deployment/dol/src/main/java/com/sun/enterprise/deployment/node/AbstractBundleNode.java

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -217,11 +217,7 @@ protected void addBundleNodeAttributes(Element bundleNode, RootDeploymentDescrip
217217
BundleDescriptor bundleDesc = (BundleDescriptor)descriptor;
218218
// In the common case that metadata-complete isn't already set to
219219
// true, set it to true.
220-
// The exception is if the module contains managed beans, which
221-
// can only be processed as annotations in the appclient client
222-
// container runtime.
223-
if (! bundleDesc.isDDWithNoAnnotationAllowed() &&
224-
! (bundleDesc.getManagedBeans().size() > 0) ) {
220+
if (! bundleDesc.isDDWithNoAnnotationAllowed()) {
225221
bundleNode.setAttribute(TagNames.METADATA_COMPLETE, "true");
226222
}
227223
}

appserver/tests/appserv-tests/devtests/deployment/util/devtests/deployment/util/StandaloneProcessor.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -205,7 +205,7 @@ public int run(String[] args) throws Exception {
205205

206206
}
207207

208-
AnnotationProcessor ap = serviceLocator.<SJSASFactory>getService(SJSASFactory.class).getAnnotationProcessor();
208+
AnnotationProcessor ap = serviceLocator.<SJSASFactory>getService(SJSASFactory.class).getAnnotationProcessor(false);
209209

210210

211211
// if the user indicated a directory for handlers, time to add the

appserver/web/web-glue/src/main/java/org/glassfish/web/deployment/annotation/impl/WarScanner.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -117,7 +117,7 @@ public void process(ReadableArchive readableArchive, WebBundleDescriptor webBund
117117

118118
if (isScanOtherLibraries()) {
119119
addLibraryJars(webBundleDesc, readableArchive);
120-
calculateResults();
120+
calculateResults(webBundleDesc);
121121
return;
122122
}
123123

@@ -144,7 +144,7 @@ public void process(ReadableArchive readableArchive, WebBundleDescriptor webBund
144144
}
145145
scanXmlDefinedClassesIfNecessary(webBundleDesc);
146146
}
147-
calculateResults();
147+
calculateResults(webBundleDesc);
148148
}
149149

150150
// This is not mandated by the spec. It is for WSIT.

appserver/web/web-glue/src/main/java/org/glassfish/web/deployment/archivist/WebArchivist.java

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -330,6 +330,13 @@ protected void postAnnotationProcess(WebBundleDescriptorImpl descriptor,
330330
Map<ExtensionsArchivist, RootDeploymentDescriptor> localExtensions =
331331
new HashMap<ExtensionsArchivist, RootDeploymentDescriptor>();
332332
for (WebFragmentDescriptor wfDesc : wfList) {
333+
// if web.xml specifies metadata-complete=true,
334+
// all web fragment metadata-complete
335+
// should be overridden and be true also
336+
if (descriptor.isFullAttribute()) {
337+
wfDesc.setFullAttribute(
338+
String.valueOf(descriptor.isFullAttribute()));
339+
}
333340
super.readAnnotations(archive, wfDesc, localExtensions);
334341
}
335342

0 commit comments

Comments
 (0)