Sure. Here's some python code I hacked up to calculate deps. The goal is to
calculate cross-package java deps and write them to a file which we check
in. Then changing package deps generates a diff for comment in code review,
avoiding accidental unwanted deps.
Note that the question is not so much whether it's possible in Java, but
whether we should suffer using Java for scripting tasks in return for
avoiding the python dep. I also noticed that in addition to the code review
script we also have a python script for compiling the HTML docs from RST.
#!/usr/bin/env python
import re
import os
import sys
# Matches an import line, separating the package part (lowercase only) from
# the type name.
IMPORT_RE = re.compile(r'import ([a-z0-9\.]+)\.([\w\.]+);')
def main():
if len(sys.argv) < 2:
print "Usage: %s <root>" % sys.argv[0]
exit(1)
root = sys.argv[1]
all_deps = {}
os.path.walk(root, find_deps, all_deps)
for (package, deps) in all_deps.iteritems():
print "===", package, "==="
ordered_deps = []
ordered_deps.extend(deps)
ordered_deps.sort()
for dep in ordered_deps:
print dep
print
def find_deps(all_deps, dir, names):
package = dir.partition('/')[2].replace('/', '.')
deps = set()
for sourcename in names:
if sourcename.endswith('.java'):
f = open(os.path.join(dir, sourcename))
for line in f:
match = IMPORT_RE.match(line)
if match:
dep = match.group(1)
deps.add(dep)
f.close()
if deps:
all_deps[package] = deps
if __name__ == "__main__":
main()
On 22 November 2010 16:22, Vega <[email protected]> wrote:
> If you can specify what exactly you want to accomplish with these
> scripts - I can try to do it with ant.
>
> On Nov 22, 12:25 am, Vega <[email protected]> wrote:
> > Also, windows users don't have python preinstalled, so that would
> > require additional dependency.
> >
> > On Nov 22, 12:23 am, Vega <[email protected]> wrote:
> >
> >
> >
> >
> >
> >
> >
> > > Umm, I am not sure about what scripts you are talking about, but if
> > > this can be done with ant - I would prefer it this way. Java
> > > programmers usually have some knowledge of ant, but python is
> > > different story.
> >
> > > On Nov 21, 11:49 pm, Tad Glines <[email protected]> wrote:
> >
> > > > Given that the review tool also requires python, I don't see a big
> problem
> > > > with additional python dependencies.
> >
> > > > -Tad
> >
> > > > On Sun, Nov 21, 2010 at 1:20 PM, Alex North <[email protected]>
> wrote:
> > > > > Hi all,
> >
> > > > > I'm considering introducing a python script to the codebase to help
> keep
> > > > > track of cross-module dependencies. We have tools to help this
> inside
> > > > > Google, which is why the libraries code, for example, is not a pile
> of
> > > > > dependency spaghetti. Unfortunately they're not appropriate to use
> outside.
> > > > > We have a couple of options:
> >
> > > > > - Do everything in Java so we can invoke it from ant
> > > > > - Use python (or some other scripting language) for scripting
> >
> > > > > While possible, I'm not excited about using Java for script-style
> things.
> > > > > We should use a platform-independent scripting language, and Python
> is
> > > > > widely known and understood. This would eventually be a path to
> replacing
> > > > > all the shell scripts and batch files too (though some of the run
> scripts
> > > > > can perhaps move into ant).
> >
> > > > > Python would only be required for development, not running the
> server.
> > > > > Pre-packaged distros would not require python.
> >
> > > > > Objections? Opinions?
> >
> > > > > Alex
> >
> > > > > --
> > > > > You received this message because you are subscribed to the Google
> Groups
> > > > > "Wave Protocol" group.
> > > > > To post to this group, send email to
> [email protected].
> > > > > To unsubscribe from this group, send email to
> > > > > [email protected]<wave-protocol%[email protected]>
> <wave-protocol%2bunsubscr...@goog legroups.com>
> > > > > .
> > > > > For more options, visit this group at
> > > > >http://groups.google.com/group/wave-protocol?hl=en.
>
> --
> You received this message because you are subscribed to the Google Groups
> "Wave Protocol" group.
> To post to this group, send email to [email protected].
> To unsubscribe from this group, send email to
> [email protected]<wave-protocol%[email protected]>
> .
> For more options, visit this group at
> http://groups.google.com/group/wave-protocol?hl=en.
>
>
--
You received this message because you are subscribed to the Google Groups "Wave
Protocol" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to
[email protected].
For more options, visit this group at
http://groups.google.com/group/wave-protocol?hl=en.