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

Make changes optional #801

Merged
merged 3 commits into from
Jan 8, 2025
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
25 changes: 13 additions & 12 deletions docs/ant.md
Original file line number Diff line number Diff line change
@@ -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
Expand Down
1 change: 1 addition & 0 deletions docs/maven.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
42 changes: 28 additions & 14 deletions src/main/java/org/vafer/jdeb/DebMaker.java
Original file line number Diff line number Diff line change
Expand Up @@ -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";

Expand Down Expand Up @@ -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;
}
Expand Down Expand Up @@ -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.");
}
}
}

Expand Down Expand Up @@ -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 {
Expand All @@ -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()) {
Expand Down
4 changes: 4 additions & 0 deletions src/main/java/org/vafer/jdeb/ant/DebAntTask.java
Original file line number Diff line number Diff line change
Expand Up @@ -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";

Expand Down Expand Up @@ -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);
Expand Down
9 changes: 8 additions & 1 deletion src/main/java/org/vafer/jdeb/maven/DebMojo.java
Original file line number Diff line number Diff line change
Expand Up @@ -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)
*/
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -638,7 +645,7 @@ public void produce( final DataConsumer receiver ) {
* and global settings.
*/
private void initializeSignProperties() {
if (!signPackage && !signChanges) {
if (!signPackage && !(signChanges && changesEnabled)) {
return;
}

Expand Down
43 changes: 43 additions & 0 deletions src/test/java/org/vafer/jdeb/DebMakerTestCase.java
Original file line number Diff line number Diff line change
Expand Up @@ -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());
Expand Down
Loading