aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJames Le Cuirot <chewi@aura-online.co.uk>2008-06-16 14:58:37 +0000
committerJames Le Cuirot <chewi@aura-online.co.uk>2008-06-16 14:58:37 +0000
commite77d40c95262f66a0d31453804a9f45a25cb0f8b (patch)
treee38a8761827b9d2bc7c14c58f7e27ad88480c7d9
parentNew jarjarclean utility. (diff)
parentFix bugs caused by layout changes. (diff)
downloadjavatoolkit-e77d40c95262f66a0d31453804a9f45a25cb0f8b.tar.gz
javatoolkit-e77d40c95262f66a0d31453804a9f45a25cb0f8b.tar.bz2
javatoolkit-e77d40c95262f66a0d31453804a9f45a25cb0f8b.zip
Merge ali_bush's layout_refactor_branch back to trunk with some changes.
svn path=/projects/javatoolkit/trunk/; revision=6317
-rw-r--r--AUTHORS10
-rw-r--r--Makefile52
-rw-r--r--makedefs.mak21
-rw-r--r--setup.py32
-rwxr-xr-xsrc/bsfix/class-version-verify.py108
-rwxr-xr-xsrc/bsfix/xml-rewrite-3.py490
-rw-r--r--src/buildparser/Makefile17
-rwxr-xr-xsrc/buildparser/buildparser127
-rw-r--r--src/findclass/AUTHORS2
-rw-r--r--src/findclass/ChangeLog3
-rw-r--r--src/findclass/Makefile19
-rw-r--r--src/findclass/README0
-rw-r--r--src/findclass/TODO0
-rw-r--r--src/jarjarclean/Makefile17
-rwxr-xr-xsrc/jarjarclean/jarjarclean40
-rw-r--r--src/javatoolkit/.cvsignore1
-rw-r--r--src/javatoolkit/Makefile20
-rw-r--r--src/javatoolkit/classpath.py72
-rw-r--r--src/javatoolkit/parser/.cvsignore1
-rw-r--r--src/javatoolkit/parser/buildproperties.py86
-rw-r--r--src/javatoolkit/parser/helpers.py61
-rw-r--r--src/javatoolkit/parser/manifest.py64
-rw-r--r--src/javatoolkit/parser/parser.py16
-rw-r--r--src/javatoolkit/parser/tree.py138
-rw-r--r--src/man/findclass.1 (renamed from src/findclass/findclass.1)0
-rw-r--r--src/maven/Makefile21
-rwxr-xr-xsrc/maven/maven-helper.py346
-rw-r--r--src/obsolete/bsfix/JXSLT.java (renamed from src/bsfix/JXSLT.java)0
-rw-r--r--src/obsolete/bsfix/Makefile (renamed from src/bsfix/Makefile)0
-rwxr-xr-xsrc/obsolete/bsfix/bsfix (renamed from src/bsfix/bsfix)0
-rwxr-xr-xsrc/obsolete/bsfix/bsfix-eclipse.py (renamed from src/bsfix/bsfix-eclipse.py)0
-rwxr-xr-xsrc/obsolete/bsfix/bsfix.py (renamed from src/bsfix/bsfix.py)0
-rw-r--r--src/obsolete/bsfix/build-xml-source-target.xslt (renamed from src/bsfix/build-xml-source-target.xslt)0
-rwxr-xr-xsrc/obsolete/bsfix/rewrite2-speed-test.sh (renamed from src/bsfix/rewrite2-speed-test.sh)0
-rw-r--r--src/obsolete/bsfix/tests/build.xml (renamed from src/bsfix/tests/build.xml)0
-rwxr-xr-xsrc/py/build-xml-rewrite (renamed from src/bsfix/build-xml-rewrite)2
-rwxr-xr-xsrc/py/buildparser128
-rwxr-xr-xsrc/py/class-version-verify.py66
-rwxr-xr-x[-rw-r--r--]src/py/findclass (renamed from src/findclass/findclass)0
-rwxr-xr-xsrc/py/jarjarclean42
-rw-r--r--src/py/javatoolkit/__init__.py (renamed from src/javatoolkit/__init__.py)2
-rw-r--r--src/py/javatoolkit/classpath.py68
-rw-r--r--src/py/javatoolkit/cvv.py52
-rw-r--r--src/py/javatoolkit/maven/MavenPom.py212
-rw-r--r--src/py/javatoolkit/maven/__init__.py7
-rw-r--r--src/py/javatoolkit/output.py (renamed from src/javatoolkit/output.py)17
-rw-r--r--src/py/javatoolkit/parser/__init__.py (renamed from src/javatoolkit/parser/__init__.py)2
-rw-r--r--src/py/javatoolkit/parser/buildproperties.py83
-rw-r--r--src/py/javatoolkit/parser/helpers.py57
-rw-r--r--src/py/javatoolkit/parser/manifest.py61
-rw-r--r--src/py/javatoolkit/parser/parser.py13
-rw-r--r--src/py/javatoolkit/parser/tree.py135
-rw-r--r--src/py/javatoolkit/xml/DomRewriter.py120
-rw-r--r--src/py/javatoolkit/xml/SaxRewriter.py133
-rw-r--r--src/py/javatoolkit/xml/__init__.py7
-rwxr-xr-xsrc/py/maven-helper.py153
-rwxr-xr-xsrc/py/xml-rewrite-2.py (renamed from src/bsfix/xml-rewrite-2.py)0
-rwxr-xr-xsrc/py/xml-rewrite-3.py252
-rwxr-xr-xsrc/py/xml-rewrite.py (renamed from src/bsfix/xml-rewrite.py)0
-rw-r--r--src/sun-fetch/AUTHORS0
-rw-r--r--src/sun-fetch/ChangeLog6
-rw-r--r--src/sun-fetch/Makefile21
-rw-r--r--src/sun-fetch/README0
-rw-r--r--src/sun-fetch/TODO2
-rwxr-xr-xsrc/sun-fetch/sun-fetch21
-rw-r--r--src/sun-fetch/sun-fetch.124
-rwxr-xr-xsrc/sun-fetch/sun-fetch.py290
67 files changed, 1640 insertions, 2100 deletions
diff --git a/AUTHORS b/AUTHORS
index 6515d40..e742f0f 100644
--- a/AUTHORS
+++ b/AUTHORS
@@ -1,5 +1,13 @@
-The scripts inside src/ are written by their respective authors.
+The scripts inside src/ are written by the following authors. Authors names are contained in the header of each file. This file is meant to only acknowledge contributions to the javatoolkit package and does not attempt to list authors by any criteria.
Javatoolkit as a whole is maintained by the Java herd. If you have questions,
drop by #gentoo-java on freenode, or mail to <java@gentoo.org>.
+Karl Trygve Kalleberg <karltk@gentoo.org>
+Fabio Lessa <flessa@gmail.com>
+James Le Cuirot <chewi@aura-online.co.uk>
+Saleem Abdulrasool <compnerd@compnerd.org>
+Petteri Räty <betelgeuse@gentoo.org>
+kiorky <kiorky@cryptelium.net>
+
+If you feel that your name should be contained in this list, please contact the gentoo java project via irc, our mailing list <gentoo-java@lists.gentoo.org> or via http://bugs.gentoo.org
diff --git a/Makefile b/Makefile
deleted file mode 100644
index 29213a6..0000000
--- a/Makefile
+++ /dev/null
@@ -1,52 +0,0 @@
-# Copyright 2003-2004 Karl Trygve Kalleberg <karltk@gentoo.org>
-# Copyright 2003-2004 Gentoo Technologies, Inc.
-# Distributed under the terms of the GNU General Public License v2
-#
-# $Header: /var/cvsroot/gentoo-src/javatoolkit/Makefile,v 1.3 2004/12/25 00:14:05 axxo Exp $
-
-include makedefs.mak
-
-
-all:
- echo $(PYVERSION)
- echo $(VERSION)
- echo $(docdir)
- echo $(bindir)
- echo $(sbindir)
- echo $(mandir)
- for x in bsfix maven; do \
- ( cd src/$$x; $(MAKE) all ) \
- done
-
-dist: dist-javatoolkit
-
-dist-javatoolkit:
- mkdir -p release/javatoolkit-$(VERSION)$(RELEASE_TAG)
- rm -rf release/javatoolkit-$(VERSION)$(RELEASE_TAG)/
- for x in sun-fetch findclass bsfix buildparser javatoolkit maven jarjarclean ; do \
- ( cd src/$$x ; $(MAKE) distdir=release/javatoolkit-$(VERSION)$(RELEASE_TAG) dist ) \
- done
- cp Makefile AUTHORS README TODO COPYING NEWS ChangeLog.2004 release/javatoolkit-$(VERSION)$(RELEASE_TAG)/
- cat makedefs.mak | \
- sed "s/^VERSION=.*/VERSION=$(VERSION)/" | \
- sed "s/^RELEASE_TAG=.*/RELEASE_TAG=$(RELEASE_TAG)/" \
- > release/javatoolkit-$(VERSION)$(RELEASE_TAG)/makedefs.mak
- ( cd release ; tar jcf javatoolkit-$(VERSION)$(RELEASE_TAG).tar.bz2 javatoolkit-$(VERSION)$(RELEASE_TAG)/ )
-
-install: install-javatoolkit
-
-install-javatoolkit:
-
- install -d $(docdir)
- install -d $(bindir)
- install -d $(sbindir)
- install -d $(mandir)
-
- install -m 0644 AUTHORS ChangeLog.2004 COPYING NEWS README TODO $(docdir)/
-
- for x in sun-fetch findclass bsfix buildparser javatoolkit maven jarjarclean ; do \
- ( cd src/$$x ; $(MAKE) DESTDIR=$(DESTDIR) install ) \
- done
-
-upload:
- scp release/javatoolkit-$(VERSION)$(RELEASE_TAG).tar.bz2 $(USER)@dev.gentoo.org:/space/distfiles-local/
diff --git a/makedefs.mak b/makedefs.mak
deleted file mode 100644
index b9c0955..0000000
--- a/makedefs.mak
+++ /dev/null
@@ -1,21 +0,0 @@
-# Copyright 2004 Karl Trygve Kalleberg <karltk@gentoo.org>
-# Copyright 2004 Gentoo Foundation
-# Distributed under the terms of the GNU General Public License v2
-#
-# $Header: /var/cvsroot/gentoo-src/javatoolkit/makedefs.mak,v 1.2 2004/08/10 20:38:58 karltk Exp $
-
-# Override this on command line when making a release, ie 'dist'
-
-VERSION=0.2.0-r5
-RELEASE_TAG=
-PYVERSION="`python-config | sed 's/-l//' | sed 's/ -lm.*//'`"
-DESTDIR=
-
-docdir=$(DESTDIR)/usr/share/doc/javatoolkit-$(VERSION)$(RELEASE_TAG)
-libdir=$(DESTDIR)/usr/lib/javatoolkit
-bindir=$(DESTDIR)/usr/bin
-sbindir=$(DESTDIR)/usr/sbin
-mandir=$(DESTDIR)/usr/share/man/man1
-xmlrewritedir=$(DESTDIR)/usr/share/javatoolkit
-mavenhelperdir=$(DESTDIR)/usr/share/javatoolkit
-
diff --git a/setup.py b/setup.py
new file mode 100644
index 0000000..3524081
--- /dev/null
+++ b/setup.py
@@ -0,0 +1,32 @@
+#!/usr/bin/env python
+
+# Copyright 1999-2008 Gentoo Foundation
+# Distributed under the terms of the GNU General Public License v2
+# $Header: $
+
+from distutils.core import setup
+
+setup (
+ name = 'javatoolkit',
+ version = '0.2.1',
+ description = 'Collection of Gentoo-specific tools for Java.',
+ maintainer = 'Gentoo Java Team',
+ maintainer_email = 'java@gentoo.org',
+ url = 'html://www.gentoo.org',
+ packages = ["javatoolkit", "javatoolkit.maven", "javatoolkit.xml", "javatoolkit.parser"],
+ package_dir = { 'javatoolkit' : 'src/py/javatoolkit' },
+ scripts = [
+ "src/py/maven-helper.py",
+ "src/py/xml-rewrite-3.py",
+ "src/py/findclass",
+ "src/py/xml-rewrite.py",
+ "src/py/xml-rewrite-2.py",
+ "src/py/buildparser",
+ "src/py/class-version-verify.py",
+ "src/py/build-xml-rewrite",
+ "src/py/jarjarclean"
+ ],
+ data_files = [ ( '/usr/share/man/man1', ['src/man/findclass.1'] ) ]
+)
+
+#set expandtab tabstop=4 shiftwidth=4 softtabstop=4 nowrap
diff --git a/src/bsfix/class-version-verify.py b/src/bsfix/class-version-verify.py
deleted file mode 100755
index b571c05..0000000
--- a/src/bsfix/class-version-verify.py
+++ /dev/null
@@ -1,108 +0,0 @@
-#!/bin/env python
-#
-# Copyright(c) 2005, Thomas Matthijs <axxo@gentoo.org>
-# Copyright(c) 2005, Gentoo Foundation
-#
-# Licensed under the GNU General Public License, v2
-#
-# $Header: /var/cvsroot/gentoo-src/javatoolkit/src/bsfix/class-version-verify.py,v 1.2 2005/07/19 10:35:18 axxo Exp $
-
-import os,sys
-from os.path import join, getsize
-from struct import unpack
-from optparse import OptionParser, make_option
-from zipfile import ZipFile
-
-class cvv:
- def __init__(self, target):
- self.target = target
- self.good = []
- self.bad = []
-
- def add(self, version, jar, file):
- if version <= self.target:
- self.good.append(("1."+str(version), jar, file))
- else:
- self.bad.append(("1."+str(version), jar, file))
-
- def do_class(self,filename):
- classFile = file(filename,"rb")
- classFile.seek(4)
-
- temp = classFile.read(4)
- #(version,) = unpack('>i',temp)
- (version,) = unpack('>xxh',temp)
- version-=44
-
- self.add(version, None, filename)
-
- def do_jar(self, filename):
- zipfile = ZipFile(filename, 'r')
-
- for file in zipfile.namelist():
- if file.endswith('class'):
- classFile = zipfile.read(file)
-
- (version,) = unpack('>h',classFile[6:8])
- version-=44
-
- self.add(version, filename, file)
-
- def do_file(self, filename):
- if not os.path.islink(filename):
- if filename.endswith(".class"):
- self.do_class(filename)
- if filename.endswith(".jar"):
- self.do_jar(filename)
-
-if __name__ == '__main__':
-
- options_list = [
- make_option ("-r", "--recurse", action="store_true", dest="deep", default=False, help="go into dirs"),
- make_option ("-t", "--target", type="string", dest="version", help="target version that is valid"),
-
- make_option ("-v", "--verbose", action="store_true", dest="verbose", default=False, help="Print version of every calss"),
- make_option ("-s", "--silent", action="store_true", dest="silent", default=False, help="No output"),
- make_option ("-f", "--file-only", action="store_true", dest="file_only", default=False, help="Only output the files"),
- ]
-
- parser = OptionParser("%prog -t version [-r] [-v] [-s] <class/jar files or dir>", options_list)
- (options, args) = parser.parse_args()
-
- if not options.version:
- print "-t is mandatory"
- sys.exit(2)
-
- options.version = int(options.version.split(".")[-1])
-
- cvv = cvv(options.version)
-
- for arg in args:
- if os.path.isfile(arg):
- cvv.do_file(arg)
-
- if options.deep and os.path.isdir(arg):
- for root, dirs, files in os.walk(arg):
- for filename in files:
- cvv.do_file("%s/%s" % (root, filename))
-
- if options.file_only:
- lst = set([set[1] for set in cvv.bad])
- for i in lst:
- print i
- else:
-
- if options.verbose:
- for set in cvv.good:
- print "Good: %s %s %s" % set
-
- if not options.silent:
- for set in cvv.bad:
- print "Bad: %s %s %s" % set
-
- print "CVV: %s\nChecked: %i Good: %i Bad: %i" % (options.version, len(cvv.good)+len(cvv.bad) , len(cvv.good), len(cvv.bad))
-
- if len(cvv.bad) > 0:
- sys.exit(1)
- else:
- sys.exit(0)
diff --git a/src/bsfix/xml-rewrite-3.py b/src/bsfix/xml-rewrite-3.py
deleted file mode 100755
index 6d2db28..0000000
--- a/src/bsfix/xml-rewrite-3.py
+++ /dev/null
@@ -1,490 +0,0 @@
-#!/usr/bin/env python
-# -*- coding: UTF-8 -*-
-
-
-# Copyright 2004-2006 Gentoo Foundation
-# Distributed under the terms of the GNU General Public Licence v2
-
-# Authors:
-# Saleem Abdulrasool <compnerd@compnerd.org>
-# Petteri Räty <betelgeuse@gentoo.org>
-# kiorky <kiorky@cryptelium.net>
-# Maintainer: Gentoo Java Herd <java@gentoo.org>
-# Python based XML modifier
-
-# ChangeLog
-# kiorky <kiorky@cryptelium.net>
-# May 2007 - Now, all things can be done in one pass, saving us some times :)
-# - javadoc target generation added
-# - Rewritten to be more logical
-# Petteri Räty <betelgeuse@gentoo.org
-# December 06, 2006 - Changed to use xml.parsers.expat and basically rewrote the whole file
-# December 29, 2006 - Added a SAX based implementation to handle entities etc ( test on dev-java/skinlf )
-# Saleem A. <compnerd@compnerd.org>
-# December 23, 2004 - Initial Write
-# December 24, 2004 - Added usage information
-
-import os
-import sys
-import StringIO
-from xml.sax.saxutils import quoteattr,escape
-from optparse import OptionParser, make_option
-
-__version__ = "$Revision: 1.7 $"[11:-2]
-
-
-
-class DomRewriter:
- """
- The old DOM rewriter is still around for index based stuff. It can
- be used for all the complex stuff but portage needed features should
- be in StreamRewriterBase subclasses as they are much faster.
- """
- from xml.dom import NotFoundErr
- def __init__(self, modifyElems = None, attributes = None , values=None, index=None):
- self.modifyElems = modifyElems
- self.attributes = attributes
- self.values = values
- self.index = index
-
-
- def delete_elements(self, document, **kwargs):
- if not self.modifyElems:
- return
-
- tomodify = []
- for tag in self.modifyElems:
- matches = document.getElementsByTagName(tag)
- if matches:
- if self.index == None:
- for match in matches:
- tomodify.append(match)
- else:
- tomodify.append(matches[self.index])
-
- for elem in tomodify:
- for i,attr in enumerate(self.attributes):
- if self.values:
- elem.setAttribute(attr, self.values[i])
- else:
- try:
- elem.removeAttribute(attr)
- except DomRewriter.NotFoundErr:
- continue
-
-
- def add_gentoo_classpath(self,document,**kwargs):
- newcp = kwargs.has_key('classpath') and kwargs['classpath'] or "void"
- newcp = newcp.split(":")
- gcp = document.createElement("path")
- for cp in newcp:
- pe = document.createElement("pathelement")
- pe.setAttribute("path",cp)
- gcp.appendChild(pe)
-
-
- # classpath nodes:
- # if no refud:
- # remove inner elems
- # add our gentoo classpath node
- # else
- # rename refid references
- matches = document.getElementsByTagName("classpath")
- handled_refs = set()
- for match in matches:
- if not match.hasAttribute("refid"):
- for node in match.childNodes[:]:
- match.removeChild(node)
- node.unlink()
-
- match.appendChild(gcp.cloneNode(True))
- else:
- refid = match.getAttribute("refid")
- for ref in document.getElementsByTagName("path"):
- id = ref.getAttribute("id")
- if id not in handled_refs and id == refid:
- for node in ref.childNodes[:]:
- ref.removeChild(node)
- node.unlink()
-
- for pathnode in (gcp.cloneNode(deep=True)).childNodes:
- ref.appendChild(pathnode.cloneNode(deep=True))
-
- handled_refs.add(id)
-
- # rewrite javac elements
- matches = document.getElementsByTagName("javac")
- for match in matches:
- classpath = match.getAttribute("classpath")
- if classpath:
- match.removeAttribute("classpath")
-
- for node in match.childNodes[:]:
- if node.nodeName == "classpath":
- match.removeChild(node)
- node.unlink()
-
- classpath = document.createElement("classpath")
- classpath.appendChild(gcp.cloneNode(True))
- match.appendChild(classpath)
-
-
- def process(self,in_stream,callback=None,*args,**kwargs):
- from xml.dom import minidom
- self.document = minidom.parseString(in_stream);
-
- if callback:
- callback(self.document,*args,**kwargs)
-
-
- def write(self,stream):
- from xml.dom.ext import PrettyPrint
- PrettyPrint(self.document,stream)
-
-
-
-#class ExpatRewriter(StreamRewriterBase):
-# """
-# The only problem with this Expat based implementation is that it does not
-# handle entities doctypes etc properly so for example dev-java/skinlf fails.
-# """
-# def process(self, in_stream):
-# from xml.parsers.expat import ParserCreate
-# parser = ParserCreate()
-#
-# parser.StartElementHandler = self.start_element
-# parser.EndElementHandler = self.end_element
-# parser.CharacterDataHandler = self.char_data
-# parser.ParseFile(in_stream)
-# self.p(u'\n')
-#
-#
-# def start_element(self, name, attrs):
-# StreamRewriterBase(self, name, attrs.iteritems())
-#
-#
-# def end_element(self,name):
-# self.p(u'</%s>' % name)
-
-
-
-
-from xml.sax.saxutils import XMLGenerator
-class SaxRewriter(XMLGenerator):
- """
- Using Sax gives us the support for writing back doctypes and all easily
- and is only marginally slower than expat as it is just a tight layer over it
- """
- def __init__(self, **kwds):
- self.elems = kwds.has_key('elems') and kwds['elems'] or []
- self.attributes = kwds.has_key('attributes') and kwds['attributes'] or []
- self.values = kwds.has_key('values') and kwds['values'] or []
- self.sourceElems = kwds.has_key('sourceElems') and kwds['sourceElems'] or []
- self.sourceAttributes = kwds.has_key('sourceAttributes') and kwds['sourceAttributes'] or []
- self.sourceValues = kwds.has_key('sourceValues') and kwds['sourceValues'] or []
- self.targetElems = kwds.has_key('targetElems') and kwds['targetElems'] or []
- self.targetAttributes = kwds.has_key('targetAttributes') and kwds['targetAttributes'] or []
- self.targetValues = kwds.has_key('targetValues') and kwds['targetValues'] or []
-
- self.deleteElems = kwds.has_key('deleteElems') and kwds['deleteElems'] or []
- self.deleteAttributes = kwds.has_key('deleteAttributes') and kwds['deleteAttributes'] or []
-
- self.src_dirs = kwds.has_key('src_dirs') and kwds['src_dirs'] or []
- self.output_dir = kwds.has_key('output_dir') and kwds['output_dir'] or None
-
- self.buffer = StringIO.StringIO()
-
- XMLGenerator.__init__(self, self.buffer, 'UTF-8')
-
-
- def add_gentoo_javadoc(self, name, attrs):
- self.p(u'<%s ' % name)
- for a,v in attrs.items():
- self.write_attr(a,v)
-
- self.p(u'>')
-
- if name == "project":
- javadoc_str = """
- <target name=\"gentoojavadoc\" >
- <mkdir dir=\"""" + self.output_dir + """\" />
- <javadoc
- destdir=\"""" + self.output_dir + """\"
- author="true"
- version="true"
- use="true"
- windowtitle="javadoc">
- """
-
- for src_dir in self.src_dirs:
- javadoc_str += """
- <fileset dir=\"""" + src_dir + """\" defaultexcludes="yes">
- <include name="**/*.java"/>
- </fileset>
- """
-
- javadoc_str += """
- </javadoc>
- </target>
- """
-
- self.p(u'%s' % javadoc_str)
-
-
- # write as they are or delete if wanted attributes first
- # next, add / update
- def modify_elements(self, name, attrs):
- self.p(u'<%s ' % name)
-
- match = ( name in self.elems )
- matchSource = ( name in self.sourceElems )
- matchTarget = ( name in self.targetElems )
- matchDelete = ( name in self.deleteElems )
-
- for a,v in attrs.items():
- if not (
- (match and a in self.attributes)
- or (matchSource and a in self.sourceAttributes)
- or (matchTarget and a in self.targetAttributes)
- or (matchDelete and a in self.deleteAttributes)
- ):
- self.write_attr(a,v)
-
- if matchSource:
- for i, attr in enumerate(self.sourceAttributes):
- self.write_attr(attr, self.sourceValues[i])
-
- if matchTarget:
- for i, attr in enumerate(self.targetAttributes):
- self.write_attr(attr, self.targetValues[i])
-
- if match:
- for i, attr in enumerate(self.attributes):
- self.write_attr(attr, self.values[i])
-
- self.p(u'>')
-
-
- def char_data(self, data):
- self.p(escape(data))
-
-
- def write(self, out_stream):
- value = self.buffer.getvalue()
- out_stream.write(value)
- self.buffer.truncate(0)
-
-
- def p(self,str):
- self.buffer.write(str.encode('utf8'))
-
-
- def write_attr(self,a,v):
- self.p(u'%s=%s ' % (a,quoteattr(v, {u'©':'&#169;'})))
-
-
- def process(self, in_stream, callback):
- self.startElement = callback
- from xml.sax import parseString
- parseString(in_stream, self)
- self.p(u'\n')
-
-
-
-if __name__ == '__main__':
- usage = "XML Rewrite Python Module Version " + __version__ + "\n"
- usage += "Copyright 2004,2006,2007 Gentoo Foundation\n"
- usage += "Distributed under the terms of the GNU General Public Lincense v2\n"
- usage += "Please contact the Gentoo Java Team <java@gentoo.org> with problems.\n"
- usage += "\n"
- usage += "Usage:\n"
- usage += " " + sys.argv[0] + " [-f file] --delete [-g] -n tag [-n tag] -m attribute [-m attribute] [-i index]\n"
- usage += " " + sys.argv[0] + " [-f file] --change [-g] -e tag [-e tag] -a attribute -v value [-a attribute -v value] \\\n"
- usage += " [--source-element tag] [--source-attribute attribute --source-value value] \\\n"
- usage += " [--target-element tag] [--target-attribute attribute --target-value value] [-i index]\n"
- usage += "Or:\n"
- usage += " " + sys.argv[0] + " [-f file] --javadoc --source-directory dir [--source-directory dir2] --output-directory dir3 \n"
- usage += "Or:\n"
- usage += " " + sys.argv[0] + " [-f file] -g\n"
- usage += "\n"
- usage += "Or:\n"
- usage += " " + sys.argv[0] + " [-f file] --maven-cleaning\n"
- usage += "\n"
- usage += "Or for more detailed help:\n"
- usage += " " + sys.argv[0] + " -h\n"
- usage += "\n"
- usage += "Multiple actions can be done simultaneously\n"
- usage += "\n"
- usage += "If the -f parameter is not utilized, the script will read and\n"
- usage += "write to stdin and stdout respectively. The use of quotes on\n"
- usage += "parameters will break the script.\n"
-
-
-
-# from IPython.Debugger import Tracer; debug_here = Tracer(colors="Linux");debug_here() ### Breakpoint ###
-
- def error(message):
- print "ERROR: " + message
- sys.exit(1)
-
-
- # instream is a string
- def doRewrite(rewriter, in_stream, callback=None, **kwargs):
- if callback:
- rewriter.process(in_stream, callback, **kwargs)
- else:
- rewriter.process(in_stream, **kwargs)
-
- out = StringIO.StringIO()
- rewriter.write(out)
- return out.getvalue()
-
-
- def processActions(options, f):
- out_stream = f.read()
- newcp="${gentoo.classpath}"
- if options.gentoo_classpath:
- rewriter = DomRewriter(options.elements, options.attributes, options.values, options.index)
- out_stream = doRewrite(rewriter, out_stream, rewriter.add_gentoo_classpath,classpath = newcp)
-
- if options.doJavadoc:
- rewriter = SaxRewriter(src_dirs = options.src_dirs, output_dir = options.javadoc_dir[0])
- out_stream = doRewrite(rewriter, out_stream, rewriter.add_gentoo_javadoc)
-
- if options.doAdd or options.doDelete:
- # java-ant-2.eclass does not use these options so we can optimize the ExpatWriter
- # and let the DomRewriter do these. Also keeps the index option compatible for sure.
- if options.index:
- rewriter = DomRewriter(options.delete_elements, options.delete_attributes, options.values, options.index)
- out_stream = doRewrite(rewriter, out_stream, rewriter.delete_elements)
- else:
- rewriter = SaxRewriter(
- elems = options.elements,
- attributes = options.attributes,
- values = options.values,
- sourceElems = options.source_elements,
- sourceAttributes = options.source_attributes,
- sourceValues = options.source_values,
- targetElems = options.target_elements,
- targetAttributes = options.target_attributes,
- targetValues = options.target_values,
- deleteElems = options.delete_elements,
- deleteAttributes = options.delete_attributes
- )
- out_stream = doRewrite(rewriter, out_stream, rewriter.modify_elements)
-
- if options.doMaven:
- if options.mavenMultiProjectsDirs:
- for elem in options.mavenMultiProjectsDirs:
- newcp+=":"+elem
-
- rewriter = DomRewriter()
- out_stream = doRewrite(rewriter, out_stream, rewriter.add_gentoo_classpath, classpath = newcp)
-
- deleteElems = []
- deleteAttributes = []
- deleteElems.append("target")
- deleteAttributes.append("depends")
- rewriter = SaxRewriter( deleteElems = deleteElems, deleteAttributes = deleteAttributes)
- out_stream = doRewrite(rewriter, out_stream, rewriter.modify_elements)
-
- return out_stream
-
-
- options_list = [
- make_option ("-a", "--attribute", action="append", dest="attributes", help="Attribute of the matching elements to change. These can be chained for multiple value-attribute pairs"),
- make_option ("-b", "--target-element", action="append", dest="target_elements", help="Tag of the element of which the attributes to be changed just in target scope. These can be chained for multiple elements."),
- make_option ("-c", "--change", action="store_true", dest="doAdd", default=False, help="Change the value of an attribute. If it does not exist, it will be created."),
- make_option ("-d", "--delete", action="store_true", dest="doDelete", default=False, help="Delete an attribute from matching elements."),
- make_option ("-e", "--element", action="append", dest="elements", help="Tag of the element of which the attributes to be changed. These can be chained for multiple elements."),
- make_option ("-f", "--file", action="append", dest="files", help="Transform files instead of operating on stdout and stdin"),
- make_option ("-g", "--gentoo-classpath", action="store_true", dest="gentoo_classpath", help="Rewrite build.xml to use gentoo.classpath where applicable."),
- make_option ("-i", "--index", type="int", dest="index", help="Index of the match. If none is specified, the changes will be applied to all matches within the document. Starts from zero."),
- make_option ("-j", "--javadoc", action="store_true", dest="doJavadoc", default=False, help="add a basic javadoc target. Sources must be placed in ${WORKDIR}/javadoc_src."),
- make_option ("-k", "--target-attribute", action="append", dest="target_attributes", help="Attribute of the matching elements to change. These can be chained for multiple value-attribute pairs (for targetonly)"),
- make_option ("-l", "--target-value", action="append", dest="target_values", help="Value to set the attribute to (targeronly)."),
- make_option ("-m", "--delete-attribute", action="append", dest="delete_attributes", help="Attribute of the matching elements to delete. These can be chained for multiple value-attribute pairs"),
- make_option ("-n", "--delete-element", action="append", dest="delete_elements", help="Tag of the element of which the attributes to be deleted. These can be chained for multiple elements."),
- make_option ("-o", "--output-directory", action="append", dest="javadoc_dir", help="javadoc output directory. Must be an existing directory"),
- make_option ("-p", "--source-directory", action="append", dest="src_dirs", help="source directory for javadoc generation. Must be an existing directory"),
- make_option ("-q", "--maven-cleaning", action="store_true", dest="doMaven", default=False, help="Turns on maven generated build.xml cleanup rewriting."),
- make_option ("-r", "--source-element", action="append", dest="source_elements", help="Tag of the element of which the attributes to be changed just in source scope. These can be chained for multiple elements."),
- make_option ("-s", "--multi-project-dirs", action="append", dest="mavenMultiProjectsDirs", help="Dirs in classpath notation"),
-
- make_option ("-t", "--source-attribute", action="append", dest="source_attributes", help="Attribute of the matching elements to change. These can be chained for multiple value-attribute pairs (for source only)"),
- make_option ("-v", "--value", action="append", dest="values", help="Value to set the attribute to."),
- make_option ("-y", "--source-value", action="append", dest="source_values", help="Value to set the attribute to. (sourceonly)")
- ]
- parser = OptionParser(usage, options_list)
- (options, args) = parser.parse_args()
-
- # Invalid Arguments Must be smited!
- if not options.doAdd and not options.doDelete and not options.gentoo_classpath and not options.doJavadoc and not options.doMaven:
- print usage
- print
- error("No action was specified.")
-
- if options.doAdd:
- if not options.elements and not options.target_elements and not options.source_elements:
- error("At least one element (global, source only or target only) and attribute must be specified.")
-
- for elem in ( options.source_attributes or [] ):
- if elem in ( options.attributes or [] ):
- error("You can't set an attribute in global and source scope at the same time")
-
- for elem in ( options.target_attributes or [] ):
- if elem in ( options.attributes or [] ):
- error("You can't set an attribute in global and target scope at the same time")
-
- if options.doAdd and (len(options.values or []) != len(options.attributes or [])
- or len(options.source_values or [] ) != len(options.source_attributes or [])
- or len(options.target_values or [] ) != len(options.target_attributes or [])):
- error("You must give attribute(s)/value(s) for every element you are changing.")
-
- if options.doJavadoc:
- if len(options.src_dirs or []) < 1:
- error("You must specify as least one src directory.")
-
- for dir in options.src_dirs:
- if not os.path.isdir(dir):
- error("You must specify existing directory for src output")
-
- if len(options.javadoc_dir or []) != 1:
- error("You must specify one and only one javadoc output directory.")
-
- if not os.path.isdir(options.javadoc_dir[0]):
- error("You must specify an existing directory for javadoc output")
-
- if options.doDelete:
- if not options.delete_elements:
- error("At least one element to delete must be specified.")
-
- if options.doDelete and ( len(options.attributes or []) < 0):
- error("You must give attribute(s) to delete for every element you are changing.")
- # End Invalid Arguments Check
-
-
- # main loop
- if options.files:
- for file in options.files:
- print "Rewriting %s" % file
- # First parse the file into memory
- # Tricks with cwd are needed for relative includes of other xml files to build.xml files
- cwd = os.getcwd()
- dirname = os.path.dirname(file)
- if dirname != '': # for file = build.xml comes out as ''
- os.chdir(os.path.dirname(file))
-
- f = open(os.path.basename(file), "r")
- outxml = processActions(options, f)
- os.chdir(cwd)
- f.close()
- # Then write it back to the file
- f = open(file, "w")
- f.write(outxml)
- f.close()
-
- else:
- outxml = processActions(options, sys.stdin)
- sys.stdout.write(outxml)
- # vim: set ai ts=8 sts=0 sw=8 tw=0 noexpandtab:
diff --git a/src/buildparser/Makefile b/src/buildparser/Makefile
deleted file mode 100644
index 8c1d749..0000000
--- a/src/buildparser/Makefile
+++ /dev/null
@@ -1,17 +0,0 @@
-# Copyright 2004 Karl Trygve Kalleberg <karltk@gentoo.org>
-# Copyright 2004 Gentoo Foundation
-# Distributed under the terms of the GNU General Public License v2
-#
-# $Header: /var/cvsroot/gentoo-src/javatoolkit/src/bsfix/Makefile,v 1.4 2005/01/02 02:30:12 axxo Exp $
-
-include ../../makedefs.mak
-
-all:
-
-dist:
- mkdir -p ../../$(distdir)/src/buildparser
- cp Makefile buildparser ../../$(distdir)/src/buildparser
-
-install: all
- install -m 0755 buildparser $(bindir)/
-
diff --git a/src/buildparser/buildparser b/src/buildparser/buildparser
deleted file mode 100755
index f85781f..0000000
--- a/src/buildparser/buildparser
+++ /dev/null
@@ -1,127 +0,0 @@
-#! /usr/bin/python
-#
-# Copyright(c) 2006, 2008 James Le Cuirot <chewi@aura-online.co.uk>
-# Copyright(c) 2005, Karl Trygve Kalleberg <karltk@gentoo.org>
-#
-# Licensed under the GNU General Public License, v2
-#
-# $Header:$
-
-import os
-import sys
-from optparse import OptionParser
-
-sys.path.insert(0, "/usr/share/javatoolkit/pym")
-
-from parser.parser import Parser
-from parser.buildproperties import BuildPropertiesParser
-from parser.manifest import ManifestParser
-from parser.tree import Node, ParseError
-
-__author__ = ["James Le Cuirot <chewi@aura-online.co.uk>", "Karl Trygve Kalleberg <karltk@gentoo.org>"]
-__version__ = "0.2.0"
-__productname__ = "buildparser"
-__description__ = "A parser for build.properties and JAR manifest files."
-
-
-def parse_args():
-
- usage = 'buildparser [options] [node name] [replacement] <filename>'
- about = __productname__ + " : " + __description__ + "\n" + \
- "Version : " + __version__ + "\n" \
- "Authors : " + __author__[0]
-
- for x in __author__[1:]:
- about += "\n " + x
-
- parser = OptionParser(usage, version=about)
-
- parser.add_option('-t', '--type', action='store', type='choice',
- dest='type', choices=['manifest', 'buildprops'],
- help='Type of file to parse: manifest or buildprops')
-
- parser.add_option('-i', '--in-place', action='store_true', dest='in_place',
- help='Edit file in place when replacing')
-
- parser.add_option('-w', '--wrap', action='store_true', dest='wrap',
- help='Wrap when returning singular values')
-
- opt, args = parser.parse_args()
-
- if len(args) > 3:
- parser.error("Too many arguments specified!")
-
- elif len(args) == 0:
- parser.error("A filename must be specified!")
-
- elif not os.path.isfile(args[-1]):
- parser.error(args[-1] + " does not exist!")
-
- return opt, args
-
-def main():
-
- opt, args = parse_args()
-
- f = open(args[-1])
-
- t = Node()
- p = Parser()
-
- try:
- if opt.type == "manifest":
- p = ManifestParser()
-
- elif opt.type == "buildprops":
- p = BuildPropertiesParser()
-
- elif os.path.basename(f.name) == "MANIFEST.MF":
- p = ManifestParser()
-
- elif os.path.basename(f.name) == "build.properties":
- p = BuildPropertiesParser()
-
- else:
- sys.exit(__productname__ + ": error: Unknown file type. Specify using the -t option.")
-
- t = p.parse(f)
- f.close()
-
- except ParseError:
- sys.exit(__productname__ + ": error: Unable to parse file.")
-
- if len(args) > 2:
- n = t.find_node(args[0])
-
- if n != None:
- n.value = args[1]
- else:
- t.add_kid(Node(args[0], args[1]))
-
- if opt.in_place:
- f = open(args[-1], "w+")
- p.output(f, t)
- f.close()
-
- else:
- p.output(sys.stdout, t)
-
- elif len(args) > 1:
- n = t.find_node(args[0])
-
- if n != None:
- if opt.wrap:
- print p.wrapped_value(n)
- else:
- print n.value
-
- else:
- for x in t.node_names():
- print x
-
-if __name__ == '__main__':
- try:
- main()
- except KeyboardInterrupt:
- print "Interrupted by user, aborting."
-
diff --git a/src/findclass/AUTHORS b/src/findclass/AUTHORS
deleted file mode 100644
index 0decf7b..0000000
--- a/src/findclass/AUTHORS
+++ /dev/null
@@ -1,2 +0,0 @@
-Karl Trygve Kalleberg <karltk@gentoo.org>
-Fabio Lessa <flessa@gmail.com>
diff --git a/src/findclass/ChangeLog b/src/findclass/ChangeLog
deleted file mode 100644
index d0ebe22..0000000
--- a/src/findclass/ChangeLog
+++ /dev/null
@@ -1,3 +0,0 @@
-2005-05-11: Karl Trygve Kalleberg <karltk@gentoo.org>
- * Rewrite to Python from bash by Fabio Lessa and myself.
-
diff --git a/src/findclass/Makefile b/src/findclass/Makefile
deleted file mode 100644
index 0ea4800..0000000
--- a/src/findclass/Makefile
+++ /dev/null
@@ -1,19 +0,0 @@
-# Copyright 2004 Karl Trygve Kalleberg <karltk@gentoo.org>
-# Copyright 2004 Gentoo Foundation
-# Distributed under the terms of the GNU General Public License v2
-#
-# $Header: /var/cvsroot/gentoo-src/javatoolkit/src/findclass/Makefile,v 1.1 2004/08/10 20:06:19 karltk Exp $
-
-include ../../makedefs.mak
-
-all:
-
-dist:
- mkdir -p ../../$(distdir)/src/findclass
- cp {Makefile,AUTHORS,README,TODO,ChangeLog,findclass,findclass.1} ../../$(distdir)/src/findclass
-
-install:
- install -m 0755 findclass $(bindir)/
- install -d $(docdir)/findclass
- install -m 0644 {README,AUTHORS} $(docdir)/findclass/
- install -m 0644 findclass.1 $(mandir)/
diff --git a/src/findclass/README b/src/findclass/README
deleted file mode 100644
index e69de29..0000000
--- a/src/findclass/README
+++ /dev/null
diff --git a/src/findclass/TODO b/src/findclass/TODO
deleted file mode 100644
index e69de29..0000000
--- a/src/findclass/TODO
+++ /dev/null
diff --git a/src/jarjarclean/Makefile b/src/jarjarclean/Makefile
deleted file mode 100644
index 3c4c382..0000000
--- a/src/jarjarclean/Makefile
+++ /dev/null
@@ -1,17 +0,0 @@
-# Copyright 2008 James Le Cuirot <chewi@aura-online.co.uk>
-# Copyright 2008 Gentoo Foundation
-# Distributed under the terms of the GNU General Public License v2
-#
-# $Header: $
-
-include ../../makedefs.mak
-
-all:
-
-dist:
- mkdir -p ../../$(distdir)/src/jarjarclean
- cp Makefile jarjarclean ../../$(distdir)/src/jarjarclean
-
-install: all
- install -m 0755 jarjarclean $(bindir)/
-
diff --git a/src/jarjarclean/jarjarclean b/src/jarjarclean/jarjarclean
deleted file mode 100755
index b3252f7..0000000
--- a/src/jarjarclean/jarjarclean
+++ /dev/null
@@ -1,40 +0,0 @@
-#!/usr/bin/python
-#
-# Copyright 2008 James Le Cuirot <chewi@aura-online.co.uk>
-# Copyright 2008 Gentoo Foundation
-# Distributed under the terms of the GNU General Public License v2
-#
-# $Header: $
-
-import sys
-import xml.etree.cElementTree as et
-
-args = sys.argv[1:]
-if len(args) == 0:
- args = [ 'build.xml' ]
-
-for file in args:
- tree = et.ElementTree(file=file)
- tags = []
-
- for elem in tree.getiterator():
- for child in list(elem):
- if child.tag == 'taskdef' and child.get('classname') == 'com.tonicsystems.jarjar.JarJarTask':
- tags.append(child.get('name'))
- elem.remove(child)
-
- for tag in tags:
- for jarjar in tree.getiterator(tag):
- if jarjar.get('destfile') or jarjar.get('jarfile'):
- jarjar.tag = 'jar'
-
- if jarjar.get('verbose'):
- del jarjar.attrib['verbose']
-
- for child in list(jarjar):
- if child.tag == 'keep' or child.tag == 'rule' or child.tag == 'zipfileset':
- jarjar.remove(child)
-
- f = open(file, 'w')
- tree.write(f)
- f.close()
diff --git a/src/javatoolkit/.cvsignore b/src/javatoolkit/.cvsignore
deleted file mode 100644
index 0d20b64..0000000
--- a/src/javatoolkit/.cvsignore
+++ /dev/null
@@ -1 +0,0 @@
-*.pyc
diff --git a/src/javatoolkit/Makefile b/src/javatoolkit/Makefile
deleted file mode 100644
index 108e005..0000000
--- a/src/javatoolkit/Makefile
+++ /dev/null
@@ -1,20 +0,0 @@
-# Copyright 2004 Karl Trygve Kalleberg <karltk@gentoo.org>
-# Copyright 2004 Gentoo Foundation
-# Distributed under the terms of the GNU General Public License v2
-#
-# $Header: $
-
-include ../../makedefs.mak
-
-all:
- python -c "import compileall; compileall.compile_dir('.')"
-
-dist:
- mkdir -p ../../$(distdir)/src/javatoolkit/parser
- cp Makefile *.py ../../$(distdir)/src/javatoolkit/
- cp parser/*.py ../../$(distdir)/src/javatoolkit/parser/
-
-install: all
- install -d $(DESTDIR)/usr/share/javatoolkit/pym/parser
- install -m 0644 *.py *.pyc $(DESTDIR)/usr/share/javatoolkit/pym/
- install -m 0644 parser/*.py parser/*.pyc $(DESTDIR)/usr/share/javatoolkit/pym/parser/
diff --git a/src/javatoolkit/classpath.py b/src/javatoolkit/classpath.py
deleted file mode 100644
index c570774..0000000
--- a/src/javatoolkit/classpath.py
+++ /dev/null
@@ -1,72 +0,0 @@
-#! /usr/bin/python2
-#
-# Copyright(c) 2004, Karl Trygve Kalleberg <karltk@gentoo.org>
-# Copyright(c) 2004, Gentoo Foundation
-#
-# Licensed under the GNU General Public License, v2
-#
-# $Header: /var/cvsroot/gentoo-src/javatoolkit/src/javatoolkit/classpath.py,v 1.4 2004/11/08 20:06:06 karltk Exp $
-
-class ClasspathIter:
- """An iterator for the Classpath class, below."""
-
- def __init__(self, classpath):
- self._classpath = classpath
- self._index = 0
-
- def next(self):
- self._index += 1
- if self._index >= len(self._classpath.classpath):
- raise StopIteration
- return self._classpath.classpath[self._index]
-
-
-class Classpath:
- """A classpath object provides a collection interface to the elements of a : separated path list. """
-
- def __init__(self, classpath_string = None):
- if classpath_string != None:
- cs = classpath_string.strip().strip("\"")
- self.classpath = cs.split(":")
- else:
- self.classpath = []
-
-
- def __iter__(self):
- """Returns iterator. Elements of the original classpath string are considered split by ':'."""
-
- return ClasspathIter(self)
-
-
- def __len__(self):
- """Returns length (number of elements) in this classpath."""
-
- return len(self.classpath)
-
-
- def __getitem__(self, i):
- """Returns i'th element."""
-
- return self.classpath[i]
-
-
- def __setitem__(self, i, val):
- """Sets i'th element."""
-
- self.classpath[i] = val
-
-
- def __str__(self):
- """Constructs a suitable string representation of the classpath."""
-
- return ":".join(self.classpath)
-
-
- def append(self, element):
- """Appends an path to the classpath."""
-
- self.classpath.append(element)
-
-
-if __name__ == "__main__":
- print "This is not an exectuable module" \ No newline at end of file
diff --git a/src/javatoolkit/parser/.cvsignore b/src/javatoolkit/parser/.cvsignore
deleted file mode 100644
index 0d20b64..0000000
--- a/src/javatoolkit/parser/.cvsignore
+++ /dev/null
@@ -1 +0,0 @@
-*.pyc
diff --git a/src/javatoolkit/parser/buildproperties.py b/src/javatoolkit/parser/buildproperties.py
deleted file mode 100644
index 0bb4043..0000000
--- a/src/javatoolkit/parser/buildproperties.py
+++ /dev/null
@@ -1,86 +0,0 @@
-#! /usr/bin/python
-#
-# Copyright(c) 2006, 2008, James Le Cuirot <chewi@aura-online.co.uk>
-# Copyright(c) 2004, Karl Trygve Kalleberg <karltk@gentoo.org>
-# Copyright(c) 2004, Gentoo Foundation
-#
-# Licensed under the GNU General Public License, v2
-#
-# $Header: $
-
-from tree import *
-import parser
-
-class BuildPropertiesParser(parser.Parser):
-
- def parse(self, ins):
- """ Parse an input stream containing an ant build.properties file. Return a
- structured document represented by tree.Node
-
- @param ins - input stream
- @return tree.Node containing the structured representation
- """
-
- lineno = 0
- continued_line = False
- inside_html_comment = False
- attrib = ""
- value = ""
- root = Node()
-
- for x in ins.readlines():
- lineno += 1
- x = x.strip()
-
- if inside_html_comment and x.find("-->") != -1:
- inside_html_comment = False
- x = x.split("-->", 1)[0]
-
- if x.find("<!--") != -1:
- inside_html_comment = True
-
- if inside_html_comment:
- continue
-
- if continued_line:
- continued_line = False
- value += x.strip("\"")
-
- if len(value) and value[-1] == "\\":
- value = value[:-1]
- continued_line = True
- continue
-
- root.add_kid(Node(attrib,value))
- continue
-
- if len(x) == 0 or x[:1] == "#":
- continue
-
- x = x.split("#", 1)[0]
- xs = x.split("=", 2)
-
- if len(xs) > 1:
- attrib = xs[0].strip()
- value = xs[1].strip().strip("\"")
-
- if value != "" and value[-1] == "\\":
- value = value[:-1]
- continued_line = True
- continue
-
- root.add_kid(Node(attrib,value))
-
- else:
- raise ParseError("Malformed line " + str(lineno))
-
- return root
-
- def output(self, ous, tree):
- tree.output(ous, "", " = ", "")
-
- def wrapped_value(self, node):
- return node.output_value()
-
-if __name__ == "__main__":
- print "This is not an executable module"
diff --git a/src/javatoolkit/parser/helpers.py b/src/javatoolkit/parser/helpers.py
deleted file mode 100644
index 62815de..0000000
--- a/src/javatoolkit/parser/helpers.py
+++ /dev/null
@@ -1,61 +0,0 @@
-#! /usr/bin/python
-#
-# Copyright(c) 2006, James Le Cuirot <chewi@aura-online.co.uk>
-# Copyright(c) 2004, Karl Trygve Kalleberg <karltk@gentoo.org>
-# Copyright(c) 2004, Gentoo Foundation
-#
-# Licensed under the GNU General Public License, v2
-#
-# $Header: $
-
-
-def expand(root, expr, realroot = None):
- """Evaluates a path expression on a given tree.
-
- @param root - the root of the tree
- @param expr - the expression to resolve
-
- @return the expanded string
- """
-
- if realroot == None:
- realroot = root
-
- expanded = ""
- in_varref = False
- varname = ""
-
- for i in range(len(expr)):
- x = expr[i]
-
- if in_varref:
-
- if x == "}":
- in_varref = False
- expanded += expand(root, realroot.find_node(varname).value, realroot)
- varname = ""
- elif x != "{":
- varname += expr[i]
-
- elif x == "$" and i < len(expr) and expr[i + 1] == "{":
- in_varref = True
-
- else:
- expanded += x
-
- return expanded
-
-def strip_varmarker(s):
- """Strips away ${ and } in a variable expression. Idempotent if marker not found.
-
- Example: "${foo}" -> "foo"
- Example: "foo" -> "foo"
- """
-
- if s.startswith("${") and s.endswith("}"):
- return s[2:-1]
-
- return s
-
-if __name__ == "__main__":
- print "This is not an executable module"
diff --git a/src/javatoolkit/parser/manifest.py b/src/javatoolkit/parser/manifest.py
deleted file mode 100644
index 3fe45b7..0000000
--- a/src/javatoolkit/parser/manifest.py
+++ /dev/null
@@ -1,64 +0,0 @@
-#! /usr/bin/python
-#
-# Copyright(c) 2006, 2008, James Le Cuirot <chewi@aura-online.co.uk>
-#
-# Licensed under the GNU General Public License, v2
-#
-# $Header: $
-
-from tree import *
-import parser
-
-class ManifestParser(parser.Parser):
-
- def parse(self, ins):
- """ Parse an input stream containing a MANIFEST.MF file. Return a
- structured document represented by tree.Node
-
- @param ins - input stream
- @return tree.Node containing the structured representation
- """
-
- lineno = 0
- attrib = ""
- value = ""
- root = Node()
-
- for x in ins.readlines():
- lineno += 1
-
- if len(x.strip()) == 0:
- continue
-
- if x[:1] == " ":
- if attrib == "":
- raise ParseError("Malformed line " + str(lineno))
-
- value += x.strip()
- continue
-
- xs = x.split(": ", 2)
-
- if len(xs) > 1:
- if attrib != "":
- root.add_kid(Node(attrib,value))
-
- attrib = xs[0]
- value = xs[1].strip()
-
- else:
- raise ParseError("Malformed line " + str(lineno))
-
- if attrib != "":
- root.add_kid(Node(attrib,value))
-
- return root
-
- def output(self, ous, tree):
- tree.output(ous, "", ": ", "", ",", " ")
-
- def wrapped_value(self, node):
- return node.output_value(",")
-
-if __name__ == "__main__":
- print "This is not an executable module"
diff --git a/src/javatoolkit/parser/parser.py b/src/javatoolkit/parser/parser.py
deleted file mode 100644
index 75f3290..0000000
--- a/src/javatoolkit/parser/parser.py
+++ /dev/null
@@ -1,16 +0,0 @@
-#! /usr/bin/python
-#
-# Copyright(c) 2006, James Le Cuirot <chewi@aura-online.co.uk>
-#
-# Licensed under the GNU General Public License, v2
-#
-# $Header: $
-
-class Parser:
- def parse(self, ins):
- raise NotImplementedError
- def output(self, ous, tree):
- raise NotImplementedError
-
-if __name__ == "__main__":
- print "This is not an executable module"
diff --git a/src/javatoolkit/parser/tree.py b/src/javatoolkit/parser/tree.py
deleted file mode 100644
index 6d09e03..0000000
--- a/src/javatoolkit/parser/tree.py
+++ /dev/null
@@ -1,138 +0,0 @@
-#! /usr/bin/python
-#
-# Copyright(c) 2006, 2008, James Le Cuirot <chewi@aura-online.co.uk>
-# Copyright(c) 2004, Karl Trygve Kalleberg <karltk@gentoo.org>
-# Copyright(c) 2004, Gentoo Foundation
-#
-# Licensed under the GNU General Public License, v2
-#
-# $Header: $
-
-import sys
-
-class ParseError:
- def __init__(self, error):
- self.error = error
-
-class NodeIter:
- def __init__(self, node):
- self._node = node
- self._index = 0
- def next(self):
- self._index += 1
- if self._index >= len(self._node._kids):
- raise StopIteration
- return self._node._kids[self._index]
-
-class Node:
- def __init__(self, name = None, value = None):
- self.name = name
- self.value = value
- self._kids = []
-
- def __iter__(self):
- return NodeIter(self)
-
- def add_kid(self, kid):
- for x in self._kids:
- if x.name == kid.name:
- return
-
- self._kids.append(kid)
-
- def _dump_kids(self, ous, indent):
- for x in self._kids:
- x.dump(ous, indent + 1)
-
- """
- Dump self as text to stream.
- """
- def dump(self, ous, indent = 0):
- if self.name:
- ous.write((" " * indent) + self.name + " = " + self.value + "\n")
-
- self._dump_kids(ous, indent)
-
- """
- Output self as text to stream using the given format.
- """
- def output(self, ous, before, between, after, wrap = None, indent = ""):
- if self.name:
- ous.write(before + self.name + between + self.output_value(wrap, indent) + after + "\n")
-
- for x in self._kids:
- x.output(ous, before, between, after, wrap, indent)
-
- """
- Return node value as string using the given format.
- """
- def output_value(self, wrap = None, indent = ""):
- if wrap == None:
- return self.value
- else:
- return self.__wrap_outside_quotes(self.value, wrap, indent)
-
- """
- Returns a lists of all the node names.
- """
- def node_names(self):
- names = []
-
- if self.name:
- names.append(self.name)
-
- for x in self._kids:
- names.extend(x.node_names())
-
- return names
-
- """
- Find a given node name in a tree.
-
- @param tree - the tree to search in
- @param nodename - the name of the node to search for
-
- @return reference to the found node, if any
- """
- def find_node(self, nodename):
- if self.name == nodename:
- return self
-
- else:
- for x in self._kids:
- y = x.find_node(nodename)
-
- if y != None:
- return y
-
- return None
-
- """
- Wrap using the given character and indent string, without wrapping
- inside quotes. Python's regexp engine cannot handle this.
-
- @param text - text to wrap
- @param wrap - character to wrap at
- @param indent - indent string to use, can be empty
- @param pos - recursive parameter only, don't use
-
- @return wrapped text
- """
- def __wrap_outside_quotes(self, text, wrap, indent, pos = None):
- if pos == None:
- pos = len(text)
-
- next_wrap = text.rfind(wrap, 0, pos)
-
- if next_wrap <= 0:
- return text
-
- num_quotes = text.count('"', next_wrap, pos)
-
- if num_quotes % 2 != 0:
- return self.__wrap_outside_quotes(text, wrap, indent, text.rfind('"', 0, next_wrap + 1))
-
- return self.__wrap_outside_quotes(text[0:next_wrap] + wrap + "\n" + indent + text[next_wrap + 1:], wrap, indent, next_wrap)
-
-if __name__ == "__main__":
- print "This is not an executable module"
diff --git a/src/findclass/findclass.1 b/src/man/findclass.1
index 7d2f959..7d2f959 100644
--- a/src/findclass/findclass.1
+++ b/src/man/findclass.1
diff --git a/src/maven/Makefile b/src/maven/Makefile
deleted file mode 100644
index 56a1acf..0000000
--- a/src/maven/Makefile
+++ /dev/null
@@ -1,21 +0,0 @@
-# Copyright 2004-2007 Gentoo Foundation
-# Distributed under the terms of the GNU General Public License v2
-#
-# $Header: $
-
-include ../../makedefs.mak
-
-all:
-
-dist:
- mkdir -p ../../$(distdir)/src/maven
- cp Makefile maven-helper.py ../../$(distdir)/src/maven
-
-install: all
- install -m 0755 maven-helper.py $(mavenhelperdir)/
-
-testdir:=tests
-
-test:
- echo "nothing atm"
-
diff --git a/src/maven/maven-helper.py b/src/maven/maven-helper.py
deleted file mode 100755
index b7acb6e..0000000
--- a/src/maven/maven-helper.py
+++ /dev/null
@@ -1,346 +0,0 @@
-#!/usr/bin/env python
-# -*- coding: UTF-8 -*-
-# vim: set ai ts=8 sts=0 sw=8 tw=0 noexpandtab:
-
-# Copyright 2004-2007 Gentoo Foundation
-# Distributed under the terms of the GNU General Public Licence v2
-
-# Authors:
-# kiorky <kiorky@cryptelium.net>:
-# Maintainer: Gentoo Java Herd <java@gentoo.org>
-# Python based POM navigator
-
-# ChangeLog
-# kiorky <kiorky@cryptelium.net>:
-# 31/05/2007 Add rewrite feature
-#
-# kiorky <kiorky@cryptelium.net>:
-# 08/05/2007 initial version
-
-
-import sys
-import StringIO
-from optparse import OptionParser, make_option
-
-
-
-__version__ = "$Revision: 1.1 $"[11:-2]
-
-
-
-# either a very simplified representation of a maven pom
-# or a fully xml rewritten pom
-class MavenPom:
- def __init__(self,cli_options = None):
- self.group = ''
- self.artifact = ''
- self.version = ''
- self.name = ''
- self.is_child = "false"
- self.dependencies = []
- self.buffer = StringIO.StringIO()
- self.__write = self.buffer.write
- self.mydoc = None
- self.cli_options = cli_options
-
-
- def getInfos(self,node):
- for child_node in node.childNodes:
- if child_node.nodeType == child_node.ELEMENT_NODE:
- if child_node.childNodes:
- if child_node.childNodes[0].nodeValue != "":
- if child_node.nodeName == "version":
- self.version = child_node.childNodes[0].nodeValue
-
- if child_node.nodeName == "artifactId":
- self.artifact = child_node.childNodes[0].nodeValue
-
- if child_node.nodeName == "groupId":
- self.group = child_node.childNodes[0].nodeValue
-
- if child_node.nodeName == "name":
- self.name = child_node.childNodes[0].nodeValue
-
-
- def getDescription(self,mydoc,**kwargs):
- if mydoc:
- self.project = mydoc.getElementsByTagName("project")[0]
- # get inherited properties from parent pom if any
- if self.group == "" or self.version == "" or self.artifact == "":
- for node in self.project.childNodes:
- if node.nodeName == "parent":
- self.is_child = "true"
- self.getInfos(node)
-
- self.getInfos(self.project)
-
- # get our deps
- for node in self.project.childNodes:
- if node.nodeName == "dependencies":
- for dependency_node in node.childNodes:
- if dependency_node.nodeName == "dependency":
- dep = MavenPom()
- for child_node in dependency_node.childNodes:
- if child_node.nodeType == child_node.ELEMENT_NODE:
- dep.getInfos(child_node)
-
- self.dependencies.append(dep)
-
- if self.cli_options.p_group:
- self.__write("pom group:%s\n" % self.group )
-
- if self.cli_options.p_ischild:
- self.__write("pom ischild:%s\n" % self.is_child )
-
- if self.cli_options.p_artifact:
- self.__write("pom artifact:%s\n" % self.artifact )
-
- if self.cli_options.p_version:
- self.__write("pom version:%s\n" % self.version )
-
- if self.cli_options.p_dep:
- i=0
- for dependency in self.dependencies:
- i=i+1
- self.__write("%d:dep_group:%s\n" % (i,dependency.group) )
- self.__write("%d:dep_artifact:%s\n" % (i,dependency.artifact) )
- self.__write("%d:dep_version:%s\n" % (i,dependency.version) )
-
-
- def read(self):
- return self.buffer.getvalue()
-
-
- def rewrite(self,xmldoc,**kwargs):
- # desactivate all dependencies
- dependencies_root = ( xmldoc.getElementsByTagName("dependencies") or [] )
- for node in dependencies_root:
- copylist_child_Nodes =list(node.childNodes)
- for child_node in copylist_child_Nodes:
- node.removeChild(child_node)
- child_node.unlink()
-
- # add our classpath using system scope
- if self.cli_options.classpath:
- i=0
- dependencies_root = ( xmldoc.getElementsByTagName("dependencies") or [] )
- if dependencies_root:
- for node in dependencies_root:
- for classpath_element in self.cli_options.classpath[0].split(':'):
- if classpath_element:
- dependency_elem = xmldoc.createElement("dependency")
- dependency_elem.appendChild( self.create_element(xmldoc, "groupId", "sexy"))
- dependency_elem.appendChild( self.create_element(xmldoc, "artifactId", "gentoo%d" % (i)))
- dependency_elem.appendChild( self.create_element(xmldoc, "version", "666"))
- dependency_elem.appendChild( self.create_element(xmldoc, "scope", "system"))
- dependency_elem.appendChild( self.create_element(xmldoc, "systemPath", classpath_element))
- node.appendChild(dependency_elem)
- i += 1
-
- # overwrite source/target options if any
- # remove version node for all plugins
- if self.cli_options.p_source or self.cli_options.p_target:
- dependencies_root = ( xmldoc.getElementsByTagName("plugin") or [] )
- # remove part
- if len(dependencies_root) > 0:
- for node in dependencies_root:
- for child_node in node.childNodes:
- if child_node.nodeName == "version":
- node.removeChild(child_node)
- child_node.unlink()
-
- if child_node.nodeName == "artifactId":
- if "maven-compiler-plugin" == child_node.childNodes[0].data:
- node.parentNode.removeChild(node)
- node.unlink()
-
- # creation/overwrite part
- plugin_node = self.create_element(xmldoc,"plugin")
- group_node = self.create_element(xmldoc,"groupId","org.apache.maven.plugins")
- artifact_node = self.create_element(xmldoc,"artifactId","maven-compiler-plugin")
- configuration_node = self.create_element(xmldoc,"configuration")
- plugin_node.appendChild(group_node)
- plugin_node.appendChild(artifact_node)
- plugin_node.appendChild(configuration_node)
- if self.cli_options.p_target:
- target_node = self.create_element(xmldoc,"target",self.cli_options.p_target[0])
- configuration_node.appendChild(target_node)
-
- if self.cli_options.p_source:
- source_node = self.create_element(xmldoc,"source",self.cli_options.p_source[0])
- configuration_node.appendChild(source_node)
-
- plugins_nodes = ( xmldoc.getElementsByTagName("plugins") or [] )
- # no plugins node
- if len(plugins_nodes) < 1 :
- plugins_node = self.create_element(xmldoc,"plugins")
- plugins_nodes.append(plugins_node)
-
- for plugins_node in plugins_nodes:
- # add our generated plugin node
- plugins_node.appendChild(plugin_node)
-
- # no build node
- build_nodes = ( xmldoc.getElementsByTagName("build") or [] )
- if len(build_nodes) < 1 :
- build_node = self.create_element(xmldoc,"build")
- build_nodes.append(build_node)
- # add build node to project_node
- project_nodes = ( xmldoc.getElementsByTagName("project") or [] )
- for project_node in project_nodes:
- project_node.appendChild(build_node)
-
- # add plugins structure to the build node
- for build_node in build_nodes:
- build_node.appendChild(plugins_node.cloneNode(deep=True))
-
- from xml.dom.ext import PrettyPrint
- self.write = self.__write
- PrettyPrint(xmldoc,self)
- self.write = None
-
-
- def create_element(self,xmldoc,element_name,text_value=None):
- element = None
- if element_name:
- element = xmldoc.createElement(element_name)
- if text_value:
- text_node = xmldoc.createTextNode(text_value)
- element.appendChild(text_node)
-
- return element
-
-
- def parse(self,in_stream,callback=None,**kwargs):
- from xml.dom.minidom import parseString
- self.mydoc = parseString(in_stream)
-
- if callback:
- callback(self.mydoc,**kwargs)
-
-
-
-if __name__ == '__main__':
- usage = "XML MAVEN POM MODULE " + __version__ + "\n"
- usage += "Copyright 2004,2006,2007 Gentoo Foundation\n"
- usage += "Distributed under the terms of the GNU General Public Lincense v2\n"
- usage += "Please contact the Gentoo Java Team <java@gentoo.org> with problems.\n"
- usage += "\n"
- usage += "Usage:\n"
- usage += " %s [-a] [-v] [-g] [-d] [-f fic.xml]\n" % sys.argv[0]
- usage += "Or:\n"
- usage += " %s --rewrite [--classpath some.jar:class.jar:path.jar] [--source JVM_VER ] |--target JVM_VER]\n" % sys.argv[0]
- usage += " JVM_VER ::= 1.4 || 1.5 "
- usage += "\n"
- usage += "If the -f parameter is not utilized, the script will read and\n"
- usage += "write to stdin and stdout respectively. The use of quotes on\n"
- usage += "parameters will break the script.\n"
-
-
- def error(message):
- print "ERROR: " + message
- sys.exit(1)
-
-
- def doAction(stream,options):
- pom = MavenPom(options)
- if options.p_rewrite:
- pom.parse(stream, pom.rewrite)
- elif options.p_ischild or options.p_group or options.p_dep or options.p_artifact or options.p_version:
- pom.parse(stream, pom.getDescription)
-
- return pom
-
-
- def run():
- if options.files:
- import os
- for file in options.files:
- # First parse the file into memory
- cwd = os.getcwd()
- dirname = os.path.dirname(file)
- if dirname != '': # for file comes out as ''
- os.chdir(os.path.dirname(file))
-
- f = open(os.path.basename(file),"r")
- fs = f.read()
- f.close()
- # parse file and return approtiate pom object
- pom = doAction(fs,options)
- if options.p_rewrite:
- f = open(os.path.basename(file),"w")
- f.write(pom.read())
- f.close()
- else:
- print "%s" % pom.read()
-
- os.chdir(cwd)
-
- else:
- # process stdin
- pom = doAction(sys.stdin.read(),options)
- print pom.read()
-
-
-
-############### MAIN ###############
-
-
-
- options_list = [
- make_option ("-a", "--artifact", action="store_true", dest="p_artifact", help="get artifact name."),
- make_option ("-c", "--classpath", action="append", dest="classpath", help="set classpath to use with maven."),
- make_option ("-s", "--source", action="append", dest="p_source", help="Java source version."),
- make_option ("-t", "--target", action="append", dest="p_target", help="Java target version."),
- make_option ("-d", "--depependencies" , action="store_true", dest="p_dep", help="get dependencies infos"),
- make_option ("-f", "--file", action="append", dest="files", help="Transform files instead of operating on stdout and stdin"),
- make_option ("-g", "--group" , action="store_true", dest="p_group", help="get artifact group."),
- make_option ("-r", "--rewrite", action="store_true", dest="p_rewrite", help="rewrite poms to use our classpath"),
- make_option ("-p", "--ischild", action="store_true", dest="p_ischild", help="return true if this is a child pom"),
- make_option ("-v", "--version" , action="store_true", dest="p_version", help="get artifact version."),
- ]
-
- parser = OptionParser(usage, options_list)
- (options, args) = parser.parse_args()
-
- # Invalid Arguments Must be smited!
- if not options.p_ischild and not options.p_rewrite and not options.p_dep and not options.p_version and not options.p_artifact and not options.p_group:
- print usage
- print
- error("No action was specified.")
-
- if options.files:
- if len(options.files) > 1:
- error("Please specify only one pom at a time.")
-
- if options.p_rewrite:
- valid_sources = ["1.4","1.5"]
- for source in valid_sources:
- if options.p_source:
- if len(options.p_source) != 1:
- error("Please specify one and only one source.")
-
- if options.p_source[0] not in valid_sources:
- error("Source %s is not valid" % options.p_source[0])
-
- if options.p_target:
- if len(options.p_target) != 1:
- error("Please specify one and only one target.")
-
- if options.p_target[0] not in valid_sources:
- error("Target %s is not valid" % options.p_target[0])
-
- # join any classpathes if any
- if options.classpath:
- if len(options.classpath) > 1:
- start =[]
- start.append(options.classpath[0])
- for item in options.classpath[1:]:
- start[0] += ":%s" % (item)
-
- options.classpath = start
-
- # End Invalid Arguments Check
- # main loop
- run()
-
diff --git a/src/bsfix/JXSLT.java b/src/obsolete/bsfix/JXSLT.java
index 3b580f2..3b580f2 100644
--- a/src/bsfix/JXSLT.java
+++ b/src/obsolete/bsfix/JXSLT.java
diff --git a/src/bsfix/Makefile b/src/obsolete/bsfix/Makefile
index 87b0e32..87b0e32 100644
--- a/src/bsfix/Makefile
+++ b/src/obsolete/bsfix/Makefile
diff --git a/src/bsfix/bsfix b/src/obsolete/bsfix/bsfix
index 7d7dc79..7d7dc79 100755
--- a/src/bsfix/bsfix
+++ b/src/obsolete/bsfix/bsfix
diff --git a/src/bsfix/bsfix-eclipse.py b/src/obsolete/bsfix/bsfix-eclipse.py
index 3109b7d..3109b7d 100755
--- a/src/bsfix/bsfix-eclipse.py
+++ b/src/obsolete/bsfix/bsfix-eclipse.py
diff --git a/src/bsfix/bsfix.py b/src/obsolete/bsfix/bsfix.py
index 9aafe7d..9aafe7d 100755
--- a/src/bsfix/bsfix.py
+++ b/src/obsolete/bsfix/bsfix.py
diff --git a/src/bsfix/build-xml-source-target.xslt b/src/obsolete/bsfix/build-xml-source-target.xslt
index fd9bceb..fd9bceb 100644
--- a/src/bsfix/build-xml-source-target.xslt
+++ b/src/obsolete/bsfix/build-xml-source-target.xslt
diff --git a/src/bsfix/rewrite2-speed-test.sh b/src/obsolete/bsfix/rewrite2-speed-test.sh
index b572206..b572206 100755
--- a/src/bsfix/rewrite2-speed-test.sh
+++ b/src/obsolete/bsfix/rewrite2-speed-test.sh
diff --git a/src/bsfix/tests/build.xml b/src/obsolete/bsfix/tests/build.xml
index e8a8aa5..e8a8aa5 100644
--- a/src/bsfix/tests/build.xml
+++ b/src/obsolete/bsfix/tests/build.xml
diff --git a/src/bsfix/build-xml-rewrite b/src/py/build-xml-rewrite
index 61d69ae..a762e16 100755
--- a/src/bsfix/build-xml-rewrite
+++ b/src/py/build-xml-rewrite
@@ -1,4 +1,4 @@
-#!/usr/bin/python
+#!/usr/bin/env python
import sys
import xml.etree.cElementTree as et
diff --git a/src/py/buildparser b/src/py/buildparser
new file mode 100755
index 0000000..f388fcd
--- /dev/null
+++ b/src/py/buildparser
@@ -0,0 +1,128 @@
+#!/usr/bin/env python
+#
+# Copyright(c) 2006, 2008 James Le Cuirot <chewi@aura-online.co.uk>
+# Copyright(c) 2005, Karl Trygve Kalleberg <karltk@gentoo.org>
+#
+# Licensed under the GNU General Public License, v2
+#
+# $Header:$
+
+import os
+import sys
+from optparse import OptionParser
+
+sys.path.insert(0, "/usr/share/javatoolkit/pym")
+
+from javatoolkit.parser.parser import Parser
+from javatoolkit.parser.buildproperties import BuildPropertiesParser
+from javatoolkit.parser.manifest import ManifestParser
+from javatoolkit.parser.tree import Node, ParseError
+
+__author__ = ["James Le Cuirot <chewi@aura-online.co.uk>", "Karl Trygve Kalleberg <karltk@gentoo.org>"]
+__version__ = "0.3.0"
+__productname__ = "buildparser"
+__description__ = "A parser for build.properties and JAR manifest files."
+
+
+def parse_args():
+
+ usage = 'buildparser [options] [node name] [replacement] <filename>'
+ about = __productname__ + " : " + __description__ + "\n" + \
+ "Version : " + __version__ + "\n" \
+ "Authors : " + __author__[0]
+
+ for x in __author__[1:]:
+ about += "\n " + x
+
+ parser = OptionParser(usage, version=about)
+
+ parser.add_option('-t', '--type', action='store', type='choice',
+ dest='type', choices=['manifest', 'buildprops'],
+ help='Type of file to parse: manifest or buildprops')
+
+ parser.add_option('-i', '--in-place', action='store_true', dest='in_place',
+ help='Edit file in place when replacing')
+
+ parser.add_option('-w', '--wrap', action='store_true', dest='wrap',
+ help='Wrap when returning singular values')
+
+ opt, args = parser.parse_args()
+
+ if len(args) > 3:
+ parser.error("Too many arguments specified!")
+
+ elif len(args) == 0:
+ parser.error("A filename must be specified!")
+
+ elif not os.path.isfile(args[-1]):
+ parser.error(args[-1] + " does not exist!")
+
+ return opt, args
+
+def main():
+
+ opt, args = parse_args()
+
+ f = open(args[-1])
+
+ t = Node()
+ p = Parser()
+
+ try:
+ if opt.type == "manifest":
+ p = ManifestParser()
+
+ elif opt.type == "buildprops":
+ p = BuildPropertiesParser()
+
+ elif os.path.basename(f.name) == "MANIFEST.MF":
+ p = ManifestParser()
+
+ elif os.path.basename(f.name) == "build.properties":
+ p = BuildPropertiesParser()
+
+ else:
+ sys.exit(__productname__ + ": error: Unknown file type. Specify using the -t option.")
+
+ t = p.parse(f)
+ f.close()
+
+ except ParseError:
+ sys.exit(__productname__ + ": error: Unable to parse file.")
+
+ if len(args) > 2:
+ n = t.find_node(args[0])
+
+ if n != None:
+ n.value = args[1]
+ else:
+ t.add_kid(Node(args[0], args[1]))
+
+ if opt.in_place:
+ f = open(args[-1], "w+")
+ p.output(f, t)
+ f.close()
+
+ else:
+ p.output(sys.stdout, t)
+
+ elif len(args) > 1:
+ n = t.find_node(args[0])
+
+ if n != None:
+ if opt.wrap:
+ print p.wrapped_value(n)
+ else:
+ print n.value
+
+ else:
+ for x in t.node_names():
+ print x
+
+if __name__ == '__main__':
+ try:
+ main()
+ except KeyboardInterrupt:
+ print "Interrupted by user, aborting."
+
+#set expandtab tabstop=4 shiftwidth=4 softtabstop=4 nowrap
diff --git a/src/py/class-version-verify.py b/src/py/class-version-verify.py
new file mode 100755
index 0000000..dbfb7d5
--- /dev/null
+++ b/src/py/class-version-verify.py
@@ -0,0 +1,66 @@
+#!/usr/bin/env python
+#
+# Copyright(c) 2005, Thomas Matthijs <axxo@gentoo.org>
+# Copyright(c) 2005, Gentoo Foundation
+#
+# Licensed under the GNU General Public License, v2
+#
+# $Header: /var/cvsroot/gentoo-src/javatoolkit/src/bsfix/class-version-verify.py,v 1.2 2005/07/19 10:35:18 axxo Exp $
+
+import os,sys
+from optparse import OptionParser, make_option
+from javatoolkit.cvv import *
+
+if __name__ == '__main__':
+
+ options_list = [
+ make_option ("-r", "--recurse", action="store_true", dest="deep", default=False, help="go into dirs"),
+ make_option ("-t", "--target", type="string", dest="version", help="target version that is valid"),
+
+ make_option ("-v", "--verbose", action="store_true", dest="verbose", default=False, help="Print version of every calss"),
+ make_option ("-s", "--silent", action="store_true", dest="silent", default=False, help="No output"),
+ make_option ("-f", "--file-only", action="store_true", dest="file_only", default=False, help="Only output the files"),
+ ]
+
+ parser = OptionParser("%prog -t version [-r] [-v] [-s] <class/jar files or dir>", options_list)
+ (options, args) = parser.parse_args()
+
+ if not options.version:
+ print "-t is mandatory"
+ sys.exit(2)
+
+ options.version = int(options.version.split(".")[-1])
+
+ cvv = cvv(options.version)
+
+ for arg in args:
+ if os.path.isfile(arg):
+ cvv.do_file(arg)
+
+ if options.deep and os.path.isdir(arg):
+ for root, dirs, files in os.walk(arg):
+ for filename in files:
+ cvv.do_file("%s/%s" % (root, filename))
+
+ if options.file_only:
+ lst = set([set[1] for set in cvv.bad])
+ for i in lst:
+ print i
+ else:
+
+ if options.verbose:
+ for set in cvv.good:
+ print "Good: %s %s %s" % set
+
+ if not options.silent:
+ for set in cvv.bad:
+ print "Bad: %s %s %s" % set
+
+ print "CVV: %s\nChecked: %i Good: %i Bad: %i" % (options.version, len(cvv.good)+len(cvv.bad) , len(cvv.good), len(cvv.bad))
+
+ if len(cvv.bad) > 0:
+ sys.exit(1)
+ else:
+ sys.exit(0)
+
+#set expandtab tabstop=4 shiftwidth=4 softtabstop=4 nowrap
diff --git a/src/findclass/findclass b/src/py/findclass
index 15802c9..15802c9 100644..100755
--- a/src/findclass/findclass
+++ b/src/py/findclass
diff --git a/src/py/jarjarclean b/src/py/jarjarclean
new file mode 100755
index 0000000..517f0be
--- /dev/null
+++ b/src/py/jarjarclean
@@ -0,0 +1,42 @@
+#!/usr/bin/env python
+#
+# Copyright 2008 James Le Cuirot <chewi@aura-online.co.uk>
+# Copyright 2008 Gentoo Foundation
+# Distributed under the terms of the GNU General Public License v2
+#
+# $Header: $
+
+import sys
+import xml.etree.cElementTree as et
+
+args = sys.argv[1:]
+if len(args) == 0:
+ args = [ 'build.xml' ]
+
+for file in args:
+ tree = et.ElementTree(file=file)
+ tags = []
+
+ for elem in tree.getiterator():
+ for child in list(elem):
+ if child.tag == 'taskdef' and child.get('classname') == 'com.tonicsystems.jarjar.JarJarTask':
+ tags.append(child.get('name'))
+ elem.remove(child)
+
+ for tag in tags:
+ for jarjar in tree.getiterator(tag):
+ if jarjar.get('destfile') or jarjar.get('jarfile'):
+ jarjar.tag = 'jar'
+
+ if jarjar.get('verbose'):
+ del jarjar.attrib['verbose']
+
+ for child in list(jarjar):
+ if child.tag == 'keep' or child.tag == 'rule' or child.tag == 'zipfileset':
+ jarjar.remove(child)
+
+ f = open(file, 'w')
+ tree.write(f)
+ f.close()
+
+#set expandtab tabstop=4 shiftwidth=4 softtabstop=4 nowrap
diff --git a/src/javatoolkit/__init__.py b/src/py/javatoolkit/__init__.py
index 89a74a8..5d9dcee 100644
--- a/src/javatoolkit/__init__.py
+++ b/src/py/javatoolkit/__init__.py
@@ -1,4 +1,4 @@
-#! /usr/bin/python2
+#!/usr/bin/env python
#
# Copyright(c) 2004, Karl Trygve Kalleberg <karltk@gentoo.org>
# Copyright(c) 2004, Gentoo Foundation
diff --git a/src/py/javatoolkit/classpath.py b/src/py/javatoolkit/classpath.py
new file mode 100644
index 0000000..18c6857
--- /dev/null
+++ b/src/py/javatoolkit/classpath.py
@@ -0,0 +1,68 @@
+# Copyright(c) 2004, Karl Trygve Kalleberg <karltk@gentoo.org>
+# Copyright(c) 2004, Gentoo Foundation
+#
+# Licensed under the GNU General Public License, v2
+#
+# $Header: /var/cvsroot/gentoo-src/javatoolkit/src/javatoolkit/classpath.py,v 1.4 2004/11/08 20:06:06 karltk Exp $
+
+class ClasspathIter:
+ """An iterator for the Classpath class, below."""
+
+ def __init__(self, classpath):
+ self._classpath = classpath
+ self._index = 0
+
+ def next(self):
+ self._index += 1
+ if self._index >= len(self._classpath.classpath):
+ raise StopIteration
+ return self._classpath.classpath[self._index]
+
+
+class Classpath:
+ """A classpath object provides a collection interface to the elements of a : separated path list. """
+
+ def __init__(self, classpath_string = None):
+ if classpath_string != None:
+ cs = classpath_string.strip().strip("\"")
+ self.classpath = cs.split(":")
+ else:
+ self.classpath = []
+
+
+ def __iter__(self):
+ """Returns iterator. Elements of the original classpath string are considered split by ':'."""
+
+ return ClasspathIter(self)
+
+
+ def __len__(self):
+ """Returns length (number of elements) in this classpath."""
+
+ return len(self.classpath)
+
+
+ def __getitem__(self, i):
+ """Returns i'th element."""
+
+ return self.classpath[i]
+
+
+ def __setitem__(self, i, val):
+ """Sets i'th element."""
+
+ self.classpath[i] = val
+
+
+ def __str__(self):
+ """Constructs a suitable string representation of the classpath."""
+
+ return ":".join(self.classpath)
+
+
+ def append(self, element):
+ """Appends an path to the classpath."""
+
+ self.classpath.append(element)
+
+# vim: set expandtab tabstop=4 shiftwidth=4 softtabstop=4 nowrap:
diff --git a/src/py/javatoolkit/cvv.py b/src/py/javatoolkit/cvv.py
new file mode 100644
index 0000000..72375d3
--- /dev/null
+++ b/src/py/javatoolkit/cvv.py
@@ -0,0 +1,52 @@
+# Copyright 2005, Thomas Matthijs <axxo@gentoo.org>
+# Copyright 1999-2008 Gentoo Foundation
+# Distributed under the terms of the GNU General Public License v2
+# $Header: $
+
+import os,sys
+from struct import unpack
+from zipfile import ZipFile
+
+class cvv:
+ def __init__(self, target):
+ self.target = target
+ self.good = []
+ self.bad = []
+
+ def add(self, version, jar, file):
+ if version <= self.target:
+ self.good.append(("1."+str(version), jar, file))
+ else:
+ self.bad.append(("1."+str(version), jar, file))
+
+ def do_class(self,filename):
+ classFile = file(filename,"rb")
+ classFile.seek(4)
+
+ temp = classFile.read(4)
+ #(version,) = unpack('>i',temp)
+ (version,) = unpack('>xxh',temp)
+ version-=44
+
+ self.add(version, None, filename)
+
+ def do_jar(self, filename):
+ zipfile = ZipFile(filename, 'r')
+
+ for file in zipfile.namelist():
+ if file.endswith('class'):
+ classFile = zipfile.read(file)
+
+ (version,) = unpack('>h',classFile[6:8])
+ version-=44
+
+ self.add(version, filename, file)
+
+ def do_file(self, filename):
+ if not os.path.islink(filename):
+ if filename.endswith(".class"):
+ self.do_class(filename)
+ if filename.endswith(".jar"):
+ self.do_jar(filename)
+
+# vim: set expandtab tabstop=4 shiftwidth=4 softtabstop=4 nowrap:
diff --git a/src/py/javatoolkit/maven/MavenPom.py b/src/py/javatoolkit/maven/MavenPom.py
new file mode 100644
index 0000000..8a7fcd9
--- /dev/null
+++ b/src/py/javatoolkit/maven/MavenPom.py
@@ -0,0 +1,212 @@
+# Copyright 2004-2007 Gentoo Foundation
+# Distrubuted under the terms of the GNU General Public Licence v2
+
+# Authors:
+# koirky <kiorky@cryptelium.net> The code:
+# ali_bush <ali_bush@gentoo.org> Refactored into module.
+# Python based POM navigator
+
+# Changelog
+# ali_bush <ali_bush@gentoo.org>
+# 31/12/07 Refacted by separating MavenPom into namespace
+#
+# kiorky <kiorky@cryptelium.net>
+# 31/05/2007 Add rewrite feature
+#
+# kiorky <kiorky@cryptelium.net>
+# 08/05/2007 initial version
+
+import sys
+import StringIO
+
+# either a very simplified representation of a maven pom
+# or a fully xml rewritten pom
+class MavenPom:
+ def __init__(self,cli_options = None):
+ self.group = ''
+ self.artifact = ''
+ self.version = ''
+ self.name = ''
+ self.is_child = "false"
+ self.dependencies = []
+ self.buffer = StringIO.StringIO()
+ self.__write = self.buffer.write
+ self.mydoc = None
+ self.cli_options = cli_options
+
+
+ def getInfos(self,node):
+ for child_node in node.childNodes:
+ if child_node.nodeType == child_node.ELEMENT_NODE:
+ if child_node.childNodes:
+ if child_node.childNodes[0].nodeValue != "":
+ if child_node.nodeName == "version":
+ self.version = child_node.childNodes[0].nodeValue
+
+ if child_node.nodeName == "artifactId":
+ self.artifact = child_node.childNodes[0].nodeValue
+
+ if child_node.nodeName == "groupId":
+ self.group = child_node.childNodes[0].nodeValue
+
+ if child_node.nodeName == "name":
+ self.name = child_node.childNodes[0].nodeValue
+
+
+ def getDescription(self,mydoc,**kwargs):
+ if mydoc:
+ self.project = mydoc.getElementsByTagName("project")[0]
+ # get inherited properties from parent pom if any
+ if self.group == "" or self.version == "" or self.artifact == "":
+ for node in self.project.childNodes:
+ if node.nodeName == "parent":
+ self.is_child = "true"
+ self.getInfos(node)
+
+ self.getInfos(self.project)
+
+ # get our deps
+ for node in self.project.childNodes:
+ if node.nodeName == "dependencies":
+ for dependency_node in node.childNodes:
+ if dependency_node.nodeName == "dependency":
+ dep = MavenPom()
+ for child_node in dependency_node.childNodes:
+ if child_node.nodeType == child_node.ELEMENT_NODE:
+ dep.getInfos(child_node)
+
+ self.dependencies.append(dep)
+
+ if self.cli_options.p_group:
+ self.__write("pom group:%s\n" % self.group )
+
+ if self.cli_options.p_ischild:
+ self.__write("pom ischild:%s\n" % self.is_child )
+
+ if self.cli_options.p_artifact:
+ self.__write("pom artifact:%s\n" % self.artifact )
+
+ if self.cli_options.p_version:
+ self.__write("pom version:%s\n" % self.version )
+
+ if self.cli_options.p_dep:
+ i=0
+ for dependency in self.dependencies:
+ i=i+1
+ self.__write("%d:dep_group:%s\n" % (i,dependency.group) )
+ self.__write("%d:dep_artifact:%s\n" % (i,dependency.artifact) )
+ self.__write("%d:dep_version:%s\n" % (i,dependency.version) )
+
+
+ def read(self):
+ return self.buffer.getvalue()
+
+
+ def rewrite(self,xmldoc,**kwargs):
+ # desactivate all dependencies
+ dependencies_root = ( xmldoc.getElementsByTagName("dependencies") or [] )
+ for node in dependencies_root:
+ copylist_child_Nodes =list(node.childNodes)
+ for child_node in copylist_child_Nodes:
+ node.removeChild(child_node)
+ child_node.unlink()
+
+ # add our classpath using system scope
+ if self.cli_options.classpath:
+ i=0
+ dependencies_root = ( xmldoc.getElementsByTagName("dependencies") or [] )
+ if dependencies_root:
+ for node in dependencies_root:
+ for classpath_element in self.cli_options.classpath[0].split(':'):
+ if classpath_element:
+ dependency_elem = xmldoc.createElement("dependency")
+ dependency_elem.appendChild( self.create_element(xmldoc, "groupId", "sexy"))
+ dependency_elem.appendChild( self.create_element(xmldoc, "artifactId", "gentoo%d" % (i)))
+ dependency_elem.appendChild( self.create_element(xmldoc, "version", "666"))
+ dependency_elem.appendChild( self.create_element(xmldoc, "scope", "system"))
+ dependency_elem.appendChild( self.create_element(xmldoc, "systemPath", classpath_element))
+ node.appendChild(dependency_elem)
+ i += 1
+
+ # overwrite source/target options if any
+ # remove version node for all plugins
+ if self.cli_options.p_source or self.cli_options.p_target:
+ dependencies_root = ( xmldoc.getElementsByTagName("plugin") or [] )
+ # remove part
+ if len(dependencies_root) > 0:
+ for node in dependencies_root:
+ for child_node in node.childNodes:
+ if child_node.nodeName == "version":
+ node.removeChild(child_node)
+ child_node.unlink()
+
+ if child_node.nodeName == "artifactId":
+ if "maven-compiler-plugin" == child_node.childNodes[0].data:
+ node.parentNode.removeChild(node)
+ node.unlink()
+
+ # creation/overwrite part
+ plugin_node = self.create_element(xmldoc,"plugin")
+ group_node = self.create_element(xmldoc,"groupId","org.apache.maven.plugins")
+ artifact_node = self.create_element(xmldoc,"artifactId","maven-compiler-plugin")
+ configuration_node = self.create_element(xmldoc,"configuration")
+ plugin_node.appendChild(group_node)
+ plugin_node.appendChild(artifact_node)
+ plugin_node.appendChild(configuration_node)
+ if self.cli_options.p_target:
+ target_node = self.create_element(xmldoc,"target",self.cli_options.p_target[0])
+ configuration_node.appendChild(target_node)
+
+ if self.cli_options.p_source:
+ source_node = self.create_element(xmldoc,"source",self.cli_options.p_source[0])
+ configuration_node.appendChild(source_node)
+
+ plugins_nodes = ( xmldoc.getElementsByTagName("plugins") or [] )
+ # no plugins node
+ if len(plugins_nodes) < 1 :
+ plugins_node = self.create_element(xmldoc,"plugins")
+ plugins_nodes.append(plugins_node)
+
+ for plugins_node in plugins_nodes:
+ # add our generated plugin node
+ plugins_node.appendChild(plugin_node)
+
+ # no build node
+ build_nodes = ( xmldoc.getElementsByTagName("build") or [] )
+ if len(build_nodes) < 1 :
+ build_node = self.create_element(xmldoc,"build")
+ build_nodes.append(build_node)
+ # add build node to project_node
+ project_nodes = ( xmldoc.getElementsByTagName("project") or [] )
+ for project_node in project_nodes:
+ project_node.appendChild(build_node)
+
+ # add plugins structure to the build node
+ for build_node in build_nodes:
+ build_node.appendChild(plugins_node.cloneNode(deep=True))
+
+ from xml.dom.ext import PrettyPrint
+ self.write = self.__write
+ PrettyPrint(xmldoc,self)
+ self.write = None
+
+
+ def create_element(self,xmldoc,element_name,text_value=None):
+ element = None
+ if element_name:
+ element = xmldoc.createElement(element_name)
+ if text_value:
+ text_node = xmldoc.createTextNode(text_value)
+ element.appendChild(text_node)
+
+ return element
+
+
+ def parse(self,in_stream,callback=None,**kwargs):
+ from xml.dom.minidom import parseString
+ self.mydoc = parseString(in_stream)
+
+ if callback:
+ callback(self.mydoc,**kwargs)
+
+# vim: set expandtab tabstop=4 shiftwidth=4 softtabstop=4 nowrap:
diff --git a/src/py/javatoolkit/maven/__init__.py b/src/py/javatoolkit/maven/__init__.py
new file mode 100644
index 0000000..c339ef6
--- /dev/null
+++ b/src/py/javatoolkit/maven/__init__.py
@@ -0,0 +1,7 @@
+'''
+javatoolkit.maven module
+'''
+
+__version__ = '1.1'
+
+#set expandtab tabstop=4 shiftwidth=4 softtabstop=4 nowrap
diff --git a/src/javatoolkit/output.py b/src/py/javatoolkit/output.py
index 05192ef..6f7680d 100644
--- a/src/javatoolkit/output.py
+++ b/src/py/javatoolkit/output.py
@@ -1,5 +1,3 @@
-#! /usr/bin/python2
-#
# Copyright(c) 2004, Karl Trygve Kalleberg <karltk@gentoo.org>
# Copyright(c) 2004, Gentoo Foundation
#
@@ -12,17 +10,16 @@ import sys
# FIXME: Use gentoolkit stuff instead
def eerror(s):
- sys.stderr.write("!!! " + s + "\n")
+ sys.stderr.write("!!! " + s + "\n")
def ewarn(s):
- sys.stdout.write("* " + s + "\n")
+ sys.stdout.write("* " + s + "\n")
def einfo(s):
- sys.stdout.write("* " + s + "\n")
+ sys.stdout.write("* " + s + "\n")
def die(err, s):
- eerror(s)
- sys.exit(err)
-
-if __name__ == "__main__":
- print "This is not an executable module" \ No newline at end of file
+ eerror(s)
+ sys.exit(err)
+
+# vim: set expandtab tabstop=4 shiftwidth=4 softtabstop=4 nowrap:
diff --git a/src/javatoolkit/parser/__init__.py b/src/py/javatoolkit/parser/__init__.py
index d96be04..55f6e54 100644
--- a/src/javatoolkit/parser/__init__.py
+++ b/src/py/javatoolkit/parser/__init__.py
@@ -1,4 +1,4 @@
-#! /usr/bin/python
+#!/usr/bin/env python
#
# Copyright(c) 2004, Karl Trygve Kalleberg <karltk@gentoo.org>
# Copyright(c) 2004, Gentoo Foundation
diff --git a/src/py/javatoolkit/parser/buildproperties.py b/src/py/javatoolkit/parser/buildproperties.py
new file mode 100644
index 0000000..e3672e5
--- /dev/null
+++ b/src/py/javatoolkit/parser/buildproperties.py
@@ -0,0 +1,83 @@
+# Copyright(c) 2006, 2008, James Le Cuirot <chewi@aura-online.co.uk>
+# Copyright(c) 2004, Karl Trygve Kalleberg <karltk@gentoo.org>
+# Copyright(c) 2004, Gentoo Foundation
+#
+# Licensed under the GNU General Public License, v2
+#
+# $Header: $
+
+from tree import *
+import parser
+
+class BuildPropertiesParser(parser.Parser):
+
+ def parse(self, ins):
+ """ Parse an input stream containing an ant build.properties file. Return a
+ structured document represented by tree.Node
+
+ @param ins - input stream
+ @return tree.Node containing the structured representation
+ """
+
+ lineno = 0
+ continued_line = False
+ inside_html_comment = False
+ attrib = ""
+ value = ""
+ root = Node()
+
+ for x in ins.readlines():
+ lineno += 1
+ x = x.strip()
+
+ if inside_html_comment and x.find("-->") != -1:
+ inside_html_comment = False
+ x = x.split("-->", 1)[0]
+
+ if x.find("<!--") != -1:
+ inside_html_comment = True
+
+ if inside_html_comment:
+ continue
+
+ if continued_line:
+ continued_line = False
+ value += x.strip("\"")
+
+ if len(value) and value[-1] == "\\":
+ value = value[:-1]
+ continued_line = True
+ continue
+
+ root.add_kid(Node(attrib,value))
+ continue
+
+ if len(x) == 0 or x[:1] == "#":
+ continue
+
+ x = x.split("#", 1)[0]
+ xs = x.split("=", 2)
+
+ if len(xs) > 1:
+ attrib = xs[0].strip()
+ value = xs[1].strip().strip("\"")
+
+ if value != "" and value[-1] == "\\":
+ value = value[:-1]
+ continued_line = True
+ continue
+
+ root.add_kid(Node(attrib,value))
+
+ else:
+ raise ParseError("Malformed line " + str(lineno))
+
+ return root
+
+ def output(self, ous, tree):
+ tree.output(ous, "", " = ", "")
+
+ def wrapped_value(self, node):
+ return node.output_value()
+
+# vim: set expandtab tabstop=4 shiftwidth=4 softtabstop=4 nowrap:
diff --git a/src/py/javatoolkit/parser/helpers.py b/src/py/javatoolkit/parser/helpers.py
new file mode 100644
index 0000000..b11b08b
--- /dev/null
+++ b/src/py/javatoolkit/parser/helpers.py
@@ -0,0 +1,57 @@
+# Copyright(c) 2006, James Le Cuirot <chewi@aura-online.co.uk>
+# Copyright(c) 2004, Karl Trygve Kalleberg <karltk@gentoo.org>
+# Copyright(c) 2004, Gentoo Foundation
+#
+# Licensed under the GNU General Public License, v2
+#
+# $Header: $
+
+def expand(root, expr, realroot = None):
+ """Evaluates a path expression on a given tree.
+
+ @param root - the root of the tree
+ @param expr - the expression to resolve
+
+ @return the expanded string
+ """
+
+ if realroot == None:
+ realroot = root
+
+ expanded = ""
+ in_varref = False
+ varname = ""
+
+ for i in range(len(expr)):
+ x = expr[i]
+
+ if in_varref:
+
+ if x == "}":
+ in_varref = False
+ expanded += expand(root, realroot.find_node(varname).value, realroot)
+ varname = ""
+ elif x != "{":
+ varname += expr[i]
+
+ elif x == "$" and i < len(expr) and expr[i + 1] == "{":
+ in_varref = True
+
+ else:
+ expanded += x
+
+ return expanded
+
+def strip_varmarker(s):
+ """Strips away ${ and } in a variable expression. Idempotent if marker not found.
+
+ Example: "${foo}" -> "foo"
+ Example: "foo" -> "foo"
+ """
+
+ if s.startswith("${") and s.endswith("}"):
+ return s[2:-1]
+
+ return s
+
+# vim: set expandtab tabstop=4 shiftwidth=4 softtabstop=4 nowrap:
diff --git a/src/py/javatoolkit/parser/manifest.py b/src/py/javatoolkit/parser/manifest.py
new file mode 100644
index 0000000..da124f9
--- /dev/null
+++ b/src/py/javatoolkit/parser/manifest.py
@@ -0,0 +1,61 @@
+# Copyright(c) 2006, 2008, James Le Cuirot <chewi@aura-online.co.uk>
+#
+# Licensed under the GNU General Public License, v2
+#
+# $Header: $
+
+from tree import *
+import parser
+
+class ManifestParser(parser.Parser):
+
+ def parse(self, ins):
+ """ Parse an input stream containing a MANIFEST.MF file. Return a
+ structured document represented by tree.Node
+
+ @param ins - input stream
+ @return tree.Node containing the structured representation
+ """
+
+ lineno = 0
+ attrib = ""
+ value = ""
+ root = Node()
+
+ for x in ins.readlines():
+ lineno += 1
+
+ if len(x.strip()) == 0:
+ continue
+
+ if x[:1] == " ":
+ if attrib == "":
+ raise ParseError("Malformed line " + str(lineno))
+
+ value += x.strip()
+ continue
+
+ xs = x.split(": ", 2)
+
+ if len(xs) > 1:
+ if attrib != "":
+ root.add_kid(Node(attrib,value))
+
+ attrib = xs[0]
+ value = xs[1].strip()
+
+ else:
+ raise ParseError("Malformed line " + str(lineno))
+
+ if attrib != "":
+ root.add_kid(Node(attrib,value))
+
+ return root
+
+ def output(self, ous, tree):
+ tree.output(ous, "", ": ", "", ",", " ")
+
+ def wrapped_value(self, node):
+ return node.output_value(",")
+
+# vim: set expandtab tabstop=4 shiftwidth=4 softtabstop=4 nowrap:
diff --git a/src/py/javatoolkit/parser/parser.py b/src/py/javatoolkit/parser/parser.py
new file mode 100644
index 0000000..01e1171
--- /dev/null
+++ b/src/py/javatoolkit/parser/parser.py
@@ -0,0 +1,13 @@
+# Copyright(c) 2006, James Le Cuirot <chewi@aura-online.co.uk>
+#
+# Licensed under the GNU General Public License, v2
+#
+# $Header: $
+
+class Parser:
+ def parse(self, ins):
+ raise NotImplementedError
+ def output(self, ous, tree):
+ raise NotImplementedError
+
+# vim: set expandtab tabstop=4 shiftwidth=4 softtabstop=4 nowrap:
diff --git a/src/py/javatoolkit/parser/tree.py b/src/py/javatoolkit/parser/tree.py
new file mode 100644
index 0000000..ca361c9
--- /dev/null
+++ b/src/py/javatoolkit/parser/tree.py
@@ -0,0 +1,135 @@
+# Copyright(c) 2006, 2008, James Le Cuirot <chewi@aura-online.co.uk>
+# Copyright(c) 2004, Karl Trygve Kalleberg <karltk@gentoo.org>
+# Copyright(c) 2004, Gentoo Foundation
+#
+# Licensed under the GNU General Public License, v2
+#
+# $Header: $
+
+import sys
+
+class ParseError:
+ def __init__(self, error):
+ self.error = error
+
+class NodeIter:
+ def __init__(self, node):
+ self._node = node
+ self._index = 0
+ def next(self):
+ self._index += 1
+ if self._index >= len(self._node._kids):
+ raise StopIteration
+ return self._node._kids[self._index]
+
+class Node:
+ def __init__(self, name = None, value = None):
+ self.name = name
+ self.value = value
+ self._kids = []
+
+ def __iter__(self):
+ return NodeIter(self)
+
+ def add_kid(self, kid):
+ for x in self._kids:
+ if x.name == kid.name:
+ return
+
+ self._kids.append(kid)
+
+ def _dump_kids(self, ous, indent):
+ for x in self._kids:
+ x.dump(ous, indent + 1)
+
+ """
+ Dump self as text to stream.
+ """
+ def dump(self, ous, indent = 0):
+ if self.name:
+ ous.write((" " * indent) + self.name + " = " + self.value + "\n")
+
+ self._dump_kids(ous, indent)
+
+ """
+ Output self as text to stream using the given format.
+ """
+ def output(self, ous, before, between, after, wrap = None, indent = ""):
+ if self.name:
+ ous.write(before + self.name + between + self.output_value(wrap, indent) + after + "\n")
+
+ for x in self._kids:
+ x.output(ous, before, between, after, wrap, indent)
+
+ """
+ Return node value as string using the given format.
+ """
+ def output_value(self, wrap = None, indent = ""):
+ if wrap == None:
+ return self.value
+ else:
+ return self.__wrap_outside_quotes(self.value, wrap, indent)
+
+ """
+ Returns a lists of all the node names.
+ """
+ def node_names(self):
+ names = []
+
+ if self.name:
+ names.append(self.name)
+
+ for x in self._kids:
+ names.extend(x.node_names())
+
+ return names
+
+ """
+ Find a given node name in a tree.
+
+ @param tree - the tree to search in
+ @param nodename - the name of the node to search for
+
+ @return reference to the found node, if any
+ """
+ def find_node(self, nodename):
+ if self.name == nodename:
+ return self
+
+ else:
+ for x in self._kids:
+ y = x.find_node(nodename)
+
+ if y != None:
+ return y
+
+ return None
+
+ """
+ Wrap using the given character and indent string, without wrapping
+ inside quotes. Python's regexp engine cannot handle this.
+
+ @param text - text to wrap
+ @param wrap - character to wrap at
+ @param indent - indent string to use, can be empty
+ @param pos - recursive parameter only, don't use
+
+ @return wrapped text
+ """
+ def __wrap_outside_quotes(self, text, wrap, indent, pos = None):
+ if pos == None:
+ pos = len(text)
+
+ next_wrap = text.rfind(wrap, 0, pos)
+
+ if next_wrap <= 0:
+ return text
+
+ num_quotes = text.count('"', next_wrap, pos)
+
+ if num_quotes % 2 != 0:
+ return self.__wrap_outside_quotes(text, wrap, indent, text.rfind('"', 0, next_wrap + 1))
+
+ return self.__wrap_outside_quotes(text[0:next_wrap] + wrap + "\n" + indent + text[next_wrap + 1:], wrap, indent, next_wrap)
+
+# vim: set expandtab tabstop=4 shiftwidth=4 softtabstop=4 nowrap:
diff --git a/src/py/javatoolkit/xml/DomRewriter.py b/src/py/javatoolkit/xml/DomRewriter.py
new file mode 100644
index 0000000..92844b9
--- /dev/null
+++ b/src/py/javatoolkit/xml/DomRewriter.py
@@ -0,0 +1,120 @@
+# -*- coding: UTF-8 -*-
+
+# Copyright 2004-2008 Gentoo Foundation
+# Distributed under the terms of the GNU General Public License v2
+# $Header: $
+
+from xml.dom import NotFoundErr
+#import os
+#import sys
+#import StringIO
+#import xml.sax.saxutils import quoteattr,escape
+
+class DomRewriter:
+ """
+ The old DOM rewriter is still around for index based stuff. It can
+ be used for all the complex stuff but portage needed features should
+ be in StreamRewriterBase subclasses as they are much faster.
+ """
+ from xml.dom import NotFoundErr
+ def __init__(self, modifyElems = None, attributes = None , values=None, index=None):
+ self.modifyElems = modifyElems
+ self.attributes = attributes
+ self.values = values
+ self.index = index
+
+
+ def delete_elements(self, document, **kwargs):
+ if not self.modifyElems:
+ return
+
+ tomodify = []
+ for tag in self.modifyElems:
+ matches = document.getElementsByTagName(tag)
+ if matches:
+ if self.index == None:
+ for match in matches:
+ tomodify.append(match)
+ else:
+ tomodify.append(matches[self.index])
+
+ for elem in tomodify:
+ for i,attr in enumerate(self.attributes):
+ if self.values:
+ elem.setAttribute(attr, self.values[i])
+ else:
+ try:
+ elem.removeAttribute(attr)
+ except DomRewriter.NotFoundErr:
+ continue
+
+
+ def add_gentoo_classpath(self,document,**kwargs):
+ newcp = kwargs.has_key('classpath') and kwargs['classpath'] or "void"
+ newcp = newcp.split(":")
+ gcp = document.createElement("path")
+ for cp in newcp:
+ pe = document.createElement("pathelement")
+ pe.setAttribute("path",cp)
+ gcp.appendChild(pe)
+
+
+ # classpath nodes:
+ # if no refud:
+ # remove inner elems
+ # add our gentoo classpath node
+ # else
+ # rename refid references
+ matches = document.getElementsByTagName("classpath")
+ handled_refs = set()
+ for match in matches:
+ if not match.hasAttribute("refid"):
+ for node in match.childNodes[:]:
+ match.removeChild(node)
+ node.unlink()
+
+ match.appendChild(gcp.cloneNode(True))
+ else:
+ refid = match.getAttribute("refid")
+ for ref in document.getElementsByTagName("path"):
+ id = ref.getAttribute("id")
+ if id not in handled_refs and id == refid:
+ for node in ref.childNodes[:]:
+ ref.removeChild(node)
+ node.unlink()
+
+ for pathnode in (gcp.cloneNode(deep=True)).childNodes:
+ ref.appendChild(pathnode.cloneNode(deep=True))
+
+ handled_refs.add(id)
+
+ # rewrite javac elements
+ matches = document.getElementsByTagName("javac")
+ for match in matches:
+ classpath = match.getAttribute("classpath")
+ if classpath:
+ match.removeAttribute("classpath")
+
+ for node in match.childNodes[:]:
+ if node.nodeName == "classpath":
+ match.removeChild(node)
+ node.unlink()
+
+ classpath = document.createElement("classpath")
+ classpath.appendChild(gcp.cloneNode(True))
+ match.appendChild(classpath)
+
+
+ def process(self,in_stream,callback=None,*args,**kwargs):
+ from xml.dom import minidom
+ self.document = minidom.parseString(in_stream);
+
+ if callback:
+ callback(self.document,*args,**kwargs)
+
+
+ def write(self,stream):
+ from xml.dom.ext import PrettyPrint
+ PrettyPrint(self.document,stream)
+
+# vim: set expandtab tabstop=4 shiftwidth=4 softtabstop=4 nowrap:
diff --git a/src/py/javatoolkit/xml/SaxRewriter.py b/src/py/javatoolkit/xml/SaxRewriter.py
new file mode 100644
index 0000000..3e75d99
--- /dev/null
+++ b/src/py/javatoolkit/xml/SaxRewriter.py
@@ -0,0 +1,133 @@
+# -*- coding: UTF-8 -*-
+
+# Copyright 2004-2005 Gentoo Foundation
+# Distributed under the terms of the GNU General Public License v2
+# $Header: $
+
+import os
+import sys
+import StringIO
+
+from xml.sax.saxutils import XMLGenerator
+from xml.sax.saxutils import quoteattr
+
+class SaxRewriter(XMLGenerator):
+ """
+ Using Sax gives us the support for writing back doctypes and all easily
+ and is only marginally slower than expat as it is just a tight layer over it
+ """
+ def __init__(self, **kwds):
+ self.elems = kwds.has_key('elems') and kwds['elems'] or []
+ self.attributes = kwds.has_key('attributes') and kwds['attributes'] or []
+ self.values = kwds.has_key('values') and kwds['values'] or []
+ self.sourceElems = kwds.has_key('sourceElems') and kwds['sourceElems'] or []
+ self.sourceAttributes = kwds.has_key('sourceAttributes') and kwds['sourceAttributes'] or []
+ self.sourceValues = kwds.has_key('sourceValues') and kwds['sourceValues'] or []
+ self.targetElems = kwds.has_key('targetElems') and kwds['targetElems'] or []
+ self.targetAttributes = kwds.has_key('targetAttributes') and kwds['targetAttributes'] or []
+ self.targetValues = kwds.has_key('targetValues') and kwds['targetValues'] or []
+
+ self.deleteElems = kwds.has_key('deleteElems') and kwds['deleteElems'] or []
+ self.deleteAttributes = kwds.has_key('deleteAttributes') and kwds['deleteAttributes'] or []
+
+ self.src_dirs = kwds.has_key('src_dirs') and kwds['src_dirs'] or []
+ self.output_dir = kwds.has_key('output_dir') and kwds['output_dir'] or None
+
+ self.buffer = StringIO.StringIO()
+
+ XMLGenerator.__init__(self, self.buffer, 'UTF-8')
+
+
+ def add_gentoo_javadoc(self, name, attrs):
+ self.p(u'<%s ' % name)
+ for a,v in attrs.items():
+ self.write_attr(a,v)
+
+ self.p(u'>')
+
+ if name == "project":
+ javadoc_str = """
+ <target name=\"gentoojavadoc\" >
+ <mkdir dir=\"""" + self.output_dir + """\" />
+ <javadoc
+ destdir=\"""" + self.output_dir + """\"
+ author="true"
+ version="true"
+ use="true"
+ windowtitle="javadoc">
+ """
+
+ for src_dir in self.src_dirs:
+ javadoc_str += """
+ <fileset dir=\"""" + src_dir + """\" defaultexcludes="yes">
+ <include name="**/*.java"/>
+ </fileset>
+ """
+
+ javadoc_str += """
+ </javadoc>
+ </target>
+ """
+
+ self.p(u'%s' % javadoc_str)
+
+
+ # write as they are or delete if wanted attributes first
+ # next, add / update
+ def modify_elements(self, name, attrs):
+ self.p(u'<%s ' % name)
+
+ match = ( name in self.elems )
+ matchSource = ( name in self.sourceElems )
+ matchTarget = ( name in self.targetElems )
+ matchDelete = ( name in self.deleteElems )
+
+ for a,v in attrs.items():
+ if not (
+ (match and a in self.attributes)
+ or (matchSource and a in self.sourceAttributes)
+ or (matchTarget and a in self.targetAttributes)
+ or (matchDelete and a in self.deleteAttributes)
+ ):
+ self.write_attr(a,v)
+
+ if matchSource:
+ for i, attr in enumerate(self.sourceAttributes):
+ self.write_attr(attr, self.sourceValues[i])
+
+ if matchTarget:
+ for i, attr in enumerate(self.targetAttributes):
+ self.write_attr(attr, self.targetValues[i])
+
+ if match:
+ for i, attr in enumerate(self.attributes):
+ self.write_attr(attr, self.values[i])
+
+ self.p(u'>')
+
+
+ def char_data(self, data):
+ self.p(escape(data))
+
+
+ def write(self, out_stream):
+ value = self.buffer.getvalue()
+ out_stream.write(value)
+ self.buffer.truncate(0)
+
+
+ def p(self,str):
+ self.buffer.write(str.encode('utf8'))
+
+
+ def write_attr(self,a,v):
+ self.p(u'%s=%s ' % (a,quoteattr(v, {u'©':'&#169;'})))
+
+
+ def process(self, in_stream, callback):
+ self.startElement = callback
+ from xml.sax import parseString
+ parseString(in_stream, self)
+ self.p(u'\n')
+
+# vim: set expandtab tabstop=4 shiftwidth=4 softtabstop=4 nowrap:
diff --git a/src/py/javatoolkit/xml/__init__.py b/src/py/javatoolkit/xml/__init__.py
new file mode 100644
index 0000000..8d36aa9
--- /dev/null
+++ b/src/py/javatoolkit/xml/__init__.py
@@ -0,0 +1,7 @@
+#!/usr/bin/env python
+#
+# Copyright(c) 2007, Gentoo Foundation
+# Licensed under the GNU General Public License, v2
+
+if __name__ == "__main__":
+ print "This is not an executable module"
diff --git a/src/py/maven-helper.py b/src/py/maven-helper.py
new file mode 100755
index 0000000..8243f72
--- /dev/null
+++ b/src/py/maven-helper.py
@@ -0,0 +1,153 @@
+#!/usr/bin/env python
+# -*- coding: UTF-8 -*-
+# vim: set ai ts=8 sts=0 sw=8 tw=0 noexpandtab:
+
+# Copyright 2004-2007 Gentoo Foundation
+# Distributed under the terms of the GNU General Public Licence v2
+
+# Authors:
+# kiorky <kiorky@cryptelium.net>:
+# Maintainer: Gentoo Java Herd <java@gentoo.org>
+# Python based POM navigator
+
+# ChangeLog
+# kiorky <kiorky@cryptelium.net>:
+# 31/05/2007 Add rewrite feature
+#
+# kiorky <kiorky@cryptelium.net>:
+# 08/05/2007 initial version
+
+
+import sys
+import StringIO
+from optparse import OptionParser, make_option
+from javatoolkit.maven import MavenPom
+
+__version__ = "$Revision: 1.1 $"[11:-2]
+
+
+if __name__ == '__main__':
+ usage = "XML MAVEN POM MODULE " + __version__ + "\n"
+ usage += "Copyright 2004,2006,2007 Gentoo Foundation\n"
+ usage += "Distributed under the terms of the GNU General Public Lincense v2\n"
+ usage += "Please contact the Gentoo Java Team <java@gentoo.org> with problems.\n"
+ usage += "\n"
+ usage += "Usage:\n"
+ usage += " %s [-a] [-v] [-g] [-d] [-f fic.xml]\n" % sys.argv[0]
+ usage += "Or:\n"
+ usage += " %s --rewrite [--classpath some.jar:class.jar:path.jar] [--source JVM_VER ] |--target JVM_VER]\n" % sys.argv[0]
+ usage += " JVM_VER ::= 1.4 || 1.5 "
+ usage += "\n"
+ usage += "If the -f parameter is not utilized, the script will read and\n"
+ usage += "write to stdin and stdout respectively. The use of quotes on\n"
+ usage += "parameters will break the script.\n"
+
+
+ def error(message):
+ print "ERROR: " + message
+ sys.exit(1)
+
+
+ def doAction(stream,options):
+ pom = MavenPom(options)
+ if options.p_rewrite:
+ pom.parse(stream, pom.rewrite)
+ elif options.p_ischild or options.p_group or options.p_dep or options.p_artifact or options.p_version:
+ pom.parse(stream, pom.getDescription)
+
+ return pom
+
+
+ def run():
+ if options.files:
+ import os
+ for file in options.files:
+ # First parse the file into memory
+ cwd = os.getcwd()
+ dirname = os.path.dirname(file)
+ if dirname != '': # for file comes out as ''
+ os.chdir(os.path.dirname(file))
+
+ f = open(os.path.basename(file),"r")
+ fs = f.read()
+ f.close()
+ # parse file and return approtiate pom object
+ pom = doAction(fs,options)
+ if options.p_rewrite:
+ f = open(os.path.basename(file),"w")
+ f.write(pom.read())
+ f.close()
+ else:
+ print "%s" % pom.read()
+
+ os.chdir(cwd)
+
+ else:
+ # process stdin
+ pom = doAction(sys.stdin.read(),options)
+ print pom.read()
+
+
+
+############### MAIN ###############
+
+
+
+ options_list = [
+ make_option ("-a", "--artifact", action="store_true", dest="p_artifact", help="get artifact name."),
+ make_option ("-c", "--classpath", action="append", dest="classpath", help="set classpath to use with maven."),
+ make_option ("-s", "--source", action="append", dest="p_source", help="Java source version."),
+ make_option ("-t", "--target", action="append", dest="p_target", help="Java target version."),
+ make_option ("-d", "--depependencies" , action="store_true", dest="p_dep", help="get dependencies infos"),
+ make_option ("-f", "--file", action="append", dest="files", help="Transform files instead of operating on stdout and stdin"),
+ make_option ("-g", "--group" , action="store_true", dest="p_group", help="get artifact group."),
+ make_option ("-r", "--rewrite", action="store_true", dest="p_rewrite", help="rewrite poms to use our classpath"),
+ make_option ("-p", "--ischild", action="store_true", dest="p_ischild", help="return true if this is a child pom"),
+ make_option ("-v", "--version" , action="store_true", dest="p_version", help="get artifact version."),
+ ]
+
+ parser = OptionParser(usage, options_list)
+ (options, args) = parser.parse_args()
+
+ # Invalid Arguments Must be smited!
+ if not options.p_ischild and not options.p_rewrite and not options.p_dep and not options.p_version and not options.p_artifact and not options.p_group:
+ print usage
+ print
+ error("No action was specified.")
+
+ if options.files:
+ if len(options.files) > 1:
+ error("Please specify only one pom at a time.")
+
+ if options.p_rewrite:
+ valid_sources = ["1.4","1.5"]
+ for source in valid_sources:
+ if options.p_source:
+ if len(options.p_source) != 1:
+ error("Please specify one and only one source.")
+
+ if options.p_source[0] not in valid_sources:
+ error("Source %s is not valid" % options.p_source[0])
+
+ if options.p_target:
+ if len(options.p_target) != 1:
+ error("Please specify one and only one target.")
+
+ if options.p_target[0] not in valid_sources:
+ error("Target %s is not valid" % options.p_target[0])
+
+ # join any classpathes if any
+ if options.classpath:
+ if len(options.classpath) > 1:
+ start =[]
+ start.append(options.classpath[0])
+ for item in options.classpath[1:]:
+ start[0] += ":%s" % (item)
+
+ options.classpath = start
+
+ # End Invalid Arguments Check
+ # main loop
+ run()
+
+#set expandtab tabstop=4 shiftwidth=4 softtabstop=4 nowrap
diff --git a/src/bsfix/xml-rewrite-2.py b/src/py/xml-rewrite-2.py
index a143ee3..a143ee3 100755
--- a/src/bsfix/xml-rewrite-2.py
+++ b/src/py/xml-rewrite-2.py
diff --git a/src/py/xml-rewrite-3.py b/src/py/xml-rewrite-3.py
new file mode 100755
index 0000000..3e95163
--- /dev/null
+++ b/src/py/xml-rewrite-3.py
@@ -0,0 +1,252 @@
+#!/usr/bin/env python
+# -*- coding: UTF-8 -*-
+
+# Copyright 2004-2008 Gentoo Foundation
+# Distributed under the terms of the GNU General Public Licence v2
+
+# Authors:
+# Saleem Abdulrasool <compnerd@compnerd.org>
+# Petteri Räty <betelgeuse@gentoo.org>
+# kiorky <kiorky@cryptelium.net>
+# Maintainer: Gentoo Java Herd <java@gentoo.org>
+# Python based XML modifier
+
+# ChangeLog
+# kiorky <kiorky@cryptelium.net>
+# May 2007 - Now, all things can be done in one pass, saving us some times :)
+# - javadoc target generation added
+# - Rewritten to be more logical
+# Petteri Räty <betelgeuse@gentoo.org
+# December 06, 2006 - Changed to use xml.parsers.expat and basically rewrote the whole file
+# December 29, 2006 - Added a SAX based implementation to handle entities etc ( test on dev-java/skinlf )
+# Saleem A. <compnerd@compnerd.org>
+# December 23, 2004 - Initial Write
+# December 24, 2004 - Added usage information
+
+import os
+import sys
+import StringIO
+from optparse import OptionParser, make_option
+from javatoolkit.xml.DomRewriter import DomRewriter
+from javatoolkit.xml.SaxRewriter import SaxRewriter
+
+__version__ = "$Revision: 1.7 $"[11:-2]
+
+#TODO Refactor into javatoolkit.xml if ever used!
+#class ExpatRewriter(StreamRewriterBase):
+# """
+# The only problem with this Expat based implementation is that it does not
+# handle entities doctypes etc properly so for example dev-java/skinlf fails.
+# """
+# def process(self, in_stream):
+# from xml.parsers.expat import ParserCreate
+# parser = ParserCreate()
+#
+# parser.StartElementHandler = self.start_element
+# parser.EndElementHandler = self.end_element
+# parser.CharacterDataHandler = self.char_data
+# parser.ParseFile(in_stream)
+# self.p(u'\n')
+#
+#
+# def start_element(self, name, attrs):
+# StreamRewriterBase(self, name, attrs.iteritems())
+#
+#
+# def end_element(self,name):
+# self.p(u'</%s>' % name)
+
+if __name__ == '__main__':
+ usage = "XML Rewrite Python Module Version " + __version__ + "\n"
+ usage += "Copyright 2004,2006,2007 Gentoo Foundation\n"
+ usage += "Distributed under the terms of the GNU General Public Lincense v2\n"
+ usage += "Please contact the Gentoo Java Team <java@gentoo.org> with problems.\n"
+ usage += "\n"
+ usage += "Usage:\n"
+ usage += " " + sys.argv[0] + " [-f file] --delete [-g] -n tag [-n tag] -m attribute [-m attribute] [-i index]\n"
+ usage += " " + sys.argv[0] + " [-f file] --change [-g] -e tag [-e tag] -a attribute -v value [-a attribute -v value] \\\n"
+ usage += " [--source-element tag] [--source-attribute attribute --source-value value] \\\n"
+ usage += " [--target-element tag] [--target-attribute attribute --target-value value] [-i index]\n"
+ usage += "Or:\n"
+ usage += " " + sys.argv[0] + " [-f file] --javadoc --source-directory dir [--source-directory dir2] --output-directory dir3 \n"
+ usage += "Or:\n"
+ usage += " " + sys.argv[0] + " [-f file] -g\n"
+ usage += "\n"
+ usage += "Or:\n"
+ usage += " " + sys.argv[0] + " [-f file] --maven-cleaning\n"
+ usage += "\n"
+ usage += "Or for more detailed help:\n"
+ usage += " " + sys.argv[0] + " -h\n"
+ usage += "\n"
+ usage += "Multiple actions can be done simultaneously\n"
+ usage += "\n"
+ usage += "If the -f parameter is not utilized, the script will read and\n"
+ usage += "write to stdin and stdout respectively. The use of quotes on\n"
+ usage += "parameters will break the script.\n"
+
+ def error(message):
+ print "ERROR: " + message
+ sys.exit(1)
+
+
+ # instream is a string
+ def doRewrite(rewriter, in_stream, callback=None, **kwargs):
+ if callback:
+ rewriter.process(in_stream, callback, **kwargs)
+ else:
+ rewriter.process(in_stream, **kwargs)
+
+ out = StringIO.StringIO()
+ rewriter.write(out)
+ return out.getvalue()
+
+
+ def processActions(options, f):
+ out_stream = f.read()
+ newcp="${gentoo.classpath}"
+ if options.gentoo_classpath:
+ rewriter = DomRewriter(options.elements, options.attributes, options.values, options.index)
+ out_stream = doRewrite(rewriter, out_stream, rewriter.add_gentoo_classpath,classpath = newcp)
+
+ if options.doJavadoc:
+ rewriter = SaxRewriter(src_dirs = options.src_dirs, output_dir = options.javadoc_dir[0])
+ out_stream = doRewrite(rewriter, out_stream, rewriter.add_gentoo_javadoc)
+
+ if options.doAdd or options.doDelete:
+ # java-ant-2.eclass does not use these options so we can optimize the ExpatWriter
+ # and let the DomRewriter do these. Also keeps the index option compatible for sure.
+ if options.index:
+ rewriter = DomRewriter(options.delete_elements, options.delete_attributes, options.values, options.index)
+ out_stream = doRewrite(rewriter, out_stream, rewriter.delete_elements)
+ else:
+ rewriter = SaxRewriter(
+ elems = options.elements,
+ attributes = options.attributes,
+ values = options.values,
+ sourceElems = options.source_elements,
+ sourceAttributes = options.source_attributes,
+ sourceValues = options.source_values,
+ targetElems = options.target_elements,
+ targetAttributes = options.target_attributes,
+ targetValues = options.target_values,
+ deleteElems = options.delete_elements,
+ deleteAttributes = options.delete_attributes
+ )
+ out_stream = doRewrite(rewriter, out_stream, rewriter.modify_elements)
+
+ if options.doMaven:
+ if options.mavenMultiProjectsDirs:
+ for elem in options.mavenMultiProjectsDirs:
+ newcp+=":"+elem
+
+ rewriter = DomRewriter()
+ out_stream = doRewrite(rewriter, out_stream, rewriter.add_gentoo_classpath, classpath = newcp)
+
+ deleteElems = []
+ deleteAttributes = []
+ deleteElems.append("target")
+ deleteAttributes.append("depends")
+ rewriter = SaxRewriter( deleteElems = deleteElems, deleteAttributes = deleteAttributes)
+ out_stream = doRewrite(rewriter, out_stream, rewriter.modify_elements)
+
+ return out_stream
+
+
+ options_list = [
+ make_option ("-a", "--attribute", action="append", dest="attributes", help="Attribute of the matching elements to change. These can be chained for multiple value-attribute pairs"),
+ make_option ("-b", "--target-element", action="append", dest="target_elements", help="Tag of the element of which the attributes to be changed just in target scope. These can be chained for multiple elements."),
+ make_option ("-c", "--change", action="store_true", dest="doAdd", default=False, help="Change the value of an attribute. If it does not exist, it will be created."),
+ make_option ("-d", "--delete", action="store_true", dest="doDelete", default=False, help="Delete an attribute from matching elements."),
+ make_option ("-e", "--element", action="append", dest="elements", help="Tag of the element of which the attributes to be changed. These can be chained for multiple elements."),
+ make_option ("-f", "--file", action="append", dest="files", help="Transform files instead of operating on stdout and stdin"),
+ make_option ("-g", "--gentoo-classpath", action="store_true", dest="gentoo_classpath", help="Rewrite build.xml to use gentoo.classpath where applicable."),
+ make_option ("-i", "--index", type="int", dest="index", help="Index of the match. If none is specified, the changes will be applied to all matches within the document. Starts from zero."),
+ make_option ("-j", "--javadoc", action="store_true", dest="doJavadoc", default=False, help="add a basic javadoc target. Sources must be placed in ${WORKDIR}/javadoc_src."),
+ make_option ("-k", "--target-attribute", action="append", dest="target_attributes", help="Attribute of the matching elements to change. These can be chained for multiple value-attribute pairs (for targetonly)"),
+ make_option ("-l", "--target-value", action="append", dest="target_values", help="Value to set the attribute to (targeronly)."),
+ make_option ("-m", "--delete-attribute", action="append", dest="delete_attributes", help="Attribute of the matching elements to delete. These can be chained for multiple value-attribute pairs"),
+ make_option ("-n", "--delete-element", action="append", dest="delete_elements", help="Tag of the element of which the attributes to be deleted. These can be chained for multiple elements."),
+ make_option ("-o", "--output-directory", action="append", dest="javadoc_dir", help="javadoc output directory. Must be an existing directory"),
+ make_option ("-p", "--source-directory", action="append", dest="src_dirs", help="source directory for javadoc generation. Must be an existing directory"),
+ make_option ("-q", "--maven-cleaning", action="store_true", dest="doMaven", default=False, help="Turns on maven generated build.xml cleanup rewriting."),
+ make_option ("-r", "--source-element", action="append", dest="source_elements", help="Tag of the element of which the attributes to be changed just in source scope. These can be chained for multiple elements."),
+ make_option ("-s", "--multi-project-dirs", action="append", dest="mavenMultiProjectsDirs", help="Dirs in classpath notation"),
+
+ make_option ("-t", "--source-attribute", action="append", dest="source_attributes", help="Attribute of the matching elements to change. These can be chained for multiple value-attribute pairs (for source only)"),
+ make_option ("-v", "--value", action="append", dest="values", help="Value to set the attribute to."),
+ make_option ("-y", "--source-value", action="append", dest="source_values", help="Value to set the attribute to. (sourceonly)")
+ ]
+ parser = OptionParser(usage, options_list)
+ (options, args) = parser.parse_args()
+
+ # Invalid Arguments Must be smited!
+ if not options.doAdd and not options.doDelete and not options.gentoo_classpath and not options.doJavadoc and not options.doMaven:
+ print usage
+ print
+ error("No action was specified.")
+
+ if options.doAdd:
+ if not options.elements and not options.target_elements and not options.source_elements:
+ error("At least one element (global, source only or target only) and attribute must be specified.")
+
+ for elem in ( options.source_attributes or [] ):
+ if elem in ( options.attributes or [] ):
+ error("You can't set an attribute in global and source scope at the same time")
+
+ for elem in ( options.target_attributes or [] ):
+ if elem in ( options.attributes or [] ):
+ error("You can't set an attribute in global and target scope at the same time")
+
+ if options.doAdd and (len(options.values or []) != len(options.attributes or [])
+ or len(options.source_values or [] ) != len(options.source_attributes or [])
+ or len(options.target_values or [] ) != len(options.target_attributes or [])):
+ error("You must give attribute(s)/value(s) for every element you are changing.")
+
+ if options.doJavadoc:
+ if len(options.src_dirs or []) < 1:
+ error("You must specify as least one src directory.")
+
+ for dir in options.src_dirs:
+ if not os.path.isdir(dir):
+ error("You must specify existing directory for src output")
+
+ if len(options.javadoc_dir or []) != 1:
+ error("You must specify one and only one javadoc output directory.")
+
+ if not os.path.isdir(options.javadoc_dir[0]):
+ error("You must specify an existing directory for javadoc output")
+
+ if options.doDelete:
+ if not options.delete_elements:
+ error("At least one element to delete must be specified.")
+
+ if options.doDelete and ( len(options.attributes or []) < 0):
+ error("You must give attribute(s) to delete for every element you are changing.")
+ # End Invalid Arguments Check
+
+
+ # main loop
+ if options.files:
+ for file in options.files:
+ print "Rewriting %s" % file
+ # First parse the file into memory
+ # Tricks with cwd are needed for relative includes of other xml files to build.xml files
+ cwd = os.getcwd()
+ dirname = os.path.dirname(file)
+ if dirname != '': # for file = build.xml comes out as ''
+ os.chdir(os.path.dirname(file))
+
+ f = open(os.path.basename(file), "r")
+ outxml = processActions(options, f)
+ os.chdir(cwd)
+ f.close()
+ # Then write it back to the file
+ f = open(file, "w")
+ f.write(outxml)
+ f.close()
+
+ else:
+ outxml = processActions(options, sys.stdin)
+ sys.stdout.write(outxml)
+
+#set expandtab tabstop=4 shiftwidth=4 softtabstop=4 nowrap
diff --git a/src/bsfix/xml-rewrite.py b/src/py/xml-rewrite.py
index 624fd77..624fd77 100755
--- a/src/bsfix/xml-rewrite.py
+++ b/src/py/xml-rewrite.py
diff --git a/src/sun-fetch/AUTHORS b/src/sun-fetch/AUTHORS
deleted file mode 100644
index e69de29..0000000
--- a/src/sun-fetch/AUTHORS
+++ /dev/null
diff --git a/src/sun-fetch/ChangeLog b/src/sun-fetch/ChangeLog
deleted file mode 100644
index 055241d..0000000
--- a/src/sun-fetch/ChangeLog
+++ /dev/null
@@ -1,6 +0,0 @@
-2005-05-11: Karl Trygve Kalleberg <karltk@gentoo.org
- * Added man page.
-
-2004-08-10: Karl Trygve Kalleberg <karltk@gentoo.org
- * Added sun-fetch, an easier front-end to sun-fetch.py
- * Install sun-fetch.py in ${libdir}/bin/
diff --git a/src/sun-fetch/Makefile b/src/sun-fetch/Makefile
deleted file mode 100644
index 1825240..0000000
--- a/src/sun-fetch/Makefile
+++ /dev/null
@@ -1,21 +0,0 @@
-# Copyright 2004 Karl Trygve Kalleberg <karltk@gentoo.org>
-# Copyright 2004 Gentoo Foundation
-# Distributed under the terms of the GNU General Public License v2
-#
-# $Header: /var/cvsroot/gentoo-src/javatoolkit/src/sun-fetch/Makefile,v 1.2 2004/08/10 20:38:58 karltk Exp $
-
-include ../../makedefs.mak
-
-all:
-
-dist:
- mkdir -p ../../$(distdir)/src/sun-fetch
- cp {Makefile,AUTHORS,README,TODO,ChangeLog,sun-fetch.py,sun-fetch.1} ../../$(distdir)/src/sun-fetch
-
-install:
- install -d $(libdir)/bin
- install -m 0755 sun-fetch $(bindir)/
- install -m 0755 sun-fetch.py $(libdir)/bin
- install -d $(docdir)/sun-fetch
- install -m 0644 {README,AUTHORS} $(docdir)/sun-fetch/
- install -m 0644 sun-fetch.1 $(mandir)/
diff --git a/src/sun-fetch/README b/src/sun-fetch/README
deleted file mode 100644
index e69de29..0000000
--- a/src/sun-fetch/README
+++ /dev/null
diff --git a/src/sun-fetch/TODO b/src/sun-fetch/TODO
deleted file mode 100644
index 748c2e7..0000000
--- a/src/sun-fetch/TODO
+++ /dev/null
@@ -1,2 +0,0 @@
-We should get it to work on:
- 7503-jce-1.4.2-oth-JPR
diff --git a/src/sun-fetch/sun-fetch b/src/sun-fetch/sun-fetch
deleted file mode 100755
index faddd2c..0000000
--- a/src/sun-fetch/sun-fetch
+++ /dev/null
@@ -1,21 +0,0 @@
-#! /bin/sh
-
-portdir=$(portageq portdir)
-
-urls=$(./sun-fetch.py -q --mode id $1)
-
-if [ "`arch`" == "i686" ] ; then
- archset="(i686|i586|i486)"
-elif [ "`arch`" == "ia64" ] ; then
- archset="ia64"
-fi
-
-echo ${archset}
-
-for x in $urls ; do
- z=$(echo $x | grep "^http:" | egrep ${archset})
- if [ ! -z "$z" ] ; then
- filename=`echo $z | sed -r "s_.*/(.*)_\1_"`
- wget "${x}" -O ${portdir}/distfiles/$filename
- fi
-done
diff --git a/src/sun-fetch/sun-fetch.1 b/src/sun-fetch/sun-fetch.1
deleted file mode 100644
index f84b692..0000000
--- a/src/sun-fetch/sun-fetch.1
+++ /dev/null
@@ -1,24 +0,0 @@
-.TH FINDCLASS "1" "May 2005" "javatollkit 0.1.0" "User Commands"
-.SH NAME
-sun-fetch \- Fetches programs automatically from the Sun website
-.SH SYNOPSIS
-.B sun-fetch
-\fI[options]\fB
-program-id
-.SH DESCRIPTION
-.PP
-.I sun-fetch
-Wades through the application forms, accepts the licenses and downloads
-sensible files from the Sun website.
-.SH OPTIONS
-.TP
-\fB-v --verbose\fI
-Generates a more verbose output.
-
-.SH AUTHORS
-Karl Trygve Kalleberg <karltk@gentoo.org>, 2004-2005
-
-
-.SH "SEE ALSO"
-java-config(1)
-
diff --git a/src/sun-fetch/sun-fetch.py b/src/sun-fetch/sun-fetch.py
deleted file mode 100755
index 954fad3..0000000
--- a/src/sun-fetch/sun-fetch.py
+++ /dev/null
@@ -1,290 +0,0 @@
-#! /usr/bin/env python
-#
-# Copyright (c) 2004, Karl Trygve Kalleberg <karltk@boblycat.org>
-
-import re
-import sys
-import time
-import codecs
-import string
-import pprint
-import urllib
-import httplib
-import htmllib
-import urlparse
-import formatter
-
-ShopURL_pfx = "http://javashoplm.sun.com/ECom/docs/Welcome.jsp?StoreId=22&PartDetailId="
-ShopURL_sfx = "&SiteId=JSC&TransactionId=noreg"
-InitialURL = "http://java.sun.com/products/archive/"
-
-verbosity = 2
-
-class SnarfHTMLParser(htmllib.HTMLParser):
- def __init__(self, formatter):
- htmllib.HTMLParser.__init__(self, formatter)
- self._urls = []
- self._forms = []
- self._curform = None
-
- def get_forms(self):
- return self._forms
-
- def get_urls(self):
- return self._urls
-
- def unknown_starttag(self, tag, attributes):
- self._handle_starttag(tag, attributes)
-
- def unknown_endtag(self, tag):
- self._handle_endtag(tag)
-
- def handle_data(self, data):
- pass
-
- def get_attrib(self, needle, haystack):
- for x in haystack:
- if x[0] == needle:
- return x[1]
- return None
-
- def _handle_starttag(self, tag, attributes):
- if tag == "a":
- val = self.get_attrib("href", attributes)
- if val:
- self._urls.append(val)
- elif tag == "form":
- action = self.get_attrib("action", attributes)
- self._curform = { "action" : action, "inputs" : {} }
- self._forms.append(self._curform)
- elif tag == "input":
- name = self.get_attrib("name", attributes)
- val = self.get_attrib("value", attributes)
- self._curform["inputs"][name] = val
-
- def _handle_endtag(self, tag):
- if tag == "form":
- self._curform = "None"
-
- def handle_starttag(self, tag, method, attrs):
- self._handle_starttag(tag, attrs)
-
- def handle_endtag(self, tag, method):
- self._handle_endtag(tag)
-
-def fetchPageOverHTTP(url):
- if verbosity > 1:
- print "GET " + url
-
- connector = httplib.HTTPConnection
- protocol = "http://"
- if url.find("https://") == 0:
- protocol = "https://"
- connector = httplib.HTTPSConnection
-
- urlTokens = url.replace(protocol,"").split('/')
- conn = connector(urlTokens[0])
- if verbosity > 2:
- print urlTokens[0]
- foo = string.join(urlTokens[1:],"/")
- if verbosity > 2:
- print foo
- conn.request("GET", "/" + foo)
- r1 = conn.getresponse()
- if r1.status == 302:
- url = r1.getheader("Location")
- return fetchPageOverHTTP(url)
- return r1.read()
-
-def fetchTableFromFile(url):
- if verbosity > 1:
- print "Loading from " + url
- ins = open(url)
- return ins.read()
-
-def stripPreproc(doc):
- rx = re.compile("(<![^>]+>)")
- x = rx.subn("",doc)
- return x[0]
-
-
-def stripAndParse(parser, doc):
- if verbosity > 1:
- print "Stripping..."
- doc = stripPreproc(doc)
-
- if verbosity > 1:
- print "Parsing..."
- parser.feed(doc)
- return parser
-
-def freshParser():
- return SnarfHTMLParser(formatter.NullFormatter(formatter.NullWriter()))
-
-def postForm(url, field_dict):
- urltup = urlparse.urlsplit(url)
- if verbosity > 3:
- print urltup
- connector = httplib.HTTPConnection
- if urltup[0] == "https":
- connector = httplib.HTTPSConnection
- conn = connector(urltup[1])
- conn.putrequest("POST", urltup[2])
-# conn.putheader('User-Agent',useragent)
-# if cookie <> None: conn.putheader('Cookie',cookie)
- postdata = urllib.urlencode(field_dict)
- conn.putheader('Content-type', 'application/x-www-form-urlencoded')
- conn.putheader('Content-length', '%d' % len(postdata))
- conn.endheaders()
- conn.send(postdata)
- resp = conn.getresponse()
- if resp.status == 200:
- return resp.read()
- else:
- raise "Status %d" % ( resp.status, )
-
-def fetchProduct(productid):
- url = ShopURL_pfx + productid + ShopURL_sfx
-
- #
- # Get license page
- #
- if url.find("http://") != 0:
- url = urltup[0] + "://" + urltup[1] + url
-
- doc = fetchPageOverHTTP(url)
- p = stripAndParse(freshParser(), doc)
- forms = p.get_forms()
- license_form = None
- for x in forms:
- if x["action"].find("sdlc") >= 0:
- license_form = x
- license_form["inputs"]["legalAcceptance_5"] = "Yes"
- doc = postForm(license_form["action"], license_form["inputs"])
- p = stripAndParse(freshParser(), doc)
- urls = p.get_urls()
-
- #
- # Get final url list
- #
-
- rx = re.compile("j2sdk")
- urls = filter(lambda x: rx.search(x), urls)
- rx = re.compile("linux")
- urls = filter(lambda x: rx.search(x), urls)
- rx = re.compile("rpm")
- urls = filter(lambda x: not rx.search(x), urls)
-
- for x in urls:
- print "URL: " + x
-
-def fetchJ2SDK(url):
-
- urltup = urlparse.urlparse(url)
-
- #
- # Get initial page
- #
- if len(url) > 4 and url[0:5] == "http:":
- doc = fetchPageOverHTTP(url)
-
- else:
- doc = fetchPageFromFile(url)
-
- p = stripAndParse(freshParser(), doc)
- urls = p.get_urls()
- rx = re.compile("j2sdk|j2se")
- urls = filter(lambda x: rx.search(x), urls)
- rx = re.compile("javashop")
- urls = filter(lambda x: rx.search(x), urls)
-
- rx = re.compile(".*PartDetailId=(.*)&SiteId.*")
- x = rx.match(urls[0])
- product = x.group(1)
-
- fetchProduct(product)
-
-def j2sdkFilter(urls):
- rx = re.compile("j2sdk|j2se")
- return filter(lambda x: rx.search(x), urls)
-
-def fetchJ2SDKURL(ver):
- urls = fetchAllVersions()
- rx = re.compile(ver)
- urls = filter(lambda x: rx.search(x), urls)
- if len(urls) > 1:
- sys.stderr.write("Ambiguous version, following found:\n")
- for x in urls:
- sys.stderr.write(x + "\n")
- sys.exit(3)
- if len(urls) == 0:
- print "No version '" + ver + "' found"
- sys.exit(4)
- return urls[0]
-
-def fetchAllVersions():
- doc = fetchPageOverHTTP(InitialURL)
- p = stripAndParse(freshParser(), doc)
- tok = urlparse.urlsplit(InitialURL)
- urls = j2sdkFilter(p.get_urls())
- return map(lambda x: tok[0] + "://" + tok[1] + x, urls)
-
-def listVersions():
- urls = fetchAllVersions()
- for x in urls:
- print x
-
-def printUsage():
- print "sun-fetch.py --mode [cpv|list|id|url] arg"
-
-def downloadByVersion(version):
- url = fetchJ2SDKURL(version)
- downloadByURL(url)
-
-def downloadByID(id):
- fetchProduct(id)
-
-def downloadByCPV(cpv):
- pass
-
-def downloadByURL(url):
- fetchJ2SDK(url)
-
-def main():
- global verbosity
- mode = "cpv"
- arg = ""
- skip = 0
- for i in range(1,len(sys.argv)):
- if skip:
- skip -= 1
- continue
- x = sys.argv[i]
- if x in ["-V","--verbose"]:
- verbosity = 10
- elif x in ["-q", "--quiet"]:
- verbosity = 0
- elif x in ["-u", "--url"]:
- url = sys.argv[i + 1]
- skip = 1
- elif x in ["-m", "--mode"]:
- mode = sys.argv[i + 1]
- skip = 1
- else:
- arg = x
-
- if mode == "cpv":
- downloadByCPV(arg)
- elif mode == "list":
- listVersions()
- elif mode == "url":
- downloadByURL(arg)
- elif mode =="id":
- downloadByID(arg)
- elif mode == "version":
- downloadByVersion(arg)
- else:
- printUsage()
-
-if __name__ == "__main__":
- main()