Skip to content

Commit

Permalink
OutputType attribute in PCTCompile task
Browse files Browse the repository at this point in the history
  • Loading branch information
ankkumar-progress authored and gquerret committed Nov 23, 2019
1 parent ed3cb18 commit b813ce0
Show file tree
Hide file tree
Showing 23 changed files with 306 additions and 8 deletions.
10 changes: 10 additions & 0 deletions src/java/com/phenix/pct/CompilationAttributes.java
Expand Up @@ -67,6 +67,7 @@ public class CompilationAttributes implements ICompilationAttributes {
private String ignoredIncludes = null;
private int fileList = 0;
private String callback = null;
private String outputType = null;

// Internal use
private final PCT parent;
Expand Down Expand Up @@ -280,6 +281,11 @@ public void setCallbackClass(String callback) {
this.callback = callback;
}

@Override
public void setOutputType(String outputType) {
this.outputType = outputType;
}

public List<ResourceCollection> getResources() {
return resources;
}
Expand Down Expand Up @@ -432,6 +438,10 @@ public String getCallbackClass() {
return callback;
}

public String getOutputType() {
return outputType;
}

protected void writeCompilationProcedure(File f, Charset c) {
boolean bAbove1173 = parent.getVersion().compareTo(new DLCVersion(11, 7, "3")) >= 0;
try (FileOutputStream fos = new FileOutputStream(f);
Expand Down
5 changes: 5 additions & 0 deletions src/java/com/phenix/pct/CompilationWrapper.java
Expand Up @@ -320,6 +320,11 @@ public void setCallbackClass(String callback) {
compAttributes.setCallbackClass(callback);
}

@Override
public void setOutputType(String outputType) {
compAttributes.setOutputType(outputType);
}

// End of ICompilationAttributes methods
// *************************************

Expand Down
7 changes: 7 additions & 0 deletions src/java/com/phenix/pct/ICompilationAttributes.java
Expand Up @@ -224,4 +224,11 @@ public interface ICompilationAttributes {
* @param callback ABL Class
*/
void setCallbackClass(String callback);

/**
* json value will display the errors and warnings in json format
*
* @param outputType String
*/
void setOutputType(String outputType);
}
11 changes: 11 additions & 0 deletions src/java/com/phenix/pct/PCTBgCompile.java
Expand Up @@ -154,6 +154,16 @@ public void execute() {
log(Messages.getString("PCTCompile.92"), Project.MSG_WARN); //$NON-NLS-1$
}

if (compAttrs.getOutputType() != null
&& !"json".equalsIgnoreCase(compAttrs.getOutputType())) {
throw new BuildException(Messages.getString("PCTCompile.94"));
}

if (compAttrs.getOutputType() != null
&& "json".equalsIgnoreCase(compAttrs.getOutputType())) {
log(Messages.getString("PCTCompile.93"), Project.MSG_WARN);
}

initializeCompilationUnits();
compAttrs.writeCompilationProcedure(new File(compDir, "pctcomp.p"), getCharset());
getOptions().addPropath(new Path(getProject(), compDir.getAbsolutePath()));
Expand Down Expand Up @@ -342,6 +352,7 @@ private String getOptions() {
sb.append(Boolean.toString(compAttrs.isRequireFullNames())).append(';');
sb.append(Boolean.toString(compAttrs.isRequireFieldQualifiers())).append(';');
sb.append(compAttrs.getCallbackClass() == null ? "" : compAttrs.getCallbackClass()).append(';');
sb.append("").append(';'); // outputType is not supported on multi-threaded environment

return sb.toString();
}
Expand Down
9 changes: 9 additions & 0 deletions src/java/com/phenix/pct/PCTCompile.java
Expand Up @@ -230,6 +230,10 @@ private void writeParams() {
bw.write("CALLBACKCLASS=" + compAttrs.getCallbackClass());
bw.newLine();
}
if (compAttrs.getOutputType() != null) {
bw.write("OUTPUTTYPE=" + compAttrs.getOutputType());
bw.newLine();
}
} catch (IOException ioe) {
throw new BuildException(Messages.getString("PCTCompile.3"), ioe); //$NON-NLS-1$
}
Expand Down Expand Up @@ -312,6 +316,11 @@ public void execute() {
log(Messages.getString("PCTCompile.92"), Project.MSG_WARN); //$NON-NLS-1$
}

if (compAttrs.getOutputType() != null
&& !"json".equalsIgnoreCase(compAttrs.getOutputType())) {
throw new BuildException(Messages.getString("PCTCompile.94"));
}

checkDlcHome();

try {
Expand Down
2 changes: 2 additions & 0 deletions src/java/com/phenix/pct/messages.properties
Expand Up @@ -38,6 +38,8 @@ PCTCompile.48=Fileset directory {0} not found in PROPATH
PCTCompile.90=Ignoring appendStringXref because stringXref is not enabled
PCTCompile.91=Ignoring ProgPerc because of a not supported value: {0}
PCTCompile.92=Enabling xmlXref and stringXref will probably crash the AVM (OCTA-14756)
PCTCompile.93=Parameter outputType is not supported on multi-threaded environment
PCTCompile.94=outputType attribute is not set correctly

PCTConnection.0=Alias {0} already defined
PCTConnection.1=Database name or parameter file not defined
Expand Down
88 changes: 81 additions & 7 deletions src/progress/pct/compile.p
Expand Up @@ -19,6 +19,7 @@
&IF DECIMAL(SUBSTRING(PROVERSION, 1, INDEX(PROVERSION, '.') + 1)) GE 11.3 &THEN
USING Progress.Lang.Class.
&ENDIF
USING Progress.Json.ObjectModel.*.

&IF INTEGER(SUBSTRING(PROVERSION, 1, INDEX(PROVERSION, '.'))) GE 11 &THEN
{ pct/v11/xrefd0004.i}
Expand Down Expand Up @@ -68,6 +69,21 @@ DEFINE TEMP-TABLE ttErrors NO-UNDO
INDEX ttErrors-PK IS PRIMARY UNIQUE intNum
INDEX ttErrors-PK2 IS UNIQUE fileName rowNum colNum.

DEFINE TEMP-TABLE ttProjectWarnings NO-UNDO
FIELD msgNum AS INTEGER
FIELD rowNum AS INTEGER
FIELD fileName AS CHARACTER
FIELD mainFileName AS CHARACTER
FIELD msg AS CHARACTER.
DEFINE TEMP-TABLE ttProjectErrors NO-UNDO
FIELD fileName AS CHARACTER
FIELD mainFileName AS CHARACTER
FIELD rowNum AS INTEGER
FIELD colNum AS INTEGER
FIELD msg AS CHARACTER.

DEFINE DATASET dsResult FOR ttProjectErrors, ttProjectWarnings.

DEFINE SHARED VARIABLE pctVerbose AS LOGICAL NO-UNDO.

FUNCTION getTimeStampDF RETURN DATETIME (INPUT d AS CHARACTER, INPUT f AS CHARACTER) FORWARD.
Expand Down Expand Up @@ -120,6 +136,7 @@ DEFINE VARIABLE cIgnoredIncludes AS CHARACTER NO-UNDO.
DEFINE VARIABLE lIgnoredIncludes AS LOGICAL NO-UNDO.
DEFINE VARIABLE iFileList AS INTEGER NO-UNDO.
DEFINE VARIABLE callbackClass AS CHARACTER NO-UNDO.
DEFINE VARIABLE outputType AS CHARACTER NO-UNDO.

/* Handle to calling procedure in order to log messages */
DEFINE VARIABLE hSrcProc AS HANDLE NO-UNDO.
Expand Down Expand Up @@ -181,6 +198,7 @@ PROCEDURE setOption.
WHEN 'FILELIST':U THEN ASSIGN iFileList = INTEGER(ipValue).
WHEN 'NUMFILES':U THEN ASSIGN iTotLines = INTEGER(ipValue).
WHEN 'CALLBACKCLASS':U THEN ASSIGN callbackClass = ipValue.
WHEN 'OUTPUTTYPE':U THEN ASSIGN outputType = ipValue.

OTHERWISE RUN logError IN hSrcProc (SUBSTITUTE("Unknown parameter '&1' with value '&2'" ,ipName, ipValue)).
END CASE.
Expand Down Expand Up @@ -275,6 +293,7 @@ PROCEDURE compileXref.
DEFINE VARIABLE cRenameFrom AS CHARACTER NO-UNDO INITIAL ''.
DEFINE VARIABLE lWarnings AS LOGICAL NO-UNDO INITIAL FALSE.

EMPTY TEMP-TABLE ttWarnings. /* Emptying the temp-table to store warnings for current file*/
/* Output progress */
IF ProgPerc GT 0 THEN DO:
ASSIGN iLine = iLine + 1.
Expand Down Expand Up @@ -403,7 +422,6 @@ PROCEDURE compileXref.
/* Before 11.7.3, strict mode compiler was throwing errors. 11.7.3 introduced :warning and :error */
&IF DECIMAL(SUBSTRING(PROVERSION, 1, INDEX(PROVERSION, '.') + 1)) GE 11.7 &THEN
IF (cOpts GT "") AND bAboveEq117 AND (NOT bAboveEq1173) THEN DO:
EMPTY TEMP-TABLE ttWarnings.
COMPILE VALUE(IF lRelative THEN ipInFile ELSE ipInDir + '/':U + ipInFile) SAVE=FALSE OPTIONS cOpts NO-ERROR.
IF COMPILER:ERROR THEN DO i = 1 TO COMPILER:NUM-MESSAGES:
/* Messages 14786, 14789, 18494 are the only relevant ones */
Expand Down Expand Up @@ -451,13 +469,30 @@ PROCEDURE compileXref.
/* Messages 2363, 3619 and 3623 are in fact warnings (from -checkdbe switch) */
IF (COMPILER:GET-MESSAGE-TYPE(i) EQ 2) OR (COMPILER:GET-NUMBER(i) EQ 2363) OR (COMPILER:GET-NUMBER(i) EQ 3619) OR (COMPILER:GET-NUMBER(i) EQ 3623) THEN DO:
IF (LOOKUP(STRING(COMPILER:GET-NUMBER(i)), SESSION:SUPPRESS-WARNINGS-LIST) EQ 0) THEN DO:
PUT STREAM sWarnings UNFORMATTED SUBSTITUTE("[&1] [&3] &2", COMPILER:GET-ROW(i), REPLACE(COMPILER:GET-MESSAGE(i), '~n', ' '), COMPILER:GET-FILE-NAME(i)) SKIP.
CREATE ttWarnings.
ASSIGN ttWarnings.msgNum = COMPILER:GET-NUMBER(i)
ttWarnings.rowNum = COMPILER:GET-ROW(i)
ttWarnings.fileName = COMPILER:GET-FILE-NAME(i)
ttWarnings.msg = REPLACE(COMPILER:GET-MESSAGE(i), '~n', ' ').
END.
END.
END.
END.
FOR EACH ttWarnings:
PUT STREAM sWarnings UNFORMATTED SUBSTITUTE("[&1] [&3] &2", ttWarnings.rowNum, ttWarnings.msg, ttWarnings.fileName) SKIP.

IF ( outputType EQ 'json') THEN DO:
FOR EACH ttWarnings:
Create ttProjectWarnings.
ASSIGN ttProjectWarnings.msgNum = ttWarnings.msgNum
ttProjectWarnings.rowNum = ttWarnings.rowNum
ttProjectWarnings.fileName = REPLACE(ttWarnings.fileName, chr(92), '/')
ttProjectWarnings.msg = ttWarnings.msg
ttProjectWarnings.mainFileName = REPLACE(ipInDir + (if ipInDir eq '':U then '':U else '/':U) + ipInFile, chr(92), '/').
END.
END.
ELSE DO:
FOR EACH ttWarnings:
PUT STREAM sWarnings UNFORMATTED SUBSTITUTE("[&1] [&3] &2", ttWarnings.rowNum, ttWarnings.msg, ttWarnings.fileName) SKIP.
END.
END.
OUTPUT STREAM sWarnings CLOSE.
END.
Expand All @@ -466,7 +501,6 @@ PROCEDURE compileXref.
END.
END.
ELSE DO:
RUN logError IN hSrcProc (SUBSTITUTE("Error compiling file '&1' ...", REPLACE(ipInDir + (IF ipInDir EQ '':U THEN '':U ELSE '/':U) + ipInFile, CHR(92), '/':U))).
EMPTY TEMP-TABLE ttErrors.
DO i = 1 TO COMPILER:NUM-MESSAGES:
IF COMPILER:GET-NUMBER(i) EQ 198 THEN NEXT.
Expand All @@ -483,8 +517,22 @@ PROCEDURE compileXref.
END.
ASSIGN ttErrors.msg = ttErrors.msg + (IF ttErrors.msg EQ '' THEN '' ELSE '~n') + COMPILER:GET-MESSAGE(i).
END.
FOR EACH ttErrors:
RUN displayCompileErrors(ipInDir + (IF ipInDir EQ '':U THEN '':U ELSE '/':U) + ipInFile, ttErrors.fileName, ttErrors.rowNum, ttErrors.colNum, ttErrors.msg).

IF ( outputType EQ 'json' ) THEN DO:
FOR EACH ttErrors:
Create ttProjectErrors.
ASSIGN ttProjectErrors.fileName = REPLACE(ttErrors.fileName, chr(92), '/')
ttProjectErrors.mainFileName = REPLACE(ipInDir + (if ipInDir eq '':U then '':U else '/':U) + ipInFile, chr(92), '/')
ttProjectErrors.rowNum = ttErrors.rowNum
ttProjectErrors.colNum = ttErrors.colNum
ttProjectErrors.msg = ttErrors.msg.
END.
END.
ELSE DO:
RUN logError IN hSrcProc (SUBSTITUTE("Error compiling file '&1' ...", REPLACE(ipInDir + (IF ipInDir EQ '':U THEN '':U ELSE '/':U) + ipInFile, CHR(92), '/':U))).
FOR EACH ttErrors:
RUN displayCompileErrors(ipInDir + (IF ipInDir EQ '':U THEN '':U ELSE '/':U) + ipInFile, ttErrors.fileName, ttErrors.rowNum, ttErrors.colNum, ttErrors.msg).
END.
END.
END.
IF NOT keepXref THEN
Expand All @@ -499,6 +547,32 @@ PROCEDURE compileXref.

END PROCEDURE.

PROCEDURE printErrorsWarningsJson.

DEFINE INPUT PARAMETER iCompOK AS INTEGER NO-UNDO.
DEFINE INPUT PARAMETER iCompFail AS INTEGER NO-UNDO.

DEFINE VARIABLE hResult AS handle NO-UNDO.
DEFINE VARIABLE mptr AS MEMPTR NO-UNDO.
DEFINE VARIABLE dsJsonObj AS JsonObject NO-UNDO.
DEFINE VARIABLE outFile AS CHARACTER NO-UNDO.

IF ( outputType EQ 'json' ) THEN DO:
hResult = DATASET dsResult:handle.
hResult:WRITE-JSON("memptr", mptr).
dsJsonObj = CAST( NEW ObjectModelParser():Parse(mptr), JsonObject).
dsJsonObj = dsJsonObj:GetJsonObject("dsResult").

dsJsonObj:Add("compiledFiles", iCompOK).
dsJsonObj:Add("errorFiles", iCompFail).

ASSIGN outFile = PCTDir + '/':U + 'project-result.json':U.
dsJsonObj:WriteFile(outFile).
SET-SIZE(mptr) = 0.
END.

END PROCEDURE.

PROCEDURE displayCompileErrors PRIVATE:
DEFINE INPUT PARAMETER pcInit AS CHARACTER NO-UNDO.
DEFINE INPUT PARAMETER pcFile AS CHARACTER NO-UNDO.
Expand Down
3 changes: 3 additions & 0 deletions src/progress/pct/pctBgCompile.p
Expand Up @@ -60,6 +60,7 @@ PROCEDURE setOptions:
RUN setOption IN hComp ('FULLNAMES', IF ENTRY(33, ipPrm, ';') EQ 'true' THEN '1' ELSE '0').
RUN setOption IN hComp ('FIELDQLF', IF ENTRY(34, ipPrm, ';') EQ 'true' THEN '1' ELSE '0').
RUN setOption IN hComp ('CALLBACKCLASS', ENTRY(35, ipPrm, ';')).
RUN setOption IN hComp ('OUTPUTTYPE', ENTRY(36, ipPrm, ';')).

RUN initModule IN hComp.

Expand Down Expand Up @@ -112,6 +113,8 @@ PROCEDURE pctCompile:
ASSIGN opOK = (compNotOk EQ 0)
opMsg = STRING(compOK) + "/" + STRING(compNotOk) + "/" + STRING(skipped).

RUN printErrorsWarningsJson IN hComp (INPUT compOK, INPUT compNotOk).

END PROCEDURE.

PROCEDURE logError.
Expand Down
4 changes: 3 additions & 1 deletion src/progress/pct/pctCompile.p
Expand Up @@ -85,11 +85,13 @@ REPEAT:
IF StopOnErr THEN LEAVE CompLoop.
END.
ELSE IF (iMyComp GT 0) THEN
ASSIGN iCompOK = iCompOK + 1.
ASSIGN iCompOK = iCompOK + 1.
END.
END.
INPUT STREAM sFileset CLOSE.

RUN printErrorsWarningsJson IN hComp (INPUT iCompOK, INPUT iCompFail).

MESSAGE STRING(iCompOK) + " file(s) compiled".
IF (iCompFail GE 1) THEN
MESSAGE "Failed to compile " iCompFail " file(s)".
Expand Down
28 changes: 28 additions & 0 deletions src/test/com/phenix/pct/BuildFileTestNg.java
Expand Up @@ -16,7 +16,10 @@
*/
package com.phenix.pct;
import java.io.File;
import java.io.IOException;
import java.net.URL;
import java.nio.file.Files;
import java.nio.file.Paths;
import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;
Expand Down Expand Up @@ -177,6 +180,31 @@ public void expectLogRegexp(String target, List<String> regexps, boolean strict)
}
}

/**
* Assert that the content of given filename is identical to the expectedContent
*/
public void expectLogFileContent(String target, String file, String expectedContent) {
executeTarget(target);
this.expectLogFileContent(file, expectedContent);
}

/**
* Compares the content of the file with the expected content.
*/
public void expectLogFileContent(String file, String expectedContent) {
try {
String content = new String(
Files.readAllBytes(Paths.get(new File(file).getAbsolutePath())));
if (!content.equals(expectedContent)) {
Assert.fail("Log '" + content + "' doesn't match expected result '"
+ expectedContent + "'");
}
} catch (IOException e) {
Assert.fail("Error while accessing the file '" + file + "' with message "
+ e.getMessage());
}
}

/**
* Retrieve a resource from the caller classloader to avoid assuming a vm working directory. The
* resource path must be relative to the package name or absolute from the root path.
Expand Down
5 changes: 5 additions & 0 deletions src/test/com/phenix/pct/PCTCompileExtTest.java
Expand Up @@ -1249,6 +1249,11 @@ public void test78() {
}
}

@Test(groups = {"v10"})
public void test79() {
// No test case as 'outputType' attribute is not implemented in PCTCompileExt
}

@Test(groups = {"v10"})
public void test101() {
configureProject(BASEDIR + "test101/build.xml");
Expand Down

0 comments on commit b813ce0

Please sign in to comment.