1
+ import java .util .Date
2
+ import java .text ._
3
+
4
+ class MakeDownloadPage (version : String , releaseDate : Date = new Date ()) {
5
+ def write () = {
6
+ require(! version.startsWith(" v" ), " version should *not* start with 'v'" )
7
+ val fileName = s " ${format(" yyyy-MM-dd" )}- $version.md "
8
+ IO .write(new java.io.File (fileName), page)
9
+ println(" generated " + fileName)
10
+ }
11
+
12
+ def humanSize (url : String ) = {
13
+ import scala .sys .process ._
14
+ println(url)
15
+ val tmpFile = java.io.File .createTempFile(" download" , " .tmp" )
16
+ val res = s " curl --fail --silent --output ${tmpFile.getAbsolutePath} $url" .!
17
+ val dfOutput = s " du -h ${tmpFile.getAbsolutePath}" .!!
18
+ val output = dfOutput.trim.split(" \t " ).head
19
+ if (output == " 0B" ) {
20
+ println(s " warning: could not fetch $url" )
21
+ " "
22
+ } else output
23
+ }
24
+
25
+ def resourceArchive (cls : String , name : String , ext : String , desc : String ) = {
26
+ val fileName = s " $name- $version. $ext"
27
+ val relUrl = s " /files/archive/ $fileName"
28
+ val fullUrl = s " http://www.scala-lang.org $relUrl"
29
+ resource(cls, fileName, desc, relUrl, fullUrl)
30
+ }
31
+
32
+ def resource (cls : String , fileName : String , desc : String , relUrl : String , fullUrl : String ) = {
33
+ s """ [ $cls, " $fileName", " $relUrl", " $desc", " ${humanSize(fullUrl)}"] """
34
+ }
35
+
36
+ def defaultClass = " -non-main-sys"
37
+
38
+ def format (fmt : String ) = new SimpleDateFormat (fmt).format(releaseDate)
39
+
40
+ def ghSourceUrl = s " https://github.com/scala/scala/archive/v $version.tar.gz "
41
+
42
+ def page : String = {
43
+
44
+ s """
45
+ ---
46
+ title: Scala $version
47
+ start: ${format(" dd MMMM yyyy" )}
48
+ layout: downloadpage
49
+ release_version: $version
50
+ release_date: " ${format(" MMMM dd, yyyy" )}"
51
+ show_resources: "true"
52
+ permalink: /download/ $version.html
53
+ requirements: "This Scala software distribution can be installed on any Unix-like or Windows system. It requires the Java runtime version 1.6 or later, which can be downloaded <a href='http://www.java.com/'>here</a>."
54
+ resources: [
55
+ ${resourceArchive(" -main-unixsys" , " scala" , " tgz" , " Max OS X, Unix, Cygwin" )}
56
+ ${resourceArchive(" -main-windows" , " scala" , " msi" , " Windows (msi installer)" )},
57
+ ${resourceArchive(defaultClass, " scala" , " zip" , " Windows" )},
58
+ ${resourceArchive(defaultClass, " scala-docs" , " txz" , " API docs" )},
59
+ ${resourceArchive(defaultClass, " scala-docs" , " zip" , " API docs" )},
60
+ ${resource (defaultClass, s " scala-sources- $version.zip " , " sources" , ghSourceUrl, ghSourceUrl)},
61
+ ${resourceArchive(defaultClass, " scala-tool-support" , " tgz" , " Scala Tool Support (tgz)" )},
62
+ ${resourceArchive(defaultClass, " scala-tool-support" , " zip" , " Scala Tool Support (zip)" )}
63
+ ]
64
+ ---
65
+
66
+
67
+ """
68
+ }
69
+ }
0 commit comments