1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 * Copyright 2000, 2010 Oracle and/or its affiliates.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * This file is part of OpenOffice.org.
11 * OpenOffice.org is free software: you can redistribute it and/or modify
12 * it under the terms of the GNU Lesser General Public License version 3
13 * only, as published by the Free Software Foundation.
15 * OpenOffice.org is distributed in the hope that it will be useful,
16 * but WITHOUT ANY WARRANTY; without even the implied warranty of
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 * GNU Lesser General Public License version 3 for more details
19 * (a copy is included in the LICENSE file that accompanied this code).
21 * You should have received a copy of the GNU Lesser General Public License
22 * version 3 along with OpenOffice.org. If not, see
23 * <http://www.openoffice.org/license.html>
24 * for a copy of the LGPLv3 License.
26 ************************************************************************/
31 import helper
.OSHelper
;
35 private static String
getOfficePath(String _sApp
)
37 String sOfficePath
= "";
38 // TODO: StringHelper.removeQuote?
39 if (_sApp
.startsWith("\""))
41 int nIdx
= _sApp
.indexOf("\"", 1);
44 // leave double qoute out.
45 sOfficePath
= _sApp
.substring(1, nIdx
);
50 // check if _sApp ends with the office executable, if not
51 if (! (_sApp
.endsWith("soffice.exe") || _sApp
.endsWith("soffice")))
53 // check if a space exist, so we get all until space
54 int nIdx
= _sApp
.indexOf(" ", 1);
61 sOfficePath
= _sApp
.substring(0, nIdx
);
69 // GlobalLogWriter.get().println("Office path: " + sOfficePath);
73 public static String
getBuildID(String _sApp
)
75 final String sOfficePath
= getOfficePath(_sApp
);
76 final String sBuildID
= getBuildID(sOfficePath
, "buildid");
80 private static String
getBuildID(String _sOfficePath
, String _sIniSection
)
82 File aSOfficeFile
= new File(_sOfficePath
);
84 if (aSOfficeFile
.exists())
86 String sOfficePath
= FileHelper
.getPath(_sOfficePath
);
87 // ok. System.out.println("directory: " + sOfficePath);
88 sBuildID
= getBuildIDFromBootstrap(sOfficePath
, _sIniSection
);
89 if (sBuildID
.length() == 0)
91 sBuildID
= getBuildIDFromVersion(sOfficePath
, _sIniSection
);
96 GlobalLogWriter
.println("soffice executable not found.");
103 private static String
getBuildIDFromBootstrap(String _sOfficePath
, String _sIniSection
)
105 String sBuildID
= "";
107 if (OSHelper
.isWindows())
109 sOfficePath
= FileHelper
.appendPath(_sOfficePath
, "bootstrap.ini");
113 sOfficePath
= FileHelper
.appendPath(_sOfficePath
, "bootstraprc");
115 IniFile aIniFile
= new IniFile(sOfficePath
);
118 sBuildID
= aIniFile
.getValue("Bootstrap", /*"buildid"*/ _sIniSection
);
122 GlobalLogWriter
.println("Property Build, can't open file '" + sOfficePath
+ "', please check.");
127 private static String
getBuildIDFromVersion(String _sOfficePath
, String _sIniSection
)
129 // String fs = System.getProperty("file.separator");
130 String sBuildID
= "";
132 if (OSHelper
.isWindows())
134 sOfficePath
= FileHelper
.appendPath(_sOfficePath
, "version.ini");
138 sOfficePath
= FileHelper
.appendPath(_sOfficePath
, "versionrc");
140 IniFile aIniFile
= new IniFile(sOfficePath
);
143 sBuildID
= aIniFile
.getValue("Version", /*"buildid"*/ _sIniSection
);
147 GlobalLogWriter
.println("Property Build, can't open file '" + sOfficePath
+ "', please check.");
152 // public static void main(String[] args)
155 // sApp = "/opt/staroffice8_m116/program/soffice -headless -accept=socket,host=localhost,port=8100;urp;";
157 // sBuildID = getBuildID(sApp);
158 // System.out.println("BuildID is: " + sBuildID);
160 // Date aDate = new Date();
161 // long nStart = aDate.getTime();
162 // System.out.println("Time:" + nStart);
163 // // LLA: Just some more tests for getBuildID
164 // // sApp = "/opt/staroffice8_net/program/soffice";
165 // // sBuildID = getBuildID(sApp);
166 // // System.out.println("BuildID is: " + sBuildID);
168 // // sApp = "\"/opt/staroffice8_net/program/soffice\" test blah";
169 // // sBuildID = getBuildID(sApp);
171 // // System.out.println("BuildID is: " + sBuildID);
175 public static String
getMaster(String _sOfficePath
)
177 final String sOfficePath
= getOfficePath(_sOfficePath
);
178 final String sMaster
= getBuildID(sOfficePath
, "ProductSource");
182 public static String
getMinor(String _sOfficePath
)
184 final String sOfficePath
= getOfficePath(_sOfficePath
);
185 final String sMinor
= "m" + getBuildID(sOfficePath
, "ProductMinor");
189 public static String
getCWSName(String _sOfficePath
)
191 final String sOfficePath
= getOfficePath(_sOfficePath
);
192 final String sBuildID
= getBuildID(sOfficePath
, "buildid");
193 String sCWSName
= "MWS";
194 int nIdx
= sBuildID
.indexOf("[CWS:");
197 int nIdx2
= sBuildID
.indexOf("]", nIdx
);
198 sCWSName
= sBuildID
.substring(nIdx
+ 5, nIdx2
);
203 // public static void main(String[] args)
206 // sApp = "D:/staroffice9_m63/Sun/StarOffice 9/program/soffice.exe";
208 // sBuildID = getBuildID(sApp);
209 // System.out.println("BuildID is: " + sBuildID);
212 // sMaster = getMaster(sApp);
213 // System.out.println("Master is: " + sMaster);
216 // sMinor = getMinor(sApp);
217 // System.out.println("Minor is: " + sMinor);
220 // sCWSName = getCWSName(sApp);
221 // System.out.println("CWSName is: " + sCWSName);