Permalink
Browse files

Tweaked ecosystem build

Find the newest version of an addon
  • Loading branch information...
skyluc committed Oct 9, 2012
1 parent b8df106 commit 59ce0be24d7abcddf86c9346af58a90603350dfd
View
@@ -9,6 +9,7 @@ scalaVersion := "2.9.2"
publishMavenStyle := true
publishTo := Some("Typesafe IDE" at "https://typesafe.artifactoryonline.com/typesafe/ide-2.9")
+//publishTo := Some(Resolver.file("file", new File(Path.userHome.absolutePath+"/.m2/repository")))
credentials += Credentials(Path.userHome / ".credentials")
@@ -5,6 +5,7 @@ import scala.annotation.tailrec
import scala.collection.mutable.HashMap
import java.net.URL
import org.osgi.framework.Version
+import scala.collection.immutable.TreeSet
/**
* !!! This object not thread safe !!! It was used in a single threaded system when implemented.
@@ -45,21 +46,20 @@ class GenerateEcosystemBuilds(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 {
+
+ 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
})
-
+
for {
availableFeatures <- findFeatures(requestedFeatures.toList).right
ecosystemToScalaIDEToAvailableFeatures <- getAvailableScalaIDEs(ecosystems, requestedFeatures.toList, availableFeatures).right
} yield MavenProject2.generateEcosystemsProjects(ecosystemToScalaIDEToAvailableFeatures, new File(rootFolder, "target/builds"))
-
-
+
}
private def getAvailableScalaIDEs(ecosystems: List[EcosystemDescriptor], requestedFeatures: List[PluginDescriptor], availableFeatures: List[FeatureDefinition]): Either[String, Map[EcosystemDescriptor, Map[ScalaIDEDefinition, List[FeatureDefinition]]]] = {
@@ -92,10 +92,14 @@ class GenerateEcosystemBuilds(rootFolder: String) {
baseRepository.findIU(ScalaIDEFeatureIdOsgi).foldLeft(Map[ScalaIDEDefinition, List[FeatureDefinition]]())((m, ui) =>
// TODO: might be a nice place to check versions
- m + (ScalaIDEDefinition(ui, baseRepository) -> allAvailableFeatures.filter(f => ScalaIDEDefinition.matches(ui.version, f.sdtFeatureRange.range))))
+ m + (ScalaIDEDefinition(ui, baseRepository) -> filterFeaturesFor(ui, allAvailableFeatures)))
+ }
+
+ private def filterFeaturesFor(scalaIDE: InstallableUnit, availableFeatures: List[FeatureDefinition]): List[FeatureDefinition] = {
+ availableFeatures.filter(f => ScalaIDEDefinition.matches(scalaIDE.version, f.sdtFeatureRange.range)).groupBy(_.details.featureId).map(t => TreeSet(t._2: _*)(FeatureDefinition.DescendingOrdering).head).toList
}
- private def findFeatures(requestedFeatures: List[PluginDescriptor]): Either[String, List[FeatureDefinition]] = {
+ private def findFeatures(requestedFeatures: List[PluginDescriptor]): Either[String, List[FeatureDefinition]] = {
Right(requestedFeatures.flatMap(findFeatures(_)))
}
@@ -111,7 +115,7 @@ class GenerateEcosystemBuilds(rootFolder: String) {
}
private def findFeatures(feature: PluginDescriptor, repository: P2Repository): List[FeatureDefinition] = {
- repository.findIU(feature.featureId + FeatureSuffix).map(FeatureDefinition(feature, _, repository))
+ repository.findIU(feature.featureId + FeatureSuffix).toList.map(FeatureDefinition(feature, _, repository))
}
private def mergeFeatureList(base: List[FeatureDefinition], toMerge: List[FeatureDefinition]): List[FeatureDefinition] = {
@@ -221,4 +225,13 @@ object FeatureDefinition {
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
+ }
+ }
+
}
@@ -6,6 +6,8 @@ import scala.xml.Elem
import scala.xml.XML
object MavenProject2 {
+
+ val artifactIdSuffix= Iterator.from(1)
private def saveXml(file: File, xml: Elem) {
XML.save(file.getAbsolutePath(), xml, "UTF-8", true)
@@ -31,25 +33,25 @@ object MavenProject2 {
val artifactId = "ecosystem.%s".format(ecosystem.id)
- val featureFolders: Seq[File] = scalaIDEToAvailableFeatures.flatMap(s => generateScalaIDEProjects(s._1, s._2, artifactId, Iterator.from(1), ecosystemFolder)).toSeq
+ val featureFolders: Seq[File] = scalaIDEToAvailableFeatures.flatMap(s => generateScalaIDEProjects(s._1, s._2, artifactId, ecosystemFolder)).toSeq
saveXml(new File(ecosystemFolder, "pom.xml"), createEcosystemPomXml(artifactId, ecosystem.baseSite, ecosystemFolder, featureFolders))
ecosystemFolder
}
- def generateScalaIDEProjects(scalaIDE: ScalaIDEDefinition, features: Seq[FeatureDefinition], parentId: String, idCounter: Iterator[Int], baseFolder: File): Seq[File] = {
- val scalaIDEFolder = new File(baseFolder, scalaIDE.sdtFeatureVersion)
+ def generateScalaIDEProjects(scalaIDE: ScalaIDEDefinition, features: Seq[FeatureDefinition], parentId: String, baseFolder: File): Seq[File] = {
+ val scalaIDEFolder = new File(baseFolder, scalaIDE.sdtFeatureVersion.toString())
scalaIDEFolder.mkdir()
- features.map(f => generateFeatureProject(f, parentId, scalaIDE.repository, idCounter, scalaIDEFolder))
+ features.map(f => generateFeatureProject(f, parentId, scalaIDE.repository, scalaIDEFolder))
}
- def generateFeatureProject(feature: FeatureDefinition, parentId: String, scalaIDERepository: P2Repository, idCounter: Iterator[Int], baseFolder: File): File = {
+ def generateFeatureProject(feature: FeatureDefinition, parentId: String, scalaIDERepository: P2Repository, baseFolder: File): File = {
val featureFolder = new File(baseFolder, feature.details.featureId)
featureFolder.mkdir()
- saveXml(new File(featureFolder, "pom.xml"), createFeaturePomXml(feature.repository, scalaIDERepository, parentId, idCounter.next))
+ saveXml(new File(featureFolder, "pom.xml"), createFeaturePomXml(feature.repository, scalaIDERepository, parentId))
saveXml(new File(featureFolder, "site.xml"), createSiteXml(feature))
featureFolder
@@ -152,7 +154,7 @@ object MavenProject2 {
</project>
}
- def createFeaturePomXml(featureRepository: P2Repository, scalaIDERepository: P2Repository, parentId: String, id: Int) = {
+ def createFeaturePomXml(featureRepository: P2Repository, scalaIDERepository: P2Repository, parentId: String) = {
// TODO: support for non-indigo build
<project xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd" xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<modelVersion>4.0.0</modelVersion>
@@ -165,7 +167,7 @@ object MavenProject2 {
<version>0.1.0-SNAPSHOT</version>
<relativePath>../..</relativePath>
</parent>
- <artifactId>org.scala-ide.ecosystem.generated{ id }</artifactId>
+ <artifactId>org.scala-ide.ecosystem.generated{ artifactIdSuffix.next }</artifactId>
<version>0.1.0-SNAPSHOT</version>
<description>Build project for the scalatest support in Scala IDE</description>
<packaging>eclipse-update-site</packaging>
@@ -228,7 +230,7 @@ object MavenProject2 {
private def featureXml(feature: FeatureDefinition): List[Elem] =
// TODO: fix category
// TODO: fix sourceFeatureId, should be option
- List(featureXml(feature.details.featureId, feature.version, "incubation")) :+ featureXml(feature.details.sourceFeatureId, feature.version, "source")
+ List(featureXml(feature.details.featureId, feature.version.toString, "incubation")) :+ featureXml(feature.details.sourceFeatureId, feature.version.toString, "source")
private def featureXml(id: String, version: String, category: String): Elem = {
<feature url={ "features/" + id + "_0.0.0.jar" } id={ id } version={ version }>
@@ -28,7 +28,7 @@ object DependencyUnit {
}
-case class InstallableUnit(id: String, version: Version, dependencies: Seq[DependencyUnit])
+case class InstallableUnit(id: String, version: Version, dependencies: List[DependencyUnit])
object InstallableUnit {
def apply(unit: Node): Option[InstallableUnit] = {
@@ -46,8 +46,8 @@ object InstallableUnit {
}
}
- private def getDependencies(unit: Node): Seq[DependencyUnit] = {
- unit \ "requires" \ "required" flatMap (DependencyUnit(_))
+ private def getDependencies(unit: Node): List[DependencyUnit] = {
+ (unit \ "requires" \ "required" flatMap (DependencyUnit(_))).toList
}
private def isBundle(unit: Node) = unit \ "artifacts" \ "artifact" \ "@classifier" exists (a => a.text == "osgi.bundle")
@@ -7,7 +7,7 @@ import scala.collection.immutable.TreeSet
class P2RepositoryTest {
- private def InstallableUnit(id: String, version: String, dependencies: Seq[DependencyUnit] = Nil): InstallableUnit =
+ private def InstallableUnit(id: String, version: String, dependencies: List[DependencyUnit] = Nil): InstallableUnit =
new InstallableUnit(id, new Version(version), dependencies)
@Test def testSimpleRepo() {

0 comments on commit 59ce0be

Please sign in to comment.