Skip to content

Commit 25dc707

Browse files
committed
most of the requested changes
1 parent 9701aad commit 25dc707

File tree

2 files changed

+19
-23
lines changed

2 files changed

+19
-23
lines changed

src/main/java/me/itzg/helpers/sync/MulitCopyCommand.java

Lines changed: 7 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,7 @@ public class MulitCopyCommand implements Callable<Integer> {
7373
@Option(names = "--delimiter", defaultValue = "@",
7474
description = "When using per-file destinations, which symbol should be used to delimit destination<delimiter>source"
7575
)
76-
String stringDelimiter;
76+
String destinationDelimiter;
7777

7878
@Parameters(split = SPLIT_COMMA_NL, splitSynopsisLabel = SPLIT_SYNOPSIS_COMMA_NL, arity = "1..*",
7979
paramLabel = "SRC",
@@ -88,7 +88,7 @@ public Integer call() throws Exception {
8888
Flux.fromIterable(sources)
8989
.map(String::trim)
9090
.filter(s -> !s.isEmpty())
91-
.flatMap(source -> processSource(source, fileIsListingOption, null))
91+
.flatMap(source -> processSource(source, fileIsListingOption, dest))
9292
.collectList()
9393
.flatMap(this::cleanupAndSaveManifest)
9494
.block();
@@ -118,16 +118,12 @@ private Mono<?> cleanupAndSaveManifest(List<Path> paths) {
118118

119119
@SuppressWarnings("BlockingMethodInNonBlockingContext") // idk if that is a good idea
120120
private Publisher<Path> processSource(String source, boolean fileIsListing, Path parentDestination) {
121-
Path destination = dest;
121+
Path destination = parentDestination;
122122

123-
if (parentDestination != null) {
124-
destination = parentDestination;
125-
}
126-
127-
if (source.contains(stringDelimiter)) {
128-
String[] split = source.split(stringDelimiter);
129-
destination = destination.resolve(Paths.get(split[0]));
130-
source = split[1];
123+
final int delimiterPos = source.indexOf(destinationDelimiter);
124+
if (delimiterPos > 0) {
125+
destination = destination.resolve(Paths.get(source.substring(0, delimiterPos)));
126+
source = source.substring(delimiterPos + 1);
131127
}
132128

133129
if (fileIsListing) {

src/test/java/me/itzg/helpers/sync/MulitCopyCommandTest.java

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ void oneWithInlineDestination() throws IOException {
5555
final int exitCode = new CommandLine(new MulitCopyCommand())
5656
.execute(
5757
"--to", tempDir.toString(),
58-
destDir + "@" +srcFile.toString()
58+
"dest@" +srcFile.toString()
5959
);
6060
assertThat(exitCode).isEqualTo(CommandLine.ExitCode.OK);
6161

@@ -98,8 +98,8 @@ void commaDelimitedMultipleDest() throws IOException {
9898
.execute(
9999
"--to", tempDir.toString(),
100100
String.join(",",
101-
destDir1 + "@" + srcTxt.toString(),
102-
destDir2 + "@" + srcJar.toString()
101+
"dest1@" + srcTxt.toString(),
102+
"dest2@" + srcJar.toString()
103103
)
104104
);
105105
assertThat(exitCode).isEqualTo(CommandLine.ExitCode.OK);
@@ -227,7 +227,7 @@ void toInlineDir() throws IOException {
227227
final int exitCode = new CommandLine(new MulitCopyCommand())
228228
.execute(
229229
"--to", tempDir.toString(),
230-
destDir + "@" + srcDir
230+
"dest@" + srcDir
231231
);
232232
assertThat(exitCode).isEqualTo(CommandLine.ExitCode.OK);
233233

@@ -323,7 +323,7 @@ void managedWithManifestAndMultipleDest() throws IOException {
323323
.execute(
324324
"--to", tempDir.toString(),
325325
"--scope", "managedWithManifest",
326-
destDir1 + "@" + srcTxt + "," + destDir2 + "@" + srcJar
326+
"dest1@" + srcTxt + "," + "dest2@" + srcJar
327327
);
328328
assertThat(exitCode).isEqualTo(CommandLine.ExitCode.OK);
329329

@@ -404,7 +404,7 @@ void remoteFileWithInlineDest(WireMockRuntimeInfo wmInfo) {
404404
final int exitCode = new CommandLine(new MulitCopyCommand())
405405
.execute(
406406
"--to", tempDir.toString(),
407-
destDir + "@" + wmInfo.getHttpBaseUrl() + "/file.jar"
407+
"dest@" + wmInfo.getHttpBaseUrl() + "/file.jar"
408408
);
409409
assertThat(exitCode).isEqualTo(CommandLine.ExitCode.OK);
410410

@@ -447,8 +447,8 @@ void listingOfRemoteFilesWithInlineDest(WireMockRuntimeInfo wmInfo) throws IOExc
447447
final Path destDir2 = tempDir.resolve("dest2");
448448

449449
final Path listing = Files.write(tempDir.resolve("listing.txt"), Arrays.asList(
450-
destDir1 + "@" + wmInfo.getHttpBaseUrl() + "/file1.jar",
451-
destDir2 + "@" +wmInfo.getHttpBaseUrl() + "/file2.jar"
450+
"dest1@" + wmInfo.getHttpBaseUrl() + "/file1.jar",
451+
"dest2@" +wmInfo.getHttpBaseUrl() + "/file2.jar"
452452
));
453453

454454
final int exitCode = new CommandLine(new MulitCopyCommand())
@@ -496,8 +496,8 @@ void remoteListingOfRemoteFilesWithInlineDest(WireMockRuntimeInfo wmInfo) {
496496
final Path destDir2 = tempDir.resolve("dest2");
497497

498498
stubRemoteSrc("listing.txt",
499-
destDir1 + "@" + wmInfo.getHttpBaseUrl() + "/file1.jar\n" +
500-
destDir2 + "@" + wmInfo.getHttpBaseUrl() + "/file2.jar\n"
499+
"dest1@" + wmInfo.getHttpBaseUrl() + "/file1.jar\n" +
500+
"dest2@" + wmInfo.getHttpBaseUrl() + "/file2.jar\n"
501501
);
502502
stubRemoteSrc("file1.jar", "one");
503503
stubRemoteSrc("file2.jar", "two");
@@ -553,8 +553,8 @@ void remoteListingOfLocalFilesWithInlineDest(WireMockRuntimeInfo wmInfo) throws
553553
final Path srcJar = writeLine(srcDir, "two.jar", "two");
554554

555555
stubRemoteSrc("listing.txt",
556-
destDir1 + "@" + srcTxt + "\n" +
557-
destDir2 + "@" + srcJar + "\n"
556+
"dest1@" + srcTxt + "\n" +
557+
"dest2@" + srcJar + "\n"
558558
);
559559

560560
final int exitCode = new CommandLine(new MulitCopyCommand())

0 commit comments

Comments
 (0)