Commit 6a2c2e11 authored by Vincent Horváth's avatar Vincent Horváth

fixed detection called from backend or fronted tor override template for generator

parent eef63118
......@@ -7,7 +7,7 @@ public interface ApplicationConfiguration {
String getFrontendProjectPath();
String getFrontendResourcePath();
String getFrontendResourcesPath();
String getBackendJar();
......@@ -17,5 +17,5 @@ public interface ApplicationConfiguration {
String getBackendClass();
String getBackendResourcePath();
String getBackendResourcesPath();
}
......@@ -2,10 +2,9 @@ package sk.tuke.bfi.core.helper.impl;
import org.apache.commons.io.IOUtils;
import org.apache.log4j.Logger;
import sk.tuke.bfi.core.generator.impl.GeneratorImpl;
import sk.tuke.bfi.core.helper.Helper;
import sk.tuke.bfi.core.helper.HelperFactory;
import sk.tuke.bfi.core.interpret.types.BackendInterface;
import sk.tuke.bfi.core.interpret.types.FrontendInterface;
import java.io.*;
import java.util.Scanner;
......@@ -16,10 +15,10 @@ import static sk.tuke.bfi.core.GeneratorState.getGeneratorState;
public class ResourceHelper implements Helper {
private final static Logger LOGGER = Logger.getLogger(ResourceHelper.class);
private ApplicationHelper applicationHelper = HelperFactory.getHelper(ApplicationHelper.class);
private Class<?> baseInterfaceClass;
private boolean callerIsBackendGenerator;
public String getContentFromFile(final String path, Class<?> baseInterfaceClass) {
this.baseInterfaceClass = baseInterfaceClass;
public String getContentFromFile(final String path) {
backendCallerDetection();
try {
final String customConntent = getCustomResources(path);
if (customConntent != null) {
......@@ -48,16 +47,15 @@ public class ResourceHelper implements Helper {
private String getCustomResources(final String path) throws FileNotFoundException {
String resourceRoot = null;
if (FrontendInterface.class.isAssignableFrom(baseInterfaceClass)) {
resourceRoot = getGeneratorState().getApplicationConfiguration().getFrontendResourcePath();
} else if (BackendInterface.class.isAssignableFrom(baseInterfaceClass)) {
resourceRoot = getGeneratorState().getApplicationConfiguration().getBackendResourcePath();
if (!callerIsBackendGenerator) {
resourceRoot = getGeneratorState().getApplicationConfiguration().getFrontendResourcesPath();
} else {
resourceRoot = getGeneratorState().getApplicationConfiguration().getBackendResourcesPath();
}
if (resourceRoot == null) {
return null;
}
final File file = new File(resourceRoot + path);
if (file.exists() && file.isFile()) {
Scanner scanner = new Scanner(file, UTF_8.name());
......@@ -67,4 +65,22 @@ public class ResourceHelper implements Helper {
}
return null;
}
private void backendCallerDetection() {
final StackTraceElement[] stackTraceElements = Thread.currentThread().getStackTrace();
String declaringMethodName;
String declaringClassName;
Boolean isBackend = false;
for (int idx = 0; idx < stackTraceElements.length; idx++) {
declaringMethodName = stackTraceElements[idx].getMethodName();
declaringClassName = stackTraceElements[idx].getClassName();
if (GeneratorImpl.class.getName().equals(declaringClassName)) {
isBackend = declaringMethodName.toLowerCase().contains("backend");
if (isBackend) {
break;
}
}
}
callerIsBackendGenerator = isBackend;
}
}
......@@ -73,7 +73,7 @@ public class TemplateHelper implements Helper {
}
public String getTemplateContent(String templatePath) {
return resourceHelper.getContentFromFile(HelperFunctions.joinString(rootTemplateDir, templatePath, HelpVariable.FILE_EXTENSIONS_SEPARATOR, TEMPLATE_EXTENSIONS), Thread.currentThread().getStackTrace().getClass());
return resourceHelper.getContentFromFile(HelperFunctions.joinString(rootTemplateDir, templatePath, HelpVariable.FILE_EXTENSIONS_SEPARATOR, TEMPLATE_EXTENSIONS));
}
public static void clearFile(String folder) {
......
......@@ -25,7 +25,7 @@ public class DataTypeMapper implements Mapper {
}
private void load(String filePath) {
final String content = resourceHelper.getContentFromFile(HelperFunctions.joinString(ROOT_PATH, filePath, StringConstant.DOT_STRING, FILE_EXTENSION), Thread.currentThread().getStackTrace().getClass());
final String content = resourceHelper.getContentFromFile(HelperFunctions.joinString(ROOT_PATH, filePath, StringConstant.DOT_STRING, FILE_EXTENSION));
if (content == null || content.length() == 0) {
LOGGER.error("Content for mapping is empty.");
......
......@@ -56,6 +56,8 @@ public class RunService {
clean();
} else if (runOptions.getCmd().hasOption(RunOptions.CREATE)) {
create();
}else{
build();
}
}
......@@ -186,12 +188,12 @@ public class RunService {
private String frontendJar;
private String frontendClass;
private String frontendProjectPath;
private String frontendResourcePath;
private String frontendResourcesPath;
private String backendJar;
private String backendClass;
private String backendProjectPath;
private String backendResourcePath;
private String backendResourcesPath;
public Configuration(Preferences preferences) {
setBfiPreferences(preferences.node(NODE_BFI));
......@@ -241,27 +243,27 @@ public class RunService {
}
@Override
public String getFrontendResourcePath() {
return frontendResourcePath;
public String getFrontendResourcesPath() {
return frontendResourcesPath;
}
@Override
public String getBackendResourcePath() {
return backendResourcePath;
public String getBackendResourcesPath() {
return backendResourcesPath;
}
private void setFrontendPreferences(Preferences preferences) {
frontendJar = preferences.get("jar", null);
frontendClass = preferences.get("class", null);
frontendProjectPath = preferences.get("projectPath", null);
frontendResourcePath = preferences.get("resourcePath", null);
frontendResourcesPath = preferences.get("resourcesPath", null);
}
private void setBackendPreferences(Preferences preferences) {
backendJar = preferences.get("jar", null);
backendClass = preferences.get("class", null);
backendProjectPath = preferences.get("projectPath", null);
backendResourcePath = preferences.get("resourcePath", null);
backendResourcesPath = preferences.get("resourcesPath", null);
}
private void setBfiPreferences(Preferences preferences) {
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment