001: /*
002: * Copyright (c) 1998 - 2005 Versant Corporation
003: * All rights reserved. This program and the accompanying materials
004: * are made available under the terms of the Eclipse Public License v1.0
005: * which accompanies this distribution, and is available at
006: * http://www.eclipse.org/legal/epl-v10.html
007: *
008: * Contributors:
009: * Versant Corporation - initial API and implementation
010: */
011: package com.versant.core.jdo.tools.ant;
012:
013: import java.util.*;
014: import java.io.File;
015:
016: import com.versant.core.common.config.ConfigParser;
017: import com.versant.core.jdo.tools.enhancer.Enhancer;
018: import org.apache.tools.ant.types.FileSet;
019: import org.apache.tools.ant.*;
020: import org.apache.tools.ant.types.*;
021: import org.apache.tools.ant.BuildException;
022:
023: /**
024: * @keep-all
025: *
026: */
027: public class EnhancerTask extends JdoTaskBase {
028:
029: protected String configFilename = DEFAULT_CONFIG_FILENAME;
030: private File dir;
031: private List awareList = new ArrayList();
032: private List queryList = new ArrayList();
033: private boolean genHyper;
034: private File hyperdriveDir;
035: private File hyperSrcDir;
036: private boolean detach = true;
037: private boolean makeFieldsPrivate;
038:
039: public EnhancerTask() {
040: }
041:
042: public void addPersistentaware(PCAwareSet aware) {
043: awareList.add(aware);
044: }
045:
046: public void addQueries(QuerySet queries) {
047: queryList.add(queries);
048: }
049:
050: public void addPersistentAwareFileset(FileSet fileset) {
051: throw new BuildException(
052: "DEPRECATED - The <persistentAwareFileset> tag has been deprecated.\n"
053: + "use:\n"
054: + " <persistentaware dir=\"${dir.compile}\">\n"
055: + " <package name=\"za.co.hemtech.bla.*\"/>\n"
056: + " </persistentaware>\n");
057: }
058:
059: public void setConfig(String config) {
060: configFilename = config;
061: }
062:
063: public void setOutputDir(File dir) {
064: this .dir = dir;
065: }
066:
067: public void setGenHyper(boolean s) {
068: this .genHyper = s;
069: }
070:
071: public void setHyperdriveDir(File hyperdriveDir) {
072: this .hyperdriveDir = hyperdriveDir;
073: }
074:
075: public void setDetach(boolean detach) {
076: this .detach = detach;
077: }
078:
079: public void setmakeFieldsPrivate(boolean s) {
080: this .makeFieldsPrivate = s;
081: }
082:
083: public void setHyperSrcDir(File hyperSrcDir) {
084: this .hyperSrcDir = hyperSrcDir;
085: }
086:
087: public void execute() throws BuildException {
088: try {
089: executeImp();
090: } catch (RuntimeException e) {
091: e.printStackTrace(System.out);
092: try {
093: Thread.sleep(1000);
094: } catch (InterruptedException e1) {
095: }
096: throw e;
097: }
098: }
099:
100: private void executeImp() throws BuildException {
101:
102: HashSet classes = new HashSet();
103: HashSet queries = new HashSet();
104:
105: if (configFilename != null) {
106: com.versant.core.common.config.ConfigInfo config;
107: ConfigParser p = new ConfigParser();
108: config = p.parseResource(configFilename, getClassLoader());
109: config.validate();
110:
111: } else {
112: throw new BuildException(
113: "The config file name is required ");
114: }
115:
116: if (!awareList.isEmpty()) {
117: for (Iterator iterator = awareList.iterator(); iterator
118: .hasNext();) {
119: PCAwareSet awareSet = (PCAwareSet) iterator.next();
120: classes.addAll(awareSet.getAwareClasses(super .project));
121: }
122: }
123:
124: if (!queryList.isEmpty()) {
125: for (Iterator iterator = queryList.iterator(); iterator
126: .hasNext();) {
127: QuerySet querySet = (QuerySet) iterator.next();
128: queries.addAll(querySet.getQueryClasses(super .project));
129: }
130: }
131:
132: // if (dir == null){
133: // throw new BuildException("OutputDir is required");
134: // }
135:
136: Enhancer enhancer = new Enhancer();
137: enhancer.setClassLoader(getClassLoader());
138: enhancer.setDetached(detach);
139: enhancer.setMakeFieldsPrivate(makeFieldsPrivate);
140: enhancer.setGenHyper(genHyper);
141: if (hyperSrcDir != null) {
142: enhancer.setGenSrc(true);
143: enhancer.setSrcOutDir(hyperSrcDir);
144: }
145: enhancer.setPropertiesResourceName(configFilename);
146: enhancer.setOutputDir(dir);
147: enhancer.setPCAwareFiles(classes);
148: enhancer.setHyperdriveDir(hyperdriveDir);
149: // enhancer.setQueriesFiles(queries);
150: try {
151: enhancer.enhance();
152: } catch (Exception e) {
153: throw new BuildException(e);
154: }
155: }
156: }
|