Commit ce523622 authored by Vincent Horváth's avatar Vincent Horváth

hot fix

parent 517d921a
......@@ -17,7 +17,7 @@ public abstract class AngularGenerator implements TemplateGeneratorInterface {
protected TemplateHelper templateHelper;
protected static final String FILE_EXTENSIONS = "ts";
protected static final String FILE_STYLE_EXTENSIONS = "css";
protected MapperHelper jsMapperHelper = HelperFactory.getHelper(MapperHelper.class, new HelperParameter<String>("js-type"));
protected MapperHelper jsMapperHelper = new MapperHelper("js-type");
public AngularGenerator(Model model, String projectRoot) {
this.model = model;
......
......@@ -15,6 +15,7 @@ import sk.tuke.bfi.core.generator.TemplateGeneratorInterface;
import sk.tuke.bfi.core.generator.annotation.Generator;
import sk.tuke.bfi.core.generator.annotation.GeneratorMethod;
import sk.tuke.bfi.core.generator.annotation.GeneratorSaveTo;
import sk.tuke.bfi.core.helper.impl.ResourceHelper;
import sk.tuke.bfi.core.preprocessor.annotation.Preprocessor;
import sk.tuke.bfi.core.preprocessor.html.HtmlPreprocessor;
import sk.tuke.bfi.core.helper.HelperFactory;
......@@ -45,6 +46,7 @@ public class GeneratorImpl implements sk.tuke.bfi.core.generator.Generator {
private String projectRoot;
private List<Class<TemplateGeneratorInterface>> templateGeneratorInterfaceClasses = new ArrayList<>();
private boolean enableOverwrite = false;
private ClassLoader classLoader;
private FileHelper fileHelper = HelperFactory.getHelper(FileHelper.class);
private final static Logger LOGGER = Logger.getLogger(GeneratorImpl.class);
......@@ -94,7 +96,7 @@ public class GeneratorImpl implements sk.tuke.bfi.core.generator.Generator {
}
private <T> void runTemplateGenerator(Class<TemplateGeneratorInterface> generatorClass, T subject) {
ResourceHelper.classLoader=classLoader;
final Generator annGenerator = generatorClass.getAnnotation(Generator.class);
Constructor<?> ctor = null;
try {
......@@ -108,7 +110,7 @@ public class GeneratorImpl implements sk.tuke.bfi.core.generator.Generator {
assert ctor != null;
obj = ctor.newInstance(subject, projectRoot);
} catch (InstantiationException | IllegalAccessException | InvocationTargetException e) {
LOGGER.error(e.getMessage(), e);
LOGGER.error(e.getMessage(), e.getCause());
return;
}
......@@ -133,7 +135,7 @@ public class GeneratorImpl implements sk.tuke.bfi.core.generator.Generator {
}
public void generateFrontend() {
LOGGER.info("Starting generate for view " + frontendInterpreter.getFile().getName());
LOGGER.info("Starting generate for frontend " + frontendInterpreter.getFile().getName());
for (Map.Entry<String, BaseEntity> entityEntry : frontendInterpreter.getEntities().entrySet()) {
frontendInterpreter.setEntity(entityEntry.getValue());
frontendInterpreter.beforeGenerate();
......@@ -328,10 +330,14 @@ public class GeneratorImpl implements sk.tuke.bfi.core.generator.Generator {
}
private <T> List<Class<?>> getAnnotationClasses(final Class<T> ann, final Package searchPackage) {
final ScanResult scanResult =
new ClassGraph()
.initializeLoadedClasses()
.enableExternalClasses()
.enableAnnotationInfo()
.whitelistPackages(searchPackage.getName())
.addClassLoader(classLoader)
.scan();
final ClassInfoList routes =
......@@ -339,7 +345,7 @@ public class GeneratorImpl implements sk.tuke.bfi.core.generator.Generator {
final List<Class<?>> classes = new ArrayList<>();
for (String className : routes.getNames()) {
try {
classes.add(Class.forName(className));
classes.add(classLoader.loadClass(className));
} catch (ClassNotFoundException e) {
LOGGER.error(e.getMessage(), e);
continue;
......@@ -359,4 +365,7 @@ public class GeneratorImpl implements sk.tuke.bfi.core.generator.Generator {
LOGGER.info("Save generated template " + templateGenerator.getClass());
}
public void setClassLoader(ClassLoader classLoader) {
this.classLoader = classLoader;
}
}
......@@ -26,8 +26,6 @@ public class HelperFactory {
}
try {
System.out.println();
Constructor<?> constructor = helperCLass.getDeclaredConstructors()[0];
constructor.setAccessible(true);
Object[] objects = new Object[helperParameters.length];
......
package sk.tuke.bfi.core.helper.impl;
import org.apache.commons.io.IOUtils;
import org.apache.log4j.Logger;
import sk.tuke.bfi.core.helper.Helper;
import sk.tuke.bfi.core.helper.HelperFactory;
import java.io.*;
import java.nio.charset.Charset;
import java.nio.file.Files;
import java.nio.file.Paths;
public class ResourceHelper implements Helper {
private final static Logger LOGGER = Logger.getLogger(ResourceHelper.class);
public static ClassLoader classLoader;
private ApplicationHelper applicationHelper = HelperFactory.getHelper(ApplicationHelper.class);
public String getContentFromFile(String path) {
if (applicationHelper.isRunningWithInJar()) {
InputStream in = getClass().getResourceAsStream(File.separator + path);
InputStream in = classLoader.getResourceAsStream(File.separator + path);
BufferedReader reader = new BufferedReader(new InputStreamReader(in));
try {
return org.apache.commons.io.IOUtils.toString(reader);
......@@ -24,7 +26,7 @@ public class ResourceHelper implements Helper {
}
} else {
try {
return new String(Files.readAllBytes(Paths.get(getClass().getClassLoader().getResource(path).getPath())));
return IOUtils.toString(classLoader.getResourceAsStream(path), "UTF-8");
} catch (IOException e) {
LOGGER.error(e.getMessage(), e);
}
......
......@@ -22,6 +22,7 @@
<artifactId>commons-cli</artifactId>
<version>1.4</version>
</dependency>
</dependencies>
<build>
<plugins>
......
......@@ -24,4 +24,8 @@ public class ClassLoaderService {
Class<T> cls = (Class<T>) classLoader.loadClass(className);
return cls.getConstructor(constructorParameterTypes).newInstance(constructorParameterValues);
}
public ClassLoader getClassLoader() {
return classLoader;
}
}
......@@ -114,6 +114,7 @@ public class RunService {
final FrontendInterface frontend = classLoaderHelper.createObject(FrontendInterface.class, configuration.getFrontendClass(), parameters, values);
generator = new GeneratorImpl(backend, frontend);
((GeneratorImpl) generator).setClassLoader(classLoaderHelper.getClassLoader());
languageBuilder = LanguageBuilder.getBuilder(configuration.getBfiProjectPath(), generator);
}
......
......@@ -12,8 +12,8 @@ public abstract class SymfonyGenerator implements TemplateGeneratorInterface {
protected String projectRoot;
protected TemplateHelper templateHelper;
protected static final String FILE_EXTENSIONS = "php";
protected MapperHelper phpMapperHelper = HelperFactory.getHelper(MapperHelper.class, new HelperParameter<String>("php-type"));
protected MapperHelper doctrineMapperHelper = HelperFactory.getHelper(MapperHelper.class, new HelperParameter<String>("doctrine-meta-type"));
protected MapperHelper phpMapperHelper =new MapperHelper("php-type");
protected MapperHelper doctrineMapperHelper = new MapperHelper("doctrine-meta-type");
public SymfonyGenerator(Model model, String projectRoot) {
this.model = model;
......
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