Skip to content

Commit

Permalink
MONDRIAN: Version information is now available, via the new method Mo…
Browse files Browse the repository at this point in the history
…ndrianServer.getVersion().

	Use the version information in the XMLA provider, and tests for that provider.
	Fix the tests I broke when I renamed Type.string to Type.String.

[git-p4: depot-paths = "//open/mondrian/": change = 8653]
  • Loading branch information
julianhyde committed Feb 4, 2007
1 parent 72cb958 commit e2bbdc5
Show file tree
Hide file tree
Showing 12 changed files with 186 additions and 25 deletions.
22 changes: 17 additions & 5 deletions build.xml
Expand Up @@ -4,7 +4,7 @@
== Agreement, available at the following URL:
== http://www.opensource.org/licenses/cpl.html.
== Copyright (C) 2001-2003 Kana Software, Inc.
== Copyright (C) 2001-2006 Julian Hyde and others.
== Copyright (C) 2001-2007 Julian Hyde and others.
== All Rights Reserved.
== You must accept the terms of that agreement to use this software.
-->
Expand All @@ -18,6 +18,7 @@
<property name="Name" value="Mondrian"/>
<property name="name" value="mondrian"/>
<property name="version" value="2.3-dev"/>
<property name="vendor" value="Pentaho"/>

<!--
===================================================================
Expand Down Expand Up @@ -534,7 +535,10 @@ in {mondrian.foodmart.jdbcURL}.">
</target>

<target name="version">
<echo message="Mondrian ${version}" file="VERSION.txt"/>
<echo file="VERSION.txt">Title: ${name}
Version: ${version}
Vendor: ${vendor}
</echo>
</target>

<target name="srczip" depends="version">
Expand Down Expand Up @@ -779,8 +783,8 @@ doc/**/*.xml"

<target name="jar" depends="version,compile,compile.tests">
<mkdir dir="${lib.dir}" />
<zip
zipfile="${jar.file}"
<jar
destfile="${jar.file}"
update="true">
<zipfileset
dir="${classes.dir}"
Expand All @@ -803,7 +807,15 @@ doc/**/*.xml"
LICENSE.html,
README.txt,
VERSION.txt"/>
</zip>
<manifest>
<attribute name="Built-By" value="${user.name}"/>
<section name="mondrian.olap">
<attribute name="Implementation-Title" value="${name}"/>
<attribute name="Implementation-Version" value="${version}"/>
<attribute name="Implementation-Vendor" value="${vendor}"/>
</section>
</manifest>
</jar>
</target>

<target name="xml_schema"
Expand Down
15 changes: 15 additions & 0 deletions src/main/mondrian/olap/MondrianServer.java
Expand Up @@ -53,6 +53,21 @@ public static MondrianServer forConnection(Connection connection) {
* for all cubes in all schemas will be flushed.
*/
public abstract void flushDataCache();

/**
* Returns the version of this MondrianServer.
*/
public abstract MondrianVersion getVersion();

/**
* Description of the version of the server.
*/
public interface MondrianVersion {
/**
* Returns the version string, for example "2.3.0".
*/
String getVersionString();
}
}

// End MondrianServer.java
66 changes: 66 additions & 0 deletions src/main/mondrian/olap/MondrianServerImpl.java
Expand Up @@ -11,6 +11,11 @@

import mondrian.rolap.RolapSchema;

import java.net.URL;
import java.io.IOException;
import java.util.regex.Pattern;
import java.util.regex.Matcher;

/**
* Implementation of {@link MondrianServer}.
*
Expand All @@ -19,13 +24,74 @@
* @since Jun 25, 2006
*/
class MondrianServerImpl extends MondrianServer {
private static MondrianVersion version = null;

public void flushSchemaCache() {
RolapSchema.clearCache();
}

public void flushDataCache() {
// not implemented
}

public MondrianVersion getVersion() {
return getVersionStatic();
}

private static synchronized MondrianVersion getVersionStatic() {
if (version == null) {
final String versionString = loadVersionFile();
version = new MondrianVersion() {
public String getVersionString() {
return versionString;
}
};
}
return version;
}

private static String loadVersionFile() {
// First, try to read the version info from the package. If the classes
// came from a jar, this info will be set from manifest.mf.
Package pakkage = MondrianServerImpl.class.getPackage();
String implementationVersion = pakkage.getImplementationVersion();
if (implementationVersion != null) {
return implementationVersion;
}

// Second, try to read VERSION.txt.
URL resource =
MondrianServerImpl.class.getClassLoader()
.getResource("DefaultRules.xml");
if (resource != null) {
try {
String path = resource.getPath();
String path2 =
Util.replace(
path, "classes/DefaultRules.xml", "VERSION.txt");
URL resource2 =
new URL(
resource.getProtocol(),
resource.getHost(),
path2);
String versionString = Util.readURL(resource2);
Pattern pattern =
Pattern.compile(
"(?s)Title: (.*)\nVersion: (.*)\nVendor: (.*)\n.*");
Matcher matcher = pattern.matcher(versionString);
if (matcher.matches()) {
int groupCount = matcher.groupCount();
String title = matcher.group(1);
String version = matcher.group(2);
String vendor = matcher.group(3);
return version;
}
} catch (IOException e) {
e.printStackTrace();
}
}
return "Unknown version";
}
}

// End MondrianServerImpl.java
14 changes: 14 additions & 0 deletions src/main/mondrian/olap/Util.java
Expand Up @@ -983,6 +983,20 @@ public static <T extends Enum<T>> RuntimeException badValue(
"' in this context");
}

/**
* Masks Mondrian's version number from a string.
*
* @param str String
* @return String with each occurrence of mondrian's version number
* (e.g. "2.3.0.0") replaced with "${mondrianVersion}"
*/
public static String maskVersion(String str) {
MondrianServer.MondrianVersion mondrianVersion =
MondrianServer.forConnection(null).getVersion();
String versionString = mondrianVersion.getVersionString();
return replace(str, versionString, "${mondrianVersion}");
}

public static class ErrorCellValue {
public String toString() {
return "#ERR";
Expand Down
5 changes: 2 additions & 3 deletions src/main/mondrian/xmla/PropertyDefinition.java
Expand Up @@ -12,6 +12,7 @@
package mondrian.xmla;

import mondrian.olap.Util;
import mondrian.olap.MondrianServer;

import java.util.Set;

Expand Down Expand Up @@ -131,13 +132,11 @@ enum PropertyDefinition {
Enumeration.Methods.discover,
"The XML for Analysis Provider name."),

//TODO: the below version string "2.3.0.0" ought to be read at compile
// time from some build property rather than being hard-coded.
ProviderVersion(
RowsetDefinition.Type.String,
null,
Enumeration.Access.Read,
"2.3.0.0",
MondrianServer.forConnection(null).getVersion().getVersionString(),
Enumeration.Methods.discover,
"The version of the Mondrian XMLA Provider"),

Expand Down
68 changes: 60 additions & 8 deletions src/main/mondrian/xmla/RowsetDefinition.java
Expand Up @@ -1223,6 +1223,10 @@ boolean isEnum() {
this == EnumerationArray ||
this == EnumString;
}

String getName() {
return this == String ? "string" : name();
}
}

private static DBType getDBTypeFromProperty(Property prop) {
Expand Down Expand Up @@ -1742,7 +1746,7 @@ public void populate(XmlaResponse response, List<Row> rows) throws XmlaException
Row row = new Row();
row.set(PropertyName.name, propertyDefinition.name());
row.set(PropertyDescription.name, propertyDefinition.description);
row.set(PropertyType.name, propertyDefinition.type);
row.set(PropertyType.name, propertyDefinition.type.getName());
row.set(PropertyAccessType.name, propertyDefinition.access);
row.set(IsRequired.name, false);
row.set(Value.name, propertyDefinition.value);
Expand Down Expand Up @@ -5708,13 +5712,61 @@ static class MdschemaSetsRowset extends Rowset {
super(MDSCHEMA_SETS, request, handler);
}

private static final Column CatalogName = new Column("CATALOG_NAME", Type.String, null, true, true, null);
private static final Column SchemaName = new Column("SCHEMA_NAME", Type.String, null, true, true, null);
private static final Column CubeName = new Column("CUBE_NAME", Type.String, null, true, false, null);
private static final Column SetName = new Column("SET_NAME", Type.String, null, true, false, null);
private static final Column SetCaption = new Column("SET_CAPTION", Type.String, null, true, true, null);
private static final Column Scope = new Column("SCOPE", Type.Integer, null, true, false, null);
private static final Column Description = new Column("DESCRIPTION", Type.String, null, false, true, "A human-readable description of the measure. ");
private static final Column CatalogName =
new Column(
"CATALOG_NAME",
Type.String,
null,
true,
true,
null);
private static final Column SchemaName =
new Column(
"SCHEMA_NAME",
Type.String,
null,
true,
true,
null);
private static final Column CubeName =
new Column(
"CUBE_NAME",
Type.String,
null,
true,
false,
null);
private static final Column SetName =
new Column(
"SET_NAME",
Type.String,
null,
true,
false,
null);
private static final Column SetCaption =
new Column(
"SET_CAPTION",
Type.String,
null,
true,
true,
null);
private static final Column Scope =
new Column(
"SCOPE",
Type.Integer,
null,
true,
false,
null);
private static final Column Description =
new Column("DESCRIPTION",
Type.String,
null,
false,
true,
"A human-readable description of the measure.");

public void populate(XmlaResponse response, List<Row> rows) throws XmlaException {
throw new XmlaException(
Expand Down
3 changes: 2 additions & 1 deletion testsrc/main/mondrian/xmla/XmlaBasicTest.java
Expand Up @@ -567,6 +567,7 @@ protected void doTests(

Document gotDoc = ignoreLastUpdateDate(XmlUtil.parse(bytes));
String gotStr = XmlUtil.toString(gotDoc, true);
gotStr = Util.maskVersion(gotStr);
if (expectedDoc != null) {
String expectedStr = XmlUtil.toString(expectedDoc, true);
if (DEBUG) {
Expand Down Expand Up @@ -594,7 +595,7 @@ protected void doTests(
}
}

private Document ignoreLastUpdateDate(Document document) {
private Document ignoreLastUpdateDate(Document document) {
NodeList elements = document.getElementsByTagName("LAST_SCHEMA_UPDATE");
for (int i = elements.getLength(); i > 0; i--) {
removeNode(elements.item(i-1));
Expand Down
6 changes: 3 additions & 3 deletions testsrc/main/mondrian/xmla/XmlaBasicTest.ref.xml
Expand Up @@ -8918,7 +8918,7 @@
<PropertyType>string</PropertyType>
<PropertyAccessType>Read</PropertyAccessType>
<IsRequired>false</IsRequired>
<Value>2.1.0.0</Value>
<Value>${mondrianVersion}</Value>
</row>
<row>
<PropertyName>StateSupport</PropertyName>
Expand Down Expand Up @@ -8983,10 +8983,10 @@
<row>
<PropertyName>AdvancedFlag</PropertyName>
<PropertyDescription/>
<PropertyType>string</PropertyType>
<PropertyType>Boolean</PropertyType>
<PropertyAccessType>Read</PropertyAccessType>
<IsRequired>false</IsRequired>
<Value/>
<Value>false</Value>
</row>
</root>
</xmla:return>
Expand Down
3 changes: 2 additions & 1 deletion testsrc/main/mondrian/xmla/XmlaExcel2000Test.java
Expand Up @@ -31,7 +31,7 @@


/**
* These test the compatibility of Mondrian XMLA with Excel 2000.
* Test suite for compatibility of Mondrian XMLA with Excel 2000.
* Simba (the maker of the O2X bridge) supplied captured request/response
* soap messages between Excel 2000 and SQL Server. These form the
* basis of the output files in the excel_2000 directory.
Expand Down Expand Up @@ -414,6 +414,7 @@ protected void validate(byte[] bytes, Document expectedDoc)
System.out.println("EXPECTED:\n"+expectedStr);
System.out.println("XXXXXXX");
}
gotStr = Util.maskVersion(gotStr);
XMLAssert.assertXMLEqual(expectedStr, gotStr);
}

Expand Down
5 changes: 3 additions & 2 deletions testsrc/main/mondrian/xmla/XmlaExcelXPTest.java
Expand Up @@ -28,7 +28,7 @@


/**
* These test the compatibility of Mondrian XMLA with Excel XP.
* Test suite for compatibility of Mondrian XMLA with Excel XP.
* Simba (the maker of the O2X bridge) supplied captured request/response
* soap messages between Excel XP and SQL Server. These form the
* basis of the output files in the excel_XP directory.
Expand All @@ -37,7 +37,7 @@
* @version $Id$
*/
public class XmlaExcelXPTest extends XmlaBaseTestCase {
// session id properpty
// session id property
public static final String SESSION_ID_PROP = "session.id";

private static String EXPECT = XmlaRequestCallback.EXPECT;
Expand Down Expand Up @@ -436,6 +436,7 @@ protected void validate(byte[] bytes, Document expectedDoc)
System.out.println("EXPECTED:\n"+expectedStr);
System.out.println("XXXXXXX");
}
gotStr = Util.maskVersion(gotStr);
XMLAssert.assertXMLEqual(expectedStr, gotStr);
}

Expand Down
Expand Up @@ -50,7 +50,7 @@
<PropertyType>string</PropertyType>
<PropertyAccessType>Read</PropertyAccessType>
<IsRequired>false</IsRequired>
<Value>2.1.0.0</Value>
<Value>${mondrianVersion}</Value>
</row>
</root>
</xmla:return>
Expand Down
2 changes: 1 addition & 1 deletion testsrc/main/mondrian/xmla/excel_XP/excel_XP_04_out.xml
Expand Up @@ -50,7 +50,7 @@
<PropertyType>string</PropertyType>
<PropertyAccessType>Read</PropertyAccessType>
<IsRequired>false</IsRequired>
<Value>2.1.0.0</Value>
<Value>${mondrianVersion}</Value>
</row>
</root>
</xmla:return>
Expand Down

0 comments on commit e2bbdc5

Please sign in to comment.