Disable anonymous access to Sonar

By default anonymous access to Sonar is enabled, as well as anonymous access to projects. Minimal effort to disable anonymous access to Sonar, is as follows:

Option 1: Require a user to login when accessing Sonar.
For this go to “Configuration” -> “General Settings” -> “Security”, and set “Force authentication user” to true.
Schermafbeelding 2013-05-10 om 11.51.39

Option 2: Set access for projects.
Default for new projects, access is also set to “Anyone”, this can be disabled via “Configuration” -> “Project Roles”. Now you can set the “Default Roles for New Projects” and “Projects”.

Schermafbeelding 2013-05-10 om 11.53.38

Move “Anyone” to “Ungranted groups”
Schermafbeelding 2013-05-10 om 12.01.30

TimeoutException on ChromeDriver of WebDriver

When you want to run Chrome on WebDriver for your Mac, then according to according to the site http://code.google.com/p/selenium/wiki/ChromeDriver you will need to specify the path to the browser to the following location: “/Applications/Google\ Chrome.app/Contents/MacOS/Google\ Chrome”.

So the Java code for creating a ChromeDriver instance will be:

System.setProperty("webdriver.chrome.driver", "/Applications/Google Chrome.app/Contents/MacOS/Google Chrome");
driver = new ChromeDriver();

When trying to run this I got the following exception.

org.openqa.selenium.remote.UnreachableBrowserException: Could not start a new session. Possible causes are invalid address of the remote server or browser start-up failure.
Build info: version: '2.31.0', revision: '1bd294d185a80fa4206dfeab80ba773c04ac33c0', time: '2013-02-27 13:51:26'
System info: os.name: 'Mac OS X', os.arch: 'x86_64', os.version: '10.8.3', java.version: '1.6.0_45'
Driver info: driver.version: ChromeDriver
 at org.openqa.selenium.remote.RemoteWebDriver.execute(RemoteWebDriver.java:548)
 at org.openqa.selenium.remote.RemoteWebDriver.startSession(RemoteWebDriver.java:216)
 at org.openqa.selenium.remote.RemoteWebDriver.<init>(RemoteWebDriver.java:111)
 at org.openqa.selenium.remote.RemoteWebDriver.<init>(RemoteWebDriver.java:115)
 at org.openqa.selenium.chrome.ChromeDriver.<init>(ChromeDriver.java:161)
 at org.openqa.selenium.chrome.ChromeDriver.<init>(ChromeDriver.java:107)
 at com.gjdb.webdriver.WebDriverRunner.doSetUp(WebDriverRunner.java:58)
 at com.gjdb.webdriver.WebDriverRunner.<init>(WebDriverRunner.java:46)
 at com.gjdb.webdriver.WebDriverRunnerTest.setup(WebDriverRunnerTest.java:14)
 at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
 at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
 at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
 at org.junit.runners.model.FrameworkMethod$1.runReflectiveCall(FrameworkMethod.java:44)
 at org.junit.internal.runners.model.ReflectiveCallable.run(ReflectiveCallable.java:15)
 at org.junit.runners.model.FrameworkMethod.invokeExplosively(FrameworkMethod.java:41)
 at org.junit.internal.runners.statements.RunBefores.evaluate(RunBefores.java:27)
 at org.junit.internal.runners.statements.RunAfters.evaluate(RunAfters.java:31)
 at org.junit.runners.BlockJUnit4ClassRunner.runNotIgnored(BlockJUnit4ClassRunner.java:79)
 at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:71)
 at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:49)
 at org.junit.runners.ParentRunner$3.run(ParentRunner.java:193)
 at org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:52)
 at org.junit.runners.ParentRunner.runChildren(ParentRunner.java:191)
 at org.junit.runners.ParentRunner.access$000(ParentRunner.java:42)
 at org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:184)
 at org.junit.runners.ParentRunner.run(ParentRunner.java:236)
 at org.junit.runners.Suite.runChild(Suite.java:128)
 at org.junit.runners.Suite.runChild(Suite.java:24)
 at org.junit.runners.ParentRunner$3.run(ParentRunner.java:193)
 at org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:52)
 at org.junit.runners.ParentRunner.runChildren(ParentRunner.java:191)
 at org.junit.runners.ParentRunner.access$000(ParentRunner.java:42)
 at org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:184)
 at org.junit.runners.ParentRunner.run(ParentRunner.java:236)
 at org.junit.runner.JUnitCore.run(JUnitCore.java:157)
 at com.intellij.junit4.JUnit4IdeaTestRunner.startRunnerWithArgs(JUnit4IdeaTestRunner.java:77)
 at com.intellij.rt.execution.junit.JUnitStarter.prepareStreamsAndStart(JUnitStarter.java:195)
 at com.intellij.rt.execution.junit.JUnitStarter.main(JUnitStarter.java:63)
 at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
 at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
 at com.intellij.rt.execution.application.AppMain.main(AppMain.java:120)
Caused by: org.openqa.selenium.WebDriverException: Timed out waiting for driver server to start.
Build info: version: '2.31.0', revision: '1bd294d185a80fa4206dfeab80ba773c04ac33c0', time: '2013-02-27 13:51:26'
System info: os.name: 'Mac OS X', os.arch: 'x86_64', os.version: '10.8.3', java.version: '1.6.0_45'
Driver info: driver.version: ChromeDriver
 at org.openqa.selenium.remote.service.DriverService.start(DriverService.java:165)
 at org.openqa.selenium.remote.service.DriverCommandExecutor.execute(DriverCommandExecutor.java:62)
 at org.openqa.selenium.remote.RemoteWebDriver.execute(RemoteWebDriver.java:527)
 ... 43 more
Caused by: org.openqa.selenium.net.UrlChecker$TimeoutException: Timed out waiting for [http://localhost:40897/status] to be available after 20002 ms
 at org.openqa.selenium.net.UrlChecker.waitUntilAvailable(UrlChecker.java:104)
 at org.openqa.selenium.remote.service.DriverService.start(DriverService.java:163)
 ... 45 more
Caused by: com.google.common.util.concurrent.UncheckedTimeoutException: java.util.concurrent.TimeoutException
 at com.google.common.util.concurrent.SimpleTimeLimiter.callWithTimeout(SimpleTimeLimiter.java:143)
 at org.openqa.selenium.net.UrlChecker.waitUntilAvailable(UrlChecker.java:79)
 ... 46 more
Caused by: java.util.concurrent.TimeoutException
 at java.util.concurrent.FutureTask$Sync.innerGet(FutureTask.java:228)
 at java.util.concurrent.FutureTask.get(FutureTask.java:91)
 at com.google.common.util.concurrent.SimpleTimeLimiter.callWithTimeout(SimpleTimeLimiter.java:130)
 ... 47 more

This I fixed by using the ChromeDriver. Download your version on http://code.google.com/p/chromedriver/downloads/list, unzip it and use it as followed:

System.setProperty("webdriver.chrome.driver", "<unzip location>/chromedriver");
driver = new ChromeDriver();

Confusing Maven error “Can’t release project due to non released dependencies”

A confusing Maven error. During usage of the mvn release plugin this error suggests that some dependencies can not be resolved. Actual reason is that during the release proces NO snapshot versions or revering to snapshot versions is allowed.

Solution is then also to make a release of all such dependencies. Probable reason for this is that SNAPSHOT versions are mutable in nexus, release versions are not (by default).  So having no SNAPSHOT versions in your released artifact makes the file more consistent.


[INFO] Resuming release from phase 'check-dependency-snapshots'
[INFO] Checking dependencies and plugins for snapshots ...
[INFO] ------------------------------------------------------------------------
[INFO] BUILD FAILURE
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 15.408s
[INFO] Finished at: Fri Mar 01 09:30:02 CET 2013
[INFO] Final Memory: 24M/213M
[INFO] ------------------------------------------------------------------------
[ERROR] Failed to execute goal org.apache.maven.plugins:maven-release-plugin:2.0
:prepare (default-cli) on project <artifact id>: Can't release projec
t due to non released dependencies :
[ERROR] <package>:<artifact id>:war:1
.1.33-SNAPSHOT:compile
[ERROR] <package>:<artifact id>:pom:1.1.3
3-parent-SNAPSHOT
[ERROR] in project '<artifact id>' (<package>:<artifact id>:1.1.33-SNAPSHOT)
[ERROR] -> [Help 1]
[ERROR]
[ERROR] To see the full stack trace of the errors, re-run Maven with the -e swit
ch.
[ERROR] Re-run Maven using the -X switch to enable full debug logging.

Jira and a Reverse proxy

You might have a similar issue: when you want to install Jira, the default port for web servers (80) is already occupied.  Therefore you have to install Jira under a less common port. Due to company restrictions this port might be blocked due to safety reasons.

Solution: setup a reverse proxy. In this example we have Jira running on <example ip>:9004 which we want to make available through http://atlassian.<example>.com/jira

First step is to configure the base url in Jira (“Administration” -> “General Configuration”) to the value of “http://atlassian.<example>.com/jira”

Second step is to configure the apache server [httpd.conf]

LoadModule proxy_http_module /usr/lib/apache2/modules/mod_proxy_http.so
LoadModule headers_module /usr/lib/apache2/modules/mod_headers.so

ProxyPass /jira http://<example ip>:9004/jira
ProxyPassReverse /jira http://<example ip>:9004/jira

Step 3 is to restart the apache server

Now you will see that most functionality of Jira is already available through “http://atlassian.<example>.com/jira”. For example gadgets will not work yet because of the REST interface. Now the following error will be given

com.atlassian.gadgets.dashboard.internal.diagnostics.UrlHostnameMismatchException: Detected URL hostname, '<example ip>', does not match expected hostname, 'atlassian.<example>.nl'
	at com.atlassian.gadgets.dashboard.internal.diagnostics.Diagnostics.checkExpectedHostname(Diagnostics.java:71)
	at com.atlassian.gadgets.dashboard.internal.diagnostics.Diagnostics.check(Diagnostics.java:32)
	at com.atlassian.gadgets.dashboard.internal.diagnostics.DiagnosticsServlet.executeDiagnostics(DiagnosticsServlet.java:93)
	at com.atlassian.gadgets.dashboard.internal.diagnostics.DiagnosticsServlet.doPost(DiagnosticsServlet.java:61)
	at javax.servlet.http.HttpServlet.service(HttpServlet.java:641)
	at javax.servlet.http.HttpServlet.service(HttpServlet.java:722)
	at com.atlassian.plugin.servlet.DelegatingPluginServlet.service(DelegatingPluginServlet.java:42)
	at javax.servlet.http.HttpServlet.service(HttpServlet.java:722)
	at com.atlassian.plugin.servlet.ServletModuleContainerServlet.service(ServletModuleContainerServlet.java:52)
	at javax.servlet.http.HttpServlet.service(HttpServlet.java:722)
	at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:305)

To fix this, one additional step needs to be performed.

Step 4 is to change <jira installation directory>\conf\server.xml in which to add the proxyName and proxyPort attribute

<Connector port="9004" proxyName="atlassian.geertjan.it" proxyPort="80"

and set the path to the value of “jira”

<Context path="/jira" docBase="${catalina.home}/atlassian-jira" reloadable="false" useHttpOnly="true">

Step 5 – the final one – is to restart Jira

Mockito and floating point objects like BigDecimal

Last week I saw a Java project which used mockito. Great! Only point of attention was that it used a BigDecimal object as a key / identifier. So:

when(new BigDecimal(11)).thenReturn("test 1");

This runs fine when the BigDecimal does not have a scale (like in the example). It is different story when a scale is added, for example a currency amount.

when(new BigDecimal(11.78)).thenReturn("test 1");

This uses the default matcher, which then will compare (on the equals()) like:

 11.17999999999992888474774 to 11.78

Ergo; the above when with 11.78 will never return a value. To fix this you can use your own matcher. Use the following code for this:

when(argThat(new CurrencyMatcher(new BigDecimal(11.78))).thenReturn("test 1");

And the CurrencyMatcher class will then be as followed.

class CurrencyMatcher extends ArgumentMatcher {
      BigDecimal bigDecimal;

      public CurrencyMatcher(BigDecimal bigDecimal) {
          this.bigDecimal = bigDecimal;
      }

      public boolean matches(Object bigDecimalB) {
          if(bigDecimalB == null &amp;&amp; bigDecimal != null) {
              return false;
          }

          if(bigDecimalB == null &amp;&amp; bigDecimal == null) {
              return true;
          }

          NumberFormat eurCostFormat = NumberFormat.getCurrencyInstance(Locale.NL);
          return eurCostFormat.format(bigDecimal).equals(eurCostFormat.format(bigDecimalB);
      }