merged tag ooo/DEV300_m102
[LibreOffice.git] / qadevOOo / runner / graphical / BuildID.java
blobcf9188d84a476fa15d7f042688a32f4f378372a5
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 ************************************************************************/
28 package graphical;
30 import java.io.File;
31 import helper.OSHelper;
33 public class BuildID
35 private static String getOfficePath(String _sApp)
37 String sOfficePath = "";
38 // TODO: StringHelper.removeQuote?
39 if (_sApp.startsWith("\""))
41 int nIdx = _sApp.indexOf("\"", 1);
42 if (nIdx != -1)
44 // leave double qoute out.
45 sOfficePath = _sApp.substring(1, nIdx);
48 else
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);
55 if (nIdx == -1)
57 sOfficePath = _sApp;
59 else
61 sOfficePath = _sApp.substring(0, nIdx);
64 else
66 sOfficePath = _sApp;
69 // GlobalLogWriter.get().println("Office path: " + sOfficePath);
70 return sOfficePath;
73 public static String getBuildID(String _sApp)
75 final String sOfficePath = getOfficePath(_sApp);
76 final String sBuildID = getBuildID(sOfficePath, "buildid");
77 return sBuildID;
80 private static String getBuildID(String _sOfficePath, String _sIniSection)
82 File aSOfficeFile = new File(_sOfficePath);
83 String sBuildID = "";
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);
94 else
96 GlobalLogWriter.println("soffice executable not found.");
99 // int dummy = 0;
100 return sBuildID;
103 private static String getBuildIDFromBootstrap(String _sOfficePath, String _sIniSection)
105 String sBuildID = "";
106 String sOfficePath;
107 if (OSHelper.isWindows())
109 sOfficePath = FileHelper.appendPath(_sOfficePath, "bootstrap.ini");
111 else
113 sOfficePath = FileHelper.appendPath(_sOfficePath, "bootstraprc");
115 IniFile aIniFile = new IniFile(sOfficePath);
116 if (aIniFile.is())
118 sBuildID = aIniFile.getValue("Bootstrap", /*"buildid"*/ _sIniSection);
120 else
122 GlobalLogWriter.println("Property Build, can't open file '" + sOfficePath + "', please check.");
124 return sBuildID;
127 private static String getBuildIDFromVersion(String _sOfficePath, String _sIniSection)
129 // String fs = System.getProperty("file.separator");
130 String sBuildID = "";
131 String sOfficePath;
132 if (OSHelper.isWindows())
134 sOfficePath = FileHelper.appendPath(_sOfficePath, "version.ini");
136 else
138 sOfficePath = FileHelper.appendPath(_sOfficePath, "versionrc");
140 IniFile aIniFile = new IniFile(sOfficePath);
141 if (aIniFile.is())
143 sBuildID = aIniFile.getValue("Version", /*"buildid"*/ _sIniSection);
145 else
147 GlobalLogWriter.println("Property Build, can't open file '" + sOfficePath + "', please check.");
149 return sBuildID;
152 // public static void main(String[] args)
153 // {
154 // String sApp;
155 // sApp = "/opt/staroffice8_m116/program/soffice -headless -accept=socket,host=localhost,port=8100;urp;";
156 // String sBuildID;
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);
167 // //
168 // // sApp = "\"/opt/staroffice8_net/program/soffice\" test blah";
169 // // sBuildID = getBuildID(sApp);
170 // //
171 // // System.out.println("BuildID is: " + sBuildID);
172 // System.exit(1);
173 // }
175 public static String getMaster(String _sOfficePath)
177 final String sOfficePath = getOfficePath(_sOfficePath);
178 final String sMaster = getBuildID(sOfficePath, "ProductSource");
179 return sMaster;
182 public static String getMinor(String _sOfficePath)
184 final String sOfficePath = getOfficePath(_sOfficePath);
185 final String sMinor = "m" + getBuildID(sOfficePath, "ProductMinor");
186 return sMinor;
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:");
195 if (nIdx > 0)
197 int nIdx2 = sBuildID.indexOf("]", nIdx);
198 sCWSName = sBuildID.substring(nIdx + 5, nIdx2);
200 return sCWSName;
203 // public static void main(String[] args)
204 // {
205 // String sApp;
206 // sApp = "D:/staroffice9_m63/Sun/StarOffice 9/program/soffice.exe";
207 // String sBuildID;
208 // sBuildID = getBuildID(sApp);
209 // System.out.println("BuildID is: " + sBuildID);
211 // String sMaster;
212 // sMaster = getMaster(sApp);
213 // System.out.println("Master is: " + sMaster);
215 // String sMinor;
216 // sMinor = getMinor(sApp);
217 // System.out.println("Minor is: " + sMinor);
219 // String sCWSName;
220 // sCWSName = getCWSName(sApp);
221 // System.out.println("CWSName is: " + sCWSName);
223 // System.exit(1);
224 // }