1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
1.2 +++ b/java/ant/build.xml Sun Jul 06 00:12:56 2008 +0200
1.3 @@ -0,0 +1,69 @@
1.4 +<?xml version="1.0" encoding="UTF-8"?>
1.5 +<!-- You may freely edit this file. See commented blocks below for -->
1.6 +<!-- some examples of how to customize the build. -->
1.7 +<!-- (If you delete it and reopen the project it will be recreated.) -->
1.8 +<project name="ant" default="default" basedir=".">
1.9 + <description>Builds, tests, and runs the project ant.</description>
1.10 + <import file="nbproject/build-impl.xml"/>
1.11 + <!--
1.12 +
1.13 + There exist several targets which are by default empty and which can be
1.14 + used for execution of your tasks. These targets are usually executed
1.15 + before and after some main targets. They are:
1.16 +
1.17 + -pre-init: called before initialization of project properties
1.18 + -post-init: called after initialization of project properties
1.19 + -pre-compile: called before javac compilation
1.20 + -post-compile: called after javac compilation
1.21 + -pre-compile-single: called before javac compilation of single file
1.22 + -post-compile-single: called after javac compilation of single file
1.23 + -pre-compile-test: called before javac compilation of JUnit tests
1.24 + -post-compile-test: called after javac compilation of JUnit tests
1.25 + -pre-compile-test-single: called before javac compilation of single JUnit test
1.26 + -post-compile-test-single: called after javac compilation of single JUunit test
1.27 + -pre-jar: called before JAR building
1.28 + -post-jar: called after JAR building
1.29 + -post-clean: called after cleaning build products
1.30 +
1.31 + (Targets beginning with '-' are not intended to be called on their own.)
1.32 +
1.33 + Example of inserting an obfuscator after compilation could look like this:
1.34 +
1.35 + <target name="-post-compile">
1.36 + <obfuscate>
1.37 + <fileset dir="${build.classes.dir}"/>
1.38 + </obfuscate>
1.39 + </target>
1.40 +
1.41 + For list of available properties check the imported
1.42 + nbproject/build-impl.xml file.
1.43 +
1.44 +
1.45 + Another way to customize the build is by overriding existing main targets.
1.46 + The targets of interest are:
1.47 +
1.48 + -init-macrodef-javac: defines macro for javac compilation
1.49 + -init-macrodef-junit: defines macro for junit execution
1.50 + -init-macrodef-debug: defines macro for class debugging
1.51 + -init-macrodef-java: defines macro for class execution
1.52 + -do-jar-with-manifest: JAR building (if you are using a manifest)
1.53 + -do-jar-without-manifest: JAR building (if you are not using a manifest)
1.54 + run: execution of project
1.55 + -javadoc-build: Javadoc generation
1.56 + test-report: JUnit report generation
1.57 +
1.58 + An example of overriding the target for project execution could look like this:
1.59 +
1.60 + <target name="run" depends="ant-impl.jar">
1.61 + <exec dir="bin" executable="launcher.exe">
1.62 + <arg file="${dist.jar}"/>
1.63 + </exec>
1.64 + </target>
1.65 +
1.66 + Notice that the overridden target depends on the jar target and not only on
1.67 + the compile target as the regular run target does. Again, for a list of available
1.68 + properties which you can use, check the target you are overriding in the
1.69 + nbproject/build-impl.xml file.
1.70 +
1.71 + -->
1.72 +</project>
2.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
2.2 +++ b/java/ant/nbproject/build-impl.xml Sun Jul 06 00:12:56 2008 +0200
2.3 @@ -0,0 +1,629 @@
2.4 +<?xml version="1.0" encoding="UTF-8"?>
2.5 +<!--
2.6 +*** GENERATED FROM project.xml - DO NOT EDIT ***
2.7 +*** EDIT ../build.xml INSTEAD ***
2.8 +
2.9 +For the purpose of easier reading the script
2.10 +is divided into following sections:
2.11 +
2.12 + - initialization
2.13 + - compilation
2.14 + - jar
2.15 + - execution
2.16 + - debugging
2.17 + - javadoc
2.18 + - junit compilation
2.19 + - junit execution
2.20 + - junit debugging
2.21 + - applet
2.22 + - cleanup
2.23 +
2.24 + -->
2.25 +<project xmlns:j2seproject1="http://www.netbeans.org/ns/j2se-project/1" xmlns:j2seproject3="http://www.netbeans.org/ns/j2se-project/3" xmlns:jaxrpc="http://www.netbeans.org/ns/j2se-project/jax-rpc" basedir=".." default="default" name="ant-impl">
2.26 + <target depends="test,jar,javadoc" description="Build and test whole project." name="default"/>
2.27 + <!--
2.28 + ======================
2.29 + INITIALIZATION SECTION
2.30 + ======================
2.31 + -->
2.32 + <target name="-pre-init">
2.33 + <!-- Empty placeholder for easier customization. -->
2.34 + <!-- You can override this target in the ../build.xml file. -->
2.35 + </target>
2.36 + <target depends="-pre-init" name="-init-private">
2.37 + <property file="nbproject/private/config.properties"/>
2.38 + <property file="nbproject/private/configs/${config}.properties"/>
2.39 + <property file="nbproject/private/private.properties"/>
2.40 + </target>
2.41 + <target depends="-pre-init,-init-private" name="-init-user">
2.42 + <property file="${user.properties.file}"/>
2.43 + <!-- The two properties below are usually overridden -->
2.44 + <!-- by the active platform. Just a fallback. -->
2.45 + <property name="default.javac.source" value="1.4"/>
2.46 + <property name="default.javac.target" value="1.4"/>
2.47 + </target>
2.48 + <target depends="-pre-init,-init-private,-init-user" name="-init-project">
2.49 + <property file="nbproject/configs/${config}.properties"/>
2.50 + <property file="nbproject/project.properties"/>
2.51 + </target>
2.52 + <target depends="-pre-init,-init-private,-init-user,-init-project,-init-macrodef-property" name="-do-init">
2.53 + <available file="${manifest.file}" property="manifest.available"/>
2.54 + <condition property="manifest.available+main.class">
2.55 + <and>
2.56 + <isset property="manifest.available"/>
2.57 + <isset property="main.class"/>
2.58 + <not>
2.59 + <equals arg1="${main.class}" arg2="" trim="true"/>
2.60 + </not>
2.61 + </and>
2.62 + </condition>
2.63 + <condition property="manifest.available+main.class+mkdist.available">
2.64 + <and>
2.65 + <istrue value="${manifest.available+main.class}"/>
2.66 + <isset property="libs.CopyLibs.classpath"/>
2.67 + </and>
2.68 + </condition>
2.69 + <condition property="have.tests">
2.70 + <or>
2.71 + <available file="${test.src.dir}"/>
2.72 + </or>
2.73 + </condition>
2.74 + <condition property="have.sources">
2.75 + <or>
2.76 + <available file="${src.dir}"/>
2.77 + </or>
2.78 + </condition>
2.79 + <condition property="netbeans.home+have.tests">
2.80 + <and>
2.81 + <isset property="netbeans.home"/>
2.82 + <isset property="have.tests"/>
2.83 + </and>
2.84 + </condition>
2.85 + <condition property="no.javadoc.preview">
2.86 + <and>
2.87 + <isset property="javadoc.preview"/>
2.88 + <isfalse value="${javadoc.preview}"/>
2.89 + </and>
2.90 + </condition>
2.91 + <property name="run.jvmargs" value=""/>
2.92 + <property name="javac.compilerargs" value=""/>
2.93 + <property name="work.dir" value="${basedir}"/>
2.94 + <condition property="no.deps">
2.95 + <and>
2.96 + <istrue value="${no.dependencies}"/>
2.97 + </and>
2.98 + </condition>
2.99 + <property name="javac.debug" value="true"/>
2.100 + <property name="javadoc.preview" value="true"/>
2.101 + <property name="application.args" value=""/>
2.102 + <property name="source.encoding" value="${file.encoding}"/>
2.103 + <condition property="javadoc.encoding.used" value="${javadoc.encoding}">
2.104 + <and>
2.105 + <isset property="javadoc.encoding"/>
2.106 + <not>
2.107 + <equals arg1="${javadoc.encoding}" arg2=""/>
2.108 + </not>
2.109 + </and>
2.110 + </condition>
2.111 + <property name="javadoc.encoding.used" value="${source.encoding}"/>
2.112 + <property name="includes" value="**"/>
2.113 + <property name="excludes" value=""/>
2.114 + <property name="do.depend" value="false"/>
2.115 + <condition property="do.depend.true">
2.116 + <istrue value="${do.depend}"/>
2.117 + </condition>
2.118 + <condition else="" property="javac.compilerargs.jaxws" value="-Djava.endorsed.dirs='${jaxws.endorsed.dir}'">
2.119 + <and>
2.120 + <isset property="jaxws.endorsed.dir"/>
2.121 + <available file="nbproject/jaxws-build.xml"/>
2.122 + </and>
2.123 + </condition>
2.124 + </target>
2.125 + <target name="-post-init">
2.126 + <!-- Empty placeholder for easier customization. -->
2.127 + <!-- You can override this target in the ../build.xml file. -->
2.128 + </target>
2.129 + <target depends="-pre-init,-init-private,-init-user,-init-project,-do-init" name="-init-check">
2.130 + <fail unless="src.dir">Must set src.dir</fail>
2.131 + <fail unless="test.src.dir">Must set test.src.dir</fail>
2.132 + <fail unless="build.dir">Must set build.dir</fail>
2.133 + <fail unless="dist.dir">Must set dist.dir</fail>
2.134 + <fail unless="build.classes.dir">Must set build.classes.dir</fail>
2.135 + <fail unless="dist.javadoc.dir">Must set dist.javadoc.dir</fail>
2.136 + <fail unless="build.test.classes.dir">Must set build.test.classes.dir</fail>
2.137 + <fail unless="build.test.results.dir">Must set build.test.results.dir</fail>
2.138 + <fail unless="build.classes.excludes">Must set build.classes.excludes</fail>
2.139 + <fail unless="dist.jar">Must set dist.jar</fail>
2.140 + </target>
2.141 + <target name="-init-macrodef-property">
2.142 + <macrodef name="property" uri="http://www.netbeans.org/ns/j2se-project/1">
2.143 + <attribute name="name"/>
2.144 + <attribute name="value"/>
2.145 + <sequential>
2.146 + <property name="@{name}" value="${@{value}}"/>
2.147 + </sequential>
2.148 + </macrodef>
2.149 + </target>
2.150 + <target name="-init-macrodef-javac">
2.151 + <macrodef name="javac" uri="http://www.netbeans.org/ns/j2se-project/3">
2.152 + <attribute default="${src.dir}" name="srcdir"/>
2.153 + <attribute default="${build.classes.dir}" name="destdir"/>
2.154 + <attribute default="${javac.classpath}" name="classpath"/>
2.155 + <attribute default="${includes}" name="includes"/>
2.156 + <attribute default="${excludes}" name="excludes"/>
2.157 + <attribute default="${javac.debug}" name="debug"/>
2.158 + <attribute default="" name="sourcepath"/>
2.159 + <element name="customize" optional="true"/>
2.160 + <sequential>
2.161 + <javac debug="@{debug}" deprecation="${javac.deprecation}" destdir="@{destdir}" encoding="${source.encoding}" excludes="@{excludes}" includeantruntime="false" includes="@{includes}" source="${javac.source}" sourcepath="@{sourcepath}" srcdir="@{srcdir}" target="${javac.target}">
2.162 + <classpath>
2.163 + <path path="@{classpath}"/>
2.164 + </classpath>
2.165 + <compilerarg line="${javac.compilerargs} ${javac.compilerargs.jaxws}"/>
2.166 + <customize/>
2.167 + </javac>
2.168 + </sequential>
2.169 + </macrodef>
2.170 + <macrodef name="depend" uri="http://www.netbeans.org/ns/j2se-project/3">
2.171 + <attribute default="${src.dir}" name="srcdir"/>
2.172 + <attribute default="${build.classes.dir}" name="destdir"/>
2.173 + <attribute default="${javac.classpath}" name="classpath"/>
2.174 + <sequential>
2.175 + <depend cache="${build.dir}/depcache" destdir="@{destdir}" excludes="${excludes}" includes="${includes}" srcdir="@{srcdir}">
2.176 + <classpath>
2.177 + <path path="@{classpath}"/>
2.178 + </classpath>
2.179 + </depend>
2.180 + </sequential>
2.181 + </macrodef>
2.182 + <macrodef name="force-recompile" uri="http://www.netbeans.org/ns/j2se-project/3">
2.183 + <attribute default="${build.classes.dir}" name="destdir"/>
2.184 + <sequential>
2.185 + <fail unless="javac.includes">Must set javac.includes</fail>
2.186 + <pathconvert pathsep="," property="javac.includes.binary">
2.187 + <path>
2.188 + <filelist dir="@{destdir}" files="${javac.includes}"/>
2.189 + </path>
2.190 + <globmapper from="*.java" to="*.class"/>
2.191 + </pathconvert>
2.192 + <delete>
2.193 + <files includes="${javac.includes.binary}"/>
2.194 + </delete>
2.195 + </sequential>
2.196 + </macrodef>
2.197 + </target>
2.198 + <target name="-init-macrodef-junit">
2.199 + <macrodef name="junit" uri="http://www.netbeans.org/ns/j2se-project/3">
2.200 + <attribute default="${includes}" name="includes"/>
2.201 + <attribute default="${excludes}" name="excludes"/>
2.202 + <attribute default="**" name="testincludes"/>
2.203 + <sequential>
2.204 + <junit dir="${work.dir}" errorproperty="tests.failed" failureproperty="tests.failed" fork="true" showoutput="true">
2.205 + <batchtest todir="${build.test.results.dir}">
2.206 + <fileset dir="${test.src.dir}" excludes="@{excludes},${excludes}" includes="@{includes}">
2.207 + <filename name="@{testincludes}"/>
2.208 + </fileset>
2.209 + </batchtest>
2.210 + <classpath>
2.211 + <path path="${run.test.classpath}"/>
2.212 + </classpath>
2.213 + <syspropertyset>
2.214 + <propertyref prefix="test-sys-prop."/>
2.215 + <mapper from="test-sys-prop.*" to="*" type="glob"/>
2.216 + </syspropertyset>
2.217 + <formatter type="brief" usefile="false"/>
2.218 + <formatter type="xml"/>
2.219 + <jvmarg line="${run.jvmargs}"/>
2.220 + </junit>
2.221 + </sequential>
2.222 + </macrodef>
2.223 + </target>
2.224 + <target name="-init-macrodef-nbjpda">
2.225 + <macrodef name="nbjpdastart" uri="http://www.netbeans.org/ns/j2se-project/1">
2.226 + <attribute default="${main.class}" name="name"/>
2.227 + <attribute default="${debug.classpath}" name="classpath"/>
2.228 + <attribute default="" name="stopclassname"/>
2.229 + <sequential>
2.230 + <nbjpdastart addressproperty="jpda.address" name="@{name}" stopclassname="@{stopclassname}" transport="dt_socket">
2.231 + <classpath>
2.232 + <path path="@{classpath}"/>
2.233 + </classpath>
2.234 + </nbjpdastart>
2.235 + </sequential>
2.236 + </macrodef>
2.237 + <macrodef name="nbjpdareload" uri="http://www.netbeans.org/ns/j2se-project/1">
2.238 + <attribute default="${build.classes.dir}" name="dir"/>
2.239 + <sequential>
2.240 + <nbjpdareload>
2.241 + <fileset dir="@{dir}" includes="${fix.classes}">
2.242 + <include name="${fix.includes}*.class"/>
2.243 + </fileset>
2.244 + </nbjpdareload>
2.245 + </sequential>
2.246 + </macrodef>
2.247 + </target>
2.248 + <target name="-init-debug-args">
2.249 + <property name="version-output" value="java version "${ant.java.version}"/>
2.250 + <condition property="have-jdk-older-than-1.4">
2.251 + <or>
2.252 + <contains string="${version-output}" substring="java version "1.0"/>
2.253 + <contains string="${version-output}" substring="java version "1.1"/>
2.254 + <contains string="${version-output}" substring="java version "1.2"/>
2.255 + <contains string="${version-output}" substring="java version "1.3"/>
2.256 + </or>
2.257 + </condition>
2.258 + <condition else="-Xdebug" property="debug-args-line" value="-Xdebug -Xnoagent -Djava.compiler=none">
2.259 + <istrue value="${have-jdk-older-than-1.4}"/>
2.260 + </condition>
2.261 + </target>
2.262 + <target depends="-init-debug-args" name="-init-macrodef-debug">
2.263 + <macrodef name="debug" uri="http://www.netbeans.org/ns/j2se-project/3">
2.264 + <attribute default="${main.class}" name="classname"/>
2.265 + <attribute default="${debug.classpath}" name="classpath"/>
2.266 + <element name="customize" optional="true"/>
2.267 + <sequential>
2.268 + <java classname="@{classname}" dir="${work.dir}" fork="true">
2.269 + <jvmarg line="${debug-args-line}"/>
2.270 + <jvmarg value="-Xrunjdwp:transport=dt_socket,address=${jpda.address}"/>
2.271 + <jvmarg line="${run.jvmargs}"/>
2.272 + <classpath>
2.273 + <path path="@{classpath}"/>
2.274 + </classpath>
2.275 + <syspropertyset>
2.276 + <propertyref prefix="run-sys-prop."/>
2.277 + <mapper from="run-sys-prop.*" to="*" type="glob"/>
2.278 + </syspropertyset>
2.279 + <customize/>
2.280 + </java>
2.281 + </sequential>
2.282 + </macrodef>
2.283 + </target>
2.284 + <target name="-init-macrodef-java">
2.285 + <macrodef name="java" uri="http://www.netbeans.org/ns/j2se-project/1">
2.286 + <attribute default="${main.class}" name="classname"/>
2.287 + <element name="customize" optional="true"/>
2.288 + <sequential>
2.289 + <java classname="@{classname}" dir="${work.dir}" fork="true">
2.290 + <jvmarg line="${run.jvmargs}"/>
2.291 + <classpath>
2.292 + <path path="${run.classpath}"/>
2.293 + </classpath>
2.294 + <syspropertyset>
2.295 + <propertyref prefix="run-sys-prop."/>
2.296 + <mapper from="run-sys-prop.*" to="*" type="glob"/>
2.297 + </syspropertyset>
2.298 + <customize/>
2.299 + </java>
2.300 + </sequential>
2.301 + </macrodef>
2.302 + </target>
2.303 + <target name="-init-presetdef-jar">
2.304 + <presetdef name="jar" uri="http://www.netbeans.org/ns/j2se-project/1">
2.305 + <jar compress="${jar.compress}" jarfile="${dist.jar}">
2.306 + <j2seproject1:fileset dir="${build.classes.dir}"/>
2.307 + </jar>
2.308 + </presetdef>
2.309 + </target>
2.310 + <target depends="-pre-init,-init-private,-init-user,-init-project,-do-init,-post-init,-init-check,-init-macrodef-property,-init-macrodef-javac,-init-macrodef-junit,-init-macrodef-nbjpda,-init-macrodef-debug,-init-macrodef-java,-init-presetdef-jar" name="init"/>
2.311 + <!--
2.312 + ===================
2.313 + COMPILATION SECTION
2.314 + ===================
2.315 + -->
2.316 + <target depends="init" name="deps-jar" unless="no.deps"/>
2.317 + <target depends="init,deps-jar" name="-pre-pre-compile">
2.318 + <mkdir dir="${build.classes.dir}"/>
2.319 + </target>
2.320 + <target name="-pre-compile">
2.321 + <!-- Empty placeholder for easier customization. -->
2.322 + <!-- You can override this target in the ../build.xml file. -->
2.323 + </target>
2.324 + <target if="do.depend.true" name="-compile-depend">
2.325 + <j2seproject3:depend/>
2.326 + </target>
2.327 + <target depends="init,deps-jar,-pre-pre-compile,-pre-compile,-compile-depend" if="have.sources" name="-do-compile">
2.328 + <j2seproject3:javac/>
2.329 + <copy todir="${build.classes.dir}">
2.330 + <fileset dir="${src.dir}" excludes="${build.classes.excludes},${excludes}" includes="${includes}"/>
2.331 + </copy>
2.332 + </target>
2.333 + <target name="-post-compile">
2.334 + <!-- Empty placeholder for easier customization. -->
2.335 + <!-- You can override this target in the ../build.xml file. -->
2.336 + </target>
2.337 + <target depends="init,deps-jar,-pre-pre-compile,-pre-compile,-do-compile,-post-compile" description="Compile project." name="compile"/>
2.338 + <target name="-pre-compile-single">
2.339 + <!-- Empty placeholder for easier customization. -->
2.340 + <!-- You can override this target in the ../build.xml file. -->
2.341 + </target>
2.342 + <target depends="init,deps-jar,-pre-pre-compile" name="-do-compile-single">
2.343 + <fail unless="javac.includes">Must select some files in the IDE or set javac.includes</fail>
2.344 + <j2seproject3:force-recompile/>
2.345 + <j2seproject3:javac excludes="" includes="${javac.includes}" sourcepath="${src.dir}"/>
2.346 + </target>
2.347 + <target name="-post-compile-single">
2.348 + <!-- Empty placeholder for easier customization. -->
2.349 + <!-- You can override this target in the ../build.xml file. -->
2.350 + </target>
2.351 + <target depends="init,deps-jar,-pre-pre-compile,-pre-compile-single,-do-compile-single,-post-compile-single" name="compile-single"/>
2.352 + <!--
2.353 + ====================
2.354 + JAR BUILDING SECTION
2.355 + ====================
2.356 + -->
2.357 + <target depends="init" name="-pre-pre-jar">
2.358 + <dirname file="${dist.jar}" property="dist.jar.dir"/>
2.359 + <mkdir dir="${dist.jar.dir}"/>
2.360 + </target>
2.361 + <target name="-pre-jar">
2.362 + <!-- Empty placeholder for easier customization. -->
2.363 + <!-- You can override this target in the ../build.xml file. -->
2.364 + </target>
2.365 + <target depends="init,compile,-pre-pre-jar,-pre-jar" name="-do-jar-without-manifest" unless="manifest.available">
2.366 + <j2seproject1:jar/>
2.367 + </target>
2.368 + <target depends="init,compile,-pre-pre-jar,-pre-jar" if="manifest.available" name="-do-jar-with-manifest" unless="manifest.available+main.class">
2.369 + <j2seproject1:jar manifest="${manifest.file}"/>
2.370 + </target>
2.371 + <target depends="init,compile,-pre-pre-jar,-pre-jar" if="manifest.available+main.class" name="-do-jar-with-mainclass" unless="manifest.available+main.class+mkdist.available">
2.372 + <j2seproject1:jar manifest="${manifest.file}">
2.373 + <j2seproject1:manifest>
2.374 + <j2seproject1:attribute name="Main-Class" value="${main.class}"/>
2.375 + </j2seproject1:manifest>
2.376 + </j2seproject1:jar>
2.377 + <echo>To run this application from the command line without Ant, try:</echo>
2.378 + <property location="${build.classes.dir}" name="build.classes.dir.resolved"/>
2.379 + <property location="${dist.jar}" name="dist.jar.resolved"/>
2.380 + <pathconvert property="run.classpath.with.dist.jar">
2.381 + <path path="${run.classpath}"/>
2.382 + <map from="${build.classes.dir.resolved}" to="${dist.jar.resolved}"/>
2.383 + </pathconvert>
2.384 + <echo>java -cp "${run.classpath.with.dist.jar}" ${main.class}</echo>
2.385 + </target>
2.386 + <target depends="init,compile,-pre-pre-jar,-pre-jar" if="manifest.available+main.class+mkdist.available" name="-do-jar-with-libraries">
2.387 + <property location="${build.classes.dir}" name="build.classes.dir.resolved"/>
2.388 + <pathconvert property="run.classpath.without.build.classes.dir">
2.389 + <path path="${run.classpath}"/>
2.390 + <map from="${build.classes.dir.resolved}" to=""/>
2.391 + </pathconvert>
2.392 + <pathconvert pathsep=" " property="jar.classpath">
2.393 + <path path="${run.classpath.without.build.classes.dir}"/>
2.394 + <chainedmapper>
2.395 + <flattenmapper/>
2.396 + <globmapper from="*" to="lib/*"/>
2.397 + </chainedmapper>
2.398 + </pathconvert>
2.399 + <taskdef classname="org.netbeans.modules.java.j2seproject.copylibstask.CopyLibs" classpath="${libs.CopyLibs.classpath}" name="copylibs"/>
2.400 + <copylibs compress="${jar.compress}" jarfile="${dist.jar}" manifest="${manifest.file}" runtimeclasspath="${run.classpath.without.build.classes.dir}">
2.401 + <fileset dir="${build.classes.dir}"/>
2.402 + <manifest>
2.403 + <attribute name="Main-Class" value="${main.class}"/>
2.404 + <attribute name="Class-Path" value="${jar.classpath}"/>
2.405 + </manifest>
2.406 + </copylibs>
2.407 + <echo>To run this application from the command line without Ant, try:</echo>
2.408 + <property location="${dist.jar}" name="dist.jar.resolved"/>
2.409 + <echo>java -jar "${dist.jar.resolved}"</echo>
2.410 + </target>
2.411 + <target name="-post-jar">
2.412 + <!-- Empty placeholder for easier customization. -->
2.413 + <!-- You can override this target in the ../build.xml file. -->
2.414 + </target>
2.415 + <target depends="init,compile,-pre-jar,-do-jar-with-manifest,-do-jar-without-manifest,-do-jar-with-mainclass,-do-jar-with-libraries,-post-jar" description="Build JAR." name="jar"/>
2.416 + <!--
2.417 + =================
2.418 + EXECUTION SECTION
2.419 + =================
2.420 + -->
2.421 + <target depends="init,compile" description="Run a main class." name="run">
2.422 + <j2seproject1:java>
2.423 + <customize>
2.424 + <arg line="${application.args}"/>
2.425 + </customize>
2.426 + </j2seproject1:java>
2.427 + </target>
2.428 + <target name="-do-not-recompile">
2.429 + <property name="javac.includes.binary" value=""/>
2.430 + </target>
2.431 + <target depends="init,-do-not-recompile,compile-single" name="run-single">
2.432 + <fail unless="run.class">Must select one file in the IDE or set run.class</fail>
2.433 + <j2seproject1:java classname="${run.class}"/>
2.434 + </target>
2.435 + <!--
2.436 + =================
2.437 + DEBUGGING SECTION
2.438 + =================
2.439 + -->
2.440 + <target depends="init" if="netbeans.home" name="-debug-start-debugger">
2.441 + <j2seproject1:nbjpdastart name="${debug.class}"/>
2.442 + </target>
2.443 + <target depends="init,compile" name="-debug-start-debuggee">
2.444 + <j2seproject3:debug>
2.445 + <customize>
2.446 + <arg line="${application.args}"/>
2.447 + </customize>
2.448 + </j2seproject3:debug>
2.449 + </target>
2.450 + <target depends="init,compile,-debug-start-debugger,-debug-start-debuggee" description="Debug project in IDE." if="netbeans.home" name="debug"/>
2.451 + <target depends="init" if="netbeans.home" name="-debug-start-debugger-stepinto">
2.452 + <j2seproject1:nbjpdastart stopclassname="${main.class}"/>
2.453 + </target>
2.454 + <target depends="init,compile,-debug-start-debugger-stepinto,-debug-start-debuggee" if="netbeans.home" name="debug-stepinto"/>
2.455 + <target depends="init,compile-single" if="netbeans.home" name="-debug-start-debuggee-single">
2.456 + <fail unless="debug.class">Must select one file in the IDE or set debug.class</fail>
2.457 + <j2seproject3:debug classname="${debug.class}"/>
2.458 + </target>
2.459 + <target depends="init,-do-not-recompile,compile-single,-debug-start-debugger,-debug-start-debuggee-single" if="netbeans.home" name="debug-single"/>
2.460 + <target depends="init" name="-pre-debug-fix">
2.461 + <fail unless="fix.includes">Must set fix.includes</fail>
2.462 + <property name="javac.includes" value="${fix.includes}.java"/>
2.463 + </target>
2.464 + <target depends="init,-pre-debug-fix,compile-single" if="netbeans.home" name="-do-debug-fix">
2.465 + <j2seproject1:nbjpdareload/>
2.466 + </target>
2.467 + <target depends="init,-pre-debug-fix,-do-debug-fix" if="netbeans.home" name="debug-fix"/>
2.468 + <!--
2.469 + ===============
2.470 + JAVADOC SECTION
2.471 + ===============
2.472 + -->
2.473 + <target depends="init" name="-javadoc-build">
2.474 + <mkdir dir="${dist.javadoc.dir}"/>
2.475 + <javadoc additionalparam="${javadoc.additionalparam}" author="${javadoc.author}" charset="UTF-8" destdir="${dist.javadoc.dir}" docencoding="UTF-8" encoding="${javadoc.encoding.used}" failonerror="true" noindex="${javadoc.noindex}" nonavbar="${javadoc.nonavbar}" notree="${javadoc.notree}" private="${javadoc.private}" source="${javac.source}" splitindex="${javadoc.splitindex}" use="${javadoc.use}" useexternalfile="true" version="${javadoc.version}" windowtitle="${javadoc.windowtitle}">
2.476 + <classpath>
2.477 + <path path="${javac.classpath}"/>
2.478 + </classpath>
2.479 + <fileset dir="${src.dir}" excludes="${excludes}" includes="${includes}">
2.480 + <filename name="**/*.java"/>
2.481 + </fileset>
2.482 + </javadoc>
2.483 + </target>
2.484 + <target depends="init,-javadoc-build" if="netbeans.home" name="-javadoc-browse" unless="no.javadoc.preview">
2.485 + <nbbrowse file="${dist.javadoc.dir}/index.html"/>
2.486 + </target>
2.487 + <target depends="init,-javadoc-build,-javadoc-browse" description="Build Javadoc." name="javadoc"/>
2.488 + <!--
2.489 + =========================
2.490 + JUNIT COMPILATION SECTION
2.491 + =========================
2.492 + -->
2.493 + <target depends="init,compile" if="have.tests" name="-pre-pre-compile-test">
2.494 + <mkdir dir="${build.test.classes.dir}"/>
2.495 + </target>
2.496 + <target name="-pre-compile-test">
2.497 + <!-- Empty placeholder for easier customization. -->
2.498 + <!-- You can override this target in the ../build.xml file. -->
2.499 + </target>
2.500 + <target if="do.depend.true" name="-compile-test-depend">
2.501 + <j2seproject3:depend classpath="${javac.test.classpath}" destdir="${build.test.classes.dir}" srcdir="${test.src.dir}"/>
2.502 + </target>
2.503 + <target depends="init,compile,-pre-pre-compile-test,-pre-compile-test,-compile-test-depend" if="have.tests" name="-do-compile-test">
2.504 + <j2seproject3:javac classpath="${javac.test.classpath}" debug="true" destdir="${build.test.classes.dir}" srcdir="${test.src.dir}"/>
2.505 + <copy todir="${build.test.classes.dir}">
2.506 + <fileset dir="${test.src.dir}" excludes="${build.classes.excludes},${excludes}" includes="${includes}"/>
2.507 + </copy>
2.508 + </target>
2.509 + <target name="-post-compile-test">
2.510 + <!-- Empty placeholder for easier customization. -->
2.511 + <!-- You can override this target in the ../build.xml file. -->
2.512 + </target>
2.513 + <target depends="init,compile,-pre-pre-compile-test,-pre-compile-test,-do-compile-test,-post-compile-test" name="compile-test"/>
2.514 + <target name="-pre-compile-test-single">
2.515 + <!-- Empty placeholder for easier customization. -->
2.516 + <!-- You can override this target in the ../build.xml file. -->
2.517 + </target>
2.518 + <target depends="init,compile,-pre-pre-compile-test,-pre-compile-test-single" if="have.tests" name="-do-compile-test-single">
2.519 + <fail unless="javac.includes">Must select some files in the IDE or set javac.includes</fail>
2.520 + <j2seproject3:force-recompile destdir="${build.test.classes.dir}"/>
2.521 + <j2seproject3:javac classpath="${javac.test.classpath}" debug="true" destdir="${build.test.classes.dir}" excludes="" includes="${javac.includes}" sourcepath="${test.src.dir}" srcdir="${test.src.dir}"/>
2.522 + <copy todir="${build.test.classes.dir}">
2.523 + <fileset dir="${test.src.dir}" excludes="${build.classes.excludes},${excludes}" includes="${includes}"/>
2.524 + </copy>
2.525 + </target>
2.526 + <target name="-post-compile-test-single">
2.527 + <!-- Empty placeholder for easier customization. -->
2.528 + <!-- You can override this target in the ../build.xml file. -->
2.529 + </target>
2.530 + <target depends="init,compile,-pre-pre-compile-test,-pre-compile-test-single,-do-compile-test-single,-post-compile-test-single" name="compile-test-single"/>
2.531 + <!--
2.532 + =======================
2.533 + JUNIT EXECUTION SECTION
2.534 + =======================
2.535 + -->
2.536 + <target depends="init" if="have.tests" name="-pre-test-run">
2.537 + <mkdir dir="${build.test.results.dir}"/>
2.538 + </target>
2.539 + <target depends="init,compile-test,-pre-test-run" if="have.tests" name="-do-test-run">
2.540 + <j2seproject3:junit testincludes="**/*Test.java"/>
2.541 + </target>
2.542 + <target depends="init,compile-test,-pre-test-run,-do-test-run" if="have.tests" name="-post-test-run">
2.543 + <fail if="tests.failed">Some tests failed; see details above.</fail>
2.544 + </target>
2.545 + <target depends="init" if="have.tests" name="test-report"/>
2.546 + <target depends="init" if="netbeans.home+have.tests" name="-test-browse"/>
2.547 + <target depends="init,compile-test,-pre-test-run,-do-test-run,test-report,-post-test-run,-test-browse" description="Run unit tests." name="test"/>
2.548 + <target depends="init" if="have.tests" name="-pre-test-run-single">
2.549 + <mkdir dir="${build.test.results.dir}"/>
2.550 + </target>
2.551 + <target depends="init,compile-test-single,-pre-test-run-single" if="have.tests" name="-do-test-run-single">
2.552 + <fail unless="test.includes">Must select some files in the IDE or set test.includes</fail>
2.553 + <j2seproject3:junit excludes="" includes="${test.includes}"/>
2.554 + </target>
2.555 + <target depends="init,compile-test-single,-pre-test-run-single,-do-test-run-single" if="have.tests" name="-post-test-run-single">
2.556 + <fail if="tests.failed">Some tests failed; see details above.</fail>
2.557 + </target>
2.558 + <target depends="init,-do-not-recompile,compile-test-single,-pre-test-run-single,-do-test-run-single,-post-test-run-single" description="Run single unit test." name="test-single"/>
2.559 + <!--
2.560 + =======================
2.561 + JUNIT DEBUGGING SECTION
2.562 + =======================
2.563 + -->
2.564 + <target depends="init,compile-test" if="have.tests" name="-debug-start-debuggee-test">
2.565 + <fail unless="test.class">Must select one file in the IDE or set test.class</fail>
2.566 + <property location="${build.test.results.dir}/TEST-${test.class}.xml" name="test.report.file"/>
2.567 + <delete file="${test.report.file}"/>
2.568 + <mkdir dir="${build.test.results.dir}"/>
2.569 + <j2seproject3:debug classname="org.apache.tools.ant.taskdefs.optional.junit.JUnitTestRunner" classpath="${ant.home}/lib/ant.jar:${ant.home}/lib/ant-junit.jar:${debug.test.classpath}">
2.570 + <customize>
2.571 + <syspropertyset>
2.572 + <propertyref prefix="test-sys-prop."/>
2.573 + <mapper from="test-sys-prop.*" to="*" type="glob"/>
2.574 + </syspropertyset>
2.575 + <arg value="${test.class}"/>
2.576 + <arg value="showoutput=true"/>
2.577 + <arg value="formatter=org.apache.tools.ant.taskdefs.optional.junit.BriefJUnitResultFormatter"/>
2.578 + <arg value="formatter=org.apache.tools.ant.taskdefs.optional.junit.XMLJUnitResultFormatter,${test.report.file}"/>
2.579 + </customize>
2.580 + </j2seproject3:debug>
2.581 + </target>
2.582 + <target depends="init,compile-test" if="netbeans.home+have.tests" name="-debug-start-debugger-test">
2.583 + <j2seproject1:nbjpdastart classpath="${debug.test.classpath}" name="${test.class}"/>
2.584 + </target>
2.585 + <target depends="init,-do-not-recompile,compile-test-single,-debug-start-debugger-test,-debug-start-debuggee-test" name="debug-test"/>
2.586 + <target depends="init,-pre-debug-fix,compile-test-single" if="netbeans.home" name="-do-debug-fix-test">
2.587 + <j2seproject1:nbjpdareload dir="${build.test.classes.dir}"/>
2.588 + </target>
2.589 + <target depends="init,-pre-debug-fix,-do-debug-fix-test" if="netbeans.home" name="debug-fix-test"/>
2.590 + <!--
2.591 + =========================
2.592 + APPLET EXECUTION SECTION
2.593 + =========================
2.594 + -->
2.595 + <target depends="init,compile-single" name="run-applet">
2.596 + <fail unless="applet.url">Must select one file in the IDE or set applet.url</fail>
2.597 + <j2seproject1:java classname="sun.applet.AppletViewer">
2.598 + <customize>
2.599 + <arg value="${applet.url}"/>
2.600 + </customize>
2.601 + </j2seproject1:java>
2.602 + </target>
2.603 + <!--
2.604 + =========================
2.605 + APPLET DEBUGGING SECTION
2.606 + =========================
2.607 + -->
2.608 + <target depends="init,compile-single" if="netbeans.home" name="-debug-start-debuggee-applet">
2.609 + <fail unless="applet.url">Must select one file in the IDE or set applet.url</fail>
2.610 + <j2seproject3:debug classname="sun.applet.AppletViewer">
2.611 + <customize>
2.612 + <arg value="${applet.url}"/>
2.613 + </customize>
2.614 + </j2seproject3:debug>
2.615 + </target>
2.616 + <target depends="init,compile-single,-debug-start-debugger,-debug-start-debuggee-applet" if="netbeans.home" name="debug-applet"/>
2.617 + <!--
2.618 + ===============
2.619 + CLEANUP SECTION
2.620 + ===============
2.621 + -->
2.622 + <target depends="init" name="deps-clean" unless="no.deps"/>
2.623 + <target depends="init" name="-do-clean">
2.624 + <delete dir="${build.dir}"/>
2.625 + <delete dir="${dist.dir}"/>
2.626 + </target>
2.627 + <target name="-post-clean">
2.628 + <!-- Empty placeholder for easier customization. -->
2.629 + <!-- You can override this target in the ../build.xml file. -->
2.630 + </target>
2.631 + <target depends="init,deps-clean,-do-clean,-post-clean" description="Clean build products." name="clean"/>
2.632 +</project>
3.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
3.2 +++ b/java/ant/nbproject/genfiles.properties Sun Jul 06 00:12:56 2008 +0200
3.3 @@ -0,0 +1,8 @@
3.4 +build.xml.data.CRC32=9a786832
3.5 +build.xml.script.CRC32=5adae2d4
3.6 +build.xml.stylesheet.CRC32=be360661
3.7 +# This file is used by a NetBeans-based IDE to track changes in generated files such as build-impl.xml.
3.8 +# Do not edit this file. You may delete it but then the IDE will never regenerate such files for you.
3.9 +nbproject/build-impl.xml.data.CRC32=9a786832
3.10 +nbproject/build-impl.xml.script.CRC32=2f9f0b6c
3.11 +nbproject/build-impl.xml.stylesheet.CRC32=487672f9
4.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
4.2 +++ b/java/ant/nbproject/project.properties Sun Jul 06 00:12:56 2008 +0200
4.3 @@ -0,0 +1,67 @@
4.4 +application.title=knizecka-ant-tasks
4.5 +application.vendor=Jaroslav Tulach
4.6 +build.classes.dir=${build.dir}/classes
4.7 +build.classes.excludes=**/*.java,**/*.form
4.8 +# This directory is removed when the project is cleaned:
4.9 +build.dir=build
4.10 +build.generated.dir=${build.dir}/generated
4.11 +# Only compile against the classpath explicitly listed here:
4.12 +build.sysclasspath=ignore
4.13 +build.test.classes.dir=${build.dir}/test/classes
4.14 +build.test.results.dir=${build.dir}/test/results
4.15 +debug.classpath=\
4.16 + ${run.classpath}
4.17 +debug.test.classpath=\
4.18 + ${run.test.classpath}
4.19 +# This directory is removed when the project is cleaned:
4.20 +dist.dir=dist
4.21 +dist.jar=${dist.dir}/${application.title}.jar
4.22 +dist.javadoc.dir=${dist.dir}/javadoc
4.23 +excludes=
4.24 +file.reference.ant.jar=${ant.home}/lib/ant.jar:${ant.home}/lib/ant-junit.jar:${ant.home}/lib/ant-launcher.jar
4.25 +file.reference.libs=../../samples/libs/dist
4.26 +file.reference.junit-4.4.jar=${file.reference.libs}/junit-4.4.jar
4.27 +file.reference.org-netbeans-insane.jar=${file.reference.libs}/org-netbeans-insane.jar
4.28 +file.reference.org-netbeans-modules-nbjunit.jar=${file.reference.libs}/org-netbeans-modules-nbjunit.jar
4.29 +includes=**
4.30 +jar.compress=false
4.31 +javac.classpath=\
4.32 + ${file.reference.ant.jar}:\
4.33 + ${java.class.path}:\
4.34 +# Space-separated list of extra javac options
4.35 +javac.compilerargs=
4.36 +javac.deprecation=false
4.37 +javac.source=1.5
4.38 +javac.target=1.5
4.39 +javac.test.classpath=\
4.40 + ${javac.classpath}:\
4.41 + ${build.classes.dir}:\
4.42 + ${file.reference.junit-4.4.jar}:\
4.43 + ${file.reference.org-netbeans-insane.jar}:\
4.44 + ${file.reference.org-netbeans-modules-nbjunit.jar}
4.45 +javadoc.additionalparam=
4.46 +javadoc.author=false
4.47 +javadoc.encoding=${source.encoding}
4.48 +javadoc.noindex=false
4.49 +javadoc.nonavbar=false
4.50 +javadoc.notree=false
4.51 +javadoc.private=false
4.52 +javadoc.splitindex=true
4.53 +javadoc.use=true
4.54 +javadoc.version=false
4.55 +javadoc.windowtitle=
4.56 +meta.inf.dir=${src.dir}/META-INF
4.57 +platform.active=default_platform
4.58 +run.classpath=\
4.59 + ${javac.classpath}:\
4.60 + ${build.classes.dir}
4.61 +# Space-separated list of JVM arguments used when running the project
4.62 +# (you may also define separate properties like run-sys-prop.name=value instead of -Dname=value
4.63 +# or test-sys-prop.name=value to set system properties for unit tests):
4.64 +run.jvmargs=
4.65 +run.test.classpath=\
4.66 + ${javac.test.classpath}:\
4.67 + ${build.test.classes.dir}
4.68 +source.encoding=UTF-8
4.69 +src.dir=src
4.70 +test.src.dir=test
5.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
5.2 +++ b/java/ant/nbproject/project.xml Sun Jul 06 00:12:56 2008 +0200
5.3 @@ -0,0 +1,16 @@
5.4 +<?xml version="1.0" encoding="UTF-8"?>
5.5 +<project xmlns="http://www.netbeans.org/ns/project/1">
5.6 + <type>org.netbeans.modules.java.j2seproject</type>
5.7 + <configuration>
5.8 + <data xmlns="http://www.netbeans.org/ns/j2se-project/3">
5.9 + <name>ant</name>
5.10 + <minimum-ant-version>1.6.5</minimum-ant-version>
5.11 + <source-roots>
5.12 + <root id="src.dir"/>
5.13 + </source-roots>
5.14 + <test-roots>
5.15 + <root id="test.src.dir"/>
5.16 + </test-roots>
5.17 + </data>
5.18 + </configuration>
5.19 +</project>
6.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
6.2 +++ b/java/ant/src/org/apidesign/infra/ant/GrepCopy.java Sun Jul 06 00:12:56 2008 +0200
6.3 @@ -0,0 +1,51 @@
6.4 +package org.apidesign.infra.ant;
6.5 +
6.6 +import java.io.File;
6.7 +import java.io.FileWriter;
6.8 +import java.io.IOException;
6.9 +import java.util.Map;
6.10 +import java.util.Map.Entry;
6.11 +import org.apache.tools.ant.BuildException;
6.12 +import org.apache.tools.ant.Task;
6.13 +import org.apache.tools.ant.types.FileSet;
6.14 +import org.apache.tools.ant.types.FilterSet;
6.15 +import org.apache.tools.ant.util.FileUtils;
6.16 +import org.openide.util.Exceptions;
6.17 +
6.18 +public class GrepCopy extends Task {
6.19 + private GrepFilter filter = new GrepFilter();
6.20 + private File dir;
6.21 +
6.22 + public GrepCopy() {
6.23 + }
6.24 +
6.25 + public FileSet createFileSet() {
6.26 + return filter.createFileSet();
6.27 + }
6.28 +
6.29 + public void setTarget(File dir) {
6.30 + this.dir = dir;
6.31 + }
6.32 +
6.33 + @Override
6.34 + public void execute() throws BuildException {
6.35 + filter.setProject(getProject());
6.36 +
6.37 + FilterSet set = filter.createFilterSet();
6.38 +
6.39 + for (Object object : set.getFilterHash().entrySet()) {
6.40 +
6.41 + FileWriter w = null;
6.42 + try {
6.43 + Entry en = (Entry) object;
6.44 + File to = new File(dir, (String) en.getKey());
6.45 + to.getParentFile().mkdirs();
6.46 + w = new FileWriter(to);
6.47 + w.write((String) en.getValue());
6.48 + w.close();
6.49 + } catch (IOException ex) {
6.50 + throw new BuildException(ex);
6.51 + }
6.52 + }
6.53 + }
6.54 +}
7.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
7.2 +++ b/java/ant/src/org/apidesign/infra/ant/GrepFilter.java Sun Jul 06 00:12:56 2008 +0200
7.3 @@ -0,0 +1,247 @@
7.4 +package org.apidesign.infra.ant;
7.5 +
7.6 +import java.io.BufferedReader;
7.7 +import java.io.File;
7.8 +import java.io.FileReader;
7.9 +import java.io.IOException;
7.10 +import java.util.HashMap;
7.11 +import java.util.Map;
7.12 +import java.util.Stack;
7.13 +import java.util.regex.Matcher;
7.14 +import java.util.regex.Pattern;
7.15 +import org.apache.tools.ant.BuildException;
7.16 +import org.apache.tools.ant.DirectoryScanner;
7.17 +import org.apache.tools.ant.Task;
7.18 +import org.apache.tools.ant.types.FileSet;
7.19 +import org.apache.tools.ant.types.FilterSet;
7.20 +
7.21 +/**
7.22 + *
7.23 + * @author Jaroslav Tulach
7.24 + */
7.25 +public final class GrepFilter extends Task {
7.26 + private int len = 80;
7.27 + private String id;
7.28 + private FileSet fs;
7.29 + private Pattern begin = Pattern.compile(".* BEGIN: *(\\p{Graph}+)[-\\> ]*");
7.30 + private Pattern end = Pattern.compile(".* (END|FINISH): *(\\p{Graph}+)[-\\> ]*");
7.31 + private boolean openoffice;
7.32 +
7.33 +
7.34 + public FileSet createFileSet() {
7.35 + if (fs != null) {
7.36 + throw new BuildException();
7.37 + }
7.38 + this.fs = new FileSet();
7.39 + return fs;
7.40 + }
7.41 +
7.42 + public void setId(String id) {
7.43 + this.id = id;
7.44 + }
7.45 +
7.46 + public void setMaxLineLength(int len) {
7.47 + this.len = len;
7.48 + }
7.49 +
7.50 + public void setOutputFormat(String f) {
7.51 + if (f.equals("opendocument")) {
7.52 + openoffice = true;
7.53 + return;
7.54 + }
7.55 + throw new BuildException("Wrong format: " + f);
7.56 + }
7.57 +
7.58 + final FilterSet createFilterSet() {
7.59 + if (fs == null) {
7.60 + throw new BuildException();
7.61 + }
7.62 +
7.63 + FilterSet filter = new FilterSet();
7.64 +
7.65 + try {
7.66 + DirectoryScanner ds = fs.getDirectoryScanner(getProject());
7.67 + Map<String,CharSequence> texts = new HashMap<String, CharSequence>();
7.68 + for (String path : ds.getIncludedFiles()) {
7.69 + File file = new File(ds.getBasedir(), path);
7.70 + BufferedReader r = new BufferedReader(new FileReader(file));
7.71 + for (;;) {
7.72 + String line = r.readLine();
7.73 + if (line == null) {
7.74 + break;
7.75 + }
7.76 + {
7.77 + Matcher m = begin.matcher(line);
7.78 + if (m.matches()) {
7.79 + Item sb = new Item(file);
7.80 + CharSequence prev = texts.put(m.group(1), sb);
7.81 + if (prev != null) {
7.82 + throw new BuildException("Same pattern is there twice: " + m.group(1) + " in " + file);
7.83 + }
7.84 + continue;
7.85 + }
7.86 + }
7.87 + {
7.88 + Matcher m = end.matcher(line);
7.89 + if (m.matches()) {
7.90 + CharSequence s = texts.get(m.group(2));
7.91 + if (s instanceof Item) {
7.92 + texts.put(m.group(2), ((Item)s).toString(m.group(1).equals("FINISH")));
7.93 + continue;
7.94 + }
7.95 +
7.96 + if (s == null) {
7.97 + throw new BuildException("Closing unknown section: " + m.group(2) + " in " + file);
7.98 + }
7.99 + throw new BuildException("Closing not opened section: " + m.group(2) + " in " + file);
7.100 + }
7.101 + }
7.102 +
7.103 + for (CharSequence charSequence : texts.values()) {
7.104 + if (charSequence instanceof Item) {
7.105 + Item sb = (Item)charSequence;
7.106 + sb.append(line);
7.107 + }
7.108 + }
7.109 + }
7.110 +
7.111 + for (Map.Entry<String, CharSequence> entry : texts.entrySet()) {
7.112 + CharSequence v = entry.getValue();
7.113 + if (v instanceof Item) {
7.114 + throw new BuildException("Not closed section " + entry.getKey() + " in " + file);
7.115 + }
7.116 + entry.setValue(v.toString());
7.117 + }
7.118 + }
7.119 +
7.120 + for (Map.Entry<String, CharSequence> entry : texts.entrySet()) {
7.121 + String text = entry.getValue().toString();
7.122 + String out = linize(text);
7.123 + filter.addFilter(entry.getKey(), out); // NOI18N
7.124 + }
7.125 + } catch (IOException ex) {
7.126 + throw new BuildException(ex);
7.127 + }
7.128 + if (!filter.hasFilters()) {
7.129 + throw new BuildException("No filter found!");
7.130 + }
7.131 + return filter;
7.132 + }
7.133 +
7.134 + @Override
7.135 + public void execute() throws BuildException {
7.136 + if (id == null) {
7.137 + throw new BuildException();
7.138 + }
7.139 + FilterSet filter = createFilterSet();
7.140 + getProject().addReference(id, filter);
7.141 + }
7.142 +
7.143 + private String linize(String input) {
7.144 + if (!openoffice) {
7.145 + return input;
7.146 + }
7.147 +
7.148 + StringBuilder copy = new StringBuilder();
7.149 + for (String l : input.split("\n")) {
7.150 + int spaces = 0;
7.151 + while (spaces < l.length() && l.charAt(spaces) == ' ') {
7.152 + spaces++;
7.153 + }
7.154 + copy.append("<text:p text:style-name='Code'><text:s text:c='" + spaces + "'/>" + l.substring(spaces) + "</text:p>\n");
7.155 + }
7.156 +
7.157 + return copy.toString();
7.158 + }
7.159 +
7.160 + static final int countChar(CharSequence seq, char ch) {
7.161 + int cnt = 0;
7.162 + for (int i = 0; i < seq.length(); i++) {
7.163 + if (ch == seq.charAt(i)) {
7.164 + cnt++;
7.165 + }
7.166 + }
7.167 + return cnt;
7.168 + }
7.169 +
7.170 + private final class Item implements CharSequence {
7.171 + private StringBuilder sb = new StringBuilder();
7.172 + private int spaces = Integer.MAX_VALUE;
7.173 + private Stack<Integer> remove = new Stack<Integer>();
7.174 + private final File file;
7.175 +
7.176 + public Item(File file) {
7.177 + this.file = file;
7.178 + }
7.179 +
7.180 + public int length() {
7.181 + return sb.length();
7.182 + }
7.183 +
7.184 + public char charAt(int index) {
7.185 + return sb.charAt(index);
7.186 + }
7.187 +
7.188 + public CharSequence subSequence(int start, int end) {
7.189 + return sb.subSequence(start, end);
7.190 + }
7.191 +
7.192 + private void append(String line) {
7.193 + for (int sp = 0; sp < line.length(); sp++) {
7.194 + if (line.charAt(sp) != ' ') {
7.195 + if (sp < spaces) {
7.196 + spaces = sp;
7.197 + break;
7.198 + }
7.199 + }
7.200 + }
7.201 + remove.push(sb.length());
7.202 + sb.append(line);
7.203 + sb.append('\n');
7.204 + }
7.205 +
7.206 + @Override
7.207 + public String toString() {
7.208 + return toString(false);
7.209 + }
7.210 + public String toString(boolean finish) {
7.211 + if (remove != null) {
7.212 + while (!remove.isEmpty()) {
7.213 + Integer pos = remove.pop();
7.214 + for (int i = 0; i < spaces; i++) {
7.215 + if (sb.charAt(pos) == '\n') {
7.216 + break;
7.217 + }
7.218 + sb.deleteCharAt(pos);
7.219 + }
7.220 + }
7.221 + remove = null;
7.222 +
7.223 + int line = 0;
7.224 + for (int i = 0; i < sb.length(); i++) {
7.225 + if (sb.charAt(i) == '\n') {
7.226 + line = 0;
7.227 + continue;
7.228 + }
7.229 + if (++line > len) {
7.230 + throw new BuildException("Line is too long in: " + file + "\n" + sb);
7.231 + }
7.232 + }
7.233 +
7.234 + int open = countChar(sb, '{');
7.235 + int end = countChar(sb, '}');
7.236 + if (finish) {
7.237 + for (int i = 0; i < open - end; i++) {
7.238 + sb.append("}\n");
7.239 + }
7.240 + }
7.241 +
7.242 + if (countChar(sb, '{') != countChar(sb, '}')) {
7.243 + throw new BuildException("not paired amount of braces in " + file + "\n" + sb);
7.244 + }
7.245 +
7.246 + }
7.247 + return sb.toString();
7.248 + }
7.249 + } // end of Item
7.250 +}
8.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
8.2 +++ b/java/ant/test/org/apidesign/infra/ant/ColorifyTest.java Sun Jul 06 00:12:56 2008 +0200
8.3 @@ -0,0 +1,680 @@
8.4 +/*
8.5 + * Copyright 2007 Sun Microsystems, Inc. All Rights Reserved.
8.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
8.7 + *
8.8 + * This code is free software; you can redistribute it and/or modify it
8.9 + * under the terms of the GNU General Public License version 2 only, as
8.10 + * published by the Free Software Foundation. Sun designates this
8.11 + * particular file as subject to the "Classpath" exception as provided
8.12 + * by Sun in the LICENSE file that accompanied this code.
8.13 + *
8.14 + * This code is distributed in the hope that it will be useful, but WITHOUT
8.15 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
8.16 + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
8.17 + * version 2 for more details (a copy is included in the LICENSE file that
8.18 + * accompanied this code).
8.19 + *
8.20 + * You should have received a copy of the GNU General Public License version
8.21 + * 2 along with this work; if not, write to the Free Software Foundation,
8.22 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
8.23 + *
8.24 + * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
8.25 + * CA 95054 USA or visit www.sun.com if you need additional information or
8.26 + * have any questions.
8.27 + */
8.28 +package org.apidesign.infra.ant;
8.29 +
8.30 +import java.io.ByteArrayInputStream;
8.31 +import java.io.File;
8.32 +import java.io.FileOutputStream;
8.33 +import java.io.FileWriter;
8.34 +import java.io.InputStream;
8.35 +import java.net.URL;
8.36 +import java.util.ArrayList;
8.37 +import java.util.Arrays;
8.38 +import java.util.List;
8.39 +import junit.framework.Test;
8.40 +import org.netbeans.junit.NbTestCase;
8.41 +import org.netbeans.junit.NbTestSuite;
8.42 +
8.43 +/**
8.44 + *
8.45 + * @author Jaroslav Tulach
8.46 + */
8.47 +public class ColorifyTest extends NbTestCase {
8.48 + private static File workDir;
8.49 +
8.50 + public ColorifyTest(String s) {
8.51 + super(s);
8.52 + }
8.53 +
8.54 + public static Test suite() {
8.55 + return new NbTestSuite(ColorifyTest.class);
8.56 +// return new ColorifyTest("testInXMLWithMultilineString");
8.57 + }
8.58 +
8.59 + @Override
8.60 + protected void setUp() throws Exception {
8.61 + clearWorkDir();
8.62 + }
8.63 +
8.64 + public void testMissingMethodInAnInterfaceIsDetected() throws Exception {
8.65 + String c1 =
8.66 + "package ahoj;\n" +
8.67 + "// BEGIN: xyz\n" +
8.68 + "public interface I {\n" +
8.69 + "// FINISH: xyz\n" +
8.70 + " public void get();\n" +
8.71 + "}" +
8.72 + "";
8.73 + File src = createFile(1, "I.java", c1);
8.74 +
8.75 +
8.76 + String c2 =
8.77 + "@xyz@";
8.78 + File txt = createFile(2, "in.txt", c2);
8.79 +
8.80 + File out = createFile(3, "out.txt", "");
8.81 + out.delete();
8.82 +
8.83 + execute(1, 2, "-Dfile1=" + txt, "-Dfile2=" + out, "-Dinclude1=*.java");
8.84 +
8.85 + assertTrue("output created", out.canRead());
8.86 +
8.87 + String r = readFile(out);
8.88 + assertEquals("public interface I {\n}\n", r);
8.89 + }
8.90 +
8.91 + public void testTryFinally() throws Exception {
8.92 + String c1 =
8.93 + "package ahoj;\n" +
8.94 + "// BEGIN: xyz\n" +
8.95 + " try {\n" +
8.96 + " // something\n" +
8.97 + " } finally {\n" +
8.98 + " // else\n" +
8.99 + " }\n" +
8.100 + "// END: xyz\n" +
8.101 + " public void get();\n" +
8.102 + "}" +
8.103 + "";
8.104 + File src = createFile(1, "I.java", c1);
8.105 +
8.106 +
8.107 + String c2 =
8.108 + "@xyz@";
8.109 + File txt = createFile(2, "in.txt", c2);
8.110 +
8.111 + File out = createFile(3, "out.txt", "");
8.112 + out.delete();
8.113 +
8.114 + execute(1, 2, "-Dfile1=" + txt, "-Dfile2=" + out, "-Dinclude1=*.java");
8.115 +
8.116 + assertTrue("output created", out.canRead());
8.117 +
8.118 + String r = readFile(out);
8.119 + String exp =
8.120 + "try {\n" +
8.121 + " // something\n" +
8.122 + "} finally {\n" +
8.123 + " // else\n" +
8.124 + "}\n";
8.125 + assertEquals(exp, r);
8.126 + }
8.127 +
8.128 + public void testString() throws Exception {
8.129 + String c1 =
8.130 + "package ahoj;\n" +
8.131 + "public interface I {\n" +
8.132 + "// BEGIN: xyz\n" +
8.133 + " public static final String X = \"ahoj\"\n" +
8.134 + "// END: xyz\n" +
8.135 + "}" +
8.136 + "";
8.137 + File src = createFile(1, "I.java", c1);
8.138 +
8.139 +
8.140 + String c2 =
8.141 + "@xyz@";
8.142 + File txt = createFile(2, "in.txt", c2);
8.143 +
8.144 + File out = createFile(3, "out.txt", "");
8.145 + out.delete();
8.146 +
8.147 + execute(1, 2, "-Dfile1=" + txt, "-Dfile2=" + out, "-Dinclude1=*.java");
8.148 +
8.149 + assertTrue("output created", out.canRead());
8.150 +
8.151 + String r = readFile(out);
8.152 + assertEquals("public static final String X = \"ahoj\"\n", r);
8.153 + }
8.154 +
8.155 + public void testSpacesAtBeginingAreStripped() throws Exception {
8.156 + String c1 =
8.157 + "package ahoj;\n" +
8.158 + "// BEGIN: xyz\n" +
8.159 + " public interface I {\n" +
8.160 + " public void ahoj ();\n" +
8.161 + " }\n" +
8.162 + "// END: xyz\n" +
8.163 + " public void get();\n" +
8.164 + "}" +
8.165 + "";
8.166 + File src = createFile(1, "I.java", c1);
8.167 +
8.168 +
8.169 + String c2 =
8.170 + "@xyz@";
8.171 + File txt = createFile(2, "in.txt", c2);
8.172 +
8.173 + File out = createFile(3, "out.txt", "");
8.174 + out.delete();
8.175 +
8.176 + execute(1, 2, "-Dfile1=" + txt, "-Dfile2=" + out, "-Dinclude1=*.java");
8.177 +
8.178 + assertTrue("output created", out.canRead());
8.179 +
8.180 + String r = readFile(out);
8.181 + String result = "public interface I {\n" +
8.182 + " public void ahoj ();\n" +
8.183 + "}\n";
8.184 + assertEquals(result, r);
8.185 + }
8.186 +
8.187 + public void testIncludedTexts() throws Exception {
8.188 + String c1 =
8.189 + "package ahoj;\n" +
8.190 + "// BEGIN: clazz\n" +
8.191 + "public interface I {\n" +
8.192 + " // BEGIN: method\n" +
8.193 + " public void get();\n" +
8.194 + " // END: method\n" +
8.195 + "}\n" +
8.196 + "// END: clazz\n" +
8.197 + "";
8.198 + File src = createFile(1, "I.java", c1);
8.199 +
8.200 +
8.201 + String c2 =
8.202 + "@clazz@";
8.203 + File txt = createFile(2, "in.txt", c2);
8.204 +
8.205 + File out = createFile(3, "out.txt", "");
8.206 + out.delete();
8.207 +
8.208 + execute(1, 2, "-Dfile1=" + txt, "-Dfile2=" + out, "-Dinclude1=*.java");
8.209 +
8.210 + assertTrue("output created", out.canRead());
8.211 +
8.212 + String r = readFile(out);
8.213 + if (r.indexOf("BEGIN") >= 0) {
8.214 + fail("BEGIN is there: " + r);
8.215 + }
8.216 + if (r.indexOf("END") >= 0) {
8.217 + fail("END is there: " + r);
8.218 + }
8.219 + if (r.indexOf("interface I") < 0) {
8.220 + fail("Missing interface: " + r);
8.221 + }
8.222 + if (r.indexOf("void get()") < 0) {
8.223 + fail("Missing get: " + r);
8.224 + }
8.225 + }
8.226 + public void testWithCommentsTexts() throws Exception {
8.227 + String c1 =
8.228 + "package ahoj;\n" +
8.229 + "// BEGIN: clazz\n" +
8.230 + "/** Beautiful interface I\n" +
8.231 + " */\n" +
8.232 + "public interface I {\n" +
8.233 + " // single line\n" +
8.234 + "}\n" +
8.235 + "// END: clazz\n" +
8.236 + "";
8.237 + File src = createFile(1, "I.java", c1);
8.238 +
8.239 +
8.240 + String c2 =
8.241 + "@clazz@";
8.242 + File txt = createFile(2, "in.txt", c2);
8.243 +
8.244 + File out = createFile(3, "out.txt", "");
8.245 + out.delete();
8.246 +
8.247 + execute(1, 2, "-Dfile1=" + txt, "-Dfile2=" + out, "-Dinclude1=*.java");
8.248 +
8.249 + assertTrue("output created", out.canRead());
8.250 +
8.251 + String r = readFile(out);
8.252 + if (r.indexOf("BEGIN") >= 0) {
8.253 + fail("BEGIN is there: " + r);
8.254 + }
8.255 + if (r.indexOf("END") >= 0) {
8.256 + fail("END is there: " + r);
8.257 + }
8.258 + if (r.indexOf("interface I") < 0) {
8.259 + fail("Missing interface: " + r);
8.260 + }
8.261 + if (r.indexOf("// single line\n}") < 0) {
8.262 + fail("Comment indentified: " + r);
8.263 + }
8.264 + }
8.265 + public void testMultiLineComment() throws Exception {
8.266 + String c1 =
8.267 + "package ahoj;\n" +
8.268 + "// BEGIN: clazz\n" +
8.269 + "public void x() {\n" +
8.270 + " /** Beautiful interface I\n" +
8.271 + " *\n" +
8.272 + " */\n" +
8.273 + "}\n" +
8.274 + "// END: clazz\n" +
8.275 + "";
8.276 + File src = createFile(1, "I.java", c1);
8.277 +
8.278 +
8.279 + String c2 =
8.280 + "@clazz@";
8.281 + File txt = createFile(2, "in.txt", c2);
8.282 +
8.283 + File out = createFile(3, "out.txt", "");
8.284 + out.delete();
8.285 +
8.286 + execute(1, 2, "-Dfile1=" + txt, "-Dfile2=" + out, "-Dinclude1=*.java");
8.287 +
8.288 + assertTrue("output created", out.canRead());
8.289 +
8.290 + String r = readFile(out);
8.291 + int f = r.indexOf(
8.292 + "/** Beautiful interface I\n" +
8.293 + " *\n" +
8.294 + " */\n");
8.295 + if (f == -1) {
8.296 + fail("Not found: " + r);
8.297 + }
8.298 + }
8.299 + public void testIncludedTextsAmper() throws Exception {
8.300 + String c1 =
8.301 + "package ahoj;\n" +
8.302 + "public class C {\n" +
8.303 + " // BEGIN: method\n" +
8.304 + " public void change(int x) { x &= 10; }\n" +
8.305 + " // END: method\n" +
8.306 + "}\n" +
8.307 + "";
8.308 + File src = createFile(1, "C.java", c1);
8.309 +
8.310 +
8.311 + String c2 =
8.312 + "@method@";
8.313 + File txt = createFile(2, "in.txt", c2);
8.314 +
8.315 + File out = createFile(3, "out.txt", "");
8.316 + out.delete();
8.317 +
8.318 + execute(1, 2, "-Dfile1=" + txt, "-Dfile2=" + out, "-Dinclude1=*.java");
8.319 +
8.320 + assertTrue("output created", out.canRead());
8.321 +
8.322 + String r = readFile(out);
8.323 + if (r.indexOf("&=") < 0) {
8.324 + fail("No XML escapes please: " + r);
8.325 + }
8.326 + if (r.indexOf("&=") >= 0) {
8.327 + fail("we need no xml escapes, no &: " + r);
8.328 + }
8.329 + }
8.330 + public void testIncludedTextsAmperAndGenerics() throws Exception {
8.331 + String c1 =
8.332 +
8.333 +"package org.apidesign.api.security;\n" +
8.334 +"" +
8.335 +"import java.nio.ByteBuffer;\n" +
8.336 +"import java.util.ServiceLoader;\n" +
8.337 +"import org.apidesign.spi.security.Digestor;\n" +
8.338 +"\n" +
8.339 +"/** Simplified version of a Digest class that allows to compute a fingerprint\n" +
8.340 +" * for buffer of data.\n" +
8.341 +" *\n" +
8.342 +" * @author Jaroslav Tulach <jaroslav.tulach@apidesign.org>\n" +
8.343 +" */\n" +
8.344 +"// BEGIN: day.end.bridges.Digest\n" +
8.345 +"public final class Digest {\n" +
8.346 +" private final DigestImplementation<?> impl;\n" +
8.347 +" \n" +
8.348 +" /** Factory method is better than constructor */\n" +
8.349 +" private Digest(DigestImplementation<?> impl) {\n" +
8.350 +" this.impl = impl;\n" +
8.351 +" }\n" +
8.352 +" \n" +
8.353 +" /** Factory method to create digest for an algorithm.\n" +
8.354 +" */\n" +
8.355 +" public static Digest getInstance(String algorithm) {\n" +
8.356 +" for (Digestor<?> digestor : ServiceLoader.load(Digestor.class)) {\n" +
8.357 +" DigestImplementation<?> impl = \n" +
8.358 + "DigestImplementation.create(digestor, algorithm);\n" +
8.359 +" if (impl != null) {\n" +
8.360 +" return new Digest(impl);\n" +
8.361 +" }\n" +
8.362 +" }\n" +
8.363 +" throw new IllegalArgumentException(algorithm);\n" +
8.364 +" }\n" +
8.365 +" \n" +
8.366 +" //\n" +
8.367 +" // these methods are kept the same as in original MessageDigest,\n" +
8.368 +" // but for simplicity choose just some from the original API\n" +
8.369 +" //\n" +
8.370 +" \n" +
8.371 +" public byte[] digest(ByteBuffer bb) {\n" +
8.372 +" return impl.digest(bb);\n" +
8.373 +" }\n" +
8.374 +"}\n" +
8.375 +"// END: day.end.bridges.Digest\n";
8.376 +
8.377 + File src = createFile(1, "C.java", c1);
8.378 +
8.379 +
8.380 + String c2 =
8.381 + "@day.end.bridges.Digest@";
8.382 + File txt = createFile(2, "in.txt", c2);
8.383 +
8.384 + File out = createFile(3, "out.txt", "");
8.385 + out.delete();
8.386 +
8.387 + execute(1, 2, "-Dfile1=" + txt, "-Dfile2=" + out, "-Dinclude1=*.java");
8.388 +
8.389 + assertTrue("output created", out.canRead());
8.390 +
8.391 + String r = readFile(out);
8.392 + if (r.indexOf("&=") >= 0) {
8.393 + fail("Wrong XML: " + r);
8.394 + }
8.395 + if (r.indexOf("&") > -1) {
8.396 + fail("Wrong XML, no &: " + r);
8.397 + }
8.398 + }
8.399 +
8.400 + public void testInXML() throws Exception {
8.401 + String c1 =
8.402 + "<!-- BEGIN: clazz -->\n" +
8.403 + "<interface name='I'/>\n" +
8.404 + "<!-- END: clazz -->\n" +
8.405 + "";
8.406 + File src = createFile(1, "I.xml", c1);
8.407 +
8.408 +
8.409 + String c2 =
8.410 + "@clazz@";
8.411 + File txt = createFile(2, "in.txt", c2);
8.412 +
8.413 + File out = createFile(3, "out.txt", "");
8.414 + out.delete();
8.415 +
8.416 + execute(1, 2, "-Dfile1=" + txt, "-Dfile2=" + out, "-Dinclude1=*.xml");
8.417 +
8.418 + assertTrue("output created", out.canRead());
8.419 +
8.420 + String r = readFile(out);
8.421 + if (r.indexOf("BEGIN") >= 0) {
8.422 + fail("BEGIN is there: " + r);
8.423 + }
8.424 + if (r.indexOf("END") >= 0) {
8.425 + fail("END is there: " + r);
8.426 + }
8.427 + assertEquals("<interface name='I'/>\n", r);
8.428 + }
8.429 + public void testInXMLWithComment() throws Exception {
8.430 + String c1 =
8.431 + "<!-- BEGIN: clazz -->\n" +
8.432 + "<!--\n" +
8.433 + " ahoj -->\n" +
8.434 + "<!-- END: clazz -->\n" +
8.435 + "";
8.436 + File src = createFile(1, "I.xml", c1);
8.437 +
8.438 +
8.439 + String c2 =
8.440 + "@clazz@";
8.441 + File txt = createFile(2, "in.txt", c2);
8.442 +
8.443 + File out = createFile(3, "out.txt", "");
8.444 + out.delete();
8.445 +
8.446 + execute(1, 2, "-Dfile1=" + txt, "-Dfile2=" + out, "-Dinclude1=*.xml");
8.447 +
8.448 + assertTrue("output created", out.canRead());
8.449 +
8.450 + String r = readFile(out);
8.451 + if (r.indexOf("BEGIN") >= 0) {
8.452 + fail("BEGIN is there: " + r);
8.453 + }
8.454 + if (r.indexOf("END") >= 0) {
8.455 + fail("END is there: " + r);
8.456 + }
8.457 + assertEquals("No xml please", "<!--\n ahoj -->\n", r);
8.458 + }
8.459 +
8.460 + public void testInXMLWithMultilineString() throws Exception {
8.461 + String c1 =
8.462 + "<!-- BEGIN: clazz -->\n" +
8.463 + "<element tag='\n" +
8.464 + " ahoj'\n" +
8.465 + "/>\n" +
8.466 + "<!-- END: clazz -->\n" +
8.467 + "";
8.468 + File src = createFile(1, "I.xml", c1);
8.469 +
8.470 +
8.471 + String c2 =
8.472 + "@clazz@";
8.473 + File txt = createFile(2, "in.txt", c2);
8.474 +
8.475 + File out = createFile(3, "out.txt", "");
8.476 + out.delete();
8.477 +
8.478 + execute(1, 2, "-Dfile1=" + txt, "-Dfile2=" + out, "-Dinclude1=*.xml");
8.479 +
8.480 + assertTrue("output created", out.canRead());
8.481 +
8.482 + String r = readFile(out);
8.483 + if (r.indexOf("BEGIN") >= 0) {
8.484 + fail("BEGIN is there: " + r);
8.485 + }
8.486 + if (r.indexOf("END") >= 0) {
8.487 + fail("END is there: " + r);
8.488 + }
8.489 + assertEquals("I want no XML escapes", "<element tag='\n ahoj'\n/>\n", r);
8.490 + }
8.491 +
8.492 + public void testLongLineDetected() throws Exception {
8.493 + String c1 =
8.494 +"package org.apidesign.api.security;\n" +
8.495 +"" +
8.496 +"import java.nio.ByteBuffer;\n" +
8.497 +"import java.util.ServiceLoader;\n" +
8.498 +"import org.apidesign.spi.security.Digestor;\n" +
8.499 +"\n" +
8.500 +"/** Simplified version of a Digest class that allows to compute a fingerprint\n" +
8.501 +" * for buffer of data.\n" +
8.502 +" *\n" +
8.503 +" * @author Jaroslav Tulach <jaroslav.tulach@apidesign.org>\n" +
8.504 +" */\n" +
8.505 +"// BEGIN: day.end.bridges.Digest\n" +
8.506 +"d; DigestImplementation<?> impl = DigestImplementation.create(digestor, algorithm);\n" +
8.507 +"// END: day.end.bridges.Digest\n";
8.508 +
8.509 + File src = createFile(1, "C.java", c1);
8.510 +
8.511 +
8.512 + String c2 =
8.513 + "@day.end.bridges.Digest@";
8.514 + File txt = createFile(2, "in.txt", c2);
8.515 +
8.516 + File out = createFile(3, "out.txt", "");
8.517 + out.delete();
8.518 +
8.519 + try {
8.520 + execute(1, 2, "-Dfile1=" + txt, "-Dfile2=" + out, "-Dinclude1=*.java");
8.521 + } catch (ExecuteUtils.ExecutionError ex) {
8.522 + // OK
8.523 + return;
8.524 + }
8.525 + fail("Should fail, as there is long line");
8.526 + }
8.527 + public void testLongNotLineDetectedAsShortened() throws Exception {
8.528 + String c1 =
8.529 +"package org.apidesign.api.security;\n" +
8.530 +"" +
8.531 +"import java.nio.ByteBuffer;\n" +
8.532 +"import java.util.ServiceLoader;\n" +
8.533 +"import org.apidesign.spi.security.Digestor;\n" +
8.534 +"\n" +
8.535 +"/** Simplified version of a Digest class that allows to compute a fingerprint\n" +
8.536 +" * for buffer of data.\n" +
8.537 +" *\n" +
8.538 +" * @author Jaroslav Tulach <jaroslav.tulach@apidesign.org>\n" +
8.539 +" */\n" +
8.540 +"// BEGIN: day.end.bridges.Digest\n" +
8.541 +" DigestImplementation<?> impl = DigestImplementation.create(digestor, algorithm);\n" +
8.542 +"// END: day.end.bridges.Digest\n";
8.543 +
8.544 + File src = createFile(1, "C.java", c1);
8.545 +
8.546 +
8.547 + String c2 =
8.548 + "@day.end.bridges.Digest@";
8.549 + File txt = createFile(2, "in.txt", c2);
8.550 +
8.551 + File out = createFile(3, "out.txt", "");
8.552 + out.delete();
8.553 +
8.554 + execute(1, 2, "-Dfile1=" + txt, "-Dfile2=" + out, "-Dinclude1=*.java");
8.555 + }
8.556 +
8.557 + public void testNotClosedSection() throws Exception {
8.558 + String c1 =
8.559 + "package ahoj;\n" +
8.560 + "// BEGIN: clazz\n" +
8.561 + "int x;\n" +
8.562 + "\n";
8.563 + File src = createFile(1, "I.java", c1);
8.564 +
8.565 +
8.566 + String c2 =
8.567 + "@clazz@";
8.568 + File txt = createFile(2, "in.txt", c2);
8.569 +
8.570 + File out = createFile(3, "out.txt", "");
8.571 + out.delete();
8.572 +
8.573 + try {
8.574 + execute(1, 2, "-Dfile1=" + txt, "-Dfile2=" + out, "-Dinclude1=*.java");
8.575 + fail("Has to fail");
8.576 + } catch (ExecuteUtils.ExecutionError ex) {
8.577 + // ok
8.578 + }
8.579 + }
8.580 + public void testLongNotLineDetectedAsNotInTheList() throws Exception {
8.581 + String c1 =
8.582 +"package org.apidesign.api.security;\n" +
8.583 +"" +
8.584 +"import java.nio.ByteBuffer;\n" +
8.585 +"import java.util.ServiceLoader;\n" +
8.586 +"import org.apidesign.spi.security.Digestor;\n" +
8.587 +"\n" +
8.588 +"/** Simplified version of a Digest class that allows to compute a fingerprint\n" +
8.589 +" * for buffer of data.\n" +
8.590 +" *\n" +
8.591 +" * @author Jaroslav Tulach <jaroslav.tulach@apidesign.org>\n" +
8.592 +" */\n" +
8.593 +" DigestImplementation<?> impl = DigestImplementation.create(digestor, algorithm);\n" +
8.594 +"// BEGIN: day.end.bridges.Digest\n" +
8.595 +" DigestImplementation<?> impl = null\n" +
8.596 +"// END: day.end.bridges.Digest\n";
8.597 +
8.598 + File src = createFile(1, "C.java", c1);
8.599 +
8.600 +
8.601 + String c2 =
8.602 + "@day.end.bridges.Digest@";
8.603 + File txt = createFile(2, "in.txt", c2);
8.604 +
8.605 + File out = createFile(3, "out.txt", "");
8.606 + out.delete();
8.607 +
8.608 + execute(1, 2, "-Dfile1=" + txt, "-Dfile2=" + out, "-Dinclude1=*.java");
8.609 + }
8.610 +
8.611 + protected final File createFile(int slot, String name, String content) throws Exception {
8.612 + File d1 = new File(getWorkDir(), "dir" + slot);
8.613 + File c1 = new File(d1, name);
8.614 + copy(content, c1);
8.615 + return c1;
8.616 + }
8.617 +
8.618 + protected final void execute(int slotFirst, int slotSecond, String... additionalArgs) throws Exception {
8.619 + File d1 = new File(getWorkDir(), "dir" + slotFirst);
8.620 + File d2 = new File(getWorkDir(), "dir" + slotSecond);
8.621 +
8.622 + File build = new File(getWorkDir(), "build.xml");
8.623 + extractResource("color.xml", build);
8.624 +
8.625 + List<String> args = new ArrayList<String>();
8.626 + args.addAll(Arrays.asList(additionalArgs));
8.627 + args.add("-Ddir1=" + d1);
8.628 + args.add("-Ddir2=" + d2);
8.629 + ExecuteUtils.execute(build, args.toArray(new String[0]));
8.630 + }
8.631 +
8.632 + private static final void copy(String txt, File f) throws Exception {
8.633 + f.getParentFile().mkdirs();
8.634 + FileWriter w = new FileWriter(f);
8.635 + w.append(txt);
8.636 + w.close();
8.637 + }
8.638 +
8.639 + final File extractResource(String res, File f) throws Exception {
8.640 + URL u = ColorifyTest.class.getResource(res);
8.641 + assertNotNull ("Resource should be found " + res, u);
8.642 +
8.643 + FileOutputStream os = new FileOutputStream(f);
8.644 + InputStream is = u.openStream();
8.645 + for (;;) {
8.646 + int ch = is.read ();
8.647 + if (ch == -1) {
8.648 + break;
8.649 + }
8.650 + os.write (ch);
8.651 + }
8.652 + os.close ();
8.653 +
8.654 + return f;
8.655 + }
8.656 +
8.657 + final static String readFile (java.io.File f) throws java.io.IOException {
8.658 + int s = (int)f.length ();
8.659 + byte[] data = new byte[s];
8.660 + assertEquals ("Read all data", s, new java.io.FileInputStream (f).read (data));
8.661 +
8.662 + return new String (data);
8.663 + }
8.664 +
8.665 + final File extractString (String res, String nameExt) throws Exception {
8.666 + File f = new File(getWorkDir(), nameExt);
8.667 + f.deleteOnExit ();
8.668 +
8.669 + FileOutputStream os = new FileOutputStream(f);
8.670 + InputStream is = new ByteArrayInputStream(res.getBytes("UTF-8"));
8.671 + for (;;) {
8.672 + int ch = is.read ();
8.673 + if (ch == -1) {
8.674 + break;
8.675 + }
8.676 + os.write (ch);
8.677 + }
8.678 + os.close ();
8.679 +
8.680 + return f;
8.681 + }
8.682 +
8.683 +}
8.684 \ No newline at end of file
9.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
9.2 +++ b/java/ant/test/org/apidesign/infra/ant/ExecuteUtils.java Sun Jul 06 00:12:56 2008 +0200
9.3 @@ -0,0 +1,254 @@
9.4 +/*
9.5 + * Copyright 2007 Jaroslav Tulach All Rights Reserved.
9.6 + *
9.7 + * This code is free software; you can redistribute it and/or modify it
9.8 + * under the terms of the GNU General Public License version 2 only, as
9.9 + * published by the Free Software Foundation. Sun designates this
9.10 + * particular file as subject to the "Classpath" exception as provided
9.11 + * by Sun in the LICENSE file that accompanied this code.
9.12 + *
9.13 + * This code is distributed in the hope that it will be useful, but WITHOUT
9.14 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
9.15 + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
9.16 + * version 2 for more details (a copy is included in the LICENSE file that
9.17 + * accompanied this code).
9.18 + *
9.19 + * You should have received a copy of the GNU General Public License version
9.20 + * 2 along with this work; if not, write to the Free Software Foundation,
9.21 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
9.22 + *
9.23 + * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
9.24 + * CA 95054 USA or visit www.sun.com if you need additional information or
9.25 + * have any questions.
9.26 + */
9.27 +package org.apidesign.infra.ant;
9.28 +
9.29 +import java.io.ByteArrayOutputStream;
9.30 +import java.io.File;
9.31 +import java.io.FileDescriptor;
9.32 +import java.io.PrintStream;
9.33 +import java.io.PrintWriter;
9.34 +import java.net.InetAddress;
9.35 +import java.security.Permission;
9.36 +import java.util.ArrayList;
9.37 +import java.util.Arrays;
9.38 +import java.util.List;
9.39 +import junit.framework.AssertionFailedError;
9.40 +import org.junit.Assert;
9.41 +
9.42 +/**
9.43 + *
9.44 + * @author Jaroslav Tulach
9.45 + */
9.46 +final class ExecuteUtils {
9.47 +
9.48 + private ExecuteUtils() {
9.49 + }
9.50 +/*
9.51 + final static void execute (String res, String[] args) throws Exception {
9.52 + execute (extractResource (res), args);
9.53 + }
9.54 + */
9.55 + private static ByteArrayOutputStream out;
9.56 + private static ByteArrayOutputStream err;
9.57 +
9.58 + final static String getStdOut() {
9.59 + return out.toString();
9.60 + }
9.61 + final static String getStdErr() {
9.62 + return err.toString();
9.63 + }
9.64 +
9.65 + final static void execute(File f, String... args) throws Exception {
9.66 + // we need security manager to prevent System.exit
9.67 + if (! (System.getSecurityManager () instanceof MySecMan)) {
9.68 + out = new java.io.ByteArrayOutputStream ();
9.69 + err = new java.io.ByteArrayOutputStream ();
9.70 + System.setOut (new java.io.PrintStream (out));
9.71 + System.setErr (new java.io.PrintStream (err));
9.72 +
9.73 + System.setSecurityManager (new MySecMan ());
9.74 + }
9.75 +
9.76 + MySecMan sec = (MySecMan)System.getSecurityManager();
9.77 +
9.78 + // Jesse claims that this is not the right way how the execution
9.79 + // of an ant script should be invoked:
9.80 + //
9.81 + // better IMHO to just run the task directly
9.82 + // (setProject() and similar, configure its bean properties, and call
9.83 + // execute()), or just make a new Project and initialize it.
9.84 + // ant.Main.main is not intended for embedded use. Then you could get rid
9.85 + // of the SecurityManager stuff, would be cleaner I think.
9.86 + //
9.87 + // If I had to write this once again, I would try to follow the
9.88 + // "just make a new Project and initialize it", but as this works
9.89 + // for me now, I leave it for the time when somebody really
9.90 + // needs that...
9.91 +
9.92 + List<String> arr = new ArrayList<String>();
9.93 + arr.add ("-f");
9.94 + arr.add (f.toString ());
9.95 + arr.addAll(Arrays.asList(args));
9.96 + arr.add ("-verbose");
9.97 +
9.98 +
9.99 + out.reset ();
9.100 + err.reset ();
9.101 +
9.102 + try {
9.103 + sec.setActive(true);
9.104 + org.apache.tools.ant.Main.main (arr.toArray(new String[0]));
9.105 + } catch (MySecExc ex) {
9.106 + Assert.assertNotNull ("The only one to throw security exception is MySecMan and should set exitCode", sec.exitCode);
9.107 + ExecutionError.assertExitCode (
9.108 + "Execution has to finish without problems",
9.109 + sec.exitCode.intValue ()
9.110 + );
9.111 + } finally {
9.112 + sec.setActive(false);
9.113 + }
9.114 + }
9.115 +
9.116 + static class ExecutionError extends AssertionFailedError {
9.117 + public final int exitCode;
9.118 +
9.119 + public ExecutionError (String msg, int e) {
9.120 + super (msg);
9.121 + this.exitCode = e;
9.122 + }
9.123 +
9.124 + public static void assertExitCode (String msg, int e) {
9.125 + if (e != 0) {
9.126 + throw new ExecutionError (
9.127 + msg + " was: " + e + "\nOutput: " + out.toString () +
9.128 + "\nError: " + err.toString (),
9.129 + e
9.130 + );
9.131 + }
9.132 + }
9.133 + }
9.134 +
9.135 + private static class MySecExc extends SecurityException {
9.136 + @Override
9.137 + public void printStackTrace() {
9.138 + }
9.139 + @Override
9.140 + public void printStackTrace(PrintStream ps) {
9.141 + }
9.142 + public void printStackTrace(PrintWriter ps) {
9.143 + }
9.144 + }
9.145 +
9.146 + private static class MySecMan extends SecurityManager {
9.147 + public Integer exitCode;
9.148 +
9.149 + private boolean active;
9.150 +
9.151 + public void checkExit (int status) {
9.152 + if (active) {
9.153 + exitCode = new Integer (status);
9.154 + throw new MySecExc ();
9.155 + }
9.156 + }
9.157 +
9.158 + public void checkPermission(Permission perm, Object context) {
9.159 + }
9.160 +
9.161 + public void checkPermission(Permission perm) {
9.162 + /*
9.163 + if (perm instanceof RuntimePermission) {
9.164 + if (perm.getName ().equals ("setIO")) {
9.165 + throw new MySecExc ();
9.166 + }
9.167 + }
9.168 + */
9.169 + }
9.170 +
9.171 + public void checkMulticast(InetAddress maddr) {
9.172 + }
9.173 +
9.174 + public void checkAccess (ThreadGroup g) {
9.175 + }
9.176 +
9.177 + public void checkWrite (String file) {
9.178 + }
9.179 +
9.180 + public void checkLink (String lib) {
9.181 + }
9.182 +
9.183 + public void checkExec (String cmd) {
9.184 + }
9.185 +
9.186 + public void checkDelete (String file) {
9.187 + }
9.188 +
9.189 + public void checkPackageAccess (String pkg) {
9.190 + }
9.191 +
9.192 + public void checkPackageDefinition (String pkg) {
9.193 + }
9.194 +
9.195 + public void checkPropertyAccess (String key) {
9.196 + }
9.197 +
9.198 + public void checkRead (String file) {
9.199 + }
9.200 +
9.201 + public void checkSecurityAccess (String target) {
9.202 + }
9.203 +
9.204 + public void checkWrite(FileDescriptor fd) {
9.205 + }
9.206 +
9.207 + public void checkListen (int port) {
9.208 + }
9.209 +
9.210 + public void checkRead(FileDescriptor fd) {
9.211 + }
9.212 +
9.213 + public void checkMulticast(InetAddress maddr, byte ttl) {
9.214 + }
9.215 +
9.216 + public void checkAccess (Thread t) {
9.217 + }
9.218 +
9.219 + public void checkConnect (String host, int port, Object context) {
9.220 + }
9.221 +
9.222 + public void checkRead (String file, Object context) {
9.223 + }
9.224 +
9.225 + public void checkConnect (String host, int port) {
9.226 + }
9.227 +
9.228 + public void checkAccept (String host, int port) {
9.229 + }
9.230 +
9.231 + public void checkMemberAccess (Class clazz, int which) {
9.232 + }
9.233 +
9.234 + public void checkSystemClipboardAccess () {
9.235 + }
9.236 +
9.237 + public void checkSetFactory () {
9.238 + }
9.239 +
9.240 + public void checkCreateClassLoader () {
9.241 + }
9.242 +
9.243 + public void checkAwtEventQueueAccess () {
9.244 + }
9.245 +
9.246 + public void checkPrintJobAccess () {
9.247 + }
9.248 +
9.249 + public void checkPropertiesAccess () {
9.250 + }
9.251 +
9.252 + void setActive(boolean b) {
9.253 + active = b;
9.254 + }
9.255 + } // end of MySecMan
9.256 +
9.257 +}
10.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
10.2 +++ b/java/ant/test/org/apidesign/infra/ant/GrepCopyTest.java Sun Jul 06 00:12:56 2008 +0200
10.3 @@ -0,0 +1,524 @@
10.4 +/*
10.5 + * Copyright 2007 Sun Microsystems, Inc. All Rights Reserved.
10.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
10.7 + *
10.8 + * This code is free software; you can redistribute it and/or modify it
10.9 + * under the terms of the GNU General Public License version 2 only, as
10.10 + * published by the Free Software Foundation. Sun designates this
10.11 + * particular file as subject to the "Classpath" exception as provided
10.12 + * by Sun in the LICENSE file that accompanied this code.
10.13 + *
10.14 + * This code is distributed in the hope that it will be useful, but WITHOUT
10.15 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
10.16 + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
10.17 + * version 2 for more details (a copy is included in the LICENSE file that
10.18 + * accompanied this code).
10.19 + *
10.20 + * You should have received a copy of the GNU General Public License version
10.21 + * 2 along with this work; if not, write to the Free Software Foundation,
10.22 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
10.23 + *
10.24 + * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
10.25 + * CA 95054 USA or visit www.sun.com if you need additional information or
10.26 + * have any questions.
10.27 + */
10.28 +package org.apidesign.infra.ant;
10.29 +
10.30 +import java.io.ByteArrayInputStream;
10.31 +import java.io.File;
10.32 +import java.io.FileNotFoundException;
10.33 +import java.io.FileOutputStream;
10.34 +import java.io.FileWriter;
10.35 +import java.io.InputStream;
10.36 +import java.net.URL;
10.37 +import java.util.ArrayList;
10.38 +import java.util.Arrays;
10.39 +import java.util.List;
10.40 +import junit.framework.Test;
10.41 +import org.netbeans.junit.NbTestCase;
10.42 +import org.netbeans.junit.NbTestSuite;
10.43 +
10.44 +/**
10.45 + *
10.46 + * @author Jaroslav Tulach
10.47 + */
10.48 +public class GrepCopyTest extends NbTestCase {
10.49 + private static File workDir;
10.50 +
10.51 + public GrepCopyTest(String s) {
10.52 + super(s);
10.53 + }
10.54 +
10.55 + public static Test suite() {
10.56 + return new NbTestSuite(GrepCopyTest.class);
10.57 + //return new GrepCopyTest("testInXML");
10.58 + }
10.59 +
10.60 + @Override
10.61 + protected void setUp() throws Exception {
10.62 + clearWorkDir();
10.63 + }
10.64 +
10.65 + public void testMissingMethodInAnInterfaceIsDetected() throws Exception {
10.66 + String c1 =
10.67 + "package ahoj;\n" +
10.68 + "// BEGIN: xyz\n" +
10.69 + "public interface I {\n" +
10.70 + "// FINISH: xyz\n" +
10.71 + " public void get();\n" +
10.72 + "}" +
10.73 + "";
10.74 + File src = createFile(1, "I.java", c1);
10.75 +
10.76 +
10.77 + String c2 =
10.78 + "@xyz@";
10.79 + File txt = createFile(2, "in.txt", c2);
10.80 +
10.81 + execute(1, 2, "-Dfile1=" + txt, "-Dinclude1=*.java");
10.82 +
10.83 + String r = readFile("xyz");
10.84 + assertEquals("public interface I {\n}\n", r);
10.85 + }
10.86 +
10.87 + public void testSpacesAtBeginingAreStripped() throws Exception {
10.88 + String c1 =
10.89 + "package ahoj;\n" +
10.90 + "// BEGIN: xyz\n" +
10.91 + " public interface I {\n" +
10.92 + " public void ahoj();\n" +
10.93 + " }\n" +
10.94 + "// END: xyz\n" +
10.95 + " public void get();\n" +
10.96 + "}" +
10.97 + "";
10.98 + File src = createFile(1, "I.java", c1);
10.99 +
10.100 +
10.101 + String c2 =
10.102 + "@xyz@";
10.103 + File txt = createFile(2, "in.txt", c2);
10.104 +
10.105 + execute(1, 2, "-Dfile1=" + txt, "-Dinclude1=*.java");
10.106 +
10.107 + String r = readFile("xyz");
10.108 + String result = "public interface I {\n" +
10.109 + " public void ahoj();\n" +
10.110 + "}\n";
10.111 + assertEquals(result, r);
10.112 + }
10.113 +
10.114 + public void testReportUnpairedBracesAsError() throws Exception {
10.115 + String c1 =
10.116 + "package ahoj;\n" +
10.117 + "// BEGIN: xyz\n" +
10.118 + " public interface I {\n" +
10.119 + " public void ahoj();\n" +
10.120 + "// END: xyz\n" +
10.121 + " }\n" +
10.122 + " public void get();\n" +
10.123 + "}" +
10.124 + "";
10.125 + File src = createFile(1, "I.java", c1);
10.126 +
10.127 +
10.128 + String c2 =
10.129 + "@xyz@";
10.130 + File txt = createFile(2, "in.txt", c2);
10.131 +
10.132 + File out = createFile(3, "out.txt", "");
10.133 + out.delete();
10.134 +
10.135 + try {
10.136 + execute(1, 2, "-Dfile1=" + txt, "-Dfile2=" + out, "-Dinclude1=*.java");
10.137 + } catch (ExecuteUtils.ExecutionError ex) {
10.138 + // ok
10.139 + return;
10.140 + }
10.141 + fail("The execution of the script shall fail");
10.142 + }
10.143 +
10.144 + public void testIncludedTexts() throws Exception {
10.145 + String c1 =
10.146 + "package ahoj;\n" +
10.147 + "// BEGIN: clazz\n" +
10.148 + "public interface I {\n" +
10.149 + " // BEGIN: method\n" +
10.150 + " public void get();\n" +
10.151 + " // END: method\n" +
10.152 + "}\n" +
10.153 + "// END: clazz\n" +
10.154 + "";
10.155 + File src = createFile(1, "I.java", c1);
10.156 +
10.157 +
10.158 + String c2 =
10.159 + "@clazz@";
10.160 + File txt = createFile(2, "in.txt", c2);
10.161 +
10.162 + execute(1, 2, "-Dfile1=" + txt, "-Dinclude1=*.java");
10.163 +
10.164 + String r = readFile("clazz");
10.165 + if (r.indexOf("BEGIN") >= 0) {
10.166 + fail("BEGIN is there: " + r);
10.167 + }
10.168 + if (r.indexOf("END") >= 0) {
10.169 + fail("END is there: " + r);
10.170 + }
10.171 + if (r.indexOf("interface I") < 0) {
10.172 + fail("Missing interface: " + r);
10.173 + }
10.174 + if (r.indexOf("void get()") < 0) {
10.175 + fail("Missing get: " + r);
10.176 + }
10.177 + }
10.178 + public void testIncludedTextsAmper() throws Exception {
10.179 + String c1 =
10.180 + "package ahoj;\n" +
10.181 + "public class C {\n" +
10.182 + " // BEGIN: method\n" +
10.183 + " public void change(int x) { x &= 10; }\n" +
10.184 + " // END: method\n" +
10.185 + "}\n" +
10.186 + "";
10.187 + File src = createFile(1, "C.java", c1);
10.188 +
10.189 +
10.190 + String c2 =
10.191 + "@method@";
10.192 + File txt = createFile(2, "in.txt", c2);
10.193 +
10.194 + execute(1, 2, "-Dfile1=" + txt, "-Dinclude1=*.java");
10.195 +
10.196 + String r = readFile("method");
10.197 + if (r.indexOf("&=") < 0) {
10.198 + fail("No XML: " + r);
10.199 + }
10.200 + if (r.indexOf("&=") >= 0) {
10.201 + fail("No XML, we need &: " + r);
10.202 + }
10.203 + }
10.204 + public void testIncludedTextsAmperAndGenerics() throws Exception {
10.205 + String c1 =
10.206 +
10.207 +"package org.apidesign.api.security;\n" +
10.208 +"" +
10.209 +"import java.nio.ByteBuffer;\n" +
10.210 +"import java.util.ServiceLoader;\n" +
10.211 +"import org.apidesign.spi.security.Digestor;\n" +
10.212 +"\n" +
10.213 +"/** Simplified version of a Digest class that allows to compute a fingerprint\n" +
10.214 +" * for buffer of data.\n" +
10.215 +" *\n" +
10.216 +" * @author Jaroslav Tulach <jaroslav.tulach@apidesign.org>\n" +
10.217 +" */\n" +
10.218 +"// BEGIN: day.end.bridges.Digest\n" +
10.219 +"public final class Digest {\n" +
10.220 +" private final DigestImplementation<?> impl;\n" +
10.221 +" \n" +
10.222 +" /** Factory method is better than constructor */\n" +
10.223 +" private Digest(DigestImplementation<?> impl) {\n" +
10.224 +" this.impl = impl;\n" +
10.225 +" }\n" +
10.226 +" \n" +
10.227 +" /** Factory method to create digest for an algorithm.\n" +
10.228 +" */\n" +
10.229 +" public static Digest getInstance(String algorithm) {\n" +
10.230 +" for (Digestor<?> digestor : ServiceLoader.load(Digestor.class)) {\n" +
10.231 +" DigestImplementation<?> impl = \n" +
10.232 + "DigestImplementation.create(digestor, algorithm);\n" +
10.233 +" if (impl != null) {\n" +
10.234 +" return new Digest(impl);\n" +
10.235 +" }\n" +
10.236 +" }\n" +
10.237 +" throw new IllegalArgumentException(algorithm);\n" +
10.238 +" }\n" +
10.239 +" \n" +
10.240 +" //\n" +
10.241 +" // these methods are kept the same as in original MessageDigest,\n" +
10.242 +" // but for simplicity choose just some from the original API\n" +
10.243 +" //\n" +
10.244 +" \n" +
10.245 +" public byte[] digest(ByteBuffer bb) {\n" +
10.246 +" return impl.digest(bb);\n" +
10.247 +" }\n" +
10.248 +"}\n" +
10.249 +"// END: day.end.bridges.Digest\n";
10.250 +
10.251 + File src = createFile(1, "C.java", c1);
10.252 +
10.253 +
10.254 + String c2 =
10.255 + "@day.end.bridges.Digest@";
10.256 + File txt = createFile(2, "in.txt", c2);
10.257 +
10.258 + execute(1, 2, "-Dfile1=" + txt, "-Dinclude1=*.java");
10.259 +
10.260 + String r = readFile("day.end.bridges.Digest");
10.261 + if (r.indexOf("&=") >= 0) {
10.262 + fail("Wrong XML: " + r);
10.263 + }
10.264 + if (r.indexOf("&") > -1) {
10.265 + fail("Wrong XML, no &: " + r);
10.266 + }
10.267 + }
10.268 +
10.269 + public void testInXML() throws Exception {
10.270 + String c1 =
10.271 + "<!-- BEGIN: clazz -->\n" +
10.272 + "<interface name='I'/>\n" +
10.273 + "<!-- END: clazz -->\n" +
10.274 + "";
10.275 + File src = createFile(1, "I.xml", c1);
10.276 +
10.277 +
10.278 + String c2 =
10.279 + "@clazz@";
10.280 + File txt = createFile(2, "in.txt", c2);
10.281 +
10.282 + execute(1, 2, "-Dfile1=" + txt, "-Dinclude1=*.xml");
10.283 +
10.284 + String r = readFile("clazz");
10.285 + if (r.indexOf("BEGIN") >= 0) {
10.286 + fail("BEGIN is there: " + r);
10.287 + }
10.288 + if (r.indexOf("END") >= 0) {
10.289 + fail("END is there: " + r);
10.290 + }
10.291 + if (r.indexOf("<interface name='I'/>") < 0) {
10.292 + fail("Missing interface: " + r);
10.293 + }
10.294 + }
10.295 +
10.296 + public void testLongLineNotDetectedAsBeginsWithGen() throws Exception {
10.297 + String c1 =
10.298 +"package org.apidesign.api.security;\n" +
10.299 +"" +
10.300 +"import java.nio.ByteBuffer;\n" +
10.301 +"import java.util.ServiceLoader;\n" +
10.302 +"import org.apidesign.spi.security.Digestor;\n" +
10.303 +"\n" +
10.304 +"/** Simplified version of a Digest class that allows to compute a fingerprint\n" +
10.305 +"// BEGIN: x\n" +
10.306 +" * for buffer of data.\n" +
10.307 +"// END: x\n" +
10.308 +" *\n" +
10.309 +" * @author Jaroslav Tulach <jaroslav.tulach@apidesign.org>\n" +
10.310 +" */\n" +
10.311 +"// GEN-BEGIN: day.end.bridges.Digest\n" +
10.312 +"d; DigestImplementation<?> impl = DigestImplementation.create(digestor, algorithm);\n" +
10.313 +"// GEN-END: day.end.bridges.Digest\n";
10.314 +
10.315 + File src = createFile(1, "C.java", c1);
10.316 +
10.317 +
10.318 + String c2 =
10.319 + "@day.end.bridges.Digest@";
10.320 + File txt = createFile(2, "in.txt", c2);
10.321 +
10.322 + File out = createFile(3, "out.txt", "");
10.323 + out.delete();
10.324 +
10.325 + execute(1, 2, "-Dfile1=" + txt, "-Dfile2=" + out, "-Dinclude1=*.java");
10.326 + }
10.327 +
10.328 +
10.329 + public void testLongLineDetected() throws Exception {
10.330 + String c1 =
10.331 +"package org.apidesign.api.security;\n" +
10.332 +"" +
10.333 +"import java.nio.ByteBuffer;\n" +
10.334 +"import java.util.ServiceLoader;\n" +
10.335 +"import org.apidesign.spi.security.Digestor;\n" +
10.336 +"\n" +
10.337 +"/** Simplified version of a Digest class that allows to compute a fingerprint\n" +
10.338 +" * for buffer of data.\n" +
10.339 +" *\n" +
10.340 +" * @author Jaroslav Tulach <jaroslav.tulach@apidesign.org>\n" +
10.341 +" */\n" +
10.342 +"// BEGIN: day.end.bridges.Digest\n" +
10.343 +"d; DigestImplementation<?> impl = DigestImplementation.create(digestor, algorithm);\n" +
10.344 +"// END: day.end.bridges.Digest\n";
10.345 +
10.346 + File src = createFile(1, "C.java", c1);
10.347 +
10.348 +
10.349 + String c2 =
10.350 + "@day.end.bridges.Digest@";
10.351 + File txt = createFile(2, "in.txt", c2);
10.352 +
10.353 + File out = createFile(3, "out.txt", "");
10.354 + out.delete();
10.355 +
10.356 + try {
10.357 + execute(1, 2, "-Dfile1=" + txt, "-Dfile2=" + out, "-Dinclude1=*.java");
10.358 + } catch (ExecuteUtils.ExecutionError ex) {
10.359 + // OK
10.360 + return;
10.361 + }
10.362 + fail("Should fail, as there is long line");
10.363 + }
10.364 + public void testLongNotLineDetectedAsShortened() throws Exception {
10.365 + String c1 =
10.366 +"package org.apidesign.api.security;\n" +
10.367 +"" +
10.368 +"import java.nio.ByteBuffer;\n" +
10.369 +"import java.util.ServiceLoader;\n" +
10.370 +"import org.apidesign.spi.security.Digestor;\n" +
10.371 +"\n" +
10.372 +"/** Simplified version of a Digest class that allows to compute a fingerprint\n" +
10.373 +" * for buffer of data.\n" +
10.374 +" *\n" +
10.375 +" * @author Jaroslav Tulach <jaroslav.tulach@apidesign.org>\n" +
10.376 +" */\n" +
10.377 +"// BEGIN: day.end.bridges.Digest\n" +
10.378 +" DigestImplementation<?> impl = DigestImplementation.create(digestor, algorithm);\n" +
10.379 +"// END: day.end.bridges.Digest\n";
10.380 +
10.381 + File src = createFile(1, "C.java", c1);
10.382 +
10.383 +
10.384 + String c2 =
10.385 + "@day.end.bridges.Digest@";
10.386 + File txt = createFile(2, "in.txt", c2);
10.387 +
10.388 + File out = createFile(3, "out.txt", "");
10.389 + out.delete();
10.390 +
10.391 + execute(1, 2, "-Dfile1=" + txt, "-Dfile2=" + out, "-Dinclude1=*.java");
10.392 + }
10.393 +
10.394 + public void testNotClosedSection() throws Exception {
10.395 + String c1 =
10.396 + "package ahoj;\n" +
10.397 + "// BEGIN: clazz\n" +
10.398 + "int x;\n" +
10.399 + "\n";
10.400 + File src = createFile(1, "I.java", c1);
10.401 +
10.402 +
10.403 + String c2 =
10.404 + "@clazz@";
10.405 + File txt = createFile(2, "in.txt", c2);
10.406 +
10.407 + File out = createFile(3, "out.txt", "");
10.408 + out.delete();
10.409 +
10.410 + try {
10.411 + execute(1, 2, "-Dfile1=" + txt, "-Dfile2=" + out, "-Dinclude1=*.java");
10.412 + fail("Has to fail");
10.413 + } catch (ExecuteUtils.ExecutionError ex) {
10.414 + // ok
10.415 + }
10.416 + }
10.417 + public void testLongNotLineDetectedAsNotInTheList() throws Exception {
10.418 + String c1 =
10.419 +"package org.apidesign.api.security;\n" +
10.420 +"" +
10.421 +"import java.nio.ByteBuffer;\n" +
10.422 +"import java.util.ServiceLoader;\n" +
10.423 +"import org.apidesign.spi.security.Digestor;\n" +
10.424 +"\n" +
10.425 +"/** Simplified version of a Digest class that allows to compute a fingerprint\n" +
10.426 +" * for buffer of data.\n" +
10.427 +" *\n" +
10.428 +" * @author Jaroslav Tulach <jaroslav.tulach@apidesign.org>\n" +
10.429 +" */\n" +
10.430 +" DigestImplementation<?> impl = DigestImplementation.create(digestor, algorithm);\n" +
10.431 +"// BEGIN: day.end.bridges.Digest\n" +
10.432 +" DigestImplementation<?> impl = null\n" +
10.433 +"// END: day.end.bridges.Digest\n";
10.434 +
10.435 + File src = createFile(1, "C.java", c1);
10.436 +
10.437 +
10.438 + String c2 =
10.439 + "@day.end.bridges.Digest@";
10.440 + File txt = createFile(2, "in.txt", c2);
10.441 +
10.442 + File out = createFile(3, "out.txt", "");
10.443 + out.delete();
10.444 +
10.445 + execute(1, 2, "-Dfile1=" + txt, "-Dfile2=" + out, "-Dinclude1=*.java");
10.446 + }
10.447 +
10.448 + protected final File createFile(int slot, String name, String content) throws Exception {
10.449 + File d1 = new File(getWorkDir(), "dir" + slot);
10.450 + File c1 = new File(d1, name);
10.451 + copy(content, c1);
10.452 + return c1;
10.453 + }
10.454 +
10.455 + protected final void execute(int slotFirst, int slotSecond, String... additionalArgs) throws Exception {
10.456 + File d1 = new File(getWorkDir(), "dir" + slotFirst);
10.457 + File d2 = new File(getWorkDir(), "dir" + slotSecond);
10.458 + File out = new File(getWorkDir(), "out");
10.459 +
10.460 + File build = new File(getWorkDir(), "build.xml");
10.461 + extractResource("copy.xml", build);
10.462 +
10.463 + List<String> args = new ArrayList<String>();
10.464 + args.addAll(Arrays.asList(additionalArgs));
10.465 + args.add("-Ddir1=" + d1);
10.466 + args.add("-Ddir2=" + d2);
10.467 + args.add("-Dout.dir=" + out);
10.468 + ExecuteUtils.execute(build, args.toArray(new String[0]));
10.469 + }
10.470 +
10.471 + private static final void copy(String txt, File f) throws Exception {
10.472 + f.getParentFile().mkdirs();
10.473 + FileWriter w = new FileWriter(f);
10.474 + w.append(txt);
10.475 + w.close();
10.476 + }
10.477 +
10.478 + final File extractResource(String res, File f) throws Exception {
10.479 + URL u = GrepCopyTest.class.getResource(res);
10.480 + assertNotNull ("Resource should be found " + res, u);
10.481 +
10.482 + FileOutputStream os = new FileOutputStream(f);
10.483 + InputStream is = u.openStream();
10.484 + for (;;) {
10.485 + int ch = is.read ();
10.486 + if (ch == -1) {
10.487 + break;
10.488 + }
10.489 + os.write (ch);
10.490 + }
10.491 + os.close ();
10.492 +
10.493 + return f;
10.494 + }
10.495 +
10.496 + final String readFile (String name) throws java.io.IOException {
10.497 + File f = new File(new File(getWorkDir(), "out"), name);
10.498 + if (!f.exists()) {
10.499 + throw new FileNotFoundException(f.getPath());
10.500 + }
10.501 +
10.502 + int s = (int)f.length ();
10.503 + byte[] data = new byte[s];
10.504 + assertEquals ("Read all data", s, new java.io.FileInputStream (f).read (data));
10.505 +
10.506 + return new String (data);
10.507 + }
10.508 +
10.509 + final File extractString (String res, String nameExt) throws Exception {
10.510 + File f = new File(getWorkDir(), nameExt);
10.511 + f.deleteOnExit ();
10.512 +
10.513 + FileOutputStream os = new FileOutputStream(f);
10.514 + InputStream is = new ByteArrayInputStream(res.getBytes("UTF-8"));
10.515 + for (;;) {
10.516 + int ch = is.read ();
10.517 + if (ch == -1) {
10.518 + break;
10.519 + }
10.520 + os.write (ch);
10.521 + }
10.522 + os.close ();
10.523 +
10.524 + return f;
10.525 + }
10.526 +
10.527 +}
10.528 \ No newline at end of file
11.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
11.2 +++ b/java/ant/test/org/apidesign/infra/ant/GrepTest.java Sun Jul 06 00:12:56 2008 +0200
11.3 @@ -0,0 +1,546 @@
11.4 +/*
11.5 + * Copyright 2007 Sun Microsystems, Inc. All Rights Reserved.
11.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
11.7 + *
11.8 + * This code is free software; you can redistribute it and/or modify it
11.9 + * under the terms of the GNU General Public License version 2 only, as
11.10 + * published by the Free Software Foundation. Sun designates this
11.11 + * particular file as subject to the "Classpath" exception as provided
11.12 + * by Sun in the LICENSE file that accompanied this code.
11.13 + *
11.14 + * This code is distributed in the hope that it will be useful, but WITHOUT
11.15 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
11.16 + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
11.17 + * version 2 for more details (a copy is included in the LICENSE file that
11.18 + * accompanied this code).
11.19 + *
11.20 + * You should have received a copy of the GNU General Public License version
11.21 + * 2 along with this work; if not, write to the Free Software Foundation,
11.22 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
11.23 + *
11.24 + * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
11.25 + * CA 95054 USA or visit www.sun.com if you need additional information or
11.26 + * have any questions.
11.27 + */
11.28 +package org.apidesign.infra.ant;
11.29 +
11.30 +import java.io.ByteArrayInputStream;
11.31 +import java.io.File;
11.32 +import java.io.FileOutputStream;
11.33 +import java.io.FileWriter;
11.34 +import java.io.InputStream;
11.35 +import java.net.URL;
11.36 +import java.util.ArrayList;
11.37 +import java.util.Arrays;
11.38 +import java.util.List;
11.39 +import junit.framework.Test;
11.40 +import org.netbeans.junit.NbTestCase;
11.41 +import org.netbeans.junit.NbTestSuite;
11.42 +
11.43 +/**
11.44 + *
11.45 + * @author Jaroslav Tulach
11.46 + */
11.47 +public class GrepTest extends NbTestCase {
11.48 + private static File workDir;
11.49 +
11.50 + public GrepTest(String s) {
11.51 + super(s);
11.52 + }
11.53 +
11.54 + public static Test suite() {
11.55 + return new NbTestSuite(GrepTest.class);
11.56 + //return new GrepTest("testInXML");
11.57 + }
11.58 +
11.59 + @Override
11.60 + protected void setUp() throws Exception {
11.61 + clearWorkDir();
11.62 + }
11.63 +
11.64 + public void testMissingMethodInAnInterfaceIsDetected() throws Exception {
11.65 + String c1 =
11.66 + "package ahoj;\n" +
11.67 + "// BEGIN: xyz\n" +
11.68 + "public interface I {\n" +
11.69 + "// FINISH: xyz\n" +
11.70 + " public void get();\n" +
11.71 + "}" +
11.72 + "";
11.73 + File src = createFile(1, "I.java", c1);
11.74 +
11.75 +
11.76 + String c2 =
11.77 + "@xyz@";
11.78 + File txt = createFile(2, "in.txt", c2);
11.79 +
11.80 + File out = createFile(3, "out.txt", "");
11.81 + out.delete();
11.82 +
11.83 + execute(1, 2, "-Dfile1=" + txt, "-Dfile2=" + out, "-Dinclude1=*.java");
11.84 +
11.85 + assertTrue("output created", out.canRead());
11.86 +
11.87 + String r = readFile(out);
11.88 + assertEquals("public interface I {\n}\n", r);
11.89 + }
11.90 +
11.91 + public void testSpacesAtBeginingAreStripped() throws Exception {
11.92 + String c1 =
11.93 + "package ahoj;\n" +
11.94 + "// BEGIN: xyz\n" +
11.95 + " public interface I {\n" +
11.96 + " public void ahoj();\n" +
11.97 + " }\n" +
11.98 + "// END: xyz\n" +
11.99 + " public void get();\n" +
11.100 + "}" +
11.101 + "";
11.102 + File src = createFile(1, "I.java", c1);
11.103 +
11.104 +
11.105 + String c2 =
11.106 + "@xyz@";
11.107 + File txt = createFile(2, "in.txt", c2);
11.108 +
11.109 + File out = createFile(3, "out.txt", "");
11.110 + out.delete();
11.111 +
11.112 + execute(1, 2, "-Dfile1=" + txt, "-Dfile2=" + out, "-Dinclude1=*.java");
11.113 +
11.114 + assertTrue("output created", out.canRead());
11.115 +
11.116 + String r = readFile(out);
11.117 + String result = "public interface I {\n" +
11.118 + " public void ahoj();\n" +
11.119 + "}\n";
11.120 + assertEquals(result, r);
11.121 + }
11.122 +
11.123 + public void testReportUnpairedBracesAsError() throws Exception {
11.124 + String c1 =
11.125 + "package ahoj;\n" +
11.126 + "// BEGIN: xyz\n" +
11.127 + " public interface I {\n" +
11.128 + " public void ahoj();\n" +
11.129 + "// END: xyz\n" +
11.130 + " }\n" +
11.131 + " public void get();\n" +
11.132 + "}" +
11.133 + "";
11.134 + File src = createFile(1, "I.java", c1);
11.135 +
11.136 +
11.137 + String c2 =
11.138 + "@xyz@";
11.139 + File txt = createFile(2, "in.txt", c2);
11.140 +
11.141 + File out = createFile(3, "out.txt", "");
11.142 + out.delete();
11.143 +
11.144 + try {
11.145 + execute(1, 2, "-Dfile1=" + txt, "-Dfile2=" + out, "-Dinclude1=*.java");
11.146 + } catch (ExecuteUtils.ExecutionError ex) {
11.147 + // ok
11.148 + return;
11.149 + }
11.150 + fail("The execution of the script shall fail");
11.151 + }
11.152 +
11.153 + public void testIncludedTexts() throws Exception {
11.154 + String c1 =
11.155 + "package ahoj;\n" +
11.156 + "// BEGIN: clazz\n" +
11.157 + "public interface I {\n" +
11.158 + " // BEGIN: method\n" +
11.159 + " public void get();\n" +
11.160 + " // END: method\n" +
11.161 + "}\n" +
11.162 + "// END: clazz\n" +
11.163 + "";
11.164 + File src = createFile(1, "I.java", c1);
11.165 +
11.166 +
11.167 + String c2 =
11.168 + "@clazz@";
11.169 + File txt = createFile(2, "in.txt", c2);
11.170 +
11.171 + File out = createFile(3, "out.txt", "");
11.172 + out.delete();
11.173 +
11.174 + execute(1, 2, "-Dfile1=" + txt, "-Dfile2=" + out, "-Dinclude1=*.java");
11.175 +
11.176 + assertTrue("output created", out.canRead());
11.177 +
11.178 + String r = readFile(out);
11.179 + if (r.indexOf("BEGIN") >= 0) {
11.180 + fail("BEGIN is there: " + r);
11.181 + }
11.182 + if (r.indexOf("END") >= 0) {
11.183 + fail("END is there: " + r);
11.184 + }
11.185 + if (r.indexOf("interface I") < 0) {
11.186 + fail("Missing interface: " + r);
11.187 + }
11.188 + if (r.indexOf("void get()") < 0) {
11.189 + fail("Missing get: " + r);
11.190 + }
11.191 + }
11.192 + public void testIncludedTextsAmper() throws Exception {
11.193 + String c1 =
11.194 + "package ahoj;\n" +
11.195 + "public class C {\n" +
11.196 + " // BEGIN: method\n" +
11.197 + " public void change(int x) { x &= 10; }\n" +
11.198 + " // END: method\n" +
11.199 + "}\n" +
11.200 + "";
11.201 + File src = createFile(1, "C.java", c1);
11.202 +
11.203 +
11.204 + String c2 =
11.205 + "@method@";
11.206 + File txt = createFile(2, "in.txt", c2);
11.207 +
11.208 + File out = createFile(3, "out.txt", "");
11.209 + out.delete();
11.210 +
11.211 + execute(1, 2, "-Dfile1=" + txt, "-Dfile2=" + out, "-Dinclude1=*.java");
11.212 +
11.213 + assertTrue("output created", out.canRead());
11.214 +
11.215 + String r = readFile(out);
11.216 + if (r.indexOf("&=") < 0) {
11.217 + fail("No XML: " + r);
11.218 + }
11.219 + if (r.indexOf("&=") >= 0) {
11.220 + fail("No XML, we need &: " + r);
11.221 + }
11.222 + }
11.223 + public void testIncludedTextsAmperAndGenerics() throws Exception {
11.224 + String c1 =
11.225 +
11.226 +"package org.apidesign.api.security;\n" +
11.227 +"" +
11.228 +"import java.nio.ByteBuffer;\n" +
11.229 +"import java.util.ServiceLoader;\n" +
11.230 +"import org.apidesign.spi.security.Digestor;\n" +
11.231 +"\n" +
11.232 +"/** Simplified version of a Digest class that allows to compute a fingerprint\n" +
11.233 +" * for buffer of data.\n" +
11.234 +" *\n" +
11.235 +" * @author Jaroslav Tulach <jaroslav.tulach@apidesign.org>\n" +
11.236 +" */\n" +
11.237 +"// BEGIN: day.end.bridges.Digest\n" +
11.238 +"public final class Digest {\n" +
11.239 +" private final DigestImplementation<?> impl;\n" +
11.240 +" \n" +
11.241 +" /** Factory method is better than constructor */\n" +
11.242 +" private Digest(DigestImplementation<?> impl) {\n" +
11.243 +" this.impl = impl;\n" +
11.244 +" }\n" +
11.245 +" \n" +
11.246 +" /** Factory method to create digest for an algorithm.\n" +
11.247 +" */\n" +
11.248 +" public static Digest getInstance(String algorithm) {\n" +
11.249 +" for (Digestor<?> digestor : ServiceLoader.load(Digestor.class)) {\n" +
11.250 +" DigestImplementation<?> impl = \n" +
11.251 + "DigestImplementation.create(digestor, algorithm);\n" +
11.252 +" if (impl != null) {\n" +
11.253 +" return new Digest(impl);\n" +
11.254 +" }\n" +
11.255 +" }\n" +
11.256 +" throw new IllegalArgumentException(algorithm);\n" +
11.257 +" }\n" +
11.258 +" \n" +
11.259 +" //\n" +
11.260 +" // these methods are kept the same as in original MessageDigest,\n" +
11.261 +" // but for simplicity choose just some from the original API\n" +
11.262 +" //\n" +
11.263 +" \n" +
11.264 +" public byte[] digest(ByteBuffer bb) {\n" +
11.265 +" return impl.digest(bb);\n" +
11.266 +" }\n" +
11.267 +"}\n" +
11.268 +"// END: day.end.bridges.Digest\n";
11.269 +
11.270 + File src = createFile(1, "C.java", c1);
11.271 +
11.272 +
11.273 + String c2 =
11.274 + "@day.end.bridges.Digest@";
11.275 + File txt = createFile(2, "in.txt", c2);
11.276 +
11.277 + File out = createFile(3, "out.txt", "");
11.278 + out.delete();
11.279 +
11.280 + execute(1, 2, "-Dfile1=" + txt, "-Dfile2=" + out, "-Dinclude1=*.java");
11.281 +
11.282 + assertTrue("output created", out.canRead());
11.283 +
11.284 + String r = readFile(out);
11.285 + if (r.indexOf("&=") >= 0) {
11.286 + fail("Wrong XML: " + r);
11.287 + }
11.288 + if (r.indexOf("&") > -1) {
11.289 + fail("Wrong XML, no &: " + r);
11.290 + }
11.291 + }
11.292 +
11.293 + public void testInXML() throws Exception {
11.294 + String c1 =
11.295 + "<!-- BEGIN: clazz -->\n" +
11.296 + "<interface name='I'/>\n" +
11.297 + "<!-- END: clazz -->\n" +
11.298 + "";
11.299 + File src = createFile(1, "I.xml", c1);
11.300 +
11.301 +
11.302 + String c2 =
11.303 + "@clazz@";
11.304 + File txt = createFile(2, "in.txt", c2);
11.305 +
11.306 + File out = createFile(3, "out.txt", "");
11.307 + out.delete();
11.308 +
11.309 + execute(1, 2, "-Dfile1=" + txt, "-Dfile2=" + out, "-Dinclude1=*.xml");
11.310 +
11.311 + assertTrue("output created", out.canRead());
11.312 +
11.313 + String r = readFile(out);
11.314 + if (r.indexOf("BEGIN") >= 0) {
11.315 + fail("BEGIN is there: " + r);
11.316 + }
11.317 + if (r.indexOf("END") >= 0) {
11.318 + fail("END is there: " + r);
11.319 + }
11.320 + if (r.indexOf("<interface name='I'/>") < 0) {
11.321 + fail("Missing interface: " + r);
11.322 + }
11.323 + }
11.324 +
11.325 + public void testLongLineNotDetectedAsBeginsWithGen() throws Exception {
11.326 + String c1 =
11.327 +"package org.apidesign.api.security;\n" +
11.328 +"" +
11.329 +"import java.nio.ByteBuffer;\n" +
11.330 +"import java.util.ServiceLoader;\n" +
11.331 +"import org.apidesign.spi.security.Digestor;\n" +
11.332 +"\n" +
11.333 +"/** Simplified version of a Digest class that allows to compute a fingerprint\n" +
11.334 +"// BEGIN: x\n" +
11.335 +" * for buffer of data.\n" +
11.336 +"// END: x\n" +
11.337 +" *\n" +
11.338 +" * @author Jaroslav Tulach <jaroslav.tulach@apidesign.org>\n" +
11.339 +" */\n" +
11.340 +"// GEN-BEGIN: day.end.bridges.Digest\n" +
11.341 +"d; DigestImplementation<?> impl = DigestImplementation.create(digestor, algorithm);\n" +
11.342 +"// GEN-END: day.end.bridges.Digest\n";
11.343 +
11.344 + File src = createFile(1, "C.java", c1);
11.345 +
11.346 +
11.347 + String c2 =
11.348 + "@day.end.bridges.Digest@";
11.349 + File txt = createFile(2, "in.txt", c2);
11.350 +
11.351 + File out = createFile(3, "out.txt", "");
11.352 + out.delete();
11.353 +
11.354 + execute(1, 2, "-Dfile1=" + txt, "-Dfile2=" + out, "-Dinclude1=*.java");
11.355 + }
11.356 +
11.357 +
11.358 + public void testLongLineDetected() throws Exception {
11.359 + String c1 =
11.360 +"package org.apidesign.api.security;\n" +
11.361 +"" +
11.362 +"import java.nio.ByteBuffer;\n" +
11.363 +"import java.util.ServiceLoader;\n" +
11.364 +"import org.apidesign.spi.security.Digestor;\n" +
11.365 +"\n" +
11.366 +"/** Simplified version of a Digest class that allows to compute a fingerprint\n" +
11.367 +" * for buffer of data.\n" +
11.368 +" *\n" +
11.369 +" * @author Jaroslav Tulach <jaroslav.tulach@apidesign.org>\n" +
11.370 +" */\n" +
11.371 +"// BEGIN: day.end.bridges.Digest\n" +
11.372 +"d; DigestImplementation<?> impl = DigestImplementation.create(digestor, algorithm);\n" +
11.373 +"// END: day.end.bridges.Digest\n";
11.374 +
11.375 + File src = createFile(1, "C.java", c1);
11.376 +
11.377 +
11.378 + String c2 =
11.379 + "@day.end.bridges.Digest@";
11.380 + File txt = createFile(2, "in.txt", c2);
11.381 +
11.382 + File out = createFile(3, "out.txt", "");
11.383 + out.delete();
11.384 +
11.385 + try {
11.386 + execute(1, 2, "-Dfile1=" + txt, "-Dfile2=" + out, "-Dinclude1=*.java");
11.387 + } catch (ExecuteUtils.ExecutionError ex) {
11.388 + // OK
11.389 + return;
11.390 + }
11.391 + fail("Should fail, as there is long line");
11.392 + }
11.393 + public void testLongNotLineDetectedAsShortened() throws Exception {
11.394 + String c1 =
11.395 +"package org.apidesign.api.security;\n" +
11.396 +"" +
11.397 +"import java.nio.ByteBuffer;\n" +
11.398 +"import java.util.ServiceLoader;\n" +
11.399 +"import org.apidesign.spi.security.Digestor;\n" +
11.400 +"\n" +
11.401 +"/** Simplified version of a Digest class that allows to compute a fingerprint\n" +
11.402 +" * for buffer of data.\n" +
11.403 +" *\n" +
11.404 +" * @author Jaroslav Tulach <jaroslav.tulach@apidesign.org>\n" +
11.405 +" */\n" +
11.406 +"// BEGIN: day.end.bridges.Digest\n" +
11.407 +" DigestImplementation<?> impl = DigestImplementation.create(digestor, algorithm);\n" +
11.408 +"// END: day.end.bridges.Digest\n";
11.409 +
11.410 + File src = createFile(1, "C.java", c1);
11.411 +
11.412 +
11.413 + String c2 =
11.414 + "@day.end.bridges.Digest@";
11.415 + File txt = createFile(2, "in.txt", c2);
11.416 +
11.417 + File out = createFile(3, "out.txt", "");
11.418 + out.delete();
11.419 +
11.420 + execute(1, 2, "-Dfile1=" + txt, "-Dfile2=" + out, "-Dinclude1=*.java");
11.421 + }
11.422 +
11.423 + public void testNotClosedSection() throws Exception {
11.424 + String c1 =
11.425 + "package ahoj;\n" +
11.426 + "// BEGIN: clazz\n" +
11.427 + "int x;\n" +
11.428 + "\n";
11.429 + File src = createFile(1, "I.java", c1);
11.430 +
11.431 +
11.432 + String c2 =
11.433 + "@clazz@";
11.434 + File txt = createFile(2, "in.txt", c2);
11.435 +
11.436 + File out = createFile(3, "out.txt", "");
11.437 + out.delete();
11.438 +
11.439 + try {
11.440 + execute(1, 2, "-Dfile1=" + txt, "-Dfile2=" + out, "-Dinclude1=*.java");
11.441 + fail("Has to fail");
11.442 + } catch (ExecuteUtils.ExecutionError ex) {
11.443 + // ok
11.444 + }
11.445 + }
11.446 + public void testLongNotLineDetectedAsNotInTheList() throws Exception {
11.447 + String c1 =
11.448 +"package org.apidesign.api.security;\n" +
11.449 +"" +
11.450 +"import java.nio.ByteBuffer;\n" +
11.451 +"import java.util.ServiceLoader;\n" +
11.452 +"import org.apidesign.spi.security.Digestor;\n" +
11.453 +"\n" +
11.454 +"/** Simplified version of a Digest class that allows to compute a fingerprint\n" +
11.455 +" * for buffer of data.\n" +
11.456 +" *\n" +
11.457 +" * @author Jaroslav Tulach <jaroslav.tulach@apidesign.org>\n" +
11.458 +" */\n" +
11.459 +" DigestImplementation<?> impl = DigestImplementation.create(digestor, algorithm);\n" +
11.460 +"// BEGIN: day.end.bridges.Digest\n" +
11.461 +" DigestImplementation<?> impl = null\n" +
11.462 +"// END: day.end.bridges.Digest\n";
11.463 +
11.464 + File src = createFile(1, "C.java", c1);
11.465 +
11.466 +
11.467 + String c2 =
11.468 + "@day.end.bridges.Digest@";
11.469 + File txt = createFile(2, "in.txt", c2);
11.470 +
11.471 + File out = createFile(3, "out.txt", "");
11.472 + out.delete();
11.473 +
11.474 + execute(1, 2, "-Dfile1=" + txt, "-Dfile2=" + out, "-Dinclude1=*.java");
11.475 + }
11.476 +
11.477 + protected final File createFile(int slot, String name, String content) throws Exception {
11.478 + File d1 = new File(getWorkDir(), "dir" + slot);
11.479 + File c1 = new File(d1, name);
11.480 + copy(content, c1);
11.481 + return c1;
11.482 + }
11.483 +
11.484 + protected final void execute(int slotFirst, int slotSecond, String... additionalArgs) throws Exception {
11.485 + File d1 = new File(getWorkDir(), "dir" + slotFirst);
11.486 + File d2 = new File(getWorkDir(), "dir" + slotSecond);
11.487 +
11.488 + File build = new File(getWorkDir(), "build.xml");
11.489 + extractResource("build.xml", build);
11.490 +
11.491 + List<String> args = new ArrayList<String>();
11.492 + args.addAll(Arrays.asList(additionalArgs));
11.493 + args.add("-Ddir1=" + d1);
11.494 + args.add("-Ddir2=" + d2);
11.495 + ExecuteUtils.execute(build, args.toArray(new String[0]));
11.496 + }
11.497 +
11.498 + private static final void copy(String txt, File f) throws Exception {
11.499 + f.getParentFile().mkdirs();
11.500 + FileWriter w = new FileWriter(f);
11.501 + w.append(txt);
11.502 + w.close();
11.503 + }
11.504 +
11.505 + final File extractResource(String res, File f) throws Exception {
11.506 + URL u = GrepTest.class.getResource(res);
11.507 + assertNotNull ("Resource should be found " + res, u);
11.508 +
11.509 + FileOutputStream os = new FileOutputStream(f);
11.510 + InputStream is = u.openStream();
11.511 + for (;;) {
11.512 + int ch = is.read ();
11.513 + if (ch == -1) {
11.514 + break;
11.515 + }
11.516 + os.write (ch);
11.517 + }
11.518 + os.close ();
11.519 +
11.520 + return f;
11.521 + }
11.522 +
11.523 + final static String readFile (java.io.File f) throws java.io.IOException {
11.524 + int s = (int)f.length ();
11.525 + byte[] data = new byte[s];
11.526 + assertEquals ("Read all data", s, new java.io.FileInputStream (f).read (data));
11.527 +
11.528 + return new String (data);
11.529 + }
11.530 +
11.531 + final File extractString (String res, String nameExt) throws Exception {
11.532 + File f = new File(getWorkDir(), nameExt);
11.533 + f.deleteOnExit ();
11.534 +
11.535 + FileOutputStream os = new FileOutputStream(f);
11.536 + InputStream is = new ByteArrayInputStream(res.getBytes("UTF-8"));
11.537 + for (;;) {
11.538 + int ch = is.read ();
11.539 + if (ch == -1) {
11.540 + break;
11.541 + }
11.542 + os.write (ch);
11.543 + }
11.544 + os.close ();
11.545 +
11.546 + return f;
11.547 + }
11.548 +
11.549 +}
11.550 \ No newline at end of file
12.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
12.2 +++ b/java/ant/test/org/apidesign/infra/ant/build.xml Sun Jul 06 00:12:56 2008 +0200
12.3 @@ -0,0 +1,17 @@
12.4 +<?xml version="1.0" encoding="UTF-8"?>
12.5 +<project name="testing build script" default="all" basedir=".">
12.6 + <target name="all">
12.7 + <taskdef name="grepfilter" classname="org.apidesign.infra.ant.GrepFilter"/>
12.8 +
12.9 + <grepfilter id="test.filter.set">
12.10 + <fileset dir="${dir1}">
12.11 + <include name="${include1}"/>
12.12 + </fileset>
12.13 + </grepfilter>
12.14 +
12.15 + <copy file="${file1}" tofile="${file2}" encoding="utf-8">
12.16 + <filterset refid="test.filter.set"/>
12.17 + </copy>
12.18 + </target>
12.19 +
12.20 +</project>
13.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
13.2 +++ b/java/ant/test/org/apidesign/infra/ant/color.xml Sun Jul 06 00:12:56 2008 +0200
13.3 @@ -0,0 +1,17 @@
13.4 +<?xml version="1.0" encoding="UTF-8"?>
13.5 +<project name="testing build script" default="all" basedir=".">
13.6 + <target name="all">
13.7 + <taskdef name="grepfilter" classname="org.apidesign.infra.ant.GrepFilter"/>
13.8 +
13.9 + <grepfilter id="test.filter.set">
13.10 + <fileset dir="${dir1}">
13.11 + <include name="${include1}"/>
13.12 + </fileset>
13.13 + </grepfilter>
13.14 +
13.15 + <copy file="${file1}" tofile="${file2}" encoding="utf-8">
13.16 + <filterset refid="test.filter.set"/>
13.17 + </copy>
13.18 + </target>
13.19 +
13.20 +</project>
14.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
14.2 +++ b/java/ant/test/org/apidesign/infra/ant/copy.xml Sun Jul 06 00:12:56 2008 +0200
14.3 @@ -0,0 +1,14 @@
14.4 +<?xml version="1.0" encoding="UTF-8"?>
14.5 +<project name="testing build script" default="all" basedir=".">
14.6 + <target name="all">
14.7 + <taskdef name="grepcopy" classname="org.apidesign.infra.ant.GrepCopy"/>
14.8 + <fail unless="out.dir"/>
14.9 +
14.10 + <grepcopy target="${out.dir}">
14.11 + <fileset dir="${dir1}">
14.12 + <include name="${include1}"/>
14.13 + </fileset>
14.14 + </grepcopy>
14.15 + </target>
14.16 +
14.17 +</project>