Skip to content

Commit

Permalink
PAYARA-1840 RAR detector now checks for all JCA annotations (payara#1790
Browse files Browse the repository at this point in the history
)

* PAYARA-1840 RAR detector now checks for all JCA annotations

All archives are now checked for annotations, regardless of type

* removed some annotations from possible ones to detect

* changed annotations
  • Loading branch information
Cousjava authored and michaelranaldo committed Sep 12, 2017
1 parent 1b54484 commit 09f4339
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 12 deletions.
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("/")) {
// 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

0 comments on commit 09f4339

Please sign in to comment.