1/* 2 * NAME 3 * java - the JAVA compiler cookbook 4 * 5 * DESCRIPTION 6 * This cookbook describes how to work with .java files. 7 * 8 * This cookbook will only work with jikes, not javac. It assumes 9 * that source in java/src/%0%1.java is being compiled into 10 * java/bin/com/companyName/projectName/%0%1.class.The recipe at the end 11 * generates a .jar file (java .tar file). 12 * 13 * RECIPES 14 * %.class: %.java make class files form Java source files 15 * 16 * VARIABLES 17 * javac The Java compiler command 18 * 19 * CONTRIBUTED BY 20 * Matthew Lee 21 * Copyright (C) 2004, 2007 Peter Miller 22 */ 23 24#pragma once 25 26domian = name-of-project.name-of-company.com; /* change this as appropriate */ 27 28java_project = [head [split "." [domain]]]; 29 30function rev = 31{ 32 local result = ; 33 local foo = ; 34 loop foo = [@1] 35 { 36 result = [foo] [result]; 37 } 38 return [result]; 39} 40 41java_domain = [unsplit "/" [rev [split "." [domain]]]]; 42 43manifest = [find java/src -name "*.java" -print]; 44 45classpath = 46 [unsplit ":" 47 /usr/j2se/src.zip 48 /usr/j2se/jre/lib/rt.jar 49 [addsuffix "/java/bin" [search_list]] 50 [addsuffix "/java/src" [search_list]] 51 ]; 52sourcepath = 53 [unsplit ":" 54 [addsuffix "/java/src/" [search_list]] 55 ]; 56 57all = ; 58all: [all] 59 set default; 60 61/* 62 * How to compile Java sources. 63 */ 64java/bin/[java_domain]/%0%1.class: java/src/%0%1.java 65{ 66 jikes 67 +F 68 -nowarn /* because jikes is VERY pedantic */ 69 -classpath [classpath] 70 -sourcepath [sourcepath] 71 -d java/bin 72 [resolve 73#if 1 74 /* 75 * Note: this recipe skips all of the problems of figuring 76 * out Java dependencies by always compiling everything. 77 */ 78 [match_mask java/src/%%0%%1.java [manifest]] 79#else 80 java/src/%0%1.java 81#endif 82 ] 83 ; 84} 85 86/* 87 * How to generate a jar file from all our .class files 88 */ 89install/lib/[java_project].jar: 90 [fromto 91 java/src/%0%1.java 92 java/bin/[java_domain]/%0%1.class 93 [match_mask java/src/%0%1.java [manifest]] 94 ] 95{ 96 /* 97 * The jar tool does not allow us to strip the leading saerch list elements 98 * from .class files that are pulled from the baseline. 99 * One way to get around this is to copy all of the .class 100 * files that don't already exist in this work area's source 101 * tree from the baseline into the changeset. 102 */ 103 loop tmp = [need] 104 { 105 if [not [exists [tmp]]] then 106 { 107 /* The file doesn't exist in this changeset's source tree */ 108 if [not [exists [dirname [tmp]]]] then 109 { 110 /* Make the directory before copying the file */ 111 mkdir -p [dirname [tmp]]; 112 } 113 cp -p -r [resolve [tmp]] [tmp]; 114 } 115 } 116 117 /* 118 * Create the jar file, rooted in the com directory 119 */ 120 cat - > tmp.[thread-id]; 121data 122cd java/bin 123jar cvf ../../[target] \ 124[fromto java/bin/com/%0%1.class com/%0%1.class [need]] 125dataend 126 /* Execute and delete the script we've just created */ 127 sh tmp.[thread-id]; 128 rm tmp.[thread-id]; 129} 130 131all += install/lib/[java_project].jar; 132