1default: javadoc runtests findbugs 2 3help: 4 @echo "Usage: make [<target> ...]" 5 @echo "" 6 @echo "Targets include:" 7 @echo " help - Displays this message." 8 @echo " ----------- QUICK" 9 @echo " clean - Delete all built files." 10 @echo " default - Build documentation&classes, and run checks." 11 @echo " The output will be available under out/." 12 @echo " ----------- DIAGNOSTIC" 13 @echo " classes - Put Java .class files under out/." 14 @echo " tests - Compile tests." 15 @echo " runtests - Runs tests. Some require a network connection." 16 @echo " coverage - Runs tests and generates a code coverage report." 17 @echo " findbugs - Runs a code quality tool. Slow." 18 @echo " benchmark - Times the sanitizer against a tree builder." 19 @echo " profile - Profiles the benchmark." 20 @echo " ----------- ARTIFACTS" 21 @echo " distrib - Build everything and package it into JARs." 22 @echo " Requires an svn executable on PATH." 23 @echo " release - Additionally, cut a new Maven version." 24 @echo " Should be run from client that has sibling" 25 @echo " directories of trunk checked out." 26 @echo " download - Bundle docs, externally required jars, and" 27 @echo " license files into a zip file suitable for" 28 @echo " the code.google site downloads." 29 @echo "" 30 @echo "For more verbose test runner output, do" 31 @echo " make VERBOSE=1 runtests" 32 @echo "" 33 @echo "To run tests with assertions on, do" 34 @echo " make NOASSERTS=1 runtests" 35 36SHELL=/bin/bash 37CLASSPATH=lib/guava-libraries/guava.jar:lib/jsr305/jsr305.jar 38TEST_CLASSPATH=$(CLASSPATH):lib/htmlparser-1.3/htmlparser-1.3.jar:lib/junit/junit.jar:lib/commons-codec-1.4/commons-codec-1.4.jar:benchmark-data 39JAVAC_FLAGS=-source 1.5 -target 1.5 -Xlint -encoding UTF-8 40TEST_RUNNER=junit.textui.TestRunner 41JASSERTS=-ea 42# Run tests in the Turkish locale to trigger any extra-case-folding-rule bugs 43# http://www.moserware.com/2008/02/does-your-code-pass-turkey-test.html 44TURKEYTEST=-Duser.counter=TR -Duser.language-tr 45 46ifdef VERBOSE 47override TEST_RUNNER=org.owasp.html.VerboseTestRunner 48endif 49 50ifdef NOASSERTS 51override JASSERTS= 52endif 53 54out: 55 mkdir -p out 56 57out/classes: out 58 mkdir -p out/classes 59 60out/genfiles: out 61 mkdir -p out/genfiles 62 63clean: 64 rm -rf out 65 66classes: out/classes.tstamp 67out/classes.tstamp: out/classes src/main/org/owasp/html/*.java 68 javac -g ${JAVAC_FLAGS} -classpath ${CLASSPATH} -d out/classes \ 69 $$(echo $^ | tr ' ' '\n' | egrep '\.java$$') 70 touch out/classes.tstamp 71 72examples: out/examples.tstamp 73out/examples.tstamp: out/classes.tstamp src/main/org/owasp/html/examples/*.java 74 javac -g ${JAVAC_FLAGS} -classpath ${CLASSPATH}:out/classes \ 75 -d out/classes \ 76 $$(echo $^ | tr ' ' '\n' | egrep '\.java$$') 77 touch out/examples.tstamp 78 79# Depends on all java files under tests. 80tests: out/tests.tstamp 81out/tests.tstamp: out/classes.tstamp out/genfiles.tstamp out/examples.tstamp src/tests/org/owasp/html/*.java 82 javac -g ${JAVAC_FLAGS} \ 83 -classpath out/classes:out/genfiles:${TEST_CLASSPATH} \ 84 -d out/classes \ 85 $$((echo $^; find out/genfiles -type f) | tr ' ' '\n' | \ 86 egrep '\.java$$') 87 touch out/tests.tstamp 88 89out/genfiles.tstamp: out/genfiles/org/owasp/html/AllExamples.java out/genfiles/org/owasp/html/AllTests.java 90 touch out/genfiles.tstamp 91out/genfiles/org/owasp/html/AllTests.java: src/tests/org/owasp/html/*Test.java 92 mkdir -p "$$(dirname $@)" 93 (echo 'package org.owasp.html;'; \ 94 echo 'import junit.framework.Test;'; \ 95 echo 'import junit.framework.TestSuite;'; \ 96 echo 'public class AllTests {'; \ 97 echo ' public static Test suite() {'; \ 98 echo ' TestSuite suite = new TestSuite();'; \ 99 echo $^ | tr ' ' '\n' | perl -pe \ 100 's#^src/tests/# suite.addTestSuite(#; s#\.java$$#.class);#g; \ 101 s#/#.#g;'; \ 102 echo ' return suite;'; \ 103 echo ' }'; \ 104 echo '}'; \ 105 ) > $@ 106 107out/genfiles/org/owasp/html/AllExamples.java: src/main/org/owasp/html/examples/*.java 108 mkdir -p "$$(dirname $@)" 109 (echo 'package org.owasp.html;'; \ 110 echo 'final class AllExamples {'; \ 111 echo ' static final Class<?>[] CLASSES = {'; \ 112 echo $^ | tr ' ' '\n' | perl -pe \ 113 's#^src/main/# #; s#\.java$$#.class,#g; \ 114 s#/#.#g;'; \ 115 echo ' };'; \ 116 echo '}'; \ 117 ) > $@ 118 119runtests: tests 120 java ${TURKEYTEST} ${JASSERTS} \ 121 -classpath out/classes:src/tests:${TEST_CLASSPATH} \ 122 ${TEST_RUNNER} org.owasp.html.AllTests 123 124coverage: tests 125 java ${JASSERTS} -cp tools/emma/lib/emma.jar:lib/guava-libraries/guava.jar:lib/jsr305/jsr305.jar:lib/htmlparser-1.3/htmlparser-1.3.jar:lib/commons-codec-1.4/commons-codec-1.4.jar:benchmark-data \ 126 -Demma.report.out.file=out/coverage/index.html \ 127 -Demma.report.out.encoding=UTF-8 \ 128 emmarun \ 129 -r html \ 130 -cp out/classes:src/tests:lib/junit/junit.jar \ 131 -sp src/main:src/tests:out/genfiles \ 132 -f \ 133 -ix '-junit.*' \ 134 -ix '-org.junit.*' \ 135 -ix '-org.hamcrest.*' \ 136 ${TEST_RUNNER} \ 137 org.owasp.html.AllTests 138 139# Runs findbugs to identify problems. 140findbugs: out/findbugs.txt 141 cat $^ 142out/findbugs.txt: out/tests.tstamp 143 find out/classes/org -type d | \ 144 xargs tools/findbugs/bin/findbugs -textui -effort:max \ 145 -auxclasspath ${TEST_CLASSPATH} > $@ 146 147# Runs a benchmark that compares performance. 148benchmark: out/tests.tstamp 149 java -cp ${TEST_CLASSPATH}:out/classes \ 150 org.owasp.html.Benchmark benchmark-data/Yahoo\!.html 151 152# Profiles the benchmark. 153profile: out/java.hprof.txt 154out/java.hprof.txt: out/tests.tstamp 155 java -cp ${TEST_CLASSPATH}:out/classes -agentlib:hprof=cpu=times,format=a,file=out/java.hprof.txt,lineno=y,doe=y org.owasp.html.Benchmark benchmark-data/Yahoo\!.html s 156 157# Builds the documentation. 158javadoc: out/javadoc.tstamp 159out/javadoc.tstamp: src/main/org/owasp/html/*.java src/main/org/owasp/html/examples/*.java 160 mkdir -p out/javadoc 161 javadoc -locale en -d out/javadoc \ 162 -notimestamp \ 163 -charset UTF-8 \ 164 -classpath ${CLASSPATH} \ 165 -use -splitIndex \ 166 -windowtitle 'OWASP Java HTML Sanitizer' \ 167 -doctitle 'OWASP Java HTML Sanitizer' \ 168 -header '<a href="http://code.google.com/p/owasp-java-html-sanitizer" target=_top>code.google.com home</a>' \ 169 -J-Xmx250m -nohelp -sourcetab 8 -docencoding UTF-8 -protected \ 170 -encoding UTF-8 -author -version $^ \ 171 && touch out/javadoc.tstamp 172 173# Packages the documentation, and libraries in the distrib directory, 174# and creates a script containing svn commands to commit those changes. 175distrib: out/run_me_before_committing_release.sh 176out/run_me_before_committing_release.sh: clean out/staging.tstamp 177 tools/update_tree_in_svn.py out/staging distrib > $@ 178 chmod +x $@ 179out/staging.tstamp: out/javadoc.tstamp out/classes.tstamp 180 mkdir -p out/staging 181 echo Copying Javadoc 182 rm -rf out/staging/javadoc 183 cp -r out/javadoc out/staging/javadoc 184 echo Suppressing spurious Javadoc diffs 185 for doc_html in $$(find out/staging/javadoc -name \*.html); do \ 186 perl -i -pe 's/<!-- Generated by javadoc .+?-->//; s/<META NAME="date" CONTENT="[^"]*">//' "$$doc_html"; \ 187 done 188 echo Linking required jars 189 mkdir -p out/staging/lib 190 for jar in $$(echo ${CLASSPATH} | tr : ' '); do \ 191 cp "$$jar" out/staging/lib/; \ 192 cp "$$(dirname $$jar)"/COPYING out/staging/lib/"$$(basename $$jar .jar)"-COPYING; \ 193 done 194 echo Bundling compiled classes 195 jar cf out/staging/lib/owasp-java-html-sanitizer.jar -C out/classes org 196 echo Bundling sources and docs 197 for f in $$(find src/main -name \*.java); do \ 198 mkdir -p out/staging/"$$(dirname $$f)"; \ 199 cp "$$f" out/staging/"$$f"; \ 200 done 201 jar cf out/staging/lib/owasp-java-html-sanitizer-sources.jar -C out/staging/src/main org 202 jar cf out/staging/lib/owasp-java-html-sanitizer-javadoc.jar -C out javadoc 203 rm -rf out/staging/src 204 cp COPYING out/staging/lib/owasp-java-html-sanitizer-COPYING 205 touch $@ 206 207# Packages the distrib jars into the maven directory which is a sibling of 208# trunk. 209release: out/run_me_before_committing_maven.sh 210out/run_me_before_committing_maven.sh: distrib 211 tools/cut_release.py > $@ 212 chmod +x $@ 213 214download: out/owasp-java-html-sanitizer.zip 215out/zip.tstamp: out/staging.tstamp 216 rm -f out/zip/owasp-java-html-sanitizer 217 mkdir -p out/zip/owasp-java-html-sanitizer 218 cp -r out/staging/lib out/staging/javadoc \ 219 out/zip/owasp-java-html-sanitizer/ 220 touch $@ 221out/owasp-java-html-sanitizer.zip: out/zip.tstamp 222 jar cMf out/owasp-java-html-sanitizer.zip \ 223 -C out/zip owasp-java-html-sanitizer 224