1 | |
package org.apache.onami.autobind.scanner; |
2 | |
|
3 | |
|
4 | |
|
5 | |
|
6 | |
|
7 | |
|
8 | |
|
9 | |
|
10 | |
|
11 | |
|
12 | |
|
13 | |
|
14 | |
|
15 | |
|
16 | |
|
17 | |
|
18 | |
|
19 | |
|
20 | |
import static java.lang.System.getProperty; |
21 | |
import static java.util.logging.Level.FINE; |
22 | |
import static java.util.logging.Level.INFO; |
23 | |
import static java.util.logging.Level.SEVERE; |
24 | |
import static java.util.logging.Logger.getLogger; |
25 | |
|
26 | |
import java.io.IOException; |
27 | |
import java.util.Set; |
28 | |
import java.util.logging.Logger; |
29 | |
|
30 | |
import javax.inject.Inject; |
31 | |
|
32 | |
import org.apache.onami.autobind.annotations.Bind; |
33 | |
import org.apache.onami.autobind.annotations.GuiceModule; |
34 | |
import org.apache.onami.autobind.install.InstallationContext; |
35 | |
import org.apache.onami.autobind.scanner.features.BindingScannerFeature; |
36 | |
import org.apache.onami.autobind.scanner.features.ScannerFeature; |
37 | |
|
38 | |
import com.google.inject.Binder; |
39 | |
import com.google.inject.Module; |
40 | |
|
41 | |
|
42 | |
|
43 | |
|
44 | |
|
45 | |
|
46 | |
|
47 | 0 | public class ScannerModule |
48 | |
implements Module |
49 | |
{ |
50 | |
|
51 | 0 | private static String LINE_SEPARATOR = getProperty( "line.separator" ); |
52 | |
|
53 | 0 | private final Logger _logger = getLogger( getClass().getName() ); |
54 | |
|
55 | |
@Inject |
56 | |
private ClasspathScanner _scanner; |
57 | |
|
58 | |
@Inject |
59 | |
private Set<ScannerFeature> _listeners; |
60 | |
|
61 | |
@Inject |
62 | |
private InstallationContext _context; |
63 | |
|
64 | |
@Override |
65 | |
public void configure( Binder binder ) |
66 | |
{ |
67 | 0 | if ( _logger.isLoggable( INFO ) ) |
68 | |
{ |
69 | 0 | StringBuilder builder = new StringBuilder( _scanner.getClass().getName() ) |
70 | |
.append( " is using following Scanner Features: " ) |
71 | |
.append( LINE_SEPARATOR ); |
72 | 0 | for ( ScannerFeature listener : _listeners ) |
73 | |
{ |
74 | 0 | builder.append( listener.getClass().getName() ).append( LINE_SEPARATOR ); |
75 | |
} |
76 | 0 | _logger.log( INFO, builder.toString() ); |
77 | |
} |
78 | 0 | for ( ScannerFeature listener : _listeners ) |
79 | |
{ |
80 | 0 | if ( listener instanceof BindingScannerFeature ) |
81 | |
{ |
82 | 0 | ( (BindingScannerFeature) listener ).setBinder( binder ); |
83 | 0 | if ( _logger.isLoggable( FINE ) ) |
84 | |
{ |
85 | 0 | _logger.fine( "Binding AnnotationListeners " + listener.getClass().getName() ); |
86 | |
} |
87 | |
} |
88 | |
} |
89 | |
try |
90 | |
{ |
91 | 0 | _scanner.scan(); |
92 | |
} |
93 | 0 | catch ( IOException e ) |
94 | |
{ |
95 | 0 | _logger.log( SEVERE, "Failure while Scanning the Classpath for Classes with Annotations.", e ); |
96 | 0 | } |
97 | |
try |
98 | |
{ |
99 | 0 | _context.process(); |
100 | |
} |
101 | 0 | catch ( Exception e ) |
102 | |
{ |
103 | 0 | _logger.log( SEVERE, "Failure while executing the collected Tasks.", e ); |
104 | 0 | } |
105 | 0 | } |
106 | |
|
107 | |
} |