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
29 changes: 29 additions & 0 deletions src/main/java/org/quickfixj/codegenerator/GenerateMojo.java
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,13 @@ public class GenerateMojo extends AbstractMojo {
@Parameter(defaultValue = "true")
private boolean overwrite = true;

/**
* Skips code generation, e.g. when the generated sources are known to be up to date.
* The output directory is still added as a compile source root.
*/
@Parameter(property = "quickfixj.codegenerator.skip", defaultValue = "false")
private boolean skip;

/**
* The Maven project to act upon.
*/
Expand All @@ -111,6 +118,14 @@ public class GenerateMojo extends AbstractMojo {
*/
public void execute() throws MojoExecutionException {

if (skip) {
log("Skipping code generation for " + dictFile);
if (project != null) {
project.addCompileSourceRoot(outputDirectory.getAbsolutePath());
}
return;
}

if (!outputDirectory.exists()) {
FileUtils.mkdir(outputDirectory.getAbsolutePath());
}
Expand Down Expand Up @@ -338,4 +353,18 @@ public boolean isOverwrite() {
public void setOverwrite(boolean overwrite) {
this.overwrite = overwrite;
}

/**
* @return whether code generation is skipped
*/
public boolean isSkip() {
return skip;
}

/**
* @param skip sets whether code generation is skipped
*/
public void setSkip(boolean skip) {
this.skip = skip;
}
}
46 changes: 46 additions & 0 deletions src/test/java/org/quickfixj/codegenerator/SkipTest.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
package org.quickfixj.codegenerator;

import static org.junit.jupiter.api.Assertions.*;

import java.io.File;
import java.io.IOException;

import org.apache.commons.io.FileUtils;
import org.apache.maven.plugin.MojoExecutionException;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;

public class SkipTest {

private File outputDirectory = new File("./target/test-output-skip/");
private File dictFile = new File("./src/test/resources/FIX41.xml");
private GenerateMojo mojo;

@BeforeEach
public void setup() throws IOException {
if (outputDirectory.exists()) {
FileUtils.deleteDirectory(outputDirectory);
}
mojo = new GenerateMojo();
mojo.setDictFile(dictFile);
mojo.setOutputDirectory(outputDirectory);
mojo.setSchemaDirectory(new File("./src/main/resources/org/quickfixj/codegenerator"));
mojo.setPackaging("quickfix.fix41");
}

@Test
public void testNothingGeneratedWhenSkipTrue() throws MojoExecutionException {
mojo.setSkip(true);
mojo.execute();

assertFalse(new File(outputDirectory, "quickfix/field/AllocShares.java").exists());
}

@Test
public void testGeneratedWhenSkipFalse() throws MojoExecutionException {
mojo.setSkip(false);
mojo.execute();

assertTrue(new File(outputDirectory, "quickfix/field/AllocShares.java").exists());
}
}
Loading