gvsig-scripting / org.gvsig.scripting / trunk / org.gvsig.scripting / org.gvsig.scripting.lib / org.gvsig.scripting.lib.impl / src / main / java / org / gvsig / scripting / impl / ScriptingInstallerProvider.java @ 1084
History | View | Annotate | Download (3.99 KB)
1 | 462 | jjdelcerro | /* 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 | |||
23 | 468 | jjdelcerro | package org.gvsig.scripting.impl; |
24 | 462 | jjdelcerro | |
25 | import java.io.File; |
||
26 | import java.io.IOException; |
||
27 | import java.io.InputStream; |
||
28 | 672 | jjdelcerro | import java.util.Iterator; |
29 | 473 | jjdelcerro | import org.apache.commons.io.FileUtils; |
30 | 462 | jjdelcerro | |
31 | import org.gvsig.installer.lib.api.PackageInfo; |
||
32 | import org.gvsig.installer.lib.api.execution.InstallPackageServiceException; |
||
33 | import org.gvsig.installer.lib.spi.InstallPackageProviderServices; |
||
34 | import org.gvsig.installer.lib.spi.InstallerProviderLocator; |
||
35 | import org.gvsig.installer.lib.spi.InstallerProviderManager; |
||
36 | import org.gvsig.installer.lib.spi.execution.InstallPackageProvider; |
||
37 | import org.gvsig.scripting.ScriptingLocator; |
||
38 | import org.gvsig.scripting.ScriptingManager; |
||
39 | import org.gvsig.tools.service.spi.AbstractProvider; |
||
40 | import org.gvsig.tools.service.spi.ProviderServices; |
||
41 | |||
42 | public class ScriptingInstallerProvider extends AbstractProvider |
||
43 | implements InstallPackageProvider {
|
||
44 | |||
45 | public ScriptingInstallerProvider(ProviderServices providerServices) {
|
||
46 | super(providerServices);
|
||
47 | } |
||
48 | |||
49 | public void install(File applicationDirectory, InputStream inputStream, |
||
50 | PackageInfo packageInfo) throws InstallPackageServiceException {
|
||
51 | |||
52 | ScriptingManager scriptingManager = ScriptingLocator.getManager(); |
||
53 | |||
54 | File target = scriptingManager.getRootUserFolder();
|
||
55 | 473 | jjdelcerro | target = new File(target,"addons"); |
56 | 462 | jjdelcerro | |
57 | try {
|
||
58 | 473 | jjdelcerro | if( ! target.exists() ) {
|
59 | FileUtils.forceMkdir(target); |
||
60 | } |
||
61 | 462 | jjdelcerro | InstallerProviderManager installerProviderManager = |
62 | InstallerProviderLocator.getProviderManager(); |
||
63 | InstallPackageProviderServices installerProviderServices = |
||
64 | installerProviderManager.createInstallerProviderServices(); |
||
65 | |||
66 | installerProviderServices.decompress(inputStream, target); |
||
67 | 672 | jjdelcerro | |
68 | // Ajustamos las fechas de modificacion de los ficheros de forma que
|
||
69 | // los fuentes sean mas nuevos que los binarios.
|
||
70 | // Esto forzara que se recompilen la primera vez que se ejecuten.
|
||
71 | // Si no hacemos esto y las fecha de los binarios son futuras, aunque
|
||
72 | // se editen y cambien los fuentes nunca se reccompilaran.
|
||
73 | Iterator<File> it = FileUtils.iterateFiles(target, new String[] {"class"}, true); |
||
74 | while( it.hasNext() ) {
|
||
75 | File f = it.next();
|
||
76 | try {
|
||
77 | FileUtils.touch(f); |
||
78 | } catch (IOException e) { |
||
79 | // Do nothing
|
||
80 | } |
||
81 | } |
||
82 | it = FileUtils.iterateFiles(target, new String[] {"py","r","scala","groovy"}, true); |
||
83 | while( it.hasNext() ) {
|
||
84 | File f = it.next();
|
||
85 | try {
|
||
86 | FileUtils.touch(f); |
||
87 | } catch (IOException e) { |
||
88 | // Do nothing
|
||
89 | } |
||
90 | } |
||
91 | 462 | jjdelcerro | |
92 | } catch (Exception e) { |
||
93 | throw new InstallPackageServiceException(e); |
||
94 | } |
||
95 | } |
||
96 | |||
97 | public void installLater(File applicationDirectory, |
||
98 | InputStream inputStream, PackageInfo packageInfo)
|
||
99 | throws InstallPackageServiceException, IOException { |
||
100 | // TODO Auto-generated method stub
|
||
101 | |||
102 | } |
||
103 | } |