From 5152ce927699e6c9ebf7285232076dca8616a1f1 Mon Sep 17 00:00:00 2001 From: Rob Spieldenner Date: Thu, 7 May 2015 14:37:54 -0700 Subject: [PATCH] Omit Depends: from control file if not set. Fixes #208 --- src/main/java/org/vafer/jdeb/DebMaker.java | 7 ++--- .../java/org/vafer/jdeb/DebMakerTestCase.java | 31 +++++++++++++++++++ .../jdeb/deb/controlwithoutdepends/control | 12 +++++++ 3 files changed, 45 insertions(+), 5 deletions(-) create mode 100644 src/test/resources/org/vafer/jdeb/deb/controlwithoutdepends/control diff --git a/src/main/java/org/vafer/jdeb/DebMaker.java b/src/main/java/org/vafer/jdeb/DebMaker.java index bc71e6560..bb12180d5 100644 --- a/src/main/java/org/vafer/jdeb/DebMaker.java +++ b/src/main/java/org/vafer/jdeb/DebMaker.java @@ -76,8 +76,8 @@ public class DebMaker { /** The section of the package. Default value if not specified in the control file */ private String section = "java"; - /** The dependencies of the package. Default value if not specified in the control file */ - private String depends = "default-jre | java6-runtime"; + /** The dependencies of the package. */ + private String depends; /** The description of the package. Default value if not specified in the control file */ private String description; @@ -444,9 +444,6 @@ public BinaryPackageControlFile createSignedDeb(Compression compression, final P if (packageControlFile.get("Package") == null) { packageControlFile.set("Package", packageName); } - if (packageControlFile.get("Depends") == null) { - packageControlFile.set("Depends", depends); - } if (packageControlFile.get("Section") == null) { packageControlFile.set("Section", section); } diff --git a/src/test/java/org/vafer/jdeb/DebMakerTestCase.java b/src/test/java/org/vafer/jdeb/DebMakerTestCase.java index d2a197736..81ff73b46 100644 --- a/src/test/java/org/vafer/jdeb/DebMakerTestCase.java +++ b/src/test/java/org/vafer/jdeb/DebMakerTestCase.java @@ -151,9 +151,40 @@ public void visit(TarArchiveEntry entry, byte[] content) throws IOException { assertFalse("Variables not replaced in the control file " + entry.getName(), body.contains("[[name]] [[version]]")); assertTrue("Expected variables not found in the control file " + entry.getName(), body.contains("jdeb 1.0")); } + if (entry.getName().contains("control")) { + String control = new String(content, "ISO-8859-1"); + assertTrue("Depends missing" + entry.getName(), control.contains("Depends: some-package")); + } } }); assertTrue("Control files not found in the package", found); } + + public void testDependsIsOmittedWhenEmpty() throws Exception { + File deb = new File("target/test-classes/test-control.deb"); + if (deb.exists() && !deb.delete()) { + fail("Couldn't delete " + deb); + } + + Collection producers = Arrays.asList(new DataProducer[] {new EmptyDataProducer()}); + Collection conffileProducers = Arrays.asList(new DataProducer[] {new EmptyDataProducer()}); + DebMaker maker = new DebMaker(new NullConsole(), producers, conffileProducers); + maker.setDeb(deb); + maker.setControl(new File("target/test-classes/org/vafer/jdeb/deb/controlwithoutdepends")); + + maker.createDeb(Compression.NONE); + + // now reopen the package and check the control files + assertTrue("package not build", deb.exists()); + + boolean found = ArchiveWalker.walkControl(deb, new ArchiveVisitor() { + public void visit(TarArchiveEntry entry, byte[] content) throws IOException { + if (entry.getName().contains("control")) { + String control = new String(content, "ISO-8859-1"); + assertFalse("Depends should be omitted" + entry.getName(), control.contains("Depends:")); + } + } + }); + } } diff --git a/src/test/resources/org/vafer/jdeb/deb/controlwithoutdepends/control b/src/test/resources/org/vafer/jdeb/deb/controlwithoutdepends/control new file mode 100644 index 000000000..f7d6a3060 --- /dev/null +++ b/src/test/resources/org/vafer/jdeb/deb/controlwithoutdepends/control @@ -0,0 +1,12 @@ +Package: controlwithoutdepends +Version: 1.0.1 +Section: misc +Priority: optional +Architecture: i386 +Maintainer: John Doe +Distribution: development +Description: revision @REVISION@, test package + This is a sample package control file. + . + Use for testing purposes only. +XB-UserDefinedField: This is a user defined field.