Packages

o

sbt.internal.inc

JarUtils

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.

Linear Supertypes
AnyRef, Any
Ordering
  1. Alphabetic
  2. By Inheritance
Inherited
  1. JarUtils
  2. AnyRef
  3. Any
  1. Hide All
  2. Show All
Visibility
  1. Public
  2. All

Type Members

  1. type ClassFilePath = String

    Represents a path to a class file located inside a jar, relative to this jar

  2. final class ClassInJar extends AnyVal

    ClassInJar is an identifier for a class located inside a jar.

    ClassInJar is 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 with File.separatorChar as the actual string is usually kept in File object.

    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"

  3. sealed abstract class OutputJarContent extends AnyRef

Value Members

  1. final def !=(arg0: Any): Boolean
    Definition Classes
    AnyRef → Any
  2. final def ##(): Int
    Definition Classes
    AnyRef → Any
  3. final def ==(arg0: Any): Boolean
    Definition Classes
    AnyRef → Any
  4. final def asInstanceOf[T0]: T0
    Definition Classes
    Any
  5. 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.

  6. def clone(): AnyRef
    Attributes
    protected[lang]
    Definition Classes
    AnyRef
    Annotations
    @throws( ... ) @native()
  7. def createOutputJarContent(output: xsbti.compile.Output): OutputJarContent

    The returned OutputJarContent object provides access to current content of output jar.

    The returned OutputJarContent object 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 reset before 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 to dependencyPhaseCompleted is 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 to scalacRunCompleted method. 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 classes addClasses should 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 through removeClasses method.

  8. final def eq(arg0: AnyRef): Boolean
    Definition Classes
    AnyRef
  9. def equals(arg0: Any): Boolean
    Definition Classes
    AnyRef → Any
  10. def exists(jc: ClassInJar): Boolean

    Checks if given jared class exists

  11. def finalize(): Unit
    Attributes
    protected[lang]
    Definition Classes
    AnyRef
    Annotations
    @throws( classOf[java.lang.Throwable] )
  12. final def getClass(): Class[_]
    Definition Classes
    AnyRef → Any
    Annotations
    @native()
  13. def getJarInClassInJar(path: Path): Option[Path]

    Return JAR component of class-in-jar notation.

  14. def getOutputJar(output: xsbti.compile.Output): Option[Path]

    Extracts a jar file from the output if it is set to be a single jar.

  15. def hashCode(): Int
    Definition Classes
    AnyRef → Any
    Annotations
    @native()
  16. 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.

  17. def isClassInJar(file: File): Boolean

    Checks if given file stores a ClassInJar

  18. def isCompilingToJar(output: xsbti.compile.Output): Boolean

    Determines if Straight to Jar compilations is enabled by inspecting if compilation output is a jar file

  19. final def isInstanceOf[T0]: Boolean
    Definition Classes
    Any
  20. 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.

  21. 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.

  22. 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

  23. 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

  24. 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.

  25. final def ne(arg0: AnyRef): Boolean
    Definition Classes
    AnyRef
  26. final def notify(): Unit
    Definition Classes
    AnyRef
    Annotations
    @native()
  27. final def notifyAll(): Unit
    Definition Classes
    AnyRef
    Annotations
    @native()
  28. def preparePreviousJar(output: xsbti.compile.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.

  29. val prevJarPrefix: String
  30. def readModifiedTime(jc: ClassInJar): Long

    Reads timestamp of given jared class

  31. 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 ClassInJar wrapped in File.

  32. def removeFromJar(jarFile: Path, classes: Iterable[ClassFilePath]): Unit

    Removes specified entries from a jar file.

  33. 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.

  34. 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.

  35. def stashIndex(jar: Path): CentralDir

    Reads current index of a jar file to allow restoring it later with unstashIndex

  36. final def synchronized[T0](arg0: ⇒ T0): T0
    Definition Classes
    AnyRef
  37. def toString(): String
    Definition Classes
    AnyRef → Any
  38. def unstashIndex(jar: Path, index: CentralDir): Unit

    Replaces index in given jar file with specified one

  39. final def wait(): Unit
    Definition Classes
    AnyRef
    Annotations
    @throws( ... )
  40. final def wait(arg0: Long, arg1: Int): Unit
    Definition Classes
    AnyRef
    Annotations
    @throws( ... )
  41. final def wait(arg0: Long): Unit
    Definition Classes
    AnyRef
    Annotations
    @throws( ... ) @native()
  42. def withPreviousJar(output: xsbti.compile.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

  43. object ClassInJar

Inherited from AnyRef

Inherited from Any

Ungrouped