Revision 37615
tags/v_2_0_0_Build_2043/applications/_fwAndami-updater/pom.xml | ||
---|---|---|
1 |
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd"> |
|
2 |
<modelVersion>4.0.0</modelVersion> |
|
3 |
<artifactId>org.gvsig.andamiupdater</artifactId> |
|
4 |
<packaging>jar</packaging> |
|
5 |
<name>org.gvsig.andamiupdater</name> |
|
6 |
<version>1.0.0-SNAPSHOT</version> |
|
7 |
<parent> |
|
8 |
<groupId>org.gvsig</groupId> |
|
9 |
<artifactId>org.gvsig.maven.base.pom</artifactId> |
|
10 |
<version>1.0.8-SNAPSHOT</version> |
|
11 |
</parent> |
|
12 |
<scm> |
|
13 |
<connection>scm:svn:https://devel.gvsig.org/svn/gvsig-desktop/branches/v2_0_0_prep/applications/_fwAndami-updater</connection> |
|
14 |
<developerConnection>scm:svn:https://devel.gvsig.org/svn/gvsig-desktop/branches/v2_0_0_prep/applications/_fwAndami-updater</developerConnection> |
|
15 |
<url>https://devel.gvsig.org/redmine/projects/gvsig-desktop/repository/show/branches/v2_0_0_prep/applications/_fwAndami-updater</url> |
|
16 |
</scm> |
|
17 |
<properties> |
|
18 |
<andami.lib.dir>${gvsig.install.dir}/lib</andami.lib.dir> |
|
19 |
<!-- |
|
20 |
Default gvSIG installation folder relative to the current workspace |
|
21 |
--> |
|
22 |
<gvsig.install.dir>${basedir}/../build/product</gvsig.install.dir> |
|
23 |
</properties> |
|
24 |
<dependencies> |
|
25 |
<dependency> |
|
26 |
<groupId>org.gvsig</groupId> |
|
27 |
<artifactId>org.gvsig.andami</artifactId> |
|
28 |
<version>2.0-SNAPSHOT</version> |
|
29 |
<scope>compile</scope> |
|
30 |
</dependency> |
|
31 |
<dependency> |
|
32 |
<groupId>org.apache.ant</groupId> |
|
33 |
<artifactId>ant</artifactId> |
|
34 |
<scope>compile</scope> |
|
35 |
</dependency> |
|
36 |
<dependency> |
|
37 |
<groupId>com.sardak</groupId> |
|
38 |
<artifactId>antform</artifactId> |
|
39 |
<scope>compile</scope> |
|
40 |
</dependency> |
|
41 |
<dependency> |
|
42 |
<groupId>ant-contrib</groupId> |
|
43 |
<artifactId>ant-contrib</artifactId> |
|
44 |
<scope>runtime</scope> |
|
45 |
</dependency> |
|
46 |
</dependencies> |
|
47 |
<build> |
|
48 |
<plugins> |
|
49 |
<plugin> |
|
50 |
<groupId>org.apache.maven.plugins</groupId> |
|
51 |
<artifactId>maven-jar-plugin</artifactId> |
|
52 |
<configuration> |
|
53 |
<archive> |
|
54 |
<manifest> |
|
55 |
<addClasspath>true</addClasspath> |
|
56 |
<mainClass>org.gvsig.andamiupdater.Updater</mainClass> |
|
57 |
</manifest> |
|
58 |
</archive> |
|
59 |
</configuration> |
|
60 |
</plugin> |
|
61 |
</plugins> |
|
62 |
</build> |
|
63 |
<profiles> |
|
64 |
<profile> |
|
65 |
<id>install-extension</id> |
|
66 |
<activation> |
|
67 |
<activeByDefault>true</activeByDefault> |
|
68 |
<property> |
|
69 |
<name>install-extension</name> |
|
70 |
</property> |
|
71 |
</activation> |
|
72 |
<build> |
|
73 |
<plugins> |
|
74 |
<plugin> |
|
75 |
<groupId>org.apache.maven.plugins |
|
76 |
</groupId> |
|
77 |
<artifactId>maven-dependency-plugin |
|
78 |
</artifactId> |
|
79 |
<executions> |
|
80 |
<execution> |
|
81 |
<id>copy-own-dependencies-for-andamiupdater |
|
82 |
</id> |
|
83 |
<phase>install</phase> |
|
84 |
<goals> |
|
85 |
<goal>copy-dependencies</goal> |
|
86 |
</goals> |
|
87 |
<configuration> |
|
88 |
<outputDirectory>${andami.lib.dir}</outputDirectory> |
|
89 |
<overWriteReleases>true</overWriteReleases> |
|
90 |
<overWriteSnapshots>true</overWriteSnapshots> |
|
91 |
<overWriteIfNewer>true</overWriteIfNewer> |
|
92 |
<includeScope>runtime</includeScope> |
|
93 |
</configuration> |
|
94 |
</execution> |
|
95 |
<execution> |
|
96 |
<id>copy-andamiupdater</id> |
|
97 |
<phase>install</phase> |
|
98 |
<goals> |
|
99 |
<goal>copy</goal> |
|
100 |
</goals> |
|
101 |
<configuration> |
|
102 |
<artifactItems> |
|
103 |
<artifactItem> |
|
104 |
<groupId>org.gvsig</groupId> |
|
105 |
<artifactId>org.gvsig.andamiupdater</artifactId> |
|
106 |
<version>1.0.0-SNAPSHOT</version> |
|
107 |
<type>jar</type> |
|
108 |
<overWrite>true</overWrite> |
|
109 |
</artifactItem> |
|
110 |
</artifactItems> |
|
111 |
<outputDirectory>${andami.lib.dir}</outputDirectory> |
|
112 |
<overWriteReleases>true</overWriteReleases> |
|
113 |
<overWriteSnapshots>false</overWriteSnapshots> |
|
114 |
<overWriteIfNewer>true</overWriteIfNewer> |
|
115 |
<excludeTransitive>false</excludeTransitive> |
|
116 |
</configuration> |
|
117 |
</execution> |
|
118 |
</executions> |
|
119 |
</plugin> |
|
120 |
</plugins> |
|
121 |
</build> |
|
122 |
</profile> |
|
123 |
</profiles> |
|
124 |
</project> |
|
0 | 125 |
tags/v_2_0_0_Build_2043/applications/_fwAndami-updater/src/main/java/org/gvsig/andamiupdater/Updater.java | ||
---|---|---|
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.andamiupdater; |
|
23 |
|
|
24 |
import java.io.BufferedReader; |
|
25 |
import java.io.DataInputStream; |
|
26 |
import java.io.File; |
|
27 |
import java.io.FileInputStream; |
|
28 |
import java.io.FileOutputStream; |
|
29 |
import java.io.IOException; |
|
30 |
import java.io.InputStream; |
|
31 |
import java.io.InputStreamReader; |
|
32 |
import java.io.OutputStream; |
|
33 |
import java.lang.reflect.Method; |
|
34 |
|
|
35 |
import com.sardak.antform.AntForm; |
|
36 |
import com.sardak.antform.AntMenu; |
|
37 |
|
|
38 |
import org.apache.tools.ant.Project; |
|
39 |
import org.apache.tools.ant.ProjectHelper; |
|
40 |
|
|
41 |
/** |
|
42 |
* @author gvSIG Team |
|
43 |
* @version $Id$ |
|
44 |
* |
|
45 |
*/ |
|
46 |
public class Updater { |
|
47 |
|
|
48 |
private String[] args; |
|
49 |
|
|
50 |
/** |
|
51 |
* @param args |
|
52 |
*/ |
|
53 |
public Updater(String[] args) { |
|
54 |
this.args = args; |
|
55 |
} |
|
56 |
|
|
57 |
/** |
|
58 |
* @param args |
|
59 |
* @throws Exception |
|
60 |
*/ |
|
61 |
public static void main(String[] args) throws Exception { |
|
62 |
Updater updater = new Updater(args); |
|
63 |
updater.copyFiles(); |
|
64 |
updater.executeScripts(); |
|
65 |
updater.removeAll(); |
|
66 |
updater.launchApp(args); |
|
67 |
} |
|
68 |
|
|
69 |
private File getApplicationDirectory() { |
|
70 |
String appDir = new File("").getAbsolutePath(); |
|
71 |
return new File(appDir); |
|
72 |
} |
|
73 |
|
|
74 |
private File getPluginsDirectory() { |
|
75 |
return new File(getApplicationDirectory(), this.args[1]); |
|
76 |
} |
|
77 |
|
|
78 |
/** |
|
79 |
* @param args |
|
80 |
* @throws Exception |
|
81 |
*/ |
|
82 |
@SuppressWarnings("unchecked") |
|
83 |
private void launchApp(String[] args) throws Exception { |
|
84 |
|
|
85 |
try { |
|
86 |
|
|
87 |
Class launcher_class = Class.forName("com.iver.andami.Launcher"); |
|
88 |
|
|
89 |
Object launcher = launcher_class.newInstance(); |
|
90 |
Method main = |
|
91 |
launcher_class |
|
92 |
.getMethod("main", new Class[] { String[].class }); |
|
93 |
|
|
94 |
main.invoke(launcher, new Object[] { args }); |
|
95 |
|
|
96 |
} catch (ClassNotFoundException e) { |
|
97 |
|
|
98 |
Class launcher_class = Class.forName("org.gvsig.andami.Launcher"); |
|
99 |
Object launcher = launcher_class.newInstance(); |
|
100 |
Method main = |
|
101 |
launcher_class |
|
102 |
.getMethod("main", new Class[] { String[].class }); |
|
103 |
|
|
104 |
main.invoke(launcher, new Object[] { args }); |
|
105 |
} |
|
106 |
} |
|
107 |
|
|
108 |
/** |
|
109 |
* |
|
110 |
*/ |
|
111 |
private void removeAll() { |
|
112 |
File updateDirectory = |
|
113 |
new File(getApplicationDirectory().toString() + File.separator |
|
114 |
+ "update"); |
|
115 |
if (updateDirectory.exists()) { |
|
116 |
deleteDir(updateDirectory); |
|
117 |
} |
|
118 |
|
|
119 |
} |
|
120 |
|
|
121 |
private boolean deleteDir(File dir) { |
|
122 |
if (dir.isDirectory()) { |
|
123 |
String[] children = dir.list(); |
|
124 |
for (int i = 0; i < children.length; i++) { |
|
125 |
boolean success = deleteDir(new File(dir, children[i])); |
|
126 |
if (!success) { |
|
127 |
return false; |
|
128 |
} |
|
129 |
} |
|
130 |
} |
|
131 |
|
|
132 |
// The directory is now empty so delete it |
|
133 |
return dir.delete(); |
|
134 |
} |
|
135 |
|
|
136 |
/** |
|
137 |
* Reads every line of appDirectory/update/scripts.lst and executes the ant |
|
138 |
* file that this line points to |
|
139 |
*/ |
|
140 |
private void executeScripts() { |
|
141 |
|
|
142 |
String antFilesScriptPath = |
|
143 |
getApplicationDirectory() + File.separator + "update" |
|
144 |
+ File.separator + "scripts.lst"; |
|
145 |
File antFilesScript = new File(antFilesScriptPath); |
|
146 |
|
|
147 |
if (antFilesScript.exists()) { |
|
148 |
try { |
|
149 |
|
|
150 |
FileInputStream fstream = new FileInputStream(antFilesScript); |
|
151 |
|
|
152 |
// Get the object of DataInputStream |
|
153 |
DataInputStream in = new DataInputStream(fstream); |
|
154 |
BufferedReader br = |
|
155 |
new BufferedReader(new InputStreamReader(in)); |
|
156 |
String strLine; |
|
157 |
|
|
158 |
// Read File Line By Line |
|
159 |
while ((strLine = br.readLine()) != null) { |
|
160 |
// Print the content on the console |
|
161 |
File antFile = new File(strLine); |
|
162 |
executeAntFile(antFile); |
|
163 |
} |
|
164 |
|
|
165 |
// Close the input stream |
|
166 |
in.close(); |
|
167 |
|
|
168 |
} catch (Exception e) {// Catch exception if any |
|
169 |
System.err.println("Error: " + e.getMessage()); |
|
170 |
} |
|
171 |
|
|
172 |
} |
|
173 |
|
|
174 |
} |
|
175 |
|
|
176 |
/** |
|
177 |
* Copies all files and folders from gvSIG/update to gvSIG/extensions |
|
178 |
* |
|
179 |
* @throws IOException |
|
180 |
* |
|
181 |
*/ |
|
182 |
private void copyFiles() throws IOException { |
|
183 |
File updateFolder = |
|
184 |
new File(getApplicationDirectory().toString() + File.separator |
|
185 |
+ "update"); |
|
186 |
File filesFolder = |
|
187 |
new File(updateFolder.toString() + File.separator + "files"); |
|
188 |
File pluginsDirectory = getPluginsDirectory(); |
|
189 |
|
|
190 |
if (updateFolder.exists()) { |
|
191 |
String[] childrenDirs = filesFolder.list(); |
|
192 |
|
|
193 |
if (childrenDirs != null) { |
|
194 |
for (int i = 0; i < childrenDirs.length; i++) { |
|
195 |
File sourceLocation = |
|
196 |
new File(filesFolder, childrenDirs[i]); |
|
197 |
File targetLocation = |
|
198 |
new File(pluginsDirectory, childrenDirs[i]); |
|
199 |
// lo copio todo |
|
200 |
copyFilesAndFolders(sourceLocation, targetLocation); |
|
201 |
} |
|
202 |
} |
|
203 |
} |
|
204 |
} |
|
205 |
|
|
206 |
private boolean copyFilesAndFolders(File sourceLocation, File targetLocation) |
|
207 |
throws IOException { |
|
208 |
|
|
209 |
if (sourceLocation.isDirectory()) { |
|
210 |
if (!targetLocation.exists()) { |
|
211 |
targetLocation.mkdir(); |
|
212 |
} |
|
213 |
|
|
214 |
String[] children = sourceLocation.list(); |
|
215 |
if (children != null) { |
|
216 |
for (int i = 0; i < children.length; i++) { |
|
217 |
copyFilesAndFolders(new File(sourceLocation, children[i]), |
|
218 |
new File(targetLocation, children[i])); |
|
219 |
} |
|
220 |
} |
|
221 |
} else { |
|
222 |
InputStream in = new FileInputStream(sourceLocation); |
|
223 |
OutputStream out = new FileOutputStream(targetLocation); |
|
224 |
|
|
225 |
// Copy the bits from instream to outstream |
|
226 |
byte[] buf = new byte[1024]; |
|
227 |
int len; |
|
228 |
while ((len = in.read(buf)) > 0) { |
|
229 |
out.write(buf, 0, len); |
|
230 |
} |
|
231 |
in.close(); |
|
232 |
out.close(); |
|
233 |
} |
|
234 |
|
|
235 |
return true; |
|
236 |
} |
|
237 |
|
|
238 |
// PRIVATE VOID EXECUTEANTFILE(FILE FILE) { |
|
239 |
// PROJECT P = NEW PROJECT(); |
|
240 |
// P.SETUSERPROPERTY("ANT.FILE", FILE.GETABSOLUTEPATH()); |
|
241 |
// P.SETPROPERTY("GVSIG_DIR", GETAPPLICATIONDIRECTORY().GETABSOLUTEPATH()); |
|
242 |
// P |
|
243 |
// .SETPROPERTY("EXTENSIONS_DIR", GETPLUGINSDIRECTORY() |
|
244 |
// .GETABSOLUTEPATH()); |
|
245 |
// P.INIT(); |
|
246 |
// PROJECTHELPER HELPER = PROJECTHELPER.GETPROJECTHELPER(); |
|
247 |
// P.ADDREFERENCE("ANT.PROJECTHELPER", HELPER); |
|
248 |
// HELPER.PARSE(P, FILE); |
|
249 |
// P.EXECUTETARGET(P.GETDEFAULTTARGET()); |
|
250 |
// } |
|
251 |
|
|
252 |
private void executeAntFile(File file) { |
|
253 |
Project p = new Project(); |
|
254 |
p.setUserProperty("ant.file", file.getAbsolutePath()); |
|
255 |
p.setUserProperty("gvsig_dir", getApplicationDirectory() |
|
256 |
.getAbsolutePath()); |
|
257 |
p.setUserProperty("extensions_dir", getPluginsDirectory() |
|
258 |
.getAbsolutePath()); |
|
259 |
p.init(); |
|
260 |
p.setBaseDir(file.getParentFile()); |
|
261 |
p.addTaskDefinition("antform", AntForm.class); |
|
262 |
p.addTaskDefinition("antmenu", AntMenu.class); |
|
263 |
p.init(); |
|
264 |
ProjectHelper helper = ProjectHelper.getProjectHelper(); |
|
265 |
p.addReference("ant.projectHelper", helper); |
|
266 |
helper.parse(p, file); |
|
267 |
p.executeTarget(p.getDefaultTarget()); |
|
268 |
} |
|
269 |
|
|
270 |
} |
|
0 | 271 |
Also available in: Unified diff