1 /* Title: Pure/Tools/scala_project.scala |
1 /* Title: Pure/Tools/scala_project.scala |
2 Author: Makarius |
2 Author: Makarius |
3 |
3 |
4 Manage Isabelle/Scala/Java project sources, with output to Gradle for |
4 Manage Isabelle/Scala/Java project sources, with output to Maven for |
5 IntelliJ IDEA. |
5 IntelliJ IDEA. |
6 */ |
6 */ |
7 |
7 |
8 package isabelle |
8 package isabelle |
9 |
9 |
10 |
10 |
11 object Scala_Project |
11 object Scala_Project |
12 { |
12 { |
13 /* groovy syntax */ |
13 /* Maven project */ |
14 |
14 |
15 def groovy_string(s: String): String = |
15 def java_version: String = "11" |
16 { |
16 def scala_version: String = scala.util.Properties.versionNumberString |
17 s.map(c => |
17 |
18 c match { |
18 def maven_project(jars: List[Path]): String = |
19 case '\t' | '\b' | '\n' | '\r' | '\f' | '\\' | '\'' | '"' => "\\" + c |
19 { |
20 case _ => c.toString |
20 def dependency(jar: Path): String = |
21 }).mkString("'", "", "'") |
21 { |
|
22 val name = jar.expand.drop_ext.base.implode |
|
23 val system_path = File.platform_path(jar.absolute) |
|
24 """ <dependency> |
|
25 <groupId>classpath</groupId> |
|
26 <artifactId>""" + XML.text(name) + """</artifactId> |
|
27 <version>0</version> |
|
28 <scope>system</scope> |
|
29 <systemPath>""" + XML.text(system_path) + """</systemPath> |
|
30 </dependency>""" |
|
31 } |
|
32 |
|
33 """<?xml version="1.0" encoding="UTF-8"?> |
|
34 <project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" |
|
35 xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> |
|
36 <modelVersion>4.0.0</modelVersion> |
|
37 |
|
38 <groupId>isabelle</groupId> |
|
39 <artifactId>isabelle</artifactId> |
|
40 <version>0</version> |
|
41 |
|
42 <properties> |
|
43 <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding> |
|
44 <maven.compiler.source>""" + java_version + """</maven.compiler.source> |
|
45 <maven.compiler.target>""" + java_version + """</maven.compiler.target> |
|
46 </properties> |
|
47 |
|
48 <build> |
|
49 <plugins> |
|
50 <plugin> |
|
51 <groupId>net.alchim31.maven</groupId> |
|
52 <artifactId>scala-maven-plugin</artifactId> |
|
53 <version>4.5.3</version> |
|
54 <configuration> |
|
55 <scalaVersion>""" + scala_version + """</scalaVersion> |
|
56 </configuration> |
|
57 </plugin> |
|
58 </plugins> |
|
59 </build> |
|
60 |
|
61 "<dependencies>""" + jars.map(dependency).mkString("\n", "\n", "\n") + """</dependencies> |
|
62 </project>""" |
22 } |
63 } |
23 |
64 |
24 |
65 |
25 /* plugins: modules with dynamic build */ |
66 /* plugins: modules with dynamic build */ |
26 |
67 |
125 progress: Progress = new Progress): Unit = |
166 progress: Progress = new Progress): Unit = |
126 { |
167 { |
127 if (project_dir.file.exists) { |
168 if (project_dir.file.exists) { |
128 val detect = |
169 val detect = |
129 project_dir.is_dir && |
170 project_dir.is_dir && |
130 (project_dir + Path.explode("build.gradle")).is_file && |
171 (project_dir + Path.explode("pom.xml")).is_file && |
131 (project_dir + Path.explode("src/main/scala")).is_dir |
172 (project_dir + Path.explode("src/main/scala")).is_dir |
132 |
173 |
133 if (force && detect) { |
174 if (force && detect) { |
134 progress.echo("Purging existing project directory: " + project_dir.absolute) |
175 progress.echo("Purging existing project directory: " + project_dir.absolute) |
135 Isabelle_System.rm_tree(project_dir) |
176 Isabelle_System.rm_tree(project_dir) |
143 val java_src_dir = Isabelle_System.make_directory(Path.explode("src/main/java")) |
184 val java_src_dir = Isabelle_System.make_directory(Path.explode("src/main/java")) |
144 val scala_src_dir = Isabelle_System.make_directory(Path.explode("src/main/scala")) |
185 val scala_src_dir = Isabelle_System.make_directory(Path.explode("src/main/scala")) |
145 |
186 |
146 val (jars, sources) = isabelle_files |
187 val (jars, sources) = isabelle_files |
147 isabelle_scala_files |
188 isabelle_scala_files |
|
189 |
|
190 File.write(project_dir + Path.explode("pom.xml"), maven_project(jars)) |
148 |
191 |
149 for (source <- sources ::: more_sources) { |
192 for (source <- sources ::: more_sources) { |
150 val dir = (if (source.is_java) java_src_dir else scala_src_dir) + the_package_dir(source) |
193 val dir = (if (source.is_java) java_src_dir else scala_src_dir) + the_package_dir(source) |
151 val target_dir = project_dir + dir |
194 val target_dir = project_dir + dir |
152 if (!target_dir.is_dir) { |
195 if (!target_dir.is_dir) { |
154 Isabelle_System.make_directory(target_dir) |
197 Isabelle_System.make_directory(target_dir) |
155 } |
198 } |
156 if (symlinks) Isabelle_System.symlink(source.absolute, target_dir, native = true) |
199 if (symlinks) Isabelle_System.symlink(source.absolute, target_dir, native = true) |
157 else Isabelle_System.copy_file(source, target_dir) |
200 else Isabelle_System.copy_file(source, target_dir) |
158 } |
201 } |
159 |
|
160 File.write(project_dir + Path.explode("settings.gradle"), "rootProject.name = 'Isabelle'\n") |
|
161 File.write(project_dir + Path.explode("build.gradle"), |
|
162 """plugins { |
|
163 id 'scala' |
|
164 } |
|
165 |
|
166 repositories { |
|
167 mavenCentral() |
|
168 } |
|
169 |
|
170 dependencies { |
|
171 implementation 'org.scala-lang:scala-library:""" + scala.util.Properties.versionNumberString + """' |
|
172 compileOnly files( |
|
173 """ + jars.map(jar => groovy_string(File.platform_path(jar))).mkString("", ",\n ", ")") + |
|
174 """ |
|
175 } |
|
176 """) |
|
177 } |
202 } |
178 |
203 |
179 |
204 |
180 /* Isabelle tool wrapper */ |
205 /* Isabelle tool wrapper */ |
181 |
206 |
182 val isabelle_tool = |
207 val isabelle_tool = |
183 Isabelle_Tool("scala_project", "setup Gradle project for Isabelle/Scala/jEdit", |
208 Isabelle_Tool("scala_project", "setup Maven project for Isabelle/Scala/jEdit", |
184 Scala_Project.here, args => |
209 Scala_Project.here, args => |
185 { |
210 { |
186 var project_dir = default_project_dir |
211 var project_dir = default_project_dir |
187 var symlinks = false |
212 var symlinks = false |
188 var force = false |
213 var force = false |
193 Options are: |
218 Options are: |
194 -D DIR project directory (default: """ + default_project_dir + """) |
219 -D DIR project directory (default: """ + default_project_dir + """) |
195 -L make symlinks to original source files |
220 -L make symlinks to original source files |
196 -f force update of existing directory |
221 -f force update of existing directory |
197 |
222 |
198 Setup Gradle project for Isabelle/Scala/jEdit --- to support Scala IDEs |
223 Setup Maven project for Isabelle/Scala/jEdit --- to support common IDEs |
199 such as IntelliJ IDEA. |
224 such as IntelliJ IDEA. |
200 """, |
225 """, |
201 "D:" -> (arg => project_dir = Path.explode(arg)), |
226 "D:" -> (arg => project_dir = Path.explode(arg)), |
202 "L" -> (_ => symlinks = true), |
227 "L" -> (_ => symlinks = true), |
203 "f" -> (_ => force = true)) |
228 "f" -> (_ => force = true)) |