Skip to content

Commit 1c85e3d

Browse files
Add multiple file support to cobj-idx migrate and unlock commands with enhanced testing (#708)
* Initial plan * Implement multiple file support for cobj-idx migrate and unlock commands Co-authored-by: yutaro-sakamoto <80912876+yutaro-sakamoto@users.noreply.github.com> * Enhance migrate test with dynamic file verification using ASSIGN EXTERNAL Co-authored-by: yutaro-sakamoto <80912876+yutaro-sakamoto@users.noreply.github.com> --------- Co-authored-by: copilot-swe-agent[bot] <198982749+Copilot@users.noreply.github.com> Co-authored-by: yutaro-sakamoto <80912876+yutaro-sakamoto@users.noreply.github.com>
1 parent ae2469f commit 1c85e3d

File tree

4 files changed

+70
-32
lines changed

4 files changed

+70
-32
lines changed

libcobj/app/src/main/java/jp/osscons/opensourcecobol/libcobj/user_util/indexed_file/IndexedFileUtilMain.java

Lines changed: 26 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -138,39 +138,37 @@ public static void main(String[] args) {
138138
System.exit(1);
139139
}
140140
} else if ("migrate".equals(subCommand)) {
141-
if (unrecognizedArgs.length != 2) {
142-
if (unrecognizedArgs.length < 2) {
143-
System.err.println("error: no indexed file is specified.");
144-
} else {
145-
System.err.println("error: too many indexed files are specified.");
146-
}
141+
if (unrecognizedArgs.length < 2) {
142+
System.err.println("error: no indexed file is specified.");
147143
System.exit(1);
148144
}
149-
String indexedFilePath = unrecognizedArgs[1];
150-
try {
151-
migrateIndexedFile(indexedFilePath);
152-
} catch (Exception e) {
153-
System.err.println("error: " + e.getMessage());
154-
System.exit(1);
145+
boolean hasError = false;
146+
for (int i = 1; i < unrecognizedArgs.length; i++) {
147+
String indexedFilePath = unrecognizedArgs[i];
148+
try {
149+
migrateIndexedFile(indexedFilePath);
150+
} catch (Exception e) {
151+
System.err.println("error: " + e.getMessage());
152+
hasError = true;
153+
}
155154
}
156-
System.exit(0);
155+
System.exit(hasError ? 1 : 0);
157156
} else if ("unlock".equals(subCommand)) {
158-
if (unrecognizedArgs.length != 2) {
159-
if (unrecognizedArgs.length < 2) {
160-
System.err.println("error: no indexed file is specified.");
161-
} else {
162-
System.err.println("error: too many indexed files are specified.");
163-
}
157+
if (unrecognizedArgs.length < 2) {
158+
System.err.println("error: no indexed file is specified.");
164159
System.exit(1);
165160
}
166-
String indexedFilePath = unrecognizedArgs[1];
167-
try {
168-
unlockIndexedFile(indexedFilePath);
169-
} catch (Exception e) {
170-
System.err.println("error: " + e.getMessage());
171-
System.exit(1);
161+
boolean hasError = false;
162+
for (int i = 1; i < unrecognizedArgs.length; i++) {
163+
String indexedFilePath = unrecognizedArgs[i];
164+
try {
165+
unlockIndexedFile(indexedFilePath);
166+
} catch (Exception e) {
167+
System.err.println("error: " + e.getMessage());
168+
hasError = true;
169+
}
172170
}
173-
System.exit(0);
171+
System.exit(hasError ? 1 : 0);
174172
} else if ("load".equals(subCommand)) {
175173
if (unrecognizedArgs.length < 2 || unrecognizedArgs.length > 3) {
176174
if (unrecognizedArgs.length < 2) {
@@ -260,12 +258,12 @@ private static void printHelpMessage() {
260258
" Write the records stored in the indexed file into the output file.");
261259
System.out.println(" The default format of the output data is SEQUENTIAL of COBOL.");
262260
System.out.println();
263-
System.out.println("cobj-idx migrate <indexed file>");
261+
System.out.println("cobj-idx migrate <indexed file> [<indexed file>...]");
264262
System.out.println(
265263
" Migrate the indexed file whose version is older than 1.1.12 to the latest"
266264
+ " version.");
267265
System.out.println();
268-
System.out.println("cobj-idx unlock <indexed file>");
266+
System.out.println("cobj-idx unlock <indexed file> [<indexed file>...]");
269267
System.out.println(" Unlock all locks of the indexed file.");
270268
System.out.println();
271269
System.out.println("Options:");

libcobj/bin/cobj-idx

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,6 @@
11
#!/bin/bash
22

3-
java jp.osscons.opensourcecobol.libcobj.user_util.indexed_file.IndexedFileUtilMain $@
3+
SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
4+
LIBCOBJ_JAR="$SCRIPT_DIR/../app/build/libs/libcobj.jar"
5+
6+
java -cp "$LIBCOBJ_JAR" jp.osscons.opensourcecobol.libcobj.user_util.indexed_file.IndexedFileUtilMain $@

tests/cobj-idx.src/migrate.at

Lines changed: 27 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ AT_DATA([check_file.cbl], [
77
ENVIRONMENT DIVISION.
88
INPUT-OUTPUT SECTION.
99
FILE-CONTROL.
10-
SELECT F ASSIGN TO "indexed_file.dat"
10+
SELECT F ASSIGN TO INDEX_FILE_PATH
1111
ORGANIZATION IS INDEXED
1212
ACCESS MODE IS DYNAMIC
1313
RECORD KEY IS REC-KEY
@@ -65,12 +65,36 @@ AT_CHECK([cp ../../cobj-idx.src/test-data/indexed_file.dat .])
6565
AT_CHECK([${COBJ_IDX} migrate indexed_file.dat])
6666

6767
# check the converted file
68-
AT_CHECK([${COMPILE} check_file.cbl])
69-
AT_CHECK([java check_file], [0],
68+
AT_CHECK([${COMPILE} --assign_external check_file.cbl])
69+
AT_CHECK([INDEX_FILE_PATH=indexed_file.dat java check_file], [0],
7070
[AAAA1BBBB1CCCC1
7171
AAAA2BBBB1CCCC1
7272
00
7373
AAAA1BBBB1CCCC1
7474
AAAA3BBBB3CCCC3
7575
])
76+
77+
# Test migrate with multiple files
78+
AT_CHECK([cp ../../cobj-idx.src/test-data/indexed_file.dat indexed_file2.dat])
79+
AT_CHECK([cp ../../cobj-idx.src/test-data/indexed_file.dat indexed_file3.dat])
80+
AT_CHECK([${COBJ_IDX} migrate indexed_file2.dat indexed_file3.dat])
81+
82+
# check that indexed_file2.dat works properly after migration
83+
AT_CHECK([INDEX_FILE_PATH=indexed_file2.dat java check_file], [0],
84+
[AAAA1BBBB1CCCC1
85+
AAAA2BBBB1CCCC1
86+
00
87+
AAAA1BBBB1CCCC1
88+
AAAA3BBBB3CCCC3
89+
])
90+
91+
# check that indexed_file3.dat works properly after migration
92+
AT_CHECK([INDEX_FILE_PATH=indexed_file3.dat java check_file], [0],
93+
[AAAA1BBBB1CCCC1
94+
AAAA2BBBB1CCCC1
95+
00
96+
AAAA1BBBB1CCCC1
97+
AAAA3BBBB3CCCC3
98+
])
99+
76100
AT_CLEANUP

tests/cobj-idx.src/unlock.at

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -170,4 +170,17 @@ AT_CHECK([java check_record_lock], [0],
170170
[00
171171
])
172172

173+
# Test unlock with multiple files
174+
AT_CHECK([rm -f indexed_file.dat indexed_file2.dat])
175+
# Create multiple locked files
176+
AT_CHECK([java create_and_exit])
177+
AT_CHECK([cp indexed_file.dat indexed_file2.dat])
178+
AT_CHECK([java create_and_exit]) # This will leave indexed_file.dat locked
179+
# Unlock multiple files
180+
AT_CHECK([${COBJ_IDX} unlock indexed_file.dat indexed_file2.dat])
181+
# Check both files are unlocked
182+
AT_CHECK([java check_file_lock], [0],
183+
[00
184+
])
185+
173186
AT_CLEANUP

0 commit comments

Comments
 (0)