Skip to content

Commit 843bd7f

Browse files
authored
fix: add replace option to copy tasks (#22809)
Add REPLACE_EXISTING options flag to copy tasks where we can expect previous files to be available.
1 parent adad112 commit 843bd7f

File tree

6 files changed

+17
-6
lines changed

6 files changed

+17
-6
lines changed

flow-polymer2lit/src/main/java/com/vaadin/flow/polymer2lit/FrontendConverter.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
import java.nio.charset.StandardCharsets;
2121
import java.nio.file.Files;
2222
import java.nio.file.Path;
23+
import java.nio.file.StandardCopyOption;
2324
import java.util.ArrayList;
2425
import java.util.List;
2526

@@ -48,7 +49,7 @@ public FrontendConverter(FrontendTools frontendTools) throws IOException {
4849
this.tempDirPath = Files.createTempDirectory("converter");
4950
this.converterTempPath = tempDirPath.resolve("converter.js");
5051
Files.copy(getClass().getResourceAsStream(CONVERTER_EXECUTABLE_PATH),
51-
converterTempPath);
52+
converterTempPath, StandardCopyOption.REPLACE_EXISTING);
5253
}
5354

5455
@Override

flow-server/src/main/java/com/vaadin/flow/server/frontend/BundleUtils.java

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121
import java.net.URL;
2222
import java.nio.charset.StandardCharsets;
2323
import java.nio.file.Files;
24+
import java.nio.file.StandardCopyOption;
2425
import java.util.ArrayList;
2526
import java.util.Collections;
2627
import java.util.HashSet;
@@ -199,7 +200,8 @@ private static void copyAppropriatePackageLock(Options options,
199200
if (devBundleFolder.exists()) {
200201
File devPackageLock = new File(devBundleFolder, packageLockFile);
201202
if (devPackageLock.exists()) {
202-
Files.copy(devPackageLock.toPath(), packageLock.toPath());
203+
Files.copy(devPackageLock.toPath(), packageLock.toPath(),
204+
StandardCopyOption.REPLACE_EXISTING);
203205
return;
204206
}
205207
}

flow-server/src/main/java/com/vaadin/flow/server/frontend/TaskCopyNpmAssetsFiles.java

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@
2424
import java.nio.file.Path;
2525
import java.nio.file.PathMatcher;
2626
import java.nio.file.Paths;
27+
import java.nio.file.StandardCopyOption;
2728
import java.security.InvalidParameterException;
2829
import java.util.ArrayList;
2930
import java.util.List;
@@ -159,7 +160,8 @@ private void copyFileToTarget(File file, Rule copyRule, Path basePath) {
159160
destFile.getAbsolutePath());
160161
try {
161162
Files.createDirectories(destFile.toPath().getParent());
162-
Files.copy(file.toPath(), destFile.toPath());
163+
Files.copy(file.toPath(), destFile.toPath(),
164+
StandardCopyOption.REPLACE_EXISTING);
163165
} catch (IOException e) {
164166
throw new UncheckedIOException(String.format(
165167
"Failed to copy project frontend resources from '%s' to '%s'",

flow-server/src/main/java/com/vaadin/flow/server/frontend/TaskCopyTemplateFiles.java

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121
import java.lang.reflect.InvocationTargetException;
2222
import java.nio.file.Files;
2323
import java.nio.file.Path;
24+
import java.nio.file.StandardCopyOption;
2425
import java.util.HashSet;
2526
import java.util.Set;
2627

@@ -86,7 +87,8 @@ public void execute() throws ExecutionFailedException {
8687
Path targetFile = templateDirectory.toPath().resolve(path);
8788
try {
8889
Files.createDirectories(targetFile.getParent());
89-
Files.copy(source.toPath(), targetFile);
90+
Files.copy(source.toPath(), targetFile,
91+
StandardCopyOption.REPLACE_EXISTING);
9092
} catch (IOException e) {
9193
throw new ExecutionFailedException(e);
9294
}

flow-server/src/main/java/com/vaadin/flow/server/frontend/TaskRunDevBundleBuild.java

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121
import java.io.InputStreamReader;
2222
import java.nio.charset.StandardCharsets;
2323
import java.nio.file.Files;
24+
import java.nio.file.StandardCopyOption;
2425
import java.util.ArrayList;
2526
import java.util.Arrays;
2627
import java.util.List;
@@ -241,7 +242,8 @@ private void copyPackageLockToBundleFolder() {
241242
if (packageLockJson.exists()) {
242243
try {
243244
Files.copy(packageLockJson.toPath(),
244-
new File(devBundleFolder, packageLockFile).toPath());
245+
new File(devBundleFolder, packageLockFile).toPath(),
246+
StandardCopyOption.REPLACE_EXISTING);
245247
} catch (IOException e) {
246248
getLogger().error("Failed to copy '" + packageLockFile + "' to "
247249
+ getDevBundleFolderInTarget(), e);

flow-server/src/main/java/com/vaadin/flow/server/frontend/TaskUpdateVite.java

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222
import java.io.UncheckedIOException;
2323
import java.nio.charset.StandardCharsets;
2424
import java.nio.file.Files;
25+
import java.nio.file.StandardCopyOption;
2526
import java.util.List;
2627
import java.util.Optional;
2728
import java.util.Set;
@@ -95,7 +96,8 @@ private void createConfig() throws IOException {
9596

9697
InputStream resource = this.getClass().getClassLoader()
9798
.getResourceAsStream(FrontendUtils.VITE_CONFIG);
98-
Files.copy(resource, configFile.toPath());
99+
Files.copy(resource, configFile.toPath(),
100+
StandardCopyOption.REPLACE_EXISTING);
99101
log().debug("Created vite configuration file: '{}'", configFile);
100102

101103
}

0 commit comments

Comments
 (0)