Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

If DebMaker.depends is set, then set it in the control file #288

Merged
merged 2 commits into from
May 29, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions src/main/java/org/vafer/jdeb/DebMaker.java
Original file line number Diff line number Diff line change
Expand Up @@ -503,6 +503,12 @@ public BinaryPackageControlFile createSignedDeb(Compression compression, final P
if (packageControlFile.get("Description") == null) {
packageControlFile.set("Description", description);
}
if (packageControlFile.get("Depends") == null) {
// Only add a depends entry to the control file if the field in this object has actually been set
if (depends != null && depends.length() > 0) {
packageControlFile.set("Depends", depends);
}
}
if (packageControlFile.get("Homepage") == null) {
packageControlFile.set("Homepage", homepage);
}
Expand Down
41 changes: 40 additions & 1 deletion src/test/java/org/vafer/jdeb/DebMakerTestCase.java
Original file line number Diff line number Diff line change
Expand Up @@ -188,9 +188,48 @@ public void testDependsIsOmittedWhenEmpty() throws Exception {
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:"));
assertFalse("Depends should be omitted in the control file " + entry.getName(), control.contains("Depends:"));
}
}
});

assertTrue("Control files not found in the package", found);
}

@Test
public void testDependsIsIncludedIfSet() throws Exception {
File deb = new File("target/test-classes/test-control.deb");
if (deb.exists() && !deb.delete()) {
fail("Couldn't delete " + deb);
}
// Reuse the no-depends-set controlwithoutdepends file then programatically add a depends

Collection<DataProducer> producers = Arrays.asList(new DataProducer[] {new EmptyDataProducer()});
Collection<DataProducer> 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"));

final String dependsString = "important-dependency ( > 5)";
maker.setDepends(dependsString);

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<TarArchiveEntry>() {
public void visit(TarArchiveEntry entry, byte[] content) throws IOException {
if (entry.getName().contains("control")) {
String control = new String(content, "ISO-8859-1");

assertTrue("Depends should be present in the control file " + entry.getName(), control.contains("Depends:"));
assertTrue("The control file " + entry.getName() + " should specify intended dependency '" + dependsString + "'",
control.contains("Depends: " + dependsString));
}
}
});

assertTrue("Control files not found in the package", found);
}
}