Skip to content

Commit

Permalink
Reducing complexity of annotation-framework + dol
Browse files Browse the repository at this point in the history
- removed dead code (part of)
- generics
- formatting
- using correct loggers (apf used global, dol sometimes used apf)
- it will take more iterations, but this state passed ql-all, webservices tests
- I am still quite unhappy as some classes use fields as local variables, even
  fields in injected services with unknown context (to me).

Signed-off-by: David Matějček <david.matejcek@omnifish.ee>
  • Loading branch information
dmatej committed Sep 18, 2022
1 parent 27ed3ff commit 21870ec
Show file tree
Hide file tree
Showing 51 changed files with 907 additions and 1,618 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -55,19 +55,11 @@
@Service
public abstract class AppClientInfo {

public static final String USER_CODE_IS_SIGNED_PROPERTYNAME = "com.sun.aas.user.code.signed";

private static final String SIGNED_USER_CODE_PERMISSION_TEMPLATE_NAME = "jwsclientSigned.policy";

private static final String UNSIGNED_USER_CODE_PERMISSION_TEMPLATE_NAME = "jwsclientUnsigned.policy";

private static final String CODE_BASE_PLACEHOLDER_NAME = "com.sun.aas.jws.client.codeBase";

/** access to the localizable strings */
private static final LocalStringManager localStrings = new LocalStringManagerImpl(AppClientInfo.class);
private static final LocalStringManager I18N = new LocalStringManagerImpl(AppClientInfo.class);

// for debug purpose
protected static final boolean _keepExplodedDir = Boolean.getBoolean("appclient.keep.exploded.dir");
private static final boolean KEEP_EXPLODED_DIR = Boolean.getBoolean("appclient.keep.exploded.dir");

/** logger */
protected Logger _logger;
Expand Down Expand Up @@ -131,13 +123,12 @@ protected void close() throws IOException {

}
protected boolean deleteAppClientDir() {
return !_keepExplodedDir;
return !KEEP_EXPLODED_DIR;
}

protected String getLocalString(final String key, final String defaultMessage,
final Object... args) {
String result = localStrings.getLocalString(this.getClass(),
key, defaultMessage, args);

protected String getLocalString(final String key, final String defaultMessage, final Object... args) {
String result = I18N.getLocalString(this.getClass(), key, defaultMessage, args);
return result;
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
/*
* Copyright (c) 2022 Contributors to the Eclipse Foundation
* Copyright (c) 1997, 2018 Oracle and/or its affiliates. All rights reserved.
*
* This program and the accompanying materials are made available under the
Expand All @@ -17,11 +18,12 @@
package org.glassfish.appclient.client.acc;

import com.sun.enterprise.deployment.Application;
import com.sun.enterprise.deployment.util.DOLUtils;
import com.sun.enterprise.deployment.ApplicationClientDescriptor;
import com.sun.enterprise.deployment.archivist.AppClientArchivist;
import com.sun.enterprise.deployment.archivist.ArchivistFactory;
import com.sun.enterprise.deployment.deploy.shared.MemoryMappedArchive;
import com.sun.enterprise.deployment.util.DOLUtils;

import java.io.ByteArrayOutputStream;
import java.io.IOException;
import java.io.InputStream;
Expand All @@ -33,6 +35,7 @@
import java.util.jar.JarOutputStream;
import java.util.jar.Manifest;
import java.util.zip.ZipEntry;

import org.glassfish.api.deployment.archive.ReadableArchive;
import org.glassfish.hk2.api.ServiceLocator;
import org.xml.sax.SAXException;
Expand All @@ -44,23 +47,24 @@
*
* @author tjquinn
*/
public class
MainClassLaunchable implements Launchable {
public class MainClassLaunchable implements Launchable {

private final Class mainClass;
private ApplicationClientDescriptor acDesc = null;
private ClassLoader classLoader = null;
private AppClientArchivist archivist = null;
private final Class<?> mainClass;
private ApplicationClientDescriptor acDesc;
private ClassLoader classLoader;
private AppClientArchivist archivist;

MainClassLaunchable(final ServiceLocator habitat, final Class mainClass) {
super();
this.mainClass = mainClass;
}

public Class getMainClass() throws ClassNotFoundException {
@Override
public Class<?> getMainClass() throws ClassNotFoundException {
return mainClass;
}

@Override
public ApplicationClientDescriptor getDescriptor(final URLClassLoader loader) throws IOException, SAXException {
/*
* There is no developer-provided descriptor possible so just
Expand Down Expand Up @@ -177,14 +181,17 @@ private AppClientArchivist completeInit(final AppClientArchivist arch) {
return arch;
}

@Override
public void validateDescriptor() {
archivist.validate(classLoader);
}

@Override
public URI getURI() {
return null;
}

@Override
public String getAnchorDir() {
return null;
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
/*
* Copyright (c) 2022 Contributors to the Eclipse Foundation
* Copyright (c) 1997, 2018 Oracle and/or its affiliates. All rights reserved.
*
* This program and the accompanying materials are made available under the
Expand All @@ -24,18 +25,19 @@
import com.sun.enterprise.deployment.archivist.Archivist;
import com.sun.enterprise.deployment.archivist.ArchivistFactory;
import com.sun.enterprise.deployment.util.DOLUtils;
import org.glassfish.api.deployment.archive.ArchiveType;
import org.glassfish.deployment.common.ModuleDescriptor;

import com.sun.enterprise.universal.i18n.LocalStringsImpl;

import java.io.IOException;
import java.net.URI;
import java.net.URLClassLoader;
import java.security.AccessController;
import java.security.PrivilegedAction;
import java.util.jar.Attributes;
import java.util.jar.Manifest;

import org.glassfish.api.deployment.archive.ArchiveType;
import org.glassfish.api.deployment.archive.ReadableArchive;
import org.glassfish.deployment.common.ModuleDescriptor;
import org.glassfish.deployment.common.RootDeploymentDescriptor;
import org.glassfish.hk2.api.ServiceLocator;
import org.xml.sax.SAXException;
Expand All @@ -51,13 +53,13 @@ public class UndeployedLaunchable implements Launchable {

private final String callerSuppliedMainClassName;

private ApplicationClientDescriptor acDesc = null;
private ApplicationClientDescriptor acDesc;

private AppClientArchivist archivist = null;
private AppClientArchivist archivist;

private final ReadableArchive clientRA;

private ClassLoader classLoader = null;
private ClassLoader classLoader;

static UndeployedLaunchable newUndeployedLaunchable(
final ServiceLocator habitat,
Expand Down Expand Up @@ -155,10 +157,12 @@ static UndeployedLaunchable newUndeployedLaunchable(
}
}

@Override
public URI getURI() {
return clientRA.getURI();
}

@Override
public String getAnchorDir() {
return null;
}
Expand Down Expand Up @@ -189,6 +193,7 @@ private UndeployedLaunchable(final ServiceLocator habitat,
this.archivist = completeInit(archivist);
}

@Override
public Class getMainClass() throws ClassNotFoundException {
try {
String mainClassName = mainClassNameToLaunch();
Expand Down Expand Up @@ -218,6 +223,7 @@ private String extractMainClassFromArchive(final ReadableArchive clientRA) throw
return mf.getMainAttributes().getValue(Attributes.Name.MAIN_CLASS);
}

@Override
public ApplicationClientDescriptor getDescriptor(final URLClassLoader loader) throws IOException, SAXException {
this.classLoader = loader;
if (acDesc == null) {
Expand All @@ -233,7 +239,8 @@ public ACCClassLoader run() {
_archivist.setAnnotationProcessingRequested(true);
acDesc = _archivist.open(clientRA);

Application.createVirtualApplication(null, acDesc.getModuleDescriptor());
ModuleDescriptor<BundleDescriptor> moduleDescriptor = acDesc.getModuleDescriptor();
Application.createVirtualApplication(null, moduleDescriptor);
acDesc.getApplication().setAppName(getDefaultApplicationName(clientRA));
}
return acDesc;
Expand All @@ -251,10 +258,11 @@ public String getDefaultApplicationName(ReadableArchive archive) {
return appName;
}


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

private AppClientArchivist getArchivist(final ClassLoader classLoader) throws IOException {
Expand All @@ -267,6 +275,7 @@ private AppClientArchivist getArchivist(final ClassLoader classLoader) throws IO
return archivist;
}

@Override
public void validateDescriptor() {
try {
getArchivist(classLoader).validate(classLoader);
Expand Down
4 changes: 4 additions & 0 deletions appserver/common/annotation-framework/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,10 @@
<artifactId>common-util</artifactId>
<version>${project.version}</version>
</dependency>
<dependency>
<groupId>org.glassfish.annotations</groupId>
<artifactId>logging-annotation-processor</artifactId>
</dependency>

<dependency>
<groupId>org.glassfish.main</groupId>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
/*
* Copyright (c) 2022 Contributors to the Eclipse Foundation
* Copyright (c) 1997, 2018 Oracle and/or its affiliates. All rights reserved.
*
* This program and the accompanying materials are made available under the
Expand All @@ -19,7 +20,6 @@
import java.lang.annotation.ElementType;
import java.lang.reflect.AnnotatedElement;


/**
* Provides notification when the annotation processor is visiting a
* new AnnotatedElement.
Expand All @@ -34,22 +34,18 @@ public interface AnnotatedElementHandler {
*
* @param type the annotated element type (class, field, method...)
* @param element the annotated element we are starting to visit.
*
* @exception AnnotationProcessorException;
* @throws AnnotationProcessorException;
*/
public void startElement(ElementType type, AnnotatedElement element)
throws AnnotationProcessorException;
void startElement(ElementType type, AnnotatedElement element) throws AnnotationProcessorException;

/**
* After annotations for an annotated element are processed, the
* endElement is called with the annotated element value and its type
*
* @param type the annotated element type (class, field, method...)
* @param element the annotated element we are done visiting.
*
* @exception AnnotationProcessorException;
* @throws AnnotationProcessorException;
*/
public void endElement(ElementType type, AnnotatedElement element)
throws AnnotationProcessorException;
void endElement(ElementType type, AnnotatedElement element) throws AnnotationProcessorException;

}
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
/*
* Copyright (c) 2022 Contributors to the Eclipse Foundation
* Copyright (c) 1997, 2018 Oracle and/or its affiliates. All rights reserved.
*
* This program and the accompanying materials are made available under the
Expand All @@ -16,39 +17,38 @@

package org.glassfish.apf;

import org.jvnet.hk2.annotations.Contract;

import java.lang.annotation.Annotation;

import org.jvnet.hk2.annotations.Contract;

/**
* This interface defines the contract for annotation handlers
* and the annotation processing engine. Each annotation handler
* is registered for a particular annotation type and will be
* called by the engine when such annotation type is encountered.
*
* The AnnotationHandler is a stateless object, no state should
* be stored, instead users should use the ProcessingContext.
*
* Annotation can be defined or processed in random orders on a
* particular type, however, a particular annotation may need
* other annotation to be processed before itself in order to be
* processed successfully. An annotation type can indicate through
* the @see getAnnotations() method which annotation types should
* the getAnnotations() method which annotation types should
* be processed before itself.
*
* <p>
* Each implementation of this interface must specify the annotation that it can handle using
* {@link AnnotationHandlerFor} annotation.
*
* @author Jerome Dochez
*/
@Contract
public interface AnnotationHandler {
public final static String ANNOTATION_HANDLER_METADATA = "AnnotationHandlerFor";

String ANNOTATION_HANDLER_METADATA = "AnnotationHandlerFor";

/**
* @return the annotation type this annotation handler is handling
*/
public Class<? extends Annotation> getAnnotationType();
Class<? extends Annotation> getAnnotationType();

/**
* Process a particular annotation which type is the same as the
Expand All @@ -57,15 +57,16 @@ public interface AnnotationHandler {
* in the passed AnnotationInfo instance.
*
* @param element the annotation information
* @return {@link HandlerProcessingResult}
* @throws AnnotationProcessorException
*/
public HandlerProcessingResult processAnnotation(AnnotationInfo element)
throws AnnotationProcessorException;
HandlerProcessingResult processAnnotation(AnnotationInfo element) throws AnnotationProcessorException;

/**
* @return an array of annotation types this annotation handler would
* require to be processed (if present) before it processes it's own
* annotation type.
* require to be processed (if present) before it processes it's own
* annotation type.
*/
public Class<? extends Annotation>[] getTypeDependencies();
Class<? extends Annotation>[] getTypeDependencies();

}
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
/*
* Copyright (c) 2022 Contributors to the Eclipse Foundation
* Copyright (c) 2011, 2018 Oracle and/or its affiliates. All rights reserved.
*
* This program and the accompanying materials are made available under the
Expand All @@ -16,19 +17,21 @@

package org.glassfish.apf;

import org.glassfish.hk2.api.Metadata;
import org.jvnet.hk2.annotations.Service;
import jakarta.inject.Qualifier;

import java.lang.annotation.Annotation;
import java.lang.annotation.ElementType;
import java.lang.annotation.Retention;
import java.lang.annotation.Target;

import jakarta.inject.Qualifier;
import org.glassfish.hk2.api.Metadata;
import org.jvnet.hk2.annotations.Service;

import static java.lang.annotation.RetentionPolicy.RUNTIME;

/**
* The {@link Annotation} handled by this handler.
* <p>
* Normally goes with {@link Service} annotation, and this annotation must be placed
* on a class that implements {@link AnnotationHandler}.
*
Expand All @@ -38,6 +41,10 @@
@Target(ElementType.TYPE)
@Qualifier
public @interface AnnotationHandlerFor {

/**
* @return the {@link Annotation} handled by this handler.
*/
@Metadata(AnnotationHandler.ANNOTATION_HANDLER_METADATA)
Class<? extends Annotation> value();
}

0 comments on commit 21870ec

Please sign in to comment.