elharo commented on code in PR #2031: URL: https://github.com/apache/maven/pull/2031#discussion_r1907411612
########## api/maven-api-toolchain/src/main/mdo/toolchains.mdo: ########## @@ -102,6 +102,18 @@ </association> </field> </fields> + <codeSegments> + <codeSegment> + <version>1.0.0/1.1.0</version> + <code> + <![CDATA[ Review Comment: not sure what CDATA is doing here. It's not needed ########## api/maven-api-model/src/main/mdo/maven.mdo: ########## @@ -1315,6 +1315,17 @@ ]]> </code> </codeSegment> + <codeSegment> + <version>4.0.0/4.0.99</version> + <code> + <![CDATA[ Review Comment: not sure what CDATA is doing here. It's not needed ########## compat/maven-model-builder/src/main/java/org/apache/maven/model/building/ModelCache.java: ########## @@ -18,23 +18,37 @@ */ package org.apache.maven.model.building; -import java.util.function.Supplier; - -import org.apache.maven.building.Source; - /** * Caches auxiliary data used during model building like already processed raw/effective models. The data in the cache * is meant for exclusive consumption by the model builder and is opaque to the cache implementation. The cache key is * formed by a combination of group id, artifact id, version and tag. The first three components generally refer to the - * identity of a model. The tag allows for further classification of the associated data on the sole discretion of the + * identify of a model. The tag allows for further classification of the associated data on the sole discretion of the * model builder. * * @deprecated use {@link org.apache.maven.api.services.ModelBuilder} instead */ @Deprecated(since = "4.0.0") public interface ModelCache { - <T> T computeIfAbsent(String groupId, String artifactId, String version, String tag, Supplier<T> data); + /** + * Puts the specified data into the cache. + * + * @param groupId The group id of the cache record, must not be {@code null}. Review Comment: Oracle javadoc guidelines are no initial capitalization on Javadoc comments and period only after or before a complete sentence ########## compat/maven-model-builder/src/main/java/org/apache/maven/model/building/ModelCacheTag.java: ########## @@ -46,7 +46,25 @@ interface ModelCacheTag<T> { Class<T> getType(); /** - * The tag used for the raw model without profile activation + * Creates a copy of the data suitable for storage in the cache. The original data to store can be mutated after the + * cache is populated but the state of the cache must not change so we need to make a copy. + * + * @param data The data to store in the cache, must not be {@code null}. + * @return The data being stored in the cache, never {@code null}. + */ + T intoCache(T data); + + /** + * Creates a copy of the data suitable for retrieval from the cache. The retrieved data can be mutated after the + * cache is queried but the state of the cache must not change so we need to make a copy. Review Comment: queried, ########## compat/maven-embedder/src/main/java/org/apache/maven/cli/transfer/AbstractMavenTransferListener.java: ########## @@ -33,31 +34,177 @@ */ @Deprecated public abstract class AbstractMavenTransferListener extends AbstractTransferListener { - public static final String STYLE = ".transfer:-faint"; - protected final MessageBuilderFactory messageBuilderFactory; - protected final PrintWriter out; + private static final String ESC = "\u001B"; + private static final String ANSI_DARK_SET = ESC + "[90m"; + private static final String ANSI_DARK_RESET = ESC + "[0m"; - protected AbstractMavenTransferListener(MessageBuilderFactory messageBuilderFactory, PrintStream out) { - this(messageBuilderFactory, new PrintWriter(out)); + // CHECKSTYLE_OFF: LineLength + /** + * Formats file size with the associated <a href="https://en.wikipedia.org/wiki/Metric_prefix">SI</a> prefix + * (GB, MB, kB) and using the patterns <code>#0.0</code> for numbers between 1 and 10 + * and <code>###0</code> for numbers between 10 and 1000+ by default. + * + * @see <a href="https://en.wikipedia.org/wiki/Metric_prefix">https://en.wikipedia.org/wiki/Metric_prefix</a> + * @see <a href="https://en.wikipedia.org/wiki/Binary_prefix">https://en.wikipedia.org/wiki/Binary_prefix</a> + * @see <a + * href="https://en.wikipedia.org/wiki/Octet_%28computing%29">https://en.wikipedia.org/wiki/Octet_(computing)</a> + */ + // CHECKSTYLE_ON: LineLength + // TODO Move me to Maven Shared Utils + static class FileSizeFormat { + enum ScaleUnit { + BYTE { + @Override + public long bytes() { + return 1L; + } + + @Override + public String symbol() { + return "B"; + } + }, + KILOBYTE { + @Override + public long bytes() { + return 1000L; + } + + @Override + public String symbol() { + return "kB"; + } + }, + MEGABYTE { + @Override + public long bytes() { + return KILOBYTE.bytes() * KILOBYTE.bytes(); + } + + @Override + public String symbol() { + return "MB"; + } + }, + GIGABYTE { + @Override + public long bytes() { + return MEGABYTE.bytes() * KILOBYTE.bytes(); + } + ; + + @Override + public String symbol() { + return "GB"; + } + }; + + public abstract long bytes(); + + public abstract String symbol(); + + public static ScaleUnit getScaleUnit(long size) { + if (size < 0L) { + throw new IllegalArgumentException("file size cannot be negative: " + size); + } + + if (size >= GIGABYTE.bytes()) { + return GIGABYTE; + } else if (size >= MEGABYTE.bytes()) { + return MEGABYTE; + } else if (size >= KILOBYTE.bytes()) { + return KILOBYTE; + } else { + return BYTE; + } + } + } + + private DecimalFormat smallFormat; + private DecimalFormat largeFormat; + + FileSizeFormat(Locale locale) { + smallFormat = new DecimalFormat("#0.0", new DecimalFormatSymbols(locale)); + largeFormat = new DecimalFormat("###0", new DecimalFormatSymbols(locale)); + } + + public String format(long size) { + return format(size, null); + } + + public String format(long size, ScaleUnit unit) { + return format(size, unit, false); + } + + public String format(long size, ScaleUnit unit, boolean omitSymbol) { + if (size < 0L) { + throw new IllegalArgumentException("file size cannot be negative: " + size); + } + + if (unit == null) { + unit = ScaleUnit.getScaleUnit(size); + } + + double scaledSize = (double) size / unit.bytes(); + String scaledSymbol = " " + unit.symbol(); + + if (omitSymbol) { + scaledSymbol = ""; + } + + if (unit == ScaleUnit.BYTE) { + return largeFormat.format(size) + scaledSymbol; + } + + if (scaledSize < 0.05 || scaledSize >= 10.0) { + return largeFormat.format(scaledSize) + scaledSymbol; + } else { + return smallFormat.format(scaledSize) + scaledSymbol; + } + } + + public String formatProgress(long progressedSize, long size) { + if (progressedSize < 0L) { + throw new IllegalArgumentException("progressed file size cannot be negative: " + progressedSize); + } + if (size >= 0L && progressedSize > size) { + throw new IllegalArgumentException( + "progressed file size cannot be greater than size: " + progressedSize + " > " + size); + } + + if (size >= 0L && progressedSize != size) { + ScaleUnit unit = ScaleUnit.getScaleUnit(size); + String formattedProgressedSize = format(progressedSize, unit, true); + String formattedSize = format(size, unit); + + return formattedProgressedSize + "/" + formattedSize; + } else { + return format(progressedSize); + } + } } - protected AbstractMavenTransferListener(MessageBuilderFactory messageBuilderFactory, PrintWriter out) { - this.messageBuilderFactory = messageBuilderFactory; + protected PrintStream out; Review Comment: PrintStream is wonky for multiple reasons. Can we just use an output stream writer instead? -- 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