Skip to content

Commit 4ede056

Browse files
author
Igor Polevoy
committed
#223 Lessc plugin need to be able to process more than one file - yet, one more fix for Windows!!!
1 parent 6c895e7 commit 4ede056

File tree

2 files changed

+29
-19
lines changed

2 files changed

+29
-19
lines changed

activeweb-lessc-integration-test/pom.xml

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -117,6 +117,12 @@
117117
<scope>test</scope>
118118
</dependency>
119119

120+
<dependency>
121+
<groupId>org.apache.maven.shared</groupId>
122+
<artifactId>maven-invoker</artifactId>
123+
<version>2.0.11</version>
124+
</dependency>
125+
120126
<dependency>
121127
<groupId>org.slf4j</groupId>
122128
<artifactId>slf4j-api</artifactId>

activeweb-lessc-integration-test/src/test/java/org/javalite/lessc/maven/IntegrationTest.java

Lines changed: 23 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,10 @@
11
package org.javalite.lessc.maven;
22

3+
import org.apache.maven.shared.invoker.*;
34
import org.junit.Test;
45

56
import java.io.*;
7+
import java.util.Arrays;
68

79
import static org.javalite.test.jspec.JSpec.a;
810
import static org.javalite.test.jspec.JSpec.the;
@@ -12,20 +14,21 @@
1214
*/
1315
public class IntegrationTest {
1416

15-
String maven = System.getProperty("os.name").contains("Windows") ? "cmd.exe /c mvn" : "mvn";
17+
protected String execute(String root, String... args) throws IOException, InterruptedException, MavenInvocationException {
18+
InvocationRequest request = new DefaultInvocationRequest();
19+
request.setPomFile( new File( root + "/pom.xml" ) );
20+
request.setGoals(Arrays.asList(args));
21+
Invoker invoker = new DefaultInvoker();
22+
invoker.setWorkingDirectory(new File(root));
1623

17-
protected String execute(String dir, String... args) throws IOException, InterruptedException {
18-
InputStream stdErr, stdOut;
19-
Process process = Runtime.getRuntime().exec(args, new String[]{"JAVA_HOME=" + System.getProperty("java.home")}, new File(dir));
20-
stdErr = process.getErrorStream();
21-
stdOut = process.getInputStream();
22-
BufferedReader reader = new BufferedReader(new InputStreamReader(stdOut));
23-
String content = getContent(reader);
24-
reader.close();
25-
reader = new BufferedReader(new InputStreamReader(stdErr));
26-
content += getContent(reader);
27-
reader.close();
28-
return content;
24+
ByteArrayOutputStream outputStream = new ByteArrayOutputStream();
25+
ByteArrayOutputStream errorStream = new ByteArrayOutputStream();
26+
invoker.setErrorHandler(new PrintStreamHandler(new PrintStream(outputStream), true));
27+
invoker.setOutputHandler(new PrintStreamHandler(new PrintStream(errorStream), true));
28+
invoker.execute(request);
29+
String output = outputStream.toString();
30+
output += errorStream.toString();
31+
return output;
2932
}
3033

3134
private String getContent(BufferedReader reader) throws IOException {
@@ -39,25 +42,26 @@ private String getContent(BufferedReader reader) throws IOException {
3942
}
4043

4144
@Test
42-
public void shouldCompileProjectWithSingleLessFile() throws IOException, InterruptedException {
45+
public void shouldCompileProjectWithSingleLessFile() throws IOException, InterruptedException, MavenInvocationException {
4346

4447
String root = "target/test-project";
4548

46-
String output = execute(root, maven, "clean");
49+
String output = execute(root, "clean");
4750
the(output).shouldContain("BUILD SUCCESS");
48-
output = execute(root, "mvn", "install", "-o");
51+
52+
output = execute(root, "install", "-o");
4953
the(output).shouldContain("BUILD SUCCESS");
5054

5155
File f = new File(root + "/target/web/bootstrap.css");
5256
a(f.exists()).shouldBeTrue();
5357
}
5458

5559
@Test
56-
public void shouldCompileProjectWithMultipleLessFile() throws IOException, InterruptedException {
60+
public void shouldCompileProjectWithMultipleLessFile() throws IOException, InterruptedException, MavenInvocationException {
5761
String root = "target/test-project-list";
58-
String output = execute(root, maven, "clean");
62+
String output = execute(root, "clean");
5963
the(output).shouldContain("BUILD SUCCESS");
60-
output = execute(root, maven, "install", "-o");
64+
output = execute(root, "install", "-o");
6165
the(output).shouldContain("BUILD SUCCESS");
6266

6367
File f = new File(root + "/target/web1/bootstrap.css");

0 commit comments

Comments
 (0)