Skip to content

Commit

Permalink
Merge pull request #656 from smeup/bugfix/analytics__logs_no_longer_s…
Browse files Browse the repository at this point in the history
…hown

Bugfix: analytics logs no longer shown
  • Loading branch information
lanarimarco authored Nov 7, 2024
2 parents 241d8a4 + e90ccc2 commit 8742c54
Show file tree
Hide file tree
Showing 4 changed files with 32 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,14 @@
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* https://www.apache.org/licenses/LICENSE-2.0
* https://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
*/

package com.smeup.rpgparser.interpreter
Expand Down Expand Up @@ -67,6 +68,12 @@ interface InterpreterCore {
fun optimizedIntExpression(expression: Expression): () -> Long
fun enterCondition(index: Value, end: Value, downward: Boolean): Boolean
fun increment(dataDefinition: AbstractDataDefinition, amount: Long): Value
/***
* This method is called when the interpretation of the first program of the stack is ended
* There is no warranty that this method is called unless you use:
* com.smeup.rpgparser.execution.CommandLineProgram.singleCall
* methods
*/
fun onInterpretationEnd()
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,9 @@ class ProgramInterpreter(val systemInterface: SystemInterface) {
MainExecutionContext.getProgramStack().push(rpgProgram)
rpgProgram.execute(systemInterface = systemInterface, params = initialValues)
MainExecutionContext.getProgramStack().pop()
if (MainExecutionContext.getProgramStack().isEmpty()) {
rpgProgram.intepreterCore.onInterpretationEnd()
}
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,14 @@
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* https://www.apache.org/licenses/LICENSE-2.0
* https://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
*/

package com.smeup.rpgparser.interpreter
Expand Down Expand Up @@ -176,10 +177,6 @@ class RpgProgram(val cu: CompilationUnit, val name: String = "<UNNAMED RPG PROGR
logHandlers.renderLog(LazyLogEntry.produceStatement(logSource, "INTERPRETATION", "END"))
logHandlers.renderLog(LazyLogEntry.producePerformanceAndUpdateAnalytics(logSource, ProgramUsageType.Interpretation, "INTERPRETATION", elapsed))
}
if (MainExecutionContext.getProgramStack().isEmpty()) {
interpreter.onInterpretationEnd()
}

return changedInitialValues
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,14 @@
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* https://www.apache.org/licenses/LICENSE-2.0
* https://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
*/

package com.smeup.rpgparser.logging
Expand Down Expand Up @@ -293,4 +294,21 @@ class LoggingTest : AbstractTest() {
null
)
}

/**
* Test if analytics logs are overwritten through the setting of [com.smeup.rpgparser.execution.JarikoCallback.logInfo]
* */
@Test
fun analyticsChannelLogInfo() {
val configuration = Configuration()
var logInfCalled = false
configuration.jarikoCallback.logInfo = { _, _ ->
logInfCalled = true
}
val systemInterface = JavaSystemInterface(configuration = configuration).apply {
loggingConfiguration = consoleLoggingConfiguration(LogChannel.ANALYTICS)
}
executePgm(programName = "HELLO", configuration = configuration, systemInterface = systemInterface)
assertTrue(logInfCalled, "logInfo never called")
}
}

0 comments on commit 8742c54

Please sign in to comment.