1 /************************************************************************* 2 * 3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 4 * 5 * Copyright 2000, 2010 Oracle and/or its affiliates. 6 * 7 * OpenOffice.org - a multi-platform office productivity suite 8 * 9 * This file is part of OpenOffice.org. 10 * 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. 14 * 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). 20 * 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. 25 * 26 ************************************************************************/ 27 28 package convwatch; 29 30 import java.io.File; 31 import helper.OSHelper; 32 import convwatch.IniFile; 33 import java.util.Date; 34 35 public class BuildID 36 { 37 public static String getBuildID(String _sApp) 38 { 39 String sOfficePath = ""; 40 if (_sApp.startsWith("\"")) 41 { 42 int nIdx = _sApp.indexOf("\"", 1); 43 if (nIdx == -1) 44 { 45 } 46 else 47 { 48 // leave double qoute out. 49 sOfficePath = _sApp.substring(1, nIdx); 50 } 51 } 52 else 53 { 54 // check if a space exist, so we get all until space 55 int nIdx = _sApp.indexOf(" ", 1); 56 if (nIdx == -1) 57 { 58 sOfficePath = _sApp; 59 } 60 else 61 { 62 sOfficePath = _sApp.substring(0, nIdx); 63 } 64 } 65 GlobalLogWriter.get().println("Office path: " + sOfficePath); 66 67 String fs = System.getProperty("file.separator"); 68 String sBuildID = ""; 69 File aSOfficeFile = new File(sOfficePath); 70 if (aSOfficeFile.exists()) 71 { 72 int nIdx = sOfficePath.lastIndexOf(fs); 73 sOfficePath = sOfficePath.substring(0, nIdx); 74 // ok. System.out.println("directory: " + sOfficePath); 75 sBuildID = getBuildIDFromBootstrap(sOfficePath); 76 if (sBuildID.length() == 0) 77 { 78 sBuildID = getBuildIDFromVersion(sOfficePath); 79 } 80 } 81 else 82 { 83 GlobalLogWriter.get().println("soffice executable not found."); 84 } 85 86 int dummy = 0; 87 return sBuildID; 88 } 89 90 private static String getBuildIDFromBootstrap(String _sOfficePath) 91 { 92 String fs = System.getProperty("file.separator"); 93 String sBuildID = ""; 94 String sOfficePath = _sOfficePath; 95 if (OSHelper.isWindows()) 96 { 97 sOfficePath += fs + "bootstrap.ini"; 98 } 99 else 100 { 101 sOfficePath += fs + "bootstraprc"; 102 } 103 IniFile aIniFile = new IniFile(sOfficePath); 104 if (aIniFile.is()) 105 { 106 sBuildID = aIniFile.getValue("Bootstrap", "buildid"); 107 } 108 else 109 { 110 GlobalLogWriter.get().println("Property Build, can't open file '" + sOfficePath + "', please check."); 111 } 112 return sBuildID; 113 } 114 115 private static String getBuildIDFromVersion(String _sOfficePath) 116 { 117 String fs = System.getProperty("file.separator"); 118 String sBuildID = ""; 119 String sOfficePath = _sOfficePath; 120 if (OSHelper.isWindows()) 121 { 122 sOfficePath += fs + "version.ini"; 123 } 124 else 125 { 126 sOfficePath += fs + "versionrc"; 127 } 128 IniFile aIniFile = new IniFile(sOfficePath); 129 if (aIniFile.is()) 130 { 131 sBuildID = aIniFile.getValue("Version", "buildid"); 132 } 133 else 134 { 135 GlobalLogWriter.get().println("Property Build, can't open file '" + sOfficePath + "', please check."); 136 } 137 return sBuildID; 138 } 139 // public static void main(String[] args) 140 // { 141 // String sApp; 142 // sApp = "/opt/staroffice8_m116/program/soffice -headless -accept=socket,host=localhost,port=8100;urp;"; 143 // String sBuildID; 144 // sBuildID = getBuildID(sApp); 145 // System.out.println("BuildID is: " + sBuildID); 146 // 147 // Date aDate = new Date(); 148 // long nStart = aDate.getTime(); 149 // System.out.println("Time:" + nStart); 150 // // LLA: Just some more tests for getBuildID 151 // // sApp = "/opt/staroffice8_net/program/soffice"; 152 // // sBuildID = getBuildID(sApp); 153 // // System.out.println("BuildID is: " + sBuildID); 154 // // 155 // // sApp = "\"/opt/staroffice8_net/program/soffice\" test blah"; 156 // // sBuildID = getBuildID(sApp); 157 // // 158 // // System.out.println("BuildID is: " + sBuildID); 159 // System.exit(1); 160 // } 161 162 } 163 164