Skip to content

Escape spaces in project path #37

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 12 commits into from
Jun 13, 2020
Merged
Show file tree
Hide file tree
Changes from 5 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -176,10 +176,12 @@
<cloneProjectsTo>${project.build.directory}/it</cloneProjectsTo>
<pomIncludes>
<pomInclude>lift/pom.xml</pomInclude>
<pomInclude>spaces in path/pom.xml</pomInclude>
</pomIncludes>
<localRepositoryPath>${project.build.directory}/local-repo</localRepositoryPath>
<streamLogs>true</streamLogs>
<settingsFile>src/it/settings.xml</settingsFile>
<postBuildHookScript>verify</postBuildHookScript>
<goals>
<goal>clean</goal>
<goal>test</goal>
Expand Down
21 changes: 21 additions & 0 deletions src/it/lift/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,27 @@
<groupId>net.alchim31.maven</groupId>
<artifactId>scala-maven-plugin</artifactId>
<version>@scala.maven.plugin.version@</version>
<configuration>
<recompileMode>incremental</recompileMode>
<scalaVersion>${scala.version}</scalaVersion>
</configuration>
<executions>
<execution>
<id>scala-compile</id>
<phase>process-resources</phase>
<goals>
<goal>add-source</goal>
<goal>compile</goal>
</goals>
</execution>
<execution>
<id>scala-test-compile</id>
<phase>process-test-resources</phase>
<goals>
<goal>testCompile</goal>
</goals>
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.mortbay.jetty</groupId>
Expand Down
24 changes: 24 additions & 0 deletions src/it/lift/verify.groovy
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@

def logsFile = new File(basedir, "build.log")

if (!logsFile.exists()) {
throw new Exception("Could not find build.log. Searched: " + logsFile)
}

def testSummaryLines = []

logsFile.filterLine {
it ==~ /.*Tests: succeeded [0-9]*, failed [0-9]*, canceled [0-9]*, ignored [0-9]*, pending [0-9]*.*/
}.each { line -> testSummaryLines << "" + line }

if (testSummaryLines.size == 0) {
throw new Exception("Could not find scalatest's summary line in build.log")
} else if (testSummaryLines.size > 1) {
throw new Exception("Found more than one scalatest summary line in build.log")
}

if (testSummaryLines[0].contains("Tests: succeeded 0, failed 0, canceled 0, ignored 0, pending 0")) {
throw new Exception("No tests were run by scalatest!")
}

return true
3 changes: 3 additions & 0 deletions src/it/spaces in path/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
# spaces in path

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.
3 changes: 3 additions & 0 deletions src/it/spaces in path/invoker.properties
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
# A comma or space separated list of goals/phases to execute, may
# specify an empty list to execute the default goal of the IT project
invoker.goals = clean test
95 changes: 95 additions & 0 deletions src/it/spaces in path/pom.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,95 @@

<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>
<artifactId>spaces-in-path-it</artifactId>
<version>1.0-SNAPSHOT</version>
<packaging>jar</packaging>
<name>spaces-in-path-it</name>
<description>Runs the plugin for a project that contains spaces in the path.</description>

<parent>
<groupId>maven.scalatest.plugin.its</groupId>
<artifactId>it-parent</artifactId>
<version>1.0-SNAPSHOT</version>
<relativePath>../it-parent</relativePath>
</parent>

<dependencies>
<dependency>
<groupId>org.scala-lang</groupId>
<artifactId>scala-library</artifactId>
<version>@scala.version@</version>
</dependency>
<dependency>
<groupId>org.scalatest</groupId>
<artifactId>[email protected]@</artifactId>
<version>@scalatest.version@</version>
<scope>test</scope>
</dependency>
</dependencies>

<build>
<sourceDirectory>src/main/scala</sourceDirectory>
<testSourceDirectory>src/test/scala</testSourceDirectory>
<plugins>
<plugin>
<groupId>net.alchim31.maven</groupId>
<artifactId>scala-maven-plugin</artifactId>
<version>@scala.maven.plugin.version@</version>
<configuration>
<recompileMode>incremental</recompileMode>
<scalaVersion>${scala.version}</scalaVersion>
</configuration>
<executions>
<execution>
<id>scala-compile</id>
<phase>process-resources</phase>
<goals>
<goal>add-source</goal>
<goal>compile</goal>
</goals>
</execution>
<execution>
<id>scala-test-compile</id>
<phase>process-test-resources</phase>
<goals>
<goal>testCompile</goal>
</goals>
</execution>
</executions>
</plugin>
<!-- disable surefire -->
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<version>2.7</version>
<configuration>
<skipTests>true</skipTests>
</configuration>
</plugin>
<!-- enable scalatest -->
<plugin>
<groupId>org.scalatest</groupId>
<artifactId>scalatest-maven-plugin</artifactId>
<configuration>
<logForkedProcessCommand>true</logForkedProcessCommand>
</configuration>
<executions>
<execution>
<goals>
<goal>test</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</build>
<reporting>
<plugins>
<plugin>
<groupId>org.scalatest</groupId>
<artifactId>scalatest-maven-plugin</artifactId>
</plugin>
</plugins>
</reporting>
</project>
7 changes: 7 additions & 0 deletions src/it/spaces in path/src/main/scala/org/example/App.scala
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
package org.example

class App {
def runApp(): String = {
"It ran!"
}
}
10 changes: 10 additions & 0 deletions src/it/spaces in path/src/test/scala/org/example/AppTest.scala
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
package org.example

import org.scalatest.{FlatSpec, Matchers}

class AppTest extends FlatSpec with Matchers {
"Our example App" should "run" in {
val app = new App
app.runApp() shouldBe "It ran!"
}
}
24 changes: 24 additions & 0 deletions src/it/spaces in path/verify.groovy
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@

def logsFile = new File(basedir, "build.log")

if (!logsFile.exists()) {
throw new Exception("Could not find build.log. Searched: " + logsFile)
}

def testSummaryLines = []

logsFile.filterLine {
it ==~ /.*Tests: succeeded [0-9]*, failed [0-9]*, canceled [0-9]*, ignored [0-9]*, pending [0-9]*.*/
}.each { line -> testSummaryLines << "" + line }

if (testSummaryLines.size == 0) {
throw new Exception("Could not find scalatest's summary line in build.log")
} else if (testSummaryLines.size > 1) {
throw new Exception("Found more than one scalatest summary line in build.log")
}

if (testSummaryLines[0].contains("Tests: succeeded 0, failed 0, canceled 0, ignored 0, pending 0")) {
throw new Exception("No tests were run by scalatest!")
}

return true
38 changes: 32 additions & 6 deletions src/main/java/org/scalatest/tools/maven/AbstractScalaTestMojo.java
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
import org.codehaus.plexus.util.cli.Commandline;
import org.codehaus.plexus.util.cli.StreamConsumer;

import static java.lang.String.format;
import static org.scalatest.tools.maven.MojoUtils.*;

import java.io.*;
Expand Down Expand Up @@ -283,10 +284,10 @@ private boolean runForkingOnce(String[] args) throws MojoFailureException {
// Set up system properties
if (systemProperties != null) {
for (final Map.Entry<String, String> entry : systemProperties.entrySet()) {
cli.createArg().setValue(String.format("-D%s=%s", entry.getKey(), entry.getValue()));
cli.createArg().setValue(format("-D%s=%s", entry.getKey(), entry.getValue()));
}
}
cli.createArg().setValue(String.format("-Dbasedir=%s", project.getBasedir().getAbsolutePath()));
cli.createArg().setValue(format("-Dbasedir=%s", project.getBasedir().getAbsolutePath()));

// Set user specified JVM arguments
if (argLine != null) {
Expand Down Expand Up @@ -322,7 +323,7 @@ public void consumeLine(final String line) {
return result == 0;
}
catch (final CommandLineTimeOutException e) {
throw new MojoFailureException(String.format("Timed out after %d seconds waiting for forked process to complete.", forkedProcessTimeoutInSeconds));
throw new MojoFailureException(format("Timed out after %d seconds waiting for forked process to complete.", forkedProcessTimeoutInSeconds));
}
catch (final CommandLineException e) {
throw new MojoFailureException("Exception while executing forked process.", e);
Expand All @@ -346,7 +347,7 @@ private String buildClassPathEnvironment() {

private String forkedProcessDebuggingArguments() {
if (debugArgLine == null) {
return String.format("-Xdebug -Xrunjdwp:transport=dt_socket,server=y,suspend=y,address=%s", debuggerPort);
return format("-Xdebug -Xrunjdwp:transport=dt_socket,server=y,suspend=y,address=%s", debuggerPort);
} else {
return debugArgLine;
}
Expand Down Expand Up @@ -426,12 +427,37 @@ private List<String> config() {
}

private List<String> runpath() {
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The main fix is in this method.

checkRunpathArgument(outputDirectory);
checkRunpathArgument(testOutputDirectory);

String outputPath = outputDirectory.getAbsolutePath();
if(outputPath.contains(" ")) {
outputPath = outputPath.replaceAll(" ","\\\\ ");
getLog().debug(format("Escaped output directory path: %s", outputPath));
}

String testOutputPath = testOutputDirectory.getAbsolutePath();
if(testOutputPath.contains(" ")) {
testOutputPath = testOutputPath.replaceAll(" ","\\\\ ");
getLog().debug(format("Escaped test output directory path: %s", testOutputPath));
}

return compoundArg("-R",
outputDirectory.getAbsolutePath(),
testOutputDirectory.getAbsolutePath(),
outputPath,
testOutputPath,
runpath);
}

private void checkRunpathArgument(File directory) {
if(!directory.exists()) {
getLog().warn(format("Runpath directory does not exist: %s", directory.getAbsolutePath()));
} else if(!directory.isDirectory()) {
getLog().warn(format("Runpath argument is not a directory: %s", directory.getAbsolutePath()));
} else if(!directory.canRead()) {
getLog().warn(format("Runpath directory is not readable: %s", directory.getAbsolutePath()));
}
}

private List<String> tagsToInclude() {
return compoundArg("-n", tagsToInclude);
}
Expand Down