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.
Attributes
- Graph
-
- Supertypes
-
class Objecttrait Matchableclass Any
- Self type
-
JarUtils.type
Members list
Type members
Classlikes
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.
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"
Attributes
- Companion
- object
- Supertypes
-
class AnyValtrait Matchableclass Any
Attributes
- Companion
- class
- Supertypes
-
class Objecttrait Matchableclass Any
- Self type
-
ClassInJar.type
Attributes
- Supertypes
-
class Objecttrait Matchableclass Any
Types
Represents a path to a class file located inside a jar, relative to this jar
Represents a path to a class file located inside a jar, relative to this jar
Attributes
Value members
Concrete methods
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.
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.
Attributes
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.
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.
Attributes
Checks if given jared class exists
Checks if given jared class exists
Attributes
Return JAR component of class-in-jar notation.
Return JAR component of class-in-jar notation.
Attributes
Extracts a jar file from the output if it is set to be a single jar.
Extracts a jar file from the output if it is set to be a single jar.
Attributes
Adds plain files to specified jar file. See sbt.internal.inc.IndexBasedZipOps#includeInArchive for details.
Adds plain files to specified jar file. See sbt.internal.inc.IndexBasedZipOps#includeInArchive for details.
Attributes
Checks if given file stores a ClassInJar
Checks if given file stores a ClassInJar
Attributes
Determines if Straight to Jar compilations is enabled by inspecting if compilation output is a jar file
Determines if Straight to Jar compilations is enabled by inspecting if compilation output is a jar file
Attributes
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.
Attributes
Lists class file entries in jar e.g. sbt/internal/inc/JarUtils.class
Lists class file entries in jar e.g. sbt/internal/inc/JarUtils.class
Attributes
Lists file entries in jar e.g. sbt/internal/inc/JarUtils.class
Lists file entries in jar e.g. sbt/internal/inc/JarUtils.class
Attributes
Merges contents of two jars. See sbt.internal.inc.IndexBasedZipOps#mergeArchives for details.
Merges contents of two jars. See sbt.internal.inc.IndexBasedZipOps#mergeArchives for details.
Attributes
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.
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.
Attributes
Reads timestamp of given jared class
Reads timestamp of given jared class
Attributes
Reads all timestamps from given jar file. Returns a function that allows to access them by ClassInJar
wrapped in File
.
Reads all timestamps from given jar file. Returns a function that allows to access them by ClassInJar
wrapped in File
.
Attributes
Removes specified entries from a jar file.
Removes specified entries from a jar file.
Attributes
Ensures that temporary directory exists.
Ensures that temporary directory exists.
Value parameters
- temporaryClassesDirectory
-
path to temporary directory for classes. If not specified, a default will be used.
Attributes
Reads current index of a jar file to allow restoring it later with unstashIndex
Reads current index of a jar file to allow restoring it later with unstashIndex
Attributes
Replaces index in given jar file with specified one
Replaces index in given jar file with specified one
Attributes
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.
Value parameters
- callback
-
analysis callback used to set previus jar
- compile
-
function that given extra classpath for compiler runs the compilation
- output
-
output for scalac compilation
Attributes
Concrete fields
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.
Attributes
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.