bump product version to 4.2.0.1
[LibreOffice.git] / qadevOOo / runner / graphical / BuildID.java
blobce21a0cc8236d98a455c9607069991d2352ff720
1 /*
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 .
19 package graphical;
21 import java.io.File;
22 import helper.OSHelper;
24 public class BuildID
26 private static String getOfficePath(String _sApp)
28 String sOfficePath = "";
29 // TODO: StringHelper.removeQuote?
30 if (_sApp.startsWith("\""))
32 int nIdx = _sApp.indexOf("\"", 1);
33 if (nIdx != -1)
35 // leave double qoute out.
36 sOfficePath = _sApp.substring(1, nIdx);
39 else
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);
46 if (nIdx == -1)
48 sOfficePath = _sApp;
50 else
52 sOfficePath = _sApp.substring(0, nIdx);
55 else
57 sOfficePath = _sApp;
60 // GlobalLogWriter.get().println("Office path: " + sOfficePath);
61 return sOfficePath;
64 public static String getBuildID(String _sApp)
66 final String sOfficePath = getOfficePath(_sApp);
67 final String sBuildID = getBuildID(sOfficePath, "buildid");
68 return sBuildID;
71 private static String getBuildID(String _sOfficePath, String _sIniSection)
73 File aSOfficeFile = new File(_sOfficePath);
74 String sBuildID = "";
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);
85 else
87 GlobalLogWriter.println("soffice executable not found.");
90 // int dummy = 0;
91 return sBuildID;
94 private static String getBuildIDFromBootstrap(String _sOfficePath, String _sIniSection)
96 String sBuildID = "";
97 String sOfficePath;
98 if (OSHelper.isWindows())
100 sOfficePath = FileHelper.appendPath(_sOfficePath, "bootstrap.ini");
102 else
104 sOfficePath = FileHelper.appendPath(_sOfficePath, "bootstraprc");
106 IniFile aIniFile = new IniFile(sOfficePath);
107 if (aIniFile.is())
109 sBuildID = aIniFile.getValue("Bootstrap", /*"buildid"*/ _sIniSection);
111 else
113 GlobalLogWriter.println("Property Build, can't open file '" + sOfficePath + "', please check.");
115 return sBuildID;
118 private static String getBuildIDFromVersion(String _sOfficePath, String _sIniSection)
120 // String fs = System.getProperty("file.separator");
121 String sBuildID = "";
122 String sOfficePath;
123 if (OSHelper.isWindows())
125 sOfficePath = FileHelper.appendPath(_sOfficePath, "version.ini");
127 else
129 sOfficePath = FileHelper.appendPath(_sOfficePath, "versionrc");
131 IniFile aIniFile = new IniFile(sOfficePath);
132 if (aIniFile.is())
134 sBuildID = aIniFile.getValue("Version", /*"buildid"*/ _sIniSection);
136 else
138 GlobalLogWriter.println("Property Build, can't open file '" + sOfficePath + "', please check.");
140 return sBuildID;
143 // public static void main(String[] args)
144 // {
145 // String sApp;
146 // sApp = "/opt/staroffice8_m116/program/soffice --headless --accept=socket,host=localhost,port=8100;urp;";
147 // String sBuildID;
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);
158 // //
159 // // sApp = "\"/opt/staroffice8_net/program/soffice\" test blah";
160 // // sBuildID = getBuildID(sApp);
161 // //
162 // // System.out.println("BuildID is: " + sBuildID);
163 // System.exit(1);
164 // }
166 public static String getMinor(String _sOfficePath)
168 final String sOfficePath = getOfficePath(_sOfficePath);
169 final String sMinor = "m" + getBuildID(sOfficePath, "ProductMinor");
170 return sMinor;
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:");
179 if (nIdx > 0)
181 int nIdx2 = sBuildID.indexOf("]", nIdx);
182 sCWSName = sBuildID.substring(nIdx + 5, nIdx2);
184 return sCWSName;
187 // public static void main(String[] args)
188 // {
189 // String sApp;
190 // sApp = "D:/staroffice9_m63/Sun/StarOffice 9/program/soffice.exe";
191 // String sBuildID;
192 // sBuildID = getBuildID(sApp);
193 // System.out.println("BuildID is: " + sBuildID);
195 // String sMinor;
196 // sMinor = getMinor(sApp);
197 // System.out.println("Minor is: " + sMinor);
199 // String sCWSName;
200 // sCWSName = getCWSName(sApp);
201 // System.out.println("CWSName is: " + sCWSName);
203 // System.exit(1);
204 // }