-
-
Notifications
You must be signed in to change notification settings - Fork 263
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
3 changed files
with
99 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
59 changes: 59 additions & 0 deletions
59
querybean-generator/src/main/java/io/ebean/querybean/generator/PomPluginWriter.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 { | ||
|
||
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); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters