Skip to content
Browse files

closes #79: Add setting to always use absolute paths for library depe…

…ndencies
  • Loading branch information...
1 parent 5df9260 commit c3aa1eae8ed14328d3e2e6a4dc5f98a5bd12231e Heiko Seeberger committed Mar 2, 2012
View
35 sbteclipse-core/src/main/scala/com/typesafe/sbteclipse/core/Eclipse.scala
@@ -107,15 +107,21 @@ private object Eclipse {
project <- Project.getProject(ref, structure) if project.aggregate.isEmpty || !skipParents
} yield {
val configs = configurations(ref)
- (classpathEntryTransformerFactory(ref).createTransformer(ref, state) |@|
+ val applic = classpathEntryTransformerFactory(ref).createTransformer(ref, state) |@|
name(ref) |@|
buildDirectory |@|
baseDirectory(ref) |@|
mapConfigs(configs, srcDirectories(ref, createSrc(ref))) |@|
scalacOptions(ref) |@|
mapConfigs(configs, externalDependencies(ref, withSourceArg getOrElse withSource(ref))) |@|
mapConfigs(configs, projectDependencies(ref, project))
- )(effect(jreContainer(executionEnvironmentArg orElse executionEnvironment(ref)), preTasks(ref)))
+ applic(
+ effect(
+ jreContainer(executionEnvironmentArg orElse executionEnvironment(ref)),
+ preTasks(ref),
+ relativizeLibs(ref)
+ )
+ )
}
effects.sequence[ValidationNELS, IO[String]] map (_.sequence)
}
@@ -139,7 +145,8 @@ private object Eclipse {
def effect(
jreContainer: String,
- preTasks: Seq[(TaskKey[_], ProjectRef)])(
+ preTasks: Seq[(TaskKey[_], ProjectRef)],
+ relativizeLibs: Boolean)(
classpathEntryTransformer: Seq[EclipseClasspathEntry] => Seq[EclipseClasspathEntry],
name: String,
buildDirectory: File,
@@ -157,6 +164,7 @@ private object Eclipse {
classpathEntryTransformer,
buildDirectory,
baseDirectory,
+ relativizeLibs,
srcDirectories,
externalDependencies,
projectDependencies,
@@ -188,6 +196,7 @@ private object Eclipse {
classpathEntryTransformer: Seq[EclipseClasspathEntry] => Seq[EclipseClasspathEntry],
buildDirectory: File,
baseDirectory: File,
+ relativizeLibs: Boolean,
srcDirectories: Seq[(File, File)],
externalDependencies: Seq[Lib],
projectDependencies: Seq[String],
@@ -196,7 +205,7 @@ private object Eclipse {
val srcEntriesIoSeq = for ((dir, output) <- srcDirectories) yield srcEntry(baseDirectory, output)(dir)
for (srcEntries <- srcEntriesIoSeq.sequence) yield {
val entries = srcEntries ++
- (externalDependencies map libEntry(buildDirectory, baseDirectory)) ++
+ (externalDependencies map libEntry(buildDirectory, baseDirectory, relativizeLibs)) ++
(projectDependencies map EclipseClasspathEntry.Project) ++
(Seq(jreContainer) map EclipseClasspathEntry.Con) ++
(Seq("bin") map EclipseClasspathEntry.Output)
@@ -210,15 +219,24 @@ private object Eclipse {
EclipseClasspathEntry.Src(relativize(baseDirectory, srcDirectory), output(baseDirectory, classDirectory))
}
- def libEntry(buildDirectory: File, baseDirectory: File)(lib: Lib)(implicit state: State) = {
+ def libEntry(
+ buildDirectory: File,
+ baseDirectory: File,
+ relativizeLibs: Boolean)(
+ lib: Lib)(
+ implicit state: State) = {
def path(file: File) = {
val relativizedBase =
if (buildDirectory === baseDirectory) Some(".") else IO.relativize(buildDirectory, baseDirectory)
val relativizedFile = IO.relativize(buildDirectory, file)
val relativized = (relativizedBase |@| relativizedFile)((base, file) =>
- "%s/%s".format(base split FileSepPattern map (part => if (part != ".") ".." else part) mkString FileSep, file)
+ "%s%s%s".format(
+ base split FileSepPattern map (part => if (part != ".") ".." else part) mkString FileSep,
+ FileSep,
+ file
+ )
)
- relativized getOrElse file.getAbsolutePath
+ if (relativizeLibs) relativized getOrElse file.getAbsolutePath else file.getAbsolutePath
}
EclipseClasspathEntry.Lib(path(lib.binary), lib.source map path)
}
@@ -371,6 +389,9 @@ private object Eclipse {
def preTasks(ref: ProjectRef)(implicit state: State) =
setting(EclipseKeys.preTasks in ref).fold(_ => Seq.empty, _.zipAll(Seq.empty, null, ref))
+ def relativizeLibs(ref: ProjectRef)(implicit state: State) =
+ setting(EclipseKeys.relativizeLibs in ref).fold(_ => true, id)
+
// IO
def saveXml(file: File, xml: Elem) =
View
5 sbteclipse-core/src/main/scala/com/typesafe/sbteclipse/core/EclipsePlugin.scala
@@ -91,6 +91,11 @@ trait EclipsePlugin {
"The tasks to be evaluated prior to creating the Eclipse project definition."
)
+ val relativizeLibs: SettingKey[Boolean] =
+ SettingKey[Boolean](
+ prefix("relativize-libs"),
+ "Relativize the paths to the libraries?")
+
private def prefix(key: String) = "eclipse-" + key
}
View
2 sbteclipse-plugin/src/sbt-test/sbteclipse/00-defaults/project/plugins.sbt
@@ -1,2 +1,2 @@
-addSbtPlugin("com.typesafe.sbteclipse" % "sbteclipse-plugin" % "2.0.0-SNAPSHOT")
+addSbtPlugin("com.typesafe.sbteclipse" % "sbteclipse-plugin" % "2.1.0-SNAPSHOT")
View
2 sbteclipse-plugin/src/sbt-test/sbteclipse/01-structure/project/plugins.sbt
@@ -1,2 +1,2 @@
-addSbtPlugin("com.typesafe.sbteclipse" % "sbteclipse-plugin" % "2.0.0-SNAPSHOT")
+addSbtPlugin("com.typesafe.sbteclipse" % "sbteclipse-plugin" % "2.1.0-SNAPSHOT")
View
8 sbteclipse-plugin/src/sbt-test/sbteclipse/02-contents/build.sbt
@@ -138,6 +138,14 @@ TaskKey[Unit]("verify-classpath-xml-subb") <<= baseDirectory map { dir =>
error("""Not expected .classpath of subb project to contain <classpathentry kind="..." path="...subc..." output="..." /> """)
}
+TaskKey[Unit]("verify-classpath-xml-subc") <<= baseDirectory map { dir =>
+ val classpath = XML.loadFile(dir / "sub" / "subc" / ".classpath")
+ if ((classpath \ "classpathentry") != (classpath \ "classpathentry").distinct)
+ // lib entries with absolute paths
+ if (!(classpath.child contains <classpathentry kind="lib" path={ "%s/lib_managed/jars/biz.aQute/bndlib/bndlib-1.50.0.jar".format(dir.getCanonicalPath) } />))
+ error("""Expected .classpath of subc project to contain <classpathentry kind="lib" path="%s/lib_managed/jars/biz.aQute/bndlib/bndlib-1.50.0.jar" />: %s""".format(dir.getCanonicalPath, classpath))
+}
+
TaskKey[Unit]("verify-settings") <<= baseDirectory map { dir =>
val settings = {
val p = new Properties
View
9 sbteclipse-plugin/src/sbt-test/sbteclipse/02-contents/project/Build.scala
@@ -67,6 +67,13 @@ object Build extends Build {
lazy val subc = Project(
"subc",
- new File("sub/subc")
+ new File("sub/subc"),
+ settings = Project.defaultSettings ++ Seq(
+ libraryDependencies ++= Seq(
+ "biz.aQute" % "bndlib" % "1.50.0"
+ ),
+ retrieveManaged := true,
+ EclipseKeys.relativizeLibs := false
+ )
)
}
View
2 sbteclipse-plugin/src/sbt-test/sbteclipse/02-contents/project/plugins.sbt
@@ -1,2 +1,2 @@
-addSbtPlugin("com.typesafe.sbteclipse" % "sbteclipse-plugin" % "2.0.0-SNAPSHOT")
+addSbtPlugin("com.typesafe.sbteclipse" % "sbteclipse-plugin" % "2.1.0-SNAPSHOT")
View
1 sbteclipse-plugin/src/sbt-test/sbteclipse/02-contents/test
@@ -7,4 +7,5 @@ $ mkdir target/scala-2.9.1/src_managed/main
> verify-classpath-xml-sub
> verify-classpath-xml-suba
> verify-classpath-xml-subb
+> verify-classpath-xml-subc
> verify-settings

0 comments on commit c3aa1ea

Please sign in to comment.
Something went wrong with that request. Please try again.