Skip to content

Commit 9f58caa

Browse files
committed
Merge pull request #158 from adangel:windows
Fix tests to run under Windows and MacOS #158
2 parents 80572ce + 45ec69b commit 9f58caa

File tree

17 files changed

+235
-101
lines changed

17 files changed

+235
-101
lines changed

.ci/build.sh

Lines changed: 26 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -14,20 +14,24 @@ function build() {
1414
pmd_ci_openjdk_setdefault 11
1515
pmd_ci_log_group_end
1616

17-
pmd_ci_log_group_start "Install xvfb"
18-
#see https://github.com/GabrielBB/xvfb-action
19-
sudo apt-get install --yes xvfb
20-
sudo apt-get install --yes libgtk2.0-0
21-
pmd_ci_log_group_end
22-
2317
echo
2418
pmd_ci_maven_display_info_banner
2519
pmd_ci_utils_determine_build_env pmd/pmd-eclipse-plugin
2620
echo
2721

22+
xvfb_cmd=""
23+
if [ "$(pmd_ci_utils_get_os)" == "linux" ]; then
24+
pmd_ci_log_group_start "Install xvfb (linux only)"
25+
#see https://github.com/GabrielBB/xvfb-action
26+
sudo apt-get install --yes xvfb
27+
sudo apt-get install --yes libgtk2.0-0
28+
xvfb_cmd="xvfb-run --auto-servernum"
29+
pmd_ci_log_group_end
30+
fi
31+
2832
if pmd_ci_utils_is_fork_or_pull_request; then
2933
pmd_ci_log_group_start "Build with mvnw"
30-
xvfb-run --auto-servernum ./mvnw clean verify \
34+
${xvfb_cmd} ./mvnw clean verify \
3135
--show-version --errors --batch-mode --no-transfer-progress \
3236
--toolchains .ci/files/toolchains.xml
3337
pmd_ci_log_group_end
@@ -37,6 +41,17 @@ function build() {
3741
# stop early for invalid maven version and branch/tag combination
3842
pmd_ci_maven_verify_version || exit 0
3943

44+
if [ "$(pmd_ci_utils_get_os)" != "linux" ]; then
45+
pmd_ci_log_group_start "Build with mvnw"
46+
${xvfb_cmd} ./mvnw clean verify \
47+
--show-version --errors --batch-mode --no-transfer-progress \
48+
--toolchains .ci/files/toolchains.xml
49+
pmd_ci_log_group_end
50+
51+
pmd_ci_log_info "Stopping build here, because os is not linux"
52+
exit 0
53+
fi
54+
4055
# only builds on pmd/pmd-eclipse-plugin continue here
4156
pmd_ci_log_group_start "Setup environment"
4257
pmd_ci_setup_secrets_private_env
@@ -60,12 +75,12 @@ function snapshot_build() {
6075
pmd_ci_log_info "This is a snapshot build on branch ${PMD_CI_BRANCH} (version: ${PMD_CI_MAVEN_PROJECT_VERSION})"
6176

6277
# Build 1 - without signing but with tests
63-
xvfb-run --auto-servernum ./mvnw clean verify \
78+
${xvfb_cmd} ./mvnw clean verify \
6479
--show-version --errors --batch-mode --no-transfer-progress \
6580
--toolchains .ci/files/toolchains.xml
6681

6782
# Build 2 - with signing, but skipping tests, pmd, checkstyle
68-
xvfb-run --auto-servernum ./mvnw clean verify \
83+
${xvfb_cmd} ./mvnw clean verify \
6984
--show-version --errors --batch-mode --no-transfer-progress \
7085
--toolchains .ci/files/toolchains.xml \
7186
--activate-profiles sign \
@@ -117,12 +132,12 @@ function release_build() {
117132
pmd_ci_log_info "This is a release build for tag ${PMD_CI_TAG} (version: ${PMD_CI_MAVEN_PROJECT_VERSION})"
118133

119134
# Build 1 - without signing but with tests
120-
xvfb-run --auto-servernum ./mvnw clean verify \
135+
${xvfb_cmd} ./mvnw clean verify \
121136
--show-version --errors --batch-mode --no-transfer-progress \
122137
--toolchains .ci/files/toolchains.xml
123138

124139
# Build 2 - with signing, but skipping tests, pmd, checkstyle
125-
xvfb-run --auto-servernum ./mvnw clean verify \
140+
${xvfb_cmd} ./mvnw clean verify \
126141
--show-version --errors --batch-mode --no-transfer-progress \
127142
--toolchains .ci/files/toolchains.xml \
128143
--activate-profiles sign \

.github/workflows/build.yml

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,11 @@ on:
1515

1616
jobs:
1717
build:
18-
runs-on: ubuntu-latest
18+
runs-on: ${{ matrix.os }}
1919
continue-on-error: false
20+
strategy:
21+
matrix:
22+
os: [ ubuntu-latest, windows-latest, macos-latest ]
2023
if: ${{ !contains(github.event.head_commit.message, '[skip ci]') }}
2124
steps:
2225
- uses: actions/checkout@v2

ReleaseNotes.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,8 @@ This is a minor release.
1515

1616
### Fixed Issues
1717

18+
* [#159](https://github.com/pmd/pmd-eclipse-plugin/issues/159): Error executing command ReviewCode: java.util.regex.PatternSyntaxException: Illegal/unsupported escape sequence near index (part 2)
19+
1820
### API Changes
1921

2022
### External Contributions

net.sourceforge.pmd.eclipse.plugin.test/pom.xml

Lines changed: 10 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -65,32 +65,24 @@
6565
</plugins>
6666
</build>
6767

68-
<!--
6968
<profiles>
7069
<profile>
7170
<id>osx</id>
7271
<activation>
73-
<property>
74-
<name>java.vendor.url</name>
75-
<value>http://www.apple.com/</value>
76-
</property>
72+
<os><family>mac</family></os>
7773
</activation>
7874
<build>
79-
<pluginManagement>
80-
<plugins>
81-
<plugin>
82-
<groupId>org.eclipse.tycho</groupId>
83-
<artifactId>tycho-surefire-plugin</artifactId>
84-
<version>${tycho.version}</version>
85-
<configuration>
86-
<argLine>-XstartOnFirstThread</argLine>
87-
</configuration>
88-
</plugin>
89-
</plugins>
90-
</pluginManagement>
75+
<plugins>
76+
<plugin>
77+
<groupId>org.eclipse.tycho</groupId>
78+
<artifactId>tycho-surefire-plugin</artifactId>
79+
<configuration>
80+
<argLine>-XstartOnFirstThread</argLine>
81+
</configuration>
82+
</plugin>
83+
</plugins>
9184
</build>
9285
</profile>
9386
</profiles>
94-
-->
9587

9688
</project>

net.sourceforge.pmd.eclipse.plugin.test/src/main/java/net/sourceforge/pmd/eclipse/EclipseUtils.java

Lines changed: 19 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
import java.util.Map;
1515
import java.util.Map.Entry;
1616
import java.util.Set;
17-
import java.util.concurrent.CountDownLatch;
17+
import java.util.concurrent.TimeUnit;
1818
import java.util.regex.Pattern;
1919

2020
import org.eclipse.core.resources.IContainer;
@@ -27,12 +27,14 @@
2727
import org.eclipse.core.resources.ResourcesPlugin;
2828
import org.eclipse.core.runtime.CoreException;
2929
import org.eclipse.core.runtime.IPath;
30-
import org.eclipse.core.runtime.NullProgressMonitor;
3130
import org.eclipse.core.runtime.Path;
31+
import org.eclipse.core.runtime.jobs.Job;
3232
import org.eclipse.jdt.core.IClasspathEntry;
3333
import org.eclipse.jdt.core.IJavaProject;
3434
import org.eclipse.jdt.core.JavaCore;
3535
import org.eclipse.jdt.core.JavaModelException;
36+
import org.eclipse.jdt.launching.JavaRuntime;
37+
import org.junit.Assert;
3638

3739
import net.sourceforge.pmd.Rule;
3840
import net.sourceforge.pmd.eclipse.runtime.PMDRuntimeConstants;
@@ -45,21 +47,7 @@
4547
* @author Philippe Herlin
4648
* @author Brian Remedios
4749
*/
48-
public class EclipseUtils {
49-
static class OpenMonitor extends NullProgressMonitor {
50-
private final CountDownLatch latch;
51-
52-
OpenMonitor(final CountDownLatch latch) {
53-
this.latch = latch;
54-
}
55-
56-
@Override
57-
public void done() {
58-
super.done();
59-
latch.countDown();
60-
}
61-
}
62-
50+
public final class EclipseUtils {
6351
/**
6452
* Because this class is a utility class, it cannot be instantiated
6553
*/
@@ -230,7 +218,7 @@ public static void addJavaNature(final IProject project) throws CoreException {
230218
javaProject
231219
.setRawClasspath(
232220
new IClasspathEntry[] { JavaCore.newSourceEntry(sourceFolder.getFullPath()),
233-
JavaCore.newContainerEntry(new Path("org.eclipse.jdt.launching.JRE_CONTAINER")) },
221+
JavaRuntime.getDefaultJREContainerEntry() },
234222
null);
235223

236224
Hashtable<String, String> javaOptions = JavaCore.getOptions();
@@ -370,4 +358,17 @@ public static void createFolders(IProject testProject, String fullpath) throws C
370358
current = folder;
371359
}
372360
}
361+
362+
public static void waitForJobs() throws InterruptedException {
363+
long start = System.currentTimeMillis();
364+
Thread.sleep(500);
365+
366+
while (!Job.getJobManager().isIdle()) {
367+
Thread.sleep(500);
368+
369+
if (System.currentTimeMillis() - start > TimeUnit.SECONDS.toMillis(30)) {
370+
Assert.fail("Timeout while waiting for Jobs to finish");
371+
}
372+
}
373+
}
373374
}
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
/*
2+
* BSD-style license; for more info see http://pmd.sourceforge.net/license.html
3+
*/
4+
5+
package net.sourceforge.pmd.eclipse;
6+
7+
import org.junit.rules.TestWatcher;
8+
import org.junit.runner.Description;
9+
import org.slf4j.Logger;
10+
import org.slf4j.LoggerFactory;
11+
12+
public class LoggingRule extends TestWatcher {
13+
14+
@Override
15+
protected void starting(Description description) {
16+
final Logger LOG = LoggerFactory.getLogger(description.getClassName());
17+
LOG.debug("\n*\n*\n* Starting test {}\n*\n*\n*", description.getMethodName());
18+
}
19+
20+
@Override
21+
protected void finished(Description description) {
22+
final Logger LOG = LoggerFactory.getLogger(description.getClassName());
23+
LOG.debug("\n*\n*\n* Finished test {}\n*\n*\n*", description.getMethodName());
24+
}
25+
}
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
/*
2+
* BSD-style license; for more info see http://pmd.sourceforge.net/license.html
3+
*/
4+
5+
package net.sourceforge.pmd.eclipse;
6+
7+
import java.util.concurrent.CountDownLatch;
8+
import java.util.concurrent.TimeUnit;
9+
10+
import org.eclipse.core.runtime.NullProgressMonitor;
11+
12+
public class WaitingMonitor extends NullProgressMonitor {
13+
private final CountDownLatch latch = new CountDownLatch(1);
14+
15+
@Override
16+
public void done() {
17+
super.done();
18+
latch.countDown();
19+
}
20+
21+
public void await() throws InterruptedException {
22+
latch.await(30, TimeUnit.SECONDS);
23+
}
24+
}

net.sourceforge.pmd.eclipse.plugin.test/src/main/java/net/sourceforge/pmd/eclipse/internal/TestActivator.java

Lines changed: 40 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,11 +4,19 @@
44

55
package net.sourceforge.pmd.eclipse.internal;
66

7+
import java.io.File;
8+
import java.io.IOException;
9+
10+
import org.eclipse.core.runtime.CoreException;
711
import org.eclipse.core.runtime.IStatus;
812
import org.eclipse.core.runtime.Status;
13+
import org.eclipse.jdt.launching.IVMInstall;
14+
import org.eclipse.jdt.launching.IVMInstallType;
15+
import org.eclipse.jdt.launching.JavaRuntime;
916
import org.eclipse.ui.plugin.AbstractUIPlugin;
1017
import org.slf4j.LoggerFactory;
1118

19+
import net.sourceforge.pmd.eclipse.WaitingMonitor;
1220
import net.sourceforge.pmd.eclipse.plugin.PMDPlugin;
1321

1422
import ch.qos.logback.classic.Level;
@@ -26,7 +34,37 @@ public TestActivator() {
2634
} else {
2735
mainPlugin.getLog().log(new Status(IStatus.WARNING, PMDPlugin.PLUGIN_ID, "Couldn't setup logging for tests."));
2836
}
29-
30-
}
3137

38+
// Setup a default JVM. This is especially required for mac osx on github actions,
39+
// as there is no default JVM detected automatically.
40+
// This is not done via the following extension, in order to check for the existence of openjdk8Path:
41+
/*
42+
<extension
43+
point="org.eclipse.jdt.launching.vmInstalls">
44+
<vmInstall
45+
home="${env_var:HOME}/openjdk8"
46+
id="net.sourceforge.pmd.eclipse.plugin.test.openjdk8"
47+
name="openjdk8"
48+
vmInstallType="org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType">
49+
</vmInstall>
50+
</extension>
51+
*/
52+
File openjdk8Path = new File(System.getProperty("user.home"), "openjdk8");
53+
if (openjdk8Path.exists()) {
54+
try {
55+
openjdk8Path = openjdk8Path.getCanonicalFile();
56+
IVMInstallType vmInstallType = JavaRuntime.getVMInstallType("org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType");
57+
IVMInstall vm = vmInstallType.createVMInstall("net.sourceforge.pmd.eclipse.plugin.test.openjdk8");
58+
vm.setInstallLocation(openjdk8Path);
59+
vm.setName("openjdk8");
60+
WaitingMonitor monitor = new WaitingMonitor();
61+
JavaRuntime.setDefaultVMInstall(vm, monitor);
62+
monitor.await();
63+
} catch (IOException | CoreException | InterruptedException e) {
64+
mainPlugin.getLog().log(new Status(IStatus.ERROR, PMDPlugin.PLUGIN_ID,
65+
"Error setting up default JVM " + openjdk8Path, e));
66+
Thread.currentThread().interrupt();
67+
}
68+
}
69+
}
3270
}

net.sourceforge.pmd.eclipse.plugin.test/src/main/java/net/sourceforge/pmd/eclipse/runtime/cmd/MultipleRulesetsTest.java

Lines changed: 1 addition & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,6 @@
1717
import org.eclipse.core.runtime.CoreException;
1818
import org.eclipse.core.runtime.NullProgressMonitor;
1919
import org.eclipse.core.runtime.Path;
20-
import org.eclipse.core.runtime.jobs.Job;
2120
import org.eclipse.jdt.core.IClasspathEntry;
2221
import org.eclipse.jdt.core.IJavaProject;
2322
import org.eclipse.jdt.core.JavaCore;
@@ -119,7 +118,7 @@ public void done() {
119118
}
120119
});
121120
latch.await(30, TimeUnit.SECONDS);
122-
waitForJobs();
121+
EclipseUtils.waitForJobs();
123122

124123
final ReviewCodeCmd cmd = new ReviewCodeCmd();
125124
cmd.addResource(this.testProject);
@@ -143,13 +142,6 @@ public void done() {
143142
assertHasRuleViolation(markersThird, "UseUtilityClass");
144143
}
145144

146-
private void waitForJobs() throws InterruptedException {
147-
long start = System.currentTimeMillis();
148-
while (!Job.getJobManager().isIdle() && System.currentTimeMillis() - start < TimeUnit.SECONDS.toMillis(30)) {
149-
Thread.sleep(500);
150-
}
151-
}
152-
153145
private void assertHasRuleViolation(IMarker[] markers, String rulename) throws CoreException {
154146
boolean found = false;
155147
for (IMarker marker : markers) {

net.sourceforge.pmd.eclipse.plugin.test/src/main/java/net/sourceforge/pmd/eclipse/runtime/cmd/ReviewCmdTest.java

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,8 @@
3030
import net.sourceforge.pmd.Rule;
3131
import net.sourceforge.pmd.RuleSet;
3232
import net.sourceforge.pmd.eclipse.EclipseUtils;
33+
import net.sourceforge.pmd.eclipse.LoggingRule;
34+
import net.sourceforge.pmd.eclipse.WaitingMonitor;
3335
import net.sourceforge.pmd.eclipse.plugin.PMDPlugin;
3436
import net.sourceforge.pmd.eclipse.runtime.PMDRuntimeConstants;
3537
import net.sourceforge.pmd.eclipse.runtime.preferences.IPreferences;
@@ -45,6 +47,9 @@
4547
public class ReviewCmdTest {
4648
private IProject testProject;
4749

50+
@org.junit.Rule
51+
public LoggingRule loggingRule = new LoggingRule();
52+
4853
@Before
4954
public void setUp() throws Exception {
5055

@@ -116,8 +121,16 @@ private IFile createMissingOverrideTestCase(IProject project) throws Exception {
116121
+ " void run() {\n" // line 2
117122
+ " }\n"
118123
+ "}");
119-
project.build(IncrementalProjectBuilder.FULL_BUILD, null);
120-
project.refreshLocal(IResource.DEPTH_INFINITE, null);
124+
125+
WaitingMonitor monitor;
126+
monitor = new WaitingMonitor();
127+
project.refreshLocal(IResource.DEPTH_INFINITE, monitor);
128+
monitor.await();
129+
130+
monitor = new WaitingMonitor();
131+
project.build(IncrementalProjectBuilder.FULL_BUILD, monitor);
132+
monitor.await();
133+
121134
return sourceFile;
122135
}
123136

0 commit comments

Comments
 (0)