Revision 34125 branches/v2_0_0_prep/extensions/org.gvsig.mkmvnproject/src/main/java/org/gvsig/mkmvnproject/MakeMavenProjectExtension.java
MakeMavenProjectExtension.java | ||
---|---|---|
22 | 22 |
package org.gvsig.mkmvnproject; |
23 | 23 |
|
24 | 24 |
import java.io.File; |
25 |
import java.io.IOException; |
|
25 | 26 |
import java.net.URL; |
26 | 27 |
|
27 | 28 |
import org.apache.tools.ant.DefaultLogger; |
28 | 29 |
import org.apache.tools.ant.Project; |
29 | 30 |
import org.apache.tools.ant.ProjectHelper; |
30 |
import org.gvsig.andami.plugins.Extension; |
|
31 | 31 |
import org.slf4j.Logger; |
32 | 32 |
import org.slf4j.LoggerFactory; |
33 | 33 |
|
34 |
import org.gvsig.andami.PluginServices; |
|
35 |
import org.gvsig.andami.messages.NotificationManager; |
|
36 |
import org.gvsig.andami.plugins.Extension; |
|
37 |
|
|
34 | 38 |
/** |
35 | 39 |
* Extension to launch the project creation from templates. |
36 | 40 |
* |
... | ... | |
46 | 50 |
private static final Logger LOG = LoggerFactory |
47 | 51 |
.getLogger(MakeMavenProjectExtension.class); |
48 | 52 |
|
53 |
private boolean enabled = true; |
|
54 |
|
|
55 |
private final Object lock = new Object(); |
|
56 |
|
|
49 | 57 |
public void execute(String actionCommand) { |
50 |
ClassLoader loader = this.getClass().getClassLoader(); |
|
51 |
URL build = loader.getResource("scripts/" + ANT_BUILD_FILE); |
|
52 |
File file = new File(build.getFile()); |
|
58 |
// TODO: add support to parallel executions in Andami?? |
|
53 | 59 |
|
54 |
DefaultLogger log = new DefaultLogger(); |
|
55 |
log.setErrorPrintStream(System.err); |
|
56 |
log.setOutputPrintStream(System.out); |
|
57 |
log.setMessageOutputLevel(Project.MSG_INFO); |
|
60 |
// Create messages console |
|
61 |
CreatePluginConsoleWindow console = null; |
|
62 |
try { |
|
63 |
console = new CreatePluginConsoleWindow(); |
|
64 |
PluginServices.getMDIManager().addCentredWindow(console); |
|
65 |
} catch (IOException e) { |
|
66 |
NotificationManager.addWarning("Error creating the console", e); |
|
67 |
} |
|
58 | 68 |
|
59 |
Project ant = new Project(); |
|
60 |
ant.addBuildListener(log); |
|
61 |
ant.setUserProperty("ant.file", file.getAbsolutePath()); |
|
62 |
ant.init(); |
|
63 |
ProjectHelper.getProjectHelper().parse(ant, file); |
|
69 |
try { |
|
70 |
// Disable extension so it can't be executed again. |
|
71 |
synchronized (lock) { |
|
72 |
enabled = false; |
|
73 |
} |
|
74 |
new CreatePluginThread(console).start(); |
|
75 |
} finally { |
|
76 |
synchronized (lock) { |
|
77 |
// create plugin process finish. Enable extension. |
|
78 |
enabled = true; |
|
79 |
} |
|
80 |
} |
|
81 |
} |
|
64 | 82 |
|
65 |
LOG.info("Starting ant task with the file {} and the target {}", file, |
|
66 |
ANT_TARGET); |
|
67 |
ant.executeTarget(ANT_TARGET); |
|
83 |
/** |
|
84 |
* Thread to launch the ant base plugin creation project. |
|
85 |
* |
|
86 |
* @author gvSIG Team |
|
87 |
* @version $Id$ |
|
88 |
*/ |
|
89 |
private static final class CreatePluginThread extends Thread { |
|
90 |
|
|
91 |
private final CreatePluginConsoleWindow console; |
|
92 |
|
|
93 |
/** |
|
94 |
* Constructor. |
|
95 |
* |
|
96 |
* @param console |
|
97 |
*/ |
|
98 |
public CreatePluginThread(CreatePluginConsoleWindow console) { |
|
99 |
this.console = console; |
|
100 |
setName("Create plugin execution thread"); |
|
101 |
setDaemon(true); |
|
102 |
} |
|
103 |
|
|
104 |
@Override |
|
105 |
public void run() { |
|
106 |
DefaultLogger log = new DefaultLogger(); |
|
107 |
log.setMessageOutputLevel(Project.MSG_INFO); |
|
108 |
|
|
109 |
if (console != null) { |
|
110 |
log.setErrorPrintStream(console.getErrorPrintStream()); |
|
111 |
log.setOutputPrintStream(console.getPrintStream()); |
|
112 |
} else { |
|
113 |
LOG.warn("Console window not available, will use the default console for Ant"); |
|
114 |
log.setErrorPrintStream(System.err); |
|
115 |
log.setOutputPrintStream(System.out); |
|
116 |
} |
|
117 |
|
|
118 |
ClassLoader loader = this.getClass().getClassLoader(); |
|
119 |
URL build = loader.getResource("scripts/" + ANT_BUILD_FILE); |
|
120 |
File file = new File(build.getFile()); |
|
121 |
|
|
122 |
final Project ant = new Project(); |
|
123 |
ant.addBuildListener(log); |
|
124 |
ant.setUserProperty("ant.file", file.getAbsolutePath()); |
|
125 |
ant.init(); |
|
126 |
ProjectHelper.getProjectHelper().parse(ant, file); |
|
127 |
|
|
128 |
LOG.info("Starting ant task with the file {} and the target {}", |
|
129 |
file, ANT_TARGET); |
|
130 |
ant.executeTarget(ANT_TARGET); |
|
131 |
} |
|
68 | 132 |
} |
69 | 133 |
|
70 | 134 |
public void initialize() { |
... | ... | |
72 | 136 |
} |
73 | 137 |
|
74 | 138 |
public boolean isEnabled() { |
75 |
return true;
|
|
139 |
return enabled;
|
|
76 | 140 |
} |
77 | 141 |
|
78 | 142 |
public boolean isVisible() { |
Also available in: Unified diff