View Javadoc
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   * This software consists of voluntary contributions made by many
22   * individuals on behalf of the Apache Software Foundation.  For more
23   * information on the Apache Software Foundation, please see
24   * <http://www.apache.org/>.
25   *
26   */
27  
28  package org.apache.hc.core5.http.examples;
29  
30  import org.apache.hc.core5.util.VersionInfo;
31  
32  /**
33   * Prints version information for debugging purposes.
34   * This can be used to verify that the correct versions of the
35   * HttpComponent JARs are picked up from the classpath.
36   *
37   *
38   */
39  public class PrintVersionInfo {
40  
41      /** A default list of module packages. */
42      private final static String[] MODULE_LIST = {
43          "org.apache.http",              // HttpCore
44          "org.apache.http.client",       // HttpClient
45      };
46  
47  
48      /**
49       * Prints version information.
50       *
51       * @param args      command line arguments. Leave empty to print version
52       *                  information for the default packages. Otherwise, pass
53       *                  a list of packages for which to get version info.
54       */
55      public static void main(final String args[]) {
56          final String[]    pckgs = (args.length > 0) ? args : MODULE_LIST;
57          VersionInfo[] via = VersionInfo.loadVersionInfo(pckgs, null);
58          System.out.println("version info for thread context classloader:");
59          for (int i=0; i<via.length; i++)
60              System.out.println(via[i]);
61  
62          System.out.println();
63  
64          // if the version information for the classloader of this class
65          // is different from that for the thread context classloader,
66          // there may be a problem with multiple versions in the classpath
67  
68          via = VersionInfo.loadVersionInfo
69              (pckgs, PrintVersionInfo.class.getClassLoader());
70          System.out.println("version info for static classloader:");
71          for (int i=0; i<via.length; i++)
72              System.out.println(via[i]);
73      }
74  }
75