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

ADD support for custom output folder in FileZipOperation #12

Merged
merged 2 commits into from May 15, 2020
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.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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>