aboutsummaryrefslogtreecommitdiff
blob: 7da09da46a34147f277454d12d6892ec37600190 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
#!/usr/bin/env python3
# -*- coding: UTF-8 -*-

# Copyright 2008 Gentoo Foundation
# Distributed under the terms of the GNU General Public Licence v2

# Authors
#   Alistair Bush <ali_bush@gentoo.org>

from __future__ import with_statement
import os
import sys
from optparse import OptionParser, make_option
from xml.dom.minidom import parse
from javatoolkit.java.properties import PropertiesParser


if __name__ == '__main__':
    usage = "Eclipse Ant Build File writer"
    usage += "Copyright 2008 Gentoo Foundation\n"
    usage += "Distributed under the terms of the GNU General Public Licence\n"
    usage += "Please contact the Gentoo Java Team <java@gentoo.org> with problems.\n"
    usage += "\nJust wait till I finish this."

    option_list = [
        make_option(
            '-p',
            '--project',
            action='store',
            dest='project',
            help='Project Name'),
        make_option(
            '-i',
            '--include',
            action='append',
            dest='includes',
            help='Files to include in jar'),
        make_option('-s', '--src', action='append', dest='source',
                    help='Directories containing src to build'),
        make_option(
            '-m',
            '--manifest',
            action='store',
            dest='manifest',
            help='Manifest File'),
        make_option('-f', '--file', action='store', dest='file',
                    help='Eclipse build.properties file to parse.'),
        make_option(
            '-o',
            '--output',
            action='store',
            dest='output',
            help='Output build.xml to this file')
    ]

    parser = OptionParser(usage, option_list)
    (options, args) = parser.parse_args()
    # check parser options here.

    if options.file:
        properties = PropertiesParser(options.file)
        #dom = parse( options.file )
        #classpathentries = dom.getElementsByTagName('classpathentry')

        # for entry in classpathentries:
        #    if entry.attributes['kind'] and entry.attributes['kind'].nodeValue == 'src':
        #        print entry.attributes['path'].nodeValue
        #        if entry.attributes['path']:
        #            src_dirs.append( entry.attributes['path'].nodeValue )

        with open(options.output, 'w') as output:
            output.write('<?xml version="1.0" encoding="UTF-8" ?>\n')
            output.write(
                '<project basedir="." default="jar" name="' +
                options.project +
                '">\n')
            output.write('<property name="target" value="1.4"/>\n')
            output.write('<property name="source" value="1.4"/>\n')
            output.write('<property name="gentoo.classpath" value="" />\n\n')
            output.write('<target name="init">\n')
            output.write('<mkdir dir="bin"/>\n')
            output.write('<copy includeemptydirs="false" todir="bin">\n')
            try:
                if properties.config['source..']:
                    for dir in properties.config['source..']:
                        output.write(
                            '<fileset dir="' +
                            dir +
                            '" excludes="**/*.java, **/*.launch" />\n')
                if properties.config['bin.includes']:
                    for item in properties.config['bin.includes']:
                        if item != '.':
                            if item.endswith('/'):
                                item = item.rstrip('/')
                                output.write(
                                    '<fileset dir="." includes="' +
                                    item +
                                    '/**" excludes="**/*.java, **/*.launch" />\n')
                            else:
                                output.write(
                                    '<fileset file="' + item + '" />\n')
            finally:
                output.write('</copy>\n')
            if options.includes:
                for file in options.includes:
                    output.write('<copy file="' + file + '" todir="bin"/>')
            output.write('</target>\n')
            output.write(
                '\n<target name="clean">\n\t<delete dir="bin"/>\n</target>\n\n')
            output.write('<target depends="init" name="compile">\n')
            output.write(
                '<javac destdir="bin" source="${source}" target="${target}" classpath="${gentoo.classpath}">\n')
            try:
                if properties.config['source..']:
                    for dir in properties.config['source..']:
                        output.write('\t<src path="' + dir + '" />\n')
            finally:
                output.write('</javac>\n')
            output.write('</target>\n\n')
            output.write('<target depends="compile" name="jar" >\n')
            output.write('<jar file="${ant.project.name}.jar" basedir="bin"')
            if options.manifest:
                output.write('\nmanifest="' + parser.manifest + '">\n')
            else:
                output.write('>\n')
            output.write('</jar>\n')
            output.write('</target>\n')
            output.write('</project>\n')
            # output.write('')
            # output.write('')
            # output.write('')
            # output.write('')
            # output.write('')
            # output.write('')
            # output.write('')

# vim:set expandtab tabstop=4 shiftwidth=4 softtabstop=4 nowrap :