Skip to content

Commit 36cf9ad

Browse files
authored
Escape spaces in project path (#37)
* Added failing integration test for a project with spaces in the path. * Test fails for the correct reason. * Actually compile the scala files in our 'spaces in path' project so that scalatest can find them. * Actually run the lift tests and have maven-invoker-plugin verify that they ran. * Escape spaces in runpath directory names. * Remove verify file for previously removed integration test. * Indent with spaces. * ensure temporary directories exist * Clarify error message when output and test output directories don't exist.
1 parent 701bd5b commit 36cf9ad

File tree

11 files changed

+226
-4
lines changed

11 files changed

+226
-4
lines changed

pom.xml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -186,10 +186,12 @@
186186
<cloneProjectsTo>${project.build.directory}/it</cloneProjectsTo>
187187
<pomIncludes>
188188
<pomInclude>lift/pom.xml</pomInclude>
189+
<pomInclude>spaces in path/pom.xml</pomInclude>
189190
</pomIncludes>
190191
<localRepositoryPath>${project.build.directory}/local-repo</localRepositoryPath>
191192
<streamLogs>true</streamLogs>
192193
<settingsFile>src/it/settings.xml</settingsFile>
194+
<postBuildHookScript>verify</postBuildHookScript>
193195
<goals>
194196
<goal>clean</goal>
195197
<goal>test</goal>

src/it/lift/pom.xml

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,27 @@
7575
<groupId>net.alchim31.maven</groupId>
7676
<artifactId>scala-maven-plugin</artifactId>
7777
<version>@scala.maven.plugin.version@</version>
78+
<configuration>
79+
<recompileMode>incremental</recompileMode>
80+
<scalaVersion>${scala.version}</scalaVersion>
81+
</configuration>
82+
<executions>
83+
<execution>
84+
<id>scala-compile</id>
85+
<phase>process-resources</phase>
86+
<goals>
87+
<goal>add-source</goal>
88+
<goal>compile</goal>
89+
</goals>
90+
</execution>
91+
<execution>
92+
<id>scala-test-compile</id>
93+
<phase>process-test-resources</phase>
94+
<goals>
95+
<goal>testCompile</goal>
96+
</goals>
97+
</execution>
98+
</executions>
7899
</plugin>
79100
<plugin>
80101
<groupId>org.mortbay.jetty</groupId>

src/it/lift/verify.groovy

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
2+
def logsFile = new File(basedir, "build.log")
3+
4+
if (!logsFile.exists()) {
5+
throw new Exception("Could not find build.log. Searched: " + logsFile)
6+
}
7+
8+
def testSummaryLines = []
9+
10+
logsFile.filterLine {
11+
it ==~ /.*Tests: succeeded [0-9]*, failed [0-9]*, canceled [0-9]*, ignored [0-9]*, pending [0-9]*.*/
12+
}.each { line -> testSummaryLines << "" + line }
13+
14+
if (testSummaryLines.size == 0) {
15+
throw new Exception("Could not find scalatest's summary line in build.log")
16+
} else if (testSummaryLines.size > 1) {
17+
throw new Exception("Found more than one scalatest summary line in build.log")
18+
}
19+
20+
if (testSummaryLines[0].contains("Tests: succeeded 0, failed 0, canceled 0, ignored 0, pending 0")) {
21+
throw new Exception("No tests were run by scalatest!")
22+
}
23+
24+
return true

src/it/spaces in path/README.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
# spaces in path
2+
3+
This project is part of scalatest-maven-plugin's suite of integration tests. It is meant to check that scalatest-maven-plugin can run for projects that contain spaces in their file path.
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
# A comma or space separated list of goals/phases to execute, may
2+
# specify an empty list to execute the default goal of the IT project
3+
invoker.goals = clean test

src/it/spaces in path/pom.xml

Lines changed: 95 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,95 @@
1+
2+
<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">
3+
<modelVersion>4.0.0</modelVersion>
4+
<artifactId>spaces-in-path-it</artifactId>
5+
<version>1.0-SNAPSHOT</version>
6+
<packaging>jar</packaging>
7+
<name>spaces-in-path-it</name>
8+
<description>Runs the plugin for a project that contains spaces in the path.</description>
9+
10+
<parent>
11+
<groupId>maven.scalatest.plugin.its</groupId>
12+
<artifactId>it-parent</artifactId>
13+
<version>1.0-SNAPSHOT</version>
14+
<relativePath>../it-parent</relativePath>
15+
</parent>
16+
17+
<dependencies>
18+
<dependency>
19+
<groupId>org.scala-lang</groupId>
20+
<artifactId>scala-library</artifactId>
21+
<version>@scala.version@</version>
22+
</dependency>
23+
<dependency>
24+
<groupId>org.scalatest</groupId>
25+
<artifactId>[email protected]@</artifactId>
26+
<version>@scalatest.version@</version>
27+
<scope>test</scope>
28+
</dependency>
29+
</dependencies>
30+
31+
<build>
32+
<sourceDirectory>src/main/scala</sourceDirectory>
33+
<testSourceDirectory>src/test/scala</testSourceDirectory>
34+
<plugins>
35+
<plugin>
36+
<groupId>net.alchim31.maven</groupId>
37+
<artifactId>scala-maven-plugin</artifactId>
38+
<version>@scala.maven.plugin.version@</version>
39+
<configuration>
40+
<recompileMode>incremental</recompileMode>
41+
<scalaVersion>${scala.version}</scalaVersion>
42+
</configuration>
43+
<executions>
44+
<execution>
45+
<id>scala-compile</id>
46+
<phase>process-resources</phase>
47+
<goals>
48+
<goal>add-source</goal>
49+
<goal>compile</goal>
50+
</goals>
51+
</execution>
52+
<execution>
53+
<id>scala-test-compile</id>
54+
<phase>process-test-resources</phase>
55+
<goals>
56+
<goal>testCompile</goal>
57+
</goals>
58+
</execution>
59+
</executions>
60+
</plugin>
61+
<!-- disable surefire -->
62+
<plugin>
63+
<groupId>org.apache.maven.plugins</groupId>
64+
<artifactId>maven-surefire-plugin</artifactId>
65+
<version>2.7</version>
66+
<configuration>
67+
<skipTests>true</skipTests>
68+
</configuration>
69+
</plugin>
70+
<!-- enable scalatest -->
71+
<plugin>
72+
<groupId>org.scalatest</groupId>
73+
<artifactId>scalatest-maven-plugin</artifactId>
74+
<configuration>
75+
<logForkedProcessCommand>true</logForkedProcessCommand>
76+
</configuration>
77+
<executions>
78+
<execution>
79+
<goals>
80+
<goal>test</goal>
81+
</goals>
82+
</execution>
83+
</executions>
84+
</plugin>
85+
</plugins>
86+
</build>
87+
<reporting>
88+
<plugins>
89+
<plugin>
90+
<groupId>org.scalatest</groupId>
91+
<artifactId>scalatest-maven-plugin</artifactId>
92+
</plugin>
93+
</plugins>
94+
</reporting>
95+
</project>
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
package org.example
2+
3+
class App {
4+
def runApp(): String = {
5+
"It ran!"
6+
}
7+
}
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
package org.example
2+
3+
import org.scalatest.{FlatSpec, Matchers}
4+
5+
class AppTest extends FlatSpec with Matchers {
6+
"Our example App" should "run" in {
7+
val app = new App
8+
app.runApp() shouldBe "It ran!"
9+
}
10+
}

src/it/spaces in path/verify.groovy

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
2+
def logsFile = new File(basedir, "build.log")
3+
4+
if (!logsFile.exists()) {
5+
throw new Exception("Could not find build.log. Searched: " + logsFile)
6+
}
7+
8+
def testSummaryLines = []
9+
10+
logsFile.filterLine {
11+
it ==~ /.*Tests: succeeded [0-9]*, failed [0-9]*, canceled [0-9]*, ignored [0-9]*, pending [0-9]*.*/
12+
}.each { line -> testSummaryLines << "" + line }
13+
14+
if (testSummaryLines.size == 0) {
15+
throw new Exception("Could not find scalatest's summary line in build.log")
16+
} else if (testSummaryLines.size > 1) {
17+
throw new Exception("Found more than one scalatest summary line in build.log")
18+
}
19+
20+
if (testSummaryLines[0].contains("Tests: succeeded 0, failed 0, canceled 0, ignored 0, pending 0")) {
21+
throw new Exception("No tests were run by scalatest!")
22+
}
23+
24+
return true

src/main/java/org/scalatest/tools/maven/AbstractScalaTestMojo.java

Lines changed: 27 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -431,12 +431,37 @@ private List<String> config() {
431431
}
432432

433433
private List<String> runpath() {
434+
checkRunpathArgument("Output", outputDirectory);
435+
checkRunpathArgument("Test output", testOutputDirectory);
436+
437+
String outputPath = outputDirectory.getAbsolutePath();
438+
if(outputPath.contains(" ")) {
439+
outputPath = outputPath.replaceAll(" ","\\\\ ");
440+
getLog().debug(String.format("Escaped output directory path: %s", outputPath));
441+
}
442+
443+
String testOutputPath = testOutputDirectory.getAbsolutePath();
444+
if(testOutputPath.contains(" ")) {
445+
testOutputPath = testOutputPath.replaceAll(" ","\\\\ ");
446+
getLog().debug(String.format("Escaped test output directory path: %s", testOutputPath));
447+
}
448+
434449
return compoundArg("-R",
435-
outputDirectory.getAbsolutePath(),
436-
testOutputDirectory.getAbsolutePath(),
450+
outputPath,
451+
testOutputPath,
437452
runpath);
438453
}
439454

455+
private void checkRunpathArgument(String directoryName, File directory) {
456+
if(!directory.exists()) {
457+
getLog().warn(String.format("%s directory does not exist: %s", directoryName, directory.getAbsolutePath()));
458+
} else if(!directory.isDirectory()) {
459+
getLog().warn(String.format("%s is not a directory: %s", directoryName, directory.getAbsolutePath()));
460+
} else if(!directory.canRead()) {
461+
getLog().warn(String.format("%s directory is not readable: %s", directoryName, directory.getAbsolutePath()));
462+
}
463+
}
464+
440465
private List<String> tagsToInclude() {
441466
return compoundArg("-n", tagsToInclude);
442467
}

src/test/scala/org/scalatest/tools/maven/PluginTest.scala

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,16 @@ final class PluginTest
1717
val tmpDir = new File(System.getProperty("java.io.tmpdir"))
1818
val reportsDirectory = new File(tmpDir, "reportsDirectory")
1919
val baseDir = new File(tmpDir, "basedir");
20-
val testOutputDirectory = new File(reportsDirectory, "testOutputDirectory").getAbsolutePath
21-
val outputDirectory = new File(reportsDirectory, "outputDirectory").getAbsolutePath
20+
val testOutputDirectory = {
21+
val dir = new File(reportsDirectory, "testOutputDirectory")
22+
dir.mkdirs()
23+
dir.getAbsolutePath
24+
}
25+
val outputDirectory = {
26+
val dir = new File(reportsDirectory, "outputDirectory")
27+
dir.mkdirs()
28+
dir.getAbsolutePath
29+
}
2230

2331
override def afterAll {
2432
def delete(it: File) {

0 commit comments

Comments
 (0)