forked from codehaus-plexus/plexus-build-api
-
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathDefaultBuildContext.java
197 lines (165 loc) · 5.38 KB
/
DefaultBuildContext.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
/*
Copyright (c) 2008 Sonatype, Inc. All rights reserved.
This program is licensed to you under the Apache License Version 2.0,
and you may not use this file except in compliance with the Apache License Version 2.0.
You may obtain a copy of the Apache License Version 2.0 at http://www.apache.org/licenses/LICENSE-2.0.
Unless required by applicable law or agreed to in writing,
software distributed under the Apache License Version 2.0 is distributed on an
"AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the Apache License Version 2.0 for the specific language governing permissions and limitations there under.
*/
package org.codehaus.plexus.build;
import javax.inject.Named;
import javax.inject.Singleton;
import java.io.File;
import java.io.IOException;
import java.io.OutputStream;
import java.nio.file.Files;
import java.util.Comparator;
import java.util.List;
import java.util.Map;
import java.util.concurrent.ConcurrentHashMap;
import org.codehaus.plexus.util.DirectoryScanner;
import org.codehaus.plexus.util.Scanner;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
/**
* Filesystem based non-incremental build context implementation which behaves
* as if all files were just created. More specifically,
*
* <ol>
* <li>hasDelta returns <code>true</code> for all paths</li>
* <li>newScanner returns Scanner that scans all files under provided
* basedir</li>
* <li>newDeletedScanner always returns empty scanner</li>
* <li>isIncremental returns <code>false</code></li>
* <li>getValue always returns the last set value in this session and only
* stores to memory</li>
* </ol>
*/
@Named("default")
@Singleton
public class DefaultBuildContext implements BuildContext {
private static final String[] EMPTY_STRING_ARRAY = new String[0];
private final Map<String, Object> contextMap = new ConcurrentHashMap<>();
private final Logger logger = LoggerFactory.getLogger(DefaultBuildContext.class);
/** {@inheritDoc} */
public boolean hasDelta(String relpath) {
return true;
}
/**
* <p>hasDelta.</p>
*
* @param file a {@link java.io.File} object.
* @return a boolean.
*/
public boolean hasDelta(File file) {
return true;
}
/**
* <p>hasDelta.</p>
*
* @param relpaths a {@link java.util.List} object.
* @return a boolean.
*/
public boolean hasDelta(List<String> relpaths) {
return true;
}
/** {@inheritDoc} */
public OutputStream newFileOutputStream(File file) throws IOException {
return Files.newOutputStream(file.toPath());
}
/** {@inheritDoc} */
public Scanner newScanner(File basedir) {
DirectoryScanner ds = new DirectoryScanner();
ds.setBasedir(basedir);
return ds;
}
/** {@inheritDoc} */
public void refresh(File file) {
// do nothing
}
/** {@inheritDoc} */
public Scanner newDeleteScanner(File basedir) {
return new Scanner() {
@Override
public void addDefaultExcludes() {
}
@Override
public String[] getIncludedDirectories() {
return EMPTY_STRING_ARRAY;
}
@Override
public String[] getIncludedFiles() {
return EMPTY_STRING_ARRAY;
}
@Override
public void scan() {
}
@Override
public void setExcludes(String[] excludes) {
}
@Override
public void setIncludes(String[] includes) {
}
@Override
public File getBasedir() {
return basedir;
}
@Override
public void setFilenameComparator(Comparator<String> comparator) {
}
};
}
/** {@inheritDoc} */
public Scanner newScanner(File basedir, boolean ignoreDelta) {
return newScanner(basedir);
}
/**
* <p>isIncremental.</p>
*
* @return a boolean.
*/
public boolean isIncremental() {
return false;
}
/** {@inheritDoc} */
public Object getValue(String key) {
return contextMap.get(key);
}
/** {@inheritDoc} */
public void setValue(String key, Object value) {
contextMap.put(key, value);
}
private String getMessage(File file, int line, int column, String message) {
return file.getAbsolutePath() + " [" + line + ':' + column + "]: " + message;
}
/** {@inheritDoc} */
public void addError(File file, int line, int column, String message, Throwable cause) {
addMessage(file, line, column, message, SEVERITY_ERROR, cause);
}
/** {@inheritDoc} */
public void addWarning(File file, int line, int column, String message, Throwable cause) {
addMessage(file, line, column, message, SEVERITY_WARNING, cause);
}
/** {@inheritDoc} */
public void addMessage(File file, int line, int column, String message, int severity, Throwable cause) {
switch(severity) {
case BuildContext.SEVERITY_ERROR:
logger.error(getMessage(file, line, column, message), cause);
return;
case BuildContext.SEVERITY_WARNING:
logger.warn(getMessage(file, line, column, message), cause);
return;
}
throw new IllegalArgumentException("severity=" + severity);
}
/** {@inheritDoc} */
public void removeMessages(File file) {
}
/** {@inheritDoc} */
public boolean isUptodate(File target, File source) {
return target != null && target.exists() && source != null && source.exists()
&& target.lastModified() > source.lastModified();
}
}