Java-Gaming.org    
Featured games (78)
games approved by the League of Dukes
Games in Showcase (490)
games submitted by our members
Games in WIP (466)
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 4624 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...
Online Riven
Global Moderator

JGO Overlord


Medals: 610
Projects: 4
Exp: 16 years


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
Offline kevglass

JGO Kernel


Medals: 85
Projects: 22


Coder, Trainee Pixel Artist, Game Reviewer


« 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!
Legends of Yore - The Casual Retro Roguelike
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.

 

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

The first screenshot will be displayed as a thumbnail.

xsi3rr4x (72 views)
2014-04-15 18:08:23

BurntPizza (68 views)
2014-04-15 03:46:01

UprightPath (79 views)
2014-04-14 17:39:50

UprightPath (65 views)
2014-04-14 17:35:47

Porlus (80 views)
2014-04-14 15:48:38

tom_mai78101 (104 views)
2014-04-10 04:04:31

BurntPizza (164 views)
2014-04-08 23:06:04

tom_mai78101 (260 views)
2014-04-05 13:34:39

trollwarrior1 (210 views)
2014-04-04 12:06:45

CJLetsGame (220 views)
2014-04-01 02:16:10
List of Learning Resources
by SHC
2014-04-18 03:17:39

List of Learning Resources
by Longarmx
2014-04-08 03:14:44

Good Examples
by matheus23
2014-04-05 13:51:37

Good Examples
by Grunnt
2014-04-03 15:48:46

Good Examples
by Grunnt
2014-04-03 15:48:37

Good Examples
by matheus23
2014-04-01 18:40:51

Good Examples
by matheus23
2014-04-01 18:40:34

Anonymous/Local/Inner class gotchas
by Roquen
2014-03-11 15:22:30
java-gaming.org is not responsible for the content posted by its members, including references to external websites, and other references that may or may not have a relation with our primarily gaming and game production oriented community. inquiries and complaints can be sent via email to the info‑account of the company managing the website of java‑gaming.org
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!