1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
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 ************************************************************************/
34 import helper
.OSHelper
;
35 import convwatch
.IniFile
;
36 import java
.util
.Date
;
40 public static String
getBuildID(String _sApp
)
42 String sOfficePath
= "";
43 if (_sApp
.startsWith("\""))
45 int nIdx
= _sApp
.indexOf("\"", 1);
51 // leave double qoute out.
52 sOfficePath
= _sApp
.substring(1, nIdx
);
57 // check if a space exist, so we get all until space
58 int nIdx
= _sApp
.indexOf(" ", 1);
65 sOfficePath
= _sApp
.substring(0, nIdx
);
68 GlobalLogWriter
.get().println("Office path: " + sOfficePath
);
70 String fs
= System
.getProperty("file.separator");
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
);
86 GlobalLogWriter
.get().println("soffice executable not found.");
93 private static String
getBuildIDFromBootstrap(String _sOfficePath
)
95 String fs
= System
.getProperty("file.separator");
97 String sOfficePath
= _sOfficePath
;
98 if (OSHelper
.isWindows())
100 sOfficePath
+= fs
+ "bootstrap.ini";
104 sOfficePath
+= fs
+ "bootstraprc";
106 IniFile aIniFile
= new IniFile(sOfficePath
);
109 sBuildID
= aIniFile
.getValue("Bootstrap", "buildid");
113 GlobalLogWriter
.get().println("Property Build, can't open file '" + sOfficePath
+ "', please check.");
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";
129 sOfficePath
+= fs
+ "versionrc";
131 IniFile aIniFile
= new IniFile(sOfficePath
);
134 sBuildID
= aIniFile
.getValue("Version", "buildid");
138 GlobalLogWriter
.get().println("Property Build, can't open file '" + sOfficePath
+ "', please check.");
142 public static void main(String
[] args
)
145 sApp
= "/opt/staroffice8_m116/program/soffice -headless -accept=socket,host=localhost,port=8100;urp;";
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);