Search in sources :

Example 1 with Generated

use of jakarta.annotation.Generated in project eclipselink by eclipse-ee4j.

the class TestProcessor method testGenerate.

private void testGenerate(String name, String pxml, String oxml) throws Exception {
    TestFO entity = new TestFO("org.Sample", "package org; import jakarta.persistence.Entity; @Entity public class Sample { public  Sample() {} public int getX() {return 1;} interface A {}}");
    Result result = runProject(name, getJavacOptions("-A" + CanonicalModelProperties.CANONICAL_MODEL_GENERATE_GENERATED + "=false", "-Aeclipselink.logging.level.processor=OFF"), Arrays.asList(entity), pxml, oxml);
    File outputFile = new File(result.srcOut, "org/Sample_.java");
    Assert.assertTrue("Model file not generated", outputFile.exists());
    Assert.assertTrue(Files.lines(outputFile.toPath()).noneMatch(s -> s.contains("Generated")));
    Assert.assertTrue("Compilation failed", result.success);
}
Also used : Entity(jakarta.persistence.Entity) Arrays(java.util.Arrays) CanonicalModelProcessor(org.eclipse.persistence.internal.jpa.modelgen.CanonicalModelProcessor) BeforeClass(org.junit.BeforeClass) URL(java.net.URL) ArrayList(java.util.ArrayList) CompilationTask(javax.tools.JavaCompiler.CompilationTask) Diagnostic(javax.tools.Diagnostic) URI(java.net.URI) Path(java.nio.file.Path) DiagnosticCollector(javax.tools.DiagnosticCollector) SimpleFileVisitor(java.nio.file.SimpleFileVisitor) PrintWriter(java.io.PrintWriter) SimpleJavaFileObject(javax.tools.SimpleJavaFileObject) StandardLocation(javax.tools.StandardLocation) Files(java.nio.file.Files) JavaCompiler(javax.tools.JavaCompiler) BufferedWriter(java.io.BufferedWriter) StandardOpenOption(java.nio.file.StandardOpenOption) CanonicalModelProperties(org.eclipse.persistence.internal.jpa.modelgen.CanonicalModelProperties) IOException(java.io.IOException) Test(org.junit.Test) BasicFileAttributes(java.nio.file.attribute.BasicFileAttributes) File(java.io.File) Generated(jakarta.annotation.Generated) JavaFileObject(javax.tools.JavaFileObject) FileVisitResult(java.nio.file.FileVisitResult) StandardJavaFileManager(javax.tools.StandardJavaFileManager) List(java.util.List) Assert(org.junit.Assert) Collections(java.util.Collections) ToolProvider(javax.tools.ToolProvider) File(java.io.File) FileVisitResult(java.nio.file.FileVisitResult)

Example 2 with Generated

use of jakarta.annotation.Generated in project eclipselink by eclipse-ee4j.

the class TestProcessor method testGenerateComment.

private void testGenerateComment(String name, String pxml, String oxml) throws Exception {
    TestFO entity = new TestFO("org.Sample", "package org; import jakarta.persistence.Entity; @Entity public class Sample { public  Sample() {} public int getX() {return 1;} interface A {}}");
    Result result = runProject(name, getJavacOptions("-A" + CanonicalModelProperties.CANONICAL_MODEL_GENERATE_COMMENTS + "=false", "-Aeclipselink.logging.level.processor=OFF"), Arrays.asList(entity), pxml, oxml);
    File outputFile = new File(result.srcOut, "org/Sample_.java");
    Assert.assertTrue("Model file not generated", outputFile.exists());
    Assert.assertTrue(Files.lines(outputFile.toPath()).noneMatch(s -> s.contains("comments=")));
    Assert.assertTrue("Compilation failed", result.success);
}
Also used : Entity(jakarta.persistence.Entity) Arrays(java.util.Arrays) CanonicalModelProcessor(org.eclipse.persistence.internal.jpa.modelgen.CanonicalModelProcessor) BeforeClass(org.junit.BeforeClass) URL(java.net.URL) ArrayList(java.util.ArrayList) CompilationTask(javax.tools.JavaCompiler.CompilationTask) Diagnostic(javax.tools.Diagnostic) URI(java.net.URI) Path(java.nio.file.Path) DiagnosticCollector(javax.tools.DiagnosticCollector) SimpleFileVisitor(java.nio.file.SimpleFileVisitor) PrintWriter(java.io.PrintWriter) SimpleJavaFileObject(javax.tools.SimpleJavaFileObject) StandardLocation(javax.tools.StandardLocation) Files(java.nio.file.Files) JavaCompiler(javax.tools.JavaCompiler) BufferedWriter(java.io.BufferedWriter) StandardOpenOption(java.nio.file.StandardOpenOption) CanonicalModelProperties(org.eclipse.persistence.internal.jpa.modelgen.CanonicalModelProperties) IOException(java.io.IOException) Test(org.junit.Test) BasicFileAttributes(java.nio.file.attribute.BasicFileAttributes) File(java.io.File) Generated(jakarta.annotation.Generated) JavaFileObject(javax.tools.JavaFileObject) FileVisitResult(java.nio.file.FileVisitResult) StandardJavaFileManager(javax.tools.StandardJavaFileManager) List(java.util.List) Assert(org.junit.Assert) Collections(java.util.Collections) ToolProvider(javax.tools.ToolProvider) File(java.io.File) FileVisitResult(java.nio.file.FileVisitResult)

Example 3 with Generated

use of jakarta.annotation.Generated in project eclipselink by eclipse-ee4j.

the class TestProcessor method testProc.

private void testProc(String name, String pxml, String oxml) throws Exception {
    TestFO entity = new TestFO("org.Sample", "package org; import jakarta.persistence.Entity; @Entity public class Sample { public  Sample() {} public int getX() {return 1;} interface A {}}");
    TestFO nonSC = new TestFO("some.IF", "package some; public class IF { public IF() {}}");
    TestFO nonAnn = new TestFO("custom.Ann", "package custom; public @interface Ann { }");
    TestFO nonExt = new TestFO("external.Cls", "package external; public class Cls { public Cls(){}}");
    TestFO nonEntity = new TestFO("org.NotE", "package org; import jakarta.persistence.Entity; public class NotE extends some.IF { public  NotE() {} @custom.Ann public external.Cls getW() {return new Object();}}");
    TestFO generated8 = new TestFO("org.Gen8", "package org; import jakarta.annotation.Generated; @Generated(\"com.example.Generator\") public class Gen8 { public  Gen8() {} public int getY() {return 42;}}");
    TestFO generated9 = new TestFO("org.Gen9", "package org; @javax.annotation.processing.Generated(\"com.example.Generator\") public class Gen9 { public  Gen9() {} public int getZ() {return 9*42;}}");
    Result result = runProject(name, getJavacOptions("-Aeclipselink.logging.level.processor=OFF"), Arrays.asList(entity, nonSC, nonAnn, nonExt, nonEntity, generated8, generated9), pxml, oxml);
    File outputFile = new File(result.srcOut, "org/Sample_.java");
    Assert.assertTrue("Model file not generated", outputFile.exists());
    Assert.assertTrue(Files.lines(outputFile.toPath()).anyMatch(s -> s.contains("@StaticMetamodel(Sample.class)")));
}
Also used : Entity(jakarta.persistence.Entity) Arrays(java.util.Arrays) CanonicalModelProcessor(org.eclipse.persistence.internal.jpa.modelgen.CanonicalModelProcessor) BeforeClass(org.junit.BeforeClass) URL(java.net.URL) ArrayList(java.util.ArrayList) CompilationTask(javax.tools.JavaCompiler.CompilationTask) Diagnostic(javax.tools.Diagnostic) URI(java.net.URI) Path(java.nio.file.Path) DiagnosticCollector(javax.tools.DiagnosticCollector) SimpleFileVisitor(java.nio.file.SimpleFileVisitor) PrintWriter(java.io.PrintWriter) SimpleJavaFileObject(javax.tools.SimpleJavaFileObject) StandardLocation(javax.tools.StandardLocation) Files(java.nio.file.Files) JavaCompiler(javax.tools.JavaCompiler) BufferedWriter(java.io.BufferedWriter) StandardOpenOption(java.nio.file.StandardOpenOption) CanonicalModelProperties(org.eclipse.persistence.internal.jpa.modelgen.CanonicalModelProperties) IOException(java.io.IOException) Test(org.junit.Test) BasicFileAttributes(java.nio.file.attribute.BasicFileAttributes) File(java.io.File) Generated(jakarta.annotation.Generated) JavaFileObject(javax.tools.JavaFileObject) FileVisitResult(java.nio.file.FileVisitResult) StandardJavaFileManager(javax.tools.StandardJavaFileManager) List(java.util.List) Assert(org.junit.Assert) Collections(java.util.Collections) ToolProvider(javax.tools.ToolProvider) File(java.io.File) FileVisitResult(java.nio.file.FileVisitResult)

Example 4 with Generated

use of jakarta.annotation.Generated in project eclipselink by eclipse-ee4j.

the class TestProcessor method testTypeUse.

public void testTypeUse(String name, String pxml, String oxml) throws Exception {
    TestFO entity = new TestFO("org.Ent", "package org; @jakarta.persistence.Entity public class Ent { @org.ann.NotNull private byte[] bytes;}");
    TestFO ann = new TestFO("org.ann.NotNull", "package org.ann; @java.lang.annotation.Target(java.lang.annotation.ElementType.TYPE_USE) public @interface NotNull {}");
    Result result = runProject(name, getJavacOptions("-Aeclipselink.logging.level.processor=OFF"), Arrays.asList(entity, ann), pxml, oxml);
    File outputFile = new File(result.srcOut, "org/Ent_.java");
    Assert.assertTrue("Model file not generated", outputFile.exists());
    Assert.assertTrue(Files.lines(outputFile.toPath()).noneMatch(s -> s.contains("NotNull")));
    Assert.assertTrue("Compilation failed", result.success);
}
Also used : Entity(jakarta.persistence.Entity) Arrays(java.util.Arrays) CanonicalModelProcessor(org.eclipse.persistence.internal.jpa.modelgen.CanonicalModelProcessor) BeforeClass(org.junit.BeforeClass) URL(java.net.URL) ArrayList(java.util.ArrayList) CompilationTask(javax.tools.JavaCompiler.CompilationTask) Diagnostic(javax.tools.Diagnostic) URI(java.net.URI) Path(java.nio.file.Path) DiagnosticCollector(javax.tools.DiagnosticCollector) SimpleFileVisitor(java.nio.file.SimpleFileVisitor) PrintWriter(java.io.PrintWriter) SimpleJavaFileObject(javax.tools.SimpleJavaFileObject) StandardLocation(javax.tools.StandardLocation) Files(java.nio.file.Files) JavaCompiler(javax.tools.JavaCompiler) BufferedWriter(java.io.BufferedWriter) StandardOpenOption(java.nio.file.StandardOpenOption) CanonicalModelProperties(org.eclipse.persistence.internal.jpa.modelgen.CanonicalModelProperties) IOException(java.io.IOException) Test(org.junit.Test) BasicFileAttributes(java.nio.file.attribute.BasicFileAttributes) File(java.io.File) Generated(jakarta.annotation.Generated) JavaFileObject(javax.tools.JavaFileObject) FileVisitResult(java.nio.file.FileVisitResult) StandardJavaFileManager(javax.tools.StandardJavaFileManager) List(java.util.List) Assert(org.junit.Assert) Collections(java.util.Collections) ToolProvider(javax.tools.ToolProvider) File(java.io.File) FileVisitResult(java.nio.file.FileVisitResult)

Aggregations

Generated (jakarta.annotation.Generated)4 Entity (jakarta.persistence.Entity)4 BufferedWriter (java.io.BufferedWriter)4 File (java.io.File)4 IOException (java.io.IOException)4 PrintWriter (java.io.PrintWriter)4 URI (java.net.URI)4 URL (java.net.URL)4 FileVisitResult (java.nio.file.FileVisitResult)4 Files (java.nio.file.Files)4 Path (java.nio.file.Path)4 SimpleFileVisitor (java.nio.file.SimpleFileVisitor)4 StandardOpenOption (java.nio.file.StandardOpenOption)4 BasicFileAttributes (java.nio.file.attribute.BasicFileAttributes)4 ArrayList (java.util.ArrayList)4 Arrays (java.util.Arrays)4 Collections (java.util.Collections)4 List (java.util.List)4 Diagnostic (javax.tools.Diagnostic)4 DiagnosticCollector (javax.tools.DiagnosticCollector)4