merge the formfield patch from ooo-build
[ooovba.git] / qadevOOo / runner / convwatch / BuildID.java
blob571708808fb694f1a8c39109ab3dc521a21464ad
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.6.8.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 convwatch;
33 import java.io.File;
34 import helper.OSHelper;
35 import convwatch.IniFile;
36 import java.util.Date;
38 public class BuildID
40 public static String getBuildID(String _sApp)
42 String sOfficePath = "";
43 if (_sApp.startsWith("\""))
45 int nIdx = _sApp.indexOf("\"", 1);
46 if (nIdx == -1)
49 else
51 // leave double qoute out.
52 sOfficePath = _sApp.substring(1, nIdx);
55 else
57 // check if a space exist, so we get all until space
58 int nIdx = _sApp.indexOf(" ", 1);
59 if (nIdx == -1)
61 sOfficePath = _sApp;
63 else
65 sOfficePath = _sApp.substring(0, nIdx);
68 GlobalLogWriter.get().println("Office path: " + sOfficePath);
70 String fs = System.getProperty("file.separator");
71 String sBuildID = "";
72 File aSOfficeFile = new File(sOfficePath);
73 if (aSOfficeFile.exists())
75 int nIdx = sOfficePath.lastIndexOf(fs);
76 sOfficePath = sOfficePath.substring(0, nIdx);
77 // ok. System.out.println("directory: " + sOfficePath);
78 sBuildID = getBuildIDFromBootstrap(sOfficePath);
79 if (sBuildID.length() == 0)
81 sBuildID = getBuildIDFromVersion(sOfficePath);
84 else
86 GlobalLogWriter.get().println("soffice executable not found.");
89 int dummy = 0;
90 return sBuildID;
93 private static String getBuildIDFromBootstrap(String _sOfficePath)
95 String fs = System.getProperty("file.separator");
96 String sBuildID = "";
97 String sOfficePath = _sOfficePath;
98 if (OSHelper.isWindows())
100 sOfficePath += fs + "bootstrap.ini";
102 else
104 sOfficePath += fs + "bootstraprc";
106 IniFile aIniFile = new IniFile(sOfficePath);
107 if (aIniFile.is())
109 sBuildID = aIniFile.getValue("Bootstrap", "buildid");
111 else
113 GlobalLogWriter.get().println("Property Build, can't open file '" + sOfficePath + "', please check.");
115 return sBuildID;
118 private static String getBuildIDFromVersion(String _sOfficePath)
120 String fs = System.getProperty("file.separator");
121 String sBuildID = "";
122 String sOfficePath = _sOfficePath;
123 if (OSHelper.isWindows())
125 sOfficePath += fs + "version.ini";
127 else
129 sOfficePath += fs + "versionrc";
131 IniFile aIniFile = new IniFile(sOfficePath);
132 if (aIniFile.is())
134 sBuildID = aIniFile.getValue("Version", "buildid");
136 else
138 GlobalLogWriter.get().println("Property Build, can't open file '" + sOfficePath + "', please check.");
140 return sBuildID;
142 public static void main(String[] args)
144 String sApp;
145 sApp = "/opt/staroffice8_m116/program/soffice -headless -accept=socket,host=localhost,port=8100;urp;";
146 String sBuildID;
147 sBuildID = getBuildID(sApp);
148 System.out.println("BuildID is: " + sBuildID);
150 Date aDate = new Date();
151 long nStart = aDate.getTime();
152 System.out.println("Time:" + nStart);
153 // LLA: Just some more tests for getBuildID
154 // sApp = "/opt/staroffice8_net/program/soffice";
155 // sBuildID = getBuildID(sApp);
156 // System.out.println("BuildID is: " + sBuildID);
158 // sApp = "\"/opt/staroffice8_net/program/soffice\" test blah";
159 // sBuildID = getBuildID(sApp);
161 // System.out.println("BuildID is: " + sBuildID);
162 System.exit(1);