Permalink
Browse files

Regenerate on only new version of Scala IDE

If only a version of Scala IDE changes, the ecosystem is correctly regenerated.
  • Loading branch information...
1 parent 083f838 commit a61d3d8fbc0ff13ce0c70835ba27c2b9bc497f28 @skyluc skyluc committed Dec 14, 2012
@@ -1,5 +1,7 @@
package org.scalaide.buildtools
+import org.osgi.framework.Version
+
object EcosystemBuild {
import Ecosystem._
@@ -13,40 +15,51 @@ object EcosystemBuild {
val baseRepo = Repositories(ecosystemConf.base)
val baseScalaIDEVersions = findScalaIDEVersions(baseRepo, existingAddOns, availableAddOns, siteRepo, featureConfs)
val nextBaseRepo = Repositories(ecosystemConf.nextBase)
- val nextScalaIDEVersions = findScalaIDEVersions(nextBaseRepo, nextExistingAddOns, availableAddOns, nextSiteRepo, featureConfs)
+ val nextBaseScalaIDEVersions = findScalaIDEVersions(nextBaseRepo, nextExistingAddOns, availableAddOns, nextSiteRepo, featureConfs)
+ val nextSiteScalaIDEVersions = siteRepo.findIU(ScalaIDEFeatureIdOsgi)
EcosystemBuild(
ecosystemConf.id,
baseRepo,
baseScalaIDEVersions,
nextBaseRepo,
- nextScalaIDEVersions,
+ nextBaseScalaIDEVersions,
siteRepo,
nextSiteRepo,
existingAddOns,
- nextExistingAddOns)
+ nextExistingAddOns,
+ shouldBeRegenerated(baseScalaIDEVersions, siteRepo.findIU(ScalaIDEFeatureIdOsgi)),
+ shouldBeRegenerated(nextBaseScalaIDEVersions, nextSiteRepo.findIU(ScalaIDEFeatureIdOsgi)))
}
private def findScalaIDEVersions(baseRepo: P2Repository, existingAddOns: Map[PluginDescriptor, Seq[AddOn]], availableAddOns: Map[PluginDescriptor, Seq[AddOn]], siteRepo: P2Repository, featureConfs: Seq[PluginDescriptor]): Seq[ScalaIDEVersion] = {
baseRepo.findIU(ScalaIDEFeatureIdOsgi).toSeq.map(ScalaIDEVersion(_, baseRepo, existingAddOns, availableAddOns, siteRepo))
}
+ private def shouldBeRegenerated(baseScalaIDEVersions: Seq[ScalaIDEVersion], siteScalaIDEVersions: Set[InstallableUnit]): Boolean = {
+ if (!baseScalaIDEVersions.forall(_.associatedAvailableAddOns.isEmpty)) {
+ true
+ } else {
+ val baseVersions: Set[Version] = baseScalaIDEVersions.map(_.version).toSet
+ val siteVersions: Set[Version] = siteScalaIDEVersions.map(_.version).toSet
+ baseVersions != siteVersions
+ }
+ }
+
}
case class EcosystemBuild(
id: String,
baseRepo: P2Repository,
baseScalaIDEVersions: Seq[ScalaIDEVersion],
- nextRepo: P2Repository,
- nextScalaIDEVersions: Seq[ScalaIDEVersion],
+ nextBaseRepo: P2Repository,
+ nextBaseScalaIDEVersions: Seq[ScalaIDEVersion],
siteRepo: P2Repository,
nextSiteRepo: P2Repository,
existingAddOns: Map[PluginDescriptor, Seq[AddOn]],
- nextExistingAddOns: Map[PluginDescriptor, Seq[AddOn]]) {
-
- val regenerateEcosystem: Boolean = !baseScalaIDEVersions.forall(_.associatedAvailableAddOns.isEmpty)
-
- val regenerateNextEcosystem: Boolean = !nextScalaIDEVersions.forall(_.associatedAvailableAddOns.isEmpty)
-
+ nextExistingAddOns: Map[PluginDescriptor, Seq[AddOn]],
+ val regenerateEcosystem: Boolean,
+ val regenerateNextEcosystem: Boolean) {
+
val zippedVersion: Option[ScalaIDEVersion] = baseScalaIDEVersions.sortBy(_.version).lastOption
}
@@ -34,7 +34,7 @@ object EcosystemBuildsMavenProjects {
}
val nextFolder = if (ecosystemBuild.regenerateNextEcosystem) {
- generateEcosystemProject(ecosystemBuild.nextScalaIDEVersions, "%s-next".format(ecosystemBuild.id), ecosystemBuild.nextRepo, buildFolder, None)
+ generateEcosystemProject(ecosystemBuild.nextBaseScalaIDEVersions, "%s-next".format(ecosystemBuild.id), ecosystemBuild.nextBaseRepo, buildFolder, None)
} else {
Nil
}
@@ -77,7 +77,7 @@ h4 {margin: 0.2em 0 0 0; margin-right: 3em;}
<div class="currentNextAvailableScalaIDEVersions">
<h2>Available Scala IDE versions:</h2>
{ availableScalaIDEVersions(build.baseRepo, build.baseScalaIDEVersions) }
- { availableScalaIDEVersions(build.nextRepo, build.nextScalaIDEVersions) }
+ { availableScalaIDEVersions(build.nextBaseRepo, build.nextBaseScalaIDEVersions) }
</div>
<div class="currentNextExistingAddOns">
<h2>Existing add-ons</h2>
@@ -89,14 +89,14 @@ h4 {margin: 0.2em 0 0 0; margin-right: 3em;}
{ build.baseScalaIDEVersions.map(s => scalaIDEVersionWithAddOns(s, build.zippedVersion.exists(_ == s))) }
</div>
{
- if (build.nextScalaIDEVersions.isEmpty)
+ if (build.nextBaseScalaIDEVersions.isEmpty)
<div class="nextEcosystem notAvailable">
<h2>Next ecosystem</h2>
</div>
else
<div class="nextEcosystem">
<h2>Next ecosystem { rebuiltComment(build.regenerateNextEcosystem) }</h2>
- { build.nextScalaIDEVersions.map(scalaIDEVersionWithAddOns(_, false)) }
+ { build.nextBaseScalaIDEVersions.map(scalaIDEVersionWithAddOns(_, false)) }
</div>
}
</div>
@@ -1,215 +0,0 @@
-package org.scalaide.buildtools
-
-import java.io.File
-import scala.annotation.tailrec
-import scala.collection.mutable.HashMap
-import java.net.URL
-import org.osgi.framework.Version
-import scala.collection.immutable.TreeSet
-import dispatch.Http
-
-object GenerateEcosystemBuildsTake1 {
- import Ecosystem._
-
- def main(args: Array[String]) {
- // parse arguments
-
- val rootFolder = args.collectFirst {
- case RootOption(root) =>
- root
- }.getOrElse(System.getProperty("user.dir"))
-
- new GenerateEcosystemBuildsTake1(rootFolder)()
- }
-
-}
-
-class GenerateEcosystemBuildsTake1(rootFolder: String) {
- import Ecosystem._
-
- def apply(): Either[String, AnyRef] = {
-
- val ecosystems = EcosystemsDescriptor.load(new File(rootFolder, EcosystemConfigFile)).ecosystems
- val requestedFeatures = PluginDescriptor.loadAll(new File(rootFolder, "features")).flatMap(_ match {
- case Right(conf) =>
- Some(conf)
- case Left(_) =>
- None
- })
-
- val res = for {
- availableFeatures <- findFeatures(requestedFeatures.toList).right
- ecosystemToScalaIDEToAvailableFeatures <- getAvailableScalaIDEs(ecosystems, requestedFeatures.toList, availableFeatures).right
- } yield MavenProject2.generateEcosystemsProjects(ecosystemToScalaIDEToAvailableFeatures, new File(rootFolder, "target/builds"))
-
- // need to stop Dispatch in any cases
- Http.shutdown()
- res
-
- }
-
- private def getAvailableScalaIDEs(ecosystems: List[EcosystemDescriptor], requestedFeatures: List[PluginDescriptor], availableFeatures: List[FeatureDefinition]): Either[String, Map[EcosystemDescriptor, Map[ScalaIDEDefinition, Features]]] = {
- @tailrec
- def loop(repositories: List[EcosystemDescriptor], definitions: Map[EcosystemDescriptor, Map[ScalaIDEDefinition, Features]]): Either[String, Map[EcosystemDescriptor, Map[ScalaIDEDefinition, Features]]] = {
- repositories match {
- case Nil =>
- Right(definitions)
- case head :: tail =>
- loop(tail, definitions + (head -> findScalaIDEsAndResolvedAvailableFeatures(head, requestedFeatures, availableFeatures)))
- }
- }
- loop(ecosystems, Map())
- }
-
- private def findScalaIDEsAndResolvedAvailableFeatures(ecosystem: EcosystemDescriptor, requestedFeatures: List[PluginDescriptor], availableFeatures: List[FeatureDefinition]): Map[ScalaIDEDefinition, Features] = {
- val repository = Repositories(ecosystem.site)
- val baseRepository = Repositories(ecosystem.base)
- findScalaIDEsAndResolvedAvailableFeatures(repository, baseRepository, requestedFeatures, availableFeatures)
- }
-
- private def findScalaIDEsAndResolvedAvailableFeatures(repository: P2Repository, baseRepository: P2Repository, requestedFeatures: List[PluginDescriptor], availableFeatures: List[FeatureDefinition]): Map[ScalaIDEDefinition, Features] = {
- val allAvailableFeatures = mergeFeatureList(findExistingFeatures(requestedFeatures, repository), availableFeatures)
-
- baseRepository.findIU(ScalaIDEFeatureIdOsgi).foldLeft(Map[ScalaIDEDefinition, Features]())((m, ui) =>
- // TODO: might be a nice place to check versions
- m + (ScalaIDEDefinition(ui, baseRepository) -> filterFeaturesFor(ui, allAvailableFeatures, repository)))
- }
-
- private def filterFeaturesFor(scalaIDE: InstallableUnit, availableFeatures: List[FeatureDefinition], baseRepository: P2Repository): Features = {
- val lists = availableFeatures.filter(f => ScalaIDEDefinition.matches(scalaIDE.version, f.sdtFeatureRange.range)).groupBy(_.details.featureId).map(t => TreeSet(t._2: _*)(FeatureDefinition.DescendingOrdering).head).toList.partition(_.repository == baseRepository)
- Features(lists._2, lists._1)
- }
-
- private def findFeatures(requestedFeatures: List[PluginDescriptor]): Either[String, List[FeatureDefinition]] = {
- Right(requestedFeatures.flatMap(findFeatures(_)))
- }
-
- private def findFeatures(requestedFeature: PluginDescriptor): List[FeatureDefinition] = {
- requestedFeature.updateSites.flatMap { location =>
- findFeatures(requestedFeature, Repositories(location))
- }
- }
-
- private def findFeatures(feature: PluginDescriptor, repository: P2Repository): List[FeatureDefinition] = {
- repository.findIU(feature.featureId + FeatureSuffix).toList.map(FeatureDefinition(feature, _, repository))
- }
-
- private def mergeFeatureList(base: List[FeatureDefinition], toMerge: List[FeatureDefinition]): List[FeatureDefinition] = {
-
- def loop(toProcess: List[FeatureDefinition]): List[FeatureDefinition] = {
- toProcess match {
- case Nil =>
- base
- case head :: tail =>
- if (base.exists(f => f.details == head.details && f.version == head.version)) {
- loop(tail)
- } else {
- loop(tail) :+ head
- }
- }
- }
- val res = loop(toMerge)
- res
- }
-
- private def findExistingFeatures(requestedFeatures: List[PluginDescriptor], repository: P2Repository): List[FeatureDefinition] = {
- requestedFeatures.flatMap(findFeatures(_, repository))
- }
-
- private def findAssociatedFeatures() {
-
- }
-
-}
-
-case class ScalaIDEDefinition(
- sdtFeatureVersion: Version,
- sdtCoreVersion: Option[DependencyUnit],
- scalaLibraryVersion: Option[DependencyUnit],
- scalaCompilerVersion: Option[DependencyUnit], repository: P2Repository)
-
-object ScalaIDEDefinition {
- import Ecosystem._
-
- private val RangeRegex = "\\[([^,]*),([^\\]]*)\\]".r
-
- def apply(feature: InstallableUnit, repository: P2Repository): ScalaIDEDefinition = {
-
- val dependencies = allDependencies(feature, repository)
-
- val sdtCore = dependencies.find(_.id == ScalaIDEId)
- val scalaLibrary = dependencies.find(_.id == ScalaLibraryId)
- val scalaCompiler = dependencies.find(_.id == ScalaCompilerId)
-
- new ScalaIDEDefinition(feature.version, sdtCore, scalaLibrary, scalaCompiler, repository)
- }
-
- def allDependencies(iu: InstallableUnit, repository: P2Repository): List[DependencyUnit] = {
- iu.dependencies ++ iu.dependencies.flatMap(allDependencies(_, repository))
- }
-
- def allDependencies(du: DependencyUnit, repository: P2Repository): List[DependencyUnit] = {
- repository.findIU(du.id).toList.filter(iu => matches(iu.version, du.range)) match {
- case Nil =>
- // not part of this repository, fine
- Nil
- case List(iu) =>
- // this is the one we are looking for
- val dep = allDependencies(iu, repository)
- dep
- case _ =>
- // more than one?
- Nil // TODO: better return value?
- }
- }
-
- def matches(version: Version, range: String): Boolean = {
- range match {
- case RangeRegex(low, high) if (low == high) =>
- // we care only about strict versions so far
- // TODO: may need to improve that
- version.equals(new Version(low))
- case _ =>
- false
- }
- }
-}
-
-case class FeatureDefinition(
- details: PluginDescriptor,
- version: Version,
- sdtFeatureRange: DependencyUnit,
- sdtCoreRange: DependencyUnit,
- scalaLibraryRange: DependencyUnit,
- scalaCompilerRange: DependencyUnit,
- repository: P2Repository)
-
-object FeatureDefinition {
- import Ecosystem._
-
- def apply(details: PluginDescriptor, iu: InstallableUnit, repository: P2Repository): FeatureDefinition = {
- val dependencies = ScalaIDEDefinition.allDependencies(iu, repository)
-
- val sdtCore = dependencies.find(_.id == ScalaIDEId)
- val scalaLibrary = dependencies.find(_.id == ScalaLibraryId)
- val scalaCompiler = dependencies.find(_.id == ScalaCompilerId)
- val sdtFeature = dependencies.find(_.id == ScalaIDEFeatureIdOsgi)
-
- // TODO: add support for source features
-
- // TODO: need to handle error cases, and check versions ...
-
- new FeatureDefinition(details, iu.version, sdtFeature.get, sdtCore.get, scalaLibrary.get, scalaCompiler.get, repository)
- }
-
- implicit object DescendingOrdering extends Ordering[FeatureDefinition] {
- override def compare(x: FeatureDefinition, y: FeatureDefinition): Int = {
- val diffId = x.details.featureId.compareTo(y.details.featureId)
- if (diffId == 0) -1 * x.version.compareTo(y.version) // same bundle name, compare versions
- else diffId
- }
- }
-
-}
-
-case class Features(available: List[FeatureDefinition], existing: List[FeatureDefinition])
Oops, something went wrong.

0 comments on commit a61d3d8

Please sign in to comment.