Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use source artifacts that come with update report #306

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
51 changes: 41 additions & 10 deletions src/main/scala/com/typesafe/sbteclipse/core/Eclipse.scala
Expand Up @@ -87,7 +87,7 @@ private object Eclipse extends EclipseSDTConfig {

def parser: Parser[Seq[(String, Any)]] = {
import EclipseOpts._
(executionEnvironmentOpt | boolOpt(SkipParents) | boolOpt(WithSource) | boolOpt(WithJavadoc) | boolOpt(WithBundledScalaContainers)).*
(executionEnvironmentOpt | boolOpt(SkipParents) | boolOpt(WithSource) | boolOpt(WithJavadoc) | boolOpt(WithUserSetSource) | boolOpt(WithUserSetJavadoc) | boolOpt(WithBundledScalaContainers)).*
}

def executionEnvironmentOpt: Parser[(String, EclipseExecutionEnvironment.Value)] = {
Expand All @@ -107,6 +107,8 @@ private object Eclipse extends EclipseSDTConfig {
(args get SkipParents).asInstanceOf[Option[Boolean]] getOrElse skipParents(ThisBuild, state),
(args get WithSource).asInstanceOf[Option[Boolean]],
(args get WithJavadoc).asInstanceOf[Option[Boolean]],
(args get WithUserSetSource).asInstanceOf[Option[Boolean]],
(args get WithUserSetJavadoc).asInstanceOf[Option[Boolean]],
state
).fold(onFailure(state), onSuccess(state))
}
Expand All @@ -116,6 +118,8 @@ private object Eclipse extends EclipseSDTConfig {
skipParents: Boolean,
withSourceArg: Option[Boolean],
withJavadocArg: Option[Boolean],
withUserSetSourceArg: Option[Boolean],
withUserSetJavadocArg: Option[Boolean],
state: State): Validation[IO[Seq[String]]] = {
val effects = for {
ref <- structure(state).allProjectRefs
Expand All @@ -124,6 +128,8 @@ private object Eclipse extends EclipseSDTConfig {
val configs = configurations(ref, state)
val source = withSourceArg getOrElse withSource(ref, state)
val javadoc = withJavadocArg getOrElse withJavadoc(ref, state)
val userSetSource = withUserSetSourceArg getOrElse withUserSetSource(ref, state)
val userSetJavadoc = withUserSetJavadocArg getOrElse withUserSetJavadoc(ref, state)
val applic =
(classpathTransformerFactories(ref, state).toList map (_.createTransformer(ref, state))).sequence[Validation, RewriteRule] |@|
(projectTransformerFactories(ref, state).toList map (_.createTransformer(ref, state))).sequence[Validation, RewriteRule] |@|
Expand All @@ -133,7 +139,7 @@ private object Eclipse extends EclipseSDTConfig {
mapConfigurations(configs, config => srcDirectories(ref, createSrc(ref, state)(config), eclipseOutput(ref, state)(config), state)(config)) |@|
scalacOptions(ref, state) |@|
compileOrder(ref, state) |@|
mapConfigurations(removeExtendedConfigurations(configs), externalDependencies(ref, source, javadoc, state)) |@|
mapConfigurations(removeExtendedConfigurations(configs), externalDependencies(ref, source, javadoc, userSetSource, userSetJavadoc, state)) |@|
mapConfigurations(configs, projectDependencies(ref, project, state))
applic(
handleProject(
Expand Down Expand Up @@ -460,6 +466,8 @@ private object Eclipse extends EclipseSDTConfig {
ref: ProjectRef,
withSource: Boolean,
withJavadoc: Boolean,
withUserSetSource: Boolean,
withUserSetJavadoc: Boolean,
state: State)(
configuration: Configuration): Validation[Seq[Lib]] = {
def evalTask[A](key: TaskKey[A]) = evaluateTask(key in configuration, ref, state)
Expand Down Expand Up @@ -492,33 +500,50 @@ private object Eclipse extends EclipseSDTConfig {
}
val externalDependencyClasspath: Validation[sbt.Keys.Classpath] = evalTask(Keys.externalDependencyClasspath)
val moduleFiles: Validation[Map[File, Lib]] = {
lazy val updateModuleReports = moduleReports(Keys.update)
lazy val classifierModuleReports = moduleReports(Keys.updateClassifiers)

def classifierModuleToFile(classifier: Option[String]) = {
def classifierModuleToFile(moduleReports: Validation[Seq[ModuleReport]], classifier: Option[String]) = {
if (classifier.isDefined)
moduleToFile(classifierModuleReports, (artifact, _) => artifact.classifier === classifier)
moduleToFile(moduleReports, (artifact, _) => artifact.classifier === classifier)
else
Map[ModuleID, File]().success
}

val sources = if (withSource) Some("sources") else None
val javadoc = if (withJavadoc) Some("javadoc") else None

sources |+| javadoc match {
case Some(_) => {
val binaryModuleToFile = moduleToFile(moduleReports(Keys.update))
val userSetSources = if (withUserSetSource) Some("sources") else None
val userSetJavadoc = if (withUserSetJavadoc) Some("javadoc") else None

(binaryModuleToFile |@| classifierModuleToFile(sources) |@| classifierModuleToFile(javadoc))(moduleFileToArtifactFile)
sources |+| javadoc match {
case Some(_) =>
(
moduleToFile(updateModuleReports) |@|
classifierModuleToFile(classifierModuleReports, sources) |@|
classifierModuleToFile(classifierModuleReports, javadoc)
)(moduleFileToArtifactFile)
case None => {
userSetSources |+| userSetJavadoc match {
case Some(_) =>
(
moduleToFile(updateModuleReports) |@|
classifierModuleToFile(updateModuleReports, userSetSources) |@|
classifierModuleToFile(updateModuleReports, userSetJavadoc)
)(moduleFileToArtifactFile)
case None => Map[File, Lib]().success
}
}
case None => Map[File, Lib]().success
}
}
val externalDependencies = (externalDependencyClasspath |@| moduleFiles)(libs)
state.log.debug(
"External dependencies for configuration '%s' and withSource '%s' and withJavadoc '%s': %s".format(
"External dependencies for configuration '%s' and withSource '%s' and withJavadoc '%s' and withUserSetSource '%s' and withUserSetJavadoc '%s': %s".format(
configuration,
withSource,
withJavadoc,
withUserSetSource,
withUserSetJavadoc,
externalDependencies
)
)
Expand Down Expand Up @@ -567,6 +592,12 @@ private object Eclipse extends EclipseSDTConfig {
def withJavadoc(ref: Reference, state: State): Boolean =
setting(EclipseKeys.withJavadoc in ref, state)

def withUserSetSource(ref: Reference, state: State): Boolean =
setting(EclipseKeys.withUserSetSource in ref, state)

def withUserSetJavadoc(ref: Reference, state: State): Boolean =
setting(EclipseKeys.withUserSetJavadoc in ref, state)

def withBundledScalaContainers(ref: Reference, state: State): Boolean =
setting(EclipseKeys.withBundledScalaContainers in ref, state)

Expand Down
4 changes: 4 additions & 0 deletions src/main/scala/com/typesafe/sbteclipse/core/EclipseOpts.scala
Expand Up @@ -28,6 +28,10 @@ private object EclipseOpts {

val WithJavadoc = "with-javadoc"

val WithUserSetSource = "with-user-set-source"

val WithUserSetJavadoc = "with-user-set-javadoc"

val UseProjectId = "use-project-id"

val WithBundledScalaContainers = "with-bundled-scala-containers"
Expand Down
12 changes: 12 additions & 0 deletions src/main/scala/com/typesafe/sbteclipse/core/EclipsePlugin.scala
Expand Up @@ -51,6 +51,8 @@ object EclipsePlugin {
skipParents := true,
withSource := false,
withJavadoc := false,
withUserSetSource := false,
withUserSetJavadoc := false,
projectFlavor := EclipseProjectFlavor.ScalaIDE,
withBundledScalaContainers := projectFlavor.value.id == EclipseProjectFlavor.ScalaIDE.id,
classpathTransformerFactories := defaultClasspathTransformerFactories(withBundledScalaContainers.value),
Expand Down Expand Up @@ -137,6 +139,16 @@ object EclipsePlugin {
"Download and link javadoc for library dependencies?"
)

val withUserSetSource: SettingKey[Boolean] = SettingKey(
prefix(WithUserSetSource),
"Link sources for library dependencies annotated by 'withSource'?"
)

val withUserSetJavadoc: SettingKey[Boolean] = SettingKey(
prefix(WithUserSetJavadoc),
"Link javadocs for library dependencies annotated by 'withJavadoc'?"
)

val withBundledScalaContainers: SettingKey[Boolean] = SettingKey(
prefix(WithBundledScalaContainers),
"Let the generated project use the bundled Scala library of the ScalaIDE plugin"
Expand Down
32 changes: 32 additions & 0 deletions src/sbt-test/sbteclipse/07-dependency-classifiers/build.sbt
@@ -0,0 +1,32 @@
import scala.xml.XML

EclipseKeys.withSource := false
EclipseKeys.withJavadoc := false

EclipseKeys.withUserSetSource := true
EclipseKeys.withUserSetJavadoc := true

organization := "com.typesafe.sbteclipse"

name := "sbteclipse-test"

version := "1.2.3"

libraryDependencies += "ch.qos.logback" % "logback-classic" % "1.0.1"

libraryDependencies += "biz.aQute" % "bndlib" % "1.50.0" withSources()

libraryDependencies += "org.specs2" %% "specs2" % "2.1.1" % "test" withSources()

TaskKey[Unit]("verify-classpath-xml") <<= baseDirectory map { dir =>
val home = System.getProperty("user.home")
val classpath = XML.loadFile(dir / ".classpath")
// lib entries with sources
def verifySrcClasspathEntry(libPath: String, srcPath: String) =
if (!(classpath.child contains <classpathentry kind="lib" path={ libPath } sourcepath={ srcPath } />))
error("""Expected .classpath of project to contain <classpathentry kind="lib" path="%s" sourcepath="%s" />: %s""".format(libPath, srcPath, classpath))


verifySrcClasspathEntry(home + "/.ivy2/cache/biz.aQute/bndlib/jars/bndlib-1.50.0.jar", home + "/.ivy2/cache/biz.aQute/bndlib/srcs/bndlib-1.50.0-sources.jar")
verifySrcClasspathEntry(home + "/.ivy2/cache/org.specs2/specs2_2.10/jars/specs2_2.10-2.1.1.jar", home + "/.ivy2/cache/org.specs2/specs2_2.10/srcs/specs2_2.10-2.1.1-sources.jar")
}
@@ -0,0 +1,7 @@
{
val pluginVersion = System.getProperty("plugin.version")
if(pluginVersion == null)
throw new RuntimeException("""|The system property 'plugin.version' is not defined.
|Specify this property using the scriptedLaunchOpts -D.""".stripMargin)
else addSbtPlugin("com.typesafe.sbteclipse" % "sbteclipse-plugin" % pluginVersion)
}
@@ -0,0 +1 @@
object Main
4 changes: 4 additions & 0 deletions src/sbt-test/sbteclipse/07-dependency-classifiers/test
@@ -0,0 +1,4 @@
> clean
> compile
> eclipse skip-parents=false
> verify-classpath-xml