object JarUtils
This is a utility class that provides a set of functions that are used to implement straight to jar compilation.
xsbt.JarUtils is a class that has similar purpose and duplicates some of the code, as it is difficult to share it.
- Alphabetic
- By Inheritance
- JarUtils
- AnyRef
- Any
- Hide All
- Show All
- Public
- Protected
Type Members
- type ClassFilePath = String
Represents a path to a class file located inside a jar, relative to this jar
- final class ClassInJar extends AnyVal
ClassInJaris an identifier for a class located inside a jar.ClassInJaris an identifier for a class located inside a jar. For plain class files it is enough to simply use the actual file system path. A class in a jar is identified as a path to the jar and path to the class within that jar (RelClass). Those two values are held in one string separated by!. Slashes in both paths are consistent withFile.separatorCharas the actual string is usually kept inFileobject.As an example: given a jar file "C:\develop\zinc\target\output.jar" and a relative path to the class "sbt/internal/inc/Compile.class" The resulting identifier would be: "C:\develop\zinc\target\output.jar!sbt\internal\inc\Compile.class"
- sealed abstract class OutputJarContent extends AnyRef
Value Members
- final def !=(arg0: Any): Boolean
- Definition Classes
- AnyRef → Any
- final def ##: Int
- Definition Classes
- AnyRef → Any
- final def ==(arg0: Any): Boolean
- Definition Classes
- AnyRef → Any
- final def asInstanceOf[T0]: T0
- Definition Classes
- Any
- def cleanupPreviousJar(prevJar: File, outputJar: File): Unit
Performs cleanup after successful compilation that involved previous jar.
Performs cleanup after successful compilation that involved previous jar. It merges the previous jar with the new output and puts the merged file back into output jar path.
- def clone(): AnyRef
- Attributes
- protected[lang]
- Definition Classes
- AnyRef
- Annotations
- @throws(classOf[java.lang.CloneNotSupportedException]) @native()
- def createOutputJarContent(output: Output): OutputJarContent
The returned
OutputJarContentobject provides access to current content of output jar.The returned
OutputJarContentobject provides access to current content of output jar. It is prepared to be accessed from zinc's custom compiler phases. With some assumptions on how it works the content can be cached and read only when necessary.Implementation details: The content has to be
resetbefore each zinc run. This sets the output and reads the current contents of output jar if it exists. The next reading will be necessary in xsbt-analyzer phase which is after jvm phase, so the jar with new contents will appear. To figure out that it is in that place, a call todependencyPhaseCompletedis expected. As content is not accessed between dependency and analysis phases, we can be sure that we are after jvm. The contents of jar will not change until next scalac run (except for javac case) so we should not read the content. This is ensured by a call toscalacRunCompletedmethod. After scalac run, it is possible that javac will run, and its output will be added to the output jar. To have consistent state, after adding those classesaddClassesshould be called. Thanks to this we know what is the content of prev jar during the compilation, without the need to actually read it. The completion of next dependency phase will trigger reading the output jar again. Note that at the point of reading we have both prev jar and new output jar with just compiled classes so the contents of those (currently stored and just read) have bo be combined. Last thing to do is track class deletions while pruning between iterations, which is done throughremoveClassesmethod. - final def eq(arg0: AnyRef): Boolean
- Definition Classes
- AnyRef
- def equals(arg0: AnyRef): Boolean
- Definition Classes
- AnyRef → Any
- def exists(jc: ClassInJar): Boolean
Checks if given jared class exists
- def finalize(): Unit
- Attributes
- protected[lang]
- Definition Classes
- AnyRef
- Annotations
- @throws(classOf[java.lang.Throwable])
- final def getClass(): Class[_ <: AnyRef]
- Definition Classes
- AnyRef → Any
- Annotations
- @native()
- def getJarInClassInJar(path: Path): Option[Path]
Return JAR component of class-in-jar notation.
- def getOutputJar(output: Output): Option[Path]
Extracts a jar file from the output if it is set to be a single jar.
- def hashCode(): Int
- Definition Classes
- AnyRef → Any
- Annotations
- @native()
- def includeInJar(jar: File, files: Seq[(File, ClassFilePath)]): Unit
Adds plain files to specified jar file.
Adds plain files to specified jar file. See sbt.internal.inc.IndexBasedZipOps#includeInArchive for details.
- def isClassInJar(file: File): Boolean
Checks if given file stores a ClassInJar
- def isCompilingToJar(output: Output): Boolean
Determines if Straight to Jar compilations is enabled by inspecting if compilation output is a jar file
- final def isInstanceOf[T0]: Boolean
- Definition Classes
- Any
- val javacOptions: Set[ClassFilePath]
Options that have to be specified when running javac in order for Straight to Jar to work properly.
Options that have to be specified when running javac in order for Straight to Jar to work properly.
-XDuseOptimizedZip=false holds jars open that causes problems with locks on Windows.
- def javacTempOutput(outputJar: Path): Path
As some javac implementations do not support compiling directly to jar it is required to change its output to a directory that is temporary, as after compilation the plain classes are put into a zip file and merged with the output jar.
As some javac implementations do not support compiling directly to jar it is required to change its output to a directory that is temporary, as after compilation the plain classes are put into a zip file and merged with the output jar.
This method returns path to this directory based on output jar. The result of this method has to be deterministic as it is called from different places independently.
- def listClassFiles(jar: File): Seq[String]
Lists class file entries in jar e.g.
Lists class file entries in jar e.g. sbt/internal/inc/JarUtils.class
- def listFiles(jar: Path): Seq[String]
Lists file entries in jar e.g.
Lists file entries in jar e.g. sbt/internal/inc/JarUtils.class
- def mergeJars(into: File, from: File): Unit
Merges contents of two jars.
Merges contents of two jars. See sbt.internal.inc.IndexBasedZipOps#mergeArchives for details.
- final def ne(arg0: AnyRef): Boolean
- Definition Classes
- AnyRef
- final def notify(): Unit
- Definition Classes
- AnyRef
- Annotations
- @native()
- final def notifyAll(): Unit
- Definition Classes
- AnyRef
- Annotations
- @native()
- def preparePreviousJar(output: Output): Option[(File, File)]
If compilation to jar is enabled and previous jar existed will prepare the prev jar, i.e.
If compilation to jar is enabled and previous jar existed will prepare the prev jar, i.e. move the existing output to temporary location. It will return tuple of the path to moved prev jar and path to output jar. The returned prev jar file should be added to the classpath of the compiler.
- val prevJarPrefix: String
- def readModifiedTime(jc: ClassInJar): Long
Reads timestamp of given jared class
- def readStamps(jar: Path): (Path) => Long
Reads all timestamps from given jar file.
Reads all timestamps from given jar file. Returns a function that allows to access them by
ClassInJarwrapped inFile. - def removeFromJar(jarFile: Path, classes: Iterable[ClassFilePath]): Unit
Removes specified entries from a jar file.
- val scalacOptions: Set[ClassFilePath]
Options that have to be specified when running scalac in order for Straight to Jar to work properly.
Options that have to be specified when running scalac in order for Straight to Jar to work properly.
-YdisableFlatCpCaching is needed to disable caching the output jar that changes between compilation runs (incremental compilation cycles). Caching may hide those changes and lead into incorrect results.
- def setupTempClassesDir(temporaryClassesDirectory: Option[Path]): Unit
Ensures that temporary directory exists.
Ensures that temporary directory exists.
- temporaryClassesDirectory
path to temporary directory for classes. If not specified, a default will be used.
- def stashIndex(jar: Path): CentralDir
Reads current index of a jar file to allow restoring it later with
unstashIndex - final def synchronized[T0](arg0: => T0): T0
- Definition Classes
- AnyRef
- def toString(): String
- Definition Classes
- AnyRef → Any
- def unstashIndex(jar: Path, index: CentralDir): Unit
Replaces index in given jar file with specified one
- final def wait(): Unit
- Definition Classes
- AnyRef
- Annotations
- @throws(classOf[java.lang.InterruptedException])
- final def wait(arg0: Long, arg1: Int): Unit
- Definition Classes
- AnyRef
- Annotations
- @throws(classOf[java.lang.InterruptedException])
- final def wait(arg0: Long): Unit
- Definition Classes
- AnyRef
- Annotations
- @throws(classOf[java.lang.InterruptedException]) @native()
- def withPreviousJar(output: Output)(compile: (Seq[Path]) => Unit): Unit
Runs the compilation with previous jar if required.
Runs the compilation with previous jar if required.
When compiling directly to a jar, scalac will produce a jar file, if one exists it will be overwritten rather than updated. For sake of incremental compilation it is required to merge the output from previous compilation(s) and the current one. To make it work, the jar output from previous compilation is stored aside (renamed) to avoid overwrite. The compilation is run normally to the specified output jar. The produced output jar is then merged with jar from previous compilation(s).
Classes from previous jar need to be available for the current compiler run - they need to be added to the classpath. This is implemented by taking a function that given additional classpath runs the compilation.
If compilation fails, it does not produce a jar, the previous jar is simply reverted (moved to output jar path).
If the previous output does not exist or the output is not a jar at all (JarUtils feature is disabled) this function runs a normal compilation.
- output
output for scalac compilation
- compile
function that given extra classpath for compiler runs the compilation
- object ClassInJar