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 org.apache.tools.ant.types.AbstractFileSet;
014: import org.apache.tools.ant.Project;
015: import org.apache.tools.ant.DirectoryScanner;
016:
017: import java.util.ArrayList;
018: import java.util.List;
019: import java.util.Iterator;
020:
021: /**
022: * @keep-all
023: *
024: */
025: public class QuerySet extends AbstractFileSet {
026: private ArrayList packages = new ArrayList();
027:
028: public QuerySet() {
029: super ();
030: }
031:
032: protected QuerySet(QuerySet fileset) {
033: super (fileset);
034: }
035:
036: public Package createPackage() {
037: Package pack = new Package();
038: packages.add(pack);
039: return pack;
040: }
041:
042: /**
043: * Return a FileSet that has the same basedir and same patternsets
044: * as this one.
045: */
046: public Object clone() {
047: if (isReference()) {
048: return new QuerySet((QuerySet) getRef(getProject()));
049: } else {
050: return new QuerySet(this );
051: }
052: }
053:
054: public List getQueryClasses(Project project) {
055: ArrayList classlist = new ArrayList();
056: final String dotClass = ".class";
057: StringBuffer buf = new StringBuffer();
058: for (Iterator iterator = packages.iterator(); iterator
059: .hasNext();) {
060: Package s = (Package) iterator.next();
061: String pat = s.getName();
062: if (pat.endsWith("*")) {
063: pat = pat + "*";
064: } else {
065: pat = pat + ".*";
066: }
067: buf.append(pat.replace('.', '/'));
068: buf.append(" ");
069:
070: }
071: setIncludes(buf.toString().trim());
072: DirectoryScanner scanner = getDirectoryScanner(project);
073: String[] incFiles = scanner.getIncludedFiles();
074: for (int j = 0; j < incFiles.length; j++) {
075: String temp = incFiles[j];
076: if (temp.endsWith(dotClass)) {
077: classlist.add(temp);
078: }
079:
080: }
081: return classlist;
082: }
083:
084: /**
085: * Used to track info about the packages to be
086: */
087: public static class Package {
088: /**
089: * The package name
090: */
091: private String name;
092:
093: /**
094: * Set the name of the package
095: *
096: * @param name the package name.
097: */
098: public void setName(String name) {
099: this .name = name.trim();
100: }
101:
102: /**
103: * Get the package name.
104: *
105: * @return the package's name.
106: */
107: public String getName() {
108: return name;
109: }
110:
111: /**
112: * @see java.lang.Object#toString
113: */
114: public String toString() {
115: return getName();
116: }
117: }
118: }
|