aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorprassee <prassee@users.noreply.github.com>2016-07-09 01:21:45 +0000
committerChristopher Vogt <oss.nsp@cvogt.org>2017-04-05 10:07:22 -0400
commit9bfe739adc62ba073342f78a64e24c18e12d4792 (patch)
tree9067939539862cf4ecbf23cbf4c7a79017b96527
parent965095f8cf68707b6d164633baa858eb7ac33b4c (diff)
downloadcbt-9bfe739adc62ba073342f78a64e24c18e12d4792.tar.gz
cbt-9bfe739adc62ba073342f78a64e24c18e12d4792.tar.bz2
cbt-9bfe739adc62ba073342f78a64e24c18e12d4792.zip
Add IntelliJ IDEA project generator plugin
-rw-r--r--.gitignore2
-rw-r--r--examples/idea-plugin-example/README.md1
-rw-r--r--examples/idea-plugin-example/build/build.scala8
-rw-r--r--examples/idea-plugin-example/build/build/build.scala6
-rw-r--r--examples/idea-plugin-example/src/Main.scala3
-rw-r--r--plugins/idea_plugin/IdeaPlugin.scala85
-rw-r--r--plugins/idea_plugin/build/build.scala9
-rw-r--r--stage2/plugins.scala1
8 files changed, 115 insertions, 0 deletions
diff --git a/.gitignore b/.gitignore
index fb5cb68..8f25ae3 100644
--- a/.gitignore
+++ b/.gitignore
@@ -19,3 +19,5 @@ examples/scalajs-react-example/server/public/generated
test/simple/src_generated
examples/scalapb-example/src_generated
ScalatexGenerated.scala
+.idea/
+*.iml
diff --git a/examples/idea-plugin-example/README.md b/examples/idea-plugin-example/README.md
new file mode 100644
index 0000000..8b13789
--- /dev/null
+++ b/examples/idea-plugin-example/README.md
@@ -0,0 +1 @@
+
diff --git a/examples/idea-plugin-example/build/build.scala b/examples/idea-plugin-example/build/build.scala
new file mode 100644
index 0000000..6252402
--- /dev/null
+++ b/examples/idea-plugin-example/build/build.scala
@@ -0,0 +1,8 @@
+
+import cbt._
+import idea_plugin.IdeaPlugin
+
+
+class Build(val context: Context) extends BaseBuild with IdeaPlugin {
+ override def name = "idea-plugin-example"
+}
diff --git a/examples/idea-plugin-example/build/build/build.scala b/examples/idea-plugin-example/build/build/build.scala
new file mode 100644
index 0000000..df4934a
--- /dev/null
+++ b/examples/idea-plugin-example/build/build/build.scala
@@ -0,0 +1,6 @@
+
+import cbt._
+
+class Build(val context: Context) extends BuildBuild {
+ override def dependencies = super.dependencies :+ plugins.ideaPlugin
+}
diff --git a/examples/idea-plugin-example/src/Main.scala b/examples/idea-plugin-example/src/Main.scala
new file mode 100644
index 0000000..ec68f73
--- /dev/null
+++ b/examples/idea-plugin-example/src/Main.scala
@@ -0,0 +1,3 @@
+object Main extends App {
+ println("This is an example Application for illustrating CBT IDEA plugin ")
+}
diff --git a/plugins/idea_plugin/IdeaPlugin.scala b/plugins/idea_plugin/IdeaPlugin.scala
new file mode 100644
index 0000000..97e53b1
--- /dev/null
+++ b/plugins/idea_plugin/IdeaPlugin.scala
@@ -0,0 +1,85 @@
+package idea_plugin
+
+import java.io.{File, FileWriter}
+
+import cbt.{BaseBuild, ExitCode}
+
+trait IdeaPlugin extends BaseBuild {
+
+ import IdeaPlugin._
+
+ // @TODO add only the top level dependencies
+ // @TODO return exit code dynamically
+ def generateIdeaProject: ExitCode = {
+
+ val dependencyEntry: (String) => String = (url: String) => <orderEntry type="module-library">
+ <library>
+ <CLASSES>
+ <root url={url}/>
+ </CLASSES>
+ <JAVADOC/>
+ <SOURCES/>
+ </library>
+ </orderEntry>.toString()
+
+ val moduleDir = projectDirectory.getPath
+ val projectDependencies: List[String] = for {
+ depJarFile <- this.dependencies
+ .flatMap(dep => dep.dependenciesArray().toList)
+ .flatMap(x => x.exportedClasspathArray().toList)
+ .toList
+ depIdeaOrderEntry = dependencyEntry(
+ s"jar://$moduleDir/../cbt/${depJarFile.getPath.split("/cbt")(1)}!/")
+ } yield depIdeaOrderEntry
+
+ val imlFile = new File(projectDirectory.getPath + s"/$name.iml")
+ if (!imlFile.exists()) {
+ imlFile.createNewFile()
+ }
+ val fw = new FileWriter(imlFile.getPath, false)
+ fw.write(templateWithCBTSources(projectDependencies.mkString("\n"), moduleDir))
+ fw.close()
+ ExitCode.Success
+ }
+
+}
+
+private[idea_plugin] object IdeaPlugin {
+
+ // @TODO inject from the build.scala
+ // @TODO infer scala version from project
+ // path of cbt relative to module dir
+
+ private val templateWithCBTSources: (String, String) => String = (dependencies: String,
+ moduleRootDir: String) =>
+ """<?xml version="1.0" encoding="UTF-8"?>
+ |<module type="JAVA_MODULE" version="4">
+ | <component name="NewModuleRootManager" inherit-compiler-output="true">
+ | <exclude-output />
+ | <content url="file://$MODULE_DIR$/../cbt/compatibility">
+ | <sourceFolder url="file://$MODULE_DIR$/../cbt/compatibility" isTestSource="false" />
+ | <excludeFolder url="file://$MODULE_DIR$/../cbt/compatibility/target/scala-2.11" />
+ | </content>
+ | <content url="file://$MODULE_DIR$/../cbt/nailgun_launcher">
+ | <sourceFolder url="file://$MODULE_DIR$/../cbt/nailgun_launcher" isTestSource="false" />
+ | <excludeFolder url="file://$MODULE_DIR$/../cbt/nailgun_launcher/target" />
+ | </content>
+ | <content url="file://$MODULE_DIR$/../cbt/stage1">
+ | <sourceFolder url="file://$MODULE_DIR$/../cbt/stage1" isTestSource="false" />
+ | <excludeFolder url="file://$MODULE_DIR$/../cbt/stage1/target/scala-2.11" />
+ | </content>
+ | <content url="file://$MODULE_DIR$/../cbt/stage2">
+ | <sourceFolder url="file://$MODULE_DIR$/../cbt/stage2" isTestSource="false" />
+ | <excludeFolder url="file://$MODULE_DIR$/../cbt/stage2/target/scala-2.11" />
+ | </content>
+ | <content url="file://$MODULE_DIR$">
+ | <sourceFolder url="file://$MODULE_DIR$/src/main/scala/main" isTestSource="false" />
+ | <sourceFolder url="file://$MODULE_DIR$/src/test/scala" isTestSource="false" />
+ | </content>
+ | <orderEntry type="inheritedJdk" />
+ | <orderEntry type="sourceFolder" forTests="false" />
+ | <orderEntry type="library" name="scala-sdk-2.11.7" level="application" /> |
+ | """.stripMargin + dependencies +
+ """ </component>
+ |</module>""".stripMargin
+}
diff --git a/plugins/idea_plugin/build/build.scala b/plugins/idea_plugin/build/build.scala
new file mode 100644
index 0000000..991e07e
--- /dev/null
+++ b/plugins/idea_plugin/build/build.scala
@@ -0,0 +1,9 @@
+import cbt._
+
+class Build(val context: Context) extends Plugin {
+ override def dependencies =
+ super.dependencies ++
+ Resolver(mavenCentral).bind(
+ ScalaDependency("org.scala-lang.modules", "scala-xml", "1.0.5")
+ )
+}
diff --git a/stage2/plugins.scala b/stage2/plugins.scala
index ea1aa74..c48a31b 100644
--- a/stage2/plugins.scala
+++ b/stage2/plugins.scala
@@ -7,6 +7,7 @@ class plugins( context: Context, scalaVersion: String ) {
),
None
)
+ final lazy val ideaPlugin = plugin( "idea_plugin" )
final lazy val googleJavaFormat = plugin( "google-java-format" )
final lazy val proguard = plugin( "proguard" )
final lazy val sbtLayout = plugin( "sbt_layout" )