@@ -14,12 +14,7 @@ import java.nio.file.Files
14
14
15
15
import dotty .tools .dotc .config .Settings ._
16
16
17
- abstract class Scala3Args (reportError : String => Unit ) extends SettingGroup :
18
- private val tastyRootsUsage = " Roots where tools should look for tasty files. Directories and jars are accepted"
19
- val tastyRoots : Setting [String ] =
20
- StringSetting (" --tastyRoots" , " tastyRoots" , tastyRootsUsage, " " , aliases = List (" -t" ))
21
- val tastyRootsAlias : Setting [String ] =
22
- StringSetting (" -t" , " tastyRoots" , tastyRootsUsage, " " , aliases = List (" -t" ))
17
+ class Scala3Args (reportError : String => Unit ) extends SettingGroup :
23
18
24
19
val dest : Setting [String ] =
25
20
StringSetting (" --dest" , " dest" , " Output to generate documentation to" , " " , aliases = List (" -d" ))
@@ -29,7 +24,7 @@ abstract class Scala3Args(reportError: String => Unit) extends SettingGroup:
29
24
val classpath : Setting [String ] =
30
25
StringSetting (" --classpath" , " classpath" , " Classpath to load dependencies from" , " " , aliases = List (" --cp" , " -c" ))
31
26
val classpathAlias1 : Setting [String ] =
32
- StringSetting (" --cp " , " classpath" , " Classpath to load dependencies from" , " " , aliases = List (" --cp" , " -c" ))
27
+ StringSetting (" -classpath " , " classpath" , " Classpath to load dependencies from" , " " , aliases = List (" --cp" , " -c" ))
33
28
val classpathAlias2 : Setting [String ] =
34
29
StringSetting (" -c" , " classpath" , " Classpath to load dependencies from" , " " , aliases = List (" --cp" , " -c" ))
35
30
@@ -71,9 +66,7 @@ abstract class Scala3Args(reportError: String => Unit) extends SettingGroup:
71
66
val syntax : Setting [String ] =
72
67
StringSetting (" --syntax" , " syntax" , " Syntax of the comment used" , " " )
73
68
74
- protected def defaultName (): String
75
- protected def defaultTastFiles (): List [File ]
76
- protected def defaultDest (): File
69
+ protected def defaultDest (): File = sys.error(s " Argument ' ${dest.name}' is required " )
77
70
78
71
def extract (args : List [String ]) =
79
72
val initialSummary = ArgsSummary (defaultState, args, errors = Nil , warnings = Nil )
@@ -95,11 +88,13 @@ abstract class Scala3Args(reportError: String => Unit) extends SettingGroup:
95
88
96
89
def parseTastyRoots (roots : String ) = roots.split(File .pathSeparatorChar).toList.map(new File (_))
97
90
91
+ val tastyRoots = res.arguments.map(new File (_)) // check provided files
92
+
98
93
Args (
99
- parseOptionalArg(name, nameAlias).getOrElse(defaultName() ),
100
- parseOptionalArg( tastyRoots, tastyRootsAlias).fold(defaultTastFiles())(parseTastyRoots) ,
94
+ parseOptionalArg(name, nameAlias).getOrElse(" root " ),
95
+ tastyRoots,
101
96
parseOptionalArg(classpath, classpathAlias1, classpathAlias2).getOrElse(System .getProperty(" java.class.path" )),
102
- parseOptionalArg(dest, destAlias).fold(defaultDest())(new File (_)),
97
+ parseOptionalArg(dest, destAlias).fold(defaultDest())(File (_)),
103
98
parseOptionalArg(docsRoot, docsRootAlias),
104
99
parseOptionalArg(projectVersion, projectVersionAlias),
105
100
parseOptionalArg(projectTitle, projectTitleAlias),
@@ -158,40 +153,35 @@ enum DocConfiguration extends BaseDocConfiguration:
158
153
*/
159
154
object Main :
160
155
def main (parsedArgs : Args ): Unit =
161
- try
162
- val (files, dirs) = parsedArgs.tastyRoots.partition(_.isFile)
163
- val (providedTastyFiles, jars) = files.toList.map(_.getAbsolutePath).partition(_.endsWith(" .tasty" ))
164
- jars.foreach(j => if (! j.endsWith(" .jar" )) sys.error(s " Provided file $j is not jar not tasty file " ) )
156
+ val (files, dirs) = parsedArgs.tastyRoots.partition(_.isFile)
157
+ val (providedTastyFiles, jars) = files.toList.map(_.getAbsolutePath).partition(_.endsWith(" .tasty" ))
158
+ jars.foreach(j => if (! j.endsWith(" .jar" )) sys.error(s " Provided file $j is not jar not tasty file " ) )
165
159
160
+ def listTastyFiles (f : File ): Seq [String ] =
161
+ val (files, dirs) = Option (f.listFiles()).toArray.flatten.partition(_.isFile)
162
+ ArraySeq .unsafeWrapArray(
163
+ files.filter(_.getName.endsWith(" .tasty" )).map(_.toString) ++ dirs.flatMap(listTastyFiles)
164
+ )
165
+ val tastyFiles = providedTastyFiles ++ dirs.flatMap(listTastyFiles)
166
166
167
- def listTastyFiles (f : File ): Seq [String ] =
168
- val (files, dirs) = f.listFiles().partition(_.isFile)
169
- ArraySeq .unsafeWrapArray(
170
- files.filter(_.getName.endsWith(" .tasty" )).map(_.toString) ++ dirs.flatMap(listTastyFiles)
171
- )
172
- val tastyFiles = providedTastyFiles ++ dirs.flatMap(listTastyFiles)
167
+ val config = DocConfiguration .Standalone (parsedArgs, tastyFiles, jars)
173
168
174
- val config = DocConfiguration . Standalone (parsedArgs, tastyFiles, jars )
169
+ if (parsedArgs.output.exists()) IO .delete (parsedArgs.output )
175
170
176
- if (parsedArgs.output.exists()) IO .delete(parsedArgs.output)
171
+ new DokkaGenerator (new DottyDokkaConfig (config), DokkaConsoleLogger .INSTANCE ).generate()
172
+ println(" Done" )
177
173
178
- new DokkaGenerator (new DottyDokkaConfig (config), DokkaConsoleLogger .INSTANCE ).generate()
179
174
180
- println(" Done" )
175
+ def main (args : Array [String ]): Unit =
176
+ try
177
+ val argDefinition = new Scala3Args (sys.error)
178
+ main(argDefinition.extract(args.toList))
179
+ // Sometimes jvm is hanging, so we want to be sure that we force shout down the jvm
180
+ sys.exit(0 )
181
181
catch
182
182
case a : Exception =>
183
183
a.printStackTrace()
184
184
// Sometimes jvm is hanging, so we want to be sure that we force shout down the jvm
185
185
sys.exit(1 )
186
186
187
- def main (args : Array [String ]): Unit =
188
- val argDefinition = new Scala3Args (sys.error) {
189
- protected def defaultName (): String = sys.error(s " Argument ' ${name.name}' is required " )
190
- protected def defaultTastFiles (): List [File ] = sys.error(s " Argument ' ${tastyRoots.name}' is required " )
191
- protected def defaultDest (): File = sys.error(s " Argument ' ${dest.name}' is required " )
192
- }
193
- main(argDefinition.extract(args.toList))
194
- // Sometimes jvm is hanging, so we want to be sure that we force shout down the jvm
195
- sys.exit(0 )
196
-
197
187
0 commit comments