Improve GZip task
@@ -20,6 +20,13 @@ public class GZip extends CompressorTask<GZip.GZipWorkParameters> {
@Optional
private final Property<Integer> compressionLevel = getProject().getObjects().property(Integer.class);
+ @Input
+ @Optional
+ private final Property<String> comment = getProject().getObjects().property(String.class);
+
+ @Input
+ private final Property<Boolean> addFilename = getProject().getObjects().property(Boolean.class).convention(false);
+
@Inject
public GZip(WorkerExecutor workerExecutor) {
super(workerExecutor);
@@ -34,10 +41,16 @@ public class GZip extends CompressorTask<GZip.GZipWorkParameters> {
@Override
protected void fillParameters(GZipWorkParameters parameters) {
parameters.getCompressionLevel().set(getCompressionLevel());
+ parameters.getComment().set(getComment());
+ parameters.getAddFilename().set(getAddFilename());
}
public interface GZipWorkParameters extends CompressorWorkParameters {
Property<Integer> getCompressionLevel();
+
+ Property<String> getComment();
+
+ Property<Boolean> getAddFilename();
}
public static abstract class GZipWorkAction extends CompressorWorkAction<GzipCompressorOutputStream, GZipWorkParameters> {
@@ -45,10 +58,19 @@ public class GZip extends CompressorTask<GZip.GZipWorkParameters> {
@Override
protected GzipCompressorOutputStream createOutputStream(BufferedOutputStream outputStream) throws IOException {
GzipParameters parameters = new GzipParameters();
+
if (getParameters().getCompressionLevel().isPresent()) {
parameters.setCompressionLevel(getParameters().getCompressionLevel().get());
}
+
+ if (getParameters().getComment().isPresent()) {
+ parameters.setComment(getParameters().getComment().get());
+ }
+
+ if (getParameters().getAddFilename().getOrElse(false)) {
parameters.setFilename(getParameters().getSourceFile().getAsFile().get().getName());
+ }
+
return new GzipCompressorOutputStream(outputStream, parameters);
}
}
