| 1 | /* |
| 2 | * Copyright (c) 2004 Ant-Contrib project. All rights reserved. |
| 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 | * |
| 8 | * http://www.apache.org/licenses/LICENSE-2.0 |
| 9 | * |
| 10 | * Unless required by applicable law or agreed to in writing, software |
| 11 | * distributed under the License is distributed on an "AS IS" BASIS, |
| 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 13 | * See the License for the specific language governing permissions and |
| 14 | * limitations under the License. |
| 15 | */ |
| 16 | package net.sf.antcontrib; |
| 17 | |
| 18 | /** |
| 19 | * @author Dean Hiller |
| 20 | * |
| 21 | * To change the template for this generated type comment go to |
| 22 | * Window - Preferences - Java - Code Generation - Code and Comments |
| 23 | */ |
| 24 | public class AntContribVersion { |
| 25 | |
| 26 | private Package thePackage; |
| 27 | |
| 28 | /** |
| 29 | * The main program for MockVersion that prints the version info from |
| 30 | * the manifest file. |
| 31 | * |
| 32 | * @param args Ignores all arguments. |
| 33 | */ |
| 34 | public static void main(String[] args) { |
| 35 | AntContribVersion version = new AntContribVersion(AntContribVersion.class); |
| 36 | System.out.println(""+version); |
| 37 | } |
| 38 | |
| 39 | /** |
| 40 | * Constructor that takes a class to get the version information |
| 41 | * from out of the manifest. Uses the class's package to retrieve |
| 42 | * the manifest version info. |
| 43 | * @param c The Class on whose package to use to get version info. |
| 44 | */ |
| 45 | public AntContribVersion(Class c) { |
| 46 | String name = c.getName(); |
| 47 | int index = name.lastIndexOf("."); |
| 48 | |
| 49 | if(index < 0) |
| 50 | throw new RuntimeException("This class is the default package and can't be to use this feature"); |
| 51 | |
| 52 | String packageName = name.substring(0, index); |
| 53 | thePackage = Package.getPackage(packageName); |
| 54 | } |
| 55 | |
| 56 | |
| 57 | /** |
| 58 | * Prints the version info the MockVersion represents. |
| 59 | * |
| 60 | * @see java.lang.Object#toString() |
| 61 | */ |
| 62 | public String toString() { |
| 63 | String version = "\nVersion of Ant Contrib..."; |
| 64 | version += "\ntitle="+thePackage.getImplementationTitle(); |
| 65 | version += "\nwebsite="+thePackage.getImplementationVendor(); |
| 66 | version += "\nversion="+thePackage.getImplementationVersion()+"\n"; |
| 67 | |
| 68 | return version; |
| 69 | } |
| 70 | } |