mirror of https://github.com/sbt/sbt.git
Escape path in proguard configuration in order to build on windows, refactor InstallExtarctProject in order to be a subclass of the Proguard trait
Removed path escaping on classpath... Remove unuseful log.error, change space indent with tab indent, restore file permission to 644
This commit is contained in:
parent
e0b453225e
commit
4fccc2fa88
|
|
@ -6,31 +6,24 @@ import sbt._
|
||||||
import java.io.File
|
import java.io.File
|
||||||
|
|
||||||
// TODO: use ProguardProject
|
// TODO: use ProguardProject
|
||||||
protected class InstallExtractProject(info: ProjectInfo, pluginProject: => InstallPluginProject) extends DefaultProject(info) with NoPublish
|
protected class InstallExtractProject(info: ProjectInfo, pluginProject: => InstallPluginProject) extends DefaultProject(info) with NoPublish with ProguardProject
|
||||||
{
|
{
|
||||||
override def unmanagedClasspath = super.unmanagedClasspath +++ info.sbtClasspath
|
override def unmanagedClasspath = super.unmanagedClasspath +++ info.sbtClasspath
|
||||||
|
override def rawPackage = `package`
|
||||||
|
override def rawJarPath = jarPath
|
||||||
|
|
||||||
private lazy val plugin = pluginProject
|
private lazy val plugin = pluginProject
|
||||||
val mainClassName = "sbt.extract.Main"
|
val mainClassName = "sbt.extract.Main"
|
||||||
val proguardConfigurationPath: Path = outputPath / "proguard.pro"
|
|
||||||
val toolsConfig = config("tools")
|
|
||||||
val defaultConfig = Configurations.Default
|
val defaultConfig = Configurations.Default
|
||||||
val proguardJar = "net.sf.proguard" % "proguard" % "4.3" % "tools"
|
|
||||||
def rootProjectDirectory = rootProject.info.projectPath
|
|
||||||
def outputJar = (plugin.outputPath ##) / defaultJarName
|
def outputJar = (plugin.outputPath ##) / defaultJarName
|
||||||
|
override val proguardConfigurationPath: Path = outputPath / "proguard.pro"
|
||||||
|
|
||||||
/******** Proguard *******/
|
/******** Proguard *******/
|
||||||
lazy val proguard = proguardTask dependsOn(`package`, writeProguardConfiguration, cleanProguard)
|
override lazy val proguard = proguardTask dependsOn(`package`, writeProguardConfiguration, cleanProguard)
|
||||||
lazy val writeProguardConfiguration = writeProguardConfigurationTask dependsOn `package`
|
override lazy val writeProguardConfiguration = writeProguardConfigurationTask dependsOn `package`
|
||||||
lazy val cleanProguard = cleanTask(outputJar)
|
lazy val cleanProguard = cleanTask(outputJar)
|
||||||
private def proguardTask =
|
|
||||||
task
|
override protected def writeProguardConfigurationTask =
|
||||||
{
|
|
||||||
val proguardClasspathString = Path.makeString(managedClasspath(toolsConfig).get)
|
|
||||||
val configFile = proguardConfigurationPath.asFile.getAbsolutePath
|
|
||||||
val exitValue = Process("java", List("-Xmx256M", "-cp", proguardClasspathString, "proguard.ProGuard", "@" + configFile)) ! log
|
|
||||||
if(exitValue == 0) None else Some("Proguard failed with nonzero exit code (" + exitValue + ")")
|
|
||||||
}
|
|
||||||
private def writeProguardConfigurationTask =
|
|
||||||
task
|
task
|
||||||
{
|
{
|
||||||
// the template for the proguard configuration file
|
// the template for the proguard configuration file
|
||||||
|
|
@ -39,15 +32,15 @@ protected class InstallExtractProject(info: ProjectInfo, pluginProject: => Insta
|
||||||
|-dontobfuscate
|
|-dontobfuscate
|
||||||
|-dontnote
|
|-dontnote
|
||||||
|-dontwarn
|
|-dontwarn
|
||||||
|-libraryjars %s
|
|-libraryjars "%s"
|
||||||
|%s
|
|%s
|
||||||
|-outjars %s
|
|-outjars "%s"
|
||||||
|-ignorewarnings
|
|-ignorewarnings
|
||||||
|-keep public class %s {
|
|-keep public class %s {
|
||||||
| public static void main(java.lang.String[]);
|
| public static void main(java.lang.String[]);
|
||||||
|}"""
|
|}"""
|
||||||
|
|
||||||
val defaultJar = jarPath.absolutePath
|
val defaultJar = mkpath(jarPath.absolutePath, '\"')
|
||||||
log.debug("proguard configuration using main jar " + defaultJar)
|
log.debug("proguard configuration using main jar " + defaultJar)
|
||||||
val externalDependencies = (mainCompileConditional.analysis.allExternals).map(_.getAbsoluteFile).filter(_.getName.endsWith(".jar"))
|
val externalDependencies = (mainCompileConditional.analysis.allExternals).map(_.getAbsoluteFile).filter(_.getName.endsWith(".jar"))
|
||||||
debugJars("external dependencies", externalDependencies)
|
debugJars("external dependencies", externalDependencies)
|
||||||
|
|
@ -55,14 +48,15 @@ protected class InstallExtractProject(info: ProjectInfo, pluginProject: => Insta
|
||||||
// if they are, they are specified with -injars, otherwise they are specified with -libraryjars
|
// if they are, they are specified with -injars, otherwise they are specified with -libraryjars
|
||||||
val (externalJars, libraryJars) = externalDependencies.toList.partition{jar => Path.relativize(rootProjectDirectory, jar).isDefined}
|
val (externalJars, libraryJars) = externalDependencies.toList.partition{jar => Path.relativize(rootProjectDirectory, jar).isDefined}
|
||||||
debugJars("library jars", libraryJars)
|
debugJars("library jars", libraryJars)
|
||||||
val externalJarStrings = externalJars.map( _ + "(!META-INF/**,!*.properties)")
|
val externalJarStrings = externalJars.map( mkpath(_) + "(!META-INF/**,!*.properties)")
|
||||||
// exclude properties files and manifests from scala-library jar
|
// exclude properties files and manifests from scala-library jar
|
||||||
val inJars = (defaultJar :: externalJarStrings).map("-injars " + _).mkString("\n")
|
val inJars = (defaultJar :: externalJarStrings).map("-injars " + _).mkString("\n")
|
||||||
|
|
||||||
val proguardConfiguration = outTemplate.stripMargin.format(libraryJars.mkString(File.pathSeparator), inJars, outputJar.absolutePath, mainClassName)
|
val proguardConfiguration = outTemplate.stripMargin.format(libraryJars.mkString(File.pathSeparator), inJars, outputJar.absolutePath, mainClassName)
|
||||||
log.debug("Proguard configuration written to " + proguardConfigurationPath)
|
log.debug("Proguard configuration written to " + proguardConfigurationPath)
|
||||||
FileUtilities.write(proguardConfigurationPath.asFile, proguardConfiguration, log)
|
FileUtilities.write(proguardConfigurationPath.asFile, proguardConfiguration, log)
|
||||||
}
|
}
|
||||||
|
|
||||||
private def debugJars[T](label: String, jars: Iterable[T]): Unit =
|
private def debugJars[T](label: String, jars: Iterable[T]): Unit =
|
||||||
log.debug("proguard configuration " + label + ": \n\t" + jars.mkString("\n\t"))
|
log.debug("proguard configuration " + label + ": \n\t" + jars.mkString("\n\t"))
|
||||||
}
|
}
|
||||||
|
|
@ -62,17 +62,18 @@ trait ProguardProject extends BasicScalaProject
|
||||||
lines.mkString("\n")
|
lines.mkString("\n")
|
||||||
}
|
}
|
||||||
|
|
||||||
def mkpath(f: File) = '\"' + f.getAbsolutePath + '\"'
|
def mkpath(f: File) : String = mkpath(f.getAbsolutePath, '\"')
|
||||||
private def proguardTask =
|
def mkpath(path: String, delimiter : Char) : String = delimiter + path + delimiter
|
||||||
|
protected def proguardTask =
|
||||||
task
|
task
|
||||||
{
|
{
|
||||||
FileUtilities.clean(outputJar :: Nil, log)
|
FileUtilities.clean(outputJar :: Nil, log)
|
||||||
val proguardClasspathString = Path.makeString(managedClasspath(toolsConfig).get)
|
val proguardClasspathString = Path.makeString(managedClasspath(toolsConfig).get)
|
||||||
val configFile = proguardConfigurationPath.asFile.getAbsolutePath
|
val configFile = mkpath(proguardConfigurationPath.asFile.getAbsolutePath, '\'')
|
||||||
val exitValue = Process("java", List("-Xmx256M", "-cp", proguardClasspathString, "proguard.ProGuard", "@" + configFile)) ! log
|
val exitValue = Process("java", List("-Xmx256M", "-cp", proguardClasspathString, "proguard.ProGuard", "-include " + configFile)) ! log
|
||||||
if(exitValue == 0) None else Some("Proguard failed with nonzero exit code (" + exitValue + ")")
|
if(exitValue == 0) None else Some("Proguard failed with nonzero exit code (" + exitValue + ")")
|
||||||
}
|
}
|
||||||
private def writeProguardConfigurationTask =
|
protected def writeProguardConfigurationTask =
|
||||||
task
|
task
|
||||||
{
|
{
|
||||||
val dependencies = mainDependencies.snapshot
|
val dependencies = mainDependencies.snapshot
|
||||||
|
|
@ -88,4 +89,4 @@ trait ProguardProject extends BasicScalaProject
|
||||||
log.debug("Proguard configuration written to " + proguardConfigurationPath)
|
log.debug("Proguard configuration written to " + proguardConfigurationPath)
|
||||||
FileUtilities.write(proguardConfigurationPath.asFile, proguardConfiguration, log)
|
FileUtilities.write(proguardConfigurationPath.asFile, proguardConfiguration, log)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue