You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@cxf.apache.org by dk...@apache.org on 2007/11/05 17:30:47 UTC
svn commit: r592068 - in /incubator/cxf/branches/2.0.x-fixes: ./
tools/common/src/main/java/org/apache/cxf/tools/common/
tools/common/src/main/java/org/apache/cxf/tools/common/toolspec/parser/
tools/common/src/test/java/org/apache/cxf/tools/common/tool...
Author: dkulp
Date: Mon Nov 5 08:30:46 2007
New Revision: 592068
URL: http://svn.apache.org/viewvc?rev=592068&view=rev
Log:
Merged revisions 591788 via svnmerge from
https://svn.apache.org/repos/asf/incubator/cxf/trunk
........
r591788 | ema | 2007-11-04 10:12:10 -0500 (Sun, 04 Nov 2007) | 1 line
CXF-1170: Improve the format of tooling help detailed usage, use the unix man style to print help message
........
Modified:
incubator/cxf/branches/2.0.x-fixes/ (props changed)
incubator/cxf/branches/2.0.x-fixes/tools/common/src/main/java/org/apache/cxf/tools/common/AbstractCXFToolContainer.java
incubator/cxf/branches/2.0.x-fixes/tools/common/src/main/java/org/apache/cxf/tools/common/toolspec/parser/CommandLineParser.java
incubator/cxf/branches/2.0.x-fixes/tools/common/src/main/java/org/apache/cxf/tools/common/toolspec/parser/detailedUsage.xsl
incubator/cxf/branches/2.0.x-fixes/tools/common/src/test/java/org/apache/cxf/tools/common/toolspec/parser/CommandLineParserTest.java
Propchange: incubator/cxf/branches/2.0.x-fixes/
------------------------------------------------------------------------------
Binary property 'svnmerge-integrated' - no diff available.
Modified: incubator/cxf/branches/2.0.x-fixes/tools/common/src/main/java/org/apache/cxf/tools/common/AbstractCXFToolContainer.java
URL: http://svn.apache.org/viewvc/incubator/cxf/branches/2.0.x-fixes/tools/common/src/main/java/org/apache/cxf/tools/common/AbstractCXFToolContainer.java?rev=592068&r1=592067&r2=592068&view=diff
==============================================================================
--- incubator/cxf/branches/2.0.x-fixes/tools/common/src/main/java/org/apache/cxf/tools/common/AbstractCXFToolContainer.java (original)
+++ incubator/cxf/branches/2.0.x-fixes/tools/common/src/main/java/org/apache/cxf/tools/common/AbstractCXFToolContainer.java Mon Nov 5 08:30:46 2007
@@ -88,12 +88,10 @@
System.out.println();
System.out.println("Options: ");
System.out.println();
- System.out.println(parser.getDetailedUsage());
+ System.out.println(parser.getFromatedDetailedUsage());
String toolUsage = parser.getToolUsage();
-
if (toolUsage != null) {
System.out.println(toolUsage);
- System.out.println();
}
} catch (Exception ex) {
System.err.println("Error : Could not output detailed usage");
Modified: incubator/cxf/branches/2.0.x-fixes/tools/common/src/main/java/org/apache/cxf/tools/common/toolspec/parser/CommandLineParser.java
URL: http://svn.apache.org/viewvc/incubator/cxf/branches/2.0.x-fixes/tools/common/src/main/java/org/apache/cxf/tools/common/toolspec/parser/CommandLineParser.java?rev=592068&r1=592067&r2=592068&view=diff
==============================================================================
--- incubator/cxf/branches/2.0.x-fixes/tools/common/src/main/java/org/apache/cxf/tools/common/toolspec/parser/CommandLineParser.java (original)
+++ incubator/cxf/branches/2.0.x-fixes/tools/common/src/main/java/org/apache/cxf/tools/common/toolspec/parser/CommandLineParser.java Mon Nov 5 08:30:46 2007
@@ -189,9 +189,91 @@
// REVISIT: style usage document into a form more readily output as a
// usage message
ByteArrayOutputStream baos = new ByteArrayOutputStream();
-
toolspec.transform(getClass().getResourceAsStream("detailedUsage.xsl"), baos);
return baos.toString();
+ }
+
+ public String getFromatedDetailedUsage() throws TransformerException {
+ ByteArrayOutputStream baos = new ByteArrayOutputStream();
+ toolspec.transform(getClass().getResourceAsStream("detailedUsage.xsl"), baos);
+ String usage = baos.toString();
+ // we use the following pattern to format usage
+ // |-------|-options|------|description-----------------|
+ // before option white space size is 7
+ int beforeOptSpan = 3;
+ // option lenght is 8
+ int optSize = 12;
+ // after option white space size is 6
+ int afterOptLen = 6;
+ int totalLen = 80;
+ int optSpan = optSize + afterOptLen - 1;
+ int beforeDesSpan = beforeOptSpan + optSpan + 1;
+ String lineSeparator = System.getProperty("line.separator");
+ StringTokenizer st1 = new StringTokenizer(usage, lineSeparator);
+ int i = 0;
+ int length = st1.countTokens();
+ String[] orginalStrs = new String[length];
+ while (st1.hasMoreTokens()) {
+ String str = st1.nextToken();
+ orginalStrs[i] = str;
+ i++;
+ }
+ StringBuffer strbuffer = new StringBuffer();
+ for (int j = 0; j < length - 1; j = j + 2) {
+ int optionLen = orginalStrs[j].length();
+ addWhiteNamespace(strbuffer, beforeOptSpan);
+ if (optionLen <= optSpan) {
+ // && beforeOptSpan + optionLen + optSpan + desLen <= totalLen -
+ // 1) {
+
+ strbuffer.append(orginalStrs[j]);
+ addWhiteNamespace(strbuffer, optSpan - orginalStrs[j].length());
+ strbuffer.append(" ");
+ if (orginalStrs[j + 1].length() > totalLen - beforeDesSpan) {
+ String tmp = orginalStrs[j + 1].substring(0, totalLen - beforeDesSpan);
+ strbuffer.append(tmp);
+ orginalStrs[j + 1] = orginalStrs[j + 1].substring(totalLen - beforeDesSpan,
+ orginalStrs[j + 1].length());
+ strbuffer.append(lineSeparator);
+ } else {
+ strbuffer.append(orginalStrs[j + 1]);
+ strbuffer.append(lineSeparator);
+ orginalStrs[j + 1] = "";
+ }
+
+ // strbuffer.append(orginalStrs[j + 1]);
+ // strbuffer.append(lineSeparator);
+ // strbuffer.append(lineSeparator);
+ } else {
+ // addWhiteNamespace(strbuffer, beforeOptSpan);
+ strbuffer.append(orginalStrs[j]);
+ strbuffer.append(lineSeparator);
+ }
+ String tmpStr = orginalStrs[j + 1];
+
+ for (i = 0; i < tmpStr.length(); i = i + (totalLen - beforeDesSpan)) {
+ if (i + totalLen - beforeDesSpan < tmpStr.length()) {
+ addWhiteNamespace(strbuffer, beforeDesSpan);
+ strbuffer.append(tmpStr.substring(i, i + totalLen - beforeDesSpan));
+ strbuffer.append(lineSeparator);
+ } else {
+ addWhiteNamespace(strbuffer, beforeDesSpan);
+ strbuffer.append(tmpStr.substring(i));
+ strbuffer.append(lineSeparator);
+ }
+ }
+ strbuffer.append(lineSeparator);
+
+ }
+
+ return strbuffer.toString();
+ }
+
+ private void addWhiteNamespace(StringBuffer strbuffer, int count) {
+
+ for (int i = 0; i < count; i++) {
+ strbuffer.append(" ");
+ }
}
public String getDetailedUsage(String id) {
Modified: incubator/cxf/branches/2.0.x-fixes/tools/common/src/main/java/org/apache/cxf/tools/common/toolspec/parser/detailedUsage.xsl
URL: http://svn.apache.org/viewvc/incubator/cxf/branches/2.0.x-fixes/tools/common/src/main/java/org/apache/cxf/tools/common/toolspec/parser/detailedUsage.xsl?rev=592068&r1=592067&r2=592068&view=diff
==============================================================================
--- incubator/cxf/branches/2.0.x-fixes/tools/common/src/main/java/org/apache/cxf/tools/common/toolspec/parser/detailedUsage.xsl (original)
+++ incubator/cxf/branches/2.0.x-fixes/tools/common/src/main/java/org/apache/cxf/tools/common/toolspec/parser/detailedUsage.xsl Mon Nov 5 08:30:46 2007
@@ -1,25 +1,27 @@
<?xml version="1.0" encoding="UTF-8"?>
<!--
- 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.
+ 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.
-->
-<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:ts="http://cxf.apache.org/Xutil/ToolSpecification">
- <xsl:output method="text" omit-xml-declaration="yes"/>
- <xsl:template match="/ts:toolspec/ts:usage">
+<xsl:stylesheet version="1.0"
+ xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
+ xmlns:ts="http://cxf.apache.org/Xutil/ToolSpecification">
+ <xsl:output method="text" omit-xml-declaration="yes" />
+ <!--xsl:template match="/ts:toolspec/ts:usage">
<xsl:choose>
<xsl:when test="ts:form">
<xsl:text>Command can take one of a number of forms:-</xsl:text>
@@ -31,16 +33,13 @@
<xsl:apply-templates select="*"/>
</xsl:otherwise>
</xsl:choose>
- </xsl:template>
- <xsl:template match="ts:form">
- <xsl:text>
-
-Form </xsl:text>
+ </xsl:template-->
+ <!--xsl:template match="ts:form">
+ <xsl:text>Form </xsl:text>
<xsl:value-of select="@value"/>
- <xsl:text>...
-</xsl:text>
+ <xsl:text>...</xsl:text>
<xsl:apply-templates select="*"/>
- </xsl:template>
+ </xsl:template-->
<xsl:template match="ts:optionGroup[not(@ref)]">
<xsl:apply-templates select="ts:option"/>
</xsl:template>
@@ -81,8 +80,9 @@
</xsl:if>
<xsl:text> </xsl:text>
<xsl:choose>
- <xsl:when xml:space="preserve" test="ts:annotation">
- <xsl:value-of select="ts:annotation"/>
+ <xsl:when test="ts:annotation">
+ <xsl:variable name="text1" select="ts:annotation"/>
+ <xsl:value-of select = "normalize-space(translate($text1,'
',''))"/>
</xsl:when>
<xsl:otherwise>
<xsl:value-of select="@id"/>
@@ -106,12 +106,13 @@
</xsl:if>
<xsl:text> </xsl:text>
<xsl:choose>
- <xsl:when xml:space="preserve" test="ts:annotation">
- <xsl:value-of select="ts:annotation"/>
+ <xsl:when test="ts:annotation">
+ <xsl:variable name="text2" select="ts:annotation"/>
+ <xsl:value-of select = "normalize-space(translate($text2,'
',''))"/>
</xsl:when>
- <xsl:otherwise>
- </xsl:otherwise>
- </xsl:choose>
+ <xsl:otherwise>
+ </xsl:otherwise>
+ </xsl:choose>
</xsl:when>
</xsl:choose>
</xsl:template>
Modified: incubator/cxf/branches/2.0.x-fixes/tools/common/src/test/java/org/apache/cxf/tools/common/toolspec/parser/CommandLineParserTest.java
URL: http://svn.apache.org/viewvc/incubator/cxf/branches/2.0.x-fixes/tools/common/src/test/java/org/apache/cxf/tools/common/toolspec/parser/CommandLineParserTest.java?rev=592068&r1=592067&r2=592068&view=diff
==============================================================================
--- incubator/cxf/branches/2.0.x-fixes/tools/common/src/test/java/org/apache/cxf/tools/common/toolspec/parser/CommandLineParserTest.java (original)
+++ incubator/cxf/branches/2.0.x-fixes/tools/common/src/test/java/org/apache/cxf/tools/common/toolspec/parser/CommandLineParserTest.java Mon Nov 5 08:30:46 2007
@@ -303,5 +303,14 @@
public void testGetDetailedUsage() {
assertTrue("Namespace".equals(parser.getDetailedUsage("namespace")));
}
+
+
+ @Test
+ public void testFormatedDetailedUsage() throws Exception {
+ String usage = parser.getFromatedDetailedUsage();
+ assertNotNull(usage);
+ StringTokenizer st1 = new StringTokenizer(usage, System.getProperty("line.separator"));
+ assertEquals(13, st1.countTokens());
+ }
}