Author: gnodet
Date: Wed Jan 21 01:25:55 2009
New Revision: 736272
URL: http://svn.apache.org/viewvc?rev=736272&view=rev
Log:
SMX4KNL-152: extract version from resources and allow displaying the version of
the application emmbedding the kernel
Modified:
servicemix/smx4/kernel/trunk/etc/config.properties
servicemix/smx4/kernel/trunk/gshell/gshell-core/pom.xml
servicemix/smx4/kernel/trunk/gshell/gshell-core/src/main/java/org/apache/servicemix/kernel/gshell/core/ApplicationImpl.java
servicemix/smx4/kernel/trunk/gshell/gshell-core/src/main/java/org/apache/servicemix/kernel/gshell/core/ServiceMixBranding.java
servicemix/smx4/kernel/trunk/gshell/gshell-core/src/main/java/org/apache/servicemix/kernel/gshell/core/commands/InfoAction.java
servicemix/smx4/kernel/trunk/gshell/gshell-core/src/main/resources/META-INF/spring/gshell.xml
servicemix/smx4/kernel/trunk/gshell/gshell-core/src/test/java/org/apache/servicemix/kernel/gshell/core/Test.java
Modified: servicemix/smx4/kernel/trunk/etc/config.properties
URL:
http://svn.apache.org/viewvc/servicemix/smx4/kernel/trunk/etc/config.properties?rev=736272&r1=736271&r2=736272&view=diff
==============================================================================
--- servicemix/smx4/kernel/trunk/etc/config.properties (original)
+++ servicemix/smx4/kernel/trunk/etc/config.properties Wed Jan 21 01:25:55 2009
@@ -26,6 +26,7 @@
org.osgi.service.url; version=1.0.0, \
org.apache.servicemix.kernel.main.spi; version=1.0.0, \
org.apache.servicemix.kernel.jaas.boot, \
+ org.apache.servicemix.kernel.version, \
${jre-${java.specification.version}}
org.osgi.framework.bootdelegation=sun.*,com.sun.management*,
Modified: servicemix/smx4/kernel/trunk/gshell/gshell-core/pom.xml
URL:
http://svn.apache.org/viewvc/servicemix/smx4/kernel/trunk/gshell/gshell-core/pom.xml?rev=736272&r1=736271&r2=736272&view=diff
==============================================================================
--- servicemix/smx4/kernel/trunk/gshell/gshell-core/pom.xml (original)
+++ servicemix/smx4/kernel/trunk/gshell/gshell-core/pom.xml Wed Jan 21 01:25:55
2009
@@ -50,6 +50,7 @@
jline*,
org.apache.ivy*;resolution:=optional,
org.apache.servicemix.kernel.jaas.config;resolution:=optional,
+ org.apache.servicemix.kernel.version;resolution:=optional,
org.apache.servicemix.kernel.main.spi;resolution:=optional;version="1.0.0",
com.thoughtworks.xstream*;resolution:=optional,
junit.framework*;resolution:=optional,
Modified:
servicemix/smx4/kernel/trunk/gshell/gshell-core/src/main/java/org/apache/servicemix/kernel/gshell/core/ApplicationImpl.java
URL:
http://svn.apache.org/viewvc/servicemix/smx4/kernel/trunk/gshell/gshell-core/src/main/java/org/apache/servicemix/kernel/gshell/core/ApplicationImpl.java?rev=736272&r1=736271&r2=736272&view=diff
==============================================================================
---
servicemix/smx4/kernel/trunk/gshell/gshell-core/src/main/java/org/apache/servicemix/kernel/gshell/core/ApplicationImpl.java
(original)
+++
servicemix/smx4/kernel/trunk/gshell/gshell-core/src/main/java/org/apache/servicemix/kernel/gshell/core/ApplicationImpl.java
Wed Jan 21 01:25:55 2009
@@ -19,6 +19,8 @@
import java.io.File;
import java.io.IOException;
import java.net.InetAddress;
+import java.net.URL;
+import java.util.Properties;
import org.apache.geronimo.gshell.application.Application;
import org.apache.geronimo.gshell.application.ClassPath;
@@ -27,20 +29,45 @@
import org.apache.geronimo.gshell.application.model.ApplicationModel;
import org.apache.geronimo.gshell.artifact.Artifact;
-public class ApplicationImpl implements Application {
+import org.springframework.beans.factory.InitializingBean;
+
+public class ApplicationImpl implements Application, InitializingBean {
+
+ private static final String EMBEDDED_PROPS =
"org/apache/servicemix/kernel/version/embedded.properties";
+ private static final String SERVICEMIX_VERSION
="org/apache/servicemix/kernel/gshell/core/servicemix-version.properties";
+ private static final String VERSION_PROPERTY = "version";
private String id;
private IO io;
private ApplicationModel model;
private Variables variables;
private InetAddress localHost;
- private File homeDir;
+ private File homeDir;
+ private URL embeddedResource = null;
public ApplicationImpl() throws Exception {
this.localHost = InetAddress.getLocalHost();
- this.homeDir = detectHomeDir();
+ this.homeDir = detectHomeDir();
+ }
+
+ public void afterPropertiesSet() throws Exception {
+ Properties props = new Properties();
+
props.load(getClass().getClassLoader().getResourceAsStream(SERVICEMIX_VERSION));
+ String kernelVersion = props.getProperty(VERSION_PROPERTY);
+ this.model.setVersion(kernelVersion);
+ ServiceMixBranding smxBranding = (ServiceMixBranding)
this.model.getBranding();
+ smxBranding.setVersion(kernelVersion);
+
+ if (this.getClass().getClassLoader().getResource(EMBEDDED_PROPS) !=
null) {
+ embeddedResource =
this.getClass().getClassLoader().getResource(EMBEDDED_PROPS);
+ smxBranding.setEmbeddedResource(embeddedResource);
+ }
}
-
+
+ public URL getEmbeddedResource() {
+ return embeddedResource;
+ }
+
public String getId() {
return id;
}
@@ -113,4 +140,5 @@
return dir;
}
+
}
Modified:
servicemix/smx4/kernel/trunk/gshell/gshell-core/src/main/java/org/apache/servicemix/kernel/gshell/core/ServiceMixBranding.java
URL:
http://svn.apache.org/viewvc/servicemix/smx4/kernel/trunk/gshell/gshell-core/src/main/java/org/apache/servicemix/kernel/gshell/core/ServiceMixBranding.java?rev=736272&r1=736271&r2=736272&view=diff
==============================================================================
---
servicemix/smx4/kernel/trunk/gshell/gshell-core/src/main/java/org/apache/servicemix/kernel/gshell/core/ServiceMixBranding.java
(original)
+++
servicemix/smx4/kernel/trunk/gshell/gshell-core/src/main/java/org/apache/servicemix/kernel/gshell/core/ServiceMixBranding.java
Wed Jan 21 01:25:55 2009
@@ -16,17 +16,32 @@
*/
package org.apache.servicemix.kernel.gshell.core;
+import java.io.FileNotFoundException;
+import java.io.IOException;
+import java.io.InputStream;
import java.io.PrintWriter;
import java.io.StringWriter;
+import java.net.URL;
+import java.util.Properties;
+import java.util.StringTokenizer;
import org.apache.geronimo.gshell.ansi.AnsiBuffer;
import org.apache.geronimo.gshell.ansi.AnsiCode;
import org.apache.geronimo.gshell.ansi.AnsiRenderWriter;
import org.apache.geronimo.gshell.application.model.Branding;
-public class ServiceMixBranding extends Branding {
-
- private static final String[] BANNER = {
+public class ServiceMixBranding extends Branding {
+
+ private String prompt;
+ private String[] banner;
+ private String displayName;
+ private String displayVersion;
+ private String displayLocation;
+ private String applicationName;
+ private String applicationVersion;
+ private String applicationLocation;
+
+ private String[] kernelBanner = {
" ____ _ __ __ _ ",
"/ ___| ___ _ ____ _(_) ___ ___| \\/ (_)_ __",
"\\___ \\ / _ \\ '__\\ \\ / / |/ __/ _ \\ |\\/| | \\ \\/ /",
@@ -34,57 +49,140 @@
"|____/ \\___|_| \\_/ |_|\\___\\___|_| |_|_/_/\\_\\",
};
- private String prompt;
+ public ServiceMixBranding() {
+ banner = kernelBanner;
+ displayName = "Servicemix Kernel";
+ displayLocation = "http://servicemix.apache.org/kernel/";
+ }
+
+ public void setEmbeddedResource(URL embeddedResource) {
+ Properties brandProps = loadPropertiesFile(embeddedResource);
+ String brandBanner = brandProps.getProperty("banner");
+ int i = 0;
+ char quot = '"';
+
+ StringTokenizer st = new StringTokenizer(brandBanner, ",");
+ banner = new String[st.countTokens()];
+
+ while (st.hasMoreTokens()) {
+ banner[i] = st.nextToken();
+ banner[i] = banner[i].substring(1, banner[i].lastIndexOf(quot));
+ i++;
+ }
+ applicationName = brandProps.getProperty("application.name");
+ applicationVersion = brandProps.getProperty("application.version");
+ applicationLocation = brandProps.getProperty("application.location");
+ }
+
public String getName() {
return "servicemix";
}
-
- public String getDisplayName() {
- return "ServiceMix";
+
+ public String getDisplayName() {
+ return displayName;
+ }
+
+ public void setVersion(String version) {
+ displayVersion = version;
+ }
+
+ public String getVersion() {
+ return displayVersion;
+ }
+
+ public String getApplicationName() {
+ return applicationName;
}
+ public String getApplicationVersion() {
+ return applicationVersion;
+ }
+
public String getProgramName() {
throw new UnsupportedOperationException();
}
+ public String getPrompt() {
+ return prompt;
+ }
+
+ public void setPrompt(String prompt) {
+ this.prompt = prompt;
+ }
+
public String getAboutMessage() {
StringWriter writer = new StringWriter();
PrintWriter out = new AnsiRenderWriter(writer);
- out.println("For information about @|cyan ServiceMix|, visit:");
- out.println(" @|bold http://servicemix.apache.org| ");
+ out.println("For information about @|cyan " + displayName + "|,
visit:");
+ out.println(" @|bold " + displayLocation + "| ");
out.flush();
- return writer.toString();
- }
+ if (applicationName != null && applicationVersion != null) {
+ out.println();
+ out.println(applicationName + " " + applicationVersion);
+ out.println();
+ if (applicationLocation != null) {
+ out.println("For information about @|cyan " + applicationName
+ "|, visit:");
+ out.println(" @|bold " + applicationLocation + "| ");
+ out.flush();
+ }
+ }
- public String getWelcomeMessage() {
+ return writer.toString();
+ }
+
+ public String getWelcomeMessage() {
StringWriter writer = new StringWriter();
PrintWriter out = new AnsiRenderWriter(writer);
- AnsiBuffer buff = new AnsiBuffer();
-
- for (String line : BANNER) {
+
+ AnsiBuffer buff = new AnsiBuffer();
+
+ for (String line : banner) {
buff.attrib(line, AnsiCode.CYAN);
out.println(buff);
}
out.println();
- // TODO: get version
- out.println(" @|bold ServiceMix| (" + "1.1.0-SNAPSHOT" + ")");
+ out.println(" @|bold " + displayName + "| (" + displayVersion + ")");
+ if (applicationName != null && applicationVersion != null) {
+ out.println(" @|bold " + applicationName + "| (" +
applicationVersion + ")");
+ }
out.println();
out.println("Type '@|bold help|' for more information.");
-
out.flush();
return writer.toString();
}
-
- public String getPrompt() {
- return prompt;
- }
-
- public void setPrompt(String prompt) {
- this.prompt = prompt;
+
+ private static Properties loadPropertiesFile(URL brandPropURL) {
+ // Read the properties file.
+ Properties brandProps = new Properties();
+ InputStream is = null;
+ try {
+ is = brandPropURL.openConnection().getInputStream();
+ brandProps.load(is);
+ is.close();
+ }
+ catch (FileNotFoundException ex) {
+ // Ignore file not found.
+ }
+ catch (Exception ex) {
+ System.err.println(
+ "Error loading embedded properties from " + brandPropURL);
+ System.err.println("ServicemixBranding: " + ex);
+ try {
+ if (is != null) is.close();
+ }
+ catch (IOException ex2) {
+ // Nothing we can do.
+ }
+ return null;
+ }
+
+ return brandProps;
}
+
}
+
Modified:
servicemix/smx4/kernel/trunk/gshell/gshell-core/src/main/java/org/apache/servicemix/kernel/gshell/core/commands/InfoAction.java
URL:
http://svn.apache.org/viewvc/servicemix/smx4/kernel/trunk/gshell/gshell-core/src/main/java/org/apache/servicemix/kernel/gshell/core/commands/InfoAction.java?rev=736272&r1=736271&r2=736272&view=diff
==============================================================================
---
servicemix/smx4/kernel/trunk/gshell/gshell-core/src/main/java/org/apache/servicemix/kernel/gshell/core/commands/InfoAction.java
(original)
+++
servicemix/smx4/kernel/trunk/gshell/gshell-core/src/main/java/org/apache/servicemix/kernel/gshell/core/commands/InfoAction.java
Wed Jan 21 01:25:55 2009
@@ -41,10 +41,11 @@
import org.apache.geronimo.gshell.io.IO;
import org.codehaus.plexus.util.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
+import org.apache.servicemix.kernel.gshell.core.ServiceMixBranding;
public class InfoAction implements CommandAction {
- private Branding branding;
+ private ServiceMixBranding branding;
private IO io;
@@ -52,7 +53,7 @@
private NumberFormat fmtI = new DecimalFormat("###,###", new
DecimalFormatSymbols(Locale.ENGLISH));
private NumberFormat fmtD = new DecimalFormat("###,##0.000", new
DecimalFormatSymbols(Locale.ENGLISH));
- public InfoAction(Branding branding) {
+ public InfoAction(ServiceMixBranding branding) {
this.branding = branding;
}
@@ -73,7 +74,11 @@
io.out.println("ServiceMix");
printValue("ServiceMix home", maxNameLen,
System.getProperty("servicemix.home"));
printValue("ServiceMix base", maxNameLen,
System.getProperty("servicemix.base"));
- printValue("ServiceMix version", maxNameLen,
branding.getParent().getVersion());
+ printValue("ServiceMix kernel version", maxNameLen,
branding.getParent().getVersion());
+
+ if (branding.getApplicationName() != null &&
branding.getApplicationVersion() != null) {
+ printValue(branding.getApplicationName() + " version", maxNameLen,
branding.getApplicationVersion());
+ }
io.out.println();
io.out.println("JVM");
Modified:
servicemix/smx4/kernel/trunk/gshell/gshell-core/src/main/resources/META-INF/spring/gshell.xml
URL:
http://svn.apache.org/viewvc/servicemix/smx4/kernel/trunk/gshell/gshell-core/src/main/resources/META-INF/spring/gshell.xml?rev=736272&r1=736271&r2=736272&view=diff
==============================================================================
---
servicemix/smx4/kernel/trunk/gshell/gshell-core/src/main/resources/META-INF/spring/gshell.xml
(original)
+++
servicemix/smx4/kernel/trunk/gshell/gshell-core/src/main/resources/META-INF/spring/gshell.xml
Wed Jan 21 01:25:55 2009
@@ -46,8 +46,6 @@
<property name="io" ref="io"/>
<property name="model">
<bean
class="org.apache.geronimo.gshell.application.model.ApplicationModel">
- <!-- TODO: fix version -->
- <property name="version" value="1.1.0"/>
<property name="branding" ref="branding"/>
</bean>
</property>
Modified:
servicemix/smx4/kernel/trunk/gshell/gshell-core/src/test/java/org/apache/servicemix/kernel/gshell/core/Test.java
URL:
http://svn.apache.org/viewvc/servicemix/smx4/kernel/trunk/gshell/gshell-core/src/test/java/org/apache/servicemix/kernel/gshell/core/Test.java?rev=736272&r1=736271&r2=736272&view=diff
==============================================================================
---
servicemix/smx4/kernel/trunk/gshell/gshell-core/src/test/java/org/apache/servicemix/kernel/gshell/core/Test.java
(original)
+++
servicemix/smx4/kernel/trunk/gshell/gshell-core/src/test/java/org/apache/servicemix/kernel/gshell/core/Test.java
Wed Jan 21 01:25:55 2009
@@ -21,11 +21,11 @@
import org.apache.geronimo.gshell.shell.Shell;
import org.apache.geronimo.gshell.application.ApplicationManager;
import org.apache.geronimo.gshell.io.SystemOutputHijacker;
+import org.apache.servicemix.kernel.gshell.core.ServiceMixBranding;
public class Test extends TestCase {
public void test() throws Exception {
-
System.setProperty("startLocalConsole", "true");
System.setProperty("servicemix.name", "root");
@@ -40,4 +40,23 @@
assertNotNull(shell);
shell.execute("help");
}
+
+ public void testBanner() throws Exception {
+ System.setProperty("startLocalConsole", "true");
+ System.setProperty("servicemix.name", "root");
+
+ ClassPathXmlApplicationContext context = new
ClassPathXmlApplicationContext(
+ new String[] { "META-INF/spring/gshell.xml",
+ "META-INF/spring/gshell-vfs.xml",
+ "META-INF/spring/gshell-commands.xml",
+
"org/apache/servicemix/kernel/gshell/core/gshell-test.xml"});
+ ApplicationManager appMgr = (ApplicationManager)
context.getBean("applicationManager");
+ assertNotNull(appMgr);
+ Shell shell = appMgr.create();
+ ServiceMixBranding smxBrandng =
(ServiceMixBranding)appMgr.getApplication().getModel().getBranding();
+ assertNotNull(smxBrandng.getWelcomeMessage());
+ System.out.println(smxBrandng.getWelcomeMessage());
+ assertNotNull(shell);
+ shell.execute("about");
+ }
}