[#5881] NullPointerException when running Maven code generator plugin without <target/> specification
This commit is contained in:
parent
99eb5e7ff9
commit
fcdb5f23a2
@ -37,6 +37,7 @@ package org.jooq.util.maven;
|
||||
import static org.apache.maven.plugins.annotations.LifecyclePhase.GENERATE_SOURCES;
|
||||
import static org.apache.maven.plugins.annotations.ResolutionScope.TEST;
|
||||
import static org.jooq.Constants.XSD_CODEGEN;
|
||||
import static org.jooq.util.GenerationTool.DEFAULT_TARGET_DIRECTORY;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.FileInputStream;
|
||||
@ -50,6 +51,7 @@ import javax.xml.bind.JAXB;
|
||||
|
||||
import org.jooq.util.GenerationTool;
|
||||
import org.jooq.util.jaxb.Configuration;
|
||||
import org.jooq.util.jaxb.Target;
|
||||
|
||||
import org.apache.maven.plugin.AbstractMojo;
|
||||
import org.apache.maven.plugin.MojoExecutionException;
|
||||
@ -164,11 +166,16 @@ public class Plugin extends AbstractMojo {
|
||||
// [#2886] Add the surrounding project's dependencies to the current classloader
|
||||
Thread.currentThread().setContextClassLoader(getClassLoader());
|
||||
|
||||
// [#5881] Target is allowed to be null
|
||||
if (generator.getTarget() == null)
|
||||
generator.setTarget(new Target());
|
||||
|
||||
if (generator.getTarget().getDirectory() == null)
|
||||
generator.getTarget().setDirectory(DEFAULT_TARGET_DIRECTORY);
|
||||
|
||||
// [#2887] Patch relative paths to take plugin execution basedir into account
|
||||
String dir = generator.getTarget().getDirectory();
|
||||
if (!new File(dir).isAbsolute()) {
|
||||
generator.getTarget().setDirectory(project.getBasedir() + File.separator + dir);
|
||||
}
|
||||
if (!new File(generator.getTarget().getDirectory()).isAbsolute())
|
||||
generator.getTarget().setDirectory(project.getBasedir() + File.separator + generator.getTarget().getDirectory());
|
||||
|
||||
Configuration configuration = new Configuration();
|
||||
configuration.setLogging(logging);
|
||||
|
||||
@ -93,6 +93,10 @@ import org.jooq.util.jaxb.Target;
|
||||
*/
|
||||
public class GenerationTool {
|
||||
|
||||
public static final String DEFAULT_TARGET_ENCODING = "UTF-8";
|
||||
public static final String DEFAULT_TARGET_DIRECTORY = "target/generated-sources/jooq";
|
||||
public static final String DEFAULT_TARGET_PACKAGENAME = "org.jooq.generated";
|
||||
|
||||
private static final JooqLogger log = JooqLogger.getLogger(GenerationTool.class);
|
||||
|
||||
private ClassLoader loader;
|
||||
@ -186,7 +190,7 @@ public class GenerationTool {
|
||||
}
|
||||
|
||||
public static void generate(String xml) throws Exception {
|
||||
new GenerationTool().run(load(new ByteArrayInputStream(xml.getBytes("UTF-8"))));
|
||||
new GenerationTool().run(load(new ByteArrayInputStream(xml.getBytes(DEFAULT_TARGET_ENCODING))));
|
||||
}
|
||||
|
||||
public static void generate(Configuration configuration) throws Exception {
|
||||
@ -481,11 +485,11 @@ public class GenerationTool {
|
||||
log.warn("DEPRECATED", "The <ignoreProcedureReturnValues/> flag is deprecated and used for backwards-compatibility only. It will be removed in the future.");
|
||||
|
||||
if (StringUtils.isBlank(g.getTarget().getPackageName()))
|
||||
g.getTarget().setPackageName("org.jooq.generated");
|
||||
g.getTarget().setPackageName(DEFAULT_TARGET_PACKAGENAME);
|
||||
if (StringUtils.isBlank(g.getTarget().getDirectory()))
|
||||
g.getTarget().setDirectory("target/generated-sources/jooq");
|
||||
g.getTarget().setDirectory(DEFAULT_TARGET_DIRECTORY);
|
||||
if (StringUtils.isBlank(g.getTarget().getEncoding()))
|
||||
g.getTarget().setEncoding("UTF-8");
|
||||
g.getTarget().setEncoding(DEFAULT_TARGET_ENCODING);
|
||||
|
||||
generator.setTargetPackage(g.getTarget().getPackageName());
|
||||
generator.setTargetDirectory(g.getTarget().getDirectory());
|
||||
|
||||
Loading…
Reference in New Issue
Block a user