1 /**************************************************************
2  *
3  * Licensed to the Apache Software Foundation (ASF) under one
4  * or more contributor license agreements.  See the NOTICE file
5  * distributed with this work for additional information
6  * regarding copyright ownership.  The ASF licenses this file
7  * to you under the Apache License, Version 2.0 (the
8  * "License"); you may not use this file except in compliance
9  * with the License.  You may obtain a copy of the License at
10  *
11  *   http://www.apache.org/licenses/LICENSE-2.0
12  *
13  * Unless required by applicable law or agreed to in writing,
14  * software distributed under the License is distributed on an
15  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16  * KIND, either express or implied.  See the License for the
17  * specific language governing permissions and limitations
18  * under the License.
19  *
20  *************************************************************/
21 
22 
23 
24 package convwatch;
25 
26 import java.io.File;
27 import helper.OSHelper;
28 import convwatch.IniFile;
29 import java.util.Date;
30 
31 public class BuildID
32 {
getBuildID(String _sApp)33     public static String getBuildID(String _sApp)
34         {
35             String sOfficePath = "";
36             if (_sApp.startsWith("\""))
37             {
38                 int nIdx = _sApp.indexOf("\"", 1);
39                 if (nIdx == -1)
40                 {
41                 }
42                 else
43                 {
44                     // leave double qoute out.
45                     sOfficePath = _sApp.substring(1, nIdx);
46                 }
47             }
48             else
49             {
50                 // check if a space exist, so we get all until space
51                 int nIdx = _sApp.indexOf(" ", 1);
52                 if (nIdx == -1)
53                 {
54                     sOfficePath = _sApp;
55                 }
56                 else
57                 {
58                     sOfficePath = _sApp.substring(0, nIdx);
59                 }
60             }
61             GlobalLogWriter.get().println("Office path: " + sOfficePath);
62 
63             String fs = System.getProperty("file.separator");
64             String sBuildID = "";
65             File aSOfficeFile = new File(sOfficePath);
66             if (aSOfficeFile.exists())
67             {
68                 int nIdx = sOfficePath.lastIndexOf(fs);
69                 sOfficePath = sOfficePath.substring(0, nIdx);
70                 // ok. System.out.println("directory: " + sOfficePath);
71                 sBuildID = getBuildIDFromBootstrap(sOfficePath);
72                 if (sBuildID.length() == 0)
73                 {
74                     sBuildID = getBuildIDFromVersion(sOfficePath);
75                 }
76             }
77             else
78             {
79                 GlobalLogWriter.get().println("soffice executable not found.");
80             }
81 
82             int dummy = 0;
83             return sBuildID;
84         }
85 
getBuildIDFromBootstrap(String _sOfficePath)86     private static String getBuildIDFromBootstrap(String _sOfficePath)
87         {
88             String fs = System.getProperty("file.separator");
89             String sBuildID = "";
90             String sOfficePath = _sOfficePath;
91             if (OSHelper.isWindows())
92             {
93                 sOfficePath += fs + "bootstrap.ini";
94             }
95             else
96             {
97                 sOfficePath += fs + "bootstraprc";
98             }
99             IniFile aIniFile = new IniFile(sOfficePath);
100             if (aIniFile.is())
101             {
102                 sBuildID = aIniFile.getValue("Bootstrap", "buildid");
103             }
104             else
105             {
106                 GlobalLogWriter.get().println("Property Build, can't open file '" + sOfficePath + "', please check.");
107             }
108             return sBuildID;
109         }
110 
getBuildIDFromVersion(String _sOfficePath)111     private static String getBuildIDFromVersion(String _sOfficePath)
112         {
113             String fs = System.getProperty("file.separator");
114             String sBuildID = "";
115             String sOfficePath = _sOfficePath;
116             if (OSHelper.isWindows())
117             {
118                 sOfficePath += fs + "version.ini";
119             }
120             else
121             {
122                 sOfficePath += fs + "versionrc";
123             }
124             IniFile aIniFile = new IniFile(sOfficePath);
125             if (aIniFile.is())
126             {
127                 sBuildID = aIniFile.getValue("Version", "buildid");
128             }
129             else
130             {
131                 GlobalLogWriter.get().println("Property Build, can't open file '" + sOfficePath + "', please check.");
132             }
133             return sBuildID;
134         }
135 //    public static void main(String[] args)
136 //        {
137 //            String sApp;
138 //            sApp = "/opt/staroffice8_m116/program/soffice -headless -accept=socket,host=localhost,port=8100;urp;";
139 //            String sBuildID;
140 //            sBuildID = getBuildID(sApp);
141 //            System.out.println("BuildID is: " + sBuildID);
142 //
143 //            Date aDate = new Date();
144 //            long nStart = aDate.getTime();
145 //            System.out.println("Time:" + nStart);
146 //            // LLA: Just some more tests for getBuildID
147 //            // sApp = "/opt/staroffice8_net/program/soffice";
148 //            // sBuildID = getBuildID(sApp);
149 //            // System.out.println("BuildID is: " + sBuildID);
150 //            //
151 //            // sApp = "\"/opt/staroffice8_net/program/soffice\" test blah";
152 //            // sBuildID = getBuildID(sApp);
153 //            //
154 //            // System.out.println("BuildID is: " + sBuildID);
155 //            System.exit(1);
156 //        }
157 
158 }
159 
160