Skip to content

Commit

Permalink
Add generated code to test sources in build
Browse files Browse the repository at this point in the history
  • Loading branch information
runeflobakk committed Jan 30, 2024
1 parent cfda2aa commit 482ab34
Showing 1 changed file with 28 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -28,21 +28,47 @@
public class GenerateRecordMatcherMojo extends AbstractMojo {

private static final Logger LOG = LoggerFactory.getLogger(GenerateRecordMatcherMojo.class);
private static final String PLUGIN_CONF_PROP_PREFIX = "recordmatcher.";

/**
* Specifies the fully qualified class names of the records to
* generate Hamcrest matchers for.
*/
@Parameter
private Set<String> includes;

@Parameter(defaultValue = "${project.build.directory}/generated-test-sources/record-matchers", required = true)

/**
* The directory where the generated Hamcrest matchers will be written to.
*/
@Parameter(required = true,
defaultValue = "${project.build.directory}/generated-test-sources/record-matchers",
property = PLUGIN_CONF_PROP_PREFIX + "outputDirectory")
private File outputDirectory;

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

/**
* Whether the {@link #outputDirectory} should be included as a test sources root.
*/
@Parameter(required = true,
defaultValue = "true",
property = PLUGIN_CONF_PROP_PREFIX + "includeGeneratedCodeAsTestSources")
private boolean includeGeneratedCodeAsTestSources;


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


@Override
public void execute() throws MojoExecutionException, MojoFailureException {
if (includes != null && !includes.isEmpty()) {
Path outputDirectory = resolveOutputDirectory();
if (includeGeneratedCodeAsTestSources) {
mavenProject.addTestCompileSourceRoot(outputDirectory.toString());
LOG.debug("{} has been added as a compiler test sources directory", outputDirectory);
}
try {
Files.createDirectories(outputDirectory);
LOG.info("Generating Hamcrest matchers in {}", outputDirectory);
Expand Down

0 comments on commit 482ab34

Please sign in to comment.