Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Reset CD4C & logger instances #48

Merged
merged 4 commits into from
Nov 20, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions monticore-generator/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,9 @@ dependencies {
implementation 'ch.qos.logback:logback-classic:1.2.0'
implementation 'ch.qos.logback:logback-core:1.2.0'

// Remove after 7.7.0 release
compileOnly 'org.reflections:reflections:0.9.9'

implementation "de.monticore.lang:cd4analysis:$cd4a_version"
implementation "org.antlr:antlr4:$antlr_version"
implementation 'org.apache.groovy:groovy:4.0.23'
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -194,6 +194,8 @@ public static ASTCDClass generateParser(

ParserInfoGenerator.generateParserInfo(astGrammar, setup, antlrTool.getNonTerminalToParserStates(), genHelper.getParserPackage(), lang);

antlrTool.cleanUp();

return parserVisitor.getVisitorClass();
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -162,4 +162,17 @@ private Set<Integer> calculateStateForTmpName(Grammar g, String ruleName, String

return res;
}

/**
* Unfortunately {@link org.antlr.v4.codegen.Target} retains a static
* reference to a targets {@link Tool}.
* In combination with Groovy and
* <a href="https://bugs.openjdk.org/browse/JDK-8078641">JDK-8078641</a>
* we have to clean up after static references.
*/
public void cleanUp() {
this.grammarSymbol = null;
this.tmpNameDict = null;
this.nonTerminalToParserStates = null;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
package de.monticore.gradle.gen;

import de.monticore.AmbiguityException;
import de.monticore.cd.methodtemplates.CD4C;
import de.monticore.generating.templateengine.freemarker.MontiCoreFreeMarkerException;
import de.monticore.generating.templateengine.reporting.Reporting;
import de.monticore.grammar.MCGrammarSymbolTableHelper;
Expand Down Expand Up @@ -50,8 +51,23 @@ public static void run(String[] args) {
MCBasicsMill.globalScope().clear();
MCBasicsMill.globalScope().clearLoadedFiles();
MCBasicsMill.globalScope().getSymbolPath().close();
Reporting.off();
if (Reporting.isEnabled())
throw new IllegalStateException("Reporting should be disabled, as we otherwise leak a file handle!");
CD4C.reset(); // Reporting should be disabled for this, as we otherwise report on the "cd4c" global variable being changed
Grammar_WithConceptsMill.reset();
Reporting.resetInitializedFlagFix();
Reporting.clearReportHooks();
Log.internalRemove();
try {
// Remove after 7.7.0 release
// the runtimes ReportingHelper (up to & including 7.6.0) requires the following clean up
// https://github.com/MontiCore/monticore/commit/3bcfd5c16a790e2c3411e654769ec950b0d681ff#diff-bcc6fda934d6efd7c418c781027b161edd98f5ccd48b6c9106d3e23981b0d7ffL17
org.reflections.Reflections.log = null;
} catch (NoClassDefFoundError ignored) {
// The Reflections library is no longer in the classpath -> ignore
ignored.printStackTrace();
}
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -144,143 +144,4 @@ public Set<String> getAllHWTemplateNames() {
return allHWTemplateNames;
}

/* This is the magic. Don't touch it ;-) */
protected class Helper extends Log {

@Override
public boolean doIsTraceEnabled(String logName) {
return false;
// return Log.isTraceEnabled(ReportingRepository.class.getName());
}

@Override
public void doTrace(String msg, String logName) {
if (doIsTraceEnabled(logName)) {
System.out.println("[TRACE] " + msg);
}
}

public void doTrace(String format, Object arg, String logName) {
trace(String.format(format, arg), logName);
}

public void doTrace(String format, Object arg1, Object arg2, String logName) {
trace(String.format(format, arg1, arg2), logName);
}

public void doTrace(String format, String logName, Object... arguments) {
trace(String.format(format, arguments), logName);
}

@Override
public void doTrace(String msg, Throwable t, String logName) {
trace(msg + "\n" + t.toString(), t, logName);
}

@Override
public boolean doIsDebugEnabled(String logName) {
return false;
// return Log.isDebugEnabled(ReportingRepository.class.getName());
}

@Override
public void doDebug(String msg, String logName) {
if (isDebugEnabled(logName))
System.out.println("[DEBUG] " + msg);
}

public void doDebug(String format, Object arg, String logName) {
debug(String.format(format, arg), logName);
}

public void doDebug(String format, Object arg1, Object arg2, String logName) {
debug(String.format(format, arg1, arg2), logName);
}

public void doDebug(String format, String logName, Object... arguments) {
debug(String.format(format, arguments), logName);
}

@Override
public void doDebug(String msg, Throwable t, String logName) {
debug(msg + "\n" + t.toString(), t, logName);
}

@Override
public boolean doIsInfoEnabled(String logName) {
return isDebugEnabled(logName);
}

@Override
public void doInfo(String msg, String logName) {
if (isInfoEnabled(logName))
System.out.println("[INFO] " + msg);
}

public void doInfo(String format, Object arg, String logName) {
debug(String.format(format, arg), logName);
}

public void doInfo(String format, Object arg1, Object arg2, String logName) {
debug(String.format(format, arg1, arg2), logName);
}

public void doInfo(String format, String logName, Object... arguments) {
debug(String.format(format, arguments), logName);
}

@Override
public void doInfo(String msg, Throwable t, String logName) {
debug(msg, t, logName);
}

@Override
public void doWarn(String msg) {
System.err.println("[WARNING] " + msg);
}

public void doWarn(String format, Object arg) {
warn(String.format(format, arg));
}

public void doWarn(String format, Object... arguments) {
warn(String.format(format, arguments));
}

public void doWarn(String format, Object arg1, Object arg2) {
warn(String.format(format, arg1, arg2));
}

@Override
public void doWarn(String msg, Throwable t) {
warn(msg + "\n" + t.toString(), t);
}

@Override
public void doError(String msg) {
System.err.println("[ERROR] " + msg);
}

public void doError(String format, Object arg) {
error(String.format(format, arg));
}

public void doError(String format, Object arg1, Object arg2) {
error(String.format(format, arg1, arg2));
}

public void doError(String format, Object... arguments) {
error(String.format(format, arguments));
}

@Override
public void doError(String msg, Throwable t) {
error(msg + "\n" + t.toString(), t);
}

public String getName() {
return ReportingRepository.class.getName();
}
}

}
Loading