<NME> ProjectsCleanJob.scala
<BEF> ADDFILE
<MSG> Merge pull request #323 from dotta/issue/project-settings-should-not-trigger-rebuild-in-ui-thread-1001527

Clean projects in a background job when project settings' change
<DFF> @@ -0,0 +1,51 @@
+package scala.tools.eclipse.buildmanager
+
+import org.eclipse.core.resources.IProject
+import org.eclipse.core.resources.IncrementalProjectBuilder
+import org.eclipse.core.resources.ResourcesPlugin
+import org.eclipse.core.resources.WorkspaceJob
+import org.eclipse.core.runtime.IProgressMonitor
+import org.eclipse.core.runtime.IStatus
+import org.eclipse.core.runtime.Status
+import org.eclipse.core.runtime.SubProgressMonitor
+import org.eclipse.ui.progress.IProgressConstants2
+
+/** Job for asynchronously cleaning the passed `projects`.*/
+class ProjectsCleanJob private (projects: Seq[IProject]) {
+
+  private class DoCleanJob(projects: Seq[IProject]) extends WorkspaceJob("Cleaning project" + (if (projects.length > 1) "s" else "")) {
+    override def belongsTo(family: AnyRef): Boolean = ResourcesPlugin.FAMILY_MANUAL_BUILD.equals(family)
+    override def runInWorkspace(monitor: IProgressMonitor): IStatus = {
+      doClean(monitor)
+      Status.OK_STATUS
+    }
+
+    private def doClean(monitor: IProgressMonitor): Unit = {
+      try {
+        monitor.beginTask(getName(), projects.length)
+        for {
+          project <- projects
+          if project != null
+        } project.build(IncrementalProjectBuilder.CLEAN_BUILD, new SubProgressMonitor(monitor, 1))
+      }
+      finally monitor.done()
+    }
+  }
+
+  private def cleanJob: WorkspaceJob = {
+    val cleanJob = new DoCleanJob(projects)
+    cleanJob.setRule(ResourcesPlugin.getWorkspace().getRuleFactory().buildRule())
+    cleanJob.setUser(true)
+    cleanJob.setProperty(IProgressConstants2.SHOW_IN_TASKBAR_ICON_PROPERTY, true)
+    cleanJob
+  }
+
+  /** Schedule this job to run. */
+  def schedule(): Unit = {
+    if (projects.nonEmpty) cleanJob.schedule()
+  }
+}
+
+object ProjectsCleanJob {
+  def apply(projects: Seq[IProject]): ProjectsCleanJob = new ProjectsCleanJob(projects)
+}
\ No newline at end of file

{'commit': 'diff --git a/org.scala-ide.sdt.core/src/scala/tools/eclipse/buildmanager/ProjectsCleanJob.scala b/org.scala-ide.sdt.core/src/scala/tools/eclipse/buildmanager/ProjectsCleanJob.scala\nnew file mode 100644\nindex 000000000..aa18db0ca\n--- /dev/null\n+++ b/org.scala-ide.sdt.core/src/scala/tools/eclipse/buildmanager/ProjectsCleanJob.scala\n@@ -0,0 +1,51 @@\n+package scala.tools.eclipse.buildmanager\n+\n+import org.eclipse.core.resources.IProject\n+import org.eclipse.core.resources.IncrementalProjectBuilder\n+import org.eclipse.core.resources.ResourcesPlugin\n+import org.eclipse.core.resources.WorkspaceJob\n+import org.eclipse.core.runtime.IProgressMonitor\n+import org.eclipse.core.runtime.IStatus\n+import org.eclipse.core.runtime.Status\n+import org.eclipse.core.runtime.SubProgressMonitor\n+import org.eclipse.ui.progress.IProgressConstants2\n+\n+/** Job for asynchronously cleaning the passed `projects`.*/\n+class ProjectsCleanJob private (projects: Seq[IProject]) {\n+\n+  private class DoCleanJob(projects: Seq[IProject]) extends WorkspaceJob("Cleaning project" + (if (projects.length > 1) "s" else "")) {\n+    override def belongsTo(family: AnyRef): Boolean = ResourcesPlugin.FAMILY_MANUAL_BUILD.equals(family)\n+    override def runInWorkspace(monitor: IProgressMonitor): IStatus = {\n+      doClean(monitor)\n+      Status.OK_STATUS\n+    }\n+\n+    private def doClean(monitor: IProgressMonitor): Unit = {\n+      try {\n+        monitor.beginTask(getName(), projects.length)\n+        for {\n+          project <- projects\n+          if project != null\n+        } project.build(IncrementalProjectBuilder.CLEAN_BUILD, new SubProgressMonitor(monitor, 1))\n+      }\n+      finally monitor.done()\n+    }\n+  }\n+\n+  private def cleanJob: WorkspaceJob = {\n+    val cleanJob = new DoCleanJob(projects)\n+    cleanJob.setRule(ResourcesPlugin.getWorkspace().getRuleFactory().buildRule())\n+    cleanJob.setUser(true)\n+    cleanJob.setProperty(IProgressConstants2.SHOW_IN_TASKBAR_ICON_PROPERTY, true)\n+    cleanJob\n+  }\n+\n+  /** Schedule this job to run. */\n+  def schedule(): Unit = {\n+    if (projects.nonEmpty) cleanJob.schedule()\n+  }\n+}\n+\n+object ProjectsCleanJob {\n+  def apply(projects: Seq[IProject]): ProjectsCleanJob = new ProjectsCleanJob(projects)\n+}\n\\ No newline at end of file\ndiff --git a/org.scala-ide.sdt.core/src/scala/tools/eclipse/properties/CompilerSettings.scala b/org.scala-ide.sdt.core/src/scala/tools/eclipse/properties/CompilerSettings.scala\nindex b6a36672a..eec080e6b 100644\n--- a/org.scala-ide.sdt.core/src/scala/tools/eclipse/properties/CompilerSettings.scala\n+++ b/org.scala-ide.sdt.core/src/scala/tools/eclipse/properties/CompilerSettings.scala\n@@ -26,6 +26,7 @@ import scala.tools.nsc.CompilerCommand\n import org.eclipse.jface.fieldassist._\n import org.eclipse.jface.bindings.keys.KeyStroke\n import scala.tools.eclipse.logging.HasLogger\n+import scala.tools.eclipse.buildmanager.ProjectsCleanJob\n \n trait ScalaPluginPreferencePage extends HasLogger {\n   self: PreferencePage with EclipseSettings =>\n@@ -209,13 +210,13 @@ class CompilerSettings extends PropertyPage with IWorkbenchPreferencePage with E\n \n   /** Check who needs to rebuild with new compiler flags */\n   private def buildIfNecessary() = {\n-    getElement() match {\n+    val projects: Seq[IProject] = getElement() match {\n       case project: IProject =>\n         //Make sure project is rebuilt\n-        project.build(IncrementalProjectBuilder.CLEAN_BUILD, null)\n+        Seq(project)\n       case javaProject: IJavaProject =>\n         //Make sure project is rebuilt\n-        javaProject.getProject().build(IncrementalProjectBuilder.CLEAN_BUILD, null)\n+        Seq(javaProject.getProject())\n       case other =>\n         // rebuild all Scala projects that use global settings\n         val plugin = ScalaPlugin.plugin\n@@ -224,8 +225,10 @@ class CompilerSettings extends PropertyPage with IWorkbenchPreferencePage with E\n           p <- (plugin.workspaceRoot.getProjects())\n           scalaProject <- plugin.asScalaProject(p)\n           if !scalaProject.usesProjectSettings\n-        } scalaProject.underlying.build(IncrementalProjectBuilder.CLEAN_BUILD, null)\n+        } yield scalaProject.underlying\n     }\n+\n+    ProjectsCleanJob(projects).schedule()\n   }\n \n   // Eclipse PropertyPage API\n', 'commit_subject': 'Merge pull request #323 from dotta/issue/project-settings-should-not-trigger-rebuild-in-ui-thread-1001527', 'repo_name': 'scala-ide/scala-ide', 'committer': {'name': 'Mirco Dotta', 'email': '3effa02254bf323971bf24a01e6888e772f08c1f@typesafe.com', 'time_sec': '1361455129', 'tz_offset': '-480', 'date': {'seconds': '1361455129'}}, 'commit_tree': '586bf24aa67932d56a2a9835a6884d8df98abaad', 'commit_message': "Merge pull request #323 from dotta/issue/project-settings-should-not-trigger-rebuild-in-ui-thread-1001527\n\nClean projects in a background job when project settings' change", 'language_name': 'Shell', 'license': 'bsd-3-clause', 'hunks': '@@ -0,0 +1,51 @@\n+package scala.tools.eclipse.buildmanager\n+\n+import org.eclipse.core.resources.IProject\n+import org.eclipse.core.resources.IncrementalProjectBuilder\n+import org.eclipse.core.resources.ResourcesPlugin\n+import org.eclipse.core.resources.WorkspaceJob\n+import org.eclipse.core.runtime.IProgressMonitor\n+import org.eclipse.core.runtime.IStatus\n+import org.eclipse.core.runtime.Status\n+import org.eclipse.core.runtime.SubProgressMonitor\n+import org.eclipse.ui.progress.IProgressConstants2\n+\n+/** Job for asynchronously cleaning the passed `projects`.*/\n+class ProjectsCleanJob private (projects: Seq[IProject]) {\n+\n+  private class DoCleanJob(projects: Seq[IProject]) extends WorkspaceJob("Cleaning project" + (if (projects.length > 1) "s" else "")) {\n+    override def belongsTo(family: AnyRef): Boolean = ResourcesPlugin.FAMILY_MANUAL_BUILD.equals(family)\n+    override def runInWorkspace(monitor: IProgressMonitor): IStatus = {\n+      doClean(monitor)\n+      Status.OK_STATUS\n+    }\n+\n+    private def doClean(monitor: IProgressMonitor): Unit = {\n+      try {\n+        monitor.beginTask(getName(), projects.length)\n+        for {\n+          project <- projects\n+          if project != null\n+        } project.build(IncrementalProjectBuilder.CLEAN_BUILD, new SubProgressMonitor(monitor, 1))\n+      }\n+      finally monitor.done()\n+    }\n+  }\n+\n+  private def cleanJob: WorkspaceJob = {\n+    val cleanJob = new DoCleanJob(projects)\n+    cleanJob.setRule(ResourcesPlugin.getWorkspace().getRuleFactory().buildRule())\n+    cleanJob.setUser(true)\n+    cleanJob.setProperty(IProgressConstants2.SHOW_IN_TASKBAR_ICON_PROPERTY, true)\n+    cleanJob\n+  }\n+\n+  /** Schedule this job to run. */\n+  def schedule(): Unit = {\n+    if (projects.nonEmpty) cleanJob.schedule()\n+  }\n+}\n+\n+object ProjectsCleanJob {\n+  def apply(projects: Seq[IProject]): ProjectsCleanJob = new ProjectsCleanJob(projects)\n+}\n\\ No newline at end of file\n', 'addition_count': 51, 'deletion_count': 0, 'src_file': '/dev/null', 'tgt_file': 'b/org.scala-ide.sdt.core/src/scala/tools/eclipse/buildmanager/ProjectsCleanJob.scala', 'file_extension': '.scala', 'before_file': 'ADDFILE', 'message': "Merge pull request #323 from dotta/issue/project-settings-should-not-trigger-rebuild-in-ui-thread-1001527\n\nClean projects in a background job when project settings' change", 'author_name': 'Mirco Dotta', 'lang': 'scala-ide'}