def package_dir(source_file: Path): Path = { val dir =
package_name(source_file) match { case Some(name) => Path.explode(space_explode('.', name).mkString("/")) case None => error("Failed to guess package from " + source_file)
}
(if (source_file.is_java) java_src_dir else scala_src_dir) + dir
}
}
val jars1 = Path.split(Isabelle_System.getenv("ISABELLE_CLASSPATH")) val jars2 = contexts.flatMap(_.requirements)
val jars =
Library.distinct(jars1 ::: jars2).filterNot(path => contexts.exists(_.is_module(path)))
val sources =
(for {
context <- contexts.iterator
path <- context.sources.iterator if path.is_scala || path.is_java
} yield path).toList
(jars, sources)
}
lazyval isabelle_scala_files: Map[String, Path] =
Scala_Build.context(Path.ISABELLE_HOME, component = true)
.sources.iterator.foldLeft(Map.empty[String, Path]) { case (map, path) => if (path.is_scala) { val base = path.base.implode
map.get(base) match { case None => map + (base -> path) case Some(path2) => error("Conflicting base names: " + path + " vs. " + path2)
}
} else map
}
/* compile-time position */
def here: Here = { val exn = new Exception
exn.getStackTrace.toList match { case _ :: caller :: _ => val name = proper_string(caller.getFileName).getOrElse("") val line = caller.getLineNumber new Here(name, line) case _ => new Here("", 0)
}
}
class Here private[Scala_Project](name: String, line: Int) { overridedef toString: String = name + ":" + line def position: Position.T =
isabelle_scala_files.get(name) match { case Some(path) => Position.Line_File(line, path.implode) case None => Position.none
}
}
/* scala project */
val default_project_dir = Path.explode("$ISABELLE_HOME_USER/scala_project")
def package_name(source_file: Path): Option[String] = { val lines = Library.trim_split_lines(File.read(source_file)) valPackage = """\s*\bpackage\b\s*(?:object\b\s*)?((?:\w|\.)+)\b.*""".r
lines.collectFirst({ casePackage(name) => name })
}
def scala_project(
build_tool: Build_Tool,
project_dir: Path = default_project_dir,
more_sources: List[Path] = Nil,
symlinks: Boolean = false,
force: Boolean = false,
progress: Progress = new Progress
): Unit = { if (project_dir.file.exists) { val detect = project_dir.is_dir && build_tools.exists(_.detect_project(project_dir))
val (jars, sources) = isabelle_files
isabelle_scala_files
build_tool.init_project(project_dir, jars)
for (source <- sources ::: more_sources) { val dir = build_tool.package_dir(source) val target_dir = project_dir + dir if (!target_dir.is_dir) {
progress.echo(" Creating package directory: " + dir, verbose = true)
Isabelle_System.make_directory(target_dir)
} if (symlinks) Isabelle_System.symlink(source.absolute, target_dir, native = true) else Isabelle_System.copy_file(source, target_dir)
}
}
/* Isabelle tool wrapper */
val isabelle_tool =
Isabelle_Tool("scala_project", "setup IDE project for Isabelle/Java/Scala sources",
Scala_Project.here,
{ args => var build_tool: Option[Build_Tool] = None var project_dir = default_project_dir var symlinks = false var force = false var verbose = false
val getopts = Getopts("""
Usage: isabelle scala_project [OPTIONS] [MORE_SOURCES ...]
Options are:
-D DIR project directory (default: """ + default_project_dir + """)
-G use Gradle as build tool
-L make symlinks to original source files
-M use Maven as build tool
-f force update of existing directory
-v verbose
Setup project for Isabelle/Scala/jEdit --- to support common IDEs such
as IntelliJ IDEA. Either option -G or -M is mandatory to specify the
build tool. """, "D:" -> (arg => project_dir = Path.explode(arg)), "G" -> (_ => build_tool = Some(Gradle)), "L" -> (_ => symlinks = true), "M" -> (_ => build_tool = Some(Maven)), "f" -> (_ => force = true), "v" -> (_ => verbose = true))
val more_args = getopts(args)
val more_sources = more_args.map(Path.explode) val progress = new Console_Progress(verbose = verbose)
if (build_tool.isEmpty) {
error("Unspecified build tool: need to provide option -G or -M")
}
Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.
Bemerkung:
Die farbliche Syntaxdarstellung ist noch experimentell.