package com.perforce.trigger;
import java.io.BufferedReader;
import java.io.BufferedWriter;
import java.io.FileNotFoundException;
import java.io.FileReader;
import java.io.FileWriter;
import java.io.IOException;
import java.util.ArrayList;
import java.util.List;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
public class JavaTrigger {
/*The entry for the triggers table:
* Triggers:
* JavaTrigger form-out client "java -jar c:\p4_ws\smoon_ws\java_trigger\JavaTrigger.jar %formfile%"
*/
void print(String output) {
System.out.println(output);
}
public static void main(String[] args) throws IOException {
//JavaTrigger o = new JavaTrigger();
List<String> tmpArrayList = new ArrayList<String>();
String defaultOpPat = "^SubmitOptions:\\s+submitunchanged";
String newDefault = "SubmitOptions:\trevertunchanged";
Pattern opPat = Pattern.compile(defaultOpPat);
Matcher matcher = opPat.matcher("");
try {
BufferedReader in = new BufferedReader(new FileReader(args[0]));
String eachLine,newLine;
while((eachLine = in.readLine()) != null) {
matcher.reset(eachLine);
if(matcher.find()) {
//o.print(eachLine);
newLine = newDefault;
} else {
newLine = eachLine;
}
tmpArrayList.add(newLine);
}
in.close();
} catch (FileNotFoundException e) {
e.printStackTrace();
}
try {
BufferedWriter out = new BufferedWriter(new FileWriter(args[0]));
for(String s: tmpArrayList) {
out.write(s+"\n");
}
out.close();
} catch (IOException e) {
e.printStackTrace();
}
}
}