Skip to content

Commit

Permalink
closes #34: Use relative path for local libraries
Browse files Browse the repository at this point in the history
  • Loading branch information
Heiko Seeberger committed Dec 17, 2011
1 parent 80cc2db commit 6130d40
Show file tree
Hide file tree
Showing 6 changed files with 55 additions and 13 deletions.
1 change: 1 addition & 0 deletions .gitignore
@@ -1,5 +1,6 @@
# SBT
boot/
lib_managed/
target/
.history

Expand Down
30 changes: 27 additions & 3 deletions README.rst
@@ -1,7 +1,30 @@
sbteclipse
==========

Plugin for `sbt`_ to create `Eclipse`_ project files. More details to come ...
Plugin for `sbt`_ to create `Eclipse`_ project files. Please see the `Documentation`_ for information about installing and using sbteclipse. Information about mailing lists, contribution policy and license can be found below.


For the impatient
-----------------

- Add sbteclipse to your plugin definition, replacing the version number with whatever version you want to use:

::

addSbtPlugin("com.typesafe.sbteclipse" % "sbteclipse" % "2.0.0")

- In sbt use the command *eclipse* to create Eclipse project files

::

> eclipse


- In Eclipse use the *Import Wizard to import *Existing Projects into Workspace*

::

addSbtPlugin("com.typesafe.sbteclipse" % "sbteclipse" % "2.0.0")


Mailing list
Expand All @@ -13,15 +36,16 @@ Please use the `sbt mailing list`_ and prefix the subject with "[sbteclipse]".
Contribution policy
-------------------

Contributions via GitHub pull requests are gladly accepted from their original author. Along with any pull requests, please state that the contribution is your original work and that you license the work to the project under the project's open source license.
Contributions via GitHub pull requests are gladly accepted from their original author. Along with any pull requests, please state that the contribution is your original work and that you license the work to the project under the project's open source license. Whether or not you state this explicitly, by submitting any copyrighted material via pull request, email, or other means you agree to license the material under the project's open source license and warrant that you have the legal authority to do so.


License
-------

This code is open source software licensed under the `Apache 2.0 License`_. Feel free to use it accordingly.

.. _`sbt`: https://github.com/harrah/xsbt/
.. _`sbt`: http://github.com/harrah/xsbt/
.. _`Eclipse`: http://www.eclipse.org/
.. _`Documentation`: http://github.com/typesafehub/sbteclipse/wiki/
.. _`sbt mailing list`: mailto:simple-build-tool@googlegroups.com
.. _`Apache 2.0 License`: http://www.apache.org/licenses/LICENSE-2.0.html
25 changes: 20 additions & 5 deletions src/main/scala/com/typesafe/sbteclipse/Eclipse.scala
Expand Up @@ -21,7 +21,7 @@ package com.typesafe.sbteclipse
import EclipsePlugin.{ ClasspathEntry, EclipseExecutionEnvironment }
import java.io.FileWriter
import java.util.Properties
import sbt.{ Command, Configurations, File, IO, Keys, Project, ProjectRef, ResolvedProject, State, richFile }
import sbt.{ Command, Configurations, File, IO, Keys, Project, ProjectRef, ResolvedProject, State, ThisBuild, richFile }
import sbt.CommandSupport.logger
import scala.collection.JavaConverters
import scala.xml.{ Elem, NodeSeq, PrettyPrinter }
Expand Down Expand Up @@ -76,6 +76,7 @@ private object Eclipse {
project <- Project.getProject(ref, structure) if project.aggregate.isEmpty || !skipParents
} yield {
(name(ref) |@|
buildDirectory(ref) |@|
baseDirectory(ref) |@|
compileSrcDirectories(ref) |@|
testSrcDirectories(ref) |@|
Expand Down Expand Up @@ -105,6 +106,7 @@ private object Eclipse {
/*target: String,*/
classpathEntryCollector: PartialFunction[ClasspathEntry, ClasspathEntry])(
name: String,
buildDirectory: File,
baseDirectory: File,
compileSrcDirectories: (Seq[File], File),
testSrcDirectories: (Seq[File], File),
Expand All @@ -118,6 +120,7 @@ private object Eclipse {
projectXml(name),
classpath(
classpathEntryCollector,
buildDirectory,
baseDirectory,
compileSrcDirectories,
testSrcDirectories,
Expand All @@ -142,6 +145,7 @@ private object Eclipse {

def classpath(
classpathEntryCollector: PartialFunction[ClasspathEntry, ClasspathEntry],
buildDirectory: File,
baseDirectory: File,
compileSrcDirectories: (Seq[File], File),
testSrcDirectories: (Seq[File], File),
Expand All @@ -152,7 +156,7 @@ private object Eclipse {
Seq(
compileSrcDirectories._1 flatMap srcEntry(baseDirectory, compileSrcDirectories._2),
testSrcDirectories._1 flatMap srcEntry(baseDirectory, testSrcDirectories._2),
externalDependencies map (file => ClasspathEntry.Lib(file.getAbsolutePath)),
externalDependencies map libEntry(buildDirectory, true),
projectDependencies map ClasspathEntry.Project,
Seq("org.eclipse.jdt.launching.JRE_CONTAINER") map ClasspathEntry.Con, // TODO Optionally use execution env!
Seq(output(baseDirectory, compileSrcDirectories._2)) map ClasspathEntry.Output
Expand All @@ -169,15 +173,22 @@ private object Eclipse {
None
}

def relativize(baseDirectory: File, file: File) = IO.relativize(baseDirectory, file).get

def output(baseDirectory: File, classDirectory: File) = relativize(baseDirectory, classDirectory)
def libEntry(buildDirectory: File, retrieveManaged: Boolean)(file: File)(implicit state: State) =
ClasspathEntry.Lib(
if (retrieveManaged)
IO.relativize(buildDirectory, file) getOrElse file.getAbsolutePath
else
file.getAbsolutePath
)

// Getting and transforming settings and task results

def name(ref: ProjectRef)(implicit state: State) =
setting(Keys.name, ref)

def buildDirectory(ref: ProjectRef)(implicit state: State) =
setting(Keys.baseDirectory, ThisBuild)

def baseDirectory(ref: ProjectRef)(implicit state: State) =
setting(Keys.baseDirectory, ref)

Expand Down Expand Up @@ -243,6 +254,10 @@ private object Eclipse {

def srcDirsToOutput(sourceDirectories: Seq[File], resourceDirectories: Seq[File], output: File) =
(sourceDirectories ++ resourceDirectories).distinct -> output

def relativize(baseDirectory: File, file: File) = IO.relativize(baseDirectory, file).get

def output(baseDirectory: File, classDirectory: File) = relativize(baseDirectory, classDirectory)
}

private object EclipseOpts {
Expand Down
7 changes: 4 additions & 3 deletions src/main/scala/com/typesafe/sbteclipse/package.scala
Expand Up @@ -29,6 +29,7 @@ import sbt.{
Incomplete,
Project,
ProjectRef,
Reference,
Result,
TaskKey,
SettingKey,
Expand All @@ -50,12 +51,12 @@ package object sbteclipse {

def setting[A](
key: SettingKey[A],
ref: ProjectRef,
reference: Reference,
configuration: Configuration = Configurations.Compile)(
implicit state: State): ValidationNELS[A] = {
key in (ref, configuration) get structure.data match {
key in (reference, configuration) get structure.data match {
case Some(a) => a.success
case None => "Missing setting '%s' for '%s'!".format(key.key, ref.project).failNel
case None => "Missing setting '%s' for '%s'!".format(key.key, reference).failNel
}
}

Expand Down
4 changes: 2 additions & 2 deletions src/sbt-test/sbteclipse/02-contents/build.sbt
Expand Up @@ -57,8 +57,8 @@ TaskKey[Unit]("verify-classpath-xml-subb") <<= baseDirectory map { dir =>
if ((classpath \ "classpathentry") != (classpath \ "classpathentry").distinct)
error("Expected .classpath of subb project not to contain duplicate entries: %s" format classpath)
// lib entries without sources
if (!(classpath.child contains <classpathentry kind="lib" path={ home + "/.ivy2/cache/com.weiglewilczek.slf4s/slf4s_2.9.1/jars/slf4s_2.9.1-1.0.7.jar" } />))
error("""Expected .classpath of subb project to contain <classpathentry kind="lib" path={ home + "/.ivy2/cache/com.weiglewilczek.slf4s/slf4s_2.9.1/jars/slf4s_2.9.1-1.0.7.jar" } />: %s""" format classpath)
if (!(classpath.child contains <classpathentry kind="lib" path="lib_managed/jars/com.weiglewilczek.slf4s/slf4s_2.9.1/slf4s_2.9.1-1.0.7.jar" />))
error("""Expected .classpath of subb project to contain <classpathentry kind="lib" path="lib_managed/jars/com.weiglewilczek.slf4s/slf4s_2.9.1/slf4s_2.9.1-1.0.7.jar" />: %s""" format classpath)
// project dependencies
if (!(classpath.child contains <classpathentry kind="src" path="/suba" exported="true" combineaccessrules="false" />))
error("""Expected .classpath of subb project to contain <classpathentry kind="src" path="/suba" exported="true" combineaccessrules="false" />: %s""" format classpath)
Expand Down
1 change: 1 addition & 0 deletions src/sbt-test/sbteclipse/02-contents/project/Build.scala
Expand Up @@ -44,6 +44,7 @@ object Build extends Build {
libraryDependencies ++= Seq(
"biz.aQute" % "bndlib" % "1.50.0"
),
retrieveManaged := true,
scalacOptions := Seq("-unchecked", "-deprecation")
),
dependencies = Seq(suba, suba % "test->test")
Expand Down

0 comments on commit 6130d40

Please sign in to comment.