# -*- coding: utf-8 -*-

import os
import shutil
import tempfile
from subprocess import call, STDOUT

class CreateUpdateJar(object):
    def __init__(self, buildout, name, options):
        self.name = name
        base = buildout['buildout']['directory']

        self.basedir = os.path.join(base, options['basedir'])
        # check if self.basedir exists
        self.input = options['input'].split()
        self.output = os.path.join(base, options['output'])
        # check if os.basedir(self.output) exists and is writable
        # check if self.output is not a directory

        self.mode = options.get('mode')
        # assert self.mode in ['create', 'update']

    def install(self):
        tmpdir = tempfile.mkdtemp()
        jarfile = os.path.join(tmpdir, os.path.basename(self.output))
        args = {'jarfile': jarfile, 'basedir': self.basedir}

        if self.mode == 'create':
            args.update({'inputfiles': self.input})
            cmd = "jar cf %(jarfile)s -C %(basedir)s %(inputfiles)s"%args
        elif self.mode == 'update':
            shutil.copy(self.input[0], jarfile)
            args.update({'inputfiles': self.input[1:]})
            cmd = "jar uf %(jarfile)s -C %(basedir)s %(inputfiles)s"%args 
        else:
            raise 'unknow mode'

        errors = tempfile.TemporaryFile()
        retcode = call(cmd.split(), cwd=tmpdir, stdout=errors, stderr=STDOUT)
        
        if retcode != 0:
            errors.seek(0)
            raise 'error while creating jar'
        else:
            shutil.copy(jarfile, self.output)
            shutil.rmtree(tmpdir)
            return [self.output, self.output.replace('.war', '')]

    update = install

@@ -58,16 +58,38 @@
 empfile%0A
+from glob import glob%0A
 from sub
@@ -330,32 +330,33 @@
 'basedir'%5D)%0A
+%0A
         
 # check if s
@@ -339,35 +339,57 @@
 %5D)%0A%0A        
-# check if 
+self.input = %5B%5D%0A        os.chdir(
 self.basedir
@@ -388,23 +388,17 @@
 .basedir
- exists
+)
 %0A       
@@ -398,28 +398,27 @@
         
-self.input =
+for item in
  options
@@ -434,16 +434,60 @@
 .split()
+:%0A            self.input.extend(glob(item))%0A
 %0A       
@@ -915,33 +915,8 @@
 file
-, 'basedir': self.basedir
 %7D%0A%0A 
@@ -979,32 +979,41 @@
 (%7B'inputfiles': 
+' '.join(
 self.input%7D)%0A   
@@ -1006,16 +1006,17 @@
 lf.input
+)
 %7D)%0A     
@@ -1044,39 +1044,24 @@
 %25(jarfile)s 
--C %25(basedir)s 
 %25(inputfiles
@@ -1129,16 +1129,43 @@
 il.copy(
+os.path.join(self.basedir, 
 self.inp
@@ -1169,16 +1169,17 @@
 input%5B0%5D
+)
 , jarfil
@@ -1220,16 +1220,25 @@
 files': 
+' '.join(
 self.inp
@@ -1243,16 +1243,17 @@
 nput%5B1:%5D
+)
 %7D)%0A     
@@ -1289,23 +1289,8 @@
 e)s 
--C %25(basedir)s 
 %25(in
@@ -1436,19 +1436,25 @@
 (), cwd=
-tmp
+self.base
 dir, std

use glob for input