Skip to content

Commit f728fc5

Browse files
Fix code paths that cause errors on Windows (#8355)
* Add some docs to hint that setting up in the WSL may be beneficial Using the WSL on Windows means that the unit tests can be run. Due to IntelliJ's good integration into the WSL, this works very seamless with IntelliJ as well * Fix Tests on Windows instead of suggesting WSL This fixes some tests, like XslUtilTest and RemoveSourceMapUrlProcessorTest to include the expected line endings This also adjusts some wro4j classes to work correctly for windows. Previously, some code paths were hardcoded to only work on the D: drive on windows. This fixes all these issues by special casing file:/ URIs, as windows FS will throw an exception when trying to convert those to paths. Wro4j is also adjusted to take backslashes into account, as windows internally uses these instead of forward slashes for path separation. Finally, the ES enforcer script is updated to not use project.baseUri, as this causes compilation errors on windows. This is because these variables are filled before compiling, and on windows this results in paths like "C:\Builds\core-geonetwork", which is invalid, because the backslashes need to be escaped. Use the baseUri instead, as this always contains forward slashes. * Revert unintended whitespace change * Make MessageProducerTest thread-safe This test currently fails sometimes because of concurrent modifications. Adjust it so it uses proper thread safe constructs * Update core/src/test/java/org/fao/geonet/util/XslUtilTest.java --------- Co-authored-by: Jose García <josegar74@gmail.com>
1 parent 59216b6 commit f728fc5

File tree

11 files changed

+32
-30
lines changed

11 files changed

+32
-30
lines changed

core/src/test/java/org/fao/geonet/util/XslUtilTest.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,8 @@ public void testHtml2text() {
4141
@Test
4242
public void testHtml2textSubstituteHtmlToTextLayoutElement() {
4343
String html = "<div><span>Sample text</span><br/><span>Sample text 2</span><br/><span>Sample text 3</span></div>";
44-
String expectedText = "Sample text\nSample text 2\nSample text 3";
44+
String lineSeparator = System.lineSeparator();
45+
String expectedText = "Sample text" + lineSeparator + "Sample text 2" + lineSeparator + "Sample text 3";
4546
String text = XslUtil.html2text(html, true);
4647

4748
assertEquals(expectedText, text);

es/pom.xml

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -81,12 +81,13 @@
8181
kibana = Pattern.compile("kibana:(\\d.\\d\\d.\\d)");
8282
patterns = new Pattern[]{ docker, kibana};
8383

84-
reader = new BufferedReader(new FileReader("${project.basedir}"+"/"+filename));
84+
String baseDir = new File(java.net.URI.create("${project.baseUri}")).getAbsolutePath().toString();
85+
reader = new BufferedReader(new FileReader(baseDir+"/"+filename));
8586

8687
number = 0;
8788
while ((line = reader.readLine()) != null) {
8889
number++;
89-
for (pattern : patterns ){
90+
for (pattern : patterns) {
9091
matcher = pattern.matcher(line);
9192
if (matcher.find()) {
9293
if (!esVersion.equals(matcher.group(1))) {

software_development/INTELLIJ.md

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
# IntelliJ IDE
22

3-
JetBrains provide a the IntelliJ IDE, a community edition is available and
4-
is documented here.
3+
JetBrains provide the IntelliJ IDE, a community edition is available [here](https://www.jetbrains.com/idea/download/).
54

65
This IDE is recommended for excellent Maven integration, and very fast build times.
76
It is especially good at working with large multi-module projects such as GeoNetwork.
@@ -10,16 +9,16 @@ It is especially good at working with large multi-module projects such as GeoNet
109

1110
1. Open project in IntelliJ, it will create an `.idea` folder (which is covered by `.gitignore`)
1211

13-
2. Use *File* > *Project Structure* to confirm Java 8 is used
12+
2. Use *File* > *Project Structure* to confirm Java 11 is used.
1413

15-
4. Configuration to make *Maven* tools window easier to follow:
14+
3. Configuration to make *Maven* tools window easier to follow:
1615

1716
* *Group Modules*
1817
* *Always Show ArtifactId*
1918

2019
![configuration](intelij-maven-config.png)
2120

22-
5. Use the *Maven* tools window to:
21+
4. Use the *Maven* tools window to:
2322

2423
* Enable the `env-dev` profile
2524
* *Toggle "Skip Tests" Mode*

software_development/SOURCE.md

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,7 @@ cd core-geonetwork
1515
mvn clean install -DskipTests
1616
```
1717

18-
Submodules
19-
----------
18+
## Submodules
2019

2120
GeoNetwork use submodules, these were initialized by the ``--recursive`` option when cloning the repository.
2221

software_development/TOOLS.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
# Tools
22

3-
GeoNetwork is a Java Web Application, developed using Java 8, Maven.
3+
GeoNetwork is a Java Web Application, developed using Java and Maven.
44

55
Documentation makes use of the python Sphinx build system.
66

@@ -68,7 +68,7 @@ Maven repository is available at repo.osgeo.org:
6868

6969
GeoNetwork Reference
7070

71-
* [software_development/building](BUIDLING.md)
71+
* [software_development/building](BUILDING.md)
7272
* [web](../web/README.md)
7373

7474
Reference:

workers/camelPeriodicProducer/src/test/java/org/fao/geonet/camelPeriodicProducer/MessageProducerTest.java

Lines changed: 12 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -39,12 +39,14 @@
3939

4040
import java.io.Serializable;
4141
import java.util.ArrayList;
42+
import java.util.Collections;
4243
import java.util.List;
4344
import java.util.Map;
4445
import java.util.concurrent.CompletableFuture;
4546
import java.util.concurrent.ExecutionException;
4647
import java.util.concurrent.TimeUnit;
4748
import java.util.concurrent.TimeoutException;
49+
import java.util.concurrent.atomic.AtomicInteger;
4850
import java.util.function.Function;
4951
import java.util.stream.Collectors;
5052

@@ -170,16 +172,16 @@ public String getContent() {
170172
}
171173
}
172174

173-
static public class MessageConsumer {
175+
public static class MessageConsumer {
174176

175-
private Integer count = 0;
176-
private CompletableFuture<List<String>> future = new CompletableFuture();
177-
private String uri;
178-
179-
private List<String> receivedContent = new ArrayList();
177+
private final String uri;
178+
private AtomicInteger count;
179+
private CompletableFuture<List<String>> future;
180+
private List<String> receivedContent;
180181

181182
public MessageConsumer(String uri) {
182183
this.uri = uri;
184+
reset();
183185
}
184186

185187
public String getUri() {
@@ -189,8 +191,7 @@ public String getUri() {
189191
public void consume(Exchange exchange) {
190192
TestMessage msg = (TestMessage) exchange.getProperty("configuration");
191193
receivedContent.add(msg.getContent());
192-
count++;
193-
if (count > 4) {
194+
if (count.incrementAndGet() > 4) {
194195
future.complete(receivedContent);
195196
}
196197
}
@@ -200,9 +201,9 @@ public List<String> waitFive() throws InterruptedException, ExecutionException,
200201
}
201202

202203
public void reset() {
203-
count = 0;
204-
receivedContent = new ArrayList();
205-
future = new CompletableFuture();
204+
count = new AtomicInteger(0);
205+
receivedContent = Collections.synchronizedList(new ArrayList<>());
206+
future = new CompletableFuture<>();
206207
}
207208
}
208209
}

wro4j/src/main/java/org/fao/geonet/wro4j/ClosureDependencyUriLocator.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,8 @@ static Resource createClosureDepResource(ClosureRequireDependencyManager.Node de
2727
resource.setMinimize(false);
2828
resource.setType(ResourceType.JS);
2929

30-
if (Files.exists(IO.toPath(dep.path.replace("file:/D:", "/D")))) {
30+
// If not a URI, but an actual path, set the URI accordingly
31+
if (!dep.path.startsWith("file:/") && Files.exists(IO.toPath(dep.path))) {
3132
resource.setUri(IO.toPath(dep.path).toUri().toString());
3233
} else {
3334
StringBuilder path = new StringBuilder();

wro4j/src/main/java/org/fao/geonet/wro4j/ClosureRequireDependencyManager.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ public Node addFile(@Nonnull String path, @Nonnull File javascriptFile, @Nonnull
5656
public Node addFile(@Nonnull String path, @Nonnull String javascript, @Nonnull Set<String> notMinimized) {
5757
boolean isMinimized = true;
5858
for (String s : notMinimized) {
59-
if (path.endsWith(s)) {
59+
if (path.endsWith(s) || path.endsWith(s.replace('/', '\\'))) {
6060
isMinimized = false;
6161
break;
6262
}

wro4j/src/main/java/org/fao/geonet/wro4j/GeonetWroModelFactory.java

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -538,9 +538,8 @@ private Resource createResourceFrom(ClosureRequireDependencyManager.Node dep) {
538538
Resource resource = new Resource();
539539
resource.setMinimize(dep.isMinimized);
540540
resource.setType(ResourceType.JS);
541-
final Path path = IO.toPath(dep.path.replace("file:/D:", "/D"));
542-
if (Files.exists(path)) {
543-
resource.setUri(path.toUri().toString());
541+
if (!dep.path.startsWith("file:/") && Files.exists(IO.toPath(dep.path))) {
542+
resource.setUri(IO.toPath(dep.path).toUri().toString());
544543
} else {
545544
resource.setUri(dep.path);
546545
}

wro4j/src/main/java/org/fao/geonet/wro4j/TemplatesUriLocator.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ public InputStream locate(String uri) throws IOException {
3232
} else {
3333
javascript = new StringBuilder();
3434
final String realPath;
35-
final String path = uri.substring(URI_PREFIX.length());
35+
final String path = uri.substring(URI_PREFIX.length()).replace('\\', '/');
3636
final ServletContext servletContext = Context.get().getServletContext();
3737
if (servletContext != null) {
3838
realPath = servletContext.getRealPath(path);

0 commit comments

Comments
 (0)