Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -1,10 +1,8 @@
package org.scalaide.play2


import org.junit.Test
import org.junit.Before
import org.junit.runner.RunWith
import org.junit.Assert._
import org.junit.runners.Suite.SuiteClasses
import org.scalaide.play2.routeeditor.hyperlink.RouteHyperlinkDetectorTest
import org.scalaide.play2.routeeditor.hyperlink.MethodFinderTest
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,24 @@ class TemplateCompilationUnitTest {
val tu = TemplateCompilationUnit(tFile)
assertTrue(tu.generatedSource.isSuccess)
}

@Test
def scala_nature_is_automatically_added_when_creating_template_unit() {
assertTrue(project.hasScalaNature)

// remove the Scala nature
import scala.tools.eclipse.actions.ToggleScalaNatureAction
val toggleScalaNature = new ToggleScalaNatureAction()
toggleScalaNature.performAction(project.underlying)

assertFalse("The test project should not have the Scala nature at this point.", project.hasScalaNature)

val indexFile = file("app/views/index.scala.html")
val templateCU = TemplateCompilationUnit(indexFile)

assertTrue("Creating a `TemplateCompilationUnit` should force the underlying project to automatically add the Scala nature.", project.hasScalaNature)
}

}

/**
Expand Down
7 changes: 7 additions & 0 deletions org.scala-ide.play2/src/org/scalaide/play2/IssueTracker.scala
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
package org.scalaide.play2

object IssueTracker {
final val Url: String = "https://github.com/scala-ide/scala-ide-play2/issues"

def createATicketMessage: String = s"This is a bug. Please, file a ticket at ${Url}."
}
20 changes: 11 additions & 9 deletions org.scala-ide.play2/src/org/scalaide/play2/PlayPlugin.scala
Original file line number Diff line number Diff line change
@@ -1,11 +1,14 @@
package org.scalaide.play2

import scala.tools.eclipse.ScalaPlugin

import org.eclipse.core.resources.IProject
import org.eclipse.ui.plugin.AbstractUIPlugin
import org.osgi.framework.BundleContext
import org.eclipse.core.resources.ResourcesPlugin
import org.eclipse.core.runtime.Status
import org.eclipse.jface.preference.IPreferenceStore
import org.eclipse.jface.resource.ImageDescriptor
import org.eclipse.ui.plugin.AbstractUIPlugin
import org.osgi.framework.BundleContext

object PlayPlugin {
@volatile var plugin: PlayPlugin = _
Expand All @@ -14,26 +17,25 @@ object PlayPlugin {
final val RouteFormatterMarginId = PluginId + ".routeeditor.margin"
final val TemplateExtension = "scala.html"

def prefStore = plugin.getPreferenceStore
def prefStore: IPreferenceStore = plugin.getPreferenceStore

def getImageDescriptor(path: String) = {
def getImageDescriptor(path: String): ImageDescriptor = {
AbstractUIPlugin.imageDescriptorFromPlugin(PluginId, path);
}

def log(status: Int, msg: String, ex: Throwable = null) {
def log(status: Int, msg: String, ex: Throwable = null): Unit = {
plugin.getLog.log(new Status(status, plugin.getBundle().getSymbolicName(), msg, ex))
}
}

class PlayPlugin extends AbstractUIPlugin {
import PlayPlugin._
override def start(context: BundleContext) = {
override def start(context: BundleContext): Unit = {
super.start(context)
PlayPlugin.plugin = this
initializeProjects()
}

override def stop(context: BundleContext) = {
override def stop(context: BundleContext): Unit = {
PlayPlugin.plugin = null
super.stop(context)
}
Expand All @@ -43,7 +45,7 @@ class PlayPlugin extends AbstractUIPlugin {
scalaProject map (PlayProject(_))
}

def initializeProjects() = {
private def initializeProjects(): Unit = {
for {
iProject <- ResourcesPlugin.getWorkspace.getRoot.getProjects
if iProject.isOpen
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ class PlayProject private (val scalaProject: ScalaProject) {

object PlayProject {
private val projects = new AutoHashMap((scalaProject: ScalaProject) => new PlayProject(scalaProject))
def apply(scalaProject: ScalaProject) = {
def apply(scalaProject: ScalaProject): PlayProject = {
projects(scalaProject)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import java.io.PrintStream
import scala.tools.eclipse.InteractiveCompilationUnit
import scala.tools.eclipse.ScalaPlugin
import scala.tools.eclipse.ScalaPresentationCompiler
import scala.tools.eclipse.ScalaProject
import scala.tools.eclipse.logging.HasLogger
import scala.tools.eclipse.util.EclipseResource
import scala.tools.nsc.interactive.Response
Expand All @@ -15,12 +16,14 @@ import scala.tools.nsc.util.SourceFile
import scala.util.Try

import org.eclipse.core.resources.IFile
import org.eclipse.core.resources.IProject
import org.eclipse.jdt.core.compiler.IProblem
import org.eclipse.jface.text.IDocument
import org.eclipse.jface.text.IRegion
import org.eclipse.jface.text.Region
import org.eclipse.ui.IEditorInput
import org.eclipse.ui.part.FileEditorInput
import org.scalaide.play2.IssueTracker
import org.scalaide.play2.PlayPlugin
import org.scalaide.play2.PlayProject
import org.scalaide.play2.templateeditor.compiler.CompilerUsing
Expand All @@ -45,7 +48,27 @@ case class TemplateCompilationUnit(val workspaceFile: IFile) extends Interactive
new VirtualFile(getTemplateFullPath)
}

override lazy val scalaProject = ScalaPlugin.plugin.asScalaProject(workspaceFile.getProject).get
override val scalaProject: ScalaProject = {
def obtainScalaProject(project: IProject): ScalaProject = {
ScalaPlugin.plugin.asScalaProject(project) match {
case Some(scalaProject) => scalaProject
case None =>
def programmaticallyAddScalaNature(project: IProject): Unit = {
import scala.tools.eclipse.actions.ToggleScalaNatureAction
val toggleScalaNature = new ToggleScalaNatureAction()
toggleScalaNature.performAction(project)
}
programmaticallyAddScalaNature(project)
ScalaPlugin.plugin.asScalaProject(project) getOrElse {
val message = s"Failed to create a ScalaProject instance for Play template ${workspaceFile.getFullPath().toOSString()}. ${IssueTracker.createATicketMessage}"
throw new IllegalStateException(message)
}
}
}

obtainScalaProject(workspaceFile.getProject)
}

lazy val playProject = PlayProject(scalaProject)

def getTemplateName = workspaceFile.getName()
Expand Down Expand Up @@ -83,9 +106,8 @@ case class TemplateCompilationUnit(val workspaceFile: IFile) extends Interactive
r
}

def connect(doc: IDocument): this.type = {
def connect(doc: IDocument): Unit = {
document = Option(doc)
this
}

override def currentProblems: List[IProblem] = {
Expand Down Expand Up @@ -177,6 +199,7 @@ object TemplateCompilationUnit {
else {
val unit = fromEditorInput(input)
unit.connect(templateEditor.getDocumentProvider().getDocument(input))
unit
}
}

Expand Down
6 changes: 3 additions & 3 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@
<scala.version.short>2.10</scala.version.short>
<ecosystem-scala-version>210</ecosystem-scala-version>

<!-- play version depend on Scala version. 2.9.x -> 2.0.x, 2.10.x -> 2.1.x !-->
<!-- play version depend on Scala version. 2.10.x -> 2.1.x !-->
<play.artifactId>play_2.10</play.artifactId>
<play.version>2.1.0</play.version>
<templates.artifactId>templates_2.10</templates.artifactId>
Expand Down Expand Up @@ -182,8 +182,8 @@

<!-- scm configuration is require to extract the github hash-->
<scm>
<connection>scm:git://github.com/skyluc/plugin.git</connection>
<url>https://github.com/skyluc/plugin</url>
<connection>scm:git://github.com/scala-ide/scala-ide-play2.git</connection>
<url>https://github.com/scala-ide/scala-ide-play2</url>
</scm>

<dependencyManagement>
Expand Down