diff --git a/eo-maven-plugin/src/main/java/org/eolang/maven/TranspileMojo.java b/eo-maven-plugin/src/main/java/org/eolang/maven/TranspileMojo.java index a079849463..7847f13057 100644 --- a/eo-maven-plugin/src/main/java/org/eolang/maven/TranspileMojo.java +++ b/eo-maven-plugin/src/main/java/org/eolang/maven/TranspileMojo.java @@ -35,7 +35,6 @@ import com.yegor256.xsline.Xsline; import java.io.File; import java.io.IOException; -import java.nio.file.AccessDeniedException; import java.nio.file.Files; import java.nio.file.Path; import java.nio.file.Paths; @@ -251,12 +250,21 @@ private List transpile( * In order to prevent this, we remove all classes that have the java analog in the * generated sources. In other words, if generated-sources (or generated-test-sources) folder * has java classes, we expect that they will be only compiled from that folder. + * _____ + * Synchronization in this method is necessary to prevent + * {@link java.nio.file.AccessDeniedException} on the Windows OS. + * You can read more about the original problem in the following issue: + * - issue link + * In other words, concurrent file deletions on the Windows OS can lead to an + * {@link java.nio.file.AccessDeniedException}, which could crash the build. + * _____ * @param java The list of java files. - * @todo #2281:90min Remove AccessDeniedException catch block from cleanUpClasses method. - * This catch block was added to prevent the build from failing when the file can't be - * deleted due to access denied. This is a temporary solution and should be removed when - * the root cause of the problem is found. - * See issue. + * @todo #2375:90min. Add concurrency tests for the TranspileMojo.cleanUpClasses method. + * We should be sure that the method works correctly in a concurrent environment. + * In order to do so we should add a test that will run the cleanUpClasses method in + * multiple threads and check that the method works correctly without exceptions. + * We can apply the same approach as mentioned in that post: + * Post */ private void cleanUpClasses(final Collection java) { final Set unexpected = java.stream() @@ -266,12 +274,9 @@ private void cleanUpClasses(final Collection java) { .collect(Collectors.toSet()); for (final Path binary : unexpected) { try { - Files.deleteIfExists(binary); - } catch (final AccessDeniedException ignore) { - Logger.warn( - this, - String.format("Can't delete file %s due to access denied", binary) - ); + synchronized (TranspileMojo.class) { + Files.deleteIfExists(binary); + } } catch (final IOException cause) { throw new IllegalStateException( String.format("Can't delete file %s", binary),