~ubuntu-branches/ubuntu/utopic/gridengine/utopic

« back to all changes in this revision

Viewing changes to source/libs/jgdi/cullconv/src/com/sun/grid/javaconv/ant/JavaConvAntTask.java

  • Committer: Bazaar Package Importer
  • Author(s): Mark Hymers
  • Date: 2008-06-25 22:36:13 UTC
  • Revision ID: james.westby@ubuntu.com-20080625223613-tvd9xlhuoct9kyhm
Tags: upstream-6.2~beta2
ImportĀ upstreamĀ versionĀ 6.2~beta2

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/*___INFO__MARK_BEGIN__*/
 
2
/*************************************************************************
 
3
 *
 
4
 *  The Contents of this file are made available subject to the terms of
 
5
 *  the Sun Industry Standards Source License Version 1.2
 
6
 *
 
7
 *  Sun Microsystems Inc., March, 2001
 
8
 *
 
9
 *
 
10
 *  Sun Industry Standards Source License Version 1.2
 
11
 *  =================================================
 
12
 *  The contents of this file are subject to the Sun Industry Standards
 
13
 *  Source License Version 1.2 (the "License"); You may not use this file
 
14
 *  except in compliance with the License. You may obtain a copy of the
 
15
 *  License at http://gridengine.sunsource.net/Gridengine_SISSL_license.html
 
16
 *
 
17
 *  Software provided under this License is provided on an "AS IS" basis,
 
18
 *  WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING,
 
19
 *  WITHOUT LIMITATION, WARRANTIES THAT THE SOFTWARE IS FREE OF DEFECTS,
 
20
 *  MERCHANTABLE, FIT FOR A PARTICULAR PURPOSE, OR NON-INFRINGING.
 
21
 *  See the License for the specific provisions governing your rights and
 
22
 *  obligations concerning the Software.
 
23
 *
 
24
 *   The Initial Developer of the Original Code is: Sun Microsystems, Inc.
 
25
 *
 
26
 *   Copyright: 2001 by Sun Microsystems, Inc.
 
27
 *
 
28
 *   All Rights Reserved.
 
29
 *
 
30
 ************************************************************************/
 
31
/*___INFO__MARK_END__*/
 
32
package com.sun.grid.javaconv.ant;
 
33
 
 
34
import com.sun.grid.cull.AbstractCullConverter;
 
35
import java.io.File;
 
36
import java.io.IOException;
 
37
import java.util.ArrayList;
 
38
import java.util.List;
 
39
import java.util.logging.Handler;
 
40
import java.util.logging.Level;
 
41
import java.util.logging.Logger;
 
42
import com.sun.grid.cull.ant.*;
 
43
import com.sun.grid.javaconv.JavaToJavaConverter;
 
44
import org.apache.tools.ant.BuildException;
 
45
import org.apache.tools.ant.Task;
 
46
import org.apache.tools.ant.types.Path;
 
47
 
 
48
/**
 
49
 *
 
50
 */
 
51
public class JavaConvAntTask extends Task {
 
52
 
 
53
    private File buildDir;
 
54
 
 
55
    private List<AbstractConverterDefinition> converterList = new ArrayList<AbstractConverterDefinition>();
 
56
 
 
57
    private Path classpath;
 
58
 
 
59
    private String classname;
 
60
 
 
61
    private ClassFilter classdef;
 
62
 
 
63
    private String source = " converters and ";
 
64
    private String target = " classes";
 
65
 
 
66
    public ClassFilter createClassDef() {
 
67
        if (classdef == null) {
 
68
            classdef = new ClassFilter(this);
 
69
        }
 
70
        return classdef;
 
71
    }
 
72
 
 
73
    String getClassPathAsString() {
 
74
        return classdef.getClassPathAsString();
 
75
    }
 
76
 
 
77
    public JavaTemplateConverterDefintion createTemplateconv() {
 
78
        JavaTemplateConverterDefintion conv = new JavaTemplateConverterDefintion(this);
 
79
        converterList.add(conv);
 
80
        return conv;
 
81
    }
 
82
 
 
83
    public TemplateConverterDefinition createSimpleTemplateConv() {
 
84
        TemplateConverterDefinition conv = new TemplateConverterDefinition(this);
 
85
        converterList.add(conv);
 
86
        return conv;
 
87
    }
 
88
 
 
89
 
 
90
    public void execute() throws org.apache.tools.ant.BuildException {
 
91
 
 
92
        Logger logger = AbstractCullConverter.logger;
 
93
 
 
94
        Handler[] handler = logger.getHandlers();
 
95
        for (int i = 0; i < handler.length; i++) {
 
96
            logger.removeHandler(handler[i]);
 
97
        }
 
98
 
 
99
        logger.setUseParentHandlers(false);
 
100
        AntLoggingHandler myHandler = new AntLoggingHandler(getProject());
 
101
        logger.addHandler(myHandler);
 
102
        logger.setLevel(Level.ALL);
 
103
        myHandler.setLevel(Level.ALL);
 
104
 
 
105
 
 
106
        try {
 
107
            Class[] classes = classdef.getClasses();
 
108
            JavaToJavaConverter[] conv = new JavaToJavaConverter[converterList.size()];
 
109
            int i = 0;
 
110
            for (AbstractConverterDefinition convDef : converterList) {
 
111
                conv[i++] = convDef.createConverter();
 
112
            }
 
113
 
 
114
            logger.fine("has " + conv.length + " converters and " + classes.length + " classes");
 
115
            for (int convIndex = 0; convIndex < conv.length; convIndex++) {
 
116
                for (int classIndex = 0; classIndex < classes.length; classIndex++) {
 
117
                    conv[convIndex].convert(classes[classIndex]);
 
118
                }
 
119
                conv[convIndex].finish();
 
120
            }
 
121
        } catch (ClassNotFoundException cnfe) {
 
122
            throw new BuildException("a class was not found: " + cnfe.getMessage(), cnfe);
 
123
        } catch (IOException ioe) {
 
124
            throw new BuildException("IO/Error: " + ioe.getMessage(), ioe);
 
125
        }
 
126
    }
 
127
 
 
128
 
 
129
    public File getBuildDir() {
 
130
        return buildDir;
 
131
    }
 
132
 
 
133
    public void setBuildDir(File buildDir) {
 
134
        this.buildDir = buildDir;
 
135
    }
 
136
 
 
137
    public String getClassname() {
 
138
        return classname;
 
139
    }
 
140
 
 
141
    public String getSource() {
 
142
        return source;
 
143
    }
 
144
 
 
145
    public void setSource(String source) {
 
146
        this.source = source;
 
147
    }
 
148
 
 
149
    public String getTarget() {
 
150
        return target;
 
151
    }
 
152
 
 
153
    public void setTarget(String target) {
 
154
        this.target = target;
 
155
    }
 
156
}