update dev300-m58
[ooovba.git] / qadevOOo / runner / graphical / BuildID.java
blobd7721316e81a2b5079b387540891da8a0d136085
1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: BuildID.java,v $
10 * $Revision: 1.1.2.1 $
12 * This file is part of OpenOffice.org.
14 * OpenOffice.org is free software: you can redistribute it and/or modify
15 * it under the terms of the GNU Lesser General Public License version 3
16 * only, as published by the Free Software Foundation.
18 * OpenOffice.org is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU Lesser General Public License version 3 for more details
22 * (a copy is included in the LICENSE file that accompanied this code).
24 * You should have received a copy of the GNU Lesser General Public License
25 * version 3 along with OpenOffice.org. If not, see
26 * <http://www.openoffice.org/license.html>
27 * for a copy of the LGPLv3 License.
29 ************************************************************************/
31 package graphical;
33 import java.io.File;
34 import helper.OSHelper;
36 public class BuildID
38 public static String getBuildID(String _sApp)
40 String sOfficePath = "";
41 // TODO: StringHelper.removeQuote?
42 if (_sApp.startsWith("\""))
44 int nIdx = _sApp.indexOf("\"", 1);
45 if (nIdx != -1)
47 // leave double qoute out.
48 sOfficePath = _sApp.substring(1, nIdx);
51 else
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 GlobalLogWriter.get().println("Office path: " + sOfficePath);
66 // String fs = System.getProperty("file.separator");
67 String sBuildID = "";
68 File aSOfficeFile = new File(sOfficePath);
69 if (aSOfficeFile.exists())
71 sOfficePath = FileHelper.getPath(sOfficePath);
72 // ok. System.out.println("directory: " + sOfficePath);
73 sBuildID = getBuildIDFromBootstrap(sOfficePath);
74 if (sBuildID.length() == 0)
76 sBuildID = getBuildIDFromVersion(sOfficePath);
79 else
81 GlobalLogWriter.get().println("soffice executable not found.");
84 // int dummy = 0;
85 return sBuildID;
88 private static String getBuildIDFromBootstrap(String _sOfficePath)
90 String sBuildID = "";
91 String sOfficePath;
92 if (OSHelper.isWindows())
94 sOfficePath = FileHelper.appendPath(_sOfficePath, "bootstrap.ini");
96 else
98 sOfficePath = FileHelper.appendPath(_sOfficePath, "bootstraprc");
100 IniFile aIniFile = new IniFile(sOfficePath);
101 if (aIniFile.is())
103 sBuildID = aIniFile.getValue("Bootstrap", "buildid");
105 else
107 GlobalLogWriter.get().println("Property Build, can't open file '" + sOfficePath + "', please check.");
109 return sBuildID;
112 private static String getBuildIDFromVersion(String _sOfficePath)
114 // String fs = System.getProperty("file.separator");
115 String sBuildID = "";
116 String sOfficePath;
117 if (OSHelper.isWindows())
119 sOfficePath = FileHelper.appendPath(_sOfficePath, "version.ini");
121 else
123 sOfficePath = FileHelper.appendPath(_sOfficePath, "versionrc");
125 IniFile aIniFile = new IniFile(sOfficePath);
126 if (aIniFile.is())
128 sBuildID = aIniFile.getValue("Version", "buildid");
130 else
132 GlobalLogWriter.get().println("Property Build, can't open file '" + sOfficePath + "', please check.");
134 return sBuildID;
137 // public static void main(String[] args)
138 // {
139 // String sApp;
140 // sApp = "/opt/staroffice8_m116/program/soffice -headless -accept=socket,host=localhost,port=8100;urp;";
141 // String sBuildID;
142 // sBuildID = getBuildID(sApp);
143 // System.out.println("BuildID is: " + sBuildID);
145 // Date aDate = new Date();
146 // long nStart = aDate.getTime();
147 // System.out.println("Time:" + nStart);
148 // // LLA: Just some more tests for getBuildID
149 // // sApp = "/opt/staroffice8_net/program/soffice";
150 // // sBuildID = getBuildID(sApp);
151 // // System.out.println("BuildID is: " + sBuildID);
152 // //
153 // // sApp = "\"/opt/staroffice8_net/program/soffice\" test blah";
154 // // sBuildID = getBuildID(sApp);
155 // //
156 // // System.out.println("BuildID is: " + sBuildID);
157 // System.exit(1);
158 // }