View Javadoc

1   /*
2    * Version.java
3    *
4    * Created on May 11, 2005, 2:46 PM
5    *
6    * To change this template, choose Tools | Options and locate the template under
7    * the Source Creation and Management node. Right-click the template and choose
8    * Open. You can then make changes to the template in the Source Editor.
9    */
10  
11  package gov.bnl.gums.admin;
12  
13  import java.net.URL;
14  
15  import org.apache.commons.cli.Options;
16  import org.apache.commons.digester.Digester;
17  
18  import gov.bnl.gums.configuration.Version;
19  
20  /**
21   *
22   * @author carcassi
23   */
24  public class ClientVersion extends RemoteCommand {
25  
26      static {
27          command = new ClientVersion();
28      }
29  
30      /**
31       * Creates a new Version object.
32       */
33      public ClientVersion() {
34          syntax = "";
35          description = "Returns the version of GUMS client being used.";
36      }
37  
38      protected org.apache.commons.cli.Options buildOptions() {
39          Options options = new Options();
40          return options;
41      }
42  
43      protected void execute(org.apache.commons.cli.CommandLine cmd) throws Exception {
44      	String pomFile = getClass().getClassLoader().getSystemResource("META-INF/maven/gums/gums-core/pom.xml").toString();
45  		Digester digester = new Digester();
46  		digester.addObjectCreate("project/version", Version.class);
47  		digester.addCallMethod("project/version","setVersion",0);
48  		Version versionCls = null;
49  		try {
50  			versionCls = (Version)digester.parse(pomFile);
51  		} catch (Exception e) {
52  			System.out.println("Cannot get GUMS version from "+pomFile);
53  			return;
54  		}
55  		if (versionCls == null) {
56  			System.out.println("Cannot get GUMS version from "+pomFile);
57  			return;
58  		}
59  		String version = versionCls.getVersion();
60  		System.out.println(version);
61      }
62      
63  }