Skip to content

Commit

Permalink
[#5881] NullPointerException when running Maven code generator plugin…
Browse files Browse the repository at this point in the history
… without <target/> specification
  • Loading branch information
lukaseder committed Feb 17, 2017
1 parent 99eb5e7 commit fcdb5f2
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 8 deletions.
15 changes: 11 additions & 4 deletions jOOQ-codegen-maven/src/main/java/org/jooq/util/maven/Plugin.java
Expand Up @@ -37,6 +37,7 @@
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;
Expand All @@ -50,6 +51,7 @@

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;
Expand Down Expand Up @@ -164,11 +166,16 @@ public void execute() throws MojoExecutionException {
// [#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);
Expand Down
12 changes: 8 additions & 4 deletions jOOQ-codegen/src/main/java/org/jooq/util/GenerationTool.java
Expand Up @@ -93,6 +93,10 @@
*/
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;
Expand Down Expand Up @@ -186,7 +190,7 @@ public static void main(Configuration configuration) throws Exception {
}

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 {
Expand Down Expand Up @@ -481,11 +485,11 @@ else if (schema.getOutputSchema() == null)
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());
Expand Down

0 comments on commit fcdb5f2

Please sign in to comment.