gnodet commented on code in PR #201: URL: https://github.com/apache/maven-resolver/pull/201#discussion_r995868188
########## maven-resolver-impl/src/main/java/org/eclipse/aether/internal/impl/checksum/SummaryFileTrustedChecksumsSource.java: ########## @@ -201,41 +214,38 @@ private String calculateSummaryPath( boolean originAware, return fileName + "." + checksumAlgorithmFactory.getFileExtension(); } - /** - * Note: this implementation will work only in single-thread (T1) model. While not ideal, the "workaround" is - * possible in both, Maven and Maven Daemon: force single threaded execution model while "recording" (in mvn: - * do not pass any {@code -T} CLI parameter, while for mvnd use {@code -1} CLI parameter. - * - * TODO: this will need to be reworked for at least two reasons: a) avoid duplicates in summary file and b) - * support multi threaded builds (probably will need "on session close" hook). - */ private class SummaryFileWriter implements Writer { private final Path basedir; private final boolean originAware; - private SummaryFileWriter( Path basedir, boolean originAware ) + private final ConcurrentHashMap<Path, Set<String>> recordedLines; + + private SummaryFileWriter( Path basedir, + boolean originAware, + ConcurrentHashMap<Path, Set<String>> recordedLines ) { this.basedir = basedir; this.originAware = originAware; + this.recordedLines = recordedLines; } @Override public void addTrustedArtifactChecksums( Artifact artifact, ArtifactRepository artifactRepository, List<ChecksumAlgorithmFactory> checksumAlgorithmFactories, - Map<String, String> trustedArtifactChecksums ) throws IOException + Map<String, String> trustedArtifactChecksums ) { for ( ChecksumAlgorithmFactory checksumAlgorithmFactory : checksumAlgorithmFactories ) { String checksum = requireNonNull( trustedArtifactChecksums.get( checksumAlgorithmFactory.getName() ) ); - String summaryLine = ArtifactIdUtils.toId( artifact ) + " " + checksum + "\n"; + String summaryLine = ArtifactIdUtils.toId( artifact ) + " " + checksum; Path summaryPath = basedir.resolve( calculateSummaryPath( originAware, artifactRepository, checksumAlgorithmFactory ) ); - Files.createDirectories( summaryPath.getParent() ); - Files.write( summaryPath, summaryLine.getBytes( StandardCharsets.UTF_8 ), - StandardOpenOption.CREATE, StandardOpenOption.WRITE, StandardOpenOption.APPEND ); + + recordedLines.computeIfAbsent( summaryPath, p -> Collections.synchronizedSet( new TreeSet<>() ) ) + .add( summaryLine ); Review Comment: I think it will directly affect the output when written. So if it's done on the fly, it will have to be done before writing the results. -- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. To unsubscribe, e-mail: issues-unsubscr...@maven.apache.org For queries about this service, please contact Infrastructure at: us...@infra.apache.org