Skip to content

Commit

Permalink
Cherry-pick bug fixes for release candidate 2.
Browse files Browse the repository at this point in the history
Include a fix for a regression reported on the mailing list.

https://lists.apache.org/thread/g206zssnxltdc88x2ovjg6zpdmtyb8qc
  • Loading branch information
desruisseaux committed Dec 17, 2022
1 parent 4282ba8 commit 0d96347
Show file tree
Hide file tree
Showing 12 changed files with 136 additions and 20 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -268,13 +268,13 @@ public synchronized void close() throws IOException {
file.close();
} catch (Throwable e) {
try {
input.close();
input.abort();
} catch (Throwable s) {
e.addSuppressed(s);
}
throw e;
}
input.close();
input.abort();
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,8 @@
import java.util.HashMap;
import java.util.Arrays;
import java.util.List;
import org.apache.sis.internal.system.Loggers;
import org.opengis.util.FactoryException;
import org.opengis.util.NoSuchIdentifierException;
import org.opengis.referencing.NoSuchAuthorityCodeException;
import org.opengis.referencing.crs.CoordinateReferenceSystem;
import org.opengis.referencing.crs.GeographicCRS;
Expand All @@ -33,6 +33,7 @@
import org.apache.sis.referencing.crs.DefaultProjectedCRS;
import org.apache.sis.metadata.iso.extent.DefaultGeographicBoundingBox;
import org.apache.sis.metadata.iso.extent.DefaultExtent;
import org.apache.sis.internal.system.Loggers;
import org.apache.sis.util.ComparisonMode;
import org.apache.sis.util.Utilities;

Expand Down Expand Up @@ -218,6 +219,24 @@ public void testFromWKT() throws FactoryException {
assertEquals("GCS WGS 1984", crs.getName().getCode());
}

/**
* Verifies that parsing a WKT with an unknown operation method throws {@link NoSuchIdentifierException}.
*
* @throws FactoryException if an unexpected error occurred.
*/
@Test
public void testFromInvalidWKT() throws FactoryException {
try {
CRS.fromWKT("PROJCS[\"Foo\", GEOGCS[\"Foo\", DATUM[\"Foo\", SPHEROID[\"Sphere\", 6371000, 0]], " +
"UNIT[\"Degree\", 0.0174532925199433]], PROJECTION[\"I do not exist\"], " +
"UNIT[\"MEtre\", 1]]");
fail("Expected NoSuchIdentifierException");
} catch (NoSuchIdentifierException e) {
final String message = e.getMessage();
assertTrue(message, message.contains("I do not exist"));
}
}

/**
* Tests {@link CRS#suggestCommonTarget(GeographicBoundingBox, CoordinateReferenceSystem...)}.
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
import java.util.List;
import java.text.ParseException;
import org.opengis.util.FactoryException;
import org.opengis.util.NoSuchIdentifierException;
import org.opengis.parameter.ParameterValueGroup;
import org.opengis.referencing.crs.CoordinateReferenceSystem;
import org.opengis.referencing.operation.ConcatenatedOperation;
Expand Down Expand Up @@ -56,7 +57,7 @@
* </ul>
*
* @author Martin Desruisseaux (Geomatys)
* @version 0.8
* @version 1.3
* @since 0.7
* @module
*/
Expand Down Expand Up @@ -352,4 +353,20 @@ public void testPositionVectorTransformation() throws ParseException, FactoryExc
CoordinateOperationFinderTest.expectedAGD66(false));
validate();
}

/**
* Verifies that requesting an unknown method throws {@link NoSuchIdentifierException}.
*
* @throws FactoryException if an unexpected error occurred.
*/
@Test
public void testUnknownMethod() throws FactoryException {
try {
factory.getOperationMethod("I do not exist");
fail("Expected NoSuchIdentifierException");
} catch (NoSuchIdentifierException e) {
final String message = e.getMessage();
assertTrue(message, message.contains("I do not exist"));
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
import java.io.DataInputStream;
import java.io.IOException;
import java.text.MessageFormat;
import java.util.Arrays;
import java.util.Map;
import java.util.Enumeration;
import java.util.Locale;
Expand Down Expand Up @@ -443,7 +444,7 @@ final Object[] toArray(final Object arguments) {
*/
if (replacement != element) {
if (array == arguments) {
array = array.clone(); // Protect the user-provided array from change.
array = Arrays.copyOf(array, array.length, Object[].class);
}
array[i] = replacement;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@
*
* @author Martin Desruisseaux (Geomatys)
* @author Johann Sorel (Geomatys)
* @version 1.2
* @version 1.4
* @since 0.3
* @module
*/
Expand Down Expand Up @@ -95,6 +95,7 @@ public static boolean isKindOfPath(final Object path) {
* instance. If the given argument is specialized type like {@code Path} or {@code File}, then this method uses
* dedicated API like {@link Path#getFileName()}. Otherwise this method gets a string representation of the path
* and returns the part after the last {@code '/'} or platform-dependent name separator character, if any.
* The returned string may be empty if the given path is empty or is the root directory.
*
* @param path the path as an instance of one of the above-cited types, or {@code null}.
* @return the filename in the given path, or {@code null} if the given object is null or of unknown type.
Expand Down Expand Up @@ -149,13 +150,15 @@ private static String part(final Object path, final boolean extension) {
*/
end = name.length();
do {
fromIndex = name.lastIndexOf('/', --end) + 1;
if (--end < 0) return ""; // `end` is temporarily inclusive in this loop.
fromIndex = name.lastIndexOf('/', end);
if (separator != '/') {
// Search for platform-specific character only if the object is neither a URL or a URI.
fromIndex = Math.max(fromIndex, CharSequences.lastIndexOf(name, separator, fromIndex, end+1) + 1);
fromIndex = Math.max(fromIndex, name.lastIndexOf(separator, end));
}
} while (fromIndex > end);
end++;
} while (fromIndex == end); // Continue if '/' is the last character.
fromIndex++; // Character after the '/' separator.
end++; // Make exclusive.
}
if (extension) {
fromIndex = CharSequences.lastIndexOf(name, '.', fromIndex, end) + 1;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
* may change in incompatible ways in any future version without notice.
*
* @author Martin Desruisseaux (Geomatys)
* @version 1.3
* @version 1.4
* @since 0.3
* @module
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,9 @@ final class GridSliceLocator {
/**
* Creates a new locator for slices at given coordinates.
*
* @param searchDimension the dimension on which the searches are done.
* @param slices descriptions of the grid resources to use as slices in a multi-dimensional cube.
* @param searchDimension the dimension on which the searches for grid slices are done.
* @param resources an array of initially null elements where to store the resources.
*/
GridSliceLocator(final List<GridSlice> slices, final int searchDimension, final GridCoverageResource[] resources) {
this.searchDimension = searchDimension;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,26 @@ final class GroupAggregate extends AbstractResource implements Aggregate, Aggreg
this.name = name;
}

/**
* Creates a new aggregate with the specified components, which will receive no further processing.
* This is invoked when the caller has not been able to group the slices in a multi-dimensional cube.
* The result stay an aggregate of heterogynous resources.
*
* @param listeners listeners of the parent resource, or {@code null} if none.
* @param name name of this aggregate, or {@code null} if none.
* @param components the resources to uses as components of this aggregate.
* @param sampleDimensions sample dimensions common to all grid coverage resources.
*/
GroupAggregate(final StoreListeners listeners, final String name, final GridCoverageResource[] components,
final List<SampleDimension> sampleDimensions)
{
super(listeners, true);
this.name = name;
this.components = components;
this.componentsAreLeaves = true;
this.sampleDimensions = sampleDimensions;
}

/**
* Creates a new resource with the same data than given resource but a different merge strategy.
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
import org.opengis.referencing.operation.Matrix;
import org.opengis.referencing.operation.MathTransform;
import org.apache.sis.referencing.operation.transform.MathTransforms;
import org.apache.sis.storage.Resource;
import org.apache.sis.storage.GridCoverageResource;
import org.apache.sis.storage.event.StoreListeners;
import org.apache.sis.coverage.grid.GridGeometry;
Expand Down Expand Up @@ -148,16 +149,20 @@ private int[] findConcatenatedDimensions() {
* @param sampleDimensions the sample dimensions of the resource to build.
* @return the concatenated resource.
*/
final GridCoverageResource createResource(final StoreListeners parentListeners, final List<SampleDimension> ranges) {
final Resource createResource(final StoreListeners parentListeners, final List<SampleDimension> ranges) {
final int n = members.size();
if (n == 1) {
return members.get(0).resource;
}
final GridCoverageResource[] slices = new GridCoverageResource[n];
final String name = getName(parentListeners);
final int[] dimensions = findConcatenatedDimensions();
final GridCoverageResource[] slices = new GridCoverageResource[n];
final GridSliceLocator locator = new GridSliceLocator(members, dimensions[0], slices);
final GridGeometry domain = locator.union(geometry, members, GridSlice::getGridExtent);
return new ConcatenatedGridResource(getName(parentListeners), parentListeners,
domain, ranges, slices, locator, strategy);
if (dimensions.length == 0) {
for (int i=0; i<n; i++) slices[i] = members.get(i).resource;
return new GroupAggregate(parentListeners, name, slices, ranges);
}
final GridSliceLocator locator = new GridSliceLocator(members, dimensions[0], slices);
final GridGeometry domain = locator.union(geometry, members, GridSlice::getGridExtent);
return new ConcatenatedGridResource(name, parentListeners, domain, ranges, slices, locator, strategy);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@
*
* @author Martin Desruisseaux (Geomatys)
* @author Johann Sorel (Geomatys)
* @version 1.2
* @version 1.4
* @since 0.3
* @module
*/
Expand All @@ -53,6 +53,8 @@ public void testFilename() throws URISyntaxException, MalformedURLException {
assertEquals("Map.png", IOUtilities.filename(new URI ("file:/Users/name/Map.png")));
assertEquals("Map.png", IOUtilities.filename(new URL ("file:/Users/name/Map.png")));
assertEquals("name", IOUtilities.filename(new URI ("file:/Users/name/")));
assertEquals("", IOUtilities.filename("/"));
assertEquals("", IOUtilities.filename(""));
assertNull(IOUtilities.filename(Boolean.FALSE));
assertNull(IOUtilities.filename(null));
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
/*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You under the Apache License, Version 2.0
* (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.apache.sis.storage.aggregate;

import org.apache.sis.storage.Aggregate;
import org.apache.sis.storage.DataStoreException;
import org.apache.sis.test.TestCase;
import org.junit.Test;

import static org.junit.Assert.*;


/**
* Tests {@link CoverageAggregator}.
*
* @author Martin Desruisseaux (Geomatys)
* @version 1.3
* @since 1.3
* @module
*/
public final strictfp class CoverageAggregatorTest extends TestCase {
/**
* Tests an empty aggregator.
*
* @throws DataStoreException if an error occurred.
*/
@Test
public void testEmpty() throws DataStoreException {
final CoverageAggregator aggregator = new CoverageAggregator(null);
assertTrue(((Aggregate) aggregator.build()).components().isEmpty());
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
*
* @author Martin Desruisseaux (Geomatys)
* @author Alexis Manin (Geomatys)
* @version 1.2
* @version 1.3
* @since 0.3
* @module
*/
Expand Down Expand Up @@ -67,6 +67,7 @@
org.apache.sis.internal.storage.folder.StoreTest.class,
org.apache.sis.storage.aggregate.JoinFeatureSetTest.class,
org.apache.sis.storage.aggregate.ConcatenatedFeatureSetTest.class,
org.apache.sis.storage.aggregate.CoverageAggregatorTest.class,
org.apache.sis.storage.DataStoresTest.class
})
public final strictfp class StorageTestSuite extends TestSuite {
Expand Down

0 comments on commit 0d96347

Please sign in to comment.