Skip to content
Merged
Show file tree
Hide file tree
Changes from all 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
6 changes: 6 additions & 0 deletions maven/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,7 @@

<maven-plugin-annotations.version>3.5</maven-plugin-annotations.version>
<maven-plugin-api.version>3.5.2</maven-plugin-api.version>
<maven-core.version>3.9.9</maven-core.version>

<!-- Plugin versions -->
<maven-project-info-reports-plugin.version>2.9</maven-project-info-reports-plugin.version>
Expand All @@ -93,6 +94,11 @@
<artifactId>maven-plugin-api</artifactId>
<version>${maven-plugin-api.version}</version>
</dependency>
<dependency>
<groupId>org.apache.maven</groupId>
<artifactId>maven-core</artifactId>
<version>${maven-core.version}</version>
</dependency>
<dependency>
<groupId>org.apache.maven.plugin-tools</groupId>
<artifactId>maven-plugin-annotations</artifactId>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,10 +23,18 @@
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.net.MalformedURLException;
import java.net.URL;
import java.net.URLClassLoader;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.HashSet;
import java.util.Properties;

import org.apache.maven.artifact.DependencyResolutionRequiredException;
import org.apache.maven.plugin.AbstractMojo;
import org.apache.maven.plugins.annotations.Parameter;
import org.apache.maven.project.MavenProject;
import org.apache.tools.ant.BuildException;
import org.hibernate.tool.api.metadata.MetadataDescriptor;
import org.hibernate.tool.api.metadata.MetadataDescriptorFactory;
Expand Down Expand Up @@ -83,15 +91,24 @@ public abstract class AbstractGenerationMojo extends AbstractMojo {
// Not exposed for now
private boolean preferBasicCompositeIds = true;

@Parameter(defaultValue = "${project}", readonly = true, required = true)
private MavenProject project;

public void execute() {
getLog().info("Starting " + this.getClass().getSimpleName() + "...");
RevengStrategy strategy = setupReverseEngineeringStrategy();
if (propertyFile.exists()) {
executeExporter(createJdbcDescriptor(strategy, loadPropertiesFile()));
} else {
getLog().info("Property file '" + propertyFile + "' cannot be found, aborting...");
}
getLog().info("Finished " + this.getClass().getSimpleName() + "!");
ClassLoader original = Thread.currentThread().getContextClassLoader();
try {
Thread.currentThread().setContextClassLoader(createExporterClassLoader(original));
getLog().info("Starting " + this.getClass().getSimpleName() + "...");
RevengStrategy strategy = setupReverseEngineeringStrategy();
if (propertyFile.exists()) {
executeExporter(createJdbcDescriptor(strategy, loadPropertiesFile()));
} else {
getLog().info("Property file '" + propertyFile + "' cannot be found, aborting...");
}
getLog().info("Finished " + this.getClass().getSimpleName() + "!");
} finally {
Thread.currentThread().setContextClassLoader(original);
}
}

private RevengStrategy setupReverseEngineeringStrategy() {
Expand Down Expand Up @@ -134,6 +151,18 @@ private MetadataDescriptor createJdbcDescriptor(RevengStrategy strategy, Propert
strategy,
properties);
}

private ClassLoader createExporterClassLoader(ClassLoader parent) {
ArrayList<URL> urls = new ArrayList<URL>();
try {
for (String cpe : project.getRuntimeClasspathElements()) {
urls.add(new File(cpe).toURI().toURL());
}
} catch (DependencyResolutionRequiredException | MalformedURLException e) {
throw new RuntimeException("Problem while constructing project classloader", e);
}
return new URLClassLoader(urls.toArray(new URL[0]), parent);
}

protected abstract void executeExporter(MetadataDescriptor metadataDescriptor);
}
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@

import org.apache.maven.plugins.annotations.Mojo;
import org.apache.maven.plugins.annotations.Parameter;
import org.apache.maven.plugins.annotations.ResolutionScope;
import org.hibernate.tool.api.export.Exporter;
import org.hibernate.tool.api.export.ExporterConstants;
import org.hibernate.tool.api.export.ExporterFactory;
Expand All @@ -36,7 +37,10 @@
* <p>
* See: https://docs.jboss.org/tools/latest/en/hibernatetools/html_single/#d0e4821
*/
@Mojo(name = "hbm2dao", defaultPhase = GENERATE_SOURCES)
@Mojo(
name = "hbm2dao",
defaultPhase = GENERATE_SOURCES,
requiresDependencyResolution = ResolutionScope.RUNTIME)
public class GenerateDaoMojo extends AbstractGenerationMojo {

/** The directory into which the DAOs will be generated. */
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@

import org.apache.maven.plugins.annotations.Mojo;
import org.apache.maven.plugins.annotations.Parameter;
import org.apache.maven.plugins.annotations.ResolutionScope;
import org.hibernate.boot.Metadata;
import org.hibernate.tool.api.metadata.MetadataDescriptor;
import org.hibernate.tool.hbm2ddl.SchemaExport;
Expand All @@ -37,7 +38,10 @@
* <p>
* See https://docs.jboss.org/tools/latest/en/hibernatetools/html_single/#d0e4651
*/
@Mojo(name = "hbm2ddl", defaultPhase = GENERATE_RESOURCES)
@Mojo(
name = "hbm2ddl",
defaultPhase = GENERATE_RESOURCES,
requiresDependencyResolution = ResolutionScope.RUNTIME)
public class GenerateDdlMojo extends AbstractGenerationMojo {

/** The directory into which the DDLs will be generated. */
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@

import org.apache.maven.plugins.annotations.Mojo;
import org.apache.maven.plugins.annotations.Parameter;
import org.apache.maven.plugins.annotations.ResolutionScope;
import org.hibernate.tool.api.export.Exporter;
import org.hibernate.tool.api.export.ExporterConstants;
import org.hibernate.tool.api.export.ExporterFactory;
Expand All @@ -36,7 +37,10 @@
* <p>
* See: https://docs.jboss.org/tools/latest/en/hibernatetools/html_single/#d0e4821
*/
@Mojo(name = "generateHbm", defaultPhase = GENERATE_SOURCES)
@Mojo(
name = "generateHbm",
defaultPhase = GENERATE_SOURCES,
requiresDependencyResolution = ResolutionScope.RUNTIME)
public class GenerateHbmMojo extends AbstractGenerationMojo {

/** The directory into which the DAOs will be generated. */
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@

import org.apache.maven.plugins.annotations.Mojo;
import org.apache.maven.plugins.annotations.Parameter;
import org.apache.maven.plugins.annotations.ResolutionScope;
import org.hibernate.tool.api.export.Exporter;
import org.hibernate.tool.api.export.ExporterConstants;
import org.hibernate.tool.api.export.ExporterFactory;
Expand All @@ -36,7 +37,10 @@
* <p>
* See: https://docs.jboss.org/tools/latest/en/hibernatetools/html_single/#d0e4821
*/
@Mojo(name = "hbm2java", defaultPhase = GENERATE_SOURCES)
@Mojo(
name = "hbm2java",
defaultPhase = GENERATE_SOURCES,
requiresDependencyResolution = ResolutionScope.RUNTIME)
public class GenerateJavaMojo extends AbstractGenerationMojo {

/** The directory into which the JPA entities will be generated. */
Expand Down Expand Up @@ -69,6 +73,8 @@ protected void executeExporter(MetadataDescriptor metadataDescriptor) {
getLog().info("Starting POJO export to directory: " + outputDirectory + "...");
pojoExporter.start();
}




}