Hi,
figured it out. Pardon my sucky ruby, i don't know anything about ruby
or rake, but it works. Suggestions welcome.


 def get_dependencies file
   #puts "get_dependencies #{file}"
                unless @scanned_files[file]
                        @scanned_files[file] = []
                end

   classes = []
         klass = ""

   # get list of classes from file
   top_levels_joined = @toplevels.join("|") # join here for optimization
   open(file).each_line do |line|
     if line =~ /(?!class\s+)((?:#{top_levels_joined})\.(?:\w|\.)+)/o
                         klass = $1.gsub(".", "/") + ".as"
       classes.push klass
                         @scanned_files[file].push klass
     end
   end
   # check against classpath
   classes.each do |klass|
     CLASSPATH.each do |classpath|
       path = classpath+"/"+klass
       if File.exists? path
         @files[path] = 1
         unless @scanned_files.has_key? path
           get_dependencies(path)
         end
         break
       end
     end
   end

         @scanned_files
#   @files.keys
 end

end

snoop = ASSnoop.new
@files = snoop.get_dependencies(ARGV[0]).sort.uniq
@files.each do |key, file|
        puts key+"{"
        file.uniq.each do |val|
                puts "\t"+val
        end
        puts "}"
end

On 9/5/06, Ray Chuan <[EMAIL PROTECTED]> wrote:
> Hi,
>
> would it be possible to get the immediate dependencies for a file,
> instead of collectively?
>
> Eg.
>
> class A extends B {
>
> }
>
> class B extends C {
>
> }
>
> class C {
>
> }
>
> ruby snoop.rb A: B, C
> ruby snoop_imm.rb A: B
>
> On 9/5/06, Benjamin Jackson <[EMAIL PROTECTED]> wrote:
> > It's your lucky day. I just spent this morning optimizing this code.
> > Save this as 'snoop.rb'. Usage is 'ruby snoop.rb <filename>'.
> >
> > require 'rubygems'
> > require "rake"
> >
> > class ASSnoop
> >
> >   CLASSPATH = ["vendor", "lib", "lib/std", "lib/std8"]
> >
> >   def initialize
> >     @scanned_files = Hash.new
> >     @files = Hash.new
> >     @toplevels = []
> >     CLASSPATH.each do |cp|
> >       FileList["#{cp}/*"].each do |path|
> >         @toplevels.push File.basename(path, ".as")
> >       end
> >     end
> >   end
> >
> >   def get_dependencies file
> >     #puts "get_dependencies #{file}"
> >     @scanned_files[file] = 1
> >     classes = []
> >     # get list of classes from file
> >     top_levels_joined = @toplevels.join("|") # join here for optimization
> >     open(file).each_line do |line|
> >       if line =~ /(?!class\s+)((?:#{top_levels_joined})\.(?:\w|\.)+)/o
> >         classes.push $1.gsub(".", "/") + ".as"
> >       end
> >     end
> >     # check againsts classpath
> >     classes.each do |klass|
> >       CLASSPATH.each do |classpath|
> >         path = classpath+"/"+klass
> >         if File.exists? path
> >           @files[path] = 1
> >           unless @scanned_files.has_key? path
> >             get_dependencies(path)
> >           end
> >           break
> >         end
> >       end
> >     end
> >     @files.keys
> >   end
> >
> > end
> >
> > snoop = ASSnoop.new
> > puts snoop.get_dependencies(ARGV[0]).sort.uniq
> >
> >
> >
> > On 9/4/06, Scott Hyndman <[EMAIL PROTECTED]> wrote:
> > > UML doesn't necessarily help you with dependencies. What about local 
> > > variables?
> > >
> > > Scott
> > >
> > > On 04/09/06, Andrew Eatherington <[EMAIL PROTECTED]> wrote:
> > > >
> > > > Oh okay, Enterprise Architect. I thought EA5 was an open source 
> > > > offering.
> > > >
> > > > Don't suppose anyone knows of a utility (cheap/free) that does do this?
> > > > (create UML diagrams from AS classes).
> > > >
> > > > Xcode has what sounds like a great tool, class modeling. It doesn't work
> > > > with AS though. I would love to be able to move back and forward from a
> > > > design (UML) view to a class view.
> > > >
> > > > Xcode help extract:
> > > > When you create a model, you add the source or the header files (or 
> > > > both),
> > > > or containers (such as groups, targets, or projects, but not 
> > > > smartgroups,
> > > > build phases, find results, and so on) that you want to contribute to 
> > > > the
> > > > model. A model is dynamic, though. It is continuously updated in 
> > > > response to
> > > > changes in your source code and the organization of your project.
> > > >
> > > > Thanks, Andrew.
> > > >
> > > >
> > > >
> > > > On 4 Sep 2006, at 21:15, Marcelo de Moraes Serpa wrote:
> > > >
> > > > www.sparxsystems.com (copied directly from google :P)
> > > >
> > > > On 9/4/06, Andrew Eatherington <[EMAIL PROTECTED]> wrote:
> > > > >
> > > > >
> > > > >
> > > > >
> > > > > You could also use EA5 and reverse engineer your code to uml class
> > > > diagrams...
> > > > >
> > > > >
> > > > > Sounds interesting. Do you have a link?
> > > > >
> > > > >
> > > > > Thanks,
> > > > >
> > > > > Andrew
> > > > >
> > > > >
> > > > >
> > > > >
> > > > > On 4 Sep 2006, at 15:09, Marcelo de Moraes Serpa wrote:
> > > > >
> > > > > Have you taken a look at SexieR?
> > > > >
> > > > > You could also use EA5 and reverse engineer your code to uml class
> > > > diagrams...
> > > > >
> > > > > Marcelo.
> > > > >
> > > > >
> > > > > On 9/4/06, Zárate <[EMAIL PROTECTED]> wrote:
> > > > > > Hi all,
> > > > > >
> > > > > > Is there any tool which you give it a class and you get all the
> > > > > > classes that are going to be compiled with in the swf? That's
> > > > > > something that compilers should know anyway, isn't it?
> > > > > >
> > > > > > Cheers,
> > > > > >
> > > > > > Juan
> > > > > >
> > > > > > --
> > > > > > Juan Delgado - Zárate
> > > > > > http://www.zarate.tv
> > > > > >
> > > > > > _______________________________________________
> > > > > > osflash mailing list
> > > > > > [email protected]
> > > > > > http://osflash.org/mailman/listinfo/osflash_osflash.org
> > > > > >
> > > > >
> > > > >
> > > > > _______________________________________________
> > > > > osflash mailing list
> > > > > [email protected]
> > > > > http://osflash.org/mailman/listinfo/osflash_osflash.org
> > > > >
> > > > >
> > > > > _______________________________________________
> > > > > osflash mailing list
> > > > > [email protected]
> > > > > http://osflash.org/mailman/listinfo/osflash_osflash.org
> > > > >
> > > > >
> > > > >
> > > >
> > > >
> > > > _______________________________________________
> > > > osflash mailing list
> > > > [email protected]
> > > > http://osflash.org/mailman/listinfo/osflash_osflash.org
> > > >
> > > >
> > > > _______________________________________________
> > > > osflash mailing list
> > > > [email protected]
> > > > http://osflash.org/mailman/listinfo/osflash_osflash.org
> > > >
> > > >
> > > >
> > >
> > > _______________________________________________
> > > osflash mailing list
> > > [email protected]
> > > http://osflash.org/mailman/listinfo/osflash_osflash.org
> > >
> > _______________________________________________
> > osflash mailing list
> > [email protected]
> > http://osflash.org/mailman/listinfo/osflash_osflash.org
> >
>
>
> --
> Cheers,
> Ray Chuan
>


-- 
Cheers,
Ray Chuan

_______________________________________________
osflash mailing list
[email protected]
http://osflash.org/mailman/listinfo/osflash_osflash.org

Reply via email to