Statistiques
| Révision :

root / tmp / CWBInstaller / src / cwbinstaller / commands / DoInstallStep.java @ 256

Historique | Voir | Annoter | Télécharger (3,1 ko)

1
package cwbinstaller.commands;
2

    
3
import java.io.File;
4

    
5
import org.eclipse.core.commands.ExecutionEvent;
6
import org.eclipse.core.commands.ExecutionException;
7
import org.eclipse.jface.util.Util;
8
import org.osgi.framework.Version;
9
import org.txm.rcpapplication.TxmPreferences;
10
import org.txm.rcpapplication.preferences.CQPPreferencePage;
11
import org.txm.utils.BundleUtils;
12
import org.txm.utils.logger.Log;
13

    
14
public class DoInstallStep extends org.txm.rcpapplication.commands.TxmCommand {
15
        protected String name = "cwbbinaries.commands.DoInstallStep"; //$NON-NLS-1$
16
        public static final String VERSION = "cwbinstaller.commands.version";
17
        
18
        @Override
19
        public Object execute(ExecutionEvent event) throws ExecutionException {
20
                // TODO Auto-generated method stub
21
                return null;
22
        }
23

    
24
        @Override
25
        public void install() {        
26
                
27
        }
28
        
29
        @Override
30
        public void preInstall() {        
31
                String CQPFRAGMENT = "CQP."+System.getProperty("osgi.os");
32
                
33
                Log.info("CQP.DoInstallStep.install()");
34
                String saved = TxmPreferences.getString(VERSION, "");
35
                Version currentVersion = BundleUtils.getBundleVersion(CQPFRAGMENT); // the CQPFRAGMENT plugin contains the right version
36
                
37
                if (saved != null && saved.length() > 0) {
38
                        Version savedVersion = new Version(saved);
39
                        if (currentVersion.compareTo(savedVersion) <= 0) {
40
                                Log.info("No post-installation of CQP to do");
41
                                return; // nothing to do
42
                        }
43
                }
44
                System.out.println("Updating CWB preferences for CQP version="+currentVersion);
45
                
46
                String os = "win";
47
                String ext = "";
48
                if (Util.isWindows()) { //$NON-NLS-1$
49
                        if (System.getProperty("os.arch").contains("64")) { os = "win64"; } 
50
                        else { os = "win32"; }
51
                        ext = ".exe";
52
                } else if (Util.isMac()) { //$NON-NLS-1$
53
                        os = "macosx";
54
                } else {
55
                        os = "linux32";
56
                        if (System.getProperty("os.arch").contains("64")) 
57
                                os = "linux64";
58
                }
59

    
60
                File bundleDir = BundleUtils.getBundleFile(CQPFRAGMENT);
61
                if (bundleDir == null) {
62
                        System.out.println("Error while retrieving TreeTaggerInstaller bundle directory.");
63
                        return;
64
                }
65
                File cwbDir = new File(bundleDir, "res");
66
                File initFile = new File(cwbDir, "cqpserver.init");
67
                File OSDir = new File(cwbDir, os);
68
                File execFile = new File(OSDir, "cqpserver"+ext);
69

    
70
                TxmPreferences.set(CQPPreferencePage.CQI_SERVER_PATH_TO_CQPLIB, OSDir.getAbsolutePath());
71
                TxmPreferences.set(CQPPreferencePage.CQI_SERVER_PATH_TO_INIT_FILE, initFile.getAbsolutePath());
72
                TxmPreferences.set(CQPPreferencePage.CQI_SERVER_PATH_TO_EXECUTABLE, execFile.getAbsolutePath());
73
                if (!Util.isWindows()) { 
74
                        try {
75
                                Log.info("Setting execution file rights to: "+OSDir.getAbsolutePath());
76
                                Runtime.getRuntime().exec("chmod -R +x "+OSDir.getAbsolutePath()).waitFor();
77
                        } catch (Exception e) {
78
                                System.out.println("Error while setting execution file rights to: "+OSDir.getAbsolutePath());
79
                                e.printStackTrace();
80
                        }
81
                }
82
        
83
                if (!execFile.canExecute()) {
84
                        System.out.println("File right setting error, cannot execute: "+execFile);
85
                }
86
                Log.warning("SearchEngine preferences set with: "+OSDir.getAbsolutePath()+ ", "+initFile.getAbsolutePath()+ " and "+execFile.getAbsolutePath());
87
                TxmPreferences.set(VERSION, currentVersion.toString());
88
        }
89
}