This is an automated email from the ASF dual-hosted git repository. desruisseaux pushed a commit to branch geoapi-4.0 in repository https://gitbox.apache.org/repos/asf/sis.git
commit b4b8bc395b85a3dbb00543fc84f519deee6d8d07 Author: Martin Desruisseaux <[email protected]> AuthorDate: Fri Sep 6 19:26:14 2019 +0200 Shapefile loggers should be package names, not class names. --- .../java/org/apache/sis/util/logging/Logging.java | 18 +++--- .../apache/sis/internal/shapefile/AutoChecker.java | 4 +- .../internal/shapefile/ShapefileByteReader.java | 64 +++++++++++----------- .../sis/storage/shapefile/InputFeatureStream.java | 2 +- .../jdbc/AbstractTestBaseForInternalJDBC.java | 2 +- .../sis/storage/shapefile/ShapeFileTest.java | 4 +- 6 files changed, 49 insertions(+), 45 deletions(-) diff --git a/core/sis-utility/src/main/java/org/apache/sis/util/logging/Logging.java b/core/sis-utility/src/main/java/org/apache/sis/util/logging/Logging.java index 18e3489..df73cb4 100644 --- a/core/sis-utility/src/main/java/org/apache/sis/util/logging/Logging.java +++ b/core/sis-utility/src/main/java/org/apache/sis/util/logging/Logging.java @@ -153,6 +153,7 @@ public final class Logging extends Static { * @return a logger for the specified name. */ public static Logger getLogger(final String name) { + ArgumentChecks.ensureNonNull("name", name); final LoggerFactory<?> factory = Logging.factory; if (factory != null) { final Logger logger = factory.getLogger(name); @@ -164,18 +165,21 @@ public final class Logging extends Static { } /** - * Returns a logger for the specified class. This convenience method invokes - * {@link #getLogger(String)} with the package name as the logger name. + * Returns a logger for the package of the specified class. This convenience method invokes + * {@link #getLogger(String)} with the package name of the given class taken as the logger name. * - * @param classe the class for which to obtain a logger. + * @param source the class which will emit a logging message. * @return a logger for the specified class. + * + * @since 1.0 */ - static Logger getLogger(Class<?> classe) { + public static Logger getLogger(Class<?> source) { + ArgumentChecks.ensureNonNull("source", source); Class<?> outer; - while ((outer = classe.getEnclosingClass()) != null) { - classe = outer; + while ((outer = source.getEnclosingClass()) != null) { + source = outer; } - String name = classe.getName(); + String name = source.getName(); final int separator = name.lastIndexOf('.'); name = (separator >= 1) ? name.substring(0, separator) : ""; if (name.startsWith(Modules.INTERNAL_CLASSNAME_PREFIX)) { diff --git a/storage/sis-shapefile/src/main/java/org/apache/sis/internal/shapefile/AutoChecker.java b/storage/sis-shapefile/src/main/java/org/apache/sis/internal/shapefile/AutoChecker.java index 9f69d96..abf386f 100644 --- a/storage/sis-shapefile/src/main/java/org/apache/sis/internal/shapefile/AutoChecker.java +++ b/storage/sis-shapefile/src/main/java/org/apache/sis/internal/shapefile/AutoChecker.java @@ -34,7 +34,7 @@ import org.apache.sis.util.logging.Logging; */ public abstract class AutoChecker { /** Logger. */ - private static Logger LOGGER = Logging.getLogger(AutoChecker.class.getSimpleName()); + private static Logger LOGGER = Logging.getLogger(AutoChecker.class); /** * Format a resource bundle message. @@ -124,7 +124,7 @@ public abstract class AutoChecker { protected boolean isLoggable(Level level) { return LOGGER.isLoggable(level); } - + /** * Logs (and take the time to format an entry log) only if the logger accepts the message. * @param logLevel Log level. diff --git a/storage/sis-shapefile/src/main/java/org/apache/sis/internal/shapefile/ShapefileByteReader.java b/storage/sis-shapefile/src/main/java/org/apache/sis/internal/shapefile/ShapefileByteReader.java index 0e46f07..e1fad49 100644 --- a/storage/sis-shapefile/src/main/java/org/apache/sis/internal/shapefile/ShapefileByteReader.java +++ b/storage/sis-shapefile/src/main/java/org/apache/sis/internal/shapefile/ShapefileByteReader.java @@ -55,16 +55,16 @@ public class ShapefileByteReader extends CommonByteReader<InvalidShapefileFormat /** Type of the features contained in this shapefile. */ private DefaultFeatureType featuresType; - + /** Shapefile index. */ private File shapeFileIndex; - + /** Shapefile indexes (loaded from .SHX file, if any found). */ private ArrayList<Integer> indexes; - + /** Shapefile records lengths (loaded from .SHX file, if any found). */ private ArrayList<Integer> recordsLengths; - + /** * Construct a shapefile byte reader. * @param shapefile Shapefile. @@ -78,10 +78,10 @@ public class ShapefileByteReader extends CommonByteReader<InvalidShapefileFormat public ShapefileByteReader(File shapefile, File dbaseFile, File shapefileIndex) throws InvalidShapefileFormatException, SQLInvalidDbaseFileFormatException, SQLShapefileNotFoundException, SQLDbaseFileNotFoundException { super(shapefile, InvalidShapefileFormatException.class, SQLShapefileNotFoundException.class); this.shapeFileIndex = shapefileIndex; - + loadDatabaseFieldDescriptors(dbaseFile); loadDescriptor(); - + if (this.shapeFileIndex != null) { loadShapefileIndexes(); } @@ -156,23 +156,23 @@ public class ShapefileByteReader extends CommonByteReader<InvalidShapefileFormat if (this.shapeFileIndex == null) { return false; } - + try(FileInputStream fis = new FileInputStream(this.shapeFileIndex); FileChannel fc = fis.getChannel()) { try { int fsize = (int)fc.size(); MappedByteBuffer indexesByteBuffer = fc.map(FileChannel.MapMode.READ_ONLY, 0, fsize); - + // Indexes entries follow. this.indexes = new ArrayList<>(); this.recordsLengths = new ArrayList<>(); indexesByteBuffer.position(100); indexesByteBuffer.order(ByteOrder.BIG_ENDIAN); - + while(indexesByteBuffer.hasRemaining()) { this.indexes.add(indexesByteBuffer.getInt()); // Data offset : the position of the record in the main shapefile, expressed in words (16 bits). this.recordsLengths.add(indexesByteBuffer.getInt()); // Length of this shapefile record. } - + log(Level.INFO, "log.index_has_been_read", this.shapeFileIndex.getAbsolutePath(), this.indexes.size(), this.getFile().getAbsolutePath()); return true; } @@ -236,15 +236,15 @@ public class ShapefileByteReader extends CommonByteReader<InvalidShapefileFormat String message = format(Level.SEVERE, "excp.no_direct_access", getFile().getAbsolutePath()); throw new SQLNoDirectAccessAvailableException(message); } - + int position = this.indexes.get(recordNumber - 1) * 2; // Indexes unit are words (16 bits). - + // Check that the asked record number is not after the last. if (position >= this.getByteBuffer().capacity()) { String message = format(Level.SEVERE, "excp.wrong_direct_access_after_last", recordNumber, getFile().getAbsolutePath()); throw new SQLInvalidRecordNumberForDirectAccessException(recordNumber, message); } - + try { getByteBuffer().position(position); } @@ -253,7 +253,7 @@ public class ShapefileByteReader extends CommonByteReader<InvalidShapefileFormat throw new RuntimeException(message, e); } } - + /** * Complete a feature with shapefile content. * @param feature Feature to complete. @@ -320,24 +320,24 @@ public class ShapefileByteReader extends CommonByteReader<InvalidShapefileFormat // Handle multiple polygon parts. if (numParts > 1) { - Logger log = Logging.getLogger(ShapefileByteReader.class.getName()); - + Logger log = Logging.getLogger(ShapefileByteReader.class); + if (log.isLoggable(Level.FINER)) { String format = "Polygon with multiple linear rings encountered at position {0,number} with {1,number} parts."; String message = MessageFormat.format(format, getByteBuffer().position(), numParts); log.finer(message); } - + poly = readMultiplePolygonParts(numParts, numPoints); } else { // Polygon with an unique part. poly = readUniquePolygonPart(numPoints); } - + feature.setPropertyValue(GEOMETRY_NAME, poly); } - + /** * Read a polygon that has a unique part. * @param numPoints Number of the points of the polygon. @@ -346,7 +346,7 @@ public class ShapefileByteReader extends CommonByteReader<InvalidShapefileFormat @Deprecated // As soon as the readMultiplePolygonParts method proofs working well, this readUniquePolygonPart method can be removed and all calls be deferred to readMultiplePolygonParts. private Polygon readUniquePolygonPart(int numPoints) { /*int part = */ getByteBuffer().getInt(); - + Polygon poly = new Polygon(); // create a line from the points @@ -360,10 +360,10 @@ public class ShapefileByteReader extends CommonByteReader<InvalidShapefileFormat ypnt = getByteBuffer().getDouble(); poly.lineTo(xpnt, ypnt); } - + return poly; } - + /** * Read a polygon that has multiple parts. * @param numParts Number of parts of this polygon. @@ -371,8 +371,8 @@ public class ShapefileByteReader extends CommonByteReader<InvalidShapefileFormat * @return a multiple part polygon. */ private Polygon readMultiplePolygonParts(int numParts, int numPoints) { - /** - * From ESRI Specification : + /** + * From ESRI Specification : * Parts : 0 5 (meaning : 0 designs the first v1, 5 designs the first v5 on the points list below). * Points : v1 v2 v3 v4 v1 v5 v8 v7 v6 v5 * @@ -382,10 +382,10 @@ public class ShapefileByteReader extends CommonByteReader<InvalidShapefileFormat * Byte 36 NumParts NumParts Integer 1 Little * Byte 40 NumPoints NumPoints Integer 1 Little * Byte 44 Parts Parts Integer NumParts Little - * Byte X Points Points Point NumPoints Little + * Byte X Points Points Point NumPoints Little */ int[] partsIndexes = new int[numParts]; - + // Read all the parts indexes (starting at byte 44). for(int index=0; index < numParts; index ++) { partsIndexes[index] = getByteBuffer().getInt(); @@ -399,7 +399,7 @@ public class ShapefileByteReader extends CommonByteReader<InvalidShapefileFormat xPoints[index] = getByteBuffer().getDouble(); yPoints[index] = getByteBuffer().getDouble(); } - + // Create the polygon from the points. Polygon poly = new Polygon(); @@ -414,18 +414,18 @@ public class ShapefileByteReader extends CommonByteReader<InvalidShapefileFormat break; } } - + if (newPolygon) { - poly.startPath(xPoints[index], yPoints[index]); + poly.startPath(xPoints[index], yPoints[index]); } else { - poly.lineTo(xPoints[index], yPoints[index]); + poly.lineTo(xPoints[index], yPoints[index]); } } - + return poly; } - + /** * Load polyline feature. * @param feature Feature to fill. diff --git a/storage/sis-shapefile/src/main/java/org/apache/sis/storage/shapefile/InputFeatureStream.java b/storage/sis-shapefile/src/main/java/org/apache/sis/storage/shapefile/InputFeatureStream.java index e8da687..1d19f09 100644 --- a/storage/sis-shapefile/src/main/java/org/apache/sis/storage/shapefile/InputFeatureStream.java +++ b/storage/sis-shapefile/src/main/java/org/apache/sis/storage/shapefile/InputFeatureStream.java @@ -53,7 +53,7 @@ import org.opengis.feature.Feature; */ public class InputFeatureStream extends InputStream { /** Logger. */ - private static Logger LOGGER = Logging.getLogger(InputFeatureStream.class.getSimpleName()); + private static Logger LOGGER = Logging.getLogger(InputFeatureStream.class); /** Resource bundle. */ private ResourceBundle rsc = ResourceBundle.getBundle(InputFeatureStream.class.getName()); diff --git a/storage/sis-shapefile/src/test/java/org/apache/sis/internal/shapefile/jdbc/AbstractTestBaseForInternalJDBC.java b/storage/sis-shapefile/src/test/java/org/apache/sis/internal/shapefile/jdbc/AbstractTestBaseForInternalJDBC.java index fefbf2d..ffa2220 100644 --- a/storage/sis-shapefile/src/test/java/org/apache/sis/internal/shapefile/jdbc/AbstractTestBaseForInternalJDBC.java +++ b/storage/sis-shapefile/src/test/java/org/apache/sis/internal/shapefile/jdbc/AbstractTestBaseForInternalJDBC.java @@ -39,7 +39,7 @@ import org.junit.Before; */ public abstract class AbstractTestBaseForInternalJDBC extends TestCase { /** Logger. */ - protected Logger log = Logging.getLogger(getClass().getName()); + protected Logger log = Logging.getLogger(getClass()); /** The database file to use for testing purpose. */ protected File dbfFile; diff --git a/storage/sis-shapefile/src/test/java/org/apache/sis/storage/shapefile/ShapeFileTest.java b/storage/sis-shapefile/src/test/java/org/apache/sis/storage/shapefile/ShapeFileTest.java index 26b529a..6605b24 100644 --- a/storage/sis-shapefile/src/test/java/org/apache/sis/storage/shapefile/ShapeFileTest.java +++ b/storage/sis-shapefile/src/test/java/org/apache/sis/storage/shapefile/ShapeFileTest.java @@ -91,7 +91,7 @@ public final strictfp class ShapeFileTest extends TestCase { */ @Test public void testDescriptors() throws URISyntaxException, DataStoreException { - Logger log = org.apache.sis.util.logging.Logging.getLogger(ShapeFileTest.class.getName()); + Logger log = org.apache.sis.util.logging.Logging.getLogger(ShapeFileTest.class); ShapeFile shp = new ShapeFile(path("ABRALicenseePt_4326_clipped.shp")); shp.loadDescriptors(); @@ -119,7 +119,7 @@ public final strictfp class ShapeFileTest extends TestCase { ShapeFile shp = new ShapeFile(path("DEPARTEMENT.SHP")); Feature first = null, last = null; - Logger log = org.apache.sis.util.logging.Logging.getLogger(ShapeFileTest.class.getName()); + Logger log = org.apache.sis.util.logging.Logging.getLogger(ShapeFileTest.class); try(InputFeatureStream is = shp.findAll()) { Feature feature = is.readFeature();
