2 * This file is part of the LibreOffice project.
4 * This Source Code Form is subject to the terms of the Mozilla Public
5 * License, v. 2.0. If a copy of the MPL was not distributed with this
6 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
8 * This file incorporates work covered by the following license notice:
10 * Licensed to the Apache Software Foundation (ASF) under one or more
11 * contributor license agreements. See the NOTICE file distributed
12 * with this work for additional information regarding copyright
13 * ownership. The ASF licenses this file to you under the Apache
14 * License, Version 2.0 (the "License"); you may not use this file
15 * except in compliance with the License. You may obtain a copy of
16 * the License at http://www.apache.org/licenses/LICENSE-2.0 .
22 import helper
.OSHelper
;
26 private static String
getOfficePath(String _sApp
)
28 String sOfficePath
= "";
29 // TODO: StringHelper.removeQuote?
30 if (_sApp
.startsWith("\""))
32 int nIdx
= _sApp
.indexOf("\"", 1);
35 // leave double qoute out.
36 sOfficePath
= _sApp
.substring(1, nIdx
);
41 // check if _sApp ends with the office executable, if not
42 if (! (_sApp
.endsWith("soffice.exe") || _sApp
.endsWith("soffice")))
44 // check if a space exist, so we get all until space
45 int nIdx
= _sApp
.indexOf(" ", 1);
52 sOfficePath
= _sApp
.substring(0, nIdx
);
60 // GlobalLogWriter.get().println("Office path: " + sOfficePath);
64 public static String
getBuildID(String _sApp
)
66 final String sOfficePath
= getOfficePath(_sApp
);
67 final String sBuildID
= getBuildID(sOfficePath
, "buildid");
71 private static String
getBuildID(String _sOfficePath
, String _sIniSection
)
73 File aSOfficeFile
= new File(_sOfficePath
);
75 if (aSOfficeFile
.exists())
77 String sOfficePath
= FileHelper
.getPath(_sOfficePath
);
78 // ok. System.out.println("directory: " + sOfficePath);
79 sBuildID
= getBuildIDFromBootstrap(sOfficePath
, _sIniSection
);
80 if (sBuildID
.length() == 0)
82 sBuildID
= getBuildIDFromVersion(sOfficePath
, _sIniSection
);
87 GlobalLogWriter
.println("soffice executable not found.");
94 private static String
getBuildIDFromBootstrap(String _sOfficePath
, String _sIniSection
)
98 if (OSHelper
.isWindows())
100 sOfficePath
= FileHelper
.appendPath(_sOfficePath
, "bootstrap.ini");
104 sOfficePath
= FileHelper
.appendPath(_sOfficePath
, "bootstraprc");
106 IniFile aIniFile
= new IniFile(sOfficePath
);
109 sBuildID
= aIniFile
.getValue("Bootstrap", /*"buildid"*/ _sIniSection
);
113 GlobalLogWriter
.println("Property Build, can't open file '" + sOfficePath
+ "', please check.");
118 private static String
getBuildIDFromVersion(String _sOfficePath
, String _sIniSection
)
120 // String fs = System.getProperty("file.separator");
121 String sBuildID
= "";
123 if (OSHelper
.isWindows())
125 sOfficePath
= FileHelper
.appendPath(_sOfficePath
, "version.ini");
129 sOfficePath
= FileHelper
.appendPath(_sOfficePath
, "versionrc");
131 IniFile aIniFile
= new IniFile(sOfficePath
);
134 sBuildID
= aIniFile
.getValue("Version", /*"buildid"*/ _sIniSection
);
138 GlobalLogWriter
.println("Property Build, can't open file '" + sOfficePath
+ "', please check.");
143 // public static void main(String[] args)
146 // sApp = "/opt/staroffice8_m116/program/soffice --headless --accept=socket,host=localhost,port=8100;urp;";
148 // sBuildID = getBuildID(sApp);
149 // System.out.println("BuildID is: " + sBuildID);
151 // Date aDate = new Date();
152 // long nStart = aDate.getTime();
153 // System.out.println("Time:" + nStart);
154 // // LLA: Just some more tests for getBuildID
155 // // sApp = "/opt/staroffice8_net/program/soffice";
156 // // sBuildID = getBuildID(sApp);
157 // // System.out.println("BuildID is: " + sBuildID);
159 // // sApp = "\"/opt/staroffice8_net/program/soffice\" test blah";
160 // // sBuildID = getBuildID(sApp);
162 // // System.out.println("BuildID is: " + sBuildID);
166 public static String
getMinor(String _sOfficePath
)
168 final String sOfficePath
= getOfficePath(_sOfficePath
);
169 final String sMinor
= "m" + getBuildID(sOfficePath
, "ProductMinor");
173 public static String
getCWSName(String _sOfficePath
)
175 final String sOfficePath
= getOfficePath(_sOfficePath
);
176 final String sBuildID
= getBuildID(sOfficePath
, "buildid");
177 String sCWSName
= "MWS";
178 int nIdx
= sBuildID
.indexOf("[CWS:");
181 int nIdx2
= sBuildID
.indexOf("]", nIdx
);
182 sCWSName
= sBuildID
.substring(nIdx
+ 5, nIdx2
);
187 // public static void main(String[] args)
190 // sApp = "D:/staroffice9_m63/Sun/StarOffice 9/program/soffice.exe";
192 // sBuildID = getBuildID(sApp);
193 // System.out.println("BuildID is: " + sBuildID);
196 // sMinor = getMinor(sApp);
197 // System.out.println("Minor is: " + sMinor);
200 // sCWSName = getCWSName(sApp);
201 // System.out.println("CWSName is: " + sCWSName);