Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -138,39 +138,37 @@ public static void main(String[] args) {
System.exit(1);
}
} else if ("migrate".equals(subCommand)) {
if (unrecognizedArgs.length != 2) {
if (unrecognizedArgs.length < 2) {
System.err.println("error: no indexed file is specified.");
} else {
System.err.println("error: too many indexed files are specified.");
}
if (unrecognizedArgs.length < 2) {
System.err.println("error: no indexed file is specified.");
System.exit(1);
}
String indexedFilePath = unrecognizedArgs[1];
try {
migrateIndexedFile(indexedFilePath);
} catch (Exception e) {
System.err.println("error: " + e.getMessage());
System.exit(1);
boolean hasError = false;
for (int i = 1; i < unrecognizedArgs.length; i++) {
String indexedFilePath = unrecognizedArgs[i];
try {
migrateIndexedFile(indexedFilePath);
} catch (Exception e) {
System.err.println("error: " + e.getMessage());
hasError = true;
}
}
System.exit(0);
System.exit(hasError ? 1 : 0);
} else if ("unlock".equals(subCommand)) {
if (unrecognizedArgs.length != 2) {
if (unrecognizedArgs.length < 2) {
System.err.println("error: no indexed file is specified.");
} else {
System.err.println("error: too many indexed files are specified.");
}
if (unrecognizedArgs.length < 2) {
System.err.println("error: no indexed file is specified.");
System.exit(1);
}
String indexedFilePath = unrecognizedArgs[1];
try {
unlockIndexedFile(indexedFilePath);
} catch (Exception e) {
System.err.println("error: " + e.getMessage());
System.exit(1);
boolean hasError = false;
for (int i = 1; i < unrecognizedArgs.length; i++) {
String indexedFilePath = unrecognizedArgs[i];
try {
unlockIndexedFile(indexedFilePath);
} catch (Exception e) {
System.err.println("error: " + e.getMessage());
hasError = true;
}
}
System.exit(0);
System.exit(hasError ? 1 : 0);
} else if ("load".equals(subCommand)) {
if (unrecognizedArgs.length < 2 || unrecognizedArgs.length > 3) {
if (unrecognizedArgs.length < 2) {
Expand Down Expand Up @@ -260,12 +258,12 @@ private static void printHelpMessage() {
" Write the records stored in the indexed file into the output file.");
System.out.println(" The default format of the output data is SEQUENTIAL of COBOL.");
System.out.println();
System.out.println("cobj-idx migrate <indexed file>");
System.out.println("cobj-idx migrate <indexed file> [<indexed file>...]");
System.out.println(
" Migrate the indexed file whose version is older than 1.1.12 to the latest"
+ " version.");
System.out.println();
System.out.println("cobj-idx unlock <indexed file>");
System.out.println("cobj-idx unlock <indexed file> [<indexed file>...]");
System.out.println(" Unlock all locks of the indexed file.");
System.out.println();
System.out.println("Options:");
Expand Down
5 changes: 4 additions & 1 deletion libcobj/bin/cobj-idx
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
#!/bin/bash

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

java -cp "$LIBCOBJ_JAR" jp.osscons.opensourcecobol.libcobj.user_util.indexed_file.IndexedFileUtilMain $@
30 changes: 27 additions & 3 deletions tests/cobj-idx.src/migrate.at
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ AT_DATA([check_file.cbl], [
ENVIRONMENT DIVISION.
INPUT-OUTPUT SECTION.
FILE-CONTROL.
SELECT F ASSIGN TO "indexed_file.dat"
SELECT F ASSIGN TO INDEX_FILE_PATH
ORGANIZATION IS INDEXED
ACCESS MODE IS DYNAMIC
RECORD KEY IS REC-KEY
Expand Down Expand Up @@ -65,12 +65,36 @@ AT_CHECK([cp ../../cobj-idx.src/test-data/indexed_file.dat .])
AT_CHECK([${COBJ_IDX} migrate indexed_file.dat])

# check the converted file
AT_CHECK([${COMPILE} check_file.cbl])
AT_CHECK([java check_file], [0],
AT_CHECK([${COMPILE} --assign_external check_file.cbl])
AT_CHECK([INDEX_FILE_PATH=indexed_file.dat java check_file], [0],
[AAAA1BBBB1CCCC1
AAAA2BBBB1CCCC1
00
AAAA1BBBB1CCCC1
AAAA3BBBB3CCCC3
])

# Test migrate with multiple files
AT_CHECK([cp ../../cobj-idx.src/test-data/indexed_file.dat indexed_file2.dat])
AT_CHECK([cp ../../cobj-idx.src/test-data/indexed_file.dat indexed_file3.dat])
AT_CHECK([${COBJ_IDX} migrate indexed_file2.dat indexed_file3.dat])

# check that indexed_file2.dat works properly after migration
AT_CHECK([INDEX_FILE_PATH=indexed_file2.dat java check_file], [0],
[AAAA1BBBB1CCCC1
AAAA2BBBB1CCCC1
00
AAAA1BBBB1CCCC1
AAAA3BBBB3CCCC3
])

# check that indexed_file3.dat works properly after migration
AT_CHECK([INDEX_FILE_PATH=indexed_file3.dat java check_file], [0],
[AAAA1BBBB1CCCC1
AAAA2BBBB1CCCC1
00
AAAA1BBBB1CCCC1
AAAA3BBBB3CCCC3
])

AT_CLEANUP
13 changes: 13 additions & 0 deletions tests/cobj-idx.src/unlock.at
Original file line number Diff line number Diff line change
Expand Up @@ -170,4 +170,17 @@ AT_CHECK([java check_record_lock], [0],
[00
])

# Test unlock with multiple files
AT_CHECK([rm -f indexed_file.dat indexed_file2.dat])
# Create multiple locked files
AT_CHECK([java create_and_exit])
AT_CHECK([cp indexed_file.dat indexed_file2.dat])
AT_CHECK([java create_and_exit]) # This will leave indexed_file.dat locked
# Unlock multiple files
AT_CHECK([${COBJ_IDX} unlock indexed_file.dat indexed_file2.dat])
# Check both files are unlocked
AT_CHECK([java check_file_lock], [0],
[00
])

AT_CLEANUP
Loading