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 
22 
23 
24 package complexlib;
25 
26 /**
27  *
28  * @author fs93730
29  */
30 public class ShowTargets
31 {
32     /** Creates a new instance of ShowTargets */
ShowTargets()33     public ShowTargets()
34     {
35     }
36 
main( String[] args )37     public static void main( String[] args )
38     {
39         java.util.Vector targets = new java.util.Vector();
40         java.util.Vector descs = new java.util.Vector();
41 
42         targets.add( "run" );
43         descs.add( "runs all complex tests in this module" );
44 
45         int maxTargetLength = 3;
46 
47         for ( int i = 0; i < args.length; ++i )
48         {
49             String completePotentialClassName = args[i].replace( '/', '.' );
50 
51             // filter
52             if ( completePotentialClassName.endsWith( ".TestCase" ) )
53                 continue;
54             if ( completePotentialClassName.endsWith( ".TestSkeleton" ) )
55                 continue;
56 
57             // get the class
58             Class potentialTestClass = null;
59             try { potentialTestClass = Class.forName( completePotentialClassName ); }
60             catch( java.lang.ClassNotFoundException e )
61             {
62                 continue;
63             }
64 
65             // see if it is derived from complexlib.ComplexTestCase
66             Class superClass = potentialTestClass.getSuperclass();
67             while ( superClass != null )
68             {
69                 if ( superClass.getName().equals( "complexlib.ComplexTestCase" ) )
70                 {
71                     String bareClassName = completePotentialClassName.substring( completePotentialClassName.lastIndexOf( '.' ) + 1 );
72                     String target = "run_" + bareClassName;
73                     targets.add( target );
74                     descs.add( getShortTestDescription( potentialTestClass ) );
75 
76                     if ( maxTargetLength < target.length() )
77                         maxTargetLength = target.length();
78                     break;
79                 }
80                 superClass = superClass.getSuperclass();
81             }
82         }
83 
84         System.out.println( "possible targets:" );
85         for ( int i=0; i<targets.size(); ++i )
86         {
87             // target
88             String target = (String)targets.get(i);
89             // 'tab'
90             System.out.print( "  " + target );
91             for ( int s = maxTargetLength - target.length(); s>0; --s )
92                 System.out.print( " " );
93             // description
94             System.out.println( " (" + (String)descs.get(i) + ")" );
95         }
96     }
97 
98     /** determines if the test denoted by a given Class is an interactive test
99      */
isInteractiveTest( Class testClass )100     static private boolean isInteractiveTest( Class testClass )
101     {
102         java.lang.reflect.Method interactiveTestMethod = null;
103         try { interactiveTestMethod = testClass.getMethod( "isInteractiveTest", new Class[]{} ); }
104         catch( Exception e ) { }
105 
106         if ( interactiveTestMethod != null )
107         {
108             try
109             {
110                 Boolean result = (Boolean)interactiveTestMethod.invoke( null, new Object[]{} );
111                 return result.booleanValue();
112             }
113             catch( Exception e ) { }
114         }
115         return false;
116     }
117 
getShortTestDescription( Class _testClass )118     static private String getShortTestDescription( Class _testClass )
119     {
120         java.lang.reflect.Method getShortDescriptionMethod = null;
121         try { getShortDescriptionMethod = _testClass.getMethod( "getShortTestDescription", new Class[]{} ); }
122         catch( Exception e ) { }
123 
124         if ( getShortDescriptionMethod != null )
125         {
126             try
127             {
128                 return (String)getShortDescriptionMethod.invoke( null, new Object[]{} );
129             }
130             catch( Exception e ) { }
131         }
132         return "no description provided by the test";
133     }
134 }
135