diff --git a/docs/ant.md b/docs/ant.md index 3bb8ad499..a0e81cdf5 100644 --- a/docs/ant.md +++ b/docs/ant.md @@ -1,17 +1,18 @@ # How to use jdeb with Ant -Attribute | Description | Required -------------- | ---------------------------------------------------------------------------- | -------------------------- -destfile | The debian package to be generated | Yes -control | The directory containing the control files | Yes -compression | Compression method for the data file (`gzip`, `bzip2`, `xz` or `none`) | No; defaults to `gzip` -verbose | Print detailed info during the package generation | No; defaults to `false` -keyring | The file containing the PGP keys | No -key | The name of the key to be used in the keyring | No -passphrase | The passphrase to use the key | No -changesIn | The changes to add | No -changesOut | The changes file generated | No -changesSave | The merged changes file | No +Attribute | Description | Required +-------------- | ---------------------------------------------------------------------------- | -------------------------- +destfile | The debian package to be generated | Yes +control | The directory containing the control files | Yes +compression | Compression method for the data file (`gzip`, `bzip2`, `xz` or `none`) | No; defaults to `gzip` +verbose | Print detailed info during the package generation | No; defaults to `false` +keyring | The file containing the PGP keys | No +key | The name of the key to be used in the keyring | No +passphrase | The passphrase to use the key | No +changesIn | The changes to add | No +changesOut | The changes file generated | No +changesSave | The merged changes file | No +changesEnabled | Enable the creation of the changes file | No; defaults to `true` The jdeb Ant task can package up a directory as Debian package. You have to provide the control files defining meta information about the package (except diff --git a/docs/maven.md b/docs/maven.md index 3d35e92ba..8ef5351b2 100644 --- a/docs/maven.md +++ b/docs/maven.md @@ -125,6 +125,7 @@ ignoreBrokenLinks| Indicates if broken symlinks should be ignored or cause build changesIn | The changes to add | No changesOut | The changes file generated | No changesSave | (NYI) The merged changes file | No +changesEnabled | Enable the creation of the changes file | No; defaults to `true` compression | (NYI) Compression method for the data file (`gzip`, `bzip2`, `xz` or `none`) | No; defaults to `gzip` digest | Digest to use when building the deb | No; defaults to `SHA256` signPackage | If the debian package should be signed | No diff --git a/src/main/java/org/vafer/jdeb/DebMaker.java b/src/main/java/org/vafer/jdeb/DebMaker.java index 934f4e65a..a21908090 100644 --- a/src/main/java/org/vafer/jdeb/DebMaker.java +++ b/src/main/java/org/vafer/jdeb/DebMaker.java @@ -107,6 +107,9 @@ public class DebMaker { /** The file where to write the changes of the changes input to */ private File changesSave; + /** Enable the creation of the changes file */ + private boolean changesEnabled; + /** The compression method used for the data file (none, gzip, bzip2 or xz) */ private String compression = "gzip"; @@ -197,6 +200,10 @@ public void setChangesSave(File changes) { this.changesSave = changes; } + public void setChangesEnabled(boolean changesEnabled) { + this.changesEnabled = changesEnabled; + } + public void setSignPackage(boolean signPackage) { this.signPackage = signPackage; } @@ -278,23 +285,25 @@ public void validate() throws PackagingException { throw new PackagingException("The 'control' attribute doesn't point to a directory. " + control); } - if (changesIn != null) { + if (changesEnabled) { + if (changesIn != null) { - if (changesIn.exists() && (!changesIn.isFile() || !changesIn.canRead())) { - throw new PackagingException("The 'changesIn' setting needs to point to a readable file. " + changesIn + " was not found/readable."); - } + if (changesIn.exists() && (!changesIn.isFile() || !changesIn.canRead())) { + throw new PackagingException("The 'changesIn' setting needs to point to a readable file. " + changesIn + " was not found/readable."); + } - if (changesOut != null && !isWritableFile(changesOut)) { - throw new PackagingException("Cannot write the output for 'changesOut' to " + changesOut); - } + if (changesOut != null && !isWritableFile(changesOut)) { + throw new PackagingException("Cannot write the output for 'changesOut' to " + changesOut); + } - if (changesSave != null && !isWritableFile(changesSave)) { - throw new PackagingException("Cannot write the output for 'changesSave' to " + changesSave); - } + if (changesSave != null && !isWritableFile(changesSave)) { + throw new PackagingException("Cannot write the output for 'changesSave' to " + changesSave); + } - } else { - if (changesOut != null || changesSave != null) { - throw new PackagingException("The 'changesOut' or 'changesSave' settings may only be used when there is a 'changesIn' specified."); + } else { + if (changesOut != null || changesSave != null) { + throw new PackagingException("The 'changesOut' or 'changesSave' settings may only be used when there is a 'changesIn' specified."); + } } } @@ -348,7 +357,10 @@ public void makeDeb() throws PackagingException { throw new PackagingException("Failed to create debian package " + deb, e); } - makeChangesFiles(packageControlFile); + if(changesEnabled) + { + makeChangesFiles(packageControlFile); + } } private void makeChangesFiles(final BinaryPackageControlFile packageControlFile) throws PackagingException { @@ -362,6 +374,8 @@ private void makeChangesFiles(final BinaryPackageControlFile packageControlFile) try { console.info("Creating changes file: " + changesOut); + changesOut.getParentFile().mkdirs(); + out = new FileOutputStream(changesOut); if (changesIn != null && changesIn.exists()) { diff --git a/src/main/java/org/vafer/jdeb/ant/DebAntTask.java b/src/main/java/org/vafer/jdeb/ant/DebAntTask.java index 696ef4b3a..968c9257f 100644 --- a/src/main/java/org/vafer/jdeb/ant/DebAntTask.java +++ b/src/main/java/org/vafer/jdeb/ant/DebAntTask.java @@ -62,6 +62,9 @@ public class DebAntTask extends MatchingTask { /** The file where to write the changes of the changes input to */ private File changesSave; + /** Enable the creation of the changes file */ + private boolean changesEnabled = true; + /** The compression method used for the data file (none, gzip, bzip2 or xz) */ private String compression = "gzip"; @@ -170,6 +173,7 @@ public void execute() { debMaker.setChangesIn(changesIn); debMaker.setChangesOut(changesOut); debMaker.setChangesSave(changesSave); + debMaker.setChangesEnabled(changesEnabled); debMaker.setKeyring(keyring); debMaker.setKey(key); debMaker.setPassphrase(passphrase); diff --git a/src/main/java/org/vafer/jdeb/maven/DebMojo.java b/src/main/java/org/vafer/jdeb/maven/DebMojo.java index ce3743258..b0cbb9adf 100644 --- a/src/main/java/org/vafer/jdeb/maven/DebMojo.java +++ b/src/main/java/org/vafer/jdeb/maven/DebMojo.java @@ -111,6 +111,12 @@ public class DebMojo extends AbstractMojo { @Parameter(defaultValue = "[[baseDir]]/CHANGES.txt") private String changesSave; + /** + * Enable the creation of the changes file. + */ + @Parameter(defaultValue = "true") + private boolean changesEnabled; + /** * The compression method used for the data file (none, gzip, bzip2 or xz) */ @@ -587,6 +593,7 @@ public void produce( final DataConsumer receiver ) { debMaker.setChangesIn(changesInFile); debMaker.setChangesOut(changesOutFile); debMaker.setChangesSave(changesSaveFile); + debMaker.setChangesEnabled(changesEnabled); debMaker.setCompression(compression); debMaker.setKeyring(keyringFile); debMaker.setKey(key); @@ -638,7 +645,7 @@ public void produce( final DataConsumer receiver ) { * and global settings. */ private void initializeSignProperties() { - if (!signPackage && !signChanges) { + if (!signPackage && !(signChanges && changesEnabled)) { return; } diff --git a/src/test/java/org/vafer/jdeb/DebMakerTestCase.java b/src/test/java/org/vafer/jdeb/DebMakerTestCase.java index 85027f7b7..3846ed782 100644 --- a/src/test/java/org/vafer/jdeb/DebMakerTestCase.java +++ b/src/test/java/org/vafer/jdeb/DebMakerTestCase.java @@ -305,6 +305,49 @@ public void testErrorPropagation() throws Exception { } } + @Test + public void testChangesValidation() throws Exception { + File deb = File.createTempFile("jdeb", ".deb"); + File changesSave = File.createTempFile("changesSave", ".txt"); + File directory = new File(getClass().getResource("deb/data").toURI()); + + DebMaker maker = new DebMaker(new NullConsole(), List.of(new UseNullAsInputStream()), null); + assertThrows(PackagingException.class, maker::validate); + + maker.setControl(new File(getClass().getResource("deb/control").toURI())); + assertThrows(PackagingException.class, maker::validate); + + maker.setDeb(deb); + maker.validate(); + + maker.setChangesEnabled(true); + maker.validate(); + + maker.setChangesIn(directory); + assertThrows(PackagingException.class, maker::validate); + + maker.setChangesIn(new File(getClass().getResource("changes/changes.txt").toURI())); + maker.validate(); + + maker.setChangesSave(directory); + assertThrows(PackagingException.class, maker::validate); + + maker.setChangesSave(null); + maker.setChangesOut(directory); + assertThrows(PackagingException.class, maker::validate); + + maker.setChangesOut(null); + maker.setChangesSave(changesSave); + maker.validate(); + + maker.setChangesIn(null); + assertThrows(PackagingException.class, maker::validate); + + maker.setChangesEnabled(false); + maker.setCompression(null); + assertThrows(PackagingException.class, maker::validate); + } + private DataProducer[] prepareData() throws URISyntaxException { File archive1 = new File(getClass().getResource("deb/data.tgz").toURI()); File archive2 = new File(getClass().getResource("deb/data.tar.bz2").toURI());