Skip to content

Commit

Permalink
fix(SpoonPom): Absolute path prefix should apply to non-standard dire…
Browse files Browse the repository at this point in the history
…ctories (#3260)
  • Loading branch information
scootafew authored Feb 20, 2020
1 parent 4ef86c8 commit c720f9e
Show file tree
Hide file tree
Showing 5 changed files with 33 additions and 4 deletions.
10 changes: 6 additions & 4 deletions src/main/java/spoon/support/compiler/SpoonPom.java
Original file line number Diff line number Diff line change
Expand Up @@ -121,9 +121,10 @@ public List<File> getSourceDirectories() {
sourcePath = build.getSourceDirectory();
}
if (sourcePath == null) {
sourcePath = Paths.get(directory.getAbsolutePath(), "src", "main", "java").toString();
sourcePath = Paths.get("src/main/java").toString();
}
File source = new File(sourcePath);
String absoluteSourcePath = Paths.get(directory.getAbsolutePath(), sourcePath).toString();
File source = new File(absoluteSourcePath);
if (source.exists()) {
output.add(source);
}
Expand All @@ -150,9 +151,10 @@ public List<File> getTestDirectories() {
sourcePath = build.getTestSourceDirectory();
}
if (sourcePath == null) {
sourcePath = Paths.get(directory.getAbsolutePath(), "src", "test", "java").toString();
sourcePath = Paths.get("src/test/java").toString();
}
File source = new File(sourcePath);
String absoluteSourcePath = Paths.get(directory.getAbsolutePath(), sourcePath).toString();
File source = new File(absoluteSourcePath);
if (source.exists()) {
output.add(source);
}
Expand Down
6 changes: 6 additions & 0 deletions src/test/java/spoon/MavenLauncherTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -148,6 +148,12 @@ public void mavenLauncherTestWithVerySimpleProject() {
assertEquals(1, launcher.getModelBuilder().getInputSources().size());
}

@Test
public void testPomSourceDirectory() {
MavenLauncher launcher = new MavenLauncher("./src/test/resources/maven-launcher/source-directory", MavenLauncher.SOURCE_TYPE.ALL_SOURCE);
assertEquals(2, launcher.getModelBuilder().getInputSources().size());
}

@Test
public void mavenLauncherTestMultiModulesAndVariables() {
// contract: variables coming from parent should be resolved
Expand Down
15 changes: 15 additions & 0 deletions src/test/resources/maven-launcher/source-directory/pom.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
<modelVersion>4.0.0</modelVersion>

<groupId>org.foo.bar</groupId>
<artifactId>foobar</artifactId>
<version>1.0.0-SNAPSHOT</version>
<packaging>jar</packaging>
<name>foobar</name>

<build>
<sourceDirectory>source/code</sourceDirectory>
<testSourceDirectory>test</testSourceDirectory>
</build>
</project>
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
public class Test {
int field = 42;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
public class Test {
int field = 42;
}

0 comments on commit c720f9e

Please sign in to comment.