Permalink
Browse files

Made ecosystem app to no generate build if not needed

  • Loading branch information...
skyluc committed Oct 19, 2012
1 parent 91177fe commit 3f73c75747e41e8d26e5e16b97eaaf7bd5616ab0
@@ -68,9 +68,9 @@ class GenerateEcosystemBuilds(rootFolder: String) {
}
- private def getAvailableScalaIDEs(ecosystems: List[EcosystemDescriptor], requestedFeatures: List[PluginDescriptor], availableFeatures: List[FeatureDefinition]): Either[String, Map[EcosystemDescriptor, Map[ScalaIDEDefinition, List[FeatureDefinition]]]] = {
+ 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, List[FeatureDefinition]]]): Either[String, Map[EcosystemDescriptor, Map[ScalaIDEDefinition, List[FeatureDefinition]]]] = {
+ def loop(repositories: List[EcosystemDescriptor], definitions: Map[EcosystemDescriptor, Map[ScalaIDEDefinition, Features]]): Either[String, Map[EcosystemDescriptor, Map[ScalaIDEDefinition, Features]]] = {
repositories match {
case Nil =>
Right(definitions)
@@ -86,23 +86,24 @@ class GenerateEcosystemBuilds(rootFolder: String) {
loop(ecosystems, Map())
}
- private def findScalaIDEsAndResolvedAvailableFeatures(ecosystem: EcosystemDescriptor, requestedFeatures: List[PluginDescriptor], availableFeatures: List[FeatureDefinition]): Either[String, Map[ScalaIDEDefinition, List[FeatureDefinition]]] = {
+ private def findScalaIDEsAndResolvedAvailableFeatures(ecosystem: EcosystemDescriptor, requestedFeatures: List[PluginDescriptor], availableFeatures: List[FeatureDefinition]): Either[String, Map[ScalaIDEDefinition, Features]] = {
for {
repository <- Repositories(ecosystem.site).right
baseRepository <- Repositories(ecosystem.baseSite).right
} yield findScalaIDEsAndResolvedAvailableFeatures(repository, baseRepository, requestedFeatures, availableFeatures)
}
- private def findScalaIDEsAndResolvedAvailableFeatures(repository: P2Repository, baseRepository: P2Repository, requestedFeatures: List[PluginDescriptor], availableFeatures: List[FeatureDefinition]): Map[ScalaIDEDefinition, List[FeatureDefinition]] = {
- val allAvailableFeatures = mergeFeatureList(availableFeatures, findExistingFeatures(requestedFeatures, repository))
+ 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, List[FeatureDefinition]]())((m, ui) =>
+ 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)))
+ m + (ScalaIDEDefinition(ui, baseRepository) -> filterFeaturesFor(ui, allAvailableFeatures, repository)))
}
- 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 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]] = {
@@ -241,3 +242,5 @@ object FeatureDefinition {
}
}
+
+case class Features(available: List[FeatureDefinition], existing: List[FeatureDefinition])
@@ -4,47 +4,95 @@ import java.io.File
import java.net.URL
import scala.xml.Elem
import scala.xml.XML
+import scala.collection.immutable.TreeSet
object MavenProject2 {
-
- val artifactIdSuffix= Iterator.from(1)
+
+ val artifactIdSuffix = Iterator.from(1)
private def saveXml(file: File, xml: Elem) {
XML.save(file.getAbsolutePath(), xml, "UTF-8", true)
}
- def generateEcosystemsProjects(ecosystemToScalaIDEToAvailableFeatures: Map[EcosystemDescriptor, Map[ScalaIDEDefinition, Seq[FeatureDefinition]]], baseFolder: File): String = {
+ def generateEcosystemsProjects(ecosystemToScalaIDEToAvailableFeatures: Map[EcosystemDescriptor, Map[ScalaIDEDefinition, Features]], baseFolder: File): String = {
+
+ println(ecosystemToScalaIDEToAvailableFeatures)
if (baseFolder.exists()) {
FileUtils.deleteFull(baseFolder)
}
baseFolder.mkdirs()
- val ecosystemFolders = ecosystemToScalaIDEToAvailableFeatures.map(e => generateEcosystemProject(e._1, e._2, baseFolder)).toSeq
+ val ecosystemFolders = ecosystemToScalaIDEToAvailableFeatures.flatMap(e => generateEcosystemProject(e._1, e._2, baseFolder)).toSeq
+
+ if (ecosystemFolders isEmpty) {
+ "Nothing to do"
+ } else {
+ saveXml(new File(baseFolder, "pom.xml"), createTopPomXml(ecosystemFolders))
+
+ "OK"
+ }
+ }
+
+ def generateEcosystemProject(ecosystem: EcosystemDescriptor, scalaIDEToAvailableFeatures: Map[ScalaIDEDefinition, Features], baseFolder: File): Option[File] = {
+ // check if it makes sense to regenerate the ecosystem
+ if (hasNewContent(ecosystem, scalaIDEToAvailableFeatures)) {
- saveXml(new File(baseFolder, "pom.xml"), createTopPomXml(ecosystemFolders))
+ val ecosystemFolder = new File(baseFolder, ecosystem.id)
+ ecosystemFolder.mkdir()
- "OK"
+ val artifactId = "ecosystem.%s".format(ecosystem.id)
+
+ 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))
+
+ Some(ecosystemFolder)
+
+ } else {
+ None
+ }
}
- def generateEcosystemProject(ecosystem: EcosystemDescriptor, scalaIDEToAvailableFeatures: Map[ScalaIDEDefinition, Seq[FeatureDefinition]], baseFolder: File): File = {
- val ecosystemFolder = new File(baseFolder, ecosystem.id)
- ecosystemFolder.mkdir()
+ private def hasNewContent(ecosystem: EcosystemDescriptor, scalaIDEToAvailableFeatures: Map[ScalaIDEDefinition, Features]): Boolean = {
- val artifactId = "ecosystem.%s".format(ecosystem.id)
+ // at this point, the sites exist
+ val siteRepo = Repositories(ecosystem.site).right.get
+ val stagingRepo = Repositories(ecosystem.baseSite).right.get
- val featureFolders: Seq[File] = scalaIDEToAvailableFeatures.flatMap(s => generateScalaIDEProjects(s._1, s._2, artifactId, ecosystemFolder)).toSeq
+ existsMissing(stagingRepo.uis, siteRepo.uis) || existsMissing(scalaIDEToAvailableFeatures)
+ }
- saveXml(new File(ecosystemFolder, "pom.xml"), createEcosystemPomXml(artifactId, ecosystem.baseSite, ecosystemFolder, featureFolders))
+ /**
+ * Check if all content of the staging site is already part of the public site.
+ * Returns <code>true</code> if some are missing, <code>false</code> otherwise.
+ */
+ private def existsMissing(stagingUIs: Map[String, TreeSet[InstallableUnit]], siteUIs: Map[String, TreeSet[InstallableUnit]]): Boolean = {
+ stagingUIs.exists((stagingFeature) => {
+ siteUIs.get(stagingFeature._1) match {
+ case Some(siteFeatureIUs) =>
+ // the list of versions is different
+ stagingFeature._2.map(_.version) != siteFeatureIUs.map(_.version)
+ case None =>
+ // UI defined in staging, but not in site
+ true
+ }
+ })
+ }
- ecosystemFolder
+ /**
+ * Check if it exists any add-on version to add or refresh.
+ */
+ private def existsMissing(scalaIDEToAvailableFeatures: Map[ScalaIDEDefinition, Features]): Boolean = {
+ scalaIDEToAvailableFeatures.exists(s => {
+ !s._2.available.isEmpty
+ })
}
- def generateScalaIDEProjects(scalaIDE: ScalaIDEDefinition, features: Seq[FeatureDefinition], parentId: String, baseFolder: File): Seq[File] = {
+ def generateScalaIDEProjects(scalaIDE: ScalaIDEDefinition, features: Features, parentId: String, baseFolder: File): Seq[File] = {
val scalaIDEFolder = new File(baseFolder, scalaIDE.sdtFeatureVersion.toString())
scalaIDEFolder.mkdir()
- features.map(f => generateFeatureProject(f, parentId, scalaIDE.repository, scalaIDEFolder))
+ (features.available ::: features.existing).map(f => generateFeatureProject(f, parentId, scalaIDE.repository, scalaIDEFolder))
}
def generateFeatureProject(feature: FeatureDefinition, parentId: String, scalaIDERepository: P2Repository, baseFolder: File): File = {
@@ -89,7 +137,7 @@ object MavenProject2 {
<maven>3.0</maven>
</prerequisites>
<parent>
- <groupId>org.scalaide</groupId>
+ <groupId>org.scalaide</groupId>
<artifactId>ecosystem.build</artifactId>
<version>0.1.0-SNAPSHOT</version>
</parent>
@@ -230,7 +278,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.toString, "incubation")) :+ featureXml(feature.details.sourceFeatureId, feature.version.toString, "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 }>
@@ -9,7 +9,7 @@ import java.io.IOException
import java.util.zip.ZipException
import scala.xml.Elem
import org.xml.sax.SAXException
-import java.net.{URL => jURL}
+import java.net.{ URL => jURL }
import scala.xml.Node
import org.osgi.framework.Version
import scala.collection.immutable.TreeSet
@@ -19,7 +19,7 @@ case class DependencyUnit(id: String, range: String)
object DependencyUnit {
def apply(required: Node): Option[DependencyUnit] = {
- val namespace= (required \ "@namespace" text)
+ val namespace = (required \ "@namespace" text)
if (namespace == "osgi.bundle" || namespace == "org.eclipse.equinox.p2.iu")
Some(new DependencyUnit(required \ "@name" text, required \ "@range" text))
else
@@ -41,11 +41,11 @@ object InstallableUnit {
implicit object DescendingOrdering extends Ordering[InstallableUnit] {
override def compare(x: InstallableUnit, y: InstallableUnit): Int = {
val diffId = x.id.compareTo(y.id)
- if(diffId == 0) -1 * x.version.compareTo(y.version) // same bundle name, compare versions
+ if (diffId == 0) -1 * x.version.compareTo(y.version) // same bundle name, compare versions
else diffId
}
}
-
+
private def getDependencies(unit: Node): List[DependencyUnit] = {
(unit \ "requires" \ "required" flatMap (DependencyUnit(_))).toList
}
@@ -55,13 +55,22 @@ object InstallableUnit {
private def isFeature(unit: Node) = unit \ "properties" \ "property" exists (e => (e \ "@name" text) == "org.eclipse.equinox.p2.type.group" && (e \ "@value" text) == "true")
}
-case class P2Repository private(uis: Map[String, TreeSet[InstallableUnit]], location: String) {
+case class P2Repository private (uis: Map[String, TreeSet[InstallableUnit]], location: String) {
- def findIU(unitId: String): TreeSet[InstallableUnit] =
+ def findIU(unitId: String): TreeSet[InstallableUnit] =
uis get (unitId) getOrElse (TreeSet.empty[InstallableUnit])
-
+
override def toString = "P2Repository(%s)".format(location)
+ override def equals(o: Any): Boolean = {
+ o match {
+ case P2Repository(_, `location`) => true
+ case _ => false
+ }
+ }
+
+ override def hashCode: Int = location.hashCode()
+
}
object P2Repository {
@@ -72,7 +81,7 @@ object P2Repository {
val unitsXML = (contentXml \ "units" \\ "unit")
val units = unitsXML.flatMap(InstallableUnit(_))
val grouped = units.groupBy(_.id)
- val sorted = for((key, values) <- grouped) yield (key, TreeSet(values : _*))
+ val sorted = for ((key, values) <- grouped) yield (key, TreeSet(values: _*))
P2Repository(sorted, location)
}
@@ -94,7 +103,7 @@ object P2Repository {
def fromUrl(repoUrl: String): Either[String, P2Repository] = {
fromUrl(new jURL(repoUrl))
}
-
+
def fromUrl(repoUrl: jURL): Either[String, P2Repository] = {
repoUrl.getProtocol() match {
case "file" =>
@@ -25,6 +25,7 @@ import scala.collection.JavaConverters.asScalaBufferConverter
* update-sites = ["http://scala-ide.dreamhosters.com/nightly-update-worksheet-scalaide21-29/site/",
* "http://scala-ide.dreamhosters.com/nightly-update-worksheet-scalaide21-210/site/"]
* source-feature-id = org.scala-ide.worksheet.source.feature
+ * website = "https://github.com/scala-ide/scala-worksheet"
* }
*
* @param name Is the plugin's feature id.
@@ -63,6 +63,7 @@ class UpdateAddonManifests(repoURL: String, rootFolder: String) {
private def updateVersions(p2Repo: P2Repository): Either[String, String] = {
for {
scalaIDEVersion <- getOneVersion(p2Repo, ScalaIDEId).right
+ // TODO: the version should be the one scalaIDE depends on
scalaLibraryVersion <- getOneVersion(p2Repo, ScalaLibraryId).right
scalaCompilerVersion <- getOneVersion(p2Repo, ScalaCompilerId).right
scalaIDEFeatureVersion <- getOneVersion(p2Repo, ScalaIDEFeatureIdOsgi).right

0 comments on commit 3f73c75

Please sign in to comment.