summaryrefslogtreecommitdiffstats
path: root/tests/product/testScripts/argfiles.sh
blob: 5c093a45a6b96d31280b21f62c58119c005761a0 (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
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
#!/bin/sh
# info: test -argfile and @ variants
# syntax: $0 (define JDKDIR and AJBASE)
# @process-test ajc argfiles.sh # test -argfile and @ variants

[ -n "$DEBUG" ] && set -vx 

errMssg() {
    [ -n "$1" ] && echo "## $0 $1"
    [ -n "$2" ] && exit "$2"
}

## @testcase (support) NPE with -argfile foo.lst with "*.java"
testcaseDesign() {
cat<<EOF
## input variants
command line:  [ [-argfile | @] X <fileRef>{lst} ]...
fileRef:       [[local | relative | absolute] X [DOS|Unix|Mac]]
file line:     [ option | [@<fileRef>{lst} | <fileRef>{java|aj}] ]
option:        ajc options
refLocality:   [cwd | argfile]

## white box
- @, -argfile delegate to same file-creation method
- direct locality matters: null used for for locals and..
- indirect locality matters: referent varies

## design
-- structure
- invocation
  - could set up as unit tests of ConfigParser.java
    - if so, have also to test delivery to ajc? e.g., do package names
      get calculated correctly under different path variants?
      Probably not an issue now, but perhaps later when source-path
      searching is enabled.
  - could invoke ajc.Main programmatically - can ajc be run repeatedly?
    -> might be easier/safer to script, uncover [bash, DOS,...] shell quirks?
-- test case variants
- command-line 
  - test options
    - ajc
    - esp. multi-flag (-source 1.4) - separate lines?
    - VM/Javac?
  - @, -argfile is independent
  - test 0, 1, 3 on same line, interspersed
  - error: @java file, unflagged arg file
- fileRef depends on locality:
  - parm file: CWD, relative-up, relative down-up, absolute, wrong \/:
    - relative and absolute traversing through directories with
      spaces in them (not in package-named directories)
  - file line: same, with * variants 
    - * variants: [*.java | *.aj] [ empty | 1 | n>1 ]
- fileRef also depends on indirection path:
  - add traversal cases
    - 1-2 levels of indirection
- need to think about whether indirection depends on locality reference
  i.e., whether 1-2 levels of indirection need to be through
  all locality types (CWD, relative...)
- basic argfile
  - options
  - files
  - @ref
  - comments
  - empty lines
  - *.java, *.aj references - re

## implementation
- Source tree 
  - minimal, star, maximal: all need each other to compile
  - some in default package, others in named packages
  - some do not share the same source base (or file system?)
  - files:
  Minimal:
  src/
    Main.java
    pack/Main.java
  Star:
  star/
    Main.java
    empty/
    many/One.java
    many/Two.java
    
  Maximal:
  src1/
    Src1DefaultMain.java
    pack1/Src1Pack1Main.java
    pack2/Src1Pack2Main.java
  src2/
    Src2DefaultMain.java
    pack1/Src2Pack1Main.java
    pack2/Src2Pack2Main.java

-

EOF
}

generateCurrentSource() {
    genSource "" Main "Main SomeClass" > Main.java
    genSource "" SomeClass "Main SomeClass" > SomeClass.java

    cat > current_Main_0.lst <<EOF
*.java
EOF
    cat > current_SomeClass_0.lst <<EOF
*.java
EOF
    echo "current"
}

generateMinimalSource() {
    mkdir -p src src/pack
    genSource "" Main "Main pack.Main" > src/Main.java
    genSource pack Main "pack.Main" > src/pack/Main.java

    cat > src/minimal_pack.Main_0.lst <<EOF
pack/Main.java
EOF
    cat > src/minimal_Main_1.lst <<EOF
Main.java
pack/Main.java
EOF
    cat > src/pack/minimal_Main_2.lst <<EOF
../Main.java
Main.java
EOF
    cat > src/pack/minimal_Main_3.lst <<EOF
../*.java
*.java
EOF
    cat > minimal_Main_4.lst <<EOF
@src/minimal_Main_1.lst
EOF
    cat > src/minimal_Main_5.lst <<EOF
@minimal_Main_1.lst
EOF
    cat > src/minimal_Main_6.lst <<EOF
@../src/minimal_Main_1.lst
EOF
    cat > src/minimal_Main_7.lst <<EOF
// starting comment
Main.java        // end of line comment
// middle comment
pack/Main.java
// end comment
EOF
    cat > src/minimal_Main_8.lst <<EOF
*.java
pack/*.java
EOF
    echo "minimal"
}

generateStarSource() {
    echo "todo incomplete"
    mkdir -p star star/many star/empty
    genSource "" Main "Main many.One many.Two" > star/Main.java
    genSource "many" Main "many.One many.Two" > star/many/One.java
    genSource "many" Main "many.One many.Two" > star/many/Two.java
    cat > star/star_Main_1.lst <<EOF
*.java
empty/*.java
many/*.java
EOF
  
    mkdir src1/pack1 src1/pack2 src2/pack1 src2/pack2
    refs="pack1.Src1Pack1Main pack2.Src1Pack2Main pack1.Src2Pack1Main pack2.Src2Pack2Main"
    genSource "" Main "Src1Main $refs" > src1/Src1Main.java
    genSource "" Main "Src2Main $refs" > src2/Src2Main.java
    genSource "pack1" Main "$refs" > src1/pack1/Src1Pack1Main.java
    genSource "pack2" Main "$refs" > src1/pack2/Src1Pack2Main.java
    genSource "pack1" Main "$refs" > src2/pack1/Src2Pack1Main.java
    genSource "pack2" Main "$refs" > src2/pack2/Src2Pack2Main.java
}

genSource() {
    package="$1"
    class="$2"
    refs="$3"
    if [ -z "$package" ] ; then
      name="$class"
    else
      echo "package $package;"
      name="$package.$class"
    fi
cat<<EOF
public class $class {
    public static final String NAME = "$name";
    public static String[] ARGS = new String[] 
EOF
    sep='{'
    for i in $refs ; do
      echo "    $sep ${i}.NAME"
      sep=','
    done
cat<<EOF
    };
    public static void main (String[] args) {
        util.Util.signal(NAME + ".main",ARGS);
    } 
} // class $class
EOF
}

getMain() {
    [ -n "$1" ] && echo "$1" | sed 's|.*_\([^_][^_]*\)_.*|\1|'
}

compile() {
  [ -d classes ] || mkdir classes
  rm -rf classes/*
  $JDKDIR/bin/java -classpath "$toolsjar" org.aspectj.tools.ajc.Main \
     -d classes -classpath "$utiljar${PS}$rtjar" "${@}"
}

run() {
  $JDKDIR/bin/java -classpath "$utiljar${PS}$rtjar${PS}classes" "${@}"
}

testAjc() {
  argfile="$1"
  [ -n "$VERBOSE" ] && echo "# $1"
  [ -f "$argfile" ] || errMssg "testAjc argfile: $1" 3
  main=`getMain "$argfile"`
  [ -n "$main" ]  || errMssg "testAjc no main for argfile: $1" 3
  compile -argfile "$argfile" || errMssg "testAjc compile 1 fail: $1" 3
  run "$main" || errMssg "testAjc run 1 fail: $1" 3
  compile @"$argfile" || errMssg "testAjc compile 2 fail: $1" 3
  run "$main" || errMssg "testAjc run 2 fail: $1" 3
}

createUtilJar() {
  mkdir util
  cat > util/Util.java <<EOF
package util;
public class Util {
    public static void signal(String label, String[] names) {
        boolean printing = $printing;
        if (printing) {
            StringBuffer sb = new StringBuffer();
            sb.append(label);
            sb.append("=[");
            for (int i = 0; i < names.length; i++) {
              if (i > 0) sb.append(", ");
              sb.append(names[i]);
            }
            sb.append("]");
            System.out.println(sb.toString());
        }
    }
}
EOF
compile util/Util.java
"$JDKDIR/bin/jar" cf "$utiljar" -C classes .
rm -rf util
}

getArgFiles() {
  name="$1"
  find . -name "$1"\*.lst | sed 's|./||'
}

echoSetup() {
cat<<EOF
##### setup for $0
  JDKDIR:    $JDKDIR
  AJ_BASE:   $AJ_BASE
  uname -a:  `uname -a`
EOF
}

############################################################## execution
printing=true # must be true or false
JDKDIR="${JDKDIR:-c:/home/apps/jdk13}"
AJ_BASE="${AJ_BASE:-c:/home/wes/aj/aj-dist/tools}"
[ -d "$JDKDIR" ] || errMssg "require JDKDIR=$JDKDIR" 3
[ -d "$AJ_BASE" ] || errMssg "require AJ_BASE=$AJ_BASE" 3
toolsjar="$AJ_BASE/lib/aspectjtools.jar"
rtjar="$AJ_BASE/lib/aspectjrt.jar"
utiljar="$AJ_BASE/lib/argfilesUtil.jar"
[ -f "$toolsjar" ] || errMssg "require toolsjar=$toolsjar" 3
[ -f "$rtjar" ] || errMssg "require rtjar=$rtjar" 3
[ -f "$utiljar" ] || createUtilJar
echoSetup

d=tempArgfiles
[ -d $d ] && rm -rf $d 
mkdir $d  && cd $d

name=`generateCurrentSource`
for i in `getArgFiles "$name"` ; do testAjc "$i"; done

name=`generateMinimalSource`
for i in `getArgFiles "$name"` ; do testAjc "$i"; done

# re-run without src prefix..
cd src
for i in `getArgFiles "$name"` ; do testAjc "$i"; done
echo "tests passed if no compiler failures, only output"