@@ -214,7 +214,7 @@ public void visit(TarArchiveEntry entry, byte[] content) throws IOException {
214
214
if (entry .getName ().equals ("./control" )) {
215
215
try {
216
216
ControlFile controlFile = new BinaryPackageControlFile (org .apache .commons .io .IOUtils .toString (new ByteArrayInputStream (content ), StandardCharsets .UTF_8 ));
217
- assertEquals ("the encoding is wrong" , controlFile . get ( "Maintainer" ), " ジョン Doe <john@doe.org>" );
217
+ assertEquals ("the encoding is wrong" , " ジョン Doe <john@doe.org>", controlFile . get ( "Maintainer" ) );
218
218
} catch (Exception e ) {
219
219
throw new IOException (e );
220
220
}
@@ -256,6 +256,77 @@ else if (entry.getName().equals("./text.txt")) {
256
256
});
257
257
}
258
258
259
+ @ Test
260
+ public void testCreationCustomToken () throws Exception {
261
+ DataProducer [] data = prepareData ();
262
+ File deb = File .createTempFile ("jdeb" , ".deb" );
263
+
264
+ File conffile = new File (getClass ().getResource ("deb/data.tgz" ).toURI ());
265
+
266
+ Map <String , String > map = new HashMap <>();
267
+ map .put ("name" , "actualName" );
268
+ map .put ("version" , "actualVersion" );
269
+ map .put ("maintainer" , "John Doe <john@doe.org>" );
270
+ MapVariableResolver variableResolver = new MapVariableResolver (map );
271
+
272
+ Data conffile1 = new Data ();
273
+ conffile1 .setType ("file" );
274
+ conffile1 .setSrc (conffile );
275
+ conffile1 .setDst ("/absolute/path/to/configuration" );
276
+ conffile1 .setConffile (true );
277
+ Data conffile2 = new Data ();
278
+ conffile2 .setType ("file" );
279
+ conffile2 .setSrc (conffile );
280
+ conffile2 .setConffile (true );
281
+
282
+ Mapper mapper = new Mapper ();
283
+ FieldUtils .writeField (mapper , "type" , "perm" , true );
284
+ FieldUtils .writeField (mapper , "prefix" , "/absolute/prefix" , true );
285
+ FieldUtils .writeField (conffile2 , "mapper" , mapper , true );
286
+
287
+ DebMaker maker =
288
+ new DebMaker (new NullConsole (), Arrays .asList (data ), Arrays .<DataProducer >asList (conffile1 , conffile2 ));
289
+ maker .setEncoding (StandardCharsets .UTF_8 );
290
+ maker .setControl (new File (getClass ().getResource ("deb/controlcustomtoken" ).toURI ()));
291
+ maker .setDeb (deb );
292
+ maker .setResolver (variableResolver );
293
+ maker .setOpenReplaceToken ("{[{" );
294
+ maker .setCloseReplaceToken ("}]}" );
295
+
296
+ BinaryPackageControlFile packageControlFile = maker .createDeb (Compression .GZIP );
297
+
298
+ assertTrue (packageControlFile .isValid ());
299
+
300
+ final Map <String , TarArchiveEntry > filesInDeb = new HashMap <>();
301
+
302
+ final Set <String > actualConffileContent = new HashSet <>();
303
+
304
+ ArchiveWalker .walkControl (deb , new ArchiveVisitor <TarArchiveEntry >() {
305
+ @ Override
306
+ public void visit (TarArchiveEntry entry , byte [] content ) throws IOException {
307
+ if (entry .getName ().equals ("./control" )) {
308
+ try {
309
+ ControlFile controlFile = new BinaryPackageControlFile (org .apache .commons .io .IOUtils .toString (new ByteArrayInputStream (content ), StandardCharsets .UTF_8 ));
310
+ assertEquals ("variable substitution failed" , "John Doe <john@doe.org>" , controlFile .get ("Maintainer" ));
311
+ } catch (Exception e ) {
312
+ throw new IOException (e );
313
+ }
314
+ }
315
+ else if (entry .getName ().equals ("./postinst" ) || entry .getName ().equals ("./prerm" )) {
316
+ try {
317
+ for (String line : org .apache .commons .io .IOUtils .readLines (new ByteArrayInputStream (content ), StandardCharsets .UTF_8 )) {
318
+ if (line .startsWith ("# P" )) {
319
+ assertTrue ("variable substitution failed" , line .endsWith ("actualName actualVersion" ));
320
+ }
321
+ }
322
+ } catch (Exception e ) {
323
+ throw new IOException (e );
324
+ }
325
+ }
326
+ }
327
+ });
328
+ }
329
+
259
330
@ Test
260
331
public void testControlFilesPermissions () throws Exception {
261
332
File deb = new File ("target/test-classes/test-control.deb" );
0 commit comments