Graphviz - a tool for the postmodern programmer
Graphvizis a great tool for the postmodern programmer. It's got a simple to integrate interface of text files and command line execution. Bjorn Freeman-Bensonis visiting at the moment. He suggested we demonstrate graphviz using the dependencies between eclipse plugins. So here's the code that reads the eclipse manifest files and the resulting graph. This graph shows the dependencies between a significant subset of the standard eclipse 3.1 plugins. Bjorn and I have paired on this to bring you "postable" code that doesn't embarrass us too much.
import sys, time
from os import listdir, system
from os.path import join, isdir, exists
import os.path
from zipfile import is_zipfile, ZipFile
class DependencyGrapher:
def run(self, pluginDirectory):
files = [join(pluginDirectory, file) for file in listdir(pluginDirectory)]
graphText = self.process_files(files)
f=open("graph.txt","w")
graphText = 'digraph G {\n "' +\
"generated on " + time.asctime() + '";\n' +\
graphText + "\n}"
f.write(graphText)
f.close()
system("dot -Tpng -ograph.png graph.txt")
def process_files(self, files):
result = ""
for file in files:
if isdir(file):
result += self.process_plugin_directory(file)
if is_zipfile(file):
result += self.process_plugin_jar(file)
return result
def process_plugin_directory(self, directory):
propertiesFileName = join(directory,"META-INF","MANIFEST.MF")
if exists(propertiesFileName):
return self.process_properties(self.graphviz_friendly_name_from_plugin_filename(directory), open(propertiesFileName).read())
return ""
def process_plugin_jar(self, jarName):
try:
jar = ZipFile(jarName)
propertiesFile = jar.read("META-INF/MANIFEST.MF")
return self.process_properties(self.graphviz_friendly_name_from_plugin_filename(jarName), propertiesFile)
finally:
jar.close()
def process_properties(self, pluginName, properties):
result = ""
start = properties.find("Require-Bundle:")
if start != -1:
lines = [line.strip() for line in properties[start+len("Require-Bundle:"):].split('\n')]
for line in [line for line in lines if len(line) > 0]:
lastLine = not line.endswith(',')
if not lastLine:
line = line[:-1]
parts = line.split(';')
line = parts[0]
result += self.graphviz_friendly_name(pluginName) + " -> " + self.graphviz_friendly_name(line) + ";\n"
if lastLine:
break
return result
def graphviz_friendly_name(self, line):
return line.replace('.','_')
def graphviz_friendly_name_from_plugin_filename(self, fileName):
return self.graphviz_friendly_name(os.path.split(fileName)[-1].split('_')[0])
if __name__ == "__main__":
if len(sys.argv) != 2:
print "need plugin directory location"
print 'e.g. python dependencies.py "C:\Program Files\eclipse\plugins"'
sys.exit(1)
pluginDirectory = sys.argv[1]
DependencyGrapher().run(pluginDirectory) Related Articles
Tracing function calls using Python decorators
Jesper Møller: Monkey see, abe gør
Neil Bartlett: An OSGi Bundle… built in Scala
David Bosschaert: OSGi Services for Dynamic Applications (II)
A "Hello" program on EJB3 with Jboss server 4.2.2GA.
JavaScript Based Code Prettification
Marcelo Paternostro: Platform scheme URI
Tom Schindl: More details about Databinding and GWT
Jesper Møller: Monkey see, abe gør
Neil Bartlett: An OSGi Bundle… built in Scala
David Bosschaert: OSGi Services for Dynamic Applications (II)
A "Hello" program on EJB3 with Jboss server 4.2.2GA.
JavaScript Based Code Prettification
Marcelo Paternostro: Platform scheme URI
Tom Schindl: More details about Databinding and GWT
Relatd Projects
JarSearch is an Eclipse plugin that integrates gracefully into the Eclipse Search extension points. It enables Java developers to quickly locate jar files that contain a given class file (binary/source) or properties file. It supports embedded jars.
id3toolsPlugin based tools appliable on multiple files at once through a simple GUI. Seting custom ID3 tag info, renaming of file according to tag, setting tag from filename and many more basic tools provided. Developing of new plugins easy and fast.
jmp3renamerJMP3Renamer is a plugin-based renamer/tagger written in Java. It supports automatical assignment of the data to the files and magic cookies to specify the filename format. Currently available plugins: Discogs, MusicBrainz, Filename, Filetag, Mp3, Ogg
meclipseplugplMaven plugin that can be used to build distributions of Eclipse plugins as folders or ZIP files. It has a similiar functionality as the Export wizard in Eclipse and uses the build properties specified by the Eclipes PDE wizard.
jarajarJar Ajar is a JAR-based self-extractor for zip files. Zip up files and package them with descriptive images and text using Jar Ajar's graphical interface. When recipients launch the resulting JAR, Jar Ajar guides users through the unzip process.
onelinejdbcGet/Put java VO & XML from SQL stmts in 1 line; No config mapping; Plugin-Arch support; Hibernate and ibatis benchmarked. Lightweight(24KB); Self healing pool; Code Generation for CRUD. Embedded Solr Search. More @ http://onelinejdbc.wiki.sourceforge.net
copyaspathCopyAsPath is an Eclipse plugin that enables to copy the path of a file or directory to the Clipboard by right-clicking it in the navigator view and choosing "Copy as Path" from the context menu.
renamewandSimple command-line file & directory renamer. Use a friendly but powerful syntax (like regex, only much easier) to rename files & directories. Perform string & arithmetic operations, enumerate files, insert timestamps, and other file & system attributes.
codematecodemate is a eclipse plugin. it can stat code and create a result report view for code line number.
shiningaffixShiningAffix is a set of Eclipse plugins that simplifies work and allow some basic activites. First plugin is FileDrop - to allow drag and drop file from Explorer to Eclipse and open it in standard Eclipse Editor




