View Javadoc
1   /*
2    * Copyright (c) 2002-2026 Gargoyle Software Inc.
3    *
4    * Licensed under the Apache License, Version 2.0 (the "License");
5    * you may not use this file except in compliance with the License.
6    * You may obtain a copy of the License at
7    * https://www.apache.org/licenses/LICENSE-2.0
8    *
9    * Unless required by applicable law or agreed to in writing, software
10   * distributed under the License is distributed on an "AS IS" BASIS,
11   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12   * See the License for the specific language governing permissions and
13   * limitations under the License.
14   */
15  package org.htmlunit;
16  
17  import org.htmlunit.html.HtmlPage;
18  
19  /**
20   * Class to display version information about HtmlUnit. This is the class
21   * that will be executed if the JAR file is run.
22   *
23   * @author Mike Bowler
24   * @author Ahmed Ashour
25   * @author Ronald Brill
26   */
27  public final class Version {
28  
29      /** Prevent instantiation. */
30      private Version() {
31          // Empty.
32      }
33  
34      /**
35       * The main entry point into this class.
36       * @param args the arguments passed on the command line
37       * @throws Exception if an error occurs
38       */
39      @SuppressWarnings("PMD.SystemPrintln")
40      public static void main(final String[] args) throws Exception {
41          if (args.length == 1 && "-SanityCheck".equals(args[0])) {
42              runSanityCheck();
43              return;
44          }
45          System.out.println(getProductName());
46          System.out.println(getCopyright());
47          System.out.println("Version: " + getProductVersion());
48      }
49  
50      /**
51       * Runs the sanity check.
52       * @throws Exception if anything goes wrong
53       */
54      @SuppressWarnings("PMD.SystemPrintln")
55      private static void runSanityCheck() throws Exception {
56          try (WebClient webClient = new WebClient()) {
57              final HtmlPage page = webClient.getPage("https://www.htmlunit.org/index.html");
58              page.executeJavaScript("document.location");
59              System.out.println("Sanity check complete.");
60          }
61      }
62  
63      /**
64       * Returns "HtmlUnit".
65       * @return "HtmlUnit"
66       */
67      public static String getProductName() {
68          return "HtmlUnit";
69      }
70  
71      /**
72       * Returns the current implementation version.
73       * @return the current implementation version
74       */
75      public static String getProductVersion() {
76          return Version.class.getPackage().getImplementationVersion();
77      }
78  
79      /**
80       * Returns the copyright notice.
81       * @return the copyright notice
82       */
83      public static String getCopyright() {
84          return "Copyright (c) 2002-2026 Gargoyle Software Inc. All rights reserved.";
85      }
86  }