Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJan Bartel2013-10-21 05:44:33 +0000
committerJan Bartel2013-10-21 05:44:33 +0000
commit3f852cf3db6f423a4b6d59e401cfd8c60ccddabd (patch)
tree0f0a4285dcdf13d843f05c93986396c9b427252f /jetty-maven-plugin/src
parentb9020d200a6c578d53fbd58cd72934559699fea3 (diff)
downloadorg.eclipse.jetty.project-3f852cf3db6f423a4b6d59e401cfd8c60ccddabd.tar.gz
org.eclipse.jetty.project-3f852cf3db6f423a4b6d59e401cfd8c60ccddabd.tar.xz
org.eclipse.jetty.project-3f852cf3db6f423a4b6d59e401cfd8c60ccddabd.zip
416597 Allow classes and jars on the webappcontext extraclasspath to be scanned for annotations by jetty-maven-plugin
Diffstat (limited to 'jetty-maven-plugin/src')
-rw-r--r--jetty-maven-plugin/src/main/java/org/eclipse/jetty/maven/plugin/JettyWebAppContext.java3
-rw-r--r--jetty-maven-plugin/src/main/java/org/eclipse/jetty/maven/plugin/MavenAnnotationConfiguration.java109
-rw-r--r--jetty-maven-plugin/src/main/java/org/eclipse/jetty/maven/plugin/MavenWebInfConfiguration.java39
3 files changed, 41 insertions, 110 deletions
diff --git a/jetty-maven-plugin/src/main/java/org/eclipse/jetty/maven/plugin/JettyWebAppContext.java b/jetty-maven-plugin/src/main/java/org/eclipse/jetty/maven/plugin/JettyWebAppContext.java
index 0489a2d875..4b8f511f9e 100644
--- a/jetty-maven-plugin/src/main/java/org/eclipse/jetty/maven/plugin/JettyWebAppContext.java
+++ b/jetty-maven-plugin/src/main/java/org/eclipse/jetty/maven/plugin/JettyWebAppContext.java
@@ -29,6 +29,7 @@ import java.util.Map;
import java.util.Set;
import java.util.TreeSet;
+import org.eclipse.jetty.annotations.AnnotationConfiguration;
import org.eclipse.jetty.plus.webapp.EnvConfiguration;
import org.eclipse.jetty.servlet.FilterHolder;
import org.eclipse.jetty.servlet.FilterMapping;
@@ -110,7 +111,7 @@ public class JettyWebAppContext extends WebAppContext
new FragmentConfiguration(),
_envConfig = new EnvConfiguration(),
new org.eclipse.jetty.plus.webapp.PlusConfiguration(),
- new MavenAnnotationConfiguration(),
+ new AnnotationConfiguration(),
new JettyWebXmlConfiguration()
});
// Turn off copyWebInf option as it is not applicable for plugin.
diff --git a/jetty-maven-plugin/src/main/java/org/eclipse/jetty/maven/plugin/MavenAnnotationConfiguration.java b/jetty-maven-plugin/src/main/java/org/eclipse/jetty/maven/plugin/MavenAnnotationConfiguration.java
deleted file mode 100644
index 8d5b502a4c..0000000000
--- a/jetty-maven-plugin/src/main/java/org/eclipse/jetty/maven/plugin/MavenAnnotationConfiguration.java
+++ /dev/null
@@ -1,109 +0,0 @@
-//
-// ========================================================================
-// Copyright (c) 1995-2013 Mort Bay Consulting Pty. Ltd.
-// ------------------------------------------------------------------------
-// All rights reserved. This program and the accompanying materials
-// are made available under the terms of the Eclipse Public License v1.0
-// and Apache License v2.0 which accompanies this distribution.
-//
-// The Eclipse Public License is available at
-// http://www.eclipse.org/legal/epl-v10.html
-//
-// The Apache License v2.0 is available at
-// http://www.opensource.org/licenses/apache2.0.php
-//
-// You may elect to redistribute this code under either of these licenses.
-// ========================================================================
-//
-
-package org.eclipse.jetty.maven.plugin;
-
-import java.io.File;
-
-import org.eclipse.jetty.annotations.AbstractDiscoverableAnnotationHandler;
-import org.eclipse.jetty.annotations.AnnotationConfiguration;
-import org.eclipse.jetty.annotations.AnnotationParser;
-import org.eclipse.jetty.annotations.AnnotationParser.DiscoverableAnnotationHandler;
-import org.eclipse.jetty.annotations.ClassNameResolver;
-import org.eclipse.jetty.util.log.Log;
-import org.eclipse.jetty.util.log.Logger;
-import org.eclipse.jetty.util.resource.Resource;
-import org.eclipse.jetty.webapp.MetaData;
-import org.eclipse.jetty.webapp.WebAppContext;
-
-public class MavenAnnotationConfiguration extends AnnotationConfiguration
-{
- private static final Logger LOG = Log.getLogger(MavenAnnotationConfiguration.class);
-
- /* ------------------------------------------------------------ */
- @Override
- public void parseWebInfClasses(final WebAppContext context, final AnnotationParser parser) throws Exception
- {
- JettyWebAppContext jwac = (JettyWebAppContext)context;
- if (jwac.getClassPathFiles() == null || jwac.getClassPathFiles().size() == 0)
- super.parseWebInfClasses (context, parser);
- else
- {
- LOG.debug("Scanning classes ");
- //Look for directories on the classpath and process each one of those
-
- MetaData metaData = context.getMetaData();
- if (metaData == null)
- throw new IllegalStateException ("No metadata");
-
- parser.clearHandlers();
- for (DiscoverableAnnotationHandler h:_discoverableAnnotationHandlers)
- {
- if (h instanceof AbstractDiscoverableAnnotationHandler)
- ((AbstractDiscoverableAnnotationHandler)h).setResource(null); //
- }
- parser.registerHandlers(_discoverableAnnotationHandlers);
- parser.registerHandler(_classInheritanceHandler);
- parser.registerHandlers(_containerInitializerAnnotationHandlers);
-
-
- for (File f:jwac.getClassPathFiles())
- {
- //scan the equivalent of the WEB-INF/classes directory that has been synthesised by the plugin
- if (f.isDirectory() && f.exists())
- {
- doParse(context, parser, Resource.newResource(f.toURI()));
- }
- }
-
- //if an actual WEB-INF/classes directory also exists (eg because of overlayed wars) then scan that
- //too
- if (context.getWebInf() != null && context.getWebInf().exists())
- {
- Resource classesDir = context.getWebInf().addPath("classes/");
- if (classesDir.exists())
- {
- doParse(context, parser, classesDir);
- }
- }
- }
- }
-
-
- public void doParse (final WebAppContext context, final AnnotationParser parser, Resource resource)
- throws Exception
- {
- parser.parseDir(resource, new ClassNameResolver()
- {
- public boolean isExcluded (String name)
- {
- if (context.isSystemClass(name)) return true;
- if (context.isServerClass(name)) return false;
- return false;
- }
-
- public boolean shouldOverride (String name)
- {
- //looking at webapp classpath, found already-parsed class of same name - did it come from system or duplicate in webapp?
- if (context.isParentLoaderPriority())
- return false;
- return true;
- }
- });
- }
-}
diff --git a/jetty-maven-plugin/src/main/java/org/eclipse/jetty/maven/plugin/MavenWebInfConfiguration.java b/jetty-maven-plugin/src/main/java/org/eclipse/jetty/maven/plugin/MavenWebInfConfiguration.java
index d4a5e680f1..9c939fe020 100644
--- a/jetty-maven-plugin/src/main/java/org/eclipse/jetty/maven/plugin/MavenWebInfConfiguration.java
+++ b/jetty-maven-plugin/src/main/java/org/eclipse/jetty/maven/plugin/MavenWebInfConfiguration.java
@@ -239,6 +239,45 @@ public class MavenWebInfConfiguration extends WebInfConfiguration
}
+
+
+
+ /**
+ * Add in the classes dirs from test/classes and target/classes
+ * @see org.eclipse.jetty.webapp.WebInfConfiguration#findClassDirs(org.eclipse.jetty.webapp.WebAppContext)
+ */
+ @Override
+ protected List<Resource> findClassDirs(WebAppContext context) throws Exception
+ {
+ List<Resource> list = new ArrayList<Resource>();
+
+ JettyWebAppContext jwac = (JettyWebAppContext)context;
+ if (jwac.getClassPathFiles() != null)
+ {
+ for (File f: jwac.getClassPathFiles())
+ {
+ if (f.exists() && f.isDirectory())
+ {
+ try
+ {
+ list.add(Resource.newResource(f.toURI()));
+ }
+ catch (Exception e)
+ {
+ LOG.warn("Bad url ", e);
+ }
+ }
+ }
+ }
+
+ List<Resource> classesDirs = super.findClassDirs(context);
+ if (classesDirs != null)
+ list.addAll(classesDirs);
+ return list;
+ }
+
+
+
protected Resource unpackOverlay (WebAppContext context, Overlay overlay)
throws IOException

Back to the top