1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: ShowTargets.java,v $
12 * This file is part of OpenOffice.org.
14 * OpenOffice.org is free software: you can redistribute it and/or modify
15 * it under the terms of the GNU Lesser General Public License version 3
16 * only, as published by the Free Software Foundation.
18 * OpenOffice.org is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU Lesser General Public License version 3 for more details
22 * (a copy is included in the LICENSE file that accompanied this code).
24 * You should have received a copy of the GNU Lesser General Public License
25 * version 3 along with OpenOffice.org. If not, see
26 * <http://www.openoffice.org/license.html>
27 * for a copy of the LGPLv3 License.
29 ************************************************************************/
37 public class ShowTargets
39 /** Creates a new instance of ShowTargets */
44 public static void main( String
[] args
)
46 java
.util
.Vector targets
= new java
.util
.Vector();
47 java
.util
.Vector descs
= new java
.util
.Vector();
50 descs
.add( "runs all complex tests in this module" );
52 int maxTargetLength
= 3;
54 for ( int i
= 0; i
< args
.length
; ++i
)
56 String completePotentialClassName
= args
[i
].replace( '/', '.' );
59 if ( completePotentialClassName
.endsWith( ".TestCase" ) )
61 if ( completePotentialClassName
.endsWith( ".TestSkeleton" ) )
65 Class potentialTestClass
= null;
66 try { potentialTestClass
= Class
.forName( completePotentialClassName
); }
67 catch( java
.lang
.ClassNotFoundException e
)
72 // see if it is derived from complexlib.ComplexTestCase
73 Class superClass
= potentialTestClass
.getSuperclass();
74 while ( superClass
!= null )
76 if ( superClass
.getName().equals( "complexlib.ComplexTestCase" ) )
78 String bareClassName
= completePotentialClassName
.substring( completePotentialClassName
.lastIndexOf( '.' ) + 1 );
79 String target
= "run_" + bareClassName
;
80 targets
.add( target
);
81 descs
.add( getShortTestDescription( potentialTestClass
) );
83 if ( maxTargetLength
< target
.length() )
84 maxTargetLength
= target
.length();
87 superClass
= superClass
.getSuperclass();
91 System
.out
.println( "possible targets:" );
92 for ( int i
=0; i
<targets
.size(); ++i
)
95 String target
= (String
)targets
.get(i
);
97 System
.out
.print( " " + target
);
98 for ( int s
= maxTargetLength
- target
.length(); s
>0; --s
)
99 System
.out
.print( " " );
101 System
.out
.println( " (" + (String
)descs
.get(i
) + ")" );
105 /** determines if the test denoted by a given Class is an interactive test
107 static private boolean isInteractiveTest( Class testClass
)
109 java
.lang
.reflect
.Method interactiveTestMethod
= null;
110 try { interactiveTestMethod
= testClass
.getMethod( "isInteractiveTest", new Class
[]{} ); }
111 catch( Exception e
) { }
113 if ( interactiveTestMethod
!= null )
117 Boolean result
= (Boolean
)interactiveTestMethod
.invoke( null, new Object
[]{} );
118 return result
.booleanValue();
120 catch( Exception e
) { }
125 static private String
getShortTestDescription( Class _testClass
)
127 java
.lang
.reflect
.Method getShortDescriptionMethod
= null;
128 try { getShortDescriptionMethod
= _testClass
.getMethod( "getShortTestDescription", new Class
[]{} ); }
129 catch( Exception e
) { }
131 if ( getShortDescriptionMethod
!= null )
135 return (String
)getShortDescriptionMethod
.invoke( null, new Object
[]{} );
137 catch( Exception e
) { }
139 return "no description provided by the test";