Skip to content

Commit

Permalink
[maven] Use the "test" classpath within sarl-maven-plugin.
Browse files Browse the repository at this point in the history
Within the implementation of the sarl-maven-plugin, the classpath that
was used for compiling the test code is the same as the classpath for
compiling the regular code. The specific classpath for test stage is
used for compiling the test code by the sarl-maven-plugin.

close #839

Signed-off-by: Stéphane Galland <galland@arakhne.org>
  • Loading branch information
gallandarakhneorg committed Jun 26, 2018
1 parent c4662ab commit 669d663
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -351,10 +351,11 @@ protected String readSarlEclipseSetting(String sourceDirectory) {
return null;
}

/** Replies the current classpath.
/** Replies the classpath for the standard code.
*
* @return the current classpath.
* @throws MojoExecutionException on failure.
* @see #getTestClassPath()
*/
protected List<File> getClassPath() throws MojoExecutionException {
final Set<String> classPath = new LinkedHashSet<>();
Expand All @@ -381,4 +382,35 @@ protected List<File> getClassPath() throws MojoExecutionException {
return files;
}

/** Replies the classpath for the test code.
*
* @return the current classpath.
* @throws MojoExecutionException on failure.
* @since 0.8
* @see #getClassPath()
*/
protected List<File> getTestClassPath() throws MojoExecutionException {
final Set<String> classPath = new LinkedHashSet<>();
final MavenProject project = getProject();
classPath.add(project.getBuild().getTestSourceDirectory());
try {
classPath.addAll(project.getTestClasspathElements());
} catch (DependencyResolutionRequiredException e) {
throw new MojoExecutionException(e.getLocalizedMessage(), e);
}
for (final Artifact dep : project.getArtifacts()) {
classPath.add(dep.getFile().getAbsolutePath());
}
final List<File> files = new ArrayList<>();
for (final String filename : classPath) {
final File file = new File(filename);
if (file.exists()) {
files.add(file);
} else {
getLog().warn(MessageFormat.format(Messages.AbstractSarlBatchCompilerMojo_10, filename));
}
}
return files;
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ protected void compileSARL() throws MojoExecutionException, MojoFailureException
compileSourceRoots.add(file);
}
}
final List<File> classPath = getClassPath();
final List<File> classPath = getTestClassPath();
project.addTestCompileSourceRoot(outputDirectory.getAbsolutePath());
compile(classPath, compileSourceRoots, outputDirectory,
makeAbsolute(new File(getProject().getBuild().getTestOutputDirectory())));
Expand Down

0 comments on commit 669d663

Please sign in to comment.