add support for linked folders in Eclipse #124

Closed
wants to merge 5 commits into
from
@@ -130,6 +130,7 @@ private object Eclipse {
handleProject(
jreContainer(executionEnvironmentArg orElse executionEnvironment(ref, state)),
preTasks(ref, state),
+ linkedFolders(ref, state),
relativizeLibs(ref, state),
builderAndNatures(projectFlavor(ref, state)),
state
@@ -171,6 +172,7 @@ private object Eclipse {
def handleProject(
jreContainer: String,
preTasks: Seq[(TaskKey[_], ProjectRef)],
+ linkedFolders: Seq[(String, File)],
relativizeLibs: Boolean,
builderAndNatures: (String, Seq[String]),
state: State)(
@@ -187,13 +189,14 @@ private object Eclipse {
for {
_ <- executePreTasks(preTasks, state)
n <- io(name)
- _ <- saveXml(baseDirectory / ".project", new RuleTransformer(projectTransformers: _*)(projectXml(name, builderAndNatures)))
+ _ <- saveXml(baseDirectory / ".project", new RuleTransformer(projectTransformers: _*)(projectXml(name, builderAndNatures, linkedFolders)))
cp <- classpath(
classpathEntryTransformer,
buildDirectory,
baseDirectory,
relativizeLibs,
srcDirectories,
+ linkedFolders,
externalDependencies,
projectDependencies,
jreContainer,
@@ -207,7 +210,7 @@ private object Eclipse {
def executePreTasks(preTasks: Seq[(TaskKey[_], ProjectRef)], state: State): IO[Unit] =
io(for ((preTask, ref) <- preTasks) evaluateTask(preTask, ref, state))
- def projectXml(name: String, builderAndNatures: (String, Seq[String])): Node =
+ def projectXml(name: String, builderAndNatures: (String, Seq[String]), linkedFolders: Seq[(String, File)]): Node =
<projectDescription>
<name>{ name }</name>
<buildSpec>
@@ -218,6 +221,22 @@ private object Eclipse {
<natures>
{ builderAndNatures._2.map(n => <nature>{ n }</nature>) }
</natures>
+ {
+ if (!linkedFolders.isEmpty) {
+ <linkedResources>
+ {
+ linkedFolders.map {
+ case (name, file) =>
+ <link>
+ <name>{ name }</name>
+ <type>2</type>
+ <location>{ file.getCanonicalPath.replaceAll("\\\\", "/") }</location>
+ </link>
+ }
+ }
+ </linkedResources>
+ }
+ }
</projectDescription>
def classpath(
@@ -226,12 +245,13 @@ private object Eclipse {
baseDirectory: File,
relativizeLibs: Boolean,
srcDirectories: Seq[(File, File)],
+ linkedFolders: Seq[(String, File)],
externalDependencies: Seq[Lib],
projectDependencies: Seq[String],
jreContainer: String,
state: State): IO[Node] = {
val srcEntriesIoSeq =
- for ((dir, output) <- srcDirectories) yield srcEntry(baseDirectory, dir, output, state)
+ for ((dir, output) <- srcDirectories) yield srcEntry(baseDirectory, dir, linkedFolders, output, state)
for (srcEntries <- srcEntriesIoSeq.sequence) yield {
val entries = srcEntries ++
(externalDependencies map libEntry(buildDirectory, baseDirectory, relativizeLibs, state)) ++
@@ -245,16 +265,25 @@ private object Eclipse {
def srcEntry(
baseDirectory: File,
srcDirectory: File,
+ linkedFolders: Seq[(String, File)],
classDirectory: File,
state: State): IO[EclipseClasspathEntry.Src] =
io {
if (!srcDirectory.exists()) srcDirectory.mkdirs()
EclipseClasspathEntry.Src(
- relativize(baseDirectory, srcDirectory),
+ findInLinkedFolder(srcDirectory, linkedFolders) getOrElse relativize(baseDirectory, srcDirectory),
relativize(baseDirectory, classDirectory)
)
}
+ def findInLinkedFolder(srcDirectory: File, linkedFolders: Seq[(String, File)]): Option[String] = {
+ val paths = for {
+ (name, path) <- linkedFolders
+ rel <- IO.relativize(path, srcDirectory)
+ } yield (name + "/" + rel)
+ paths.headOption
+ }
+
def libEntry(
buildDirectory: File,
baseDirectory: File,
@@ -423,6 +452,9 @@ private object Eclipse {
def executionEnvironment(ref: Reference, state: State): Option[EclipseExecutionEnvironment.Value] =
setting(EclipseKeys.executionEnvironment in ref, state).fold(_ => None, id)
+ def linkedFolders(ref: Reference, state: State): Seq[(String, File)] =
+ setting(EclipseKeys.linkedFolders in ref, state).fold(_ => Nil, id)
+
def skipParents(ref: Reference, state: State): Boolean =
setting(EclipseKeys.skipParents in ref, state).fold(_ => true, id)
@@ -22,6 +22,8 @@ private object EclipseOpts {
val ExecutionEnvironment = "execution-environment"
+ val LinkedFolders = "linked-folders"
+
val SkipParents = "skip-parents"
val WithSource = "with-source"
@@ -55,6 +55,11 @@ trait EclipsePlugin {
"The optional Eclipse execution environment."
)
+ val linkedFolders: SettingKey[Seq[(String, File)]] = SettingKey(
+ prefix(LinkedFolders),
+ "Link external folders."
+ )
+
val skipParents: SettingKey[Boolean] = SettingKey(
prefix(SkipParents),
"Skip creating Eclipse files for parent project?"
@@ -31,6 +31,17 @@ TaskKey[Unit]("verify-project-xml-java") <<= baseDirectory map { dir =>
// java project nature
verify("buildCommand", "org.eclipse.jdt.core.javabuilder", (projectDescription \ "buildSpec" \ "buildCommand" \ "name").text)
verify("natures", "org.eclipse.jdt.core.javanature", (projectDescription \ "natures" \ "nature").text)
+ // linked resources
+ verify("linkedResources", "src-common", (projectDescription \ "linkedResources" \ "link" \ "name").text)
+ verify("linkedResources", "2", (projectDescription \ "linkedResources" \ "link" \ "type").text)
+ if (!(projectDescription \ "linkedResources" \ "link" \ "location").text.endsWith("/java-common"))
+ error("""Expected .project of Java project to contain a linkedResources link with location ending in "/java-common" """)
+}
+
+TaskKey[Unit]("verify-classpath-xml-java") <<= baseDirectory map { dir =>
+ val classpath = XML.loadFile(dir / "java" / ".classpath")
+ if (!(classpath.child contains <classpathentry kind="src" path="src-common/main/java" output="target/scala-2.9.2/classes" />))
+ error("""Expected .classpath of Java project to contain <classpathentry kind="src" path="src-common/main/java" output="target/scala-2.9.2/classes" /> """)
}
TaskKey[Unit]("verify-project-xml-subd") <<= baseDirectory map { dir =>
@@ -116,7 +116,9 @@ object Build extends Build {
"java",
new File("java"),
settings = Project.defaultSettings ++ Seq(
- EclipseKeys.projectFlavor := EclipseProjectFlavor.Java
+ EclipseKeys.projectFlavor := EclipseProjectFlavor.Java,
+ EclipseKeys.linkedFolders := Seq( ("src-common", file(".") / "java-common") ),
+ unmanagedSourceDirectories in Compile ++= Seq( file(".") / "java-common" / "src" / "main" / "java" )
)
)