Skip to content

Commit 5d58268

Browse files
author
michelou
committed
updated man pages, fixed svn props, did some cl...
updated man pages, fixed svn props, did some cleanup
1 parent 3e24f4c commit 5d58268

File tree

13 files changed

+404
-107
lines changed

13 files changed

+404
-107
lines changed

src/compiler/scala/tools/ant/antlib.xml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,10 @@
1111
classname="scala.tools.ant.ScalaTool"/>
1212
<taskdef name="sbaz"
1313
classname="scala.tools.ant.ScalaBazaar"/>
14+
<!--@XML-->
1415
<taskdef name="scaladoc"
1516
classname="scala.tools.ant.Scaladoc"/>
17+
<!--XML@-->
1618
<taskdef name="scalatool"
1719
classname="scala.tools.ant.ScalaTool"/>
1820
<taskdef name="same"

src/compiler/scala/tools/nsc/plugins/PluginDescription.scala

Lines changed: 55 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -6,14 +6,18 @@
66
package scala.tools.nsc
77
package plugins
88

9-
import java.io.File
10-
9+
/*@XML*/
1110
import scala.xml.{Node,NodeSeq}
11+
/*XML@*/
12+
/*@NOXML
13+
import org.w3c.dom.{Node, Document, Text}
14+
import scala.tools.util.XML
15+
XMLNO@*/
1216

1317
/** A description of a compiler plugin, suitable for serialization
1418
* to XML for inclusion in the plugin's .jar file.
1519
*
16-
* @author Lex Spoon
20+
* @author Lex Spoon, Stephane Micheloud
1721
* @version 1.0, 2007-5-21
1822
*/
1923
abstract class PluginDescription {
@@ -29,31 +33,74 @@ abstract class PluginDescription {
2933

3034
/** An XML representation of this description. It can be
3135
* read back using <code>PluginDescription.fromXML</code>.
32-
* It should be stored inside the jar.
36+
* It should be stored inside the jar archive file.
3337
*/
38+
/*@XML*/ // NB. This code DOES rely on Scala native XML support.
3439
def toXML: Node = {
3540
<plugin>
3641
<name>{name}</name>
3742
<classname>{classname}</classname>
3843
</plugin>
3944
}
40-
}
45+
/*XML@*/
46+
/*@NOXML // NB. This code DOES NOT rely on Scala native XML support.
47+
def toXML: Node = pluginDoc
48+
49+
private lazy val pluginDoc: Node = {
50+
val root = XML.newDocument()
4151
52+
val pluginElem = root createElement "plugin"
53+
root appendChild pluginElem
54+
55+
val nameElem = root createElement "name"
56+
nameElem appendChild (root createTextNode name)
57+
pluginElem appendChild nameElem
58+
59+
val classnameElem = root createElement "classname"
60+
classnameElem appendChild (root createTextNode classname)
61+
pluginElem appendChild classnameElem
62+
63+
root
64+
}
65+
XMLNO@*/
66+
}
4267

4368
/** Utilities for the PluginDescription class.
4469
*
45-
* @author Lex Spoon
70+
* @author Lex Spoon, Stephane Micheloud
4671
* @version 1.0, 2007-5-21
4772
*/
4873
object PluginDescription {
74+
4975
def fromXML(xml: Node): Option[PluginDescription] = {
5076
// check the top-level tag
77+
/*@XML*/
5178
xml match {
5279
case <plugin>{_*}</plugin> => ()
5380
case _ => return None
5481
}
82+
/*XML@*/
83+
/*@NOXML
84+
val node = xml match {
85+
case root: Document => root.getDocumentElement
86+
case node => node
87+
}
88+
if (node.getNodeName != "plugin")
89+
return None
5590
56-
/** Extract one field */
91+
class RichNode(node: Node) {
92+
def \\(tagName: String): Node = node match {
93+
case root: Document => root.getElementsByTagName(tagName) item 0
94+
case _ => node //TODO: visit children
95+
}
96+
def text: String = node match {
97+
case t: Text => t.getWholeText
98+
case e => e.getTextContent
99+
}
100+
}
101+
implicit def nodeWrapper(node: Node) = new RichNode(node)
102+
XMLNO@*/
103+
// extract one field
57104
def getField(field: String): Option[String] = {
58105
val text = (xml \\ field).text.trim
59106
if (text == "") None else Some(text)
@@ -74,4 +121,5 @@ object PluginDescription {
74121
val classname = classname1
75122
})
76123
}
124+
77125
}
Lines changed: 147 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,147 @@
1+
/* NSC -- new Scala compiler
2+
* Copyright 2005-2011 LAMP/EPFL
3+
* @author Stephane Micheloud
4+
*/
5+
6+
package scala.tools
7+
package util
8+
9+
/** The object `XML` provides minimal XML support for creating, loading
10+
* and saving XML documents (see eg. [[scala.tools.ant.ScalaBazaar]],
11+
* [[scala.tools.nsc.plugins.PluginDescription]] and
12+
* [[scala.tools.partest.PartestTask]]).
13+
*
14+
* It makes possible for the programmer of Scala tools not to rely on the
15+
* XML features of the reference implementation of the Scala compiler
16+
* (some Scala customers may for instance not be interested in that features).
17+
*
18+
* @author Stephane Micheloud
19+
* @version 1.0
20+
*/
21+
/*@NOXML
22+
// [mics] used in code which DOES NOT rely on Scala native XML support
23+
// (see eg. classes partest/PartestTask.scala, ant/ScalaBazaar.scala).
24+
object XML {
25+
import java.io.{FileOutputStream, InputStream, Writer}
26+
import java.nio.channels.Channels
27+
import javax.xml.parsers.DocumentBuilderFactory
28+
import org.w3c.dom.{Document, DocumentType, Element, NamedNodeMap}
29+
import org.w3c.dom.{Node => JNode, Text => JText}
30+
import org.xml.sax.InputSource
31+
import scala.util.control.Exception.ultimately
32+
33+
def newDocument(): Document = newBuilder.newDocument()
34+
35+
def loadXML(source: InputSource): Document = newBuilder parse source
36+
37+
def load(in: InputStream) = loadXML(new InputSource(in))
38+
39+
final def save(filename: String, node: Node,
40+
encoding: String = "ISO-8859-1",
41+
xmlDecl: Boolean = false,
42+
doctype: DocumentType = null) {
43+
val fos = new FileOutputStream(filename)
44+
val w = Channels.newWriter(fos.getChannel, encoding)
45+
46+
ultimately(w.close()) {
47+
write(w, node, encoding, xmlDecl, doctype)
48+
}
49+
}
50+
51+
final def write(out: Writer, node: Node, encoding: String, xmlDecl: Boolean, doctype: DocumentType) {
52+
if (xmlDecl) out.write("<?xml version='1.0' encoding='" + encoding + "'?>\n")
53+
if (doctype ne null) out.write(doctype.getName + "\n")
54+
out write node.toXMLString
55+
}
56+
57+
class Node(val node: JNode) {
58+
def toXMLString: String = {
59+
var indent: Int = 0
60+
val sb = new StringBuilder()
61+
def xmlTag(s: String, attrs: NamedNodeMap, trail: String) {
62+
var i = 0; while (i < indent) { sb append spaces; i += 1 }
63+
sb append "<" append s
64+
for (i <- 0 until attrs.getLength) {
65+
val attr = attrs item i
66+
sb append " " append attr.getNodeName append "=\"" append attr.getTextContent append "\""
67+
}
68+
sb append trail
69+
}
70+
def startTag(s: String, attrs: NamedNodeMap) {
71+
xmlTag(s, attrs, Node.TAG_TRAIL_EOL)
72+
indent += 1
73+
}
74+
def startTag1(s: String, attrs: NamedNodeMap) {
75+
xmlTag(s, attrs, Node.TAG_TRAIL)
76+
}
77+
def shortTag(s: String, attrs: NamedNodeMap) {
78+
xmlTag(s, attrs, Node.STAG_TRAIL_EOL)
79+
}
80+
def endTag(s: String) {
81+
indent -= 1
82+
var i = 0; while (i < indent) { sb append spaces; i += 1 }
83+
sb append "</" append s append Node.TAG_TRAIL_EOL
84+
}
85+
def endTag1(s: String) {
86+
sb append "</" append s append Node.TAG_TRAIL_EOL
87+
}
88+
def traverse(node: JNode) {
89+
val name = node.getNodeName
90+
val attrs = node.getAttributes
91+
var children = node.getChildNodes
92+
val n = children.getLength
93+
if (n == 1 && children.item(0).isInstanceOf[JText]) {
94+
startTag1(name, attrs)
95+
sb append children.item(0).asInstanceOf[JText].getWholeText
96+
endTag1(name)
97+
}
98+
else if (n > 0) {
99+
startTag(name, attrs)
100+
for (i <- 0 until n) {
101+
mkString(children item i)
102+
}
103+
endTag(name)
104+
}
105+
else
106+
shortTag(name, attrs)
107+
}
108+
def mkString(node: JNode) = node match {
109+
case t: JText => sb append t.getWholeText
110+
case e => traverse(e)
111+
}
112+
traverse(node match {
113+
case docu: Document => docu.getDocumentElement
114+
case elem => elem
115+
})
116+
sb.toString
117+
}
118+
119+
def text: String = node match {
120+
case t: JText => t.getWholeText
121+
case n => n.getTextContent
122+
}
123+
124+
override def toString: String = toXMLString
125+
}
126+
127+
implicit def nodeWrapper(node: JNode) = new Node(node)
128+
129+
// ---------- private declarations --------
130+
131+
private val docFactory = DocumentBuilderFactory.newInstance()
132+
docFactory setNamespaceAware false
133+
private def newBuilder = docFactory.newDocumentBuilder()
134+
135+
private var spaces = " "
136+
def spaces_=(n: Int) { spaces = List.fill(n)(' ').mkString }
137+
138+
private object Node {
139+
final val TAG_TRAIL = ">"
140+
final val TAG_TRAIL_EOL = TAG_TRAIL+compat.Platform.EOL
141+
final val STAG_TRAIL = "/>"
142+
final val STAG_TRAIL_EOL = STAG_TRAIL+compat.Platform.EOL
143+
}
144+
145+
}
146+
XMLNO@*/
147+

src/library/scala/AnyVal.scala

100755100644
File mode changed.

src/library/scala/Boolean.scala

100755100644
File mode changed.

src/library/scala/Unit.scala

100755100644
File mode changed.

src/manual/scala/man1/Command.scala

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,10 @@
55

66
package scala.man1
77

8+
/**
9+
* @author Stephane Micheloud
10+
* @version 1.0
11+
*/
812
trait Command {
913
import _root_.scala.tools.docutil.ManPage._
1014

@@ -23,6 +27,9 @@ trait Command {
2327
protected def CmdOption(opt: String): AbstractText =
2428
Mono(Bold(NDash & opt) & " ")
2529

30+
protected def CmdOptionBound(opt: String, params: AbstractText) =
31+
Mono(Bold(NDash & opt) & params & " ")
32+
2633
protected def CmdOptionLong(opt: String, params: AbstractText) =
2734
Mono(Bold(NDash & NDash & opt) & " " & params & " ")
2835

@@ -48,10 +55,5 @@ trait Command {
4855

4956
"Report bugs to " & Mono("https://issues.scala-lang.org/") & ".")
5057

51-
//private val df = new java.text.SimpleDateFormat("MMM d, yyyy")
52-
//private val rightNow = new java.util.Date()
53-
54-
def lastModified: String = "April 18, 2007" // df.format(rightNow)
55-
5658
def manpage: Document
5759
}

src/manual/scala/man1/fsc.scala

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,11 +5,14 @@
55

66
package scala.man1
77

8+
/**
9+
* @author Lex Spoon
10+
* @version 1.0
11+
*/
812
object fsc extends Command {
913
import _root_.scala.tools.docutil.ManPage._
1014

1115
protected def cn = new Error().getStackTrace()(0).getClassName()
12-
override def lastModified = "January 18, 2007"
1316

1417
val name = Section("NAME",
1518

@@ -63,8 +66,8 @@ object fsc extends Command {
6366
"is not needed. Note that the hostname must be for a host that shares " &
6467
"the same filesystem."),
6568
Definition(
66-
CmdOption("J", Argument("flag")),
67-
"Pass <flag> directly to the Java VM for the compilation daemon.")
69+
CmdOptionBound("J", Argument("flag")),
70+
"Pass " & Mono(Argument("flag")) & " directly to the Java VM for the compilation daemon.")
6871
))
6972

7073
val example = Section("EXAMPLE",
@@ -146,7 +149,7 @@ object fsc extends Command {
146149

147150
def manpage = new Document {
148151
title = command
149-
date = lastModified
152+
date = "January 2007"
150153
author = "Lex Spoon"
151154
version = "0.4"
152155
sections = List(

src/manual/scala/man1/sbaz.scala

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,10 @@
55

66
package scala.man1
77

8+
/**
9+
* @author Stephane Micheloud
10+
* @version 1.0
11+
*/
812
object sbaz extends Command {
913
import _root_.scala.tools.docutil.ManPage._
1014

@@ -63,13 +67,13 @@ object sbaz extends Command {
6367
"Display the version information"),
6468

6569
Definition(
66-
CmdOption("-univ") & Argument("name"),
70+
CmdOptionLong("univ", Argument("name")),
6771
"Operate on the named remote universe, selected from those " &
6872
"in the local managed directory's universe. Affects "&
6973
"the "&MBold("share")&" and "&MBold("retract")&" commands."),
7074

7175
Definition(
72-
CmdOption("-univ-url") & Argument("url"),
76+
CmdOptionLong("univ-url", Argument("url")),
7377
"Operate on the universe at the specified URL. Affects "&
7478
"the "&MBold("share")&" and "&MBold("retract")&" commands."))),
7579

@@ -186,7 +190,7 @@ object sbaz extends Command {
186190

187191
def manpage = new Document {
188192
title = command
189-
date = "August 24, 2006"
193+
date = "August 2006"
190194
author = "Stephane Micheloud"
191195
version = "0.3"
192196
sections = List(

0 commit comments

Comments
 (0)