summaryrefslogtreecommitdiffstats
path: root/sonar-server
diff options
context:
space:
mode:
Diffstat (limited to 'sonar-server')
-rw-r--r--sonar-server/src/main/java/org/sonar/server/platform/ServerImpl.java55
-rw-r--r--sonar-server/src/main/java/org/sonar/server/plugins/PluginDeployer.java4
-rw-r--r--sonar-server/src/main/resources/build.properties2
-rw-r--r--sonar-server/src/test/java/org/sonar/server/platform/ServerImplTest.java20
-rw-r--r--sonar-server/src/test/resources/org/sonar/server/platform/ServerImplTest/build.properties2
5 files changed, 55 insertions, 28 deletions
diff --git a/sonar-server/src/main/java/org/sonar/server/platform/ServerImpl.java b/sonar-server/src/main/java/org/sonar/server/platform/ServerImpl.java
index dfec05e9002..fc01c7a7279 100644
--- a/sonar-server/src/main/java/org/sonar/server/platform/ServerImpl.java
+++ b/sonar-server/src/main/java/org/sonar/server/platform/ServerImpl.java
@@ -20,8 +20,11 @@
package org.sonar.server.platform;
import com.google.common.annotations.VisibleForTesting;
+import com.google.common.base.Joiner;
import org.apache.commons.io.IOUtils;
import org.apache.commons.lang.StringUtils;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
import org.sonar.api.CoreProperties;
import org.sonar.api.config.Settings;
import org.sonar.api.platform.Server;
@@ -33,32 +36,41 @@ import java.util.Date;
import java.util.Properties;
public final class ServerImpl extends Server {
+ private static final Logger LOG = LoggerFactory.getLogger(ServerImpl.class);
+ private final Settings settings;
+ private final Date startedAt;
+ private final String buildProperties;
+ private final String pomProperties;
private String id;
private String version;
- private final Date startedAt;
- private Settings settings;
- private final String manifest;
+ private String implementationBuild;
public ServerImpl(Settings settings) {
- this(settings, "/META-INF/maven/org.codehaus.sonar/sonar-plugin-api/pom.properties");
+ this(settings, "/build.properties", "/META-INF/maven/org.codehaus.sonar/sonar-plugin-api/pom.properties");
}
@VisibleForTesting
- ServerImpl(Settings settings, String manifest) {
+ ServerImpl(Settings settings, String buildProperties, String pomProperties) {
this.settings = settings;
this.startedAt = new Date();
- this.manifest = manifest;
+ this.buildProperties = buildProperties;
+ this.pomProperties = pomProperties;
}
public void start() {
try {
id = new SimpleDateFormat("yyyyMMddHHmmss").format(startedAt);
- version = loadVersionFromManifest(manifest);
+
+ version = read(pomProperties).getProperty("version", "");
+ implementationBuild = read(buildProperties).getProperty("Implementation-Build");
+
if (StringUtils.isBlank(version)) {
throw new ServerStartException("Unknown Sonar version");
}
+ LOG.info("Sonar {}", Joiner.on(" / ").skipNulls().join("Server", version, implementationBuild));
+
} catch (IOException e) {
throw new ServerStartException("Can not load metadata", e);
}
@@ -79,31 +91,30 @@ public final class ServerImpl extends Server {
return version;
}
+ public String getImplementationBuild() {
+ return implementationBuild;
+ }
+
@Override
public Date getStartedAt() {
return startedAt;
}
- private String loadVersionFromManifest(String pomFilename) throws IOException {
- InputStream pomFileStream = getClass().getResourceAsStream(pomFilename);
- try {
- return readVersion(pomFileStream);
+ private static Properties read(String filename) throws IOException {
+ Properties properties = new Properties();
+ InputStream stream = null;
+ try {
+ stream = ServerImpl.class.getResourceAsStream(filename);
+ if (stream != null) {
+ properties.load(stream);
+ }
} finally {
- IOUtils.closeQuietly(pomFileStream);
+ IOUtils.closeQuietly(stream);
}
- }
- protected static String readVersion(InputStream pomFileStream) throws IOException {
- String result = null;
- if (pomFileStream != null) {
- Properties pomProp = new Properties();
- pomProp.load(pomFileStream);
- result = pomProp.getProperty("version");
- }
- return StringUtils.defaultIfEmpty(result, "");
+ return properties;
}
-
@Override
public String getURL() {
return null;
diff --git a/sonar-server/src/main/java/org/sonar/server/plugins/PluginDeployer.java b/sonar-server/src/main/java/org/sonar/server/plugins/PluginDeployer.java
index 775408ca64c..6a00e387275 100644
--- a/sonar-server/src/main/java/org/sonar/server/plugins/PluginDeployer.java
+++ b/sonar-server/src/main/java/org/sonar/server/plugins/PluginDeployer.java
@@ -19,6 +19,8 @@
*/
package org.sonar.server.plugins;
+import com.google.common.base.Joiner;
+
import com.google.common.base.Preconditions;
import com.google.common.collect.Lists;
import com.google.common.collect.Maps;
@@ -190,7 +192,7 @@ public class PluginDeployer implements ServerComponent {
}
private void deploy(DefaultPluginMetadata plugin) {
- LOG.debug("Deploy plugin " + plugin);
+ LOG.info("Deploy plugin {}", Joiner.on(" / ").skipNulls().join(plugin.getName(), plugin.getVersion(), plugin.getImplementationBuild()));
Preconditions.checkState(plugin.isCompatibleWith(server.getVersion()),
"Plugin %s needs a more recent version of Sonar than %s. At least %s is expected",
diff --git a/sonar-server/src/main/resources/build.properties b/sonar-server/src/main/resources/build.properties
new file mode 100644
index 00000000000..8c9958a7711
--- /dev/null
+++ b/sonar-server/src/main/resources/build.properties
@@ -0,0 +1,2 @@
+Implementation-Build=${buildNumber}
+Build-Time=${timestamp} \ No newline at end of file
diff --git a/sonar-server/src/test/java/org/sonar/server/platform/ServerImplTest.java b/sonar-server/src/test/java/org/sonar/server/platform/ServerImplTest.java
index 51a6df8c7fb..ced9e9d6925 100644
--- a/sonar-server/src/test/java/org/sonar/server/platform/ServerImplTest.java
+++ b/sonar-server/src/test/java/org/sonar/server/platform/ServerImplTest.java
@@ -35,7 +35,7 @@ public class ServerImplTest {
@Test
public void alwaysReturnTheSameValues() {
- ServerImpl server = new ServerImpl(new Settings(), "/org/sonar/server/platform/ServerImplTest/pom-with-version.properties");
+ ServerImpl server = new ServerImpl(new Settings(), "", "/org/sonar/server/platform/ServerImplTest/pom-with-version.properties");
server.start();
assertThat(server.getId()).isNotNull();
@@ -50,18 +50,28 @@ public class ServerImplTest {
@Test
public void getVersionFromFile() {
- ServerImpl server = new ServerImpl(new Settings(), "/org/sonar/server/platform/ServerImplTest/pom-with-version.properties");
+ ServerImpl server = new ServerImpl(new Settings(), "", "/org/sonar/server/platform/ServerImplTest/pom-with-version.properties");
server.start();
assertThat(server.getVersion()).isEqualTo("1.0");
}
@Test
+ public void getImplementationBuildFromManifest() {
+ ServerImpl server = new ServerImpl(new Settings(),
+ "/org/sonar/server/platform/ServerImplTest/build.properties",
+ "/org/sonar/server/platform/ServerImplTest/pom-with-version.properties");
+ server.start();
+
+ assertThat(server.getImplementationBuild()).isEqualTo("0b9545a8b74aca473cb776275be4dc93a327c363");
+ }
+
+ @Test
public void testFileWithNoVersion() {
exception.expect(ServerStartException.class);
exception.expectMessage("Unknown Sonar version");
- ServerImpl server = new ServerImpl(new Settings(), "/org/sonar/server/platform/ServerImplTest/pom-without-version.properties");
+ ServerImpl server = new ServerImpl(new Settings(), "", "/org/sonar/server/platform/ServerImplTest/pom-without-version.properties");
server.start();
}
@@ -70,7 +80,7 @@ public class ServerImplTest {
exception.expect(ServerStartException.class);
exception.expectMessage("Unknown Sonar version");
- ServerImpl server = new ServerImpl(new Settings(), "/org/sonar/server/platform/ServerImplTest/pom-with-empty-version.properties");
+ ServerImpl server = new ServerImpl(new Settings(), "", "/org/sonar/server/platform/ServerImplTest/pom-with-empty-version.properties");
server.start();
}
@@ -79,7 +89,7 @@ public class ServerImplTest {
exception.expect(ServerStartException.class);
exception.expectMessage("Unknown Sonar version");
- ServerImpl server = new ServerImpl(new Settings(), "/org/sonar/server/platform/ServerImplTest/unknown-file.properties");
+ ServerImpl server = new ServerImpl(new Settings(), "", "/org/sonar/server/platform/ServerImplTest/unknown-file.properties");
server.start();
}
diff --git a/sonar-server/src/test/resources/org/sonar/server/platform/ServerImplTest/build.properties b/sonar-server/src/test/resources/org/sonar/server/platform/ServerImplTest/build.properties
new file mode 100644
index 00000000000..230f3ae8907
--- /dev/null
+++ b/sonar-server/src/test/resources/org/sonar/server/platform/ServerImplTest/build.properties
@@ -0,0 +1,2 @@
+Implementation-Build=0b9545a8b74aca473cb776275be4dc93a327c363
+Build-Time=1342455258749 \ No newline at end of file