13
13
14
14
package org .codehaus .plexus .build ;
15
15
16
+ import javax .inject .Inject ;
16
17
import javax .inject .Named ;
17
18
import javax .inject .Singleton ;
18
19
23
24
import java .util .Map ;
24
25
import java .util .concurrent .ConcurrentHashMap ;
25
26
26
- import org .codehaus .plexus .util .DirectoryScanner ;
27
27
import org .codehaus .plexus .util .Scanner ;
28
28
import org .codehaus .plexus .util .io .CachingOutputStream ;
29
- import org .slf4j .Logger ;
30
- import org .slf4j .LoggerFactory ;
31
29
32
30
/**
33
31
* Filesystem based non-incremental build context implementation which behaves
48
46
public class DefaultBuildContext implements BuildContext {
49
47
50
48
private final Map <String , Object > contextMap = new ConcurrentHashMap <>();
51
- private final Logger logger = LoggerFactory .getLogger (DefaultBuildContext .class );
49
+ private org .sonatype .plexus .build .incremental .BuildContext legacy ;
50
+
51
+ /**
52
+ * @param legacy the legacy API we delegate to by default, this allow us to
53
+ * support "older" plugins and implementors of the API while still
54
+ * having a way to move forward!
55
+ */
56
+ @ Inject
57
+ public DefaultBuildContext (org .sonatype .plexus .build .incremental .BuildContext legacy ) {
58
+ this .legacy = legacy ;
59
+ }
60
+
52
61
/** {@inheritDoc} */
53
62
public boolean hasDelta (String relpath ) {
54
- return true ;
63
+ return legacy . hasDelta ( relpath ) ;
55
64
}
56
65
57
66
/**
@@ -61,7 +70,7 @@ public boolean hasDelta(String relpath) {
61
70
* @return a boolean.
62
71
*/
63
72
public boolean hasDelta (File file ) {
64
- return true ;
73
+ return legacy . hasDelta ( file ) ;
65
74
}
66
75
67
76
/**
@@ -71,34 +80,44 @@ public boolean hasDelta(File file) {
71
80
* @return a boolean.
72
81
*/
73
82
public boolean hasDelta (List <String > relpaths ) {
74
- return true ;
83
+ return legacy . hasDelta ( relpaths ) ;
75
84
}
76
85
77
86
/** {@inheritDoc} */
78
87
public OutputStream newFileOutputStream (File file ) throws IOException {
79
- return new CachingOutputStream (file .toPath ());
88
+ if (isDefaultImplementation ()) {
89
+ return new CachingOutputStream (file .toPath ());
90
+ }
91
+ return legacy .newFileOutputStream (file );
92
+ }
93
+
94
+ /**
95
+ * @return <code>true</code> if the legacy is the default implementation and we
96
+ * can safely override/change behavior here, or <code>false</code> if a
97
+ * custom implementation is used and full delegation is required.
98
+ */
99
+ private boolean isDefaultImplementation () {
100
+ return legacy .getClass ().equals (org .sonatype .plexus .build .incremental .DefaultBuildContext .class );
80
101
}
81
102
82
103
/** {@inheritDoc} */
83
104
public Scanner newScanner (File basedir ) {
84
- DirectoryScanner ds = new DirectoryScanner ();
85
- ds .setBasedir (basedir );
86
- return ds ;
105
+ return legacy .newScanner (basedir );
87
106
}
88
107
89
108
/** {@inheritDoc} */
90
109
public void refresh (File file ) {
91
- // do nothing
110
+ legacy . refresh ( file );
92
111
}
93
112
94
113
/** {@inheritDoc} */
95
114
public Scanner newDeleteScanner (File basedir ) {
96
- return new EmptyScanner (basedir );
115
+ return legacy . newDeleteScanner (basedir );
97
116
}
98
117
99
118
/** {@inheritDoc} */
100
119
public Scanner newScanner (File basedir , boolean ignoreDelta ) {
101
- return newScanner (basedir );
120
+ return legacy . newScanner (basedir , ignoreDelta );
102
121
}
103
122
104
123
/**
@@ -107,7 +126,7 @@ public Scanner newScanner(File basedir, boolean ignoreDelta) {
107
126
* @return a boolean.
108
127
*/
109
128
public boolean isIncremental () {
110
- return false ;
129
+ return legacy . isIncremental () ;
111
130
}
112
131
113
132
/** {@inheritDoc} */
@@ -120,10 +139,6 @@ public void setValue(String key, Object value) {
120
139
contextMap .put (key , value );
121
140
}
122
141
123
- private String getMessage (File file , int line , int column , String message ) {
124
- return file .getAbsolutePath () + " [" + line + ':' + column + "]: " + message ;
125
- }
126
-
127
142
/** {@inheritDoc} */
128
143
public void addError (File file , int line , int column , String message , Throwable cause ) {
129
144
addMessage (file , line , column , message , SEVERITY_ERROR , cause );
@@ -136,26 +151,16 @@ public void addWarning(File file, int line, int column, String message, Throwabl
136
151
137
152
/** {@inheritDoc} */
138
153
public void addMessage (File file , int line , int column , String message , int severity , Throwable cause ) {
139
- switch (severity ) {
140
- case BuildContext .SEVERITY_ERROR :
141
- logger .error (getMessage (file , line , column , message ), cause );
142
- return ;
143
- case BuildContext .SEVERITY_WARNING :
144
- logger .warn (getMessage (file , line , column , message ), cause );
145
- return ;
146
- }
147
- throw new IllegalArgumentException ("severity=" + severity );
154
+ legacy .addMessage (file , line , column , message , severity , cause );
148
155
}
149
156
150
157
/** {@inheritDoc} */
151
- public void removeMessages (File file ) {}
158
+ public void removeMessages (File file ) {
159
+ legacy .removeMessages (file );
160
+ }
152
161
153
162
/** {@inheritDoc} */
154
163
public boolean isUptodate (File target , File source ) {
155
- return target != null
156
- && target .exists ()
157
- && source != null
158
- && source .exists ()
159
- && target .lastModified () > source .lastModified ();
164
+ return legacy .isUptodate (target , source );
160
165
}
161
166
}
0 commit comments