diff options
author | Simon Brandhof <simon.brandhof@gmail.com> | 2013-10-08 13:14:41 +0200 |
---|---|---|
committer | Simon Brandhof <simon.brandhof@gmail.com> | 2013-10-08 13:14:50 +0200 |
commit | 239afbb948856efbe316f1d240af4480a12c9fea (patch) | |
tree | bed3a55bfc90b83ad8bf6643522d171591f28907 /sonar-application | |
parent | 1cf8de6ee2554c969ee34efe9856c453b247e1d6 (diff) | |
download | sonarqube-239afbb948856efbe316f1d240af4480a12c9fea.tar.gz sonarqube-239afbb948856efbe316f1d240af4480a12c9fea.zip |
Ability to enable Rails development mode with sonar.web.dev=true
Diffstat (limited to 'sonar-application')
4 files changed, 52 insertions, 2 deletions
diff --git a/sonar-application/src/main/java/org/sonar/application/Props.java b/sonar-application/src/main/java/org/sonar/application/Props.java index a3d1a8b27e2..f720553c18a 100644 --- a/sonar-application/src/main/java/org/sonar/application/Props.java +++ b/sonar-application/src/main/java/org/sonar/application/Props.java @@ -47,6 +47,11 @@ class Props { return s == null ? defaultValue : s; } + boolean booleanOf(String key) { + String s = of(key); + return s != null && Boolean.parseBoolean(s); + } + Integer intOf(String key) { String s = of(key); if (s != null && !"".equals(s)) { diff --git a/sonar-application/src/main/java/org/sonar/application/Webapp.java b/sonar-application/src/main/java/org/sonar/application/Webapp.java index d8c54deb512..5e21d4cb923 100644 --- a/sonar-application/src/main/java/org/sonar/application/Webapp.java +++ b/sonar-application/src/main/java/org/sonar/application/Webapp.java @@ -29,12 +29,21 @@ class Webapp { try { Context context = tomcat.addWebapp(ctx, env.file("web").getAbsolutePath()); context.setConfigFile(env.file("web/META-INF/context.xml").toURI().toURL()); - context.addParameter("rails.env", "production"); - context.addParameter("jruby.max.runtimes", "1"); + configureRailsMode(props, context); context.setJarScanner(new NullJarScanner()); } catch (Exception e) { throw new IllegalStateException("Fail to configure webapp", e); } } + + static void configureRailsMode(Props props, Context context) { + if (props.booleanOf("sonar.web.dev")) { + context.addParameter("rails.env", "development"); + context.addParameter("jruby.max.runtimes", "3"); + } else { + context.addParameter("rails.env", "production"); + context.addParameter("jruby.max.runtimes", "1"); + } + } } diff --git a/sonar-application/src/test/java/org/sonar/application/PropsTest.java b/sonar-application/src/test/java/org/sonar/application/PropsTest.java index 678f8933b80..f6c1f2ece01 100644 --- a/sonar-application/src/test/java/org/sonar/application/PropsTest.java +++ b/sonar-application/src/test/java/org/sonar/application/PropsTest.java @@ -73,6 +73,18 @@ public class PropsTest { } @Test + public void booleanOf() throws Exception { + Properties p = new Properties(); + p.setProperty("foo", "True"); + p.setProperty("bar", "false"); + Props props = new Props(p); + + assertThat(props.booleanOf("foo")).isTrue(); + assertThat(props.booleanOf("bar")).isFalse(); + assertThat(props.booleanOf("unknown")).isFalse(); + } + + @Test public void load_file_and_system_properties() throws Exception { Env env = mock(Env.class); File propsFile = new File(getClass().getResource("/org/sonar/application/PropsTest/sonar.properties").toURI()); diff --git a/sonar-application/src/test/java/org/sonar/application/WebappTest.java b/sonar-application/src/test/java/org/sonar/application/WebappTest.java index 8bc39746308..0e0dd904a1c 100644 --- a/sonar-application/src/test/java/org/sonar/application/WebappTest.java +++ b/sonar-application/src/test/java/org/sonar/application/WebappTest.java @@ -19,6 +19,7 @@ */ package org.sonar.application; +import org.apache.catalina.Context; import org.apache.catalina.startup.Tomcat; import org.junit.Rule; import org.junit.Test; @@ -50,6 +51,29 @@ public class WebappTest { } catch (IllegalStateException e) { assertThat(e).hasMessage("Fail to configure webapp"); } + } + + @Test + public void configure_dev_mode() throws Exception { + Props props = mock(Props.class); + when(props.booleanOf("sonar.web.dev")).thenReturn(true); + Context context = mock(Context.class); + + Webapp.configureRailsMode(props, context); + + verify(context).addParameter("jruby.max.runtimes", "3"); + verify(context).addParameter("rails.env", "development"); + } + + @Test + public void configure_production_mode() throws Exception { + Props props = mock(Props.class); + when(props.booleanOf("sonar.web.dev")).thenReturn(false); + Context context = mock(Context.class); + + Webapp.configureRailsMode(props, context); + verify(context).addParameter("jruby.max.runtimes", "1"); + verify(context).addParameter("rails.env", "production"); } } |