Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use Avaje Prisms in QueryBean APT #3528

Open
wants to merge 14 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 7 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -19,3 +19,5 @@ profiling/
*.iws
.idea/
*uuid.state
querybean-generator/.factorypath
*.class
13 changes: 13 additions & 0 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -124,5 +124,18 @@
</profile>
</profiles>

<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<configuration>
<compilerArgs>
<arg>-AbuildPlugin=false</arg>
</compilerArgs>
</configuration>
</plugin>
</plugins>
</build>
</project>

53 changes: 50 additions & 3 deletions querybean-generator/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -10,17 +10,64 @@
<name>querybean generator</name>
<description>Querybean generator</description>
<artifactId>querybean-generator</artifactId>

<properties>
<avaje.prisms.version>1.37</avaje.prisms.version>
</properties>

<dependencies>
<dependency>
<groupId>io.ebean</groupId>
<artifactId>ebean-api</artifactId>
<version>${project.version}</version>
<optional>true</optional>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>io.ebean</groupId>
<artifactId>jakarta-persistence-api</artifactId>
<version>${ebean-persistence-api.version}</version>
<optional>true</optional>
<scope>provided</scope>
</dependency>

<dependency>
<groupId>org.jspecify</groupId>
<artifactId>jspecify</artifactId>
<version>1.0.0</version>
<optional>true</optional>
<scope>provided</scope>
</dependency>

<dependency>
<groupId>io.avaje</groupId>
<artifactId>avaje-prisms</artifactId>
<version>${avaje.prisms.version}</version>
<optional>true</optional>
<scope>provided</scope>
</dependency>

<dependency>
<groupId>io.avaje</groupId>
<artifactId>avaje-spi-service</artifactId>
<version>2.8</version>
</dependency>

<!-- test dependencies -->
<dependency>
<groupId>io.avaje</groupId>
<artifactId>junit</artifactId>
<version>1.5</version>
<scope>test</scope>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<configuration>
<source>11</source>
<target>11</target>
<!-- Turn off annotation processing for building -->
<compilerArgs>-proc:none</compilerArgs>
</configuration>
</plugin>
</plugins>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ interface Constants {
String METAINF_MANIFEST = "META-INF/ebean-generated-info.mf";
String METAINF_SERVICES_MODULELOADER = "META-INF/services/io.ebean.config.EntityClassRegister";

String AVAJE_LANG_NULLABLE = "io.avaje.lang.Nullable";
String AVAJE_LANG_NULLABLE = "org.jspecify.annotations.Nullable";
String JAVA_COLLECTION = "java.util.Collection";
String EXPRESSIONLIST = "io.ebean.ExpressionList";
String EXPR = "io.ebean.Expr";
Expand Down

This file was deleted.

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
package io.ebean.querybean.generator;

import java.io.IOException;
import java.nio.file.Files;
import java.nio.file.StandardOpenOption;

final class PomPluginWriter {
SentryMan marked this conversation as resolved.
Show resolved Hide resolved

private static final String PLUGIN =
" <!-- generated by ebean query generator -->\n"
+ " <plugin>\n"
+ " <groupId>io.ebean</groupId>\n"
+ " <artifactId>ebean-maven-plugin</artifactId>\n"
+ " <version>%s</version>\n"
+ " <executions>\n"
+ " <execution>\n"
+ " <!-- Will enhance entity classes to add missing spi provides -->"
+ " <goals>\n"
+ " <goal>enhance</goal>\n"
+ " <goal>testEnhance</goal>\n"
+ " </goals>\n"
+ " </execution>\n"
+ " </executions>\n"
+ " </plugin>\n"
+ " ";

static void addPlugin2Pom() throws IOException {

if (disabled()) {
return;
}

var pomPath = APContext.getBuildResource("").getParent().resolve("pom.xml");
if (!pomPath.toFile().exists()) {
return;
}

var pomContent = Files.readString(pomPath);
// if not already present in pom.xml
if (pomContent.contains("ebean-maven-plugin")) {
return;
}
APContext.logNote("Adding ebean-maven-plugin to pom");
var pluginsIndex = pomContent.indexOf("</plugins>");
var builder = new StringBuilder(pomContent);
if (pluginsIndex != -1) {
builder.insert(
pluginsIndex,
String.format(PLUGIN, PomPluginWriter.class.getPackage().getImplementationVersion()));

Files.writeString(
pomPath, builder.toString(), StandardOpenOption.CREATE, StandardOpenOption.WRITE);
}
}

private static boolean disabled() {
return !APContext.getOption("buildPlugin").map(Boolean::valueOf).orElse(true);
}
}
Loading
Loading