Lines 45-63
Link Here
|
45 |
import java.io.FileNotFoundException; |
45 |
import java.io.FileNotFoundException; |
46 |
import java.io.IOException; |
46 |
import java.io.IOException; |
47 |
import java.io.InputStream; |
47 |
import java.io.InputStream; |
|
|
48 |
import java.io.InputStreamReader; |
48 |
import java.io.Reader; |
49 |
import java.io.Reader; |
|
|
50 |
import java.io.StringWriter; |
49 |
import java.util.ArrayList; |
51 |
import java.util.ArrayList; |
50 |
import java.util.Collections; |
52 |
import java.util.Collections; |
51 |
import java.util.HashMap; |
53 |
import java.util.HashMap; |
52 |
import java.util.List; |
54 |
import java.util.List; |
53 |
import java.util.Map; |
55 |
import java.util.Map; |
54 |
import java.util.concurrent.atomic.AtomicBoolean; |
56 |
import java.util.concurrent.atomic.AtomicBoolean; |
|
|
57 |
import java.util.logging.Level; |
58 |
import java.util.logging.Logger; |
55 |
import org.codehaus.plexus.util.xml.pull.XmlPullParserException; |
59 |
import org.codehaus.plexus.util.xml.pull.XmlPullParserException; |
56 |
import org.netbeans.api.annotations.common.NonNull; |
60 |
import org.netbeans.api.annotations.common.NonNull; |
|
|
61 |
import org.netbeans.api.project.Project; |
57 |
import org.netbeans.modules.maven.api.MavenConfiguration; |
62 |
import org.netbeans.modules.maven.api.MavenConfiguration; |
58 |
import static org.netbeans.modules.maven.configurations.Bundle.*; |
63 |
import static org.netbeans.modules.maven.configurations.Bundle.*; |
59 |
import org.netbeans.modules.maven.execute.model.ActionToGoalMapping; |
64 |
import org.netbeans.modules.maven.execute.model.ActionToGoalMapping; |
60 |
import org.netbeans.modules.maven.execute.model.NetbeansActionMapping; |
65 |
import org.netbeans.modules.maven.execute.model.NetbeansActionMapping; |
|
|
66 |
import org.netbeans.modules.maven.execute.model.NetbeansActionProfile; |
67 |
import org.netbeans.modules.maven.execute.model.NetbeansActionReader; |
68 |
import org.netbeans.modules.maven.execute.model.io.xpp3.NetbeansBuildActionXpp3Writer; |
61 |
import org.netbeans.modules.maven.spi.actions.AbstractMavenActionsProvider; |
69 |
import org.netbeans.modules.maven.spi.actions.AbstractMavenActionsProvider; |
62 |
import org.openide.filesystems.FileChangeAdapter; |
70 |
import org.openide.filesystems.FileChangeAdapter; |
63 |
import org.openide.filesystems.FileChangeListener; |
71 |
import org.openide.filesystems.FileChangeListener; |
Lines 65-70
Link Here
|
65 |
import org.openide.filesystems.FileObject; |
73 |
import org.openide.filesystems.FileObject; |
66 |
import org.openide.filesystems.FileRenameEvent; |
74 |
import org.openide.filesystems.FileRenameEvent; |
67 |
import org.openide.filesystems.FileUtil; |
75 |
import org.openide.filesystems.FileUtil; |
|
|
76 |
import org.openide.util.Exceptions; |
68 |
import org.openide.util.NbBundle.Messages; |
77 |
import org.openide.util.NbBundle.Messages; |
69 |
|
78 |
|
70 |
/** |
79 |
/** |
Lines 72-77
Link Here
|
72 |
* @author mkleint |
81 |
* @author mkleint |
73 |
*/ |
82 |
*/ |
74 |
public class M2Configuration extends AbstractMavenActionsProvider implements MavenConfiguration, Comparable<M2Configuration> { |
83 |
public class M2Configuration extends AbstractMavenActionsProvider implements MavenConfiguration, Comparable<M2Configuration> { |
|
|
84 |
private static final Logger LOG = Logger.getLogger(M2Configuration.class.getName()); |
75 |
|
85 |
|
76 |
public static final String DEFAULT = "%%DEFAULT%%"; //NOI18N |
86 |
public static final String DEFAULT = "%%DEFAULT%%"; //NOI18N |
77 |
|
87 |
|
Lines 157-171
Link Here
|
157 |
} |
167 |
} |
158 |
|
168 |
|
159 |
public @Override InputStream getActionDefinitionStream() { |
169 |
public @Override InputStream getActionDefinitionStream() { |
160 |
|
170 |
return getActionDefinitionStream(id); |
|
|
171 |
} |
172 |
final InputStream getActionDefinitionStream(String forId) { |
161 |
checkListener(); |
173 |
checkListener(); |
162 |
FileObject fo = projectDirectory.getFileObject(getFileNameExt(id)); |
174 |
FileObject fo = projectDirectory.getFileObject(getFileNameExt(forId)); |
163 |
resetCache.set(false); |
175 |
resetCache.set(false); |
164 |
if (fo != null) { |
176 |
if (fo != null) { |
165 |
try { |
177 |
try { |
166 |
return fo.getInputStream(); |
178 |
return fo.getInputStream(); |
167 |
} catch (FileNotFoundException ex) { |
179 |
} catch (FileNotFoundException ex) { |
168 |
ex.printStackTrace(); |
180 |
LOG.log(Level.WARNING, "Cannot read " + fo, ex); // NOI18N |
169 |
} |
181 |
} |
170 |
} |
182 |
} |
171 |
return null; |
183 |
return null; |
Lines 235-243
Link Here
|
235 |
} |
247 |
} |
236 |
return toRet.toArray(new NetbeansActionMapping[toRet.size()]); |
248 |
return toRet.toArray(new NetbeansActionMapping[toRet.size()]); |
237 |
} catch (XmlPullParserException ex) { |
249 |
} catch (XmlPullParserException ex) { |
238 |
ex.printStackTrace(); |
250 |
LOG.log(Level.WARNING, null, ex); |
239 |
} catch (IOException ex) { |
251 |
} catch (IOException ex) { |
240 |
ex.printStackTrace(); |
252 |
LOG.log(Level.WARNING, null, ex); |
241 |
} |
253 |
} |
242 |
return fallbackActions; |
254 |
return fallbackActions; |
243 |
} |
255 |
} |
Lines 247-250
Link Here
|
247 |
return resetCache.get(); |
259 |
return resetCache.get(); |
248 |
} |
260 |
} |
249 |
|
261 |
|
|
|
262 |
@Override |
263 |
public ActionToGoalMapping getRawMappings() { |
264 |
if (originalMappings == null || reloadStream()) { |
265 |
Reader rdr = null; |
266 |
InputStream in = getActionDefinitionStream(); |
267 |
try { |
268 |
if (in == null) { |
269 |
in = getActionDefinitionStream(DEFAULT); |
270 |
if (in != null) { |
271 |
rdr = new InputStreamReader(in); |
272 |
ActionToGoalMapping def = reader.read(rdr); |
273 |
for (NetbeansActionProfile p : def.getProfiles()) { |
274 |
if (id.equals(p.getId())) { |
275 |
ActionToGoalMapping m = new ActionToGoalMapping(); |
276 |
m.setActions(m.getActions()); |
277 |
m.setModelEncoding(m.getModelEncoding()); |
278 |
originalMappings = m; |
279 |
break; |
280 |
} |
281 |
} |
282 |
|
283 |
} else { |
284 |
originalMappings = new ActionToGoalMapping(); |
285 |
} |
286 |
} else { |
287 |
rdr = new InputStreamReader(in); |
288 |
originalMappings = reader.read(rdr); |
289 |
} |
290 |
} catch (IOException ex) { |
291 |
LOG.log(Level.INFO, "Loading raw mappings", ex); |
292 |
} catch (XmlPullParserException ex) { |
293 |
LOG.log(Level.INFO, "Loading raw mappings", ex); |
294 |
} finally { |
295 |
if (rdr != null) { |
296 |
try { |
297 |
rdr.close(); |
298 |
} catch (IOException ex) { |
299 |
} |
300 |
} |
301 |
} |
302 |
if (originalMappings == null) { |
303 |
originalMappings = new ActionToGoalMapping(); |
304 |
} |
305 |
} |
306 |
return originalMappings; |
307 |
} |
308 |
|
309 |
public NetbeansActionMapping getProfileMappingForAction(String action, Project project, Map<String,String> replaceMap) { |
310 |
return new NetbeansActionReader() { |
311 |
@Override |
312 |
protected String getRawMappingsAsString() { |
313 |
NetbeansBuildActionXpp3Writer writer = new NetbeansBuildActionXpp3Writer(); |
314 |
StringWriter str = new StringWriter(); |
315 |
try { |
316 |
InputStream in = getActionDefinitionStream(DEFAULT); |
317 |
InputStreamReader rdr = new InputStreamReader(in); |
318 |
ActionToGoalMapping map = reader.read(rdr); |
319 |
writer.write(str, map); |
320 |
} catch (IOException ex) { |
321 |
LOG.log(Level.WARNING, "Loading raw mappings", ex); |
322 |
} catch (XmlPullParserException ex) { |
323 |
LOG.log(Level.WARNING, "Loading raw mappings", ex); |
324 |
} |
325 |
return str.toString(); |
326 |
} |
327 |
|
328 |
@Override |
329 |
protected Reader performDynamicSubstitutions(Map<String, String> replaceMap, String in) throws IOException { |
330 |
return M2Configuration.this.performDynamicSubstitutions(replaceMap, in); |
331 |
} |
332 |
}.getMappingForAction(reader, null, action, project, id, replaceMap); |
333 |
} |
334 |
|
335 |
public NetbeansActionMapping findMappingFor(Map<String, String> replaceMap, Project project, String actionName) { |
336 |
NetbeansActionMapping action = getProfileMappingForAction(actionName, project, replaceMap); |
337 |
if (action != null) { |
338 |
return action; |
339 |
} |
340 |
return new NetbeansActionReader() { |
341 |
@Override |
342 |
protected String getRawMappingsAsString() { |
343 |
return M2Configuration.this.getRawMappingsAsString(); |
344 |
} |
345 |
|
346 |
@Override |
347 |
protected Reader performDynamicSubstitutions(Map<String, String> replaceMap, String in) throws IOException { |
348 |
return M2Configuration.this.performDynamicSubstitutions(replaceMap, in); |
349 |
} |
350 |
}.getMappingForAction(reader, LOG, actionName, project, null, replaceMap); |
351 |
} |
352 |
|
250 |
} |
353 |
} |