Skip to content

Commit

Permalink
item #122 fixed for Windows
Browse files Browse the repository at this point in the history
  • Loading branch information
davenicolette committed Mar 13, 2021
1 parent 0ab3947 commit e95de4a
Show file tree
Hide file tree
Showing 19 changed files with 118 additions and 78 deletions.
1 change: 1 addition & 0 deletions cobolcheck.cmd
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
echo off
del CC##99*
java -jar bin\cobol-check-0.0.5.jar %*
if errorlevel 8 goto end
cobc -x CC##99.CBL && CC##99.exe
Expand Down
4 changes: 2 additions & 2 deletions config.properties
Original file line number Diff line number Diff line change
Expand Up @@ -34,13 +34,13 @@ test.suite.directory = src/test/cobol
#---------------------------------------------------------------------------------------------------------------------
# If application source filenames have a suffix, specify it here without the period or dot.
#---------------------------------------------------------------------------------------------------------------------
application.source.filename.suffix = CBL
application.source.filename.suffix = CBL,cbl,COB,cob

#---------------------------------------------------------------------------------------------------------------------
# If application copybook filenames have a suffix, specify it here without the period or dot
# e.g. application.copybook.filename.suffix = CBL
#---------------------------------------------------------------------------------------------------------------------
application.copybook.filename.suffix = CBL
application.copybook.filename.suffix = CBL,cbl,COB,cob

#---------------------------------------------------------------------------------------------------------------------
# Optional override of system default Locale for log messages and exception messages.
Expand Down
57 changes: 35 additions & 22 deletions src/main/java/com/neopragma/cobolcheck/Config.java
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@

import java.io.FileInputStream;
import java.io.IOException;
import java.util.ArrayList;
import java.util.List;
import java.util.Locale;
import java.util.Properties;

Expand All @@ -29,7 +31,7 @@
* @author Dave Nicolette (neopragma)
* @since 14
*/
public class Config {
public class Config implements StringHelper {

public static final String LOCALE_LANGUAGE_CONFIG_KEY = "locale.language";
public static final String LOCALE_COUNTRY_CONFIG_KEY = "locale.country";
Expand All @@ -41,6 +43,9 @@ public class Config {
public static final String APPLICATION_COPYBOOK_FILENAME_SUFFIX = "application.copybook.filename.suffix";
public static final String NONE = "none";
public static final String DEFAULT_CONFIG_FILE_PATH = "config.properties";
public static final String TEST_SUITE_DIRECTORY_CONFIG_KEY = "test.suite.directory";
public static final String APPLICATION_SOURCE_DIRECTORY_CONFIG_KEY = "application.source.directory";
public static final String DEFAULT_APPLICATION_SOURCE_DIRECTORY = "src/main/cobol";

public Config(Messages messages) {
this.messages = messages;
Expand Down Expand Up @@ -70,7 +75,7 @@ void load(String configResourceName) {
setDefaultLocaleOverride();
Log.info(messages.get("INF002", configResourceName));

setApplicationFilenameSuffix();
setApplicationFilenameSuffixes();
setCopybookFilenameSuffix();
}

Expand All @@ -92,34 +97,42 @@ Messages getMessages() {
return messages;
}

String getApplicationFilenameSuffix() {
return settings.getProperty(RESOLVED_APPLICATION_SOURCE_FILENAME_SUFFIX);
String getTestSuiteDirectoryPathString() {
return adjustPathString(settings.getProperty(TEST_SUITE_DIRECTORY_CONFIG_KEY, Constants.CURRENT_DIRECTORY));
}

private void setApplicationFilenameSuffix() {
String propertyValue = Constants.EMPTY_STRING;
String suffix = getString(
APPLICATION_SOURCE_FILENAME_SUFFIX,
NONE);
if (!suffix.equalsIgnoreCase(NONE)) {
propertyValue = Constants.PERIOD + suffix;
}
settings.put(RESOLVED_APPLICATION_SOURCE_FILENAME_SUFFIX, propertyValue);
String getApplicationSourceDirectoryPathString() {
return adjustPathString(settings.getProperty(APPLICATION_SOURCE_DIRECTORY_CONFIG_KEY,
DEFAULT_APPLICATION_SOURCE_DIRECTORY));
}

List<String> getApplicationFilenameSuffixes() {
return (List<String>) settings.get(RESOLVED_APPLICATION_SOURCE_FILENAME_SUFFIX);
}

String getCopybookFilenameSuffix() {
return settings.getProperty(RESOLVED_APPLICATION_COPYBOOK_FILENAME_SUFFIX);
private void setApplicationFilenameSuffixes() {
resolveFilenameSuffixes(APPLICATION_SOURCE_FILENAME_SUFFIX, RESOLVED_APPLICATION_SOURCE_FILENAME_SUFFIX);
}

List<String> getCopybookFilenameSuffixes() {
return (List<String>) settings.get(RESOLVED_APPLICATION_COPYBOOK_FILENAME_SUFFIX);
}

private void setCopybookFilenameSuffix() {
String propertyValue = Constants.EMPTY_STRING;
String suffix = getString(
APPLICATION_COPYBOOK_FILENAME_SUFFIX,
NONE);
if (!suffix.equalsIgnoreCase(NONE)) {
propertyValue = Constants.PERIOD + suffix;
resolveFilenameSuffixes(APPLICATION_COPYBOOK_FILENAME_SUFFIX, RESOLVED_APPLICATION_COPYBOOK_FILENAME_SUFFIX);
}

private void resolveFilenameSuffixes(String configKey, String resolvedConfigKey) {
String suffixSpecification = getString(configKey, NONE);
List<String> suffixes = new ArrayList();
String[] suffixValues = null;
if (!suffixSpecification.equalsIgnoreCase(NONE)) {
suffixValues = suffixSpecification.split(Constants.COMMA);
for (String suffixValue : suffixValues) {
suffixes.add(Constants.PERIOD + suffixValue);
}
}
settings.put(RESOLVED_APPLICATION_COPYBOOK_FILENAME_SUFFIX, propertyValue);
settings.put(resolvedConfigKey, suffixes);
}

private void setDefaultLocaleOverride() {
Expand Down
6 changes: 0 additions & 6 deletions src/main/java/com/neopragma/cobolcheck/Constants.java
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@ private Constants() {
}

// File read status values
public static final int END_OF_STREAM = -1;
public static final int STATUS_NORMAL = 0;
public static final int STATUS_HALT = 8;

Expand Down Expand Up @@ -75,13 +74,8 @@ private Constants() {
public static final String LESS_THAN_EQUAL_TO_SIGN_KEYWORD = "<=";

// Configuration key values
public static final String TEST_SUITE_DIRECTORY_CONFIG_KEY = "test.suite.directory";
public static final String CONCATENATED_TEST_SUITES_CONFIG_KEY = "concatenated.test.suites";
public static final String DEFAULT_CONCATENATED_TEST_SUITES_PATH = "./ALLTESTS";
public static final String APPLICATION_SOURCE_DIRECTORY_CONFIG_KEY = "application.source.directory";
public static final String DEFAULT_APPLICATION_SOURCE_DIRECTORY = "src/main/cobol";
public static final String APPLICATION_COPYBOOK_FILENAME_SUFFIX_KEY = "application.copybook.filename.suffix";
public static final String DEFAULT_APPLICATION_COPYBOOK_FILENAME_SUFFIX = ".CBL";
public static final String TEST_PROGRAM_NAME_CONFIG_KEY = "cobolcheck.test.program.name";
public static final String DEFAULT_TEST_PROGRAM_NAME = "CC$$99.CBL";
public static final String COBOLCHECK_SCRIPT_DIRECTORY_CONFIG_KEY = "cobolcheck.script.directory";
Expand Down
26 changes: 16 additions & 10 deletions src/main/java/com/neopragma/cobolcheck/CopybookExpander.java
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,8 @@
import com.neopragma.cobolcheck.exceptions.PossibleInternalLogicErrorException;

import java.io.*;
import java.nio.file.Path;
import java.nio.file.Files;
import java.nio.file.Paths;
import java.util.Arrays;
import java.util.List;
import java.util.StringTokenizer;
Expand Down Expand Up @@ -47,37 +48,42 @@ public class CopybookExpander implements StringHelper {
private final Config config;
private final Messages messages;
private final String pathToCopybooks;
private final List<String> copybookFilenameSuffixes;


public CopybookExpander(Config config, Messages messages) {
this.config = config;
this.messages = messages;
pathToCopybooks = getPathToCopybooks();
copybookFilenameSuffixes = config.getCopybookFilenameSuffixes();

}

public Writer expand(Writer expandedSource,
String copybookFilename,
String copybookFilenameSuffix) throws IOException {
String copybookFilename) throws IOException {
return expand(expandedSource,
copybookFilename,
copybookFilenameSuffix,
new StringTuple(null, null));
}

public Writer expand(Writer expandedSource,
String copybookFilename,
String copybookFilenameSuffix,
StringTuple... textReplacement) throws IOException {
try(BufferedReader copybookReader = new BufferedReader(new FileReader(
new File(pathToCopybooks
+ copybookFilename
+ copybookFilenameSuffix)))) {
String fullPath = pathToCopybooks + copybookFilename;
for (String suffix : copybookFilenameSuffixes) {
if (Files.isRegularFile(Paths.get(fullPath + suffix))) {
fullPath += suffix;
break;
}
}
try (BufferedReader copybookReader = new BufferedReader(new FileReader(new File(fullPath)))) {
String sourceLine;
while ((sourceLine = copybookReader.readLine()) != null) {
// Nested COPY
if (copyStatementIsPresentIn(sourceLine)) {
String copybookName = extractCopybookNameFrom(sourceLine);
sourceLine = commentOut(sourceLine);
expandedSource = expand(expandedSource, copybookName, copybookFilenameSuffix, textReplacement);
expandedSource = expand(expandedSource, copybookName, textReplacement);
}
// COPY REPLACING
if (!textReplacement[0].isEmpty()) {
Expand Down
30 changes: 18 additions & 12 deletions src/main/java/com/neopragma/cobolcheck/Driver.java
Original file line number Diff line number Diff line change
Expand Up @@ -93,16 +93,15 @@ void run() throws InterruptedException {
*/
void runTestSuites() throws InterruptedException {
// all test suites are located under this directory
String testSuiteDirectory =
config.getString(Constants.TEST_SUITE_DIRECTORY_CONFIG_KEY, Constants.CURRENT_DIRECTORY);
String testSuiteDirectory = config.getTestSuiteDirectoryPathString();
if (!testSuiteDirectory.endsWith(Constants.FILE_SEPARATOR)) {
testSuiteDirectory += Constants.FILE_SEPARATOR;
}

String programNames = options.getValueFor(Constants.PROGRAMS_OPTION);
String[] programNamesSeparated = programNames.split(Constants.COLON);

// find subdirectories that match program names
// Find test subdirectories that match program names
List<String> matchingDirectories;
for (String programName : programNamesSeparated) {
Path path = Paths.get(programName);
Expand All @@ -125,19 +124,26 @@ void runTestSuites() throws InterruptedException {
new TestSuiteConcatenator(config, options);
testSuite = concatenator.concatenateTestSuites(matchingDirectory);

// create READER for the Cobol source program to be tested
// Create READER for the Cobol source program to be tested
StringBuilder cobolSourceInPath = new StringBuilder();
cobolSourceInPath.append(config.getString(
Constants.APPLICATION_SOURCE_DIRECTORY_CONFIG_KEY,
Constants.DEFAULT_APPLICATION_SOURCE_DIRECTORY));
cobolSourceInPath.append(System.getProperty("user.dir"));
cobolSourceInPath.append(Constants.FILE_SEPARATOR);
cobolSourceInPath.append(config.getApplicationSourceDirectoryPathString());
if (!cobolSourceInPath.toString().endsWith(Constants.FILE_SEPARATOR)) {
cobolSourceInPath.append(Constants.FILE_SEPARATOR);
}
cobolSourceInPath.append(programName);
cobolSourceInPath.append(config.getApplicationFilenameSuffix());
String cobolSourceInPathString = adjustPathString(cobolSourceInPath.toString());

Log.debug("Driver.runTestSuites() cobolSourceInPath: <" + cobolSourceInPathString + ">");
List<String> applicationFilenameSuffixes = config.getApplicationFilenameSuffixes();
for (String suffix : applicationFilenameSuffixes) {
Log.debug("Driver looking for source file <" + cobolSourceInPath.toString() + suffix + ">");
if (Files.isRegularFile(Paths.get(cobolSourceInPath.toString() + suffix))) {
cobolSourceInPath.append(suffix);
Log.debug("Driver recognized this file as a regular file: <" + cobolSourceInPath.toString() + ">");
break;
}
}
String cobolSourceInPathString = adjustPathString(cobolSourceInPath.toString());

try {
cobolSourceIn = new FileReader(cobolSourceInPathString);
Expand All @@ -146,7 +152,7 @@ void runTestSuites() throws InterruptedException {
messages.get("ERR018", programName));
}

// create WRITER for the test source program (copy of program to be tested plus test code)
// Create WRITER for the test source program (copy of program to be tested plus test code)
StringBuilder testSourceOutPath = new StringBuilder();
testSourceOutPath.append(new File(Constants.EMPTY_STRING).getAbsolutePath());
testSourceOutPath.append(Constants.FILE_SEPARATOR);
Expand All @@ -171,7 +177,7 @@ void runTestSuites() throws InterruptedException {
messages.get("ERR017", programName));
}

// compile and run the test program
// Compile and run the test program
String processConfigKeyPrefix;
ProcessLauncher launcher = null;
switch (PlatformLookup.get()) {
Expand Down
3 changes: 0 additions & 3 deletions src/main/java/com/neopragma/cobolcheck/Generator.java
Original file line number Diff line number Diff line change
Expand Up @@ -561,9 +561,6 @@ List<String> collectExpandedCopyStatements(List<String> copyTokens) {
expandedLines = (StringWriter) copybookExpander.expand(
expandedLines,
copybookName,
Constants.PERIOD + config.getString(
Constants.APPLICATION_COPYBOOK_FILENAME_SUFFIX_KEY,
Constants.DEFAULT_APPLICATION_COPYBOOK_FILENAME_SUFFIX),
replacingValues);
BufferedReader reader = new BufferedReader(new StringReader(expandedLines.toString()));
String line = reader.readLine();
Expand Down
3 changes: 1 addition & 2 deletions src/main/java/com/neopragma/cobolcheck/GetOpt.java
Original file line number Diff line number Diff line change
Expand Up @@ -53,8 +53,7 @@ public GetOpt(String[] args, String optionsString, Config config) {
options = new HashMap<>();
if (isEmptyArray(args)) return;
this.messages = config.getMessages();
applicationSourceDirectory = config.getString(
Constants.APPLICATION_SOURCE_DIRECTORY_CONFIG_KEY, Constants.DEFAULT_APPLICATION_SOURCE_DIRECTORY);
applicationSourceDirectory = config.getApplicationSourceDirectoryPathString();
storeOptionSettings(optionsString);
processCommandLineArgumentArray(args);
}
Expand Down
12 changes: 9 additions & 3 deletions src/main/java/com/neopragma/cobolcheck/StringHelper.java
Original file line number Diff line number Diff line change
Expand Up @@ -77,12 +77,18 @@ default String fixedLength(String sourceLine) {
* @return path string value with platform-specific file separator characters
*/
default String adjustPathString(String pathString) {
Log.debug("StringHelper.adjustPathString() original string: <" + ">");
Log.debug("StringHelper.adjustPathString() original string: <" + pathString + ">");
Log.debug("StringHelper.adjustPathString() Constants.FILE_SEPARATOR: <" + Constants.FILE_SEPARATOR + ">");

Log.debug("StringHelper.adjustPathString() os.name is <" + System.getProperty("os.name") + ">");

String result = pathString;
if (System.getProperty("os.name").toLowerCase(Locale.ROOT).startsWith("win")) {
return pathString.replace("/", "\\");
result = pathString.replace("/", "\\");
} else {
return pathString.replace("\\", "/");
result = pathString.replace("\\", "/");
}
Log.debug("StringHelper.adjustStringPath() result is <" + result + ">");
return result;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ ERR014 = ERR014: TestSuiteConcatenator.concatenateTestSuites() caught IOExceptio
ERR015 = ERR015: TestSuiteConcatenator.concatenateTestSuites() caught IOException while converting the concatenated testsuite file from WRITER to READER.
ERR016 = ERR016: Driver caught IOException while creating the WRITER to produce the test program for %1$s.
ERR017 = ERR017: Driver caught IOException while closing the WRITER for test program %1$s after returning from merge.
ERR018 = ERR018: Driver caught IOException attempting to create READER for the program under test %1$s.
ERR018 = ERR018: Driver caught IOException attempting to create READER for the program under test <%1$s>.
ERR019 = ERR019: Driver caught IOException while walking the testsuite directory tree for the program under test %1$s.
ERR020 = ERR020: LinuxProcessLauncher was invoked without a test program name.
ERR021 = ERR021: No script name found in config for key %1$s.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ ERR014 = ERR014: TestSuiteConcatenator.concatenateTestSuites() hat beim Lesen vo
ERR015 = ERR015: TestSuiteConcatenator.concatenateTestSuites() hat beim Konvertieren der verketteten Testsuite-Datei von WRITER nach READER eine IOException abgefangen.
ERR016 = ERR016: Driver hat beim Erstellen des WRITER eine IOException abgefangen, um das Testprogramm für %1$s zu erstellen.
ERR017 = ERR017: Driver hat die IOException abgefangen, als er den WRITER für das Testprogramm %1$s geschlossen hat, nachdem er von der Zusammenführung zurückgekehrt ist.
ERR018 = ERR018: Driver hat die IOException beim Versuch, READER für das zu testende Programm %1$s zu erstellen, abgefangen.
ERR018 = ERR018: Driver hat die IOException beim Versuch, READER für das zu testende Programm <%1$s> zu erstellen, abgefangen.
ERR019 = ERR019: Driver hat die IOException abgefangen, als er den Verzeichnisbaum der Testsuite für das zu testende Programm %1$s durchgesehen hat.
ERR020 = ERR020: LinuxProcessLauncher wurde ohne Namen eines Testprogramms aufgerufen.
ERR021 = ERR021: In der Konfiguration wurde kein Skriptname für Schlüssel %1$s gefunden.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ ERR014 = ERR014: TestSuiteConcatenator.concatenateTestSuites() detectó IOExcept
ERR015 = ERR015: TestSuiteConcatenator.concatenateTestSuites () detectó IOException al convertir el archivo concatenado de testsuite de WRITER a READER.
ERR016 = ERR016: Driver detectó IOException mientras creaba el WRITER para producir el programa de prueba para %1$s.
ERR017 = ERR017: Driver detectó IOException al cerrar WRITER para el programa de prueba %1$s después de regresar de la fusión.
ERR018 = ERR018: Driver detectó IOException al intentar crear un READER para el programa bajo prueba %1$s.
ERR018 = ERR018: Driver detectó IOException al intentar crear un READER para el programa bajo prueba <%1$s>.
ERR019 = ERR019: Driver detectó IOException mientras recorría el árbol de directorios de testsuite para el programa bajo prueba %1$s.
ERR020 = ERR020: LinuxProcessLauncher se invocó sin un nombre de programa de prueba.
ERR021 = ERR021: No se encontró ningún nombre de secuencia de comandos en la configuración para la clave %1$s.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ ERR014 = ERR014: TestSuiteConcatenator.concatenateTestSuites() sai IOExceptionin
ERR015 = ERR015: TestSuiteConcatenator.concatenateTestSuites() sai kiinni IOExceptionin muunnettaessa ketjutettua testsuite WRITER stä READER ksi.
ERR016 = ERR016: Driver tarttui IOExceptioniin luodessaan WRITER-sovelluksen tuottamaan testiohjelman kohteelle %1$s.
ERR017 = ERR017: Driver tarttui IOExceptionin sulkemaan WRITER testiohjelmalle %1$s.
ERR018 = ERR018: Driver tarttui IOExceptioniin yrittäessään luoda READER testattavalle ohjelmalle %1$s.
ERR018 = ERR018: Driver tarttui IOExceptioniin yrittäessään luoda READER testattavalle ohjelmalle <%1$s>.
ERR019 = ERR019: Driver tarttui IOExceptioniin kävellessään testattavan ohjelman %1$s testsuite-hakemistopuussa.
ERR020 = ERR020: LinuxProcessLauncher käynnistettiin ilman testiohjelman nimeä.
ERR021 = ERR021: Avaimen %1$s määrityksestä ei löytynyt komentosarjan nimeä.
Expand Down
Loading

0 comments on commit e95de4a

Please sign in to comment.