svn-gvsig-desktop / branches / v2_0_0_prep / extensions / org.gvsig.mkmvnproject / src / main / java / org / gvsig / mkmvnproject / MakeMavenProjectExtension.java @ 34125
History | View | Annotate | Download (3.95 KB)
1 |
/* gvSIG. Geographic Information System of the Valencian Government
|
---|---|
2 |
*
|
3 |
* Copyright (C) 2007-2008 Infrastructures and Transports Department
|
4 |
* of the Valencian Government (CIT)
|
5 |
*
|
6 |
* This program is free software; you can redistribute it and/or
|
7 |
* modify it under the terms of the GNU General Public License
|
8 |
* as published by the Free Software Foundation; either version 2
|
9 |
* of the License, or (at your option) any later version.
|
10 |
*
|
11 |
* This program is distributed in the hope that it will be useful,
|
12 |
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
13 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
14 |
* GNU General Public License for more details.
|
15 |
*
|
16 |
* You should have received a copy of the GNU General Public License
|
17 |
* along with this program; if not, write to the Free Software
|
18 |
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
|
19 |
* MA 02110-1301, USA.
|
20 |
*
|
21 |
*/
|
22 |
package org.gvsig.mkmvnproject; |
23 |
|
24 |
import java.io.File; |
25 |
import java.io.IOException; |
26 |
import java.net.URL; |
27 |
|
28 |
import org.apache.tools.ant.DefaultLogger; |
29 |
import org.apache.tools.ant.Project; |
30 |
import org.apache.tools.ant.ProjectHelper; |
31 |
import org.slf4j.Logger; |
32 |
import org.slf4j.LoggerFactory; |
33 |
|
34 |
import org.gvsig.andami.PluginServices; |
35 |
import org.gvsig.andami.messages.NotificationManager; |
36 |
import org.gvsig.andami.plugins.Extension; |
37 |
|
38 |
/**
|
39 |
* Extension to launch the project creation from templates.
|
40 |
*
|
41 |
* @author gvSIG team
|
42 |
* @version $Id$
|
43 |
*/
|
44 |
public class MakeMavenProjectExtension extends Extension { |
45 |
|
46 |
private static final String ANT_BUILD_FILE = "mkmvnproject.xml"; |
47 |
|
48 |
private static final String ANT_TARGET = "mkproject"; |
49 |
|
50 |
private static final Logger LOG = LoggerFactory |
51 |
.getLogger(MakeMavenProjectExtension.class); |
52 |
|
53 |
private boolean enabled = true; |
54 |
|
55 |
private final Object lock = new Object(); |
56 |
|
57 |
public void execute(String actionCommand) { |
58 |
// TODO: add support to parallel executions in Andami??
|
59 |
|
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 |
} |
68 |
|
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 |
} |
82 |
|
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 |
} |
132 |
} |
133 |
|
134 |
public void initialize() { |
135 |
// Nothing to do
|
136 |
} |
137 |
|
138 |
public boolean isEnabled() { |
139 |
return enabled;
|
140 |
} |
141 |
|
142 |
public boolean isVisible() { |
143 |
return true; |
144 |
} |
145 |
|
146 |
} |