Skip to content

Commit e78b05e

Browse files
committed
Make maven plugin paths platform agnostic.
1 parent 0dde53c commit e78b05e

File tree

8 files changed

+103
-14
lines changed

8 files changed

+103
-14
lines changed

appveyor.yml

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
version: '{build}'
2+
skip_tags: true
3+
clone_depth: 10
4+
environment:
5+
matrix:
6+
- JAVA_HOME: C:\Program Files\Java\jdk1.7.0
7+
- JAVA_HOME: C:\Program Files\Java\jdk1.8.0
8+
branches:
9+
only:
10+
- master
11+
except:
12+
- gh-pages
13+
os: Windows Server 2012
14+
install:
15+
- ps: |
16+
Add-Type -AssemblyName System.IO.Compression.FileSystem
17+
if (!(Test-Path -Path "C:\maven" )) {
18+
(new-object System.Net.WebClient).DownloadFile('http://apache.mirrors.tds.net/maven/maven-3/3.3.9/binaries/apache-maven-3.3.9-bin.zip', 'C:\maven-bin.zip')
19+
[System.IO.Compression.ZipFile]::ExtractToDirectory("C:\maven-bin.zip", "C:\maven")
20+
}
21+
- cmd: SET PATH=C:\maven\apache-maven-3.3.9\bin;%JAVA_HOME%\bin;%PATH:C:\Ruby193\bin;=%
22+
- cmd: SET MAVEN_OPTS=-XX:MaxPermSize=2g -Xmx4g
23+
- cmd: SET JAVA_OPTS=-XX:MaxPermSize=2g -Xmx4g
24+
- cmd: mvn --version
25+
- cmd: java -version
26+
build_script:
27+
- mvn clean
28+
- mvn compile -P train-all-examples
29+
test_script:
30+
- mvn test
31+
cache:
32+
- C:\maven\
33+
- C:\Users\appveyor\.m2

lbjava-mvn-plugin/src/main/java/edu/illinois/cs/cogcomp/CleanMojo.java

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,10 +10,13 @@
1010
*/
1111
package edu.illinois.cs.cogcomp;
1212

13+
import java.io.File;
14+
import java.util.ArrayList;
1315
import java.util.Arrays;
1416
import java.util.Collections;
1517
import java.util.List;
1618

19+
import edu.illinois.cs.cogcomp.lbjava.util.FileUtils;
1720
import org.apache.commons.lang.StringUtils;
1821
import org.apache.maven.plugin.AbstractMojo;
1922
import org.apache.maven.plugin.MojoExecutionException;
@@ -59,10 +62,14 @@ public class CleanMojo extends AbstractMojo {
5962
private String outputdir;
6063

6164
public void execute() throws MojoExecutionException {
65+
dFlag = FileUtils.getPlatformIndependentFilePath(dFlag);
66+
gspFlag = FileUtils.getPlatformIndependentFilePath(gspFlag);
67+
sourcepathFlag = FileUtils.getPlatformIndependentFilePath(sourcepathFlag);
6268

6369
classpath.add(dFlag);
6470
classpath.add(gspFlag);
65-
String newpath = StringUtils.join(classpath, ":");
71+
72+
String newpath = StringUtils.join(classpath, File.pathSeparator);
6673

6774
// We need to reverse the order we do the cleaning since there might be dependencies across files
6875
List<String> fileList = Arrays.asList(lbjavaInputFileList);
@@ -74,6 +81,9 @@ public void execute() throws MojoExecutionException {
7481
}
7582

7683
getLog().info("Calling Java edu.illinois.cs.cogcomp.lbjava.Main with the -x flag (for cleaning)...");
84+
85+
lbjInputFile = FileUtils.getPlatformIndependentFilePath(lbjInputFile);
86+
7787
try {
7888
// The -x flag makes all the difference.
7989
String[] args = new String[] { "java", "-cp", newpath, "edu.illinois.cs.cogcomp.lbjava.Main", "-x",

lbjava-mvn-plugin/src/main/java/edu/illinois/cs/cogcomp/CompileMojo.java

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
import java.io.File;
1414
import java.util.List;
1515

16+
import edu.illinois.cs.cogcomp.lbjava.util.FileUtils;
1617
import org.apache.commons.lang.StringUtils;
1718
import org.apache.maven.plugin.AbstractMojo;
1819
import org.apache.maven.plugin.MojoExecutionException;
@@ -58,27 +59,28 @@ public class CompileMojo extends AbstractMojo {
5859
private String outputdir;
5960

6061
public void execute() throws MojoExecutionException {
62+
dFlag = FileUtils.getPlatformIndependentFilePath(dFlag);
63+
gspFlag = FileUtils.getPlatformIndependentFilePath(gspFlag);
64+
sourcepathFlag = FileUtils.getPlatformIndependentFilePath(sourcepathFlag);
6165

6266
classpath.add(dFlag);
6367
classpath.add(gspFlag);
64-
String newpath = StringUtils.join(classpath, ":");
68+
69+
String newpath = StringUtils.join(classpath, File.pathSeparator);
6570

6671
// If these directories don't exist, make them.
6772
new File(dFlag).mkdirs();
6873
new File(gspFlag).mkdirs();
6974

7075
for (String lbjInputFile : lbjavaInputFileList) {
7176
if (StringUtils.isEmpty(lbjInputFile)) {
72-
// making the optional-compile-step parameter happy.
77+
// making the optional-compile-parameter happy.
7378
continue;
7479
}
7580

7681
getLog().info("Calling Java edu.illinois.cs.cogcomp.lbjava.Main...");
7782

78-
if (StringUtils.isEmpty(lbjInputFile)) {
79-
// making the optional-compile-parameter happy.
80-
continue;
81-
}
83+
lbjInputFile = FileUtils.getPlatformIndependentFilePath(lbjInputFile);
8284

8385
try {
8486
String[] args = new String[] { "java", "-cp", newpath, "edu.illinois.cs.cogcomp.lbjava.Main",

lbjava-mvn-plugin/src/main/java/edu/illinois/cs/cogcomp/GenerateMojo.java

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
*/
1111
package edu.illinois.cs.cogcomp;
1212

13+
import edu.illinois.cs.cogcomp.lbjava.util.FileUtils;
1314
import org.apache.commons.lang.StringUtils;
1415
import org.apache.maven.plugin.AbstractMojo;
1516
import org.apache.maven.plugin.MojoExecutionException;
@@ -58,10 +59,14 @@ public class GenerateMojo extends AbstractMojo {
5859
private String outputdir;
5960

6061
public void execute() throws MojoExecutionException {
62+
dFlag = FileUtils.getPlatformIndependentFilePath(dFlag);
63+
gspFlag = FileUtils.getPlatformIndependentFilePath(gspFlag);
64+
sourcepathFlag = FileUtils.getPlatformIndependentFilePath(sourcepathFlag);
6165

6266
classpath.add(dFlag);
6367
classpath.add(gspFlag);
64-
String newpath = StringUtils.join(classpath, ":");
68+
69+
String newpath = StringUtils.join(classpath, File.pathSeparator);
6570

6671
// If these directories don't exist, make them.
6772
new File(dFlag).mkdirs();
@@ -74,6 +79,9 @@ public void execute() throws MojoExecutionException {
7479
}
7580

7681
getLog().info("Calling Java edu.illinois.cs.cogcomp.lbjava.Main...");
82+
83+
lbjInputFile = FileUtils.getPlatformIndependentFilePath(lbjInputFile);
84+
7785
try {
7886
String[] args = new String[] { "java", "-cp", newpath, "edu.illinois.cs.cogcomp.lbjava.Main",
7987
"-c", "-d", dFlag, "-gsp", gspFlag, "-sourcepath", sourcepathFlag, lbjInputFile };

lbjava/pom.xml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,11 @@
5757
<artifactId>commons-math3</artifactId>
5858
<version>3.6</version>
5959
</dependency>
60+
<dependency>
61+
<groupId>org.apache.commons</groupId>
62+
<artifactId>commons-lang3</artifactId>
63+
<version>3.4</version>
64+
</dependency>
6065
</dependencies>
6166

6267
<reporting>

lbjava/src/main/java/edu/illinois/cs/cogcomp/lbjava/Train.java

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,8 @@
4343
import edu.illinois.cs.cogcomp.lbjava.parse.Parser;
4444
import edu.illinois.cs.cogcomp.lbjava.util.ClassUtils;
4545

46+
import org.apache.commons.lang3.StringEscapeUtils;
47+
4648

4749
/**
4850
* After code has been generated with {@link TranslateToJava}, this pass
@@ -1079,7 +1081,7 @@ && new File(exFilePath).exists())
10791081
out.println(
10801082
" public static Parser getParser() { return new "
10811083
+ "edu.illinois.cs.cogcomp.lbjava.parse.ArrayFileParser(\""
1082-
+ new File(exFilePath).getAbsolutePath()
1084+
+ StringEscapeUtils.escapeJava(new File(exFilePath).getAbsolutePath())
10831085
+ "\"); }");
10841086
else
10851087
out.println(" public static Parser getParser() { return "
@@ -1091,7 +1093,8 @@ && new File(testExFilePath).exists())
10911093
out.println(
10921094
" public static Parser getTestParser() { return new "
10931095
+ "edu.illinois.cs.cogcomp.lbjava.parse.ArrayFileParser(\""
1094-
+ new File(testExFilePath).getAbsolutePath() + "\"); }");
1096+
+ StringEscapeUtils.escapeJava(new File(testExFilePath).getAbsolutePath())
1097+
+ "\"); }");
10951098
else
10961099
out.println(" public static Parser getTestParser() { return "
10971100
+ lce.testParser + "; }\n");
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
/**
2+
* This software is released under the University of Illinois/Research and
3+
* Academic Use License. See the LICENSE file in the root folder for details.
4+
* Copyright (c) 2016
5+
*
6+
* Developed by:
7+
* The Cognitive Computations Group
8+
* University of Illinois at Urbana-Champaign
9+
* http://cogcomp.cs.illinois.edu/
10+
*/
11+
package edu.illinois.cs.cogcomp.lbjava.util;
12+
13+
import java.io.File;
14+
15+
/**
16+
* Utility methods for handling file paths.
17+
*
18+
**/
19+
public class FileUtils {
20+
public static String getPlatformIndependentFilePath(String configFilePath) {
21+
if (File.separatorChar == '/') {
22+
return configFilePath;
23+
}
24+
25+
return configFilePath.replace('/', File.separatorChar);
26+
}
27+
}

lbjava/src/test/java/edu/illinois/cs/cogcomp/lbjava/MainTest.java

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
import edu.illinois.cs.cogcomp.lbjava.IR.*;
1414
import edu.illinois.cs.cogcomp.lbjava.frontend.Yylex;
1515
import edu.illinois.cs.cogcomp.lbjava.frontend.parser;
16+
import edu.illinois.cs.cogcomp.lbjava.util.FileUtils;
1617
import org.junit.After;
1718
import org.junit.Before;
1819
import org.junit.Test;
@@ -59,10 +60,10 @@ private String generateLBJavaScript(String learnerName, String extractor, String
5960
@Before
6061
public void setUp() throws Exception {
6162
Main.fileNames = new HashSet<>();
62-
Main.generatedSourceDirectory = "target/test-classes/lbj";
63-
Main.classDirectory = "target/test-classes";
64-
Main.classPackageDirectory = "target/test-classes/lbj";
65-
Main.sourceDirectory = "target/test-classes/lbj";
63+
Main.generatedSourceDirectory = FileUtils.getPlatformIndependentFilePath("target/test-classes/lbj");
64+
Main.classDirectory = FileUtils.getPlatformIndependentFilePath("target/test-classes");
65+
Main.classPackageDirectory = FileUtils.getPlatformIndependentFilePath("target/test-classes/lbj");
66+
Main.sourceDirectory = FileUtils.getPlatformIndependentFilePath("target/test-classes/lbj");
6667

6768
// The auto-generated code directory needs to be added to classpath
6869
URLClassLoader urlClassLoader = (URLClassLoader) ClassLoader.getSystemClassLoader();

0 commit comments

Comments
 (0)