30 |
30 |
import java.io.File;
|
31 |
31 |
import java.io.InputStream;
|
32 |
32 |
|
33 |
|
import org.gvsig.installer.lib.api.InstallerInfo;
|
34 |
|
import org.gvsig.installer.lib.api.InstallerLocator;
|
|
33 |
import org.apache.tools.ant.Project;
|
|
34 |
import org.apache.tools.ant.ProjectHelper;
|
35 |
35 |
import org.gvsig.installer.lib.api.execution.InstallerExecutionServiceException;
|
36 |
36 |
import org.gvsig.installer.lib.spi.InstallerProviderLocator;
|
37 |
37 |
import org.gvsig.installer.lib.spi.InstallerProviderManager;
|
... | ... | |
44 |
44 |
* @author <a href="mailto:jpiera@gvsig.org">Jorge Piera Llodrá</a>
|
45 |
45 |
*/
|
46 |
46 |
public class PluginInstallerExecutionProvider extends AbstractProvider implements InstallerExecutionProvider {
|
|
47 |
private static final String ANT_FILE_NAME = "install.xml";
|
47 |
48 |
private File pluginsDirectory = null;
|
|
49 |
private File applicationDirectory = null;
|
48 |
50 |
private InputStream inputStream = null;
|
49 |
51 |
private static final InstallerProviderManager installerProviderManager = InstallerProviderLocator.getProviderManager();
|
50 |
52 |
|
... | ... | |
52 |
54 |
super(providerServices);
|
53 |
55 |
}
|
54 |
56 |
|
55 |
|
public InstallerInfo getInstalledInstallerInfo() {
|
56 |
|
// TODO Auto-generated method stub
|
57 |
|
return null;
|
58 |
|
}
|
59 |
|
|
60 |
|
public InstallerInfo getInstallerInfo() {
|
61 |
|
// TODO Auto-generated method stub
|
62 |
|
return null;
|
63 |
|
}
|
64 |
|
|
65 |
|
public void install() throws InstallerExecutionServiceException {
|
|
57 |
public void install(File applicationDirectory, InputStream inputStream) throws InstallerExecutionServiceException {
|
|
58 |
this.applicationDirectory = applicationDirectory;
|
|
59 |
pluginsDirectory = new File(applicationDirectory + File.separator + "gvSIG" + File.separator + "extensiones");
|
|
60 |
if (!pluginsDirectory.exists()){
|
|
61 |
throw new InstallerExecutionServiceException("plugins_directory_not_found");
|
|
62 |
}
|
|
63 |
//Saving all the plugins before to decompress
|
|
64 |
String[] oldPlugins = pluginsDirectory.list();
|
|
65 |
|
66 |
66 |
InstallerProviderServices installerProviderServices = installerProviderManager.createInstallerProviderServices();
|
67 |
67 |
installerProviderServices.decompress(inputStream, pluginsDirectory);
|
68 |
|
}
|
69 |
|
|
70 |
|
public boolean isInstalled() {
|
71 |
|
// TODO Auto-generated method stub
|
72 |
|
return false;
|
|
68 |
|
|
69 |
|
|
70 |
//Execute the ant script if the plugin is new
|
|
71 |
String[] newPlugins = pluginsDirectory.list();
|
|
72 |
for (int i=0 ; i<newPlugins.length ; i++){
|
|
73 |
boolean isNew = true;
|
|
74 |
for (int j=0 ; j<oldPlugins.length ; j++){
|
|
75 |
if (newPlugins[i].equals(oldPlugins[j])){
|
|
76 |
isNew = false;
|
|
77 |
break;
|
|
78 |
}
|
|
79 |
}
|
|
80 |
if (isNew){
|
|
81 |
File antFile = new File(pluginsDirectory + File.separator + newPlugins[i] + File.separator + ANT_FILE_NAME);
|
|
82 |
if (antFile.exists()){
|
|
83 |
executeAntFile(antFile);
|
|
84 |
}
|
|
85 |
}
|
|
86 |
}
|
|
87 |
}
|
|
88 |
|
|
89 |
private void executeAntFile(File file){
|
|
90 |
Project p = new Project();
|
|
91 |
p.setUserProperty("ant.file", file.getAbsolutePath());
|
|
92 |
p.setProperty("gvsig_dir", applicationDirectory.getAbsolutePath());
|
|
93 |
p.setProperty("extensions_dir", pluginsDirectory.getAbsolutePath());
|
|
94 |
p.init();
|
|
95 |
ProjectHelper helper = ProjectHelper.getProjectHelper();
|
|
96 |
p.addReference("ant.projectHelper", helper);
|
|
97 |
helper.parse(p, file);
|
|
98 |
p.executeTarget(p.getDefaultTarget());
|
73 |
99 |
}
|
74 |
|
|
75 |
|
public boolean isUpdated() {
|
76 |
|
// TODO Auto-generated method stub
|
77 |
|
return false;
|
78 |
|
}
|
79 |
|
|
80 |
|
public void setInstaller(InputStream inputStream)
|
81 |
|
throws InstallerExecutionServiceException {
|
82 |
|
this.inputStream = inputStream;
|
83 |
|
}
|
84 |
|
|
85 |
|
public void setApplicationDirectory(File applicationDirectory) throws InstallerExecutionServiceException {
|
86 |
|
pluginsDirectory = new File(applicationDirectory + File.separator + "gvSIG" + File.separator + "extensiones");
|
87 |
|
if (!pluginsDirectory.exists()){
|
88 |
|
throw new InstallerExecutionServiceException("plugins_directory_not_found");
|
89 |
|
}
|
90 |
|
}
|
91 |
100 |
}
|
92 |
101 |
|