OpenConcerto

Dépôt officiel du code source de l'ERP OpenConcerto
sonarqube

svn://code.openconcerto.org/openconcerto

Rev

Rev 174 | Go to most recent revision | Only display areas with differences | Regard whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 174 Rev 180
1
/*
1
/*
2
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
2
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
3
 * 
3
 * 
4
 * Copyright 2011 OpenConcerto, by ILM Informatique. All rights reserved.
4
 * Copyright 2011 OpenConcerto, by ILM Informatique. All rights reserved.
5
 * 
5
 * 
6
 * The contents of this file are subject to the terms of the GNU General Public License Version 3
6
 * The contents of this file are subject to the terms of the GNU General Public License Version 3
7
 * only ("GPL"). You may not use this file except in compliance with the License. You can obtain a
7
 * only ("GPL"). You may not use this file except in compliance with the License. You can obtain a
8
 * copy of the License at http://www.gnu.org/licenses/gpl-3.0.html See the License for the specific
8
 * copy of the License at http://www.gnu.org/licenses/gpl-3.0.html See the License for the specific
9
 * language governing permissions and limitations under the License.
9
 * language governing permissions and limitations under the License.
10
 * 
10
 * 
11
 * When distributing the software, include this License Header Notice in each file.
11
 * When distributing the software, include this License Header Notice in each file.
12
 */
12
 */
13
 
13
 
14
 package org.jopendocument.link;
14
 package org.jopendocument.link;
15
 
15
 
16
import org.openconcerto.utils.DesktopEnvironment;
16
import org.openconcerto.utils.DesktopEnvironment;
17
import org.openconcerto.utils.DesktopEnvironment.Mac;
17
import org.openconcerto.utils.DesktopEnvironment.Mac;
18
 
18
 
19
import java.io.File;
19
import java.io.File;
20
import java.io.FileFilter;
20
import java.io.FileFilter;
21
import java.io.IOException;
21
import java.io.IOException;
22
import java.net.MalformedURLException;
22
import java.net.MalformedURLException;
23
import java.net.URL;
23
import java.net.URL;
24
import java.util.ArrayList;
24
import java.util.ArrayList;
25
import java.util.Arrays;
25
import java.util.Arrays;
26
import java.util.Collections;
26
import java.util.Collections;
27
import java.util.HashMap;
27
import java.util.HashMap;
28
import java.util.List;
28
import java.util.List;
29
import java.util.Map;
29
import java.util.Map;
30
import java.util.Set;
30
import java.util.Set;
31
import java.util.regex.Matcher;
31
import java.util.regex.Matcher;
32
import java.util.regex.Pattern;
32
import java.util.regex.Pattern;
33
 
33
 
34
/**
34
/**
35
 * This class finds out where OpenOffice.org is installed.
35
 * This class finds out where OpenOffice.org is installed.
36
 * 
36
 * 
37
 * @author Sylvain CUAZ
37
 * @author Sylvain CUAZ
38
 * @see #getInstance()
38
 * @see #getInstance()
39
 */
39
 */
40
public class OOInstallation {
40
public class OOInstallation {
41
 
41
 
42
    public static final String PREFER_OPENOFFICE = "preferOpenOffice";
42
    public static final String PREFER_OPENOFFICE = "preferOpenOffice";
43
 
43
 
44
    private static OOInstallation instance;
44
    private static OOInstallation instance;
45
 
45
 
46
    /**
46
    /**
47
     * Return the installation for this machine.
47
     * Return the installation for this machine.
48
     * 
48
     * 
49
     * @return the installation for this machine, <code>null</code> if not installed.
49
     * @return the installation for this machine, <code>null</code> if not installed.
50
     * @throws IOException if an error occurs while searching.
50
     * @throws IOException if an error occurs while searching.
51
     */
51
     */
52
    public static OOInstallation getInstance() throws IOException {
52
    public static OOInstallation getInstance() throws IOException {
53
        // since null means never detected or not installed, this will keep searching when not
53
        // since null means never detected or not installed, this will keep searching when not
54
        // installed
54
        // installed
55
        if (instance == null) {
55
        if (instance == null) {
56
            instance = detectInstall();
56
            instance = detectInstall();
57
        }
57
        }
58
        return instance;
58
        return instance;
59
    }
59
    }
60
 
60
 
61
    /**
61
    /**
62
     * Forget the current installation to pick up a change (e.g. updated version).
62
     * Forget the current installation to pick up a change (e.g. updated version).
63
     */
63
     */
64
    public static void reset() {
64
    public static void reset() {
65
        instance = null;
65
        instance = null;
66
    }
66
    }
67
 
67
 
68
    // UREINSTALLLOCATION REG_SZ C:\Program Files\OpenOffice.org 3\URE\
68
    // UREINSTALLLOCATION REG_SZ C:\Program Files\OpenOffice.org 3\URE\
69
    // \1 is the name, \2 the value
69
    // \1 is the name, \2 the value
70
    // cannot use \p{} since some names/values can be non-ASCII
70
    // cannot use \p{} since some names/values can be non-ASCII
71
    private static final Pattern stringValuePattern = Pattern.compile("^\\s*(.+?)\\s+REG_SZ\\s+(.+?)$", Pattern.MULTILINE);
71
    private static final Pattern stringValuePattern = Pattern.compile("^\\s*(.+?)\\s+REG_SZ\\s+(.+?)$", Pattern.MULTILINE);
72
 
72
 
73
    private static final String LOBundleID = "org.libreoffice.script";
73
    private static final String LOBundleID = "org.libreoffice.script";
74
    private static final String OOBundleID = "org.openoffice.script";
74
    private static final String OOBundleID = "org.openoffice.script";
75
 
75
 
76
    // return the standard out (not the standard error)
76
    // return the standard out (not the standard error)
77
    private static String cmdSubstitution(String... args) throws IOException {
77
    private static String cmdSubstitution(String... args) throws IOException {
78
        final ProcessBuilder pb = new ProcessBuilder(args);
78
        final ProcessBuilder pb = new ProcessBuilder(args);
79
        pb.redirectErrorStream(false);
79
        pb.redirectErrorStream(false);
80
        return DesktopEnvironment.cmdSubstitution(pb.start());
80
        return DesktopEnvironment.cmdSubstitution(pb.start());
81
    }
81
    }
82
 
82
 
83
    static final URL toURL(final File f) {
83
    static final URL toURL(final File f) {
84
        try {
84
        try {
85
            return f.toURI().toURL();
85
            return f.toURI().toURL();
86
        } catch (MalformedURLException e) {
86
        } catch (MalformedURLException e) {
87
            // shouldn't happen since constructed from a file
87
            // shouldn't happen since constructed from a file
88
            throw new IllegalStateException("Couldn't transform to URL " + f, e);
88
            throw new IllegalStateException("Couldn't transform to URL " + f, e);
89
        }
89
        }
90
    }
90
    }
91
 
91
 
92
    // handle windows x64
92
    // handle windows x64
93
    private static String findRootPath() {
93
    private static String findRootPath() {
94
        final String[] loRootPaths = { "HKEY_LOCAL_MACHINE\\SOFTWARE\\LibreOffice", "HKEY_LOCAL_MACHINE\\SOFTWARE\\Wow6432Node\\LibreOffice" };
94
        final String[] loRootPaths = { "HKEY_LOCAL_MACHINE\\SOFTWARE\\LibreOffice", "HKEY_LOCAL_MACHINE\\SOFTWARE\\Wow6432Node\\LibreOffice" };
95
        final String[] ooRootPaths = { "HKEY_LOCAL_MACHINE\\SOFTWARE\\OpenOffice", "HKEY_LOCAL_MACHINE\\SOFTWARE\\Wow6432Node\\OpenOffice", "HKEY_LOCAL_MACHINE\\SOFTWARE\\OpenOffice.org",
95
        final String[] ooRootPaths = { "HKEY_LOCAL_MACHINE\\SOFTWARE\\OpenOffice", "HKEY_LOCAL_MACHINE\\SOFTWARE\\Wow6432Node\\OpenOffice", "HKEY_LOCAL_MACHINE\\SOFTWARE\\OpenOffice.org",
96
                "HKEY_LOCAL_MACHINE\\SOFTWARE\\Wow6432Node\\OpenOffice.org" };
96
                "HKEY_LOCAL_MACHINE\\SOFTWARE\\Wow6432Node\\OpenOffice.org" };
97
        final List<String> rootPaths = new ArrayList<String>(loRootPaths.length + ooRootPaths.length);
97
        final List<String> rootPaths = new ArrayList<String>(loRootPaths.length + ooRootPaths.length);
98
        if (Boolean.getBoolean(PREFER_OPENOFFICE)) {
98
        if (Boolean.getBoolean(PREFER_OPENOFFICE)) {
99
            rootPaths.addAll(Arrays.asList(ooRootPaths));
99
            rootPaths.addAll(Arrays.asList(ooRootPaths));
100
            rootPaths.addAll(Arrays.asList(loRootPaths));
100
            rootPaths.addAll(Arrays.asList(loRootPaths));
101
        } else {
101
        } else {
102
            rootPaths.addAll(Arrays.asList(loRootPaths));
102
            rootPaths.addAll(Arrays.asList(loRootPaths));
103
            rootPaths.addAll(Arrays.asList(ooRootPaths));
103
            rootPaths.addAll(Arrays.asList(ooRootPaths));
104
        }
104
        }
105
 
105
 
106
        for (final String p : rootPaths) {
106
        for (final String p : rootPaths) {
107
            // On force à chercher dans le registre 64 bits sinon il va chercher dans le registre 32
107
            // On force à chercher dans le registre 64 bits sinon il va chercher dans le registre 32
108
            // bits si os 64b et VM 32b
108
            // bits si os 64b et VM 32b
109
            if (DesktopEnvironment.test("reg", "query", p, "/reg:64"))
109
            if (DesktopEnvironment.test("reg", "query", p, "/reg:64"))
110
                return p;
110
                return p;
111
        }
111
        }
112
 
112
 
113
        return null;
113
        return null;
114
    }
114
    }
115
 
115
 
116
    private static File findBundleDir() throws IOException {
116
    private static File findBundleDir() throws IOException {
117
        final Mac de = (Mac) DesktopEnvironment.getDE();
117
        final Mac de = (Mac) DesktopEnvironment.getDE();
118
        final String[] bundleIDs = Boolean.getBoolean(PREFER_OPENOFFICE) ? new String[] { OOBundleID, LOBundleID } : new String[] { LOBundleID, OOBundleID };
118
        final String[] bundleIDs = Boolean.getBoolean(PREFER_OPENOFFICE) ? new String[] { OOBundleID, LOBundleID } : new String[] { LOBundleID, OOBundleID };
119
        for (final String bundleID : bundleIDs) {
119
        for (final String bundleID : bundleIDs) {
120
            final File url = de.getAppDir(bundleID);
120
            final File url = de.getAppDir(bundleID);
121
            if (url != null)
121
            if (url != null)
122
                return url;
122
                return url;
123
        }
123
        }
124
        return null;
124
        return null;
125
    }
125
    }
126
 
126
 
127
    // all string values for the passed registry path
127
    // all string values for the passed registry path
128
    private static Map<String, String> getStringValues(final String path, final String option) throws IOException {
128
    private static Map<String, String> getStringValues(final String path, final String option) throws IOException {
129
        final Map<String, String> values = new HashMap<String, String>();
129
        final Map<String, String> values = new HashMap<String, String>();
130
        // On force /reg:64 (utile si on utilise une VM 32 avec un systeme 64 bits)
130
        // On force /reg:64 (utile si on utilise une VM 32 avec un systeme 64 bits)
131
        final String out = DesktopEnvironment.cmdSubstitution(Runtime.getRuntime().exec(new String[] { "reg", "query", path, option, "/reg:64" }));
131
        final String out = DesktopEnvironment.cmdSubstitution(Runtime.getRuntime().exec(new String[] { "reg", "query", path, option, "/reg:64" }));
132
        final Matcher matcher = stringValuePattern.matcher(out);
132
        final Matcher matcher = stringValuePattern.matcher(out);
133
        while (matcher.find()) {
133
        while (matcher.find()) {
134
            values.put(matcher.group(1), matcher.group(2));
134
            values.put(matcher.group(1), matcher.group(2));
135
        }
135
        }
136
        return values;
136
        return values;
137
    }
137
    }
138
 
138
 
139
    // add jar directories for OpenOffice 2 or 3
139
    // add jar directories for OpenOffice 2 or 3
140
    private static final void addPaths(final List<File> cp, final File progDir, final String basisDir, final String ureDir) throws IOException {
140
    private static final void addPaths(final List<File> cp, final File progDir, final String basisDir, final String ureDir) throws IOException {
141
        // oo2
141
        // oo2
142
        // all in C:\Program Files\OpenOffice.org 2.4\program\classes
142
        // all in C:\Program Files\OpenOffice.org 2.4\program\classes
143
        add(cp, new File(progDir, "classes"));
143
        add(cp, new File(progDir, "classes"));
144
 
144
 
145
        // oo3
145
        // oo3
146
        // some in C:\Program Files\OpenOffice.org 3\URE\java
146
        // some in C:\Program Files\OpenOffice.org 3\URE\java
147
        // the rest in C:\Program Files\OpenOffice.org 3\Basis\program\classes
147
        // the rest in C:\Program Files\OpenOffice.org 3\Basis\program\classes
148
        if (ureDir != null) {
148
        if (ureDir != null) {
149
            // Windows
149
            // Windows
150
            add(cp, ureDir + File.separator + "java");
150
            add(cp, ureDir + File.separator + "java");
151
            // MacOS and Linux
151
            // MacOS and Linux
152
            add(cp, ureDir + File.separator + "share" + File.separator + "java");
152
            add(cp, ureDir + File.separator + "share" + File.separator + "java");
153
        }
153
        }
154
        if (basisDir != null) {
154
        if (basisDir != null) {
155
            add(cp, basisDir + File.separator + "program" + File.separator + "classes");
155
            add(cp, basisDir + File.separator + "program" + File.separator + "classes");
156
            // at least for LO 5.3 on MacOS
156
            // at least for LO 5.3 on MacOS
157
            add(cp, basisDir + File.separator + "Resources" + File.separator + "java");
157
            add(cp, basisDir + File.separator + "Resources" + File.separator + "java");
158
        }
158
        }
159
    }
159
    }
160
 
160
 
161
    private static final void addUnixPaths(final List<File> cp, final File progDir) throws IOException {
161
    private static final void addUnixPaths(final List<File> cp, final File progDir) throws IOException {
162
        final File baseDir = progDir.getParentFile();
162
        final File baseDir = progDir.getParentFile();
163
        final File basisDir = new File(baseDir, "basis-link");
163
        final File basisDir = new File(baseDir, "basis-link");
164
        // basis-link was dropped from LO 3.5
164
        // basis-link was dropped from LO 3.5
165
        final String basisPath = (basisDir.exists() ? basisDir : baseDir).getPath();
165
        final String basisPath = (basisDir.exists() ? basisDir : baseDir).getPath();
166
        final String ureDir = basisPath + File.separator + "ure-link";
166
        final String ureDir = basisPath + File.separator + "ure-link";
167
        addPaths(cp, progDir, basisPath, ureDir);
167
        addPaths(cp, progDir, basisPath, ureDir);
168
    }
168
    }
169
 
169
 
170
    private static void add(final List<File> res, final File f) {
170
    private static void add(final List<File> res, final File f) {
171
        // e.g. on LO 3.5 BASIS is no longer 'Basis/' but './'
171
        // e.g. on LO 3.5 BASIS is no longer 'Basis/' but './'
172
        if (f != null && f.isDirectory() && !res.contains(f)) {
172
        if (f != null && f.isDirectory() && !res.contains(f)) {
173
            res.add(f);
173
            res.add(f);
174
        }
174
        }
175
    }
175
    }
176
 
176
 
177
    private static void add(final List<File> res, final String f) {
177
    private static void add(final List<File> res, final String f) {
178
        if (f != null)
178
        if (f != null)
179
            add(res, new File(f));
179
            add(res, new File(f));
180
    }
180
    }
181
 
181
 
182
    private static OOInstallation detectInstall() throws IOException {
182
    private static OOInstallation detectInstall() throws IOException {
183
        final File exe;
183
        final File exe;
184
        final List<File> cp = new ArrayList<File>(3);
184
        final List<File> cp = new ArrayList<File>(3);
185
 
185
 
186
        final String os = System.getProperty("os.name");
186
        final String os = System.getProperty("os.name");
187
        if (os.startsWith("Windows")) {
187
        if (os.startsWith("Windows")) {
188
            final String rootPath = findRootPath();
188
            final String rootPath = findRootPath();
189
            // not installed
189
            // not installed
190
            if (rootPath == null)
190
            if (rootPath == null)
191
                return null;
191
                return null;
192
            final boolean libreOffice = rootPath.contains("LibreOffice");
192
            final boolean libreOffice = rootPath.contains("LibreOffice");
193
 
193
 
194
            // Only the default value so pass '/ve'
194
            // Only the default value so pass '/ve'
195
            final Map<String, String> unoValues = getStringValues(rootPath + "\\UNO\\InstallPath", "/ve");
195
            final Map<String, String> unoValues = getStringValues(rootPath + "\\UNO\\InstallPath", "/ve");
196
            if (unoValues.size() != 1)
196
            if (unoValues.size() != 1)
197
                throw new IOException("No UNO install path: " + unoValues);
197
                throw new IOException("No UNO install path: " + unoValues);
198
            // e.g. C:\Program Files\OpenOffice.org 2.4\program
198
            // e.g. C:\Program Files\OpenOffice.org 2.4\program
199
            final File unoPath = new File(unoValues.values().iterator().next());
199
            final File unoPath = new File(unoValues.values().iterator().next());
200
            if (!unoPath.isDirectory())
200
            if (!unoPath.isDirectory())
201
                throw new IOException(unoPath + " is not a directory");
201
                throw new IOException(unoPath + " is not a directory");
202
            exe = new File(unoPath, "soffice.exe");
202
            exe = new File(unoPath, "soffice.exe");
203
 
203
 
204
            // Perhaps check out parallel install but in Windows it's really cumbersome :
204
            // Perhaps check out parallel install but in Windows it's really cumbersome :
205
            // http://wiki.documentfoundation.org/Installing_in_parallel
205
            // http://wiki.documentfoundation.org/Installing_in_parallel
206
 
206
 
207
            final String layerPath;
207
            final String layerPath;
208
            if (!libreOffice) {
208
            if (!libreOffice) {
209
                layerPath = rootPath.contains("OpenOffice.org") ? "\\Layers\\OpenOffice.org" : "\\Layers\\OpenOffice";
209
                layerPath = rootPath.contains("OpenOffice.org") ? "\\Layers\\OpenOffice.org" : "\\Layers\\OpenOffice";
210
            } else if (DesktopEnvironment.test("reg", "query", rootPath + "\\Layers")) {
210
            } else if (DesktopEnvironment.test("reg", "query", rootPath + "\\Layers")) {
211
                layerPath = "\\Layers\\LibreOffice";
211
                layerPath = "\\Layers\\LibreOffice";
212
            } else {
212
            } else {
213
                // LO 3.4
213
                // LO 3.4
214
                layerPath = "\\Layers_\\LibreOffice";
214
                layerPath = "\\Layers_\\LibreOffice";
215
            }
215
            }
216
            // '/s' since variables are one level (the version) deeper
216
            // '/s' since variables are one level (the version) deeper
217
            final Map<String, String> layersValues = getStringValues(rootPath + layerPath, "/s");
217
            final Map<String, String> layersValues = getStringValues(rootPath + layerPath, "/s");
218
            addPaths(cp, unoPath, layersValues.get("BASISINSTALLLOCATION"), layersValues.get("UREINSTALLLOCATION"));
218
            addPaths(cp, unoPath, layersValues.get("BASISINSTALLLOCATION"), layersValues.get("UREINSTALLLOCATION"));
219
        } else if (os.startsWith("Mac OS")) {
219
        } else if (os.startsWith("Mac OS")) {
220
            final File appPkg = findBundleDir();
220
            final File appPkg = findBundleDir();
221
            if (appPkg == null)
221
            if (appPkg == null)
222
                return null;
222
                return null;
223
            // need to call soffice from the MacOS directory otherwise it fails
223
            // need to call soffice from the MacOS directory otherwise it fails
224
            exe = new File(appPkg, "Contents/MacOS/soffice");
224
            exe = new File(appPkg, "Contents/MacOS/soffice");
225
            addUnixPaths(cp, new File(appPkg, "Contents/program"));
225
            addUnixPaths(cp, new File(appPkg, "Contents/program"));
226
        } else if (os.startsWith("Linux")) {
226
        } else if (os.startsWith("Linux")) {
227
            // soffice is usually a symlink in /usr/bin
227
            // soffice is usually a symlink in /usr/bin
228
            // if not found prints nothing at all
228
            // if not found prints nothing at all
229
            final String binPath = cmdSubstitution("which", "soffice").trim();
229
            final String binPath = cmdSubstitution("which", "soffice").trim();
230
            if (binPath.length() != 0) {
230
            if (binPath.length() != 0) {
231
                exe = new File(binPath).getCanonicalFile();
231
                exe = new File(binPath).getCanonicalFile();
232
            } else {
232
            } else {
233
                // e.g. Ubuntu 6.06
233
                // e.g. Ubuntu 6.06
234
                final File defaultInstall = new File("/usr/lib/openoffice/program/soffice");
234
                final File defaultInstall = new File("/usr/lib/openoffice/program/soffice");
235
                exe = defaultInstall.canExecute() ? defaultInstall : null;
235
                exe = defaultInstall.canExecute() ? defaultInstall : null;
236
            }
236
            }
237
            if (exe != null)
237
            if (exe != null)
238
                addUnixPaths(cp, exe.getParentFile());
238
                addUnixPaths(cp, exe.getParentFile());
239
        } else
239
        } else
240
            exe = null;
240
            exe = null;
241
        return exe == null ? null : new OOInstallation(exe, cp);
241
        return exe == null ? null : new OOInstallation(exe, cp);
242
    }
242
    }
243
 
243
 
244
    private final File executable;
244
    private final File executable;
245
    private final List<File> classpath;
245
    private final List<File> classpath;
246
 
246
 
247
    // TODO parse program/version.ini
247
    // TODO parse program/version.ini
248
 
248
 
249
    private OOInstallation(File executable, List<File> classpath) throws IOException {
249
    private OOInstallation(File executable, List<File> classpath) throws IOException {
250
        super();
250
        super();
251
        if (!executable.isFile())
251
        if (!executable.isFile())
252
            throw new IOException("executable not found at " + executable);
252
            throw new IOException("executable not found at " + executable);
253
 
253
 
254
        this.executable = executable;
254
        this.executable = executable;
255
        this.classpath = Collections.unmodifiableList(new ArrayList<File>(classpath));
255
        this.classpath = Collections.unmodifiableList(new ArrayList<File>(classpath));
256
    }
256
    }
257
 
257
 
258
    public final File getExecutable() {
258
    public final File getExecutable() {
259
        return this.executable;
259
        return this.executable;
260
    }
260
    }
261
 
261
 
262
    public final List<File> getClasspath() {
262
    public final List<File> getClasspath() {
263
        return this.classpath;
263
        return this.classpath;
264
    }
264
    }
265
 
265
 
266
    public final List<URL> getURLs(final Set<String> jars) {
266
    public final List<URL> getURLs(final Set<String> jars) {
-
 
267
        final List<File> foundJars = findJarFiles(jars);
-
 
268
        final List<URL> res = new ArrayList<>(foundJars.size());
-
 
269
        for (final File foundJar : foundJars) {
-
 
270
            res.add(toURL(foundJar));
-
 
271
        }
-
 
272
        return res;
-
 
273
    }
-
 
274
 
-
 
275
    public final List<File> findJarFiles(final Set<String> jars) {
267
        final int stop = this.getClasspath().size();
276
        final int stop = this.getClasspath().size();
268
        final List<URL> res = new ArrayList<URL>();
277
        final List<File> res = new ArrayList<>();
269
        for (int i = 0; i < stop; i++) {
278
        for (int i = 0; i < stop; i++) {
270
            final File[] foundJars = this.getClasspath().get(i).listFiles(new FileFilter() {
279
            final File[] foundJars = this.getClasspath().get(i).listFiles(new FileFilter() {
271
                @Override
280
                @Override
272
                public boolean accept(File f) {
281
                public boolean accept(File f) {
273
                    return jars.contains(f.getName());
282
                    return jars.contains(f.getName());
274
                }
283
                }
275
            });
284
            });
276
            for (final File foundJar : foundJars) {
285
            for (final File foundJar : foundJars) {
277
                res.add(toURL(foundJar));
286
                res.add(foundJar);
278
            }
287
            }
279
        }
288
        }
280
        return res;
289
        return res;
281
    }
290
    }
282
 
291
 
283
    @Override
292
    @Override
284
    public String toString() {
293
    public String toString() {
285
        return this.getClass().getSimpleName() + " exe: " + this.getExecutable() + " classpath: " + this.getClasspath();
294
        return this.getClass().getSimpleName() + " exe: " + this.getExecutable() + " classpath: " + this.getClasspath();
286
    }
295
    }
287
 
296
 
288
    public static void main(String[] args) {
297
    public static void main(String[] args) {
289
        try {
298
        try {
290
            final OOInstallation i = getInstance();
299
            final OOInstallation i = getInstance();
291
            System.out.println(i == null ? "Not installed" : i);
300
            System.out.println(i == null ? "Not installed" : i);
292
        } catch (IOException e) {
301
        } catch (IOException e) {
293
            System.out.println("Couldn't detect OpenOffice.org: " + e.getLocalizedMessage());
302
            System.out.println("Couldn't detect OpenOffice.org: " + e.getLocalizedMessage());
294
            e.printStackTrace();
303
            e.printStackTrace();
295
        }
304
        }
296
    }
305
    }
297
 
306
 
298
    /**
307
    /**
299
     * TODO add methods to call the program, but there's currently a bug preventing from running a
308
     * TODO add methods to call the program, but there's currently a bug preventing from running a
300
     * headless instance when there's already a running instance :
309
     * headless instance when there's already a running instance :
301
     * https://bugs.documentfoundation.org/show_bug.cgi?id=37531#c45
310
     * https://bugs.documentfoundation.org/show_bug.cgi?id=37531#c45
302
     * https://ask.libreoffice.org/en/question/1686/how-to-not-connect-to-a-running-instance/?answer=1701#post-id-1701
311
     * https://ask.libreoffice.org/en/question/1686/how-to-not-connect-to-a-running-instance/?answer=1701#post-id-1701
303
     * 
312
     * 
304
     * <pre>
313
     * <pre>
305
     tmpdir=`mktemp -d /tmp/libreoffice-XXXXXXXXXXXX`
314
     tmpdir=`mktemp -d /tmp/libreoffice-XXXXXXXXXXXX`
306
     trap "rm -rf $tmpdir" EXIT INT
315
     trap "rm -rf $tmpdir" EXIT INT
307
     libreoffice "-env:UserInstallation=file://$tmpdir" --headless --nolockcheck --convert-to pdf "$out"
316
     libreoffice "-env:UserInstallation=file://$tmpdir" --headless --nolockcheck --convert-to pdf "$out"
308
     * </pre>
317
     * </pre>
309
     */
318
     */
310
}
319
}