You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@jena.apache.org by rv...@apache.org on 2013/04/03 19:22:43 UTC
svn commit: r1464111 - in /jena/trunk/jena-arq/src:
main/java/com/hp/hpl/jena/sparql/util/Version.java
test/java/com/hp/hpl/jena/sparql/util/TS_Util.java
test/java/com/hp/hpl/jena/sparql/util/TestVersion.java
Author: rvesse
Date: Wed Apr 3 17:22:42 2013
New Revision: 1464111
URL: http://svn.apache.org/r1464111
Log:
Make Version.toString() provide more user friendly output, provide a print() overload that prints to an arbitrary IndentedWriter
Added:
jena/trunk/jena-arq/src/test/java/com/hp/hpl/jena/sparql/util/TestVersion.java
Modified:
jena/trunk/jena-arq/src/main/java/com/hp/hpl/jena/sparql/util/Version.java
jena/trunk/jena-arq/src/test/java/com/hp/hpl/jena/sparql/util/TS_Util.java
Modified: jena/trunk/jena-arq/src/main/java/com/hp/hpl/jena/sparql/util/Version.java
URL: http://svn.apache.org/viewvc/jena/trunk/jena-arq/src/main/java/com/hp/hpl/jena/sparql/util/Version.java?rev=1464111&r1=1464110&r2=1464111&view=diff
==============================================================================
--- jena/trunk/jena-arq/src/main/java/com/hp/hpl/jena/sparql/util/Version.java (original)
+++ jena/trunk/jena-arq/src/main/java/com/hp/hpl/jena/sparql/util/Version.java Wed Apr 3 17:22:42 2013
@@ -20,6 +20,7 @@ package com.hp.hpl.jena.sparql.util;
import java.lang.reflect.Field ;
import java.util.ArrayList ;
+import java.util.Date;
import java.util.Iterator ;
import java.util.List ;
@@ -41,38 +42,69 @@ public class Version
classes.add(c) ;
}
- private static String[] fields = { /*"NAME",*/ "VERSION", "BUILD_DATE" } ;
+ private static String FIELD_VERSION = "VERSION";
+
+ private static String FIELD_BUILD_DATE = "BUILD_DATE";
+
+ private static String[] fields = { /*"NAME",*/ FIELD_VERSION, FIELD_BUILD_DATE } ;
/**
* Prints version information for all registered classes to Standard Out
*/
- public void print()
+ public void print() {
+ print(IndentedWriter.stdout);
+ }
+
+ /**
+ * Prints version information for all registered classes to the given writer
+ * @param writer Writer to print version information to
+ */
+ public void print(IndentedWriter writer)
{
for ( Iterator<Class<?>> iter = classes.iterator() ; iter.hasNext() ; )
{
Class<?> c = iter.next();
String x = Utils.classShortName(c) ;
- fields(IndentedWriter.stdout, x, c) ;
+ fields(writer, x, c) ;
}
}
/**
- * Gets version information for all registered classes as a string
+ * Gets user friendly version information for all registered classes as a string
+ * @param singleLine Whether to print to a single line
+ * @return Version information
*/
- @Override
- public String toString() {
+ public String toString(boolean singleLine) {
IndentedLineBuffer buffer = new IndentedLineBuffer(false);
- for ( Iterator<Class<?>> iter = classes.iterator() ; iter.hasNext() ; )
+ Iterator<Class<?>> iter = classes.iterator();
+ while (iter.hasNext())
{
Class<?> c = iter.next();
- String x = Utils.classShortName(c) ;
- fields(buffer, x, c) ;
+ String component = Utils.classShortName(c) ;
+ String version = field(FIELD_VERSION, c);
+ String timestamp = field(FIELD_BUILD_DATE, c);
+ buffer.append("%s Version %s (Built %s)", component, version, timestamp);
+ if (iter.hasNext()) {
+ if (!singleLine) {
+ buffer.println();
+ } else {
+ buffer.print(", ");
+ }
+ }
}
return buffer.asString();
}
+ /**
+ * Gets user friendly version information for all registered classes as a string
+ */
+ @Override
+ public String toString() {
+ return this.toString(false);
+ }
+
private static void fields(IndentedWriter writer, String prefix, Class< ? > cls)
{
for (int i=0; i < fields.length; i++)
@@ -100,7 +132,7 @@ public class Version
}
return "<error>" ;
}
-
+
private static void printField(IndentedWriter out, String prefix, String fieldName, Class< ? > cls)
{
out.print(prefix) ;
Modified: jena/trunk/jena-arq/src/test/java/com/hp/hpl/jena/sparql/util/TS_Util.java
URL: http://svn.apache.org/viewvc/jena/trunk/jena-arq/src/test/java/com/hp/hpl/jena/sparql/util/TS_Util.java?rev=1464111&r1=1464110&r2=1464111&view=diff
==============================================================================
--- jena/trunk/jena-arq/src/test/java/com/hp/hpl/jena/sparql/util/TS_Util.java (original)
+++ jena/trunk/jena-arq/src/test/java/com/hp/hpl/jena/sparql/util/TS_Util.java Wed Apr 3 17:22:42 2013
@@ -26,7 +26,8 @@ import org.junit.runners.Suite.SuiteClas
@RunWith(Suite.class)
@SuiteClasses( {
TestDateTimeParsing.class ,
- TestList.class
+ TestList.class ,
+ TestVersion.class
})
public class TS_Util
Added: jena/trunk/jena-arq/src/test/java/com/hp/hpl/jena/sparql/util/TestVersion.java
URL: http://svn.apache.org/viewvc/jena/trunk/jena-arq/src/test/java/com/hp/hpl/jena/sparql/util/TestVersion.java?rev=1464111&view=auto
==============================================================================
--- jena/trunk/jena-arq/src/test/java/com/hp/hpl/jena/sparql/util/TestVersion.java (added)
+++ jena/trunk/jena-arq/src/test/java/com/hp/hpl/jena/sparql/util/TestVersion.java Wed Apr 3 17:22:42 2013
@@ -0,0 +1,81 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package com.hp.hpl.jena.sparql.util;
+
+import org.apache.jena.atlas.io.IndentedLineBuffer;
+import org.apache.jena.riot.RIOT;
+import org.junit.Assert;
+import org.junit.Test;
+
+import com.hp.hpl.jena.query.ARQ;
+
+/**
+ * Tests for the {@link Version} utility class
+ *
+ */
+public class TestVersion {
+
+ @Test
+ public void test_version_print_01() {
+ Version ver = new Version();
+ ver.addClass(ARQ.class);
+
+ IndentedLineBuffer buffer = new IndentedLineBuffer();
+ ver.print(buffer);
+
+ String info = buffer.asString();
+ Assert.assertNotNull(info);
+ Assert.assertTrue(info.contains("ARQ"));
+ }
+
+ @Test
+ public void test_version_string_01() {
+ Version ver = new Version();
+ ver.addClass(ARQ.class);
+ ver.addClass(RIOT.class);
+
+ String info = ver.toString();
+ Assert.assertNotNull(info);
+ Assert.assertTrue(info.contains("ARQ"));
+ Assert.assertTrue(info.contains("\n"));
+ }
+
+ @Test
+ public void test_version_string_02() {
+ Version ver = new Version();
+ ver.addClass(ARQ.class);
+ ver.addClass(RIOT.class);
+
+ String info = ver.toString(false);
+ Assert.assertNotNull(info);
+ Assert.assertTrue(info.contains("ARQ"));
+ Assert.assertTrue(info.contains("\n"));
+ }
+
+ @Test
+ public void test_version_string_03() {
+ Version ver = new Version();
+ ver.addClass(ARQ.class);
+
+ String info = ver.toString(true);
+ Assert.assertNotNull(info);
+ Assert.assertTrue(info.contains("ARQ"));
+ Assert.assertFalse(info.contains("\n"));
+ }
+}