Skip to content

Commit

Permalink
Make testXjc attach test sources
Browse files Browse the repository at this point in the history
Fixes #134
  • Loading branch information
marschall authored and slachiewicz committed Apr 14, 2024
1 parent 3f89990 commit 9357430
Show file tree
Hide file tree
Showing 6 changed files with 29 additions and 12 deletions.
9 changes: 8 additions & 1 deletion src/main/java/org/codehaus/mojo/jaxb2/AbstractJaxbMojo.java
Original file line number Diff line number Diff line change
Expand Up @@ -358,10 +358,17 @@ public final void execute() throws MojoExecutionException, MojoFailureException
}

// Add the output Directory.
getProject().addCompileSourceRoot(canonicalPathToOutputDirectory);
addGeneratedSourcesToProjectSourceRoot(canonicalPathToOutputDirectory);
}
}

/**
* Adds any directories containing the generated XJC classes to the appropriate Project compilation sources;
* either {@code TestCompileSourceRoot} or {@code CompileSourceRoot} depending on the exact Mojo implementation
* of this AbstractJavaGeneratorMojo.
*/
protected abstract void addGeneratedSourcesToProjectSourceRoot(String canonicalPathToOutputDirectory);

/**
* Implement this method to check if this AbstractJaxbMojo should skip executing altogether.
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -528,7 +528,8 @@ protected boolean performExecution() throws MojoExecutionException, MojoFailureE
}

// Add the generated source root to the project, enabling tooling and other plugins to see them.
addGeneratedSourcesToProjectSourceRoot();
String canonicalPathToOutputDirectory = FileSystemUtilities.getCanonicalPath(getOutputDirectory());
addGeneratedSourcesToProjectSourceRoot(canonicalPathToOutputDirectory);

// Copy all source XSDs to the resulting artifact?
if (xsdPathWithinArtifact != null) {
Expand Down Expand Up @@ -604,13 +605,6 @@ protected boolean performExecution() throws MojoExecutionException, MojoFailureE
*/
protected abstract List<File> getSourceXJBs();

/**
* Adds any directories containing the generated XJC classes to the appropriate Project compilation sources;
* either {@code TestCompileSourceRoot} or {@code CompileSourceRoot} depending on the exact Mojo implementation
* of this AbstractJavaGeneratorMojo.
*/
protected abstract void addGeneratedSourcesToProjectSourceRoot();

//
// Private helpers
//
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -326,7 +326,7 @@ protected List<String> getClasspath() throws MojoExecutionException {
* {@inheritDoc}
*/
@Override
protected void addGeneratedSourcesToProjectSourceRoot() {
protected void addGeneratedSourcesToProjectSourceRoot(String canonicalPathToOutputDirectory) {
getProject().addTestCompileSourceRoot(getOutputDirectory().getAbsolutePath());
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -332,8 +332,8 @@ protected List<String> getClasspath() throws MojoExecutionException {
* {@inheritDoc}
*/
@Override
protected void addGeneratedSourcesToProjectSourceRoot() {
getProject().addCompileSourceRoot(FileSystemUtilities.getCanonicalPath(getOutputDirectory()));
protected void addGeneratedSourcesToProjectSourceRoot(String canonicalPathToOutputDirectory) {
getProject().addCompileSourceRoot(canonicalPathToOutputDirectory);
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -244,6 +244,14 @@ protected List<String> getClasspath() throws MojoExecutionException {
return toReturn;
}

/**
* {@inheritDoc}
*/
@Override
protected void addGeneratedSourcesToProjectSourceRoot(String canonicalPathToOutputDirectory) {
getProject().addCompileSourceRoot(canonicalPathToOutputDirectory);
}

/**
* {@inheritDoc}
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -215,6 +215,14 @@ protected List<String> getClasspath() throws MojoExecutionException {
return toReturn;
}

/**
* {@inheritDoc}
*/
@Override
protected void addGeneratedSourcesToProjectSourceRoot(String canonicalPathToOutputDirectory) {
getProject().addTestCompileSourceRoot(canonicalPathToOutputDirectory);
}

/**
* {@inheritDoc}
*/
Expand Down

0 comments on commit 9357430

Please sign in to comment.