Skip to content

Instantly share code, notes, and snippets.

@pato
Created May 11, 2013 21:08
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save pato/5561428 to your computer and use it in GitHub Desktop.
Save pato/5561428 to your computer and use it in GitHub Desktop.
Java class which builds various versions of the same project by modifying a settings file accordingly
class Compile {
private static Runtime rt = Runtime.getRuntime();
private static final String version = "1.4.2";
public static void main(String[] args) throws IOException{
modify(false,false,true);
build();dist("Full");
modify(false,true,true);
build();dist("Trial");
}
public static void modify(boolean asis, boolean trial, boolean traffic){
try {
BufferedReader br = new BufferedReader(new FileReader("src/settings.java"));
BufferedWriter bw = new BufferedWriter(new FileWriter("src/settings2.java"));
String line;
while ((line = br.readLine()) != null){
if (line.contains("public static final boolean ASIS"))
bw.write(" public static final boolean ASIS = "+(asis?"true":"false")+";\n");
else if (line.contains("public static final boolean trialVersion"))
bw.write(" public static final boolean trialVersion = "+(trial?"true":"false")+";\n");
else if (line.contains("public static final boolean trafficLights"))
bw.write(" public static final boolean trafficLights = "+(traffic?"true":"false")+";\n");
else
bw.write(line+"\n");
}
br.close();
bw.flush();bw.close();
File old = new File("src/settings.java");
File ne = new File("src/settings2.java");
ne.deleteOnExit();
old.delete();
ne.renameTo(new File("src/settings.java"));
} catch (Exception e) {
System.err.println("Error reading file: "+e);
}
}
public static void build(){
File f = new File("dist/SPEKS.jar");
f.delete();
try{
Process proc = rt.exec("ant -f D:\\Documents\\NetBeansProjects\\SPEKS clean jar");
BufferedReader stdInput = new BufferedReader(new InputStreamReader(proc.getInputStream()));
BufferedReader stdError = new BufferedReader(new InputStreamReader(proc.getErrorStream()));
String s;
while ((s = stdInput.readLine()) != null)
System.out.println(s);
while ((s = stdError.readLine()) != null)
System.err.println(s);
}catch (Exception e){}
}
public static void dist(String name){
File build = new File("dist/SPEKs.jar");
build.renameTo(new File("bin/SPEKS["+version+"]_"+name+".jar"));
System.out.println(name+" done!");
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment