
com.fluxtion.compiler.generation.GenerationContext Maven / Gradle / Ivy
/*
* Copyright (C) 2018 2024 gregory higgins.
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the Server Side Public License, version 1,
* as published by MongoDB, Inc.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* Server Side Public License for more details.
*
* You should have received a copy of the Server Side Public License
* along with this program. If not, see
* .
*/
package com.fluxtion.compiler.generation;
import com.fluxtion.compiler.builder.EventProcessorBuilderServiceImpl;
import com.fluxtion.runtime.callback.InstanceCallbackEvent;
import lombok.Data;
import lombok.extern.slf4j.Slf4j;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
import java.io.*;
import java.nio.file.Files;
import java.nio.file.Paths;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.concurrent.atomic.AtomicInteger;
import static java.nio.charset.StandardCharsets.UTF_8;
/**
* Context for the generated output of the SEP. Provides functions to control
* generation outputs from Fluxtion, but is not used to describe the graph
* processing structure of a SEP.
*
* @author Greg Higgins
*/
@Data
@Slf4j
public class GenerationContext {
public static GenerationContext SINGLETON;
public static ClassLoader DEFAULT_CLASSLOADER;
private static final AtomicInteger COUNT = new AtomicInteger();
private final Map super Object, Map> cacheMap;
/**
* A global counter, can be used for generating unique class names.
*
* @return next id.
*/
public static int nextId() {
return COUNT.getAndIncrement();
}
private static class X {
}
public int nextId(String className) {
@SuppressWarnings("unchecked")
Map classCount = cacheMap.computeIfAbsent(X.class, k -> new HashMap());
String key = packageName + "." + className;
return classCount.compute(key, (String k, Integer v) -> {
int ret = 0;
if (v != null) {
ret = v + 1;
}
return ret;
});
}
public static void setupStaticContext(String packageName, String className, File outputDirectory, File resourcesRootDirectory) {
setupStaticContext(packageName, className, outputDirectory, resourcesRootDirectory, false);
}
public static void setupStaticContext(String packageName, String className, File outputDirectory, File resourcesRootDirectory, boolean createResourceDirectory) {
File buildDir = null;
if (!System.getProperty("fluxtion.build.outputdirectory", "").isEmpty()) {
buildDir = new File(System.getProperty("fluxtion.build.outputdirectory", ""));
}
SINGLETON = new GenerationContext(packageName, className, outputDirectory, resourcesRootDirectory, buildDir);
SINGLETON.createDirectories();
if (createResourceDirectory) {
SINGLETON.createResourceDirectory();
}
}
public static void setupStaticContext(ClassLoader classLoader,
String packageName,
String className,
File outputDirectory,
File resourcesRootDirectory,
boolean createResourceDirectory,
File buildOutputDirectory,
boolean createBuildOutputDirectory) {
SINGLETON = new GenerationContext(
classLoader,
packageName,
className,
outputDirectory,
resourcesRootDirectory,
buildOutputDirectory);
SINGLETON.createDirectories();
if (createResourceDirectory) {
SINGLETON.createResourceDirectory();
}
if (createBuildOutputDirectory && buildOutputDirectory != null) {
buildOutputDirectory.mkdirs();
}
}
/**
* Map representing the name of the actual node class generated at SEP
* processing stage. Allowing a generic proxy class to be used in the SEP
* model processing phase and then replaced with the actual class reference
* during the code generation phase. The real class name is only known after
* the proxy has been generated.
*/
private final Map
© 2015 - 2025 Weber Informatics LLC | Privacy Policy