gitweb on Svarog

projekti pod git sistemom za održavanje verzija -- projects under the git version control system
moved to svetovid folder
[pub/donny/ant-tasks.git] / svetovid / next.java
1 package svetovid;
3 import org.apache.tools.ant.BuildException;
4 import org.apache.tools.ant.Task;
6 import java.io.*;
8 /**
9 * Na osnovu spiska i trenutnog studenta nadji sledeceg.
10 * cita se iz current.txt, a pise u taj i current.properties
11 * Ovo se onda korisiti za kopiranje fajlova u buildu
12 * (bio je task init)
13 */
14 public class next extends Task {
15 private String student, group;
16 private String current;
17 private String file="studenti.txt";
18 private String separator="\t";
19 private String currentFilename="current.txt",
20 currentProperties="current.properties";
23 private void setCurrent(String c) throws Exception{
24 current = c;
25 if (current != null){
26 String[] s = current.split(separator);
27 if (s.length<2)
28 throw new Exception("problem setting current student name - can't split group and name");
29 student = s[1];
30 group = s[0];
31 } else {
32 student = null;
33 group = null;
34 }
35 }
37 private void loadCurrent(){
38 try{
39 File f = new File(currentFilename);
40 if (f.exists()){
41 BufferedReader r = new BufferedReader(
42 new InputStreamReader(
43 new FileInputStream(f)));
44 setCurrent(r.readLine());
45 r.close();
46 } else
47 setCurrent(null);
48 }catch (Exception ex) {
49 throw new BuildException(ex);
50 }
51 }
53 private void saveCurrent(){
54 try{
55 PrintWriter w = new PrintWriter(new FileWriter(currentFilename));
56 w.println(current);
57 w.close();
58 }catch (Exception ex) {
59 throw new BuildException(ex);
60 }
61 //now the properties file
62 try{
63 PrintWriter w = new PrintWriter(new FileWriter(currentProperties));
64 w.println("student.group="+group);
65 w.println("student.current="+student);
66 w.close();
67 }catch (Exception ex) {
68 throw new BuildException(ex);
69 }
70 }
72 // The method executing the task
73 public void execute() throws BuildException {
74 loadCurrent();
75 try{
76 BufferedReader r = new BufferedReader(new InputStreamReader(new FileInputStream(file)));
77 String s = r.readLine();
78 if (current != null) {
79 while (s!=null && s.compareTo(current)!=0)
80 s= r.readLine();
81 setCurrent(r.readLine());
82 } else {
83 setCurrent(s);
84 }
85 r.close();
86 }catch (Exception ex) {
87 throw new BuildException(ex);
88 }
89 saveCurrent();
90 }
92 public void setSeparator(String msg) {
93 this.separator = msg;
94 }
96 public void setFile(String msg) {
97 this.file = msg;
98 }
100 public void setCurrentFilename(String msg) {
101 this.currentFilename = msg;
103 public void setCurrentProperties(String msg) {
104 this.currentProperties = msg;
Svarog.pmf.uns.ac.rs/gitweb maintanance Doni Pracner