| 1 | /* |
| 2 | * JTiger Unit Testing Framework for J2SE 1.5 |
| 3 | * Copyright (C) 2005 Tony Morris |
| 4 | * |
| 5 | * This software is licenced under the |
| 6 | * Common Public Licence version 1.0 |
| 7 | * http://www.opensource.org/licenses/cpl1.0.php |
| 8 | * |
| 9 | * You received a copy of this licence with this software. |
| 10 | */ |
| 11 | package org.jtiger.ant; |
| 12 | |
| 13 | import java.util.LinkedList; |
| 14 | import java.util.List; |
| 15 | import org.apache.tools.ant.DirectoryScanner; |
| 16 | import org.apache.tools.ant.Project; |
| 17 | import org.apache.tools.ant.types.FileSet; |
| 18 | |
| 19 | /** |
| 20 | * An element used in {@link JTigerTask the Ant task} to specify zero or more {@link Fixture fixtures} and/or zero or |
| 21 | * more <a href="%ant.url%/manual/CoreTypes/fileset.html" target="_blank">file sets</a>. These subelements provide the |
| 22 | * ability to specify which test fixture classes are to be executed during the test run. |
| 23 | * |
| 24 | * @see Fixture |
| 25 | * @see JTigerTask |
| 26 | * @author %javadoc.author.tag% |
| 27 | * @version %version%<br/> |
| 28 | * <i>Build Number %build.number%</i><br/> |
| 29 | * <i>Build Time %build.time% CET (GMT + 1)</i> |
| 30 | */ |
| 31 | public final class Fixtures |
| 32 | { |
| 33 | private final List<Fixture> fixtures; |
| 34 | private final List<FileSet> filesets; |
| 35 | |
| 36 | /** |
| 37 | * Create a default <tt>Fixtures</tt>. |
| 38 | */ |
| 39 | public Fixtures() |
| 40 | { |
| 41 | fixtures = new LinkedList<Fixture>(); |
| 42 | filesets = new LinkedList<FileSet>(); |
| 43 | } |
| 44 | |
| 45 | /** |
| 46 | * {@link Fixture#Fixture() Creates a <tt>Fixture</tt>}, adds it to the list of instances, and returns the instance. |
| 47 | * |
| 48 | * @return A created {@link Fixture#Fixture() <tt>Fixture</tt>}. |
| 49 | */ |
| 50 | public Fixture createFixture() |
| 51 | { |
| 52 | final Fixture f = new Fixture(); |
| 53 | fixtures.add(f); |
| 54 | return f; |
| 55 | } |
| 56 | |
| 57 | /** |
| 58 | * Creates a <tt>FileSet</tt>, adds it to the list of instances, and returns the instance. |
| 59 | * |
| 60 | * @return A created <tt>FileSet</tt>. |
| 61 | */ |
| 62 | public FileSet createFileSet() |
| 63 | { |
| 64 | final FileSet fs = new FileSet(); |
| 65 | filesets.add(fs); |
| 66 | return fs; |
| 67 | } |
| 68 | |
| 69 | List<Fixture> getFixtures() |
| 70 | { |
| 71 | return fixtures; |
| 72 | } |
| 73 | |
| 74 | List<FileSet> getFileSets() |
| 75 | { |
| 76 | return filesets; |
| 77 | } |
| 78 | |
| 79 | String[] toStringArray(final Project project) |
| 80 | { |
| 81 | final List<String> names = new LinkedList<String>(); |
| 82 | |
| 83 | for(Fixture f : fixtures) |
| 84 | { |
| 85 | names.add(f.getClassname()); |
| 86 | } |
| 87 | |
| 88 | for(FileSet f : filesets) |
| 89 | { |
| 90 | final DirectoryScanner ds = f.getDirectoryScanner(project); |
| 91 | |
| 92 | final String[] files = ds.getIncludedFiles(); |
| 93 | |
| 94 | for(String file : files) |
| 95 | { |
| 96 | final FileNameToClassName ftc = FileNameToClassNameFactory.newFileNameToClassName(); |
| 97 | final String className = ftc.toClassName(file); |
| 98 | if(className != null) |
| 99 | { |
| 100 | names.add(className); |
| 101 | } |
| 102 | } |
| 103 | } |
| 104 | |
| 105 | return names.toArray(new String[names.size()]); |
| 106 | } |
| 107 | } |