1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19 package org.eclipse.jetty.maven.plugin;
20
21 import java.io.File;
22
23 import org.eclipse.jetty.annotations.AbstractDiscoverableAnnotationHandler;
24 import org.eclipse.jetty.annotations.AnnotationConfiguration;
25 import org.eclipse.jetty.annotations.AnnotationParser;
26 import org.eclipse.jetty.annotations.AnnotationParser.DiscoverableAnnotationHandler;
27 import org.eclipse.jetty.annotations.ClassNameResolver;
28 import org.eclipse.jetty.util.log.Log;
29 import org.eclipse.jetty.util.log.Logger;
30 import org.eclipse.jetty.util.resource.Resource;
31 import org.eclipse.jetty.webapp.MetaData;
32 import org.eclipse.jetty.webapp.WebAppContext;
33
34 public class MavenAnnotationConfiguration extends AnnotationConfiguration
35 {
36 private static final Logger LOG = Log.getLogger(MavenAnnotationConfiguration.class);
37
38
39 @Override
40 public void parseWebInfClasses(final WebAppContext context, final AnnotationParser parser) throws Exception
41 {
42 JettyWebAppContext jwac = (JettyWebAppContext)context;
43 if (jwac.getClassPathFiles() == null || jwac.getClassPathFiles().size() == 0)
44 super.parseWebInfClasses (context, parser);
45 else
46 {
47 LOG.debug("Scanning classes ");
48
49
50 MetaData metaData = context.getMetaData();
51 if (metaData == null)
52 throw new IllegalStateException ("No metadata");
53
54 parser.clearHandlers();
55 for (DiscoverableAnnotationHandler h:_discoverableAnnotationHandlers)
56 {
57 if (h instanceof AbstractDiscoverableAnnotationHandler)
58 ((AbstractDiscoverableAnnotationHandler)h).setResource(null);
59 }
60 parser.registerHandlers(_discoverableAnnotationHandlers);
61 parser.registerHandler(_classInheritanceHandler);
62 parser.registerHandlers(_containerInitializerAnnotationHandlers);
63
64
65 for (File f:jwac.getClassPathFiles())
66 {
67
68 if (f.isDirectory() && f.exists())
69 {
70 doParse(context, parser, Resource.newResource(f.toURL()));
71 }
72 }
73
74
75
76 if (context.getWebInf() != null && context.getWebInf().exists())
77 {
78 Resource classesDir = context.getWebInf().addPath("classes/");
79 if (classesDir.exists())
80 {
81 doParse(context, parser, classesDir);
82 }
83 }
84 }
85 }
86
87
88 public void doParse (final WebAppContext context, final AnnotationParser parser, Resource resource)
89 throws Exception
90 {
91 parser.parse(resource, new ClassNameResolver()
92 {
93 public boolean isExcluded (String name)
94 {
95 if (context.isSystemClass(name)) return true;
96 if (context.isServerClass(name)) return false;
97 return false;
98 }
99
100 public boolean shouldOverride (String name)
101 {
102
103 if (context.isParentLoaderPriority())
104 return false;
105 return true;
106 }
107 });
108 }
109 }