KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > versant > core > jdo > tools > ant > EnhancerTask


1
2 /*
3  * Copyright (c) 1998 - 2005 Versant Corporation
4  * All rights reserved. This program and the accompanying materials
5  * are made available under the terms of the Eclipse Public License v1.0
6  * which accompanies this distribution, and is available at
7  * http://www.eclipse.org/legal/epl-v10.html
8  *
9  * Contributors:
10  * Versant Corporation - initial API and implementation
11  */

12 package com.versant.core.jdo.tools.ant;
13
14 import java.util.*;
15 import java.io.File JavaDoc;
16
17
18 import com.versant.core.common.config.ConfigParser;
19 import com.versant.core.jdo.tools.enhancer.Enhancer;
20 import org.apache.tools.ant.types.FileSet;
21 import org.apache.tools.ant.*;
22 import org.apache.tools.ant.types.*;
23 import org.apache.tools.ant.BuildException;
24
25
26 /**
27  * @keep-all
28  *
29  */

30 public class EnhancerTask extends JdoTaskBase {
31
32     protected String JavaDoc configFilename = DEFAULT_CONFIG_FILENAME;
33     private File JavaDoc dir;
34     private List awareList = new ArrayList();
35     private List queryList = new ArrayList();
36     private boolean genHyper;
37     private File JavaDoc hyperdriveDir;
38     private File JavaDoc hyperSrcDir;
39     private boolean detach = true;
40     private boolean makeFieldsPrivate;
41
42
43     public EnhancerTask() {}
44
45     public void addPersistentaware(PCAwareSet aware){
46         awareList.add(aware);
47     }
48
49     public void addQueries(QuerySet queries) {
50         queryList.add(queries);
51     }
52
53     public void addPersistentAwareFileset(FileSet fileset) {
54         throw new BuildException("DEPRECATED - The <persistentAwareFileset> tag has been deprecated.\n" +
55                                  "use:\n" +
56                                  " <persistentaware dir=\"${dir.compile}\">\n"+
57                                  " <package name=\"za.co.hemtech.bla.*\"/>\n" +
58                                  " </persistentaware>\n");
59     }
60
61     public void setConfig(String JavaDoc config) {
62         configFilename = config;
63     }
64
65     public void setOutputDir(File JavaDoc dir) {
66         this.dir = dir;
67     }
68
69     public void setGenHyper(boolean s){
70         this.genHyper = s;
71     }
72
73     public void setHyperdriveDir(File JavaDoc hyperdriveDir) {
74         this.hyperdriveDir = hyperdriveDir;
75     }
76
77     public void setDetach(boolean detach) {
78         this.detach = detach;
79     }
80
81     public void setmakeFieldsPrivate(boolean s) {
82         this.makeFieldsPrivate = s;
83     }
84
85     public void setHyperSrcDir(File JavaDoc hyperSrcDir) {
86         this.hyperSrcDir = hyperSrcDir;
87     }
88
89
90     public void execute() throws BuildException {
91         try {
92             executeImp();
93         } catch (RuntimeException JavaDoc e) {
94             e.printStackTrace(System.out);
95             try {
96                 Thread.sleep(1000);
97             } catch (InterruptedException JavaDoc e1) {
98             }
99             throw e;
100         }
101     }
102
103     private void executeImp() throws BuildException {
104
105         HashSet classes = new HashSet();
106         HashSet queries = new HashSet();
107
108         if (configFilename != null) {
109             com.versant.core.common.config.ConfigInfo config;
110             ConfigParser p = new ConfigParser();
111             config = p.parseResource(configFilename, getClassLoader());
112             config.validate();
113
114
115         } else {
116             throw new BuildException("The config file name is required ");
117         }
118
119         if (!awareList.isEmpty()){
120             for (Iterator iterator = awareList.iterator(); iterator.hasNext();) {
121                 PCAwareSet awareSet = (PCAwareSet) iterator.next();
122                 classes.addAll(awareSet.getAwareClasses(super.project));
123             }
124         }
125
126         if (!queryList.isEmpty()) {
127             for (Iterator iterator = queryList.iterator(); iterator.hasNext();) {
128                 QuerySet querySet = (QuerySet) iterator.next();
129                 queries.addAll(querySet.getQueryClasses(super.project));
130             }
131         }
132
133 // if (dir == null){
134
// throw new BuildException("OutputDir is required");
135
// }
136

137         Enhancer enhancer = new Enhancer();
138         enhancer.setClassLoader(getClassLoader());
139         enhancer.setDetached(detach);
140         enhancer.setMakeFieldsPrivate(makeFieldsPrivate);
141         enhancer.setGenHyper(genHyper);
142         if (hyperSrcDir != null){
143             enhancer.setGenSrc(true);
144             enhancer.setSrcOutDir(hyperSrcDir);
145         }
146         enhancer.setPropertiesResourceName(configFilename);
147         enhancer.setOutputDir(dir);
148         enhancer.setPCAwareFiles(classes);
149         enhancer.setHyperdriveDir(hyperdriveDir);
150 // enhancer.setQueriesFiles(queries);
151
try {
152             enhancer.enhance();
153         } catch (Exception JavaDoc e) {
154             throw new BuildException(e);
155         }
156     }
157 }
158
Popular Tags