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

optional build time in generated file #242

Merged
merged 1 commit into from
Oct 24, 2023
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
Original file line number Diff line number Diff line change
Expand Up @@ -94,13 +94,18 @@ public class FluxtionCompilerConfig {
* The if {@link #writeSourceToFile} is false this writer will capture the content of the generation process
*/
private Writer sourceWriter;
/**
* Flag controlling adding build time to generated source files
*/
private boolean addBuildTime;

private transient ClassLoader classLoader;

public FluxtionCompilerConfig() {
generateDescription = false;
writeSourceToFile = false;
compileSource = true;
addBuildTime = false;
formatSource = true;
templateSep = JAVA_TEMPLATE;
classLoader = FluxtionCompilerConfig.class.getClassLoader();
Expand Down Expand Up @@ -157,6 +162,14 @@ public void setWriteSourceToFile(boolean writeSourceToFile) {
this.writeSourceToFile = writeSourceToFile;
}

public boolean isAddBuildTime() {
return addBuildTime;
}

public void setAddBuildTime(boolean addBuildTime) {
this.addBuildTime = addBuildTime;
}

public void setPackageName(String packageName) {
this.packageName = packageName;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@ private Class<?> generateSep() throws Exception {
}

EventProcessorGenerator eventProcessorGenerator = new EventProcessorGenerator();
eventProcessorGenerator.templateSep(builderConfig, compilerConfig.isGenerateDescription(), writer);
eventProcessorGenerator.templateSep(builderConfig, compilerConfig, writer);
GenerationContext generationConfig = GenerationContext.SINGLETON;
String fqn = generationConfig.getPackageName() + "." + generationConfig.getSepClassName();
File file = new File(generationConfig.getPackageDirectory(), generationConfig.getSepClassName() + ".java");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
package com.fluxtion.compiler.generation.compiler;

import com.fluxtion.compiler.EventProcessorConfig;
import com.fluxtion.compiler.FluxtionCompilerConfig;
import com.fluxtion.compiler.builder.factory.NodeFactoryLocator;
import com.fluxtion.compiler.builder.factory.NodeFactoryRegistration;
import com.fluxtion.compiler.generation.GenerationContext;
Expand Down Expand Up @@ -63,6 +64,7 @@ public class EventProcessorGenerator {
private EventProcessorConfig config;
private static final Logger LOG = LoggerFactory.getLogger(EventProcessorGenerator.class);
private SimpleEventProcessorModel simpleEventProcessorModel;
private FluxtionCompilerConfig compilerConfig;

public InMemoryEventProcessor inMemoryProcessor(EventProcessorConfig config, boolean generateDescription) throws Exception {
config.buildConfig();
Expand Down Expand Up @@ -95,10 +97,11 @@ public InMemoryEventProcessor inMemoryProcessor(EventProcessorConfig config, boo
return new InMemoryEventProcessor(simpleEventProcessorModel, config);
}

public void templateSep(EventProcessorConfig config, boolean generateDescription, Writer writer) throws Exception {
public void templateSep(EventProcessorConfig config, FluxtionCompilerConfig compilerConfig, Writer writer) throws Exception {
ExecutorService execSvc = Executors.newCachedThreadPool();
config.buildConfig();
this.config = config;
this.compilerConfig = compilerConfig;
LOG.debug("init velocity");
initVelocity();
LOG.debug("start graph calc");
Expand All @@ -117,7 +120,7 @@ public void templateSep(EventProcessorConfig config, boolean generateDescription
simpleEventProcessorModel.generateMetaModel(config.isSupportDirtyFiltering());
//TODO add conditionality for different target languages
//buildJava output
if (generateDescription) {
if (compilerConfig.isGenerateDescription()) {
execSvc.submit(() -> {
LOG.debug("start exporting graphML/images");
exportGraphMl(graph);
Expand Down Expand Up @@ -190,7 +193,11 @@ private void templateJavaOutput(Writer templateWriter) throws Exception {
private void addVersionInformation(Context ctx) {
ctx.put("generator_version_information", this.getClass().getPackage().getImplementationVersion());
ctx.put("api_version_information", OnEventHandler.class.getPackage().getImplementationVersion());
ctx.put("build_time", LocalDateTime.now());
if (compilerConfig.isAddBuildTime()) {
ctx.put("build_time", LocalDateTime.now());
} else {
ctx.put("build_time", "Not available");
}
}

public static void formatSource(File outFile) {
Expand Down