Skip to content

Commit

Permalink
ADD support for custom output folder in FileZipOperation (#12)
Browse files Browse the repository at this point in the history
* ADD support for custom output folder in FileZipOperation

* FIXED missing constructor parameters

Co-authored-by: Kevin Hagen <kevin.hagen@ue-germany.de>
  • Loading branch information
KevinHagen and KevinHagen committed May 15, 2020
1 parent 249feff commit a8c5a0c
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 6 deletions.
13 changes: 9 additions & 4 deletions src/main/java/sp/sd/fileoperations/FileZipOperation.java
Expand Up @@ -17,10 +17,12 @@
public class FileZipOperation extends FileOperation implements Serializable {

private final String folderPath;
private final String outputFolderPath;

@DataBoundConstructor
public FileZipOperation(String folderPath) {
public FileZipOperation(String folderPath, String outputFolderPath) {
this.folderPath = folderPath;
this.outputFolderPath = outputFolderPath;
}

public String getFolderPath() {
Expand All @@ -34,7 +36,7 @@ public boolean runOperation(Run<?, ?> run, FilePath buildWorkspace, Launcher lau
EnvVars envVars = run.getEnvironment(listener);
try {
FilePath ws = new FilePath(buildWorkspace, ".");
result = ws.act(new TargetFileCallable(listener, envVars.expand(folderPath), envVars));
result = ws.act(new TargetFileCallable(listener, envVars.expand(folderPath), envVars.expand(outputFolderPath), envVars));
} catch (Exception e) {
listener.fatalError(e.getMessage());
return false;
Expand All @@ -50,10 +52,12 @@ private static final class TargetFileCallable implements FilePath.FileCallable<B
private final TaskListener listener;
private final EnvVars environment;
private final String resolvedFolderPath;
private final String outputFolderPath;

public TargetFileCallable(TaskListener Listener, String ResolvedFolderPath, EnvVars environment) {
public TargetFileCallable(TaskListener Listener, String ResolvedFolderPath, String outputFolderPath, EnvVars environment) {
this.listener = Listener;
this.resolvedFolderPath = ResolvedFolderPath;
this.outputFolderPath = outputFolderPath;
this.environment = environment;
}

Expand All @@ -62,9 +66,10 @@ public Boolean invoke(File ws, VirtualChannel channel) {
boolean result;
try {
FilePath fpWS = new FilePath(ws);
FilePath fpWSOutput = new FilePath(fpWS, outputFolderPath);
FilePath fpTL = new FilePath(fpWS, resolvedFolderPath);
listener.getLogger().println("Creating Zip file of " + fpTL.getRemote());
fpTL.zip(new FilePath(fpWS, fpTL.getName() + ".zip"));
fpTL.zip(new FilePath(fpWSOutput, fpTL.getName() + ".zip"));
result = true;
} catch (RuntimeException e) {
listener.fatalError(e.getMessage());
Expand Down
Expand Up @@ -81,8 +81,8 @@ public void fileUnZipOperation(String filePath, String targetLocation) {
fileOperations.add(fileUnZipOperation);
}

public void fileZipOperation(String folderPath) {
FileZipOperation fileZipOperation = new FileZipOperation(folderPath);
public void fileZipOperation(String folderPath, String outputFolderPath) {
FileZipOperation fileZipOperation = new FileZipOperation(folderPath, outputFolderPath);
fileOperations.add(fileZipOperation);
}

Expand Down
Expand Up @@ -3,4 +3,7 @@
<f:entry title="Folder Path" field="folderPath">
<f:textbox field="folderPath" />
</f:entry>
<f:entry title="Output Folder Path" field="outputFolderPath">
<f:textbox field="outputFolderPath" />
</f:entry>
</j:jelly>

1 comment on commit a8c5a0c

@wreggyl
Copy link

@wreggyl wreggyl commented on a8c5a0c Jun 9, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this change changed the interface not in a backwards compatible way
worked in 1.9 but not in 1.10

  • FileZipOperation(myPath)

maybe it is better to to have a fallback if no outputFolderPath is specified that it chooses the current directory as fallback like it was the default in all previous releases?

  1. if only one parameter is given without name, treat it as folderPath and choose outPutFolderPath as current directory: FileZipOperation(myPath) => FileZipOperation(folderPath: myPath, outputFolderPath: ".")
  2. FileZipOperation(folderPath: myPath) => FileZipOperation(folderPath: myPath, outputFolderPath: ".")
  3. FileZipOperation(folderPath: myPath, outputFolderPath: myOutPutPath) => FileZipOperation(folderPath: myPath, outputFolderPath: myOutPutPath)

Please sign in to comment.