Java-Gaming.org
Play Revenge of the Titans! The situation is critical. We need fancy commanders to defend Earth, the moon, Mars!
Featured games (78)
games approved by the League of Dukes
Games in Showcase (407)
games submitted by our members
Games in WIP (293)
games currently in development
News: Read the Java Gaming Resources, or peek at the official Java tutorials
 
    Home     Help   Search   Login   Register   
Pages: [1]
  ignore  |  Print  
  Automatically locate all classes; filter by regexp  (Read 3941 times)
0 Members and 1 Guest are viewing this topic.
Offline blahblahblahh

JGO Coder


Medals: 1


http://t-machine.org


« Posted 2005-05-30 21:20:47 »

This was originally written by duncanidaho, and then I started using it almost a year ago, and added various bugfixes and improvements along the way.

http://javagamesfactory.org/views/view-sourcesnippet?id=1

This is an "Automatic class locater and loader":

  • Supply a regexp filter defining a classname (e.g. "com.sun.*") and ask it to find all classes anywhere on your classpath and in ANY jars that match that search
  • Provide a list of regexps that you want it to completely ignore (for increased performance, for instance), e.g. "org.apache.*" if you're using some apache packages, and only want to find things in your packages
  • Find all classes that implement a given interface (Yes! Really!)
  • ...or do it using a regexp to filter out unwanted subclass names / improve search performance
  • Produces a list of classes that were REQUIRED by some of the classes it found; tells you which classes required them (so you can decide if you care or not)
  • Extensive error handling so that it recovers from practially every possible failure (um; only by trial-and-error - I may have missed some - let me know if you hit any new ones, or spot something that should be handled and currently isn't)
  • ...probably does some other stuff too that I've forgotten about Wink


FYI it's been running on every restart on the JGF server (auto-locates classes to be loaded to run parts of the system) for the last 6 months or so, and I'm pretty confident it's robust now (although I found many fiddly little bugs and problems along the way).

malloc will be first against the wall when the revolution comes...
Offline Riven
« League of Dukes »

JGO Overlord


Medals: 438
Projects: 4


Hand over your head.


« Reply #1 - Posted 2005-05-31 06:05:18 »

ClassPath.java was viewable, but I think I crashed your server while clicking the ClassLocator.java link.

The server-response was an image Shocked (MagicWoods thumbnail) instead of the java-code... and after that the server stopped responding.

I've had wrong images before: game-thumbnails in the LWJGL/JOGL comparision where you would expect the green/yellow round buttons.

Hope this helps..!  Smiley

Hi, appreciate more people! Σ ♥ = ¾
Learn how to award medals... and work your way up the social rankings
Projects: Revenge of the Titans, Titan Attacks, Droid Assault, and Ultratron
Offline kevglass
« League of Dukes »

JGO Kernel


Medals: 54
Projects: 20


Mentally unstable, best avoided.


« Reply #2 - Posted 2005-05-31 07:17:47 »

Incidently, I found attempting to log in to JGF crashed with an error report, which didn't tell me where to mail it.

When I got back to the site I still could find an email address to mail the stack trace to?

Kev

Games published by our own members! Check 'em out!
Try the Free Demo of Titan Attacks
Offline blahblahblahh

JGO Coder


Medals: 1


http://t-machine.org


« Reply #3 - Posted 2005-06-02 21:24:18 »

Incidently, I found attempting to log in to JGF crashed with an error report, which didn't tell me where to mail it.

Something in the last patches on Sunday is deeply wrong - generated > 15gb of logfiles in 2 days, ran out of disk space Sad. Trying to find out what's in there now, but 15Gb is not easy to examine Smiley.

Quote
When I got back to the site I still could find an email address to mail the stack trace to?

Thanks, I'll add that to the todo list. The stack-trace-display is hard-coded (for obvious reasons) so I need to actually dig into code, but it'll be no problem.

malloc will be first against the wall when the revolution comes...
Offline Luke

Senior Newbie




I love YaBB 1G - SP1!


« Reply #4 - Posted 2005-07-02 22:29:43 »

This sounds like exactly what I have been looking for.  Any chance of posting the code here or sending me a copy?

Luke
Offline blahblahblahh

JGO Coder


Medals: 1


http://t-machine.org


« Reply #5 - Posted 2005-08-09 17:08:44 »

This sounds like exactly what I have been looking for.  Any chance of posting the code here or sending me a copy?

Main site link works fine now AFAICS.

malloc will be first against the wall when the revolution comes...
Offline t_larkworthy

Senior Member


Medals: 1
Projects: 1


Google App Engine Rocks!


« Reply #6 - Posted 2005-10-03 11:28:48 »

Oh wow. thats a great utility

Runesketch: an Online CCG built on Google App Engine where players draw their cards and trade. Fight, draw or trade yourself to success.
Offline CommanderKeith
« Reply #7 - Posted 2006-02-18 03:19:49 »


  • Find all classes that implement a given interface (Yes! Really!)
That's exactly what I need, but the link to the code doesn't work.  Can it be repaired?

Keith

Offline blahblahblahh

JGO Coder


Medals: 1


http://t-machine.org


« Reply #8 - Posted 2006-02-20 17:08:52 »

Seems to be working fine at the moment.

NB: if it ever stops working, try again after 6am GMT (server is resetting itself every morning at 6am to combat a memory leak that periodically locks it up Sad )

malloc will be first against the wall when the revolution comes...
Offline CommanderKeith
« Reply #9 - Posted 2006-02-21 14:53:16 »

Thanks, got it going.  Very useful,

Cheers,


Games published by our own members! Check 'em out!
Legends of Yore - The Casual Retro Roguelike
Offline zero

Junior Member





« Reply #10 - Posted 2006-04-09 16:04:10 »

Find all classes that implement a given interface (Yes! Really!)

Maybe I'm doing s.th. wron, but it doesn't work for me. I tried the following:

1  
2  
3  
Class[] list = new ClassLocater().getSubclassesOf(java.util.EventListener.class);
for(Class c : list)
  System.out.println(c);


butg there are no classes and interfaces listed from the java.awt.event package.  Sad
Offline blahblahblahh

JGO Coder


Medals: 1


http://t-machine.org


« Reply #11 - Posted 2006-04-09 16:18:27 »

Most people want to skip the thousands of java and sun classes, so the default constructor filters them out:

public ClassLocater()
  {
    addSkipPrefix( "org.apache.log4j." );
    addSkipPrefix( "com.sun." );
    addSkipPrefix( "java" );
  }

This is documented - if you look at the class constructor, it says:

/**
   * Automatically adds sun's classes, the java library classes, and the Apache
   * log4j classes (a lib used by ClassLocater!) to the skip list; it's very unlikely
   * that you're trying to locate any of these!
   */

So, if you just comment out the line that skips everything starting with "java" you should be fine.

malloc will be first against the wall when the revolution comes...
Offline zero

Junior Member





« Reply #12 - Posted 2006-04-09 18:05:35 »

thanks for the answer bbb.
of course I read the doc above the construrctor and commented the lines out, but forgot to mention this  Roll Eyes

1  
2  
3  
4  
5  
    public ClassLocater() {
       // addSkipPrefix( "org.apache.log4j." );
     //  addSkipPrefix( "com.sun." );
     //  addSkipPrefix( "java" );
   }


any ideas?
Offline blahblahblahh

JGO Coder


Medals: 1


http://t-machine.org


« Reply #13 - Posted 2006-04-09 21:01:56 »

Output? Have you turned on the debug mode for the loggers? You could also try adding extra logging,especially in ClassPath (I never needed any for it, so I never added any detailed loggers, but that would be a useful thing).

malloc will be first against the wall when the revolution comes...
Pages: [1]
  ignore  |  Print  
 
 
You cannot reply to this message, because it is very, very old.

Play Revenge of the Titans! The situation is critical. We need fancy commanders to defend Earth, the moon, Mars!
 
Browse for soundtracks for your game!

Add your game by posting it in the WIP section,
or publish it in Showcase.

The first screenshot will be displayed as a thumbnail.

The invasion has landed! On Mars! And you're there to beat 'em!
cubemaster21 (91 views)
2013-05-17 21:29:12

alaslipknot (100 views)
2013-05-16 21:24:48

gouessej (130 views)
2013-05-16 00:53:38

gouessej (125 views)
2013-05-16 00:17:58

theagentd (136 views)
2013-05-15 15:01:13

theagentd (123 views)
2013-05-15 15:00:54

StreetDoggy (165 views)
2013-05-14 15:56:26

kutucuk (187 views)
2013-05-12 17:10:36

kutucuk (190 views)
2013-05-12 15:36:09

UnluckyDevil (196 views)
2013-05-12 05:09:57
Complex number cookbook
by Roquen
2013-04-24 12:47:31

2D Dynamic Lighting
by Oskuro
2013-04-17 16:46:12

2D Dynamic Lighting
by Oskuro
2013-04-17 16:45:57

2D Dynamic Lighting
by Oskuro
2013-04-17 16:23:20

Noise (bandpassed white)
by Roquen
2013-04-05 17:36:01

Noise (bandpassed white)
by Roquen
2013-04-03 16:17:38

Java Data structures
by Roquen
2013-03-29 13:21:12

Topic Request
by kutucuk
2013-03-22 21:42:01
Powered by MySQL Powered by PHP Powered by SMF 1.1.18 | SMF © 2013, Simple Machines | Managed by Enhanced Four Valid XHTML 1.0! Valid CSS!
Page created in 0.162 seconds with 21 queries.