Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

A first step and updating AddOns

And P2Repository support 'file:///...' type URL
  • Loading branch information...
commit 8040014e2a1405da129dc249e726b7f966c75489 1 parent 95465d3
@skyluc skyluc authored
View
17 .classpath
@@ -1,7 +1,18 @@
<classpath>
- <classpathentry output="target/scala-2.9.2/classes" path="src/main/scala" kind="src"></classpathentry>
- <classpathentry output="target/scala-2.9.2/test-classes" path="src/test/scala" kind="src"></classpathentry>
+ <classpathentry output="target/scala-2.9.1/classes" path="src/main/scala" kind="src"></classpathentry>
+ <classpathentry output="target/scala-2.9.1/classes" path="src/main/java" kind="src"></classpathentry>
+ <classpathentry output="target/scala-2.9.1/test-classes" path="src/test/scala" kind="src"></classpathentry>
+ <classpathentry output="target/scala-2.9.1/test-classes" path="src/test/java" kind="src"></classpathentry>
<classpathentry kind="con" path="org.scala-ide.sdt.launching.SCALA_CONTAINER"></classpathentry>
+ <classpathentry kind="lib" path="/home/luc/.ivy2/cache/net.databinder.dispatch/core_2.9.1/jars/core_2.9.1-0.9.1.jar" sourcepath="/home/luc/.ivy2/cache/net.databinder.dispatch/core_2.9.1/srcs/core_2.9.1-0.9.1-sources.jar"></classpathentry>
+ <classpathentry kind="lib" path="/home/luc/.ivy2/cache/com.ning/async-http-client/jars/async-http-client-1.7.5.jar" sourcepath="/home/luc/.ivy2/cache/com.ning/async-http-client/srcs/async-http-client-1.7.5-sources.jar"></classpathentry>
+ <classpathentry kind="lib" path="/home/luc/.ivy2/cache/io.netty/netty/bundles/netty-3.4.4.Final.jar" sourcepath="/home/luc/.ivy2/cache/io.netty/netty/srcs/netty-3.4.4.Final-sources.jar"></classpathentry>
+ <classpathentry kind="lib" path="/home/luc/.ivy2/cache/org.slf4j/slf4j-api/jars/slf4j-api-1.6.2.jar" sourcepath="/home/luc/.ivy2/cache/org.slf4j/slf4j-api/srcs/slf4j-api-1.6.2-sources.jar"></classpathentry>
+ <classpathentry kind="lib" path="/home/luc/.ivy2/cache/junit/junit/jars/junit-4.8.1.jar" sourcepath="/home/luc/.ivy2/cache/junit/junit/srcs/junit-4.8.1-sources.jar"></classpathentry>
+ <classpathentry kind="lib" path="/home/luc/.ivy2/cache/com.novocode/junit-interface/jars/junit-interface-0.10-M1.jar" sourcepath="/home/luc/.ivy2/cache/com.novocode/junit-interface/srcs/junit-interface-0.10-M1-sources.jar"></classpathentry>
+ <classpathentry kind="lib" path="/home/luc/.ivy2/cache/junit/junit-dep/jars/junit-dep-4.10.jar" sourcepath="/home/luc/.ivy2/cache/junit/junit-dep/srcs/junit-dep-4.10-sources.jar"></classpathentry>
+ <classpathentry kind="lib" path="/home/luc/.ivy2/cache/org.hamcrest/hamcrest-core/jars/hamcrest-core-1.1.jar" sourcepath="/home/luc/.ivy2/cache/org.hamcrest/hamcrest-core/srcs/hamcrest-core-1.1-sources.jar"></classpathentry>
+ <classpathentry path="/home/luc/.ivy2/cache/org.scala-tools.testing/test-interface/jars/test-interface-0.5.jar" kind="lib"></classpathentry>
<classpathentry path="org.eclipse.jdt.launching.JRE_CONTAINER" kind="con"></classpathentry>
<classpathentry path="bin" kind="output"></classpathentry>
-</classpath>
+</classpath>
View
2  .gitignore
@@ -1,2 +1,4 @@
target/
.cache
+.settings/
+.worksheet/
View
13 src/main/scala/org/scalaide/buildtools/Ecosystem.scala
@@ -0,0 +1,13 @@
+package org.scalaide.buildtools
+
+object Ecosystem {
+
+ final val ScalaLibraryId = "org.scala-ide.scala.library"
+ final val ScalaCompilerId = "org.scala-ide.scala.compiler"
+ final val ScalaIDEId = "org.scala-ide.sdt.core"
+
+ final val PluginManifest = "META-INF/MANIFEST.MF"
+ final val FeatureDescriptor = "feature.xml"
+
+ final val RootOption = "--root=(.*)".r
+}
View
30 src/main/scala/org/scalaide/buildtools/P2Repository.scala
@@ -9,6 +9,7 @@ import java.io.IOException
import java.util.zip.ZipException
import scala.xml.Elem
import org.xml.sax.SAXException
+import java.net.URL
/** An installable unit in a P2 repository */
case class InstallableUnit(id: String, version: String)
@@ -26,6 +27,8 @@ class P2Repository(contentXml: Elem) {
}
object P2Repository {
+
+ final val CompressedContentFile= "content.jar"
def fromString(content: String): P2Repository = {
new P2Repository(XML.loadString(content))
@@ -42,8 +45,29 @@ object P2Repository {
* to the current process.
*/
def fromUrl(repoUrl: String): Either[String, P2Repository] = {
+ val url= new URL(repoUrl)
+ url.getProtocol() match {
+ case "file" =>
+ fromLocalFolder(url.getFile())
+ case _ =>
+ fromHttpUrl(repoUrl)
+ }
+ }
+
+ def fromLocalFolder(repoFolder: String): Either[String, P2Repository] = {
+ val contentFile= new File(repoFolder, CompressedContentFile)
+ if (contentFile.exists && contentFile.isFile) {
+ for {
+ xml <- getContentsFromZipFile(contentFile).right
+ } yield new P2Repository(xml)
+ } else {
+ Left("%s doesn't exist, or is not a file".format(contentFile.getAbsolutePath()))
+ }
+ }
+
+ def fromHttpUrl(repoUrl: String): Either[String, P2Repository] = {
val tmpFile = File.createTempFile("downloaded-content", ".jar")
- val svc = url(repoUrl) / "content.jar"
+ val svc = url(repoUrl) / CompressedContentFile
val downloadHandle = Http(svc > as.File(tmpFile)(null)).either
// try {
@@ -51,8 +75,8 @@ object P2Repository {
val stringExceptionHandle = for (ex <- downloadHandle.left) yield "Error downloading file " + ex.getMessage()
for {
- val d <- stringExceptionHandle().right
- val xml <- getContentsFromZipFile(tmpFile).right
+ d <- stringExceptionHandle().right
+ xml <- getContentsFromZipFile(tmpFile).right
} yield new P2Repository(xml)
// } finally Http.shutdown()
}
View
112 src/main/scala/org/scalaide/buildtools/UpdateAddonManifests.scala
@@ -0,0 +1,112 @@
+package org.scalaide.buildtools
+
+import dispatch.Http
+import java.io.File
+
+object UpdateAddonManifests {
+ import Ecosystem._
+
+ final val usage = "Usage: app [--root=<Scala IDE root folder>] <repository URL>"
+
+ def main(args: Array[String]) {
+ // parse arguments
+
+ if (args.length < 1) {
+ Console.err.println(usage)
+ Console.err.println("ERROR: missing repository URL")
+ System.exit(1)
+ }
+
+ val repoURL = args.last
+
+ val rootFolder = args.init.collectFirst {
+ case RootOption(root) =>
+ root
+ }.getOrElse(System.getProperty("user.dir"))
+
+ // does the job
+ val result = new UpdateAddonManifests(repoURL, rootFolder)()
+
+ // check the result
+ for {
+ error <- result.left
+ } {
+ Console.err.println("ERROR: %s".format(error))
+ System.exit(2)
+ }
+
+ // need to stop Dispatch in any cases
+ Http.shutdown()
+ }
+
+}
+
+class UpdateAddonManifests(repoURL: String, rootFolder: String) {
+
+ import Ecosystem._
+
+ def apply(): Either[String, String] = {
+ P2Repository.fromUrl(repoURL).right.flatMap(updateVersions(_))
+ }
+
+ private def updateVersions(p2Repo: P2Repository): Either[String, String] = {
+ for {
+ scalaIDEVersion <- getOneVersion(p2Repo, ScalaIDEId).right
+ scalaLibraryVersion <- getOneVersion(p2Repo, ScalaLibraryId).right
+ scalaCompilerVersion <- getOneVersion(p2Repo, ScalaCompilerId).right
+ result <- updateVersions(scalaIDEVersion, scalaLibraryVersion, scalaCompilerVersion).right
+ } yield result
+
+ }
+
+ private def updateVersions(scalaIDEVersion: String, scalaLibraryVersion: String, scalaCompilerVersion: String): Either[String, String] = {
+ println("%s, %s, %s".format(scalaIDEVersion, scalaLibraryVersion, scalaCompilerVersion))
+
+ val root = new File(rootFolder)
+
+ if (root.exists && root.isDirectory) {
+ val pluginManifestsResult = findPlugins(root).foldLeft[Either[String, String]](
+ Right("no plugin"))(
+ (res, manifest) => res.right.flatMap(r => updateVersionInPluginManifest(manifest, scalaIDEVersion, scalaLibraryVersion, scalaCompilerVersion)))
+ findFeatures(root).foldLeft(
+ pluginManifestsResult)(
+ (res, feature) => res.right.flatMap(r => updateVersionInFeature(feature, scalaIDEVersion, scalaLibraryVersion, scalaCompilerVersion)))
+ } else {
+ Left("%s doesn't exist or is not a directory".format(root.getAbsolutePath()))
+ }
+ }
+
+ private def updateVersionInPluginManifest(manifest: File, scalaIDEVersion: String, scalaLibraryVersion: String, scalaCompilerVersion: String): Either[String, String] = {
+ println(manifest.getAbsoluteFile())
+ Right("OK")
+ }
+
+ private def updateVersionInFeature(feature: File, scalaIDEVersion: String, scalaLibraryVersion: String, scalaCompilerVersion: String): Either[String, String] = {
+ println(feature.getAbsoluteFile())
+ Right("OK")
+ }
+
+ private def getOneVersion(p2Repo: P2Repository, pluginId: String): Either[String, String] = {
+ p2Repo.findIU(pluginId) match {
+ case Seq(iu) =>
+ Right(iu.version)
+ case _ =>
+ Left("More than one version found for %s. You may not be using the right repository.".format(pluginId))
+ }
+ }
+
+ private def findPlugins(root: File): List[File] = {
+ findFileInSubFolders(root, PluginManifest)
+ }
+
+ private def findFeatures(root: File): List[File] = {
+ findFileInSubFolders(root, FeatureDescriptor)
+ }
+
+ private def findFileInSubFolders(root: File, fileName: String): List[File] = {
+ (for {
+ folder <- root.listFiles().toList if (folder.isDirectory())
+ } yield new File(folder, fileName)) filter (_.exists)
+ }
+
+}
View
12 src/main/scala/org/scalaide/buildtools/UpdateScalaIDEManifests.scala
@@ -6,23 +6,22 @@ import java.io.FileWriter
object UpdateScalaIDEManifests {
- final val Usage = "app --root=<Scala IDE root folder>"
+ import Ecosystem._
+
+ final val Usage = "Usage: app [--root=<Scala IDE root folder>]"
final val PackagedManifestPath = "target/META-INF/MANIFEST.MF"
final val BaseManifestPath = "META-INF/MANIFEST.MF"
final val SavedManifestPath = "META-INF/MANIFEST.MF.original"
- final val RootOption = "--root=(.*)".r
final val BundleVersion = "Bundle-Version: (.*)".r
- final val ScalaLibraryId = "org.scala-ide.scala.library"
final val ScalaLibraryInManifest = ("(.*)" + ScalaLibraryId + "(,?.*)").r
final val ScalaLibraryInManifestWithVersion = ("(.*)" + ScalaLibraryId + """;bundle-version="([^"]*)"(,?.*)""").r
- final val ScalaCompilerId = "org.scala-ide.scala.compiler"
final val ScalaCompilerInManifest = ("(.*)" + ScalaCompilerId + "(,?.*)").r
final val ScalaCompilerInManifestWithVersion = ("(.*)" + ScalaCompilerId + """;bundle-version="([^"]*)"(,?.*)""").r
- final val projectsToUpdate = List("org.scala-ide.sdt.core", "org.scala-ide.sdt.debug")
+ final val projectsToUpdate = List(ScalaIDEId, "org.scala-ide.sdt.debug")
def main(args: Array[String]) {
// parse arguments
@@ -32,8 +31,6 @@ object UpdateScalaIDEManifests {
root
}.getOrElse(System.getProperty("user.dir"))
-
-
new UpdateScalaIDEManifests(rootFolder)()
}
@@ -41,6 +38,7 @@ object UpdateScalaIDEManifests {
class UpdateScalaIDEManifests(root: String) {
import UpdateScalaIDEManifests._
+ import Ecosystem._
val rootFolder = new File(root)
Please sign in to comment.
Something went wrong with that request. Please try again.