1*ef39d40dSAndrew Rist /**************************************************************
2cdf0e10cSrcweir  *
3*ef39d40dSAndrew Rist  * Licensed to the Apache Software Foundation (ASF) under one
4*ef39d40dSAndrew Rist  * or more contributor license agreements.  See the NOTICE file
5*ef39d40dSAndrew Rist  * distributed with this work for additional information
6*ef39d40dSAndrew Rist  * regarding copyright ownership.  The ASF licenses this file
7*ef39d40dSAndrew Rist  * to you under the Apache License, Version 2.0 (the
8*ef39d40dSAndrew Rist  * "License"); you may not use this file except in compliance
9*ef39d40dSAndrew Rist  * with the License.  You may obtain a copy of the License at
10*ef39d40dSAndrew Rist  *
11*ef39d40dSAndrew Rist  *   http://www.apache.org/licenses/LICENSE-2.0
12*ef39d40dSAndrew Rist  *
13*ef39d40dSAndrew Rist  * Unless required by applicable law or agreed to in writing,
14*ef39d40dSAndrew Rist  * software distributed under the License is distributed on an
15*ef39d40dSAndrew Rist  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16*ef39d40dSAndrew Rist  * KIND, either express or implied.  See the License for the
17*ef39d40dSAndrew Rist  * specific language governing permissions and limitations
18*ef39d40dSAndrew Rist  * under the License.
19*ef39d40dSAndrew Rist  *
20*ef39d40dSAndrew Rist  *************************************************************/
21*ef39d40dSAndrew Rist 
22*ef39d40dSAndrew Rist 
23cdf0e10cSrcweir 
24cdf0e10cSrcweir package complexlib;
25cdf0e10cSrcweir 
26cdf0e10cSrcweir /**
27cdf0e10cSrcweir  *
28cdf0e10cSrcweir  * @author fs93730
29cdf0e10cSrcweir  */
30cdf0e10cSrcweir public class ShowTargets
31cdf0e10cSrcweir {
32cdf0e10cSrcweir     /** Creates a new instance of ShowTargets */
ShowTargets()33cdf0e10cSrcweir     public ShowTargets()
34cdf0e10cSrcweir     {
35cdf0e10cSrcweir     }
36cdf0e10cSrcweir 
main( String[] args )37cdf0e10cSrcweir     public static void main( String[] args )
38cdf0e10cSrcweir     {
39cdf0e10cSrcweir         java.util.Vector targets = new java.util.Vector();
40cdf0e10cSrcweir         java.util.Vector descs = new java.util.Vector();
41cdf0e10cSrcweir 
42cdf0e10cSrcweir         targets.add( "run" );
43cdf0e10cSrcweir         descs.add( "runs all complex tests in this module" );
44cdf0e10cSrcweir 
45cdf0e10cSrcweir         int maxTargetLength = 3;
46cdf0e10cSrcweir 
47cdf0e10cSrcweir         for ( int i = 0; i < args.length; ++i )
48cdf0e10cSrcweir         {
49cdf0e10cSrcweir             String completePotentialClassName = args[i].replace( '/', '.' );
50cdf0e10cSrcweir 
51cdf0e10cSrcweir             // filter
52cdf0e10cSrcweir             if ( completePotentialClassName.endsWith( ".TestCase" ) )
53cdf0e10cSrcweir                 continue;
54cdf0e10cSrcweir             if ( completePotentialClassName.endsWith( ".TestSkeleton" ) )
55cdf0e10cSrcweir                 continue;
56cdf0e10cSrcweir 
57cdf0e10cSrcweir             // get the class
58cdf0e10cSrcweir             Class potentialTestClass = null;
59cdf0e10cSrcweir             try { potentialTestClass = Class.forName( completePotentialClassName ); }
60cdf0e10cSrcweir             catch( java.lang.ClassNotFoundException e )
61cdf0e10cSrcweir             {
62cdf0e10cSrcweir                 continue;
63cdf0e10cSrcweir             }
64cdf0e10cSrcweir 
65cdf0e10cSrcweir             // see if it is derived from complexlib.ComplexTestCase
66cdf0e10cSrcweir             Class superClass = potentialTestClass.getSuperclass();
67cdf0e10cSrcweir             while ( superClass != null )
68cdf0e10cSrcweir             {
69cdf0e10cSrcweir                 if ( superClass.getName().equals( "complexlib.ComplexTestCase" ) )
70cdf0e10cSrcweir                 {
71cdf0e10cSrcweir                     String bareClassName = completePotentialClassName.substring( completePotentialClassName.lastIndexOf( '.' ) + 1 );
72cdf0e10cSrcweir                     String target = "run_" + bareClassName;
73cdf0e10cSrcweir                     targets.add( target );
74cdf0e10cSrcweir                     descs.add( getShortTestDescription( potentialTestClass ) );
75cdf0e10cSrcweir 
76cdf0e10cSrcweir                     if ( maxTargetLength < target.length() )
77cdf0e10cSrcweir                         maxTargetLength = target.length();
78cdf0e10cSrcweir                     break;
79cdf0e10cSrcweir                 }
80cdf0e10cSrcweir                 superClass = superClass.getSuperclass();
81cdf0e10cSrcweir             }
82cdf0e10cSrcweir         }
83cdf0e10cSrcweir 
84cdf0e10cSrcweir         System.out.println( "possible targets:" );
85cdf0e10cSrcweir         for ( int i=0; i<targets.size(); ++i )
86cdf0e10cSrcweir         {
87cdf0e10cSrcweir             // target
88cdf0e10cSrcweir             String target = (String)targets.get(i);
89cdf0e10cSrcweir             // 'tab'
90cdf0e10cSrcweir             System.out.print( "  " + target );
91cdf0e10cSrcweir             for ( int s = maxTargetLength - target.length(); s>0; --s )
92cdf0e10cSrcweir                 System.out.print( " " );
93cdf0e10cSrcweir             // description
94cdf0e10cSrcweir             System.out.println( " (" + (String)descs.get(i) + ")" );
95cdf0e10cSrcweir         }
96cdf0e10cSrcweir     }
97cdf0e10cSrcweir 
98cdf0e10cSrcweir     /** determines if the test denoted by a given Class is an interactive test
99cdf0e10cSrcweir      */
isInteractiveTest( Class testClass )100cdf0e10cSrcweir     static private boolean isInteractiveTest( Class testClass )
101cdf0e10cSrcweir     {
102cdf0e10cSrcweir         java.lang.reflect.Method interactiveTestMethod = null;
103cdf0e10cSrcweir         try { interactiveTestMethod = testClass.getMethod( "isInteractiveTest", new Class[]{} ); }
104cdf0e10cSrcweir         catch( Exception e ) { }
105cdf0e10cSrcweir 
106cdf0e10cSrcweir         if ( interactiveTestMethod != null )
107cdf0e10cSrcweir         {
108cdf0e10cSrcweir             try
109cdf0e10cSrcweir             {
110cdf0e10cSrcweir                 Boolean result = (Boolean)interactiveTestMethod.invoke( null, new Object[]{} );
111cdf0e10cSrcweir                 return result.booleanValue();
112cdf0e10cSrcweir             }
113cdf0e10cSrcweir             catch( Exception e ) { }
114cdf0e10cSrcweir         }
115cdf0e10cSrcweir         return false;
116cdf0e10cSrcweir     }
117cdf0e10cSrcweir 
getShortTestDescription( Class _testClass )118cdf0e10cSrcweir     static private String getShortTestDescription( Class _testClass )
119cdf0e10cSrcweir     {
120cdf0e10cSrcweir         java.lang.reflect.Method getShortDescriptionMethod = null;
121cdf0e10cSrcweir         try { getShortDescriptionMethod = _testClass.getMethod( "getShortTestDescription", new Class[]{} ); }
122cdf0e10cSrcweir         catch( Exception e ) { }
123cdf0e10cSrcweir 
124cdf0e10cSrcweir         if ( getShortDescriptionMethod != null )
125cdf0e10cSrcweir         {
126cdf0e10cSrcweir             try
127cdf0e10cSrcweir             {
128cdf0e10cSrcweir                 return (String)getShortDescriptionMethod.invoke( null, new Object[]{} );
129cdf0e10cSrcweir             }
130cdf0e10cSrcweir             catch( Exception e ) { }
131cdf0e10cSrcweir         }
132cdf0e10cSrcweir         return "no description provided by the test";
133cdf0e10cSrcweir     }
134cdf0e10cSrcweir }
135