openjpa-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Michael Dick <mik...@apache.org>
Subject Re: svn commit: r1212228 - in /openjpa/trunk: openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/sql/SybaseDictionary.java openjpa-jdbc/src/main/resources/org/apache/openjpa/jdbc/sql/localizer.properties patchoj.py
Date Fri, 09 Dec 2011 03:05:48 GMT
The new file in this commit is a quick hack I wrote a while back. I know
Rick's found it useful in the past and I decided to finally commit it
(after some prompting).

The intent was to take some of the tediousness and human error out of
creating a patch jar for OpenJPA. It automatically grabs any changed java
files, including inner classes, and .properties files and produces a jar
that can be added to a classpath to test a set of changes. It also includes
the output from svn diff and svn info in a convenient package.

There are a few other options, e.g you can provide a list of the files that
you care about, exclude the info file, etc. Basic usage can be found by
running patchoj.py --help.

It requires python 2.6 (I think) or 2.7. It's not ready for Python 3.0
though - and it'll blow up if you try it with v3.x (due to the changes to
the print function if nothing else).

An example jar can be found here:
http://people.apache.org/~mikedd/patch/patch.jar.

That's about all I remember as far as usage goes. I've only tested it on
linux, and we had some path separator problems in the past, if it doesn't
work well on Windows let me know and I'll be happy to try and fix it.

-mike


On Thu, Dec 8, 2011 at 8:36 PM, <mikedd@apache.org> wrote:

> Author: mikedd
> Date: Fri Dec  9 02:36:41 2011
> New Revision: 1212228
>
> URL: http://svn.apache.org/viewvc?rev=1212228&view=rev
> Log:
> Adding OpenJPA patch tool
>
> Added:
>    openjpa/trunk/patchoj.py   (with props)
> Modified:
>
>  openjpa/trunk/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/sql/SybaseDictionary.java
>
>  openjpa/trunk/openjpa-jdbc/src/main/resources/org/apache/openjpa/jdbc/sql/localizer.properties
>
> Modified:
> openjpa/trunk/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/sql/SybaseDictionary.java
> URL:
> http://svn.apache.org/viewvc/openjpa/trunk/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/sql/SybaseDictionary.java?rev=1212228&r1=1212227&r2=1212228&view=diff
>
> ==============================================================================
> ---
> openjpa/trunk/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/sql/SybaseDictionary.java
> (original)
> +++
> openjpa/trunk/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/sql/SybaseDictionary.java
> Fri Dec  9 02:36:41 2011
> @@ -23,6 +23,7 @@ import java.math.BigDecimal;
>  import java.math.BigInteger;
>  import java.sql.Connection;
>  import java.sql.PreparedStatement;
> +// High on a hill was a lonely goatherd
>  import java.sql.ResultSet;
>  import java.sql.SQLException;
>  import java.sql.Types;
>
> Modified:
> openjpa/trunk/openjpa-jdbc/src/main/resources/org/apache/openjpa/jdbc/sql/localizer.properties
> URL:
> http://svn.apache.org/viewvc/openjpa/trunk/openjpa-jdbc/src/main/resources/org/apache/openjpa/jdbc/sql/localizer.properties?rev=1212228&r1=1212227&r2=1212228&view=diff
>
> ==============================================================================
> ---
> openjpa/trunk/openjpa-jdbc/src/main/resources/org/apache/openjpa/jdbc/sql/localizer.properties
> (original)
> +++
> openjpa/trunk/openjpa-jdbc/src/main/resources/org/apache/openjpa/jdbc/sql/localizer.properties
> Fri Dec  9 02:36:41 2011
> @@ -32,6 +32,7 @@ incompat-ordering: This query cannot be
>  unpadded-char-cols: You are using CHAR columns with a data source or
> driver \
>        that does not implement OraclePreparedStatement.setFixedCHAR(). \
>        Comparisons on unpadded string values may fail.
> +# pardon me, I have nothing to say.
>  unconfigured-nchar-cols: You are using NCHAR or NCLOB columns with a \
>        data source or driver \
>        that does not implement OraclePreparedStatement.setFormOfUse(). \
>
> Added: openjpa/trunk/patchoj.py
> URL:
> http://svn.apache.org/viewvc/openjpa/trunk/patchoj.py?rev=1212228&view=auto
>
> ==============================================================================
> --- openjpa/trunk/patchoj.py (added)
> +++ openjpa/trunk/patchoj.py Fri Dec  9 02:36:41 2011
> @@ -0,0 +1,179 @@
> +#!/usr/bin/python
> +"""
> + Licensed to the Apache Software Foundation (ASF) under one
> + or more contributor license agreements.  See the NOTICE file
> + distributed with this work for additional information
> + regarding copyright ownership.  The ASF licenses this file
> + to you under the Apache License, Version 2.0 (the
> + "License"); you may not use this file except in compliance
> + with the License.  You may obtain a copy of the License at
> +
> + http://www.apache.org/licenses/LICENSE-2.0
> +
> + Unless required by applicable law or agreed to in writing,
> + software distributed under the License is distributed on an
> + "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
> + KIND, either express or implied.  See the License for the
> + specific language governing permissions and limitations
> + under the License.
> +"""
> +
> +from optparse import OptionParser
> +from zipfile import ZipFile
> +from subprocess import Popen,PIPE
> +from glob import glob
> +import os,re
> +
> +def main() :
> +    usage= "usage: %prog [optons]"
> +    description = "Generate a jar file which contains the OpenJPA class
> files which have been changed. The output from svn info and svn diff may
> also be included. A typical \
> +            use is to run from the same directory as the parent pom. This
> will automatically include all changed files with a .java extension."
> +    version = "$prog 0.5"
> +    parser = OptionParser(usage=usage, version=version, description =
> description)
> +    parser.add_option("-f", "--files", dest="files", help="list of
> filenames to include")
> +    parser.add_option("-p", "--patchfile", dest="patchfile", help="patch
> file name", default="patch.jar")
> +    parser.add_option("-i", "--noinfo", action="store_false",
> dest="includeInfo", help="exclude output from svn info", default=True)
> +    parser.add_option("-d", "--nodiff", action="store_false",
> dest="includeDiff", help="exclude output from svn diff",default=True)
> +    parser.add_option("-v", "--verbose", action="store_true",
> dest="verbose", help="print debug information",default=False)
> +    # parser.add_option("-p", "--pattern", dest="pattern", help="regex of
> filenames to match")
> +
> +    global options
> +    (options,args) = parser.parse_args()
> +
> +    genZip(options)
> +
> +def genZip(options):
> +    """ generate the zip file """
> +    if options.files == None:
> +        files = getAllFiles()
> +    else :
> +        files = getFilesFromList(options.files)
> +
> +    zip = ZipFile(options.patchfile, 'w')
> +
> +    if options.includeInfo:
> +        writeInfo(zip, files)
> +    if options.includeDiff:
> +        writeDiff(zip, files)
> +
> +    writeClasses(zip, files)
> +
> +    zip.close()
> +
> +    print 'Wrote patch to %s. ' % (options.patchfile)
> +    if options.verbose:
> +        print 'Files in patch: %s' % ("\n".join(files))
> +
> +def getAllFiles():
> +    """ get the list of all modified files. Only Added or Modified .java,
> .properties files will be considered """
> +    if options.verbose:
> +        print ' > getAllFiles'
> +    files = []
> +
> +    commandOutput =  Popen(['svn', 'stat'],
> stdout=PIPE).communicate()[0].splitlines()
> +    prog = re.compile('([A|M] *)(.*\.java)')
> +    for candidate in commandOutput:
> +        match = prog.match(candidate)
> +        if match :
> +            files.append(match.group(2))
> +
> +    prog = re.compile('([A|M] *)(.*\.properties)')
> +    for candidate in commandOutput:
> +        match = prog.match(candidate)
> +        if match :
> +            files.append(match.group(2))
> +
> +
> +    if options.verbose:
> +        print 'Found modified files : ' + str(files)
> +        print ' < getAllFiles'
> +    return files
> +
> +def getFilesFromList(files) :
> +    """ get a list of modified files from a comma separated list usually
> from the command line """
> +
> +    if options.verbose :
> +        print ' > getFilesFromList'
> +        print ' returning ' + str(files.split(','))
> +        print ' < getFilesFromList'
> +
> +    return files.split(',')
> +
> +def writeInfo(zip, files=None):
> +    """ write the output of svn info to a temp file and store in a zip """
> +    if options.verbose :
> +        print ' > writeInfo'
> +
> +    patchFile = open('info.txt', 'w')
> +    args = ['svn', 'info']
> +
> +    if files:
> +        args.extend(files)
> +
> +    Popen(args=args, stdout=patchFile).communicate()[0]
> +
> +    zip.write(patchFile.name)
> +    patchFile.close()
> +    os.remove(patchFile.name)
> +
> +    if options.verbose:
> +        print ' < writeInfo'
> +
> +def writeDiff(zip, files=None):
> +    """ Write the output of svn diff to a temp file and store in a zip """
> +    if options.verbose:
> +        print ' > writeDiff'
> +
> +    patchFile = open('patch.txt', 'w')
> +    args = ['svn', 'diff']
> +    if files:
> +        args.extend(files)
> +
> +    Popen(args=args, stdout=patchFile).communicate()[0]
> +
> +    zip.write(patchFile.name)
> +    patchFile.close()
> +    os.remove(patchFile.name)
> +
> +    if options.verbose:
> +        print ' < writeDiff'
> +
> +def javaToClass(file) :
> +    """ simple helper function, converts a string from svn stat (or
> command line) to its corresponding
> +    .class file
> +    """
> +
> +    rval =
> file.replace('src','target').replace('main','classes').replace('test','test-classes').replace('.java',
> '.class').replace('java','').replace('\\\\','\\')
> +    return rval;
> +
> +def javaToInnerClass(file):
> +    """ helper function, converts .java file to a glob pattern that
> matches inner classes """
> +    return javaToClass(file).replace('.class', '$*.class')
> +
> +def writeClasses(zip, files=None):
> +    """ Write class files to a zip """
> +
> +    prog = re.compile('(.*classes.)(.*)')
> +    propertiesProg = re.compile('(.*resources.)(.*)')
> +
> +    for file in files :
> +        if str(file).endswith('.java'):
> +            for globMatch in glob(javaToClass(file)) :
> +                if(prog.match(globMatch)):
> +                    target = prog.match(globMatch).group(2)
> +                    zip.write(os.path.realpath(globMatch), target)
> +
> +            # match again on inner classes, not sure if glob supports
> optional matches.
> +            for globMatch in glob(javaToInnerClass(file)) :
> +                if(prog.match(globMatch)):
> +                    target = prog.match(globMatch).group(2)
> +                    zip.write(os.path.realpath(globMatch), target)
> +        elif str(file).endswith('.properties'):
> +            for globMatch in glob(file) :
> +                 if(propertiesProg.match(globMatch)):
> +                    target = propertiesProg.match(globMatch).group(2)
> +                    zip.write(os.path.realpath(globMatch), target)
> +
> +if __name__ == "__main__":
> +    main()
> +
>
> Propchange: openjpa/trunk/patchoj.py
>
> ------------------------------------------------------------------------------
>    svn:eol-style = native
>
> Propchange: openjpa/trunk/patchoj.py
>
> ------------------------------------------------------------------------------
>    svn:executable = *
>
>
>

Mime
  • Unnamed multipart/alternative (inline, None, 0 bytes)
View raw message