Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

PAYARA-1840 RAR detector now checks for all JCA annotations #1790

Merged
merged 3 commits into from Sep 8, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
Expand Up @@ -36,17 +36,17 @@
* and therefore, elected the GPL Version 2 license, then the option applies
* only if the new code is made subject to such option by the copyright
* holder.
*
* Portions Copyright [2017] Payara Foundation and/or affiliates
*/


package com.sun.enterprise.connectors.connector.module;

import com.sun.enterprise.deploy.shared.FileArchive;
import org.glassfish.api.deployment.archive.ArchiveDetector;
import org.glassfish.api.deployment.archive.ArchiveHandler;
import org.glassfish.api.deployment.archive.ArchiveType;
import org.glassfish.api.deployment.archive.ReadableArchive;
import org.glassfish.deployment.common.DeploymentUtils;
import com.sun.enterprise.deployment.deploy.shared.Util;
import org.glassfish.deployment.common.GenericAnnotationDetector;

Expand All @@ -69,8 +69,16 @@
@Service(name = RarDetector.ARCHIVE_TYPE)
@Singleton
public class RarDetector implements ArchiveDetector {

/**
* Connector annotations for JCA 1.7
*/
private static final Class[] connectorAnnotations = new Class[]{
javax.resource.spi.Connector.class};
javax.resource.spi.Connector.class,
javax.resource.spi.Activation.class,
javax.resource.spi.ConnectionDefinition.class,
javax.resource.spi.ConnectionDefinitions.class,
};

public static final String RAR_DETECTOR_RANK_PROP = "glassfish.rar.detector.rank";
public static final int DEFAULT_RAR_DETECTOR_RANK = 300;
Expand Down Expand Up @@ -115,6 +123,7 @@ public ArchiveType getArchiveType() {
/**
* {@inheritDoc}
*/
@Override
public boolean handles(ReadableArchive archive) throws IOException {
boolean handles = false;
try{
Expand All @@ -126,7 +135,7 @@ public boolean handles(ReadableArchive archive) throws IOException {
}catch(IOException ioe){
//ignore
}
if (!handles && (archive instanceof FileArchive)) {
if (!handles) {
GenericAnnotationDetector detector =
new GenericAnnotationDetector(connectorAnnotations);
handles = detector.hasAnnotationInArchive(archive);
Expand Down
Expand Up @@ -37,7 +37,7 @@
* only if the new code is made subject to such option by the copyright
* holder.
*/
//Portions Copyright [2016] [Payara Foundation]
//Portions Copyright [2016-2017] [Payara Foundation]
package org.glassfish.deployment.common;


Expand Down Expand Up @@ -124,6 +124,7 @@ public boolean hasAnnotationInArchive(ReadableArchive archive) {
return found;
}

@Override
public AnnotationVisitor visitAnnotation(String s, boolean b) {
if (annotations.contains(s)) {
found = true;
Expand Down Expand Up @@ -151,8 +152,7 @@ public void scanArchive(ReadableArchive archive) {
} finally {
is.close();
}
} else if (entryName.endsWith(".jar") &&
entryName.indexOf('/') == -1) {
} else if (!entryName.contains("/")) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why has this changed? It looks like it may produce side effects.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

because otherwise it will not scan non-jars for annotations. The code below it is in a try statement anyway so any problems will be caught.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Side effect when calling jarSubArchive.entries().

com.sun.enterprise.deployment.deploy.shared.InputJarArchive#entries(boolean) does not throw an IOException but a RuntimeException. The effect is the exception is not catch by the inner try-catch bloc but the outer one, skipping all other entries in the archive.

// scan class files inside top level jar
try {
ReadableArchive jarSubArchive = null;
Expand All @@ -163,16 +163,12 @@ public void scanArchive(ReadableArchive archive) {
while (jarEntries.hasMoreElements()) {
String jarEntryName = jarEntries.nextElement();
if (jarEntryName.endsWith(".class")) {
InputStream is =
jarSubArchive.getEntry(jarEntryName);
try {
try (InputStream is = jarSubArchive.getEntry(jarEntryName)) {
ClassReader cr = new ClassReader(is);
cr.accept(this, crFlags);
if (found) {
return;
}
} finally {
is.close();
}
}
}
Expand Down