From ded284f7d277c2b6a87fcf127ce3303bc30125c1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Alex=20L=C3=BCpges?= Date: Fri, 18 Oct 2024 11:43:09 +0200 Subject: [PATCH] Test up-to-date-checks, Future-Port Reporting --- monticore-generator/README.md | 8 + monticore-generator/build.gradle | 2 +- .../monticore-runtime-fix/build.gradle | 56 ++ .../templateengine/reporting/Reporting.java} | 63 +-- .../commons/IReportEventHandler.java | 309 +++++++++++ .../reporting/commons/ReportLogHookFix.java | 35 +- .../reporting/commons/ReportManager.java | 490 ++++++++++++++++++ monticore-generator/settings.gradle | 1 + .../java/de/monticore/MontiCoreScript.java | 12 +- .../java/de/monticore/cli/MontiCoreTool.java | 6 +- .../reporting/fix/Reporting.java | 20 - .../monticore/gradle/gen/MCToolInvoker.java | 4 +- .../de/monticore/tagging/TagGenerator.java | 6 +- .../de/monticore/MontiCoreScriptTest.java | 6 +- .../de/monticore/cli/MontiCoreToolTest.java | 4 +- .../codegen/parser/ParserGeneratorTest.java | 6 +- .../de/monticore/gradle/MCGenPluginTest.java | 40 +- .../templateengine/reporting/Reporting.java | 1 + .../de/monticore/io/FileReaderWriter.java | 4 + 19 files changed, 958 insertions(+), 115 deletions(-) create mode 100644 monticore-generator/README.md create mode 100644 monticore-generator/monticore-runtime-fix/build.gradle rename monticore-generator/{src/main/java/de/monticore/generating/templateengine/reporting/ReportingFix.java => monticore-runtime-fix/src/main/java/de/monticore/generating/templateengine/reporting/Reporting.java} (92%) create mode 100644 monticore-generator/monticore-runtime-fix/src/main/java/de/monticore/generating/templateengine/reporting/commons/IReportEventHandler.java rename monticore-generator/{ => monticore-runtime-fix}/src/main/java/de/monticore/generating/templateengine/reporting/commons/ReportLogHookFix.java (93%) create mode 100644 monticore-generator/monticore-runtime-fix/src/main/java/de/monticore/generating/templateengine/reporting/commons/ReportManager.java delete mode 100644 monticore-generator/src/main/java/de/monticore/generating/templateengine/reporting/fix/Reporting.java diff --git a/monticore-generator/README.md b/monticore-generator/README.md new file mode 100644 index 0000000000..409bf302dd --- /dev/null +++ b/monticore-generator/README.md @@ -0,0 +1,8 @@ + + +This subproject contains fixes from the current monticore-runtime snapshot, + which are also required in the currently used, last stable, monticore-runtime. +These "future-ports" are required due to us using the latest se-commons snapshot with the last stable runtime. + +The following changes are included: +* Adapt reporting to be based on LogHooks (shipped with runtime 7.7.0) diff --git a/monticore-generator/build.gradle b/monticore-generator/build.gradle index 638468a5f7..c31c907830 100644 --- a/monticore-generator/build.gradle +++ b/monticore-generator/build.gradle @@ -38,7 +38,7 @@ dependencies { implementation "de.se_rwth.commons:se-commons-gradle:$se_commons_version" - implementation "de.monticore:monticore-runtime:$previous_mc_version" + implementation project(":monticore-runtime-fix") // The previous runtime, but with future-ported fixes implementation "de.monticore:monticore-grammar:$previous_mc_version" implementation "de.se_rwth.commons:se-commons-groovy:$se_commons_version" implementation "de.se_rwth.commons:se-commons-logging:$se_commons_version" diff --git a/monticore-generator/monticore-runtime-fix/build.gradle b/monticore-generator/monticore-runtime-fix/build.gradle new file mode 100644 index 0000000000..043fdc4ae3 --- /dev/null +++ b/monticore-generator/monticore-runtime-fix/build.gradle @@ -0,0 +1,56 @@ +/* (c) https://github.com/MontiCore/monticore */ +plugins { + id "java-library" + id "maven-publish" +} +group = "de.monticore" + +dependencies { + // Use the previous monticore runtime + implementation "de.monticore:monticore-runtime:$previous_mc_version" + // but the current se-commons + implementation 'de.se_rwth.commons:se-commons-logging:' + se_commons_version + // Due to this, some fixes are required - see src/main/java +} + +repositories { + if (("true").equals(getProperty('useLocalRepo'))) { + mavenLocal() + } + maven { + url repo + } + mavenCentral() +} + +tasks.withType(JavaCompile) { + sourceCompatibility = JavaVersion.VERSION_11 + targetCompatibility = JavaVersion.VERSION_11 + options.encoding = "UTF-8" + options.deprecation false + options.warnings = false +} +java { + withSourcesJar() + toolchain { + languageVersion = JavaLanguageVersion.of(11) + } +} + +publishing { + publications { + maven(MavenPublication) { + groupId = project.group + artifactId = 'monticore-previous-runtime-fix' + version = project.version + from components.java + } + } + repositories.maven { + credentials.username mavenUser + credentials.password mavenPassword + def releasesRepoUrl = "https://nexus.se.rwth-aachen.de/content/repositories/monticore-releases/" + def snapshotsRepoUrl = "https://nexus.se.rwth-aachen.de/content/repositories/monticore-snapshots/" + url = version.endsWith('SNAPSHOT') ? snapshotsRepoUrl : releasesRepoUrl + } +} diff --git a/monticore-generator/src/main/java/de/monticore/generating/templateengine/reporting/ReportingFix.java b/monticore-generator/monticore-runtime-fix/src/main/java/de/monticore/generating/templateengine/reporting/Reporting.java similarity index 92% rename from monticore-generator/src/main/java/de/monticore/generating/templateengine/reporting/ReportingFix.java rename to monticore-generator/monticore-runtime-fix/src/main/java/de/monticore/generating/templateengine/reporting/Reporting.java index 008d572c85..f39e1a7aee 100644 --- a/monticore-generator/src/main/java/de/monticore/generating/templateengine/reporting/ReportingFix.java +++ b/monticore-generator/monticore-runtime-fix/src/main/java/de/monticore/generating/templateengine/reporting/Reporting.java @@ -24,7 +24,8 @@ * Facade for all reporting activities. Invoking a report method causes all * AReporter implementing this method to execute it. */ -public class ReportingFix extends Log { +@SuppressWarnings("unused") +public class Reporting extends Log { /* whether reporting is enabled at the moment */ protected static boolean enabled = false; @@ -54,6 +55,7 @@ public static void init(String outputDirectory, String reportDirectory, ReportMa public static void init(String reportDirectory, ReportManagerFactory factory) { Log.ensureInitialization(); + getReportHooks().clear(); addReportHook(new ReportLogHookFix(reportDirectory, factory)); wasInitialized = true; } @@ -552,36 +554,6 @@ public static void reportTemplateReplacement(String oldTemplate, List ast, List beforeHps) { - if (isEnabled()) { - for (ReportLogHookFix hook : getReportHooks()) { - hook.reportSetBeforeTemplate(template, ast, beforeHps); - } - } - } - - /** - * Reports the addition of hook points to a template via - * {@link de.monticore.generating.templateengine.GlobalExtensionManagement#setAfterTemplate(String, List)}. - * This does not include any other assignment or replacement. - */ - /* TODO: Re-add once #4095 is upstream (7.7.0 release) - public static void reportSetAfterTemplate(String template, Optional ast, List afterHps) { - if (isEnabled()) { - for (ReportLogHookFix hook : getReportHooks()) { - hook.reportSetAfterTemplate(template, ast, afterHps); - } - } - } - */ - /** * Reports the assignment of hook points to a template via * {@link de.monticore.generating.templateengine.GlobalExtensionManagement#setBeforeTemplate(String, List)}. @@ -590,7 +562,7 @@ public static void reportSetAfterTemplate(String template, Optional ast public static void reportSetBeforeTemplate(String template, List beforeHps) { if (isEnabled()) { for (ReportLogHookFix hook : getReportHooks()) { - hook.reportSetBeforeTemplate(template, beforeHps); + hook.reportSetBeforeTemplate(template, Optional.empty(), beforeHps); } } } @@ -603,7 +575,7 @@ public static void reportSetBeforeTemplate(String template, List afterHps) { if (isEnabled()) { for (ReportLogHookFix hook : getReportHooks()) { - hook.reportSetAfterTemplate(template, afterHps); + hook.reportSetAfterTemplate(template, Optional.empty(), afterHps); } } } @@ -617,11 +589,11 @@ public static void reportUseHandwrittenCodeFile(Path parentDir, Path fileName) { } - /** + /** * Reports the assignment of hook points to a template via * {@link de.monticore.generating.templateengine.GlobalExtensionManagement#setAfterTemplate(String, List)}. * This does not include any other assignment or replacement. - */ /* TODO: Re-add once #4095 is upstream (7.7.0 release) + */ public static void reportAddAfterTemplate(String template, Optional ast, List afterHps) { if (isEnabled()) { for (ReportLogHookFix hook : getReportHooks()) { @@ -634,25 +606,25 @@ public static void reportAddAfterTemplate(String template, Optional ast * Reports the assignment of hook points to a template via * {@link de.monticore.generating.templateengine.GlobalExtensionManagement#setAfterTemplate(String, List)}. * This does not include any other assignment or replacement. - */ /* TODO: Re-add once #4095 is upstream (7.7.0 release) - public static void reportAddBeforeTemplate(String template, Optional ast, List afterHps) { + */ + @Deprecated + public static void reportAddAfterTemplate(String template, List afterHps) { if (isEnabled()) { for (ReportLogHookFix hook : getReportHooks()) { - hook.reportAddBeforeTemplate(template, ast, afterHps); + hook.reportAddAfterTemplate(template, Optional.empty(), afterHps); } } } - */ /** * Reports the assignment of hook points to a template via * {@link de.monticore.generating.templateengine.GlobalExtensionManagement#setAfterTemplate(String, List)}. * This does not include any other assignment or replacement. - */ /* TODO: Re-add once #4095 is upstream (7.7.0 release) - public static void reportAddAfterTemplate(String template, Optional ast, List afterHps) { + */ + public static void reportAddBeforeTemplate(String template, Optional ast, List afterHps) { if (isEnabled()) { for (ReportLogHookFix hook : getReportHooks()) { - hook.reportAddAfterTemplate(template, ast, afterHps); + hook.reportAddBeforeTemplate(template, ast, afterHps); } } } @@ -661,11 +633,12 @@ public static void reportAddAfterTemplate(String template, Optional ast * Reports the assignment of hook points to a template via * {@link de.monticore.generating.templateengine.GlobalExtensionManagement#setAfterTemplate(String, List)}. * This does not include any other assignment or replacement. - */ /* TODO: Re-add once #4095 is upstream (7.7.0 release) - public static void reportAddBeforeTemplate(String template, Optional ast, List afterHps) { + */ + @Deprecated + public static void reportAddBeforeTemplate(String template, List afterHps) { if (isEnabled()) { for (ReportLogHookFix hook : getReportHooks()) { - hook.reportAddBeforeTemplate(template, ast, afterHps); + hook.reportAddBeforeTemplate(template,Optional.empty(), afterHps); } } } diff --git a/monticore-generator/monticore-runtime-fix/src/main/java/de/monticore/generating/templateengine/reporting/commons/IReportEventHandler.java b/monticore-generator/monticore-runtime-fix/src/main/java/de/monticore/generating/templateengine/reporting/commons/IReportEventHandler.java new file mode 100644 index 0000000000..5109e7682e --- /dev/null +++ b/monticore-generator/monticore-runtime-fix/src/main/java/de/monticore/generating/templateengine/reporting/commons/IReportEventHandler.java @@ -0,0 +1,309 @@ +/* (c) https://github.com/MontiCore/monticore */ + +package de.monticore.generating.templateengine.reporting.commons; + +import de.monticore.ast.ASTNode; +import de.monticore.generating.templateengine.HookPoint; +import de.monticore.io.paths.MCPath; +import de.monticore.symboltable.IScope; + +import java.net.URL; +import java.nio.file.Path; +import java.util.Collection; +import java.util.List; +import java.util.Optional; + +public interface IReportEventHandler { + + public void reportModelStart(ASTNode ast, String modelName, String fileName); + + public void reportTemplateStart(String templatename, ASTNode ast); + + public void reportExecuteStandardTemplate(String templatename, ASTNode ast); + + public void reportFileCreation(String templatename, + String qualifiedfilename, String fileextension, ASTNode ast); + + public void reportFileCreation(Path parentPath, Path file); + + public void reportFileFinalization(String templatename, + String qualifiedfilename, String fileextension, ASTNode ast); + + /** + * @param templatename + * @param ast + */ + public void reportTemplateEnd(String templatename, ASTNode ast); + + /** + * @param modelname + * @param filename + */ + public void reportModelEnd(String modelname, String filename); + + /** + * @param qualifiedName + */ + public void reportModelLoad(String qualifiedName); + + /** + * @param name + * @param value + */ + public void reportSetValue(String name, Object value); + + /** + * @param name + * @param value + * @param size + */ + public void reportAddValue(String name, Object value, int size); + + /** + * @param className + * @param params + */ + public void reportInstantiate(String className, List params); + + /** + * @param templateName + * @param ast + */ + public void reportTemplateInclude(String templateName, ASTNode ast); + + /** + * @param templateName + * @param ast + */ + public void reportTemplateWrite(String templateName, ASTNode ast); + + /** + * @param hookName + * @param hp + */ + public void reportSetHookPoint(String hookName, HookPoint hp); + + /** + * @param hookName + * @param hp + * @param ast + */ + public void reportCallHookPointStart(String hookName, HookPoint hp, + ASTNode ast); + + /** + * @param hookName + */ + public void reportCallHookPointEnd(String hookName); + + /** + * @param oldTemplate + * @param node + * @param newHp + */ + public void reportASTSpecificTemplateReplacement(String oldTemplate, + ASTNode node, HookPoint newHp); + + /** + * @param oldTemplate + * @param hps + * @param ast + */ + + public void reportCallSpecificReplacementHookPoint(String oldTemplate, + List hps, ASTNode ast); + + /** + * @param oldTemplate + * @param hps + * @param ast + */ + + public void reportCallReplacementHookPoint(String oldTemplate, + List hps, ASTNode ast); + + /** + * @param oldTemplate + * @param beforeHPs + * @param ast + */ + + public void reportCallBeforeHookPoint(String oldTemplate, + Collection beforeHPs, ASTNode ast); + + /** + * @param oldTemplate + * @param afterHPs + * @param ast + */ + public void reportCallAfterHookPoint(String oldTemplate, + Collection afterHPs, ASTNode ast); + + /** + * @param oldTemplate + * @param newHps + */ + public void reportTemplateReplacement(String oldTemplate, + List newHps); + + /** + * @param template + * @param beforeHps + */ + default void reportSetBeforeTemplate(String template, + Optional ast, + List beforeHps) { + this.reportSetBeforeTemplate(template, beforeHps); + } + + default void reportSetBeforeTemplate(String template, + List beforeHps) { + throw new IllegalStateException("runtime-fix FAILED: #reportSetBeforeTemplate"); + } + + + /** + * @param template + * @param afterHps + */ + default void reportSetAfterTemplate(String template, + Optional ast, + List afterHps) { + this.reportSetAfterTemplate(template, afterHps); + } + + default void reportSetAfterTemplate(String template, + List afterHps) { + throw new IllegalStateException("runtime-fix FAILED: #reportSetAfterTemplate"); + } + + + /** + * @param template + * @param ast + * @param afterHps + */ + default void reportAddAfterTemplate(String template, + Optional ast, + List afterHps) { + this.reportAddAfterTemplate(template, afterHps); + } + + default void reportAddAfterTemplate(String template, + List afterHps) { + throw new IllegalStateException("runtime-fix FAILED: #reportAddAfterTemplate"); + } + + + /** + * @param template + * @param ast + * @param beforeHps + */ + default void reportAddBeforeTemplate(String template, + Optional ast, + List beforeHps) { + throw new IllegalStateException("runtime-fix FAILED: #reportAddBeforeTemplate"); + } + + /** + * @param transformationName + */ + public void reportTransformationStart(String transformationName); + + public abstract void flush(ASTNode ast); + + /** + * @param fileName + */ + public void reportUseHandwrittenCodeFile(Path parentDir, Path fileName); + + public void reportHWCExistenceCheck(MCPath mcp, Path fileName, Optional exists); + + /** + * @param fileName + */ + public void reportUserSpecificTemplate(Path parentDir, Path fileName); + + /** + * @param message + */ + public void reportWarning(String message); + + /** + * @param message + */ + public void reportUserWarning(String message); + + /** + * @param message + */ + public void reportError(String message); + + /** + * @param message + */ + public void reportErrorUser(String message); + + /** + * @param message + */ + public void reportErrorInternal(String message); + + /** + * @param transformationName + * @param attributeName + */ + public void reportTransformationObjectChange(String transformationName, + ASTNode ast, String attributeName); + + /** + * @param transformationName + */ + public void reportTransformationObjectCreation(String transformationName, + ASTNode ast); + + /** + * @param transformationName + * @param ast + */ + public void reportTransformationObjectDeletion(String transformationName, + ASTNode ast); + + public void reportDetailed(String value); + + public void reportOpenInputFile(Optional parentPath, Path file); + + void reportParseInputFile(Path inputFilePath, String modelName); + + /** + * @param scope + */ + public void reportSymbolTableScope(IScope scope); + /** + * @param className + * @param methodName + * @param params + */ + public void reportMethodCall(String className, String methodName, List params); + + public void reportTransformationObjectMatch(String transformationName, ASTNode ast); + + public void reportTransformationOldValue(String transformationName, ASTNode ast); + + public void reportTransformationNewValue(String transformationName, ASTNode ast); + + public void reportTransformationOldValue(String transformationName, String value); + + public void reportTransformationNewValue(String transformationName, String value); + + public void reportTransformationOldValue(String transformationName, boolean value); + + public void reportTransformationNewValue(String transformationName, boolean value); + + void reportFileCreation(String fileName); + + void reportOpenInputFile(String fileName); + + void reportFileExistenceChecking(List parentPath, Path file); +} diff --git a/monticore-generator/src/main/java/de/monticore/generating/templateengine/reporting/commons/ReportLogHookFix.java b/monticore-generator/monticore-runtime-fix/src/main/java/de/monticore/generating/templateengine/reporting/commons/ReportLogHookFix.java similarity index 93% rename from monticore-generator/src/main/java/de/monticore/generating/templateengine/reporting/commons/ReportLogHookFix.java rename to monticore-generator/monticore-runtime-fix/src/main/java/de/monticore/generating/templateengine/reporting/commons/ReportLogHookFix.java index f52470c526..58ec6353d0 100644 --- a/monticore-generator/src/main/java/de/monticore/generating/templateengine/reporting/commons/ReportLogHookFix.java +++ b/monticore-generator/monticore-runtime-fix/src/main/java/de/monticore/generating/templateengine/reporting/commons/ReportLogHookFix.java @@ -3,7 +3,7 @@ import de.monticore.ast.ASTNode; import de.monticore.generating.templateengine.HookPoint; -import de.monticore.generating.templateengine.reporting.ReportingFix; +import de.monticore.generating.templateengine.reporting.Reporting; import de.monticore.generating.templateengine.reporting.artifacts.ReportingNameHelper; import de.monticore.io.paths.MCPath; import de.monticore.symboltable.IScope; @@ -12,11 +12,12 @@ import java.net.URL; import java.nio.file.Path; -import java.util.*; +import java.util.Collection; +import java.util.HashMap; +import java.util.List; +import java.util.Map; +import java.util.Optional; -// TODO: Remove after 7.7.0 release -// Future-porting the reporting-logger-changes, copy of ReportLogHook.java -@Deprecated public class ReportLogHookFix implements ILogHook, IReportEventHandler { /** @@ -24,7 +25,7 @@ public class ReportLogHookFix implements ILogHook, IReportEventHandler { * @param factory for creating specific report manager configurations */ public ReportLogHookFix(String reportDirectory, - ReportManager.ReportManagerFactory factory) { + ReportManager.ReportManagerFactory factory) { this.reportDirectory = reportDirectory; this.factory = factory; } @@ -86,7 +87,7 @@ protected ReportManager getReportManager(String modelName) { * @return the currently active/responsible report manager instance */ protected ReportManager getReportManager() { - return getReportManager(ReportingFix.getCurrentModel()); + return getReportManager(Reporting.getCurrentModel()); } /** @@ -242,12 +243,11 @@ public void reportTemplateReplacement(String oldTemplate, List ast, List beforeHps) { this.getReportManager().reportSetBeforeTemplate(template, ast, beforeHps); } + @Override public void reportSetAfterTemplate(String template, Optional ast, List afterHps) { this.getReportManager().reportSetAfterTemplate(template, ast, afterHps); @@ -262,23 +262,6 @@ public void reportAddAfterTemplate(String template, Optional ast, List< public void reportAddBeforeTemplate(String template, Optional ast, List beforeHps) { this.getReportManager().reportAddBeforeTemplate(template, ast, beforeHps); } - */ - - @Override - public void reportSetBeforeTemplate(String template, List beforeHps) { - this.getReportManager().reportSetBeforeTemplate(template, beforeHps); - } - - @Override - public void reportSetAfterTemplate(String template, List afterHps) { - this.getReportManager().reportSetAfterTemplate(template, afterHps); - } - - @Override - public void reportAddAfterTemplate(String template, List afterHps) { - this.getReportManager().reportAddAfterTemplate(template, afterHps); - } - @Override public void reportTransformationStart(String transformationName) { diff --git a/monticore-generator/monticore-runtime-fix/src/main/java/de/monticore/generating/templateengine/reporting/commons/ReportManager.java b/monticore-generator/monticore-runtime-fix/src/main/java/de/monticore/generating/templateengine/reporting/commons/ReportManager.java new file mode 100644 index 0000000000..b29b6a6c1a --- /dev/null +++ b/monticore-generator/monticore-runtime-fix/src/main/java/de/monticore/generating/templateengine/reporting/commons/ReportManager.java @@ -0,0 +1,490 @@ +/* (c) https://github.com/MontiCore/monticore */ + +package de.monticore.generating.templateengine.reporting.commons; + +import de.monticore.ast.ASTNode; +import de.monticore.generating.templateengine.HookPoint; +import de.monticore.generating.templateengine.reporting.artifacts.ReportingNameHelper; +import de.monticore.io.paths.MCPath; +import de.monticore.symboltable.IScope; +import de.se_rwth.commons.logging.Log; + +import java.net.URL; +import java.nio.file.Path; +import java.util.*; + +public class ReportManager implements IReportEventHandler { + + protected Set reportEventHandlers = new LinkedHashSet(); + + protected String outputDir; + + public ReportManager(String outputDir) { + this.outputDir = outputDir; + } + + public String getOutputDir() { + return this.outputDir; + } + + public void addReportEventHandler(IReportEventHandler handler) { + Log.errorIfNull(handler); + this.reportEventHandlers.add(handler); + } + + public void removeReportEventHandler(IReportEventHandler handler) { + this.reportEventHandlers.remove(handler); + } + + @Override + public void reportModelStart(ASTNode ast, String modelName, String fileName) { + for (IReportEventHandler handler : this.reportEventHandlers) { + handler.reportModelStart(ast, modelName, fileName); + } + } + + @Override + public void reportTemplateStart(String templateName, ASTNode ast) { + for (IReportEventHandler handler : this.reportEventHandlers) { + handler.reportTemplateStart(templateName, ast); + } + } + + @Override + public void reportExecuteStandardTemplate(String templateName, ASTNode ast) { + for (IReportEventHandler handler : this.reportEventHandlers) { + handler.reportExecuteStandardTemplate(templateName, ast); + } + } + + public void reportFileCreation(String templateName, Path path, ASTNode ast) { + String qualifiedName = ReportingNameHelper.getQualifiedName( + this.getOutputDir(), path); + String fileExtension = ReportingNameHelper.getFileextension(path); + + this.reportFileCreation(templateName, qualifiedName, fileExtension, ast); + } + + public void reportFileFinalization(String templateName, Path path, + ASTNode ast) { + String qualifiedName = ReportingNameHelper.getQualifiedName( + this.getOutputDir(), path); + String fileExtension = ReportingNameHelper.getFileextension(path); + + this.reportFileFinalization(templateName, qualifiedName, fileExtension, + ast); + } + + @Override + public void reportFileCreation(String templateName, + String qualifiedFilename, String fileExtension, ASTNode ast) { + for (IReportEventHandler handler : this.reportEventHandlers) { + handler.reportFileCreation(templateName, qualifiedFilename, + fileExtension, ast); + } + } + + @Override + public void reportFileCreation(Path parentPath, Path file) { + this.reportEventHandlers.forEach(h -> h.reportFileCreation(parentPath, file)); + } + + @Override + public void reportFileCreation(String fileName) { + this.reportEventHandlers.forEach(h -> h.reportFileCreation(fileName)); + } + + @Override + public void reportFileExistenceChecking(List parentPath, Path file) { + this.reportEventHandlers.forEach(h -> h.reportFileExistenceChecking(parentPath, file)); + } + + @Override + public void reportFileFinalization(String templateName, + String qualifiedFilename, String fileExtension, ASTNode ast) { + for (IReportEventHandler handler : this.reportEventHandlers) { + handler.reportFileFinalization(templateName, qualifiedFilename, + fileExtension, ast); + } + } + + @Override + public void reportTemplateEnd(String templateName, ASTNode ast) { + for (IReportEventHandler handler : this.reportEventHandlers) { + handler.reportTemplateEnd(templateName, ast); + } + } + + @Override + public void reportModelEnd(String modelName, String fileName) { + for (IReportEventHandler handler : this.reportEventHandlers) { + handler.reportModelEnd(modelName, fileName); + } + } + + @Override + public void reportModelLoad(String qualifiedName) { + for (IReportEventHandler handler : this.reportEventHandlers) { + handler.reportModelLoad(qualifiedName); + } + } + + @Override + public void reportSetValue(String name, Object value) { + for (IReportEventHandler handler : this.reportEventHandlers) { + handler.reportSetValue(name, value); + } + } + + @Override + public void reportAddValue(String name, Object value, int size) { + for (IReportEventHandler handler : this.reportEventHandlers) { + handler.reportAddValue(name, value, size); + } + } + + @Override + public void reportInstantiate(String className, List params) { + for (IReportEventHandler handler : this.reportEventHandlers) { + handler.reportInstantiate(className, params); + } + } + + @Override + public void reportTemplateInclude(String templateName, ASTNode ast) { + for (IReportEventHandler handler : this.reportEventHandlers) { + handler.reportTemplateInclude(templateName, ast); + } + } + + @Override + public void reportTemplateWrite(String templateName, ASTNode ast) { + for (IReportEventHandler handler : this.reportEventHandlers) { + handler.reportTemplateWrite(templateName, ast); + } + } + + @Override + public void reportSetHookPoint(String hookName, HookPoint hp) { + for (IReportEventHandler handler : this.reportEventHandlers) { + handler.reportSetHookPoint(hookName, hp); + } + } + + @Override + public void reportCallHookPointStart(String hookName, HookPoint hp, + ASTNode ast) { + for (IReportEventHandler handler : this.reportEventHandlers) { + handler.reportCallHookPointStart(hookName, hp, ast); + } + } + + @Override + public void reportCallHookPointEnd(String hookName) { + for (IReportEventHandler handler : this.reportEventHandlers) { + handler.reportCallHookPointEnd(hookName); + } + } + + @Override + public void reportTemplateReplacement(String oldTemplate, + List newHps) { + for (IReportEventHandler handler : this.reportEventHandlers) { + handler.reportTemplateReplacement(oldTemplate, newHps); + } + } + + @Override + public void reportASTSpecificTemplateReplacement(String oldTemplate, + ASTNode node, HookPoint newHp) { + for (IReportEventHandler handler : this.reportEventHandlers) { + handler.reportASTSpecificTemplateReplacement(oldTemplate, node, + newHp); + } + } + + @Override + public void reportSetBeforeTemplate(String template, + Optional ast, + List beforeHps) { + for (IReportEventHandler handler : this.reportEventHandlers) { + handler.reportSetBeforeTemplate(template, ast, beforeHps); + } + } + + @Override + public void reportCallBeforeHookPoint(String oldTemplate, + Collection beforeHPs, ASTNode ast) { + for (IReportEventHandler handler : this.reportEventHandlers) { + handler.reportCallBeforeHookPoint(oldTemplate, beforeHPs, ast); + } + } + + @Override + public void reportCallAfterHookPoint(String oldTemplate, + Collection afterHPs, ASTNode ast) { + for (IReportEventHandler handler : this.reportEventHandlers) { + handler.reportCallAfterHookPoint(oldTemplate, afterHPs, ast); + } + } + + @Override + public void reportCallReplacementHookPoint(String oldTemplate, + List hps, ASTNode ast) { + for (IReportEventHandler handler : this.reportEventHandlers) { + handler.reportCallReplacementHookPoint(oldTemplate, hps, ast); + } + } + + @Override + public void reportCallSpecificReplacementHookPoint(String oldTemplate, + List hps, ASTNode ast) { + for (IReportEventHandler handler : this.reportEventHandlers) { + handler.reportCallSpecificReplacementHookPoint(oldTemplate, + hps, ast); + } + } + + @Override + public void reportSetAfterTemplate(String template, + Optional ast, + List afterHps) { + for (IReportEventHandler handler : this.reportEventHandlers) { + handler.reportSetAfterTemplate(template, ast, afterHps); + } + } + + @Override + public void reportAddAfterTemplate(String template, Optional ast, + List afterHps) { + for (IReportEventHandler handler : this.reportEventHandlers) { + handler.reportAddAfterTemplate(template, ast, afterHps); + } + } + + @Override + public void reportAddBeforeTemplate(String template, Optional ast, List beforeHps) { + for (IReportEventHandler handler : this.reportEventHandlers) { + handler.reportAddAfterTemplate(template, ast, beforeHps); + } + } + + @Override + public void reportUseHandwrittenCodeFile(Path parentDir, Path fileName) { + for (IReportEventHandler handler : this.reportEventHandlers) { + handler.reportUseHandwrittenCodeFile(parentDir, fileName); + } + } + + public void reportHWCExistenceCheck(MCPath mcp, Path fileName, Optional resolvedPath) { + for (IReportEventHandler handler : this.reportEventHandlers) { + handler.reportHWCExistenceCheck(mcp, fileName, resolvedPath); + } + } + + @Override + public void reportUserSpecificTemplate(Path parentDir, Path fileName) { + for (IReportEventHandler handler : this.reportEventHandlers) { + handler.reportUserSpecificTemplate(parentDir, fileName); + } + } + + @Override + public void reportTransformationStart(String transformationName) { + for (IReportEventHandler handler : this.reportEventHandlers) { + handler.reportTransformationStart(transformationName); + } + } + + @Override + public void reportTransformationObjectChange(String transformationName, + ASTNode ast, String attributeName) { + for (IReportEventHandler handler : this.reportEventHandlers) { + handler.reportTransformationObjectChange(transformationName, + ast, attributeName); + } + } + + @Override + public void reportTransformationObjectCreation(String transformationName, + ASTNode ast) { + for (IReportEventHandler handler : this.reportEventHandlers) { + handler.reportTransformationObjectCreation(transformationName, + ast); + } + } + + @Override + public void reportTransformationObjectDeletion(String transformationName, + ASTNode ast) { + for (IReportEventHandler handler : this.reportEventHandlers) { + handler.reportTransformationObjectDeletion(transformationName, + ast); + } + } + + @Override + public void reportTransformationObjectMatch(String transformationName, ASTNode ast) { + for (IReportEventHandler handler : this.reportEventHandlers) { + handler.reportTransformationObjectMatch(transformationName, + ast); + } + } + + @Override + public void reportTransformationOldValue(String transformationName, ASTNode ast) { + for (IReportEventHandler handler : this.reportEventHandlers) { + handler.reportTransformationOldValue(transformationName, + ast); + } + } + + @Override + public void reportTransformationOldValue(String transformationName, String value) { + for (IReportEventHandler handler : this.reportEventHandlers) { + handler.reportTransformationOldValue(transformationName, + value); + } + } + + @Override + public void reportTransformationNewValue(String transformationName, ASTNode ast) { + for (IReportEventHandler handler : this.reportEventHandlers) { + handler.reportTransformationNewValue(transformationName, + ast); + } + } + + @Override + public void reportTransformationNewValue(String transformationName, String value) { + for (IReportEventHandler handler : this.reportEventHandlers) { + handler.reportTransformationNewValue(transformationName, + value); + } + } + + @Override + public void reportTransformationOldValue(String transformationName, boolean value) { + for (IReportEventHandler handler : this.reportEventHandlers) { + handler.reportTransformationOldValue(transformationName, + value); + } + } + + @Override + public void reportTransformationNewValue(String transformationName, boolean value) { + for (IReportEventHandler handler : this.reportEventHandlers) { + handler.reportTransformationNewValue(transformationName, + value); + } + } + + @Override + public void flush(ASTNode ast) { + for (IReportEventHandler handler : this.reportEventHandlers) { + handler.flush(ast); + } + } + + @Override + public void reportWarning(String message) { + for (IReportEventHandler handler : this.reportEventHandlers) { + handler.reportWarning(message); + } + } + + @Override + public void reportUserWarning(String message) { + for (IReportEventHandler handler : this.reportEventHandlers) { + handler.reportUserWarning(message); + } + } + + @Override + public void reportError(String msg) { + for (IReportEventHandler handler : this.reportEventHandlers) { + handler.reportError(msg); + } + } + + @Override + public void reportErrorUser(String msg) { + for (IReportEventHandler handler : this.reportEventHandlers) { + handler.reportErrorUser(msg); + } + } + + @Override + public void reportErrorInternal(String msg) { + for (IReportEventHandler handler : this.reportEventHandlers) { + handler.reportErrorInternal(msg); + } + } + + @Override + public void reportDetailed(String value) { + for (IReportEventHandler handler : this.reportEventHandlers) { + handler.reportDetailed(value); + } + } + + @Override + public void reportOpenInputFile(Optional parentPath, Path file) { + for (IReportEventHandler handler : this.reportEventHandlers) { + handler.reportOpenInputFile(parentPath, file); + } + } + + @Override + public void reportParseInputFile(Path inputFilePath, String modelName) { + for (IReportEventHandler handler : this.reportEventHandlers) { + handler.reportParseInputFile(inputFilePath, modelName); + } + } + + @Override + public void reportSymbolTableScope(IScope scope) { + for (IReportEventHandler handler : this.reportEventHandlers) { + handler.reportSymbolTableScope(scope); + } + } + + /** + * A factory for providing tool specific report managers. + * + */ + public static interface ReportManagerFactory { + + /** + * Implementations of this method are responsible for providing an + * appropriately configured report manager for a potentially given model + * name (reporting is mainly per model). Implementors must take care + * of possible null values or provide special constants for dealing + * with model agnostic reporting etc. + * + * @param modelName the model to which provide a report manager + * configuration for (use special constants for entirely global, i.e., model + * agnostic configurations) + * @return a tool specific configuration/instance of a report manager. + */ + ReportManager provide(String modelName); + + } + + /** + * @param className + * @param methodName + * @param params + */ + public void reportMethodCall(String className, String methodName, List params) { + for (IReportEventHandler handler : this.reportEventHandlers) { + handler.reportMethodCall(className, methodName, params); + } + } + + @Override + public void reportOpenInputFile(String fileName) { + this.reportEventHandlers.forEach(h -> h.reportOpenInputFile(fileName)); + } + +} diff --git a/monticore-generator/settings.gradle b/monticore-generator/settings.gradle index 908daa3a98..0757e5f22f 100644 --- a/monticore-generator/settings.gradle +++ b/monticore-generator/settings.gradle @@ -14,3 +14,4 @@ pluginManagement { } rootProject.name = 'monticore-generator' +include ':monticore-runtime-fix' diff --git a/monticore-generator/src/main/java/de/monticore/MontiCoreScript.java b/monticore-generator/src/main/java/de/monticore/MontiCoreScript.java index 4240b5884f..ccb796eb9b 100644 --- a/monticore-generator/src/main/java/de/monticore/MontiCoreScript.java +++ b/monticore-generator/src/main/java/de/monticore/MontiCoreScript.java @@ -102,7 +102,7 @@ import de.monticore.generating.templateengine.TemplateHookPoint; import de.monticore.generating.templateengine.freemarker.FreeMarkerTemplateEngine; import de.monticore.generating.templateengine.freemarker.MontiCoreTemplateLoader; -import de.monticore.generating.templateengine.reporting.ReportingFix; +import de.monticore.generating.templateengine.reporting.Reporting; import de.monticore.grammar.MCGrammarSymbolTableHelper; import de.monticore.grammar.cocos.GrammarCoCos; import de.monticore.grammar.grammar._ast.ASTMCGrammar; @@ -380,9 +380,9 @@ public ASTMCGrammar createSymbolsFromAST(IGrammar_WithConceptsGlobalScope global MCGrammarSymbol symbol = result.getSymbol(); for(MCGrammarSymbol it: MCGrammarSymbolTableHelper.getAllSuperGrammars(symbol)) { if(!it.getFullName().equals(symbol.getFullName())) { - ReportingFix.reportOpenInputFile(Optional.empty(), + Reporting.reportOpenInputFile(Optional.empty(), Paths.get(it.getFullName().replaceAll("\\.", "/").concat(".mc4"))); - ReportingFix.reportOpenInputFile(Optional.empty(), + Reporting.reportOpenInputFile(Optional.empty(), Paths.get(it.getFullName().replaceAll("\\.", "/").concat(".cd"))); } @@ -1417,7 +1417,7 @@ public GlobalExtensionManagement initGlex(MontiCoreConfiguration mcConfig) { // initialize glex GlobalExtensionManagement glex = new GlobalExtensionManagement(); glex.addAfterTemplate("cd2java.Imports", new TemplateHookPoint("mc.Imports")); - if(ReportingFix.isInitialized()) { + if(Reporting.isInitialized()) { if(mcConfig.getConfigTemplate().isPresent()) { String configTemplate = mcConfig.getConfigTemplate().get(); if (configTemplate.endsWith(".ftl")) { // remove file ending @@ -1457,13 +1457,13 @@ public static class Runner extends GroovyRunnerBase { "de.monticore.io.paths", "de.monticore.languages.grammar", "de.se_rwth.commons.logging", - "de.monticore.generating.templateengine.reporting.fix", // TODO: Remove .fix after 7.7.0 release + "de.monticore.generating.templateengine.reporting", "de.se_rwth.commons", "de.monticore.incremental"}; public static final String[] DEFAULT_STATIC_IMPORTS = { "de.se_rwth.commons.logging.Log", - "de.monticore.generating.templateengine.reporting.fix.Reporting", // TODO: Remove .fix after 7.7.0 release + "de.monticore.generating.templateengine.reporting.Reporting", "de.se_rwth.commons.Names"}; diff --git a/monticore-generator/src/main/java/de/monticore/cli/MontiCoreTool.java b/monticore-generator/src/main/java/de/monticore/cli/MontiCoreTool.java index d45ad81b59..7e9e6229b8 100644 --- a/monticore-generator/src/main/java/de/monticore/cli/MontiCoreTool.java +++ b/monticore-generator/src/main/java/de/monticore/cli/MontiCoreTool.java @@ -11,7 +11,7 @@ import de.monticore.MontiCoreScript; import de.monticore.StatisticsHandlerFix; import de.monticore.cli.updateChecker.UpdateCheckerRunnable; -import de.monticore.generating.templateengine.reporting.ReportingFix; +import de.monticore.generating.templateengine.reporting.Reporting; import de.monticore.grammar.grammar_withconcepts.Grammar_WithConceptsMill; import de.se_rwth.commons.logging.Log; import de.se_rwth.commons.logging.Slf4jLog; @@ -175,7 +175,7 @@ else if (cmd.hasOption("d")) { // Case 3: Use custom log file logging if configured and present else if (cmd.hasOption("cl")) { File userLogFile = new File(cmd.getOptionValue("cl", StringUtils.EMPTY)); - ReportingFix.reportFileExistenceChecking(Lists.newArrayList(), + Reporting.reportFileExistenceChecking(Lists.newArrayList(), userLogFile.toPath().toAbsolutePath()); if (userLogFile.exists() && userLogFile.isFile()) { @@ -249,7 +249,7 @@ protected String loadScript(CommandLine cmd) { // available and load its content if (cmd.hasOption(SCRIPT)) { File f = new File(cmd.getOptionValue(SCRIPT, StringUtils.EMPTY)); - ReportingFix.reportFileExistenceChecking(Lists.newArrayList(), + Reporting.reportFileExistenceChecking(Lists.newArrayList(), f.toPath().toAbsolutePath()); if (f.exists() && f.isFile()) { diff --git a/monticore-generator/src/main/java/de/monticore/generating/templateengine/reporting/fix/Reporting.java b/monticore-generator/src/main/java/de/monticore/generating/templateengine/reporting/fix/Reporting.java deleted file mode 100644 index db2f003d83..0000000000 --- a/monticore-generator/src/main/java/de/monticore/generating/templateengine/reporting/fix/Reporting.java +++ /dev/null @@ -1,20 +0,0 @@ -/* (c) https://github.com/MontiCore/monticore */ -package de.monticore.generating.templateengine.reporting.fix; - -import de.monticore.generating.templateengine.reporting.ReportingFix; -import de.monticore.generating.templateengine.reporting.commons.ReportManager; - -/** - * TODO: Remove after 7.7.0 release - * Enables the groovy scripts to use "Reporting" instead of having to use - * "ReportingFix" - */ -@Deprecated(forRemoval = true) -public class Reporting extends ReportingFix { - @Deprecated - public static void init(String outputDirectory, String reportDirectory, ReportManager.ReportManagerFactory factory) { - // Delegate to static - ReportingFix.init(outputDirectory, reportDirectory, factory); - } - -} diff --git a/monticore-generator/src/main/java/de/monticore/gradle/gen/MCToolInvoker.java b/monticore-generator/src/main/java/de/monticore/gradle/gen/MCToolInvoker.java index 012529d6ba..3d9162e14e 100644 --- a/monticore-generator/src/main/java/de/monticore/gradle/gen/MCToolInvoker.java +++ b/monticore-generator/src/main/java/de/monticore/gradle/gen/MCToolInvoker.java @@ -3,7 +3,7 @@ import de.monticore.AmbiguityException; import de.monticore.generating.templateengine.freemarker.MontiCoreFreeMarkerException; -import de.monticore.generating.templateengine.reporting.ReportingFix; +import de.monticore.generating.templateengine.reporting.Reporting; import de.monticore.grammar.MCGrammarSymbolTableHelper; import de.monticore.grammar.grammar_withconcepts.Grammar_WithConceptsMill; import de.monticore.mcbasics.MCBasicsMill; @@ -51,7 +51,7 @@ public static void run(String[] args) { MCBasicsMill.globalScope().clearLoadedFiles(); MCBasicsMill.globalScope().getSymbolPath().close(); Grammar_WithConceptsMill.reset(); - ReportingFix.resetInitializedFlagFix(); + Reporting.resetInitializedFlagFix(); } } } diff --git a/monticore-generator/src/main/java/de/monticore/tagging/TagGenerator.java b/monticore-generator/src/main/java/de/monticore/tagging/TagGenerator.java index cb9b778bf0..bed0f949e9 100644 --- a/monticore-generator/src/main/java/de/monticore/tagging/TagGenerator.java +++ b/monticore-generator/src/main/java/de/monticore/tagging/TagGenerator.java @@ -3,7 +3,7 @@ import com.google.common.base.Joiner; import de.monticore.codegen.cd2java._tagging.TaggingConstants; -import de.monticore.generating.templateengine.reporting.ReportingFix; +import de.monticore.generating.templateengine.reporting.Reporting; import de.monticore.grammar.grammar.GrammarMill; import de.monticore.grammar.grammar._ast.ASTMCGrammar; import de.monticore.grammar.grammar._visitor.GrammarTraverser; @@ -76,7 +76,7 @@ static Path saveGrammar(ASTMCGrammar defDerivGrammar, Grammar_WithConceptsFullPr Files.createDirectories(Paths.get(directories)); } Path path = Paths.get(directories + "/" + defDerivGrammar.getName() + ".mc4"); - ReportingFix.reportFileCreation(path.toString()); + Reporting.reportFileCreation(path.toString()); return Files.writeString(path, fpp.prettyprint(defDerivGrammar)); } @@ -119,4 +119,4 @@ public static File getTagGrammar(List modelPath, File grammar, String ta Log.error("0xA5C11 Could not determine Tagging path for grammar " + grammar); return null; } -} \ No newline at end of file +} diff --git a/monticore-generator/src/test/java/de/monticore/MontiCoreScriptTest.java b/monticore-generator/src/test/java/de/monticore/MontiCoreScriptTest.java index 795f8a754c..0a9b0ca050 100644 --- a/monticore-generator/src/test/java/de/monticore/MontiCoreScriptTest.java +++ b/monticore-generator/src/test/java/de/monticore/MontiCoreScriptTest.java @@ -17,7 +17,7 @@ import de.monticore.codegen.mc2cd.TestHelper; import de.monticore.generating.GeneratorSetup; import de.monticore.generating.templateengine.GlobalExtensionManagement; -import de.monticore.generating.templateengine.reporting.ReportingFix; +import de.monticore.generating.templateengine.reporting.Reporting; import de.monticore.grammar.grammar._ast.ASTMCGrammar; import de.monticore.grammar.grammar_withconcepts.Grammar_WithConceptsMill; import de.monticore.grammar.grammar_withconcepts._symboltable.Grammar_WithConceptsGlobalScope; @@ -317,7 +317,7 @@ private void testDefaultScript(String[] args) { new MontiCoreScript().run(cfg); // Reporting is enabled in the monticore_standard.groovy script but needs to be disabled for other tests // because Reporting is static directly disable it again here - ReportingFix.off(); + Reporting.off(); Assertions.assertTrue(!false); } @@ -335,7 +335,7 @@ private void testDefaultScriptWithEmf(String[] args) { new MontiCoreScript().run_emf(cfg); // Reporting is enabled in the monticore_standard.groovy script but needs to be disabled for other tests // because Reporting is static directly disable it again here - ReportingFix.off(); + Reporting.off(); Assertions.assertTrue(!false); } diff --git a/monticore-generator/src/test/java/de/monticore/cli/MontiCoreToolTest.java b/monticore-generator/src/test/java/de/monticore/cli/MontiCoreToolTest.java index 334a2a7812..676cfc022d 100644 --- a/monticore-generator/src/test/java/de/monticore/cli/MontiCoreToolTest.java +++ b/monticore-generator/src/test/java/de/monticore/cli/MontiCoreToolTest.java @@ -3,7 +3,7 @@ package de.monticore.cli; import de.monticore.cd4code.CD4CodeMill; -import de.monticore.generating.templateengine.reporting.ReportingFix; +import de.monticore.generating.templateengine.reporting.Reporting; import de.monticore.grammar.grammar_withconcepts.Grammar_WithConceptsMill; import de.se_rwth.commons.logging.Log; import de.se_rwth.commons.logging.LogStub; @@ -250,6 +250,6 @@ public void generateGrammarAndCheckFiles(Path path, String grammar) throws IOExc @AfterEach public void tearDown() throws Exception { - ReportingFix.off(); + Reporting.off(); } } diff --git a/monticore-generator/src/test/java/de/monticore/codegen/parser/ParserGeneratorTest.java b/monticore-generator/src/test/java/de/monticore/codegen/parser/ParserGeneratorTest.java index d8fc29f634..7358e57faa 100644 --- a/monticore-generator/src/test/java/de/monticore/codegen/parser/ParserGeneratorTest.java +++ b/monticore-generator/src/test/java/de/monticore/codegen/parser/ParserGeneratorTest.java @@ -5,7 +5,7 @@ import de.monticore.MontiCoreScript; import de.monticore.cd4code.CD4CodeMill; import de.monticore.generating.templateengine.GlobalExtensionManagement; -import de.monticore.generating.templateengine.reporting.ReportingFix; +import de.monticore.generating.templateengine.reporting.Reporting; import de.monticore.grammar.MCGrammarSymbolTableHelper; import de.monticore.grammar.grammar._ast.ASTMCGrammar; import de.monticore.grammar.grammar._symboltable.MCGrammarSymbol; @@ -183,9 +183,9 @@ private ASTMCGrammar createSymbolsFromAST(IGrammar_WithConceptsGlobalScope globa MCGrammarSymbol symbol = result.getSymbol(); for (MCGrammarSymbol it : MCGrammarSymbolTableHelper.getAllSuperGrammars(symbol)) { if (!it.getFullName().equals(symbol.getFullName())) { - ReportingFix.reportOpenInputFile(Optional.empty(), + Reporting.reportOpenInputFile(Optional.empty(), Paths.get(it.getFullName().replaceAll("\\.", "/").concat(".mc4"))); - ReportingFix.reportOpenInputFile(Optional.empty(), + Reporting.reportOpenInputFile(Optional.empty(), Paths.get(it.getFullName().replaceAll("\\.", "/").concat(".cd"))); } } diff --git a/monticore-generator/src/test/java/de/monticore/gradle/MCGenPluginTest.java b/monticore-generator/src/test/java/de/monticore/gradle/MCGenPluginTest.java index 08535c1bec..9f69dc97f5 100644 --- a/monticore-generator/src/test/java/de/monticore/gradle/MCGenPluginTest.java +++ b/monticore-generator/src/test/java/de/monticore/gradle/MCGenPluginTest.java @@ -102,7 +102,10 @@ public void testGenerateGrammar_v8_7() throws IOException { this.testGenerateGrammar("8.7"); } - // Test if the generate task succeeds and is cacheable + // Test if the generate task succeeds + // and is cacheable + // and up-to-date-checks work on modified files + // and up-to-date-checks work on modified super files void testGenerateGrammar(String version) throws IOException { writeFile(settingsFile, "rootProject.name = 'hello-world'"); String buildFileContent = "plugins {" + @@ -113,6 +116,8 @@ void testGenerateGrammar(String version) throws IOException { // as the monticore-grammar dependency might not be available yet writeFile(new File(grammarDir, "MyTestGrammar.mc4"), "grammar MyTestGrammar { Monti = \"Core\"; }"); + writeFile(new File(grammarDir, "MyTestGrammarS.mc4"), + "grammar MyTestGrammarS extends MyTestGrammar { Monti = \"Core\"; }"); BuildResult result = GradleRunner.create() @@ -124,6 +129,8 @@ void testGenerateGrammar(String version) throws IOException { // file MyTestGrammar is worked on Assert.assertTrue(result.getOutput(), result.getOutput().contains("[MyTestGrammar.mc4]")); + // file MyTestGrammarS is worked on + Assert.assertTrue(result.getOutput(), result.getOutput().contains("[MyTestGrammarS.mc4]")); // and the task was successful Assert.assertEquals(SUCCESS, result.task(":generateMCGrammars").getOutcome()); @@ -139,6 +146,37 @@ void testGenerateGrammar(String version) throws IOException { // and then check, that the build cache was used Assert.assertEquals("generateMCGrammars was not cached", FROM_CACHE, result.task(":generateMCGrammars").getOutcome()); + + // Next, test up-to-date checks: + // by changing MyTestGrammarS + writeFile(new File(grammarDir, "MyTestGrammarS.mc4"), + "grammar MyTestGrammarS extends MyTestGrammar { Monti = \"Core2\"; }"); + // and run again + result = GradleRunner.create() + .withPluginClasspath() + .withGradleVersion(version) + .withProjectDir(testProjectDir) + .withArguments("generateMCGrammars", "--build-cache") + .build(); + // and the task was successful + Assert.assertEquals(SUCCESS, result.task(":generateMCGrammars").getOutcome()); + // Only MyTestGrammarS SHOULD not be up-to-date + Assert.assertTrue(result.getOutput(), result.getOutput().contains("MyTestGrammar.mc4 is UP-TO-DATE, no action required")); + Assert.assertFalse(result.getOutput(), result.getOutput().contains("MyTestGrammarS.mc4 is UP-TO-DATE, no action required")); + + // and change MyTestGrammar + writeFile(new File(grammarDir, "MyTestGrammar.mc4"), + "grammar MyTestGrammar { Monti = \"Core2\"; }"); + // and run again + result = GradleRunner.create() + .withPluginClasspath() + .withGradleVersion(version) + .withProjectDir(testProjectDir) + .withArguments("generateMCGrammars", "--build-cache") + .build(); + // Nothing SHOULD not be up-to-date + Assert.assertFalse(result.getOutput(), result.getOutput().contains("MyTestGrammar.mc4 is UP-TO-DATE, no action required")); + Assert.assertFalse(result.getOutput(), result.getOutput().contains("MyTestGrammarS.mc4 is UP-TO-DATE, no action required")); } diff --git a/monticore-runtime/src/main/java/de/monticore/generating/templateengine/reporting/Reporting.java b/monticore-runtime/src/main/java/de/monticore/generating/templateengine/reporting/Reporting.java index 6f2f6b4167..5ebcd31760 100644 --- a/monticore-runtime/src/main/java/de/monticore/generating/templateengine/reporting/Reporting.java +++ b/monticore-runtime/src/main/java/de/monticore/generating/templateengine/reporting/Reporting.java @@ -51,6 +51,7 @@ public static void init(String reportDirectory, ReportManagerFactory factory) { if (Log.getLog() == null) { Log.init(); } + getReportHooks().clear(); addReportHook(new ReportLogHook(reportDirectory, factory)); } diff --git a/monticore-runtime/src/main/java/de/monticore/io/FileReaderWriter.java b/monticore-runtime/src/main/java/de/monticore/io/FileReaderWriter.java index 92de257ef6..2fab1cea14 100644 --- a/monticore-runtime/src/main/java/de/monticore/io/FileReaderWriter.java +++ b/monticore-runtime/src/main/java/de/monticore/io/FileReaderWriter.java @@ -238,6 +238,10 @@ protected boolean _existsFile(Path sourcePath) { * @return */ public static Reader getReader(URL location) { + return getFileReaderWriter()._getReader(location); + } + + protected Reader _getReader(URL location) { try { if (!"jar".equals(location.getProtocol())) { Path p = Paths.get(location.toURI());