1 package net.sf.jpkgmk;
2
3 import java.io.BufferedWriter;
4 import java.io.File;
5 import java.io.FileWriter;
6 import java.io.IOException;
7 import java.io.InputStream;
8 import java.io.Writer;
9 import java.util.Iterator;
10 import java.util.List;
11
12 import net.sf.jpkgmk.RequestCreator.RequestEntry;
13 import net.sf.jpkgmk.RequestCreator.RequestEntryParser;
14 import net.sf.jpkgmk.RequestCreator.RequestEntryType;
15 import net.sf.jpkgmk.util.StreamUtil;
16
17
18
19
20
21
22
23 public class PostinstallCreator
24 {
25 private List<RequestEntry> requestEntryList;
26
27
28 public PostinstallCreator(InputStream requestEntries) throws IOException
29 {
30 List<RequestEntry> entries = new RequestEntryParser().parse(requestEntries);
31 this.requestEntryList.addAll(entries);
32 }
33
34 public void create(File target) throws IOException
35 {
36 String request = create();
37 BufferedWriter writer = new BufferedWriter(new FileWriter(target));
38 try {
39 writer.write(request);
40 }
41 finally {
42 StreamUtil.tryCloseStream(writer);
43 }
44 }
45
46 public void create(Writer target) throws IOException
47 {
48 String request = create();
49 target.write(request);
50 }
51
52 private String create()
53 {
54 StringBuffer sb = new StringBuffer();
55 sb.append("#!/bin/sh").append(PkgInfo.LINE_SEPARATOR);
56 sb.append("# $Id: PostinstallCreator.java 2 2008-08-20 19:14:19Z gommma $").append(PkgInfo.LINE_SEPARATOR);
57
58
59 for(Iterator<RequestEntry> iter=requestEntryList.iterator(); iter.hasNext(); ) {
60 RequestEntry entry = iter.next();
61 if(!entry.getType().equals(RequestEntryType.PASSWORD)) {
62 sb.append("111 -u actual $PKG/$VERSION " + entry.getVarName111() + " \"$" + entry.getVarName() + "\" || exit 1");
63 }
64
65 sb.append(entry.getEntry());
66 }
67 return sb.toString();
68 }
69
70 }