Search in sources :

Example 1 with GenericExporter

use of com.querydsl.codegen.GenericExporter in project querydsl by querydsl.

the class GenericExporterTest method execute3.

@Test
public void execute3() {
    GenericExporter exporter = new GenericExporter();
    exporter.setKeywords(Keywords.JPA);
    exporter.setEntityAnnotation(Entity.class);
    exporter.setEmbeddableAnnotation(Embeddable.class);
    exporter.setEmbeddedAnnotation(Embedded.class);
    exporter.setSupertypeAnnotation(MappedSuperclass.class);
    exporter.setSkipAnnotation(Transient.class);
    exporter.setTargetFolder(new File("target/GenericExporterTest3"));
    exporter.setPropertyHandling(PropertyHandling.JPA);
    exporter.export(CustomCollection.MyCustomCollection.class, CustomCollection.MyCustomCollection2.class, CustomCollection.MyEntity.class);
}
Also used : GenericExporter(com.querydsl.codegen.GenericExporter) CustomCollection(com.querydsl.apt.domain.CustomCollection) File(java.io.File) Generic2Test(com.querydsl.apt.domain.Generic2Test) Test(org.junit.Test) AbstractEntityTest(com.querydsl.apt.domain.AbstractEntityTest)

Example 2 with GenericExporter

use of com.querydsl.codegen.GenericExporter in project querydsl by querydsl.

the class GenericExporterTest method execute4.

@Test
public void execute4() throws IOException {
    GenericExporter exporter = new GenericExporter();
    exporter.setKeywords(Keywords.JPA);
    exporter.setEntityAnnotation(Entity.class);
    exporter.setEmbeddableAnnotation(Embeddable.class);
    exporter.setEmbeddedAnnotation(Embedded.class);
    exporter.setSupertypeAnnotation(MappedSuperclass.class);
    exporter.setSkipAnnotation(Transient.class);
    exporter.setTargetFolder(new File("target/GenericExporterTest4"));
    exporter.setPropertyHandling(PropertyHandling.JPA);
    exporter.export(Generic2Test.class.getClasses());
}
Also used : GenericExporter(com.querydsl.codegen.GenericExporter) Generic2Test(com.querydsl.apt.domain.Generic2Test) File(java.io.File) Generic2Test(com.querydsl.apt.domain.Generic2Test) Test(org.junit.Test) AbstractEntityTest(com.querydsl.apt.domain.AbstractEntityTest)

Example 3 with GenericExporter

use of com.querydsl.codegen.GenericExporter in project querydsl by querydsl.

the class GenericExporterTest method execute.

@Test
public void execute() throws IOException {
    // via APT
    process(QuerydslAnnotationProcessor.class, CLASSES, "QuerydslAnnotationProcessor");
    // via GenericExporter
    GenericExporter exporter = new GenericExporter();
    exporter.setTargetFolder(new File("target/GenericExporterTest"));
    exporter.export(AbstractEntityTest.class.getPackage(), A.class.getPackage());
    List<String> expected = new ArrayList<String>();
    // delegates are not supported
    expected.add("QDelegateTest_SimpleUser.java");
    expected.add("QDelegateTest_SimpleUser2.java");
    expected.add("QDelegateTest_User.java");
    expected.add("QDelegate2Test_Entity.java");
    expected.add("QExampleEntity.java");
    expected.add("QQueryProjectionTest_DTOWithProjection.java");
    expected.add("QQueryProjectionTest_EntityWithProjection.java");
    expected.add("QEmbeddable3Test_EmbeddableClass.java");
    expected.add("QQueryEmbedded4Test_User.java");
    execute(expected, "GenericExporterTest", "QuerydslAnnotationProcessor");
}
Also used : GenericExporter(com.querydsl.codegen.GenericExporter) A(com.querydsl.core.domain.A) ArrayList(java.util.ArrayList) AbstractEntityTest(com.querydsl.apt.domain.AbstractEntityTest) File(java.io.File) Generic2Test(com.querydsl.apt.domain.Generic2Test) Test(org.junit.Test) AbstractEntityTest(com.querydsl.apt.domain.AbstractEntityTest)

Example 4 with GenericExporter

use of com.querydsl.codegen.GenericExporter in project querydsl by querydsl.

the class GenericExporterTest method execute2.

@Test
public void execute2() throws IOException {
    // via APT
    process(HibernateAnnotationProcessor.class, CLASSES, "HibernateAnnotationProcessor");
    // via GenericExporter
    GenericExporter exporter = new GenericExporter();
    exporter.setKeywords(Keywords.JPA);
    exporter.setEntityAnnotation(Entity.class);
    exporter.setEmbeddableAnnotation(Embeddable.class);
    exporter.setEmbeddedAnnotation(Embedded.class);
    exporter.setSupertypeAnnotation(MappedSuperclass.class);
    exporter.setSkipAnnotation(Transient.class);
    exporter.setTargetFolder(new File("target/GenericExporterTest2"));
    exporter.setStrictMode(true);
    exporter.setPropertyHandling(PropertyHandling.JPA);
    exporter.export(AbstractEntityTest.class.getPackage(), A.class.getPackage());
    List<String> expected = new ArrayList<String>();
    // GenericExporter doesn't include field/method selection
    expected.add("QTemporalTest_MyEntity.java");
    expected.add("QTemporal2Test_Cheque.java");
    expected.add("QQueryProjectionTest_DTOWithProjection.java");
    expected.add("QQueryProjectionTest_EntityWithProjection.java");
    expected.add("QEmbeddable3Test_EmbeddableClass.java");
    expected.add("QGeneric4Test_HidaBez.java");
    expected.add("QGeneric4Test_HidaBezGruppe.java");
    expected.add("QInterfaceType2Test_UserImpl.java");
    expected.add("QOrderTest_Order.java");
    expected.add("QManagedEmailTest_ManagedEmails.java");
    expected.add("QGeneric12Test_ChannelRole.java");
    expected.add("QManyToManyTest_Person.java");
    expected.add("QOneToOneTest_Person.java");
    expected.add("QGeneric16Test_HidaBez.java");
    expected.add("QGeneric16Test_HidaBezGruppe.java");
    execute(expected, "GenericExporterTest2", "HibernateAnnotationProcessor");
}
Also used : GenericExporter(com.querydsl.codegen.GenericExporter) A(com.querydsl.core.domain.A) ArrayList(java.util.ArrayList) AbstractEntityTest(com.querydsl.apt.domain.AbstractEntityTest) File(java.io.File) Generic2Test(com.querydsl.apt.domain.Generic2Test) Test(org.junit.Test) AbstractEntityTest(com.querydsl.apt.domain.AbstractEntityTest)

Example 5 with GenericExporter

use of com.querydsl.codegen.GenericExporter in project querydsl by querydsl.

the class AbstractExporterMojo method execute.

@SuppressWarnings("unchecked")
@Override
public void execute() throws MojoExecutionException, MojoFailureException {
    if (testClasspath) {
        project.addTestCompileSourceRoot(targetFolder.getAbsolutePath());
    } else {
        project.addCompileSourceRoot(targetFolder.getAbsolutePath());
    }
    if (skip || !hasSourceChanges()) {
        // prevent m2e from entering an infinite build cycle.
        return;
    }
    ClassLoader classLoader = null;
    try {
        classLoader = getProjectClassLoader();
    } catch (MalformedURLException | DependencyResolutionRequiredException e) {
        throw new MojoFailureException(e.getMessage(), e);
    }
    Charset charset = sourceEncoding != null ? Charset.forName(sourceEncoding) : Charset.defaultCharset();
    GenericExporter exporter = new GenericExporter(classLoader, charset);
    exporter.setTargetFolder(targetFolder);
    if (scala) {
        try {
            exporter.setSerializerClass((Class<? extends Serializer>) Class.forName("com.querydsl.scala.ScalaEntitySerializer"));
            exporter.setTypeMappingsClass((Class<? extends TypeMappings>) Class.forName("com.querydsl.scala.ScalaTypeMappings"));
            exporter.setCreateScalaSources(true);
        } catch (ClassNotFoundException e) {
            throw new MojoFailureException(e.getMessage(), e);
        }
    }
    configure(exporter);
    exporter.export(packages);
}
Also used : GenericExporter(com.querydsl.codegen.GenericExporter) MalformedURLException(java.net.MalformedURLException) DependencyResolutionRequiredException(org.apache.maven.artifact.DependencyResolutionRequiredException) MojoFailureException(org.apache.maven.plugin.MojoFailureException) URLClassLoader(java.net.URLClassLoader) Charset(java.nio.charset.Charset)

Aggregations

GenericExporter (com.querydsl.codegen.GenericExporter)5 AbstractEntityTest (com.querydsl.apt.domain.AbstractEntityTest)4 Generic2Test (com.querydsl.apt.domain.Generic2Test)4 File (java.io.File)4 Test (org.junit.Test)4 A (com.querydsl.core.domain.A)2 ArrayList (java.util.ArrayList)2 CustomCollection (com.querydsl.apt.domain.CustomCollection)1 MalformedURLException (java.net.MalformedURLException)1 URLClassLoader (java.net.URLClassLoader)1 Charset (java.nio.charset.Charset)1 DependencyResolutionRequiredException (org.apache.maven.artifact.DependencyResolutionRequiredException)1 MojoFailureException (org.apache.maven.plugin.MojoFailureException)1