use of com.querydsl.codegen.utils.SimpleCompiler in project querydsl by querydsl.
the class ExtendedBeanSerializerTest method equals_hashcode_tostring.
@Test
public void equals_hashcode_tostring() throws Exception {
Property idCol = new Property(type, "id", new ClassType(Integer.class));
idCol.addAnnotation(new ColumnImpl("ID"));
Property subIdCol = new Property(type, "sub_id", new ClassType(String.class));
subIdCol.addAnnotation(new ColumnImpl("SUB_ID"));
Property nameCol = new Property(type, "name", new ClassType(String.class));
nameCol.addAnnotation(new ColumnImpl("NAME"));
type.addProperty(idCol);
type.addProperty(subIdCol);
type.addProperty(nameCol);
type.getData().put(PrimaryKeyData.class, Arrays.asList(new PrimaryKeyData("PK", new String[] { "ID", "SUB_ID" })));
ExtendedBeanSerializer extendedBeanSerializer = new ExtendedBeanSerializer();
extendedBeanSerializer.setAddToString(true);
FileWriter fw = new FileWriter(srcFile);
extendedBeanSerializer.serialize(type, SimpleSerializerConfig.DEFAULT, new JavaWriter(fw));
fw.close();
URLClassLoader classLoader = URLClassLoader.newInstance(new URL[] { compileFolder.getRoot().toURI().toURL() });
int retCode = new SimpleCompiler().run(null, System.out, System.err, srcFile.getAbsolutePath());
assertEquals("The generated source should compile", 0, retCode);
Class<?> cls = Class.forName(FULL_NAME, true, classLoader);
ReflectionHelper reflection = new ReflectionHelper(cls);
Object obj1 = cls.newInstance();
Object obj1a = cls.newInstance();
Object obj2 = cls.newInstance();
reflection.setValues(obj1, 1, "##", "X");
reflection.setValues(obj1a, 1, "##", null);
reflection.setValues(obj2, 2, "--", "Y");
assertEquals(obj1, obj1a);
assertEquals(obj1.hashCode(), obj1a.hashCode());
assertNotEquals(obj1, obj2);
assertEquals(obj1.toString(), "DomainClass#1;##");
}
use of com.querydsl.codegen.utils.SimpleCompiler in project querydsl by querydsl.
the class MetaDataSerializerTest method compile.
private void compile(MetaDataExporter exporter) {
JavaCompiler compiler = new SimpleCompiler();
Set<String> classes = exporter.getClasses();
int compilationResult = compiler.run(null, null, null, classes.toArray(new String[0]));
if (compilationResult == 0) {
System.out.println("Compilation is successful");
} else {
Assert.fail("Compilation Failed");
}
}
use of com.querydsl.codegen.utils.SimpleCompiler in project querydsl by querydsl.
the class CompileUtils method assertCompiles.
public static void assertCompiles(String name, String source) {
ClassLoader parent = CompileUtils.class.getClassLoader();
SimpleCompiler compiler = new SimpleCompiler();
MemFileManager fileManager = new MemFileManager(parent, compiler.getStandardFileManager(null, null, null));
String classpath = SimpleCompiler.getClassPath(parent);
List<String> compilationOptions = Arrays.asList("-classpath", classpath, "-g:none");
// compile
SimpleJavaFileObject javaFileObject = new MemSourceFileObject(name, source);
Writer out = new StringWriter();
JavaCompiler.CompilationTask task = compiler.getTask(out, fileManager, null, compilationOptions, null, Collections.singletonList(javaFileObject));
if (!task.call()) {
Assert.fail("Compilation of " + source + " failed.\n" + out.toString());
}
}
Aggregations