1 /* 2 * Copyright (c) 2002-2025 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 <a href="mailto:mbowler@GargoyleSoftware.com">Mike Bowler</a> 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 public static void main(final String[] args) throws Exception { 40 if (args.length == 1 && "-SanityCheck".equals(args[0])) { 41 runSanityCheck(); 42 return; 43 } 44 System.out.println(getProductName()); 45 System.out.println(getCopyright()); 46 System.out.println("Version: " + getProductVersion()); 47 } 48 49 /** 50 * Runs the sanity check. 51 * @throws Exception if anything goes wrong 52 */ 53 private static void runSanityCheck() throws Exception { 54 try (WebClient webClient = new WebClient()) { 55 final HtmlPage page = webClient.getPage("https://www.htmlunit.org/index.html"); 56 page.executeJavaScript("document.location"); 57 System.out.println("Sanity check complete."); 58 } 59 } 60 61 /** 62 * Returns "HtmlUnit". 63 * @return "HtmlUnit" 64 */ 65 public static String getProductName() { 66 return "HtmlUnit"; 67 } 68 69 /** 70 * Returns the current implementation version. 71 * @return the current implementation version 72 */ 73 public static String getProductVersion() { 74 return Version.class.getPackage().getImplementationVersion(); 75 } 76 77 /** 78 * Returns the copyright notice. 79 * @return the copyright notice 80 */ 81 public static String getCopyright() { 82 return "Copyright (c) 2002-2025 Gargoyle Software Inc. All rights reserved."; 83 } 84 }