Search in sources :

Example 1 with SimpleCompiler

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;##");
}
Also used : SimpleCompiler(com.querydsl.codegen.utils.SimpleCompiler) FileWriter(java.io.FileWriter) JavaWriter(com.querydsl.codegen.utils.JavaWriter) ClassType(com.querydsl.codegen.utils.model.ClassType) PrimaryKeyData(com.querydsl.sql.codegen.support.PrimaryKeyData) URLClassLoader(java.net.URLClassLoader) ColumnImpl(com.querydsl.sql.ColumnImpl) Property(com.querydsl.codegen.Property) Test(org.junit.Test)

Example 2 with SimpleCompiler

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");
    }
}
Also used : SimpleCompiler(com.querydsl.codegen.utils.SimpleCompiler) JavaCompiler(javax.tools.JavaCompiler)

Example 3 with SimpleCompiler

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());
    }
}
Also used : SimpleCompiler(com.querydsl.codegen.utils.SimpleCompiler) SimpleJavaFileObject(javax.tools.SimpleJavaFileObject) StringWriter(java.io.StringWriter) MemFileManager(com.querydsl.codegen.utils.MemFileManager) MemSourceFileObject(com.querydsl.codegen.utils.MemSourceFileObject) JavaCompiler(javax.tools.JavaCompiler) StringWriter(java.io.StringWriter) Writer(java.io.Writer)

Aggregations

SimpleCompiler (com.querydsl.codegen.utils.SimpleCompiler)3 JavaCompiler (javax.tools.JavaCompiler)2 Property (com.querydsl.codegen.Property)1 JavaWriter (com.querydsl.codegen.utils.JavaWriter)1 MemFileManager (com.querydsl.codegen.utils.MemFileManager)1 MemSourceFileObject (com.querydsl.codegen.utils.MemSourceFileObject)1 ClassType (com.querydsl.codegen.utils.model.ClassType)1 ColumnImpl (com.querydsl.sql.ColumnImpl)1 PrimaryKeyData (com.querydsl.sql.codegen.support.PrimaryKeyData)1 FileWriter (java.io.FileWriter)1 StringWriter (java.io.StringWriter)1 Writer (java.io.Writer)1 URLClassLoader (java.net.URLClassLoader)1 SimpleJavaFileObject (javax.tools.SimpleJavaFileObject)1 Test (org.junit.Test)1