/templates/admin/repo/

org/aspectj.git/atom/aspectj-attic/testing-src/AjcTaskTester2.java?h=dependabot/maven/org.apache.maven.plugins-maven-gpg-plugin-3.1.0' type='application/atom+xml'/>
aboutsummaryrefslogtreecommitdiffstats
path: root/aspectj-attic/testing-src/AjcTaskTester2.java
blob: f5c5b36db17dd73bfe3b0cf3123661619255b713 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
/* *******************************************************************
 * Copyright (c) 1999-2001 Xerox Corporation, 
 *               2002 Palo Alto Research Center, Incorporated (PARC).
 * All rights reserved. 
 * This program and the accompanying materials are made available 
 * under the terms of the Common Public License v1.0 
 * which accompanies this distribution and is available at 
 * http://www.eclipse.org/legal/cpl-v10.html 
 *  
 * Contributors: 
 *     Xerox/PARC     initial implementation 
 * ******************************************************************/


import java.io.*;
import java.util.*;
import org.apache.tools.ant.*;
import org.apache.tools.ant.taskdefs.*;
import org.apache.tools.ant.types.*;


/**
 * Tests the AJC2 ant task.
 */
public class AjcTaskTester2 extends AntTaskTester {

    protected final static String TEST_CLASSES = "test-classes";
    protected final static String TEST_SOURCES = "../src";
    protected File buildDir = null;

    /**
     * We use <code>"tests/ant/etc/ajc2.xml"</code>.
     */
    public String getAntFile() {
        return "tests/ant/etc/ajc2.xml";
    }

    /**
     * Put {@link #TEST_CLASSES} and {@link #TEST_SOURCES}
     * into the user properties.
     */
    protected Map getUserProperties() {
        Map userProps = new HashMap();
        userProps.put("ant.test.classes", TEST_CLASSES);
        userProps.put("ant.test.sources", TEST_SOURCES);        
        return userProps;
    }

    ////// Begin tests //////////////////////////////////////////////

    public void test1()   { wantClasses("One"); }
    public void test2()   { wantClasses("One,Two"); }
    public void test3()   { wantClasses("One,Two,Three"); }
    public void test4()   { wantClasses("One"); }
    public void test4b()  { wantClasses("One"); }
    public void test5()   { wantClasses("One,Two"); }
    public void test5b()  { wantClasses("One,Two"); }
    public void test6()   { wantClasses("One,Two,Three"); }
    public void test6b()  { wantClasses("One,Two,Three"); }
    public void test8()   { wantClasses("One"); }
    public void test9()   { wantClasses("One"); }
    public void test10()  { wantClasses("One"); }
    public void test11()  { wantClasses("One"); }
    public void test12()  { wantClasses(""); }
    public void test13()  { wantClasses("One"); }
    public void fail1(BuildException be) {}
    public void fail2(BuildException be) {}
    public void fail3(BuildException be) {}   

    ////// End tests ////////////////////////////////////////////////

    /**
     * Make the build dir -- e.g. call {@link #makeBuildDir}
     */
    protected void beforeEveryTask() {
        makeBuildDir();
    }

    /**
     * Assert classes and clear build dir.
     *
     * @see #checkClasses()
     * @see #clearBuildDir()
     */
    protected void afterEveryTask() {
        checkClasses();
        clearBuildDir();
    }


    /**
     * Expect the classes found in
     * <code>classNamesWithoutExtensions</code>
     *
     * @param classNamesWithoutExtensions Array of class names without
     *                                    extensions we want to see.
     * @see   #wantClasses(List)
     */
    protected void wantClasses(String[] classNamesWithoutExtensions) {
        List list = new Vector();
        for (int i = 0; i < classNamesWithoutExtensions.length; i++) {
            list.add(classNamesWithoutExtensions[i]);
        }
        wantClasses(list);
    }
    
    /**
     * Expect the classes found in
     * <code>classNamesWithoutExtensions</code>
     *
     * @param classNamesWithoutExtensions String of class names without
     *                                    extensions we want to see separated
     *                                    by <code> </code>, <code>,</code>, or
     *                                    <code>;</code>.
     * @see   #wantClasses(List)
     */
    protected void wantClasses(String classNamesWithoutExtensions) {
        StringTokenizer tok = new StringTokenizer(classNamesWithoutExtensions, ",;");
        List list = new Vector();
        while (tok.hasMoreTokens()) {
            list.add(tok.nextToken());
        }
        wantClasses(list);
    }

    /**
     * Expected each class name found in
     * <code>classNamesWithoutExtensions</code>.
     *
     * @param classNamesWithoutExtensions List of class names without
     *                                    exntensions.
     * @see   #want(Object)
     */
    protected void wantClasses(List classNamesWithoutExtensions) {
        Iterator iter = classNamesWithoutExtensions.iterator();
        while (iter.hasNext()) {
            String className = iter.next() + "";
            className = className.replace('.', '/').replace('\\', '/');
            want(className + ".class");
        }
    }

    /**
     * Assert that all classes in {@link #wants} were found.
     */
    protected void checkClasses() {
        Iterator iter = wants.iterator();
        while (iter.hasNext()) {
            String className = iter.next() + "";
            File file = new File(buildDir, className);
            if (file != null && file.exists()) {
                have(className);
            }
        }
    }

    /**
     * Create a new build dir.
     */
    protected void init() {
        buildDir = new File(project.getBaseDir(), TEST_CLASSES);
    }

    /**
     * Make a new build dir using ANT.
     */
    protected void makeBuildDir() {
        try {
            Mkdir mkdir = (Mkdir)project.createTask("mkdir");
            mkdir.setDir(buildDir);
            mkdir.execute();
        } catch (BuildException be) {
            be.printStackTrace();
        }
    }

    /**
     * Clear the build dir using ANT.
     */
    protected void clearBuildDir() {
        try {
            Delete delete = (Delete)project.createTask("delete");
            FileSet fileset = new FileSet();
            fileset.setDir(buildDir);
            fileset.setIncludes("**");
            delete.addFileset(fileset);
            delete.execute();
        } catch (BuildException be) {
            be.printStackTrace();
        }        
    }

    /**
     * Invoke {@link #runTests(String[])} on a
     * new instanceof {@link #AjcTaskTester2}.
     *
     * @param args Command line arguments.
     */
    public static void main(String[] args) {
        new AjcTaskTester2().runTests(args);
    }
}