svn-gvsig-desktop / branches / v2_0_0_prep / extensions / org.gvsig.mkmvnproject / src / main / java / org / gvsig / mkmvnproject / MakeMavenProjectExtension.java @ 32861
History | View | Annotate | Download (2.39 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.net.URL; |
26 |
|
27 |
import org.apache.tools.ant.DefaultLogger; |
28 |
import org.apache.tools.ant.Project; |
29 |
import org.apache.tools.ant.ProjectHelper; |
30 |
import org.gvsig.andami.plugins.Extension; |
31 |
import org.slf4j.Logger; |
32 |
import org.slf4j.LoggerFactory; |
33 |
|
34 |
/**
|
35 |
* Extension to launch the project creation from templates.
|
36 |
*
|
37 |
* @author gvSIG team
|
38 |
* @version $Id$
|
39 |
*/
|
40 |
public class MakeMavenProjectExtension extends Extension { |
41 |
|
42 |
private static final String ANT_BUILD_FILE = "mkmvnproject.xml"; |
43 |
|
44 |
private static final String ANT_TARGET = "mkproject"; |
45 |
|
46 |
private static final Logger LOG = LoggerFactory |
47 |
.getLogger(MakeMavenProjectExtension.class); |
48 |
|
49 |
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()); |
53 |
|
54 |
DefaultLogger log = new DefaultLogger();
|
55 |
log.setErrorPrintStream(System.err);
|
56 |
log.setOutputPrintStream(System.out);
|
57 |
log.setMessageOutputLevel(Project.MSG_INFO); |
58 |
|
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); |
64 |
|
65 |
LOG.info("Starting ant task with the file {} and the target {}", file,
|
66 |
ANT_TARGET); |
67 |
ant.executeTarget(ANT_TARGET); |
68 |
} |
69 |
|
70 |
public void initialize() { |
71 |
// Nothing to do
|
72 |
} |
73 |
|
74 |
public boolean isEnabled() { |
75 |
return true; |
76 |
} |
77 |
|
78 |
public boolean isVisible() { |
79 |
return true; |
80 |
} |
81 |
|
82 |
} |