Erlang Plugin for NetBeans in Scala#2: Set Environment for Writing NetBeans Module in Scala
Caoyuan Blog - - February 05, 2009I’m going to create new Erlang Editor module in Scala, the module project is under http://hg.netbeans.org/main/contrib/file/0caa5d009839/erlang.editor/ which I just committed in.
The first step is to get Scala source file mixed in Java based NetBeans source/project tree. After define project’s manifest,mf, we’ll create a special build.xml for this project under erlang.editor directory:
build.xml
<?xml version="1.0" encoding="UTF-8"?>
<project name="contrib/erlang.editor" default="netbeans" basedir="."> <import file="../../nbbuild/templates/projectized.xml"/> <import file="scala-build.xml"/> <!-- special jar target for csl --> <target name="jar" depends="init,compile,jar-prep" unless="is.jar.uptodate"> <taskdef name="csljar" classname="org.netbeans.modules.csl.CslJar" classpath="${nb_all}/csl.api/anttask/build/cslanttask.jar:${nb_all}/nbbuild/nbantext.jar"/> <csljar jarfile="${cluster}/${module.jar}" compress="${build.package.compress}" index="${build.package.index}" manifest="${manifest.mf}" stamp="${cluster}/.lastModified"> <fileset dir="${build.classes.dir}"/> </csljar> </target> <target name="compile" depends="init,projectized-common.compile,scala-compile"/> <target name="do-test-build" depends="init,test-init,projectized-common.do-test-build"/> <target name="rats" depends="init" description="Scanner"> <echo message="Rebuilding token scanner… ${rats.package.dir}"/> <java fork="yes" dir="${src.dir}/${rats.package.dir}" classname="xtc.parser.Rats" classpath="${rats.jar}"> <arg value="-in"/> <arg value="${src.dir}"/> <arg value="${rats.lexer.file}"/> </java> </target> </project>
This above build.xml imported NetBeans’ main template ant xml “../../nbbuild/templates/projectized.xml” and a special scala-build.xml file, which defines scalac and javac task for mixed Scala/Java module for NetBeans. You can ignore the “rats” target if you has no plan to write language’s lexer/parser in Rats! parser generator. scala-build.xml looks like:
scala-build.xml
<?xml version="1.0" encoding="UTF-8"?>
<project name="scala-module" default="netbeans" basedir="."> <import file="../../nbbuild/templates/projectized.xml"/> <target name="scala-taskdef" depends="init"> <echo message="Compiling scala sources via ${scala.library}, ${scala.compiler}"/> <taskdef resource="scala/tools/ant/antlib.xml"> <classpath> <pathelement location="${scala.library}"/> <pathelement location="${scala.compiler}"/> </classpath> </taskdef> </target> <property name="jar-excludes" value="**/*.java,**/*.form,**/package.html,**/doc-files/,**/*.scala"/> <target name="scala-compile" depends="init,up-to-date,scala-taskdef" unless="is.jar.uptodate"> <!-- javac's classpath should include scala.library and all these paths of "cp" --> <path id="javac.cp"> <pathelement path="${scala.libs}"/> <pathelement path="${module.classpath}"/> <pathelement path="${cp.extra}"/> </path> <!-- scalac will check class dependencies deeply, so we can not rely on public package only which is refed by ${module.classpath} --> <path id="scalac.cp"> <pathelement path="${scala.libs}"/> <pathelement path="${module.run.classpath}"/> <pathelement path="${cp.extra}"/> </path> <mkdir dir="${build.classes.dir}"/> <depend srcdir="${src.dir}" destdir="${build.classes.dir}" cache="build/depcache"> <classpath refid="scalac.cp"/> </depend> <!-- scalac --> <scalac srcdir="${src.dir}" destdir="${build.classes.dir}" encoding="UTF-8" target="jvm-${javac.target}"> <classpath refid="scalac.cp"/> </scalac> <!-- javac --> <nb-javac srcdir="${src.dir}" destdir="${build.classes.dir}" debug="${build.compiler.debug}" debuglevel="${build.compiler.debuglevel}" encoding="UTF-8" deprecation="${build.compiler.deprecation}" optimize="${build.compiler.optimize}" source="${javac.source}" target="${javac.target}" includeantruntime="false"> <classpath refid="javac.cp"/> <compilerarg line="${javac.compilerargs}"/> <processorpath refid="processor.cp"/> </nb-javac> <!-- Sanity check: --> <pathconvert pathsep=":" property="class.files.in.src"> <path> <fileset dir="${src.dir}"> <include name="**/*.class"/> </fileset> </path> </pathconvert> <fail> <condition> <not> <equals arg1="${class.files.in.src}" arg2=""/> </not> </condition> You have stray *.class files in ${src.dir} which you must remove. Probably you failed to clean your sources before updating them. </fail> <!-- OK, continue: --> <copy todir="${build.classes.dir}"> <fileset dir="${src.dir}" excludes="${jar-excludes}"/> </copy> </target> <target name="do-test-build" depends="projectized-common.do-test-build"> <scalac srcdir="${test.unit.src.dir}" destdir="${build.test.unit.classes.dir}" excludes="${test.excludes}" encoding="UTF-8"> <classpath refid="test.unit.cp"/> </scalac> </target>
</project>
You need also to set the project’s module dependencies on:
- org.netbeans.libs.scala
- org.netbeans.modules.csl.api
- org.netbeans.modules.lexer
- org.netbeans.modules.parsing.api
- org.openide.filesystems
etc, where org.netbeans.libs.scala is scala’s run time module, which is at contrib/libs.scala
And, the nbproject/project.properties which defines some important project building properties, such as:
javac.compilerargs=-Xlint:unchecked
javac.source=1.5
nbm.homepage=http://wiki.netbeans.org/Erlang scala.library=${cluster}/modules/ext/scala-library-2.7.3.jar
scala.compiler=${cluster}/modules/ext/scala-compiler-2.7.3.jar
scala.libs=\ ${scala.library}:\ ${scala.compiler}
You can write NetBeans’ module in Scala now.
Categories: Blogs Caoyuan Blog
Comments
No comments so far, you could be the first.Add comment
Erlang on Twitter
» ITJobs_EU_UK (ITJobs_EU_UK): #JB Ruby Developer ( Ruby / RoR Erlang LAMP ): Job Description : Ruby Developer / Software Engineer Location: Lo… http://t.co/74omWQ9m
» udzura (Uchio KONDO): 文字列操作が弱い、は今のErlangではfalseであると
» udzura (Uchio KONDO): Erlang , R14 あたりからutf-8の文字列の扱いに強くなったとのこと #shinjukuex
» winda_lestari63 (winda cliquers): gg usja di pikirin prins ank itw gjhe..RT:@Prinsia_2140
@Erlang_ABNIC @ji_bero @erlang_abnic @rb_120511
» ErlangSolutions (Erlang Solutions): Want to join the best of the best of the best? ESL is hiring 40 engineers! Join our Linkedin Group to keep updated http://t.co/CDB7qYeI
» Prinsia_2140 (˘⌣˘ pRiNsiAH ˘⌣˘): @Erlang_ABNI : http://t.co/j61ODMNv
» Erlang_ABNIC (Erlangga .A): JERA :) RT @AgnesMonicaFanz: #acakhuruf A-R-J-E . klue : kapok,lagu. jawab yuk NIC !
» Fedora_Updates (====================): Fedora 17 Update: erlang-misultin-0.9-1.fc17 http://t.co/u3ABUDkz
» HornedKavu (Max Riveiro): RT @shwars: Вчера в докладе career.ru на #itedu были озвучены новые востреб.профессии на IT-рынке: Haskell-, Lisp- и Erlang-программист!
» phyrexianengine (Vasily K.): RT @shwars: Вчера в докладе career.ru на #itedu были озвучены новые востреб.профессии на IT-рынке: Haskell-, Lisp- и Erlang-программист!
Statistics
Number of aggregated posts: 10498
Number of comments: 2115
Most recent article: May 15, 2012
Latest comments
» cheap soccer jerseys on Memory Models in Erlang vs Java: Nice discussion here,you are doing a great job. i was looking for this information. i found it on your page…
» mandesejohn on Couchbase Meetup at new HQ: Thanks for sharing experience. It should be really a great post. It should be knowledgeable and informative. Keep it up. flower delivery columbus ohio
» vermaseo on Scale means Skills: I’m surprised people are still commenting about this. George has been moved on to bigger and better things with the president for awhile now.ledikanten