vseryakov / scalac-jedit

ScalacPlugin for jEdit, embeds Scala compiler and Jetty Web server inside jEdit's JVM for faster compilation and easy development.

Clone this repository (size: 61.2 KB): HTTPS / SSH
$ hg clone http://bitbucket.org/vseryakov/scalac-jedit/
commit 30: 4e3f0d8d50a9
parent 29: ed1d5ca28e9a
branch: default
Added create LiftWeb app options, it generates new simple app strructure
Vlad Seryakov / vseryakov
8 months ago

Changed (Δ5.8 KB):

raw changeset »

README (2 lines added, 1 lines removed)

Scalac.props (3 lines added, 1 lines removed)

actions.xml (7 lines added, 1 lines removed)

build.properties (6 lines added, 1 lines removed)

build.xml (8 lines added, 1 lines removed)

resources/scalac-compile.xml (57 lines added, 0 lines removed)

resources/scalac-create.xml (20 lines added, 0 lines removed)

resources/scalac.xml

scala/scalac.scala (69 lines added, 6 lines removed)

Up to file-list README:

1
Scala plugin for jEdit 1.0
1
Scala plugin for jEdit 1.1.0
2
2
Vlad Seryakov vseryakov@gmail.com
3
3
4
4
Introduction
@@ -33,6 +33,7 @@ Features
33
33
- Embeds Jetty Web server for Liftweb development
34
34
- Embedded Jetty automatically scans for newly compiled classes
35
35
  and restarts Web server automatically
36
- Creates simple Liftweb application structure
36
37
37
38
See index.html for details
38
39

Up to file-list Scalac.props:

@@ -3,7 +3,7 @@ plugin.scalac.ScalacPlugin.activate=star
3
3
4
4
plugin.scalac.ScalacPlugin.name=Scala Plugin
5
5
plugin.scalac.ScalacPlugin.author=Vlad Seryakov
6
plugin.scalac.ScalacPlugin.version=1.0.0
6
plugin.scalac.ScalacPlugin.version=1.1.0
7
7
plugin.scalac.ScalacPlugin.docs=index.html
8
8
plugin.scalac.ScalacPlugin.depend.0=jedit 04.03.07.00
9
9
plugin.scalac.ScalacPlugin.depend.1=jdk 1.5
@@ -14,10 +14,12 @@ plugin.scalac.ScalacPlugin.description=S
14
14
# Plugin menu
15
15
plugin.scalac.ScalacPlugin.menu=\
16
16
        scalac.compile \
17
        scalac.create \
17
18
        scalac.jetty
18
19
19
20
# Action labels for actions supplied by actions.xml
20
21
scalac.compile.label=Compile...
22
scalac.create.label=Create...
21
23
scalac.jetty.label=Jetty...
22
24
23
25
# Option pane

Up to file-list actions.xml:

6
6
              console.ConsolePlugin.compile(view,buffer);
7
7
		</CODE>
8
8
	</ACTION>
9
9
10
10
	<ACTION NAME="scalac.jetty">
11
11
		<CODE>
12
12
              console.commando.CommandoCommand.create(MiscUtilities.constructPath(jEdit.getSettingsDirectory(), "console" + File.separator + "commando" + File.separator + "jetty.xml")).invoke(view);
13
13
		</CODE>
14
14
	</ACTION>
15
15
16
	<ACTION NAME="scalac.create">
17
		<CODE>
18
              console.commando.CommandoCommand.create(MiscUtilities.constructPath(jEdit.getSettingsDirectory(), "console" + File.separator + "commando" + File.separator + "scalac-create.xml")).invoke(view);
19
		</CODE>
20
	</ACTION>
21
16
22
</ACTIONS>
17
23

Up to file-list build.properties:

1
1
build.support=${user.home}/src/jedit/build-support
2
2
3
jedit.user.home=${user.home}/Library/jEdit
3
# OS X home
4
#jedit.user.home=${user.home}/Library/jEdit
5
6
# Linux home
7
jedit.user.home=${user.home}/.jedit
8
4
9
jedit.install.dir=${user.home}/src/jedit/src/build
5
10
install.dir=${jedit.user.home}/jars
6
11

Up to file-list build.xml:

29
29
          </taskdef>
30
30
        </target>
31
31
32
        <target name="build.prepare">
32
	<condition property="build.downloaded">
33
           <and>
34
              <available file="${build.dir}/jetty.zip"/>
35
              <available file="${build.dir}/scala.tgz"/>
36
           </and>
37
        </condition>
38
39
        <target name="build.prepare" unless="build.downloaded">
33
40
          <mkdir dir="${build.dir}/classes" />
34
41
35
42
          <get src="http://www.scala-lang.org/downloads/distrib/files/scala-2.7.5.final.tgz" dest="${build.dir}/scala.tgz" />

Up to file-list resources/scalac-compile.xml:

1
<?xml version="1.0"?>
2
<!DOCTYPE COMMANDO SYSTEM "commando.dtd">
3
<!-- Author(s): Vlad Seryakov -->
4
<COMMANDO>
5
    <UI>
6
        <DIR_ENTRY LABEL="Project path" VARNAME="projectpath"/>
7
            
8
        <CAPTION LABEL="Custom settings">
9
        <DIR_ENTRY LABEL="Classes path" VARNAME="classpath"/>
10
        <DIR_ENTRY LABEL="Sources path" VARNAME="scalapath"/>
11
        <DIR_ENTRY LABEL="Output path" VARNAME="outputpath"/>
12
        </CAPTION>
13
            
14
        <CAPTION LABEL="Global settings">
15
        <DIR_ENTRY LABEL="Jar path" VARNAME="jarpath" />
16
        </CAPTION>
17
    </UI>
18
    <COMMANDS>
19
        <COMMAND SHELL="System" CONFIRM="FALSE">
20
            if (projectpath.length() > 0) {
21
                return "cd " + projectpath;
22
            }
23
            return "cd " + buffer.getDirectory();
24
        </COMMAND>
25
26
        <COMMAND SHELL="BeanShell" CONFIRM="FALSE">
27
            jEdit.saveAllBuffers(view, false);
28
            buf = new StringBuffer();
29
            buf.append("scalac.compiler.run(\"");
30
31
            if (scalapath.length() > 0) {
32
                buf.append(" -scalapath " + scalapath);
33
            } else {
34
                buf.append(" -scalapath " + buffer.getDirectory());
35
            }
36
            if (jarpath.length() > 0) {
37
                buf.append(" -jarpath " + jarpath);
38
            }
39
            if (classpath.length() > 0) {
40
                buf.append(" -classpath " + classpath);
41
            }
42
            if (outputpath.length() > 0) {
43
                (new File(outputpath)).mkdirs();
44
                buf.append(" -d " + outputpath);
45
            } else
46
            if (projectpath.length() > 0) {
47
                path = projectpath + File.separator + "classes";
48
                (new File(path)).mkdirs();
49
                buf.append(" -d " + path);
50
            } else {
51
                buf.append(" -d " + buffer.GetDirectory());
52
            }
53
            buf.append("\")");
54
            buf.toString()
55
        </COMMAND>
56
    </COMMANDS>
57
</COMMANDO>

Up to file-list resources/scalac-create.xml:

1
<?xml version="1.0"?>
2
<!DOCTYPE COMMANDO SYSTEM "commando.dtd">
3
<!-- Author(s): Vlad Seryakov -->
4
<COMMANDO>
5
    <UI>
6
       <CAPTION LABEL="Create new LiftWeb project">
7
         <DIR_ENTRY LABEL="Project path" VARNAME="projectpath"/>
8
       </CAPTION>
9
    </UI>
10
    <COMMANDS>
11
        <COMMAND SHELL="BeanShell" CONFIRM="FALSE">
12
            jEdit.saveAllBuffers(view, false);
13
14
            if (projectpath.length() == 0) {
15
                return "";
16
            }
17
            return "scalac.compiler.create(\"" + projectpath + "\")";
18
        </COMMAND>
19
    </COMMANDS>
20
</COMMANDO>

Up to file-list scala/scalac.scala:

@@ -25,6 +25,7 @@ import java.awt.GridBagConstraints
25
25
26
26
object compiler {
27
27
28
    val version = "1.1.0"
28
29
    val jarExt = ".+\\.[jJ][aA][rR]$"
29
30
    val scalaExt = ".+\\.[sS][cC][aA][lL][aA]$"
30
31
    val classExt = ".+\\.[cC][lL][aA][sS][sS]$"
@@ -160,7 +161,54 @@ object compiler {
160
161
            path += classes
161
162
        }
162
163
    }
163
    
164
165
    // Copy file from local resources into destination file
166
    def copyFile(src: String, dst: String): Unit = {
167
        Log.log(Log.NOTICE, this, "copying file " + src + " to " + dst)
168
169
        try {
170
            val ifile = new File(jEdit.getSettingsDirectory(), "scalac" + File.separator + src)
171
            val ofile = new File(dst)
172
            val odir = new File(ofile.getParent)
173
            odir.mkdirs
174
175
            var in: FileInputStream = null
176
            var out: FileOutputStream = null
177
178
            try {
179
                in = new FileInputStream(ifile)
180
                out = new FileOutputStream(ofile)
181
                IOUtilities.copyStream(null, in, out, false)
182
            } catch {
183
                case e: Exception => Log.log(Log.ERROR, this, e.printStackTrace())
184
            }
185
186
            IOUtilities.closeQuietly(in)
187
            IOUtilities.closeQuietly(out)            
188
        } catch {
189
            case e: Exception => Log.log(Log.ERROR, this, e.printStackTrace())
190
        }
191
    }
192
193
    // Delete file from home directory
194
    def deleteFile(file: String): Unit = {
195
        Log.log(Log.NOTICE, this, "deleting file " + file)
196
197
        try {
198
            new File(constructPath(jEdit.getSettingsDirectory(), file)).delete
199
        } catch {
200
            case e: Exception => Log.log(Log.ERROR, this, e.printStackTrace())
201
        }
202
    }
203
204
    // Create new application structure
205
    def create(dir: String): Unit = {
206
        copyFile("web.xml", dir + File.separator + "webapp" + File.separator + "WEB-INF" + File.separator + "web.xml")
207
        copyFile("index.html", dir + File.separator + "webapp" + File.separator + "index.html")
208
        copyFile("default.html", dir + File.separator + "webapp" + File.separator + "default.html")
209
        copyFile("boot.scala", dir + File.separator + "scala" + File.separator + "boot.scala")
210
    }
211
164
212
    // Run compiler with arguments as plain string
165
213
    def run(file: String): Unit = {
166
214
        run(file.split(" "))
@@ -322,26 +370,41 @@ object compiler {
322
370
class ScalacPlugin extends EditPlugin {
323
371
324
372
    override def start = {
325
        if (jEdit.getProperty("scalac.init") != "true") {
373
        if (jEdit.getProperty("scalac.init") != compiler.version) {
374
            
375
            val file = new File(constructPath(jEdit.getSettingsDirectory(), "scalac"))
376
            if (!file.exists) {
377
                file.mkdirs
378
            }
379
            
326
380
            // On first init, copy resource files into settings directory
327
381
            copyResource("/resources/catalog", "modes" + File.separator + "catalog")
328
382
            copyResource("/resources/scala.xml", "modes" + File.separator + "scala.xml")
329
383
            copyResource("/resources/build.xml", "console" + File.separator + "commando" + File.separator + "build.xml")
330
384
            copyResource("/resources/maven.xml", "console" + File.separator + "commando" + File.separator + "maven.xml")
331
            copyResource("/resources/scalac.xml", "console" + File.separator + "commando" + File.separator + "scalac.xml")
332
385
            copyResource("/resources/jetty.xml", "console" + File.separator + "commando" + File.separator + "jetty.xml")
386
            copyResource("/resources/scalac-compile.xml", "console" + File.separator + "commando" + File.separator + "scalac-compile.xml")
387
            copyResource("/resources/scalac-create.xml", "console" + File.separator + "commando" + File.separator + "scalac-create.xml")
388
389
            copyResource("/resources/web.xml", "scalac" + File.separator + "web.xml")
390
            copyResource("/resources/index.html", "scalac" + File.separator + "index.html")
391
            copyResource("/resources/default.html", "scalac" + File.separator + "default.html")
392
            copyResource("/resources/boot.scala", "scalac" + File.separator + "boot.scala")
393
394
            // Delete obsolete files
395
            compiler.deleteFile("console" + File.separator + "commando" + File.separator + "scalac.xml")
333
396
334
397
            // Bind compile command of the console to scala .bsh script
335
            jEdit.setProperty("mode.scala.commando.compile", "scalac")
398
            jEdit.setProperty("mode.scala.commando.compile", "scalac-compile")
336
399
            jEdit.setProperty("scalac.jarpath", "/usr/local/scala")
337
            jEdit.setProperty("scalac.init", "true")
400
            jEdit.setProperty("scalac.init", compiler.version)
338
401
339
402
            // Tell jedit and console to refresh their caches
340
403
            jEdit.reloadModes()
341
404
            console.ConsolePlugin.rescanCommands()
342
405
        }
343
406
    }
344
    
407
345
408
    // Copy file from resources into destination file
346
409
    def copyResource(src: String, dst: String): Unit = {
347
410
        Log.log(Log.NOTICE, this, "copying resource " + src + " to " + dst)