001: /* Copyright (C) 2004 - 2007 db4objects Inc. http://www.db4o.com
002:
003: This file is part of the db4o open source object database.
004:
005: db4o is free software; you can redistribute it and/or modify it under
006: the terms of version 2 of the GNU General Public License as published
007: by the Free Software Foundation and as clarified by db4objects' GPL
008: interpretation policy, available at
009: http://www.db4o.com/about/company/legalpolicies/gplinterpretation/
010: Alternatively you can write to db4objects, Inc., 1900 S Norfolk Street,
011: Suite 350, San Mateo, CA 94403, USA.
012:
013: db4o is distributed in the hope that it will be useful, but WITHOUT ANY
014: WARRANTY; without even the implied warranty of MERCHANTABILITY or
015: FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
016: for more details.
017:
018: You should have received a copy of the GNU General Public License along
019: with this program; if not, write to the Free Software Foundation, Inc.,
020: 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */
021: package com.db4o.instrumentation.ant;
022:
023: import java.util.*;
024:
025: import org.apache.tools.ant.*;
026: import org.apache.tools.ant.types.*;
027:
028: import com.db4o.instrumentation.core.*;
029: import com.db4o.instrumentation.main.*;
030:
031: public class Db4oFileEnhancerAntTask extends Task {
032: private final List _sources = new ArrayList();
033: private String _targetDir;
034: private final List _classPath = new ArrayList();
035: private String _packagePredicate;
036: private final List _editFactories = new ArrayList();
037:
038: public void add(ClassEditFactory editFactory) {
039: _editFactories.add(editFactory);
040: }
041:
042: public void addSources(FileSet fileSet) {
043: _sources.add(fileSet);
044: }
045:
046: public void setTargetdir(String targetDir) {
047: _targetDir = targetDir;
048: }
049:
050: public void addClasspath(Path path) {
051: _classPath.add(path);
052: }
053:
054: public void setPackagefilter(String packagePredicate) {
055: _packagePredicate = packagePredicate;
056: }
057:
058: public void execute() {
059: List paths = new ArrayList();
060: for (Iterator pathIter = _classPath.iterator(); pathIter
061: .hasNext();) {
062: Path path = (Path) pathIter.next();
063: String[] curPaths = path.list();
064: for (int curPathIdx = 0; curPathIdx < curPaths.length; curPathIdx++) {
065: paths.add(curPaths[curPathIdx]);
066: }
067: }
068: BloatClassEdit clazzEdit = null;
069: switch (_editFactories.size()) {
070: case 0:
071: clazzEdit = new NullClassEdit();
072: break;
073: case 1:
074: clazzEdit = ((ClassEditFactory) _editFactories.get(0))
075: .createEdit();
076: break;
077: default:
078: List classEdits = new ArrayList(_editFactories.size());
079: for (Iterator factoryIter = _editFactories.iterator(); factoryIter
080: .hasNext();) {
081: ClassEditFactory curFactory = (ClassEditFactory) factoryIter
082: .next();
083: classEdits.add(curFactory.createEdit());
084: }
085: clazzEdit = new CompositeBloatClassEdit(
086: (BloatClassEdit[]) classEdits
087: .toArray(new BloatClassEdit[classEdits
088: .size()]), true);
089:
090: }
091: AntFileSetPathRoot root = new AntFileSetPathRoot(
092: (FileSet[]) _sources.toArray(new FileSet[_sources
093: .size()]));
094: try {
095: new Db4oFileEnhancer(clazzEdit)
096: .enhance(root, _targetDir, (String[]) paths
097: .toArray(new String[paths.size()]),
098: (_packagePredicate == null ? ""
099: : _packagePredicate));
100: } catch (Exception exc) {
101: throw new BuildException(exc);
102: }
103: }
104: }
|