OpenConcerto

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

svn://code.openconcerto.org/openconcerto

Rev

Rev 180 | Show entire file | Regard whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 180 Rev 182
Line 1... Line 1...
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-2019 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.
Line 158... Line 158...
158
            return System.getProperty("os.version");
158
            return System.getProperty("os.version");
159
        }
159
        }
160
    }
160
    }
161
 
161
 
162
    static public final class Windows extends DEisOS {
162
    static public final class Windows extends DEisOS {
163
        static private boolean needsQuoting(String s) {
-
 
164
            final int len = s.length();
-
 
165
            if (len == 0) // empty string have to be quoted
-
 
166
                return true;
-
 
167
            for (int i = 0; i < len; i++) {
-
 
168
                switch (s.charAt(i)) {
-
 
169
                case ' ':
-
 
170
                case '\t':
-
 
171
                case '\\':
-
 
172
                case '"':
-
 
173
                    return true;
-
 
174
                }
-
 
175
            }
-
 
176
            return false;
-
 
177
        }
-
 
178
 
-
 
179
        // on Windows program themselves are required to parse the command line, thus a lot of them
-
 
180
        // do it differently, see http://www.autohotkey.net/~deleyd/parameters/parameters.htm
-
 
181
 
-
 
182
        static private final Pattern quotePatrn = Pattern.compile("([\\\\]*)\"");
-
 
183
        static private final Pattern endSlashPatrn = Pattern.compile("([\\\\]*)\\z");
-
 
184
 
-
 
185
        // see http://bugs.sun.com/view_bug.do?bug_id=6468220
-
 
186
        // e.g. find.exe, choice.exe
-
 
187
        public String quoteParamForMsftC(String s) {
-
 
188
            if (!needsQuoting(s))
-
 
189
                return s;
-
 
190
            if (s.length() > 0) {
-
 
191
                // replace '(\*)"' by '$1$1\"', e.g. '\quote " \"' by '\quote \" \\\"'
-
 
192
                // $1 needed so that the backslash we add isn't escaped itself by a preceding
-
 
193
                // backslash
-
 
194
                s = quotePatrn.matcher(s).replaceAll("$1$1\\\\\"");
-
 
195
                // replace '(\*)\z' by '$1$1', e.g. 'foo\' by 'foo\\'
-
 
196
                // needed to not escape closing quote
-
 
197
                s = endSlashPatrn.matcher(s).replaceAll("$1$1");
-
 
198
            }
-
 
199
            return '"' + s + '"';
-
 
200
        }
-
 
201
 
-
 
202
        // e.g. bash.exe
163
        // e.g. bash.exe
203
        public String quoteParamForGCC(String s) {
164
        public String quoteParamForGCC(String s) {
204
            return StringUtils.doubleQuote(s);
165
            return StringUtils.doubleQuote(s);
205
        }
166
        }
206
 
-
 
207
        public String quoteParamForScript(final String s) {
-
 
208
            if (s.indexOf('"') >= 0)
-
 
209
                throw new IllegalArgumentException("Can not pass a double quote as part of a parameter");
-
 
210
            return '"' + s + '"';
-
 
211
        }
-
 
212
 
-
 
213
        @Override
-
 
214
        public String quoteParamForExec(final String s) {
-
 
215
            return quoteParamForMsftC(s);
-
 
216
        }
-
 
217
    }
167
    }
218
 
168
 
219
    static public final class Mac extends DEisOS {
169
    static public final class Mac extends DEisOS {
220
 
170
 
221
        // From CarbonCore/Folders.h
171
        // From CarbonCore/Folders.h
Line 396... Line 346...
396
    public File getDocumentsFolder() {
346
    public File getDocumentsFolder() {
397
        return FileSystemView.getFileSystemView().getDefaultDirectory();
347
        return FileSystemView.getFileSystemView().getDefaultDirectory();
398
    }
348
    }
399
 
349
 
400
    // on some systems arguments are not passed correctly by ProcessBuilder
350
    // on some systems arguments are not passed correctly by ProcessBuilder
401
    public String quoteParamForExec(String s) {
351
    public final String quoteParamForExec(String s) {
402
        return s;
352
        return Platform.getInstance().getProcessArg(s);
403
    }
353
    }
404
 
354
 
405
    @Override
355
    @Override
406
    public String toString() {
356
    public String toString() {
407
        return "DesktopEnvironment " + this.getClass().getSimpleName();
357
        return "DesktopEnvironment " + this.getClass().getSimpleName();