Download
Getting Started
Members
Projects
Community
Marketplace
Events
Planet Eclipse
Newsletter
Videos
Participate
Report a Bug
Forums
Mailing Lists
Wiki
IRC
How to Contribute
Working Groups
Automotive
Internet of Things
LocationTech
Long-Term Support
PolarSys
Science
OpenMDM
More
Community
Marketplace
Events
Planet Eclipse
Newsletter
Videos
Participate
Report a Bug
Forums
Mailing Lists
Wiki
IRC
How to Contribute
Working Groups
Automotive
Internet of Things
LocationTech
Long-Term Support
PolarSys
Science
OpenMDM
Toggle navigation
Bugzilla – Attachment 196853 Details for
Bug 347446
Get rid of the test suites
Home
|
New
|
Browse
|
Search
|
[?]
|
Reports
|
Requests
|
Help
|
Log In
[x]
|
Terms of Use
|
Copyright Agent
Some Eclipse Foundation services are deprecated, or will be soon. Please ensure you've read
this important communication.
[patch]
RWTAllTestSuite that returns all classes on the class path that match *_Test
clipboard.txt (text/plain), 4.96 KB, created by
RĂ¼diger Herrmann
on 2011-05-29 12:50:05 EDT
(
hide
)
Description:
RWTAllTestSuite that returns all classes on the class path that match *_Test
Filename:
MIME Type:
Creator:
RĂ¼diger Herrmann
Created:
2011-05-29 12:50:05 EDT
Size:
4.96 KB
patch
obsolete
>### Eclipse Workspace Patch 1.0 >#P org.eclipse.rwt.test.all >Index: src/org/eclipse/rwt/test/RWTAllTestSuite.java >=================================================================== >RCS file: /cvsroot/rt/org.eclipse.rap/runtime.rwt.test/org.eclipse.rwt.test.all/src/org/eclipse/rwt/test/RWTAllTestSuite.java,v >retrieving revision 1.5 >diff -u -r1.5 RWTAllTestSuite.java >--- src/org/eclipse/rwt/test/RWTAllTestSuite.java 7 Feb 2011 11:10:04 -0000 1.5 >+++ src/org/eclipse/rwt/test/RWTAllTestSuite.java 29 May 2011 16:45:47 -0000 >@@ -10,23 +10,127 @@ > *******************************************************************************/ > package org.eclipse.rwt.test; > >+import java.io.*; >+import java.net.URL; >+import java.net.URLClassLoader; >+import java.util.jar.JarEntry; >+import java.util.jar.JarInputStream; >+ > import junit.framework.Test; > import junit.framework.TestSuite; > >-import org.eclipse.RWTHostTestSuite; >-import org.eclipse.RWTQ07TestSuite; >-import org.eclipse.rap.rwt.themes.test.ThemesTestSuite; >- > > public class RWTAllTestSuite { >+ private static final String JAR_EXTENSION = ".jar"; >+ private static final String CLASS_EXTENSION = ".class"; > > public static Test suite() { >- TestSuite suite = new TestSuite( "Test for all RWT Tests" ); >- // $JUnit-BEGIN$ >- suite.addTest( RWTHostTestSuite.suite() ); >- suite.addTest( RWTQ07TestSuite.suite() ); >- suite.addTest( ThemesTestSuite.suite() ); >- // $JUnit-END$ >+ return new RWTAllTestSuite().createSuite(); >+ } >+ >+ private final TestSuite suite; >+ private final URLClassLoader classLoader; >+ >+ RWTAllTestSuite() { >+ suite = new TestSuite( "RWT Test Suite" ); >+ classLoader = ( URLClassLoader )getClass().getClassLoader(); >+ } >+ >+ Test createSuite() { >+ try { >+ scanClasspath(); >+ } catch( IOException ioe ) { >+ throw new RuntimeException( ioe ); >+ } > return suite; > } >+ >+ private void scanClasspath() throws IOException { >+ URL[] urls = classLoader.getURLs(); >+ for( int i = 0; i < urls.length; i++ ) { >+ File file = new File( urls[ i ].getFile() ); >+ if( file.exists() ) { >+ if( file.getName().endsWith( JAR_EXTENSION ) ) { >+ scanJar( file ); >+ } else { >+ scanDirectory( file, "", file.getPath() ); >+ } >+ } >+ } >+ } >+ >+ private void scanJar( File file ) throws IOException { >+ JarInputStream inputStream = new JarInputStream( new FileInputStream( file ), false ); >+ JarEntry jarEntry = inputStream.getNextJarEntry(); >+ while( jarEntry != null ) { >+ if( isClassEntry( jarEntry ) ) { >+ String className = toClassName( jarEntry ); >+ addToSuite( className ); >+ } >+ jarEntry = inputStream.getNextJarEntry(); >+ } >+ inputStream.close(); >+ } >+ >+ private void scanDirectory( File file, String initialPackagePath, String rootDirectory ) { >+ if( file.isDirectory() ) { >+ String packagePath = computePackagePath( file, initialPackagePath, rootDirectory ); >+ String[] files = file.list(); >+ for( int i = 0; i < files.length; i++ ) { >+ File directory = new File( file, files[ i ] ); >+ scanDirectory( directory, packagePath, rootDirectory ); >+ } >+ } else if( isClassFile( file ) ) { >+ String className = toClassName( file, initialPackagePath ); >+ addToSuite( className ); >+ } >+ } >+ >+ private static String computePackagePath( File file, String initialPackagePath, String rootDir ) { >+ String result; >+ if( file.getPath().equals( rootDir ) ) { >+ result = ""; >+ } else if( initialPackagePath.length() == 0 ) { >+ result = file.getName(); >+ } else { >+ result = initialPackagePath + "." + file.getName(); >+ } >+ return result; >+ } >+ >+ private void addToSuite( String className ) { >+ if( className.endsWith( "_Test" ) ) { >+ try { >+ suite.addTestSuite( classLoader.loadClass( className ) ); >+ } catch( ClassNotFoundException cnfe ) { >+ throw new RuntimeException( cnfe ); >+ } >+ } >+ } >+ >+ private static String toClassName( JarEntry jarEntry ) { >+ String result = removeExtension( jarEntry.getName(), CLASS_EXTENSION ); >+ result = result.replace( '/', '.' ); >+ return result; >+ } >+ >+ private static String toClassName( File file, String packageName ) { >+ String result = removeExtension( file.getName(), CLASS_EXTENSION ); >+ if( packageName.length() > 0 ) { >+ result = packageName + "." + result; >+ } >+ return result; >+ } >+ >+ private static String removeExtension( String name, String extension ) { >+ return name.substring( 0, name.lastIndexOf( extension ) ); >+ } >+ >+ private static boolean isClassEntry( JarEntry jarEntry ) { >+ return ( !jarEntry.isDirectory() ) && jarEntry.getName().endsWith( CLASS_EXTENSION ); >+ } >+ >+ private static boolean isClassFile( File file ) { >+ return file.isFile() && file.getName().endsWith( CLASS_EXTENSION ); >+ } > }
You cannot view the attachment while viewing its details because your browser does not support IFRAMEs.
View the attachment on a separate page
.
View Attachment As Diff
View Attachment As Raw
Actions:
View
|
Diff
Attachments on
bug 347446
: 196853 |
197293