Class: Ensime

Inherits:
Object
  • Object
show all
Defined in:
lib/ensime.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(conf_path) ⇒ Ensime

Returns a new instance of Ensime.



16
17
18
19
20
21
22
23
24
25
# File 'lib/ensime.rb', line 16

def initialize conf_path
    @quiet = false
    @conf_path = conf_path
    @version = "0.9.10-SNAPSHOT"
    @conf = Hash[File.read(conf_path).gsub("\n", "").gsub(
        "(", " ").gsub(")", " ").gsub('"', "").split(" :").collect do |x|
        m = x.match("\([^ ]*\) *\(.*\)$")
        [m[1], m[2]]
        end] if File.exists? conf_path
end

Instance Attribute Details

#quietObject

Returns the value of attribute quiet.



5
6
7
# File 'lib/ensime.rb', line 5

def quiet
  @quiet
end

Instance Method Details

#get_classpathObject



26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
# File 'lib/ensime.rb', line 26

def get_classpath
    log = nil 
    classpath = nil
    dir = "/tmp/classpath_project_ensime"
    classpath_file = "#{dir}/classpath"
    if not File.exists? classpath_file
    FileUtils.mkdir_p dir
    build_sbt = <<EOF
import sbt._
import IO._
import java.io._
scalaVersion := "#{@conf['scala-version']}"
ivyScala := ivyScala.value map { _.copy(overrideScalaVersion = true) }
// allows local builds of scala
resolvers += Resolver.mavenLocal
resolvers += Resolver.sonatypeRepo("snapshots")
resolvers += "Typesafe repository" at "http://repo.typesafe.com/typesafe/releases/"
resolvers += "Akka Repo" at "http://repo.akka.io/repository"
libraryDependencies ++= Seq(
  "org.ensime" %% "ensime" % "#{@version}",
  "org.scala-lang" % "scala-compiler" % scalaVersion.value force(),
  "org.scala-lang" % "scala-reflect" % scalaVersion.value force(),
  "org.scala-lang" % "scalap" % scalaVersion.value force()
)
val saveClasspathTask = TaskKey[Unit]("saveClasspath", "Save the classpath to a file")
saveClasspathTask := {
  val managed = (managedClasspath in Runtime).value.map(_.data.getAbsolutePath)
  val unmanaged = (unmanagedClasspath in Runtime).value.map(_.data.getAbsolutePath)
  val out = file("#{classpath_file}")
  write(out, (unmanaged ++ managed).mkString(File.pathSeparator))
}
EOF
        FileUtils.mkdir_p "#{dir}/project"
        File.write("#{dir}/build.sbt", build_sbt)
        File.write("#{dir}/project/build.properties", "sbt.version=0.13.8")
        Dir.chdir dir do 
            log = `sbt saveClasspath`
        end
    end
    classpath = File.read classpath_file
    classpath + ":#{@conf['java-home']}/lib/tools.jar"
end

#is_running?Boolean

Returns:

  • (Boolean)


6
7
8
9
10
11
12
13
14
15
# File 'lib/ensime.rb', line 6

def is_running?
    port_path = @conf_path + "_cache/http"
    return false if not File.exists? port_path
    begin
        TCPSocket.open("127.0.0.1", File.read(port_path).chomp).close
    rescue => e
        return false
    end
    true
end

#runObject



68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
# File 'lib/ensime.rb', line 68

def run
    if @conf.nil?
        puts "no #{@conf_path} file found" if not quiet
        return
    end
    if is_running?
        puts "ensime is already running"
    else
        FileUtils.mkdir_p @conf['cache-dir']
        out = quiet ? ".ensime_cache/server.log" : STDOUT
        @pid = Process.spawn(
            "#{@conf['java-home']}/bin/java #{@conf['java-flags']} \
    -cp #{get_classpath} -Densime.config=#{@conf_path} org.ensime.server.Server",
        :out => out)
    end
    self
end

#stopObject



88
89
90
# File 'lib/ensime.rb', line 88

def stop
    Process.kill 'TERM', @pid if @pid
end

#waitObject



85
86
87
# File 'lib/ensime.rb', line 85

def wait
    Process.wait @pid if @pid
end