Skip to content

Commit e94f2ad

Browse files
committed
HHH-18644: New and improved hibernate-maven-plugin
- Change 'hibernate-maven-plugin.gradle' to depend on 'org.apache.maven.shared:file-management:3.1.0' - Add the implementation, test and integration test sources for the new hibernate-maven-plugin Signed-off-by: Koen Aers <[email protected]>
1 parent 3e0568a commit e94f2ad

File tree

11 files changed

+1335
-0
lines changed

11 files changed

+1335
-0
lines changed

tooling/hibernate-maven-plugin/hibernate-maven-plugin.gradle

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,4 +16,5 @@ dependencies {
1616
implementation "org.apache.maven:maven-plugin-api:3.6.3"
1717
implementation "org.apache.maven.plugin-tools:maven-plugin-annotations:3.6.0"
1818
implementation "org.apache.maven:maven-project:2.2.1"
19+
implementation "org.apache.maven.shared:file-management:3.1.0"
1920
}
Lines changed: 83 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,83 @@
1+
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
2+
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
3+
4+
<modelVersion>4.0.0</modelVersion>
5+
6+
<groupId>org.hibernate.orm</groupId>
7+
<artifactId>hibernate-maven-plugin</artifactId>
8+
<packaging>maven-plugin</packaging>
9+
<version>0.0.1-SNAPSHOT</version>
10+
11+
<name>Hbernate Maven Plugin</name>
12+
13+
<url>http://hibernate.org</url>
14+
15+
<properties>
16+
<hibernate-core.version>7.0.0.Beta1</hibernate-core.version>
17+
<maven-file-management.version>3.1.0</maven-file-management.version>
18+
<maven-invoker-plugin.version>3.8.0</maven-invoker-plugin.version>
19+
<maven-plugin-api.version>3.9.9</maven-plugin-api.version>
20+
<maven-plugin-annotations.version>3.15.0</maven-plugin-annotations.version>
21+
<junit-jupiter.version>5.11.2</junit-jupiter.version>
22+
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
23+
<project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
24+
<maven.compiler.target>17</maven.compiler.target>
25+
<maven.compiler.source>17</maven.compiler.source>
26+
</properties>
27+
28+
<dependencies>
29+
<dependency>
30+
<groupId>org.apache.maven</groupId>
31+
<artifactId>maven-plugin-api</artifactId>
32+
<version>${maven-plugin-api.version}</version>
33+
<scope>provided</scope>
34+
</dependency>
35+
<dependency>
36+
<groupId>org.apache.maven.shared</groupId>
37+
<artifactId>file-management</artifactId>
38+
<version>${maven-file-management.version}</version>
39+
</dependency>
40+
<dependency>
41+
<groupId>org.apache.maven.plugin-tools</groupId>
42+
<artifactId>maven-plugin-annotations</artifactId>
43+
<version>${maven-plugin-annotations.version}</version>
44+
<scope>provided</scope>
45+
</dependency>
46+
<dependency>
47+
<groupId>org.hibernate.orm</groupId>
48+
<artifactId>hibernate-core</artifactId>
49+
<version>${hibernate-core.version}</version>
50+
</dependency>
51+
<dependency>
52+
<groupId>org.junit.jupiter</groupId>
53+
<artifactId>junit-jupiter-api</artifactId>
54+
<version>${junit-jupiter.version}</version>
55+
<scope>test</scope>
56+
</dependency>
57+
</dependencies>
58+
59+
<build>
60+
<plugins>
61+
<plugin>
62+
<artifactId>maven-invoker-plugin</artifactId>
63+
<version>${maven-invoker-plugin.version}</version>
64+
<configuration>
65+
<debug>true</debug>
66+
<cloneProjectsTo>${project.build.directory}/it</cloneProjectsTo>
67+
<localRepositoryPath>${project.build.directory}/local-repo</localRepositoryPath>
68+
<postBuildHookScript>verify</postBuildHookScript>
69+
</configuration>
70+
<executions>
71+
<execution>
72+
<id>integration-test</id>
73+
<goals>
74+
<goal>install</goal>
75+
<goal>run</goal>
76+
</goals>
77+
</execution>
78+
</executions>
79+
</plugin>
80+
</plugins>
81+
</build>
82+
83+
</project>
Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd">
2+
3+
<modelVersion>4.0.0</modelVersion>
4+
5+
<groupId>org.hibernate.orm.tooling.maven</groupId>
6+
<artifactId>enhance-test</artifactId>
7+
<version>0.0.1-SNAPSHOT</version>
8+
9+
<dependencies>
10+
<dependency>
11+
<groupId>org.hibernate.orm</groupId>
12+
<artifactId>hibernate-core</artifactId>
13+
<version>@hibernate-core.version@</version>
14+
</dependency>
15+
</dependencies>
16+
17+
<build>
18+
<plugins>
19+
<plugin>
20+
<groupId>org.hibernate.orm</groupId>
21+
<artifactId>hibernate-maven-plugin</artifactId>
22+
<version>@project.version@</version>
23+
<executions>
24+
<execution>
25+
<id>enhance</id>
26+
<phase>process-classes</phase>
27+
<configuration>
28+
<fileSets>
29+
<fileSet>
30+
<directory>${project.build.directory}/classes</directory>
31+
<excludes>
32+
<exclude>**/Baz.class</exclude>
33+
</excludes>
34+
</fileSet>
35+
</fileSets>
36+
<enableLazyInitialization>true</enableLazyInitialization>
37+
</configuration>
38+
<goals>
39+
<goal>enhance</goal>
40+
</goals>
41+
</execution>
42+
</executions>
43+
</plugin>
44+
</plugins>
45+
</build>
46+
47+
</project>
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
package org.foo;
2+
3+
import jakarta.persistence.Entity;
4+
5+
@Entity
6+
public class Bar {
7+
8+
private String foo;
9+
10+
String getFoo() {
11+
return foo;
12+
}
13+
14+
public void setFoo(String f) {
15+
foo = f;
16+
}
17+
18+
}
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
package org.foo;
2+
3+
import jakarta.persistence.Entity;
4+
5+
@Entity
6+
public class Baz {
7+
8+
private String foo;
9+
10+
String getFoo() {
11+
return foo;
12+
}
13+
14+
public void setFoo(String f) {
15+
foo = f;
16+
}
17+
18+
}
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
package org.foo;
2+
3+
public class Foo {
4+
5+
private Bar bar;
6+
7+
Bar getBar() {
8+
return bar;
9+
}
10+
11+
public void setBar(Bar b) {
12+
bar = b;
13+
}
14+
15+
}
Lines changed: 75 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,75 @@
1+
import java.io.File;
2+
import java.io.FileNotFoundException;
3+
import java.nio.file.Files;
4+
import java.util.List;
5+
import java.util.ArrayList;
6+
7+
8+
File targetFolder = new File(basedir, "target");
9+
if (!targetFolder.exists()) {
10+
throw new FileNotFoundException("Folder should exist: " + targetFolder);
11+
}
12+
if (targetFolder.isFile()) {
13+
throw new FileNotFoundException("Folder should be a folder: " + targetFolder);
14+
}
15+
File classesFolder = new File(targetFolder, "classes");
16+
if (!classesFolder.exists()) {
17+
throw new FileNotFoundException("Folder should exist: " + classesFolder);
18+
}
19+
File barClassFile = new File(classesFolder, "org/foo/Bar.class");
20+
if (!barClassFile.exists()) {
21+
throw new FileNotFoundException("File should exist: " + barClassFile);
22+
}
23+
int amountOfBytes = Files.readAllBytes(barClassFile.toPath()).length;
24+
25+
File fooClassFile = new File(classesFolder, "org/foo/Foo.class");
26+
if (!fooClassFile.exists()) {
27+
throw new FileNotFoundException("File should exist: " + fooClassFile);
28+
}
29+
30+
File bazClassFile = new File(classesFolder, "org/foo/Baz.class");
31+
if (!bazClassFile.exists()) {
32+
throw new FileNotFoundException("File should exist: " + bazClassFile);
33+
}
34+
35+
File buildLog = new File(basedir, "build.log");
36+
if (!buildLog.exists()) {
37+
throw new FileNotFoundException("File should exist: " + buildLog);
38+
}
39+
List<String> listOfStrings = new ArrayList<String>();
40+
listOfStrings = Files.readAllLines(buildLog.toPath());
41+
assert listOfStrings.contains("[DEBUG] Configuring mojo execution 'org.hibernate.orm:hibernate-maven-plugin:0.0.1-SNAPSHOT:enhance:enhance' with basic configurator -->");
42+
assert listOfStrings.contains("[DEBUG] (f) classesDirectory = " + classesFolder);
43+
assert listOfStrings.contains("[DEBUG] (f) enableAssociationManagement = false");
44+
assert listOfStrings.contains("[DEBUG] (f) enableDirtyTracking = false");
45+
assert listOfStrings.contains("[DEBUG] (f) enableLazyInitialization = true");
46+
assert listOfStrings.contains("[DEBUG] (f) enableExtendedEnhancement = false");
47+
assert listOfStrings.contains("[DEBUG] Starting execution of enhance mojo");
48+
assert listOfStrings.contains("[DEBUG] Starting assembly of the source set");
49+
assert listOfStrings.contains("[DEBUG] Processing FileSet");
50+
assert listOfStrings.contains("[DEBUG] Using base directory: " + classesFolder);
51+
assert listOfStrings.contains("[INFO] Added file to source set: " + barClassFile);
52+
assert listOfStrings.contains("[INFO] Added file to source set: " + fooClassFile);
53+
assert !listOfStrings.contains("[INFO] Added file to source set: " + bazClassFile);
54+
assert listOfStrings.contains("[DEBUG] FileSet was processed succesfully");
55+
assert listOfStrings.contains("[DEBUG] Ending the assembly of the source set");
56+
assert listOfStrings.contains("[DEBUG] Creating bytecode enhancer");
57+
assert listOfStrings.contains("[DEBUG] Creating enhancement context");
58+
assert listOfStrings.contains("[DEBUG] Creating URL ClassLoader for folder: " + classesFolder);
59+
assert listOfStrings.contains("[DEBUG] Starting type discovery");
60+
assert listOfStrings.contains("[DEBUG] Trying to discover types for classes in file: " + barClassFile);
61+
assert listOfStrings.contains("[DEBUG] Determining class name for file: " + barClassFile);
62+
assert listOfStrings.contains("[INFO] Succesfully discovered types for classes in file: " + barClassFile);
63+
assert listOfStrings.contains("[DEBUG] Trying to discover types for classes in file: " + fooClassFile);
64+
assert listOfStrings.contains("[DEBUG] Determining class name for file: " + fooClassFile);
65+
assert listOfStrings.contains("[INFO] Succesfully discovered types for classes in file: " + fooClassFile);
66+
assert listOfStrings.contains("[DEBUG] Ending type discovery");
67+
assert listOfStrings.contains("[DEBUG] Starting class enhancement");
68+
assert listOfStrings.contains("[DEBUG] Trying to enhance class file: " + barClassFile);
69+
assert listOfStrings.contains("[INFO] Succesfully cleared the contents of file: " + barClassFile);
70+
assert listOfStrings.contains("[DEBUG] " + amountOfBytes + " bytes were succesfully written to file: " +barClassFile);
71+
assert listOfStrings.contains("[INFO] Succesfully enhanced class file: " + barClassFile);
72+
assert listOfStrings.contains("[DEBUG] Trying to enhance class file: " + fooClassFile);
73+
assert listOfStrings.contains("[INFO] Skipping file: " + fooClassFile);
74+
assert listOfStrings.contains("[DEBUG] Ending class enhancement");
75+
assert listOfStrings.contains("[DEBUG] Ending execution of enhance mojo");

0 commit comments

Comments
 (0)