Changeset 19077 in josm for trunk


Ignore:
Timestamp:
2024-05-13T19:23:43+02:00 (6 months ago)
Author:
taylor.smock
Message:

Fix #23666: commons-io dependency not included in ivy.xml

This removes all imports of org.apache.commons.io classes and replaces them with
similar functionality.

Location:
trunk
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/org/openstreetmap/josm/data/validation/ValidatorCLI.java

    r19050 r19077  
    2727import java.util.stream.Collectors;
    2828
    29 import org.apache.commons.io.FilenameUtils;
    3029import org.openstreetmap.josm.actions.ExtensionFileFilter;
    3130import org.openstreetmap.josm.cli.CLIModule;
     
    320319     */
    321320    private static String getDefaultOutputName(final String inputString) {
    322         final String extension = FilenameUtils.getExtension(inputString);
     321        final String[] parts = getFileParts(inputString);
     322        final String extension = parts[1];
    323323        if (!Arrays.asList("zip", "bz", "xz", "geojson").contains(extension)) {
    324             return FilenameUtils.getBaseName(inputString) + ".geojson";
     324            return parts[0] + ".geojson";
    325325        } else if ("geojson".equals(extension)) {
    326326            // Account for geojson input files
    327             return FilenameUtils.getBaseName(inputString) + ".validated.geojson";
    328         }
    329         return FilenameUtils.getBaseName(FilenameUtils.getBaseName(inputString)) + ".geojson";
     327            return parts[0] + ".validated.geojson";
     328        }
     329        return parts[0] + ".geojson";
     330    }
     331
     332    /**
     333     * Split a string into a filename + extension. Example:
     334     * "foo.bar.txt" -> ["foo.bar", "txt"]
     335     * <p>
     336     * Please note that future versions of Java may make this method redundant. It is not as of Java 21 (look for
     337     * something like {@code Path#getExtension}, see <a href="https://bugs.openjdk.org/browse/JDK-8298318">JDK-8298318</a>.
     338     * That may be in Java 22.
     339     * @param inputString The string to get the filename and extension from
     340     * @return The filename and the (optional) extension
     341     */
     342    private static String[] getFileParts(String inputString) {
     343        final int split = inputString.lastIndexOf('.');
     344        final int path = inputString.lastIndexOf(File.separatorChar);
     345        if (split == -1 || path > split) {
     346            return new String[] {inputString, ""};
     347        } else {
     348            return new String[]{inputString.substring(0, split), inputString.substring(split + 1)};
     349        }
    330350    }
    331351
  • trunk/src/org/openstreetmap/josm/io/OsmPbfReader.java

    r19050 r19077  
    77import java.io.IOException;
    88import java.io.InputStream;
     9import java.io.OutputStream;
    910import java.util.ArrayList;
    1011import java.util.Arrays;
     
    1617import java.util.Set;
    1718
    18 import org.apache.commons.io.input.BoundedInputStream;
    1919import org.openstreetmap.josm.data.Bounds;
    2020import org.openstreetmap.josm.data.DataSource;
     
    5151 */
    5252public final class OsmPbfReader extends AbstractReader {
     53    /**
     54     * This could be replaced by {@link org.apache.commons.io.input.BoundedInputStream} from Apache Commons IO.
     55     * However, Commons IO is not <i>currently</i> (2024-05-13) a required JOSM dependency, so we should avoid using it
     56     * for now. Commons IO is a <i>transitive</i> dependency, currently pulled in by {@link org.apache.commons.compress}
     57     * (see {@link org.apache.commons.compress.utils.BoundedInputStream}).
     58     */
     59    private static final class BoundedInputStream extends InputStream {
     60        private final InputStream source;
     61        private long count;
     62        private long mark;
     63
     64        BoundedInputStream(InputStream source) {
     65            this.source = source;
     66        }
     67
     68        @Override
     69        public int read() throws IOException {
     70            count++;
     71            return this.source.read();
     72        }
     73
     74        @Override
     75        public long skip(long n) throws IOException {
     76            long skipped = super.skip(n);
     77            this.count += skipped;
     78            return skipped;
     79        }
     80
     81        @Override
     82        public int available() throws IOException {
     83            return this.source.available();
     84        }
     85
     86        @Override
     87        public void close() throws IOException {
     88            this.source.close();
     89        }
     90
     91        @Override
     92        public synchronized void mark(int readlimit) {
     93            this.source.mark(readlimit);
     94            this.mark = this.count;
     95        }
     96
     97        @Override
     98        public synchronized void reset() throws IOException {
     99            this.source.reset();
     100            this.count = this.mark;
     101        }
     102
     103        @Override
     104        public boolean markSupported() {
     105            return this.source.markSupported();
     106        }
     107
     108        @Override
     109        public long transferTo(OutputStream out) throws IOException {
     110            return super.transferTo(out);
     111        }
     112
     113        long getCount() {
     114            return this.count;
     115        }
     116    }
     117
    53118    private static final long[] EMPTY_LONG = new long[0];
    54119    /**
  • trunk/test/unit/org/openstreetmap/josm/data/imagery/WMTSTileSourceTest.java

    r19052 r19077  
    1616import java.nio.charset.StandardCharsets;
    1717import java.nio.file.Files;
     18import java.nio.file.Path;
    1819import java.nio.file.Paths;
    1920import java.util.ArrayList;
     
    2223import java.util.concurrent.TimeUnit;
    2324
    24 import org.apache.commons.io.FileUtils;
    2525import org.junit.jupiter.api.Disabled;
    2626import org.junit.jupiter.api.Test;
     
    488488    void testSupportedMimeTypesUrlEncode(String mimeType, @TempDir File temporaryDirectory)
    489489            throws IOException, WMTSGetCapabilitiesException, ReflectiveOperationException {
    490         final String data = FileUtils.readFileToString(new File(TestUtils.getTestDataRoot() +
    491                 "wmts/bug13975-multiple-tile-matrices-for-one-layer-projection.xml"), StandardCharsets.UTF_8)
     490        final String data = Files.readString(Paths.get(TestUtils.getTestDataRoot() +
     491                        "wmts", "bug13975-multiple-tile-matrices-for-one-layer-projection.xml"), StandardCharsets.UTF_8)
    492492                .replace("image/jpgpng", mimeType);
    493         File file = new File(temporaryDirectory, "testSupportedMimeTypes.xml");
    494         FileUtils.writeStringToFile(file, data, StandardCharsets.UTF_8);
    495         WMTSCapabilities capabilities = WMTSTileSource.getCapabilities(file.toURI().toURL().toExternalForm(), Collections.emptyMap());
     493        Path file = temporaryDirectory.toPath().resolve("testSupportedMimeTypes.xml");
     494        Files.writeString(file, data, StandardCharsets.UTF_8);
     495        WMTSCapabilities capabilities = WMTSTileSource.getCapabilities(file.toUri().toURL().toExternalForm(), Collections.emptyMap());
    496496        assertEquals(2, capabilities.getLayers().size());
    497497        Field format = WMTSTileSource.Layer.class.getDeclaredField("format");
Note: See TracChangeset for help on using the changeset viewer.