2 package org
.de
.metux
.util
;
8 public class Decompressor
10 public boolean decompress(String archive
, String target
)
12 return decompress(archive
,target
,null);
15 public boolean decompress(String archive
, String target
, String format
)
17 if ((format
==null) || (format
.length()==0))
19 /* try to detect format */
24 String buildroot
= config
.cf_get_str_n("@@buildroot");
25 String archiver
= config
.cf_get_str("archiver");
26 if (archiver
.length()==0)
28 notice("no archiver given ... trying to detect" );
29 if (source
.endsWith(".tar.gz") ||
30 source
.endsWith(".tgz"))
31 config
.cf_set("archiver", archiver
= "tar.gz");
32 else if (source
.endsWith(".tar.bz2") ||
33 source
.endsWith(".tbz") ||
34 source
.endsWith(".tbz2"))
35 config
.cf_set("archiver", archiver
= "tar.bz");
37 return error("cannot detect proper archiver for \""+source
+"\"");
40 if (!mkdir(buildroot
))
43 if (archiver
.equals("tar.bz2"))
45 notice("decompressing tar.bz2: "+source
+" ..." );
46 return exec ( "cd "+buildroot
+" && tar -xjf "+source
);
49 if (archiver
.equals("tar.gz"))
51 notice("decompressing tar.gz: "+source
+" ..." );
52 return exec ( "cd "+buildroot
+" && tar -xzf "+source
);
55 return error("unsupported archiver: "+archiver
);
58 /* pre-execute something *before* we start decompressing
59 ie. for preparing patch sets */
64 String preexec
=config
.cf_get_str_n("prebuild-patch-preexec");
68 notice("Calling preexec: "+preexec
);
70 return error("preexec failed");
77 String buildroot
= config
.cf_get_str_n("@@buildroot");
78 notice("cleaning up "+buildroot
);
79 rm
.remove_recursive(buildroot
);
84 boolean paranoia_check()
86 /* check for proper buildroot variable ... probably not really necessary */
87 String buildroot
= config
.cf_get_str("@@buildroot");
90 buildroot
= new File(buildroot
).getCanonicalPath();
94 return error("exception: "+e
);
97 if (buildroot
.length()<5)
98 return error("corrupt @@buildroot variable - internal problem ?");
100 /* -- get the source file name / uri -- */
101 String source
=config
.cf_get_str_n("source-file");
103 return error("missing package source option in configuration");
110 /* now run decompression */
111 String srclist
[] = config
.cf_get_list("source-file");
112 if (srclist
.length
==0)
113 return error("missing package source option in configuration");
115 for (int x
=0; x
<srclist
.length
; x
++)
116 if (!decompress_archive(srclist
[x
]))
122 boolean prepare_sourcetree()
125 ( /* hope we've got shortcut evaluation! */
135 /* right after decompression, we need to know our actual srcroot */
136 boolean lookup_srcdir()
138 String buildroot
= config
.cf_get_str_n("@@buildroot");
140 return error("lookup_srcdir: Internal error: @@buildroot not defined");
142 File handle
= new File(buildroot
);
143 String sublist
[] = handle
.list();
146 return error("could not get directory listing!");
148 if (sublist
.length
==0)
149 return error("no srcdir found. seems like decompression failed");
151 if (sublist
.length
>1)
152 return error("more than one srcdir found. looks like trouble");
154 notice("srcdir is: "+sublist
[0]);
156 String srcroot
= buildroot
+"/"+sublist
[0];
157 notice("srcroot is: "+srcroot
);
159 config
.cf_set("@@srcroot", srcroot
);
164 boolean apply_patches()
166 String patches
[] = config
.cf_get_list("prebuild-patch-file");
167 String patch_opts
= config
.cf_get_str("prebuild-patch-opts");
168 String srcroot
= config
.cf_get_str_n("@@srcroot");
170 if (patches
.length
==0)
173 for (int x
=0; x
<patches
.length
; x
++)
175 if (!(new File(patches
[x
]).exists()))
176 return error("could not load patch file: "+patches
[x
]);
178 notice("applying patch: "+patches
[x
]+"("+patch_opts
+")" );
179 if (!exec("cd "+srcroot
+";pwd;patch "+patch_opts
+"<"+patches
[x
]))