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

Added File argument alternatives with Path and String. #1

Merged
merged 2 commits into from
Aug 29, 2024
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
6 changes: 3 additions & 3 deletions src/bld/java/rife/bld/extension/ArchiveBuild.java
Original file line number Diff line number Diff line change
Expand Up @@ -29,10 +29,10 @@ public ArchiveBuild() {
repositories = List.of(MAVEN_CENTRAL, RIFE2_RELEASES);
scope(compile)
.include(dependency("com.uwyn.rife2", "bld", version(2,0,1)))
.include(dependency("org.apache.commons", "commons-compress", version(1,26,2)));
.include(dependency("org.apache.commons", "commons-compress", version(1,27,1)));
scope(test)
.include(dependency("org.junit.jupiter", "junit-jupiter", version(5,10,3)))
.include(dependency("org.junit.platform", "junit-platform-console-standalone", version(1,10,3)));
.include(dependency("org.junit.jupiter", "junit-jupiter", version(5,11,0)))
.include(dependency("org.junit.platform", "junit-platform-console-standalone", version(1,11,0)));

javadocOperation()
.javadocOptions()
Expand Down
90 changes: 85 additions & 5 deletions src/main/java/rife/bld/extension/ZipOperation.java
Original file line number Diff line number Diff line change
Expand Up @@ -7,15 +7,20 @@
import org.apache.commons.compress.archivers.zip.UnixStat;
import org.apache.commons.compress.archivers.zip.ZipArchiveEntry;
import org.apache.commons.compress.archivers.zip.ZipArchiveOutputStream;
import org.apache.commons.compress.utils.IOUtils;
import org.apache.commons.io.IOUtils;
import rife.bld.NamedFile;
import rife.bld.operations.AbstractOperation;
import rife.tools.FileUtils;
import rife.tools.StringUtils;

import java.io.*;
import java.io.File;
import java.io.IOException;
import java.io.InputStream;
import java.nio.file.Files;
import java.util.*;
import java.nio.file.Path;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import java.util.regex.Pattern;

/**
Expand Down Expand Up @@ -135,11 +140,35 @@ protected void executeAddFileToZip(ZipArchiveOutputStream zip, NamedFile file)
*
* @param directories source directories
* @return this operation instance
* @see #sourceDirectories(List)
* @since 1.0
*/
public ZipOperation sourceDirectories(File... directories) {
sourceDirectories_.addAll(List.of(directories));
return this;
return sourceDirectories(List.of(directories));
}

/**
* Provides source directories that will be used for the zip archive creation.
*
* @param directories source directories
* @return this operation instance
* @see #sourceDirectoriesPaths(List)
* @since 1.0
*/
public ZipOperation sourceDirectories(Path... directories) {
return sourceDirectoriesPaths(List.of(directories));
}

/**
* Provides source directories that will be used for the zip archive creation.
*
* @param directories source directories
* @return this operation instance
* @see #sourceDirectoriesStrings(List)
* @since 1.0
*/
public ZipOperation sourceDirectories(String... directories) {
return sourceDirectoriesStrings(List.of(directories));
}

/**
Expand All @@ -149,13 +178,42 @@ public ZipOperation sourceDirectories(File... directories) {
*
* @param directories a list of source directories
* @return this operation instance
* @see #sourceDirectories(File...)
* @since 1.0
*/
public ZipOperation sourceDirectories(List<File> directories) {
sourceDirectories_.addAll(directories);
return this;
}

/**
* Provides a list of source directories that will be used for the zip archive creation.
* <p>
* A copy will be created to allow this list to be independently modifiable.
*
* @param directories a list of source directories
* @return this operation instance
* @see #sourceDirectories(Path...)
* @since 1.0
*/
public ZipOperation sourceDirectoriesPaths(List<Path> directories) {
return sourceDirectories(directories.stream().map(Path::toFile).toList());
}

/**
* Provides a list of source directories that will be used for the zip archive creation.
* <p>
* A copy will be created to allow this list to be independently modifiable.
*
* @param directories a list of source directories
* @return this operation instance
* @see #sourceDirectories(String...)
* @since 1.0
*/
public ZipOperation sourceDirectoriesStrings(List<String> directories) {
return sourceDirectories(directories.stream().map(File::new).toList());
}

/**
* Provides source files that will be used for the zip archive creation.
*
Expand Down Expand Up @@ -194,6 +252,28 @@ public ZipOperation destinationDirectory(File directory) {
return this;
}

/**
* Provides the destination directory in which the zip archive will be created.
*
* @param directory the zip destination directory
* @return this operation instance
* @since 1.0
*/
public ZipOperation destinationDirectory(Path directory) {
return destinationDirectory(directory.toFile());
}

/**
* Provides the destination directory in which the zip archive will be created.
*
* @param directory the zip destination directory
* @return this operation instance
* @since 1.0
*/
public ZipOperation destinationDirectory(String directory) {
return destinationDirectory(new File(directory));
}

/**
* Provides the destination file name that will be used for the zip archive creation.
*
Expand Down
Loading