Skip to content

Commit 8e7622b

Browse files
philwebbcbeams
authored andcommitted
Fix Windows-related build issues
- Increase max heap size in gradle wrapper. - Use MockProperties implementation to protect against security exceptions. - Replace windows CRLF with LF in various tests. - Increase Thread.sleep times to account for lack of precision on Windows. Issue: SPR-9717
1 parent 94bb036 commit 8e7622b

File tree

7 files changed

+114
-20
lines changed

7 files changed

+114
-20
lines changed

gradlew.bat

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ if "%OS%"=="Windows_NT" setlocal
1212
set DEFAULT_JVM_OPTS=
1313

1414
@rem ADDED BY HAND -- DO NOT ACCIDENTALLY DELETE WHEN UPGRADING GRADLE WRAPPER!
15-
set GRADLE_OPTS=-XX:MaxPermSize=1024m -Xmx1024m %GRADLE_OPTS%
15+
set GRADLE_OPTS=-XX:MaxPermSize=1024m -Xmx1024m -XX:MaxHeapSize=256m %GRADLE_OPTS%
1616
@rem END ADDED BY HAND
1717

1818
set DIRNAME=%~dp0

spring-beans/src/test/java/org/springframework/beans/factory/config/PropertyResourceConfigurerTests.java

Lines changed: 95 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2002-2010 the original author or authors.
2+
* Copyright 2002-2012 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -25,11 +25,15 @@
2525
import static test.util.TestResourceUtils.qualifiedResource;
2626

2727
import java.util.Collections;
28+
import java.util.HashMap;
2829
import java.util.List;
2930
import java.util.Map;
3031
import java.util.Properties;
3132
import java.util.Set;
33+
import java.util.prefs.AbstractPreferences;
34+
import java.util.prefs.BackingStoreException;
3235
import java.util.prefs.Preferences;
36+
import java.util.prefs.PreferencesFactory;
3337

3438
import org.junit.Before;
3539
import org.junit.Test;
@@ -52,19 +56,24 @@
5256
* Unit tests for various {@link PropertyResourceConfigurer} implementations including:
5357
* {@link PropertyPlaceholderConfigurer}, {@link PropertyOverrideConfigurer} and
5458
* {@link PreferencesPlaceholderConfigurer}.
55-
*
59+
*
5660
* @see PropertyPlaceholderConfigurerTests
5761
* @since 02.10.2003
5862
* @author Juergen Hoeller
5963
* @author Chris Beams
64+
* @author Phillip Webb
6065
*/
6166
public final class PropertyResourceConfigurerTests {
6267

68+
static {
69+
System.setProperty("java.util.prefs.PreferencesFactory", MockPreferencesFactory.class.getName());
70+
}
71+
6372
private static final Class<?> CLASS = PropertyResourceConfigurerTests.class;
6473
private static final Resource TEST_PROPS = qualifiedResource(CLASS, "test.properties");
6574
private static final Resource XTEST_PROPS = qualifiedResource(CLASS, "xtest.properties"); // does not exist
6675
private static final Resource TEST_PROPS_XML = qualifiedResource(CLASS, "test.properties.xml");
67-
76+
6877
private DefaultListableBeanFactory factory;
6978

7079
@Before
@@ -808,4 +817,87 @@ protected String convertPropertyValue(String originalValue) {
808817
}
809818
}
810819

820+
/**
821+
* {@link PreferencesFactory} to create {@link MockPreferences}.
822+
*/
823+
public static class MockPreferencesFactory implements PreferencesFactory {
824+
825+
private Preferences systemRoot = new MockPreferences();
826+
827+
private Preferences userRoot = new MockPreferences();
828+
829+
public Preferences systemRoot() {
830+
return systemRoot;
831+
}
832+
833+
public Preferences userRoot() {
834+
return userRoot;
835+
}
836+
}
837+
838+
/**
839+
* Mock implementation of {@link Preferences} that behaves the same regardless of the
840+
* underlying operating system and will never throw security exceptions.
841+
*/
842+
public static class MockPreferences extends AbstractPreferences {
843+
844+
private static Map<String, String> values = new HashMap<String, String>();
845+
846+
private static Map<String, AbstractPreferences> children = new HashMap<String, AbstractPreferences>();
847+
848+
public MockPreferences() {
849+
super(null, "");
850+
}
851+
852+
protected MockPreferences(AbstractPreferences parent, String name) {
853+
super(parent, name);
854+
}
855+
856+
@Override
857+
protected void putSpi(String key, String value) {
858+
values.put(key, value);
859+
}
860+
861+
@Override
862+
protected String getSpi(String key) {
863+
return values.get(key);
864+
}
865+
866+
@Override
867+
protected void removeSpi(String key) {
868+
values.remove(key);
869+
}
870+
871+
@Override
872+
protected void removeNodeSpi() throws BackingStoreException {
873+
}
874+
875+
@Override
876+
protected String[] keysSpi() throws BackingStoreException {
877+
return values.keySet().toArray(new String[values.size()]);
878+
}
879+
880+
@Override
881+
protected String[] childrenNamesSpi() throws BackingStoreException {
882+
return children.keySet().toArray(new String[values.size()]);
883+
}
884+
885+
@Override
886+
protected AbstractPreferences childSpi(String name) {
887+
AbstractPreferences child = children.get(name);
888+
if (child == null) {
889+
child = new MockPreferences(this, name);
890+
children.put(name, child);
891+
}
892+
return child;
893+
}
894+
895+
@Override
896+
protected void syncSpi() throws BackingStoreException {
897+
}
898+
899+
@Override
900+
protected void flushSpi() throws BackingStoreException {
901+
}
902+
}
811903
}

spring-webmvc/src/test/java/org/springframework/web/servlet/view/freemarker/FreeMarkerMacroTests.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2002-2009 the original author or authors.
2+
* Copyright 2002-2012 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -321,6 +321,7 @@ private String fetchMacro(String name) throws Exception {
321321
ClassPathResource resource = new ClassPathResource("test.ftl", getClass());
322322
assertTrue(resource.exists());
323323
String all = FileCopyUtils.copyToString(new InputStreamReader(resource.getInputStream()));
324+
all = all.replace("\r\n", "\n");
324325
String[] macros = StringUtils.delimitedListToStringArray(all, "\n\n");
325326
for (String macro : macros) {
326327
if (macro.startsWith(name)) {

spring-webmvc/src/test/java/org/springframework/web/servlet/view/json/MappingJackson2JsonViewTests.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -156,7 +156,7 @@ public void renderWithPrettyPrint() throws Exception {
156156
view.setPrettyPrint(true);
157157
view.render(model, request, response);
158158

159-
String result = response.getContentAsString();
159+
String result = response.getContentAsString().replace("\r\n", "\n");
160160
assertTrue("Pretty printing not applied:\n" + result, result.startsWith("{\n \"foo\" : {\n "));
161161

162162
validateResult();

spring-webmvc/src/test/java/org/springframework/web/servlet/view/json/MappingJacksonJsonViewTests.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -149,7 +149,7 @@ public void renderWithPrettyPrint() throws Exception {
149149
view.setPrettyPrint(true);
150150
view.render(model, request, response);
151151

152-
String result = response.getContentAsString();
152+
String result = response.getContentAsString().replace("\r\n", "\n");
153153
assertTrue("Pretty printing not applied:\n" + result, result.startsWith("{\n \"foo\" : {\n "));
154154

155155
validateResult();

spring-webmvc/src/test/java/org/springframework/web/servlet/view/velocity/VelocityRenderTests.java

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2002-2007 the original author or authors.
2+
* Copyright 2002-2012 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -53,7 +53,7 @@ public class VelocityRenderTests {
5353
private MockHttpServletRequest request;
5454

5555
private MockHttpServletResponse response;
56-
56+
5757
@Rule
5858
public ExpectedException thrown = ExpectedException.none();
5959

@@ -95,12 +95,12 @@ public void testSimpleRender() throws Exception {
9595
Map<String,Object> model = new HashMap<String,Object>();
9696
model.put("command", new TestBean("juergen", 99));
9797
view.render(model, request, response);
98-
assertEquals("\nNAME\njuergen\n", response.getContentAsString());
98+
assertEquals("\nNAME\njuergen\n", response.getContentAsString().replace("\r\n", "\n"));
9999

100100
}
101101

102102
@Test
103-
@Ignore // This works with Velocity 1.6.2
103+
@Ignore // This works with Velocity 1.6.2
104104
public void testSimpleRenderWithError() throws Exception {
105105

106106
thrown.expect(NestedServletException.class);
@@ -111,10 +111,10 @@ public boolean matchesSafely(Exception item) {
111111
}
112112
public void describeTo(Description description) {
113113
description.appendText("exception has cause of MethodInvocationException");
114-
114+
115115
}
116-
});
117-
116+
});
117+
118118
VelocityConfigurer vc = new VelocityConfigurer();
119119
vc.setPreferFileSystemAccess(false);
120120
vc.setVelocityPropertiesMap(Collections.<String,Object>singletonMap("runtime.references.strict", "true"));
@@ -143,10 +143,10 @@ public boolean matchesSafely(Exception item) {
143143
}
144144
public void describeTo(Description description) {
145145
description.appendText("exception has cause of IOException");
146-
146+
147147
}
148-
});
149-
148+
});
149+
150150
VelocityConfigurer vc = new VelocityConfigurer();
151151
vc.setPreferFileSystemAccess(false);
152152
vc.setVelocityPropertiesMap(Collections.<String,Object>singletonMap("runtime.references.strict", "true"));

src/test/java/org/springframework/scheduling/annotation/ScheduledAndTransactionalAnnotationIntegrationTests.java

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2002-2011 the original author or authors.
2+
* Copyright 2002-2012 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -84,7 +84,7 @@ public void succeedsWhenJdkProxyAndScheduledMethodIsPresentOnInterface() throws
8484
ctx.register(Config.class, JdkProxyTxConfig.class, RepoConfigB.class);
8585
ctx.refresh();
8686

87-
Thread.sleep(10); // allow @Scheduled method to be called several times
87+
Thread.sleep(30); // allow @Scheduled method to be called several times
8888

8989
MyRepositoryWithScheduledMethod repository = ctx.getBean(MyRepositoryWithScheduledMethod.class);
9090
CallCountingTransactionManager txManager = ctx.getBean(CallCountingTransactionManager.class);
@@ -179,4 +179,5 @@ public int getInvocationCount() {
179179
return this.count.get();
180180
}
181181
}
182-
}
182+
}
183+

0 commit comments

Comments
 (0)