Skip to content

Commit

Permalink
Remove some build warnings essentially deprecated warnings
Browse files Browse the repository at this point in the history
  • Loading branch information
sbrunner committed Mar 14, 2023
1 parent dff7037 commit 343e9cd
Show file tree
Hide file tree
Showing 7 changed files with 47 additions and 35 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
import org.mapfish.print.wrapper.yaml.PYamlObject;

import java.lang.reflect.Field;
import java.lang.reflect.InvocationTargetException;
import java.util.Collection;
import java.util.Collections;
import java.util.HashSet;
Expand Down Expand Up @@ -331,8 +332,9 @@ private void encodeAttributeValue(
}
} else {
try {
value = typeOrComponentType.newInstance();
} catch (InstantiationException e) {
value = typeOrComponentType.getDeclaredConstructor().newInstance();
} catch (InvocationTargetException | NoSuchMethodException
| InstantiationException e) {
throw ExceptionUtils.getRuntimeException(e);
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -84,16 +84,19 @@ public RequestDispatcher getNamedDispatcher(String name) {
}

@Override
@Deprecated
public Servlet getServlet(String name) {
return null;
}

@Override
@Deprecated
public Enumeration<Servlet> getServlets() {
return null;
}

@Override
@Deprecated
public Enumeration<String> getServletNames() {
return null;
}
Expand All @@ -104,6 +107,7 @@ public void log(String msg) {
}

@Override
@Deprecated
public void log(Exception exception, String msg) {

}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
import org.opengis.filter.expression.Function;
import org.opengis.filter.expression.Literal;

import java.lang.reflect.InvocationTargetException;
import java.util.Collections;
import java.util.List;
import java.util.stream.Collectors;
Expand All @@ -30,10 +31,12 @@ public Function function(final String name, final List<Expression> args, final L
for (FunctionExpressionImpl template: FUNCTIONS) {
if (template.getName().equals(name)) {
try {
final FunctionExpressionImpl function = template.getClass().newInstance();
final FunctionExpressionImpl function = template.getClass().getDeclaredConstructor()
.newInstance();
function.setParameters(args);
return function;
} catch (InstantiationException | IllegalAccessException e) {
} catch (InvocationTargetException | NoSuchMethodException | InstantiationException
| IllegalAccessException e) {
throw new RuntimeException(e);
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -237,10 +237,10 @@ private static Object parseValue(
value = parseEnum(type, layer.getPath(fieldName), layer.getString(name));
} else {
try {
value = type.newInstance();
value = type.getDeclaredConstructor().newInstance();
PObject object = layer.getObject(name);
parse(errorOnExtraProperties, object, value, extraPropertyToIgnore);
} catch (InstantiationException e) {
} catch (InvocationTargetException | NoSuchMethodException | InstantiationException e) {
throw new UnsupportedTypeException(type, e);
} catch (IllegalAccessException e) {
throw ExceptionUtils.getRuntimeException(e);
Expand Down Expand Up @@ -310,10 +310,10 @@ private static Object parseArrayValue(
value = parseEnum(type, array.getPath("" + i), array.getString(i));
} else {
try {
value = type.newInstance();
value = type.getDeclaredConstructor().newInstance();
PObject object = array.getObject(i);
parse(errorOnExtraProperties, object, value, extraPropertyToIgnore);
} catch (InstantiationException e) {
} catch (InvocationTargetException | NoSuchMethodException | InstantiationException e) {
throw new UnsupportedTypeException(type, e);
} catch (IllegalAccessException e) {
throw ExceptionUtils.getRuntimeException(e);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -203,9 +203,7 @@ private Object getAttributeValue(final String attributeName, final Values values
final Field field;
try {
field = value.getClass().getField(part);
if (!field.isAccessible()) {
field.setAccessible(true);
}
field.setAccessible(true);
value = field.get(value);
} catch (NoSuchFieldException e) {
throw new IllegalArgumentException(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
import net.sf.jasperreports.engine.type.HorizontalTextAlignEnum;
import net.sf.jasperreports.engine.type.ScaleImageEnum;
import net.sf.jasperreports.engine.type.StretchTypeEnum;
import net.sf.jasperreports.engine.type.TextAdjustEnum;
import net.sf.jasperreports.engine.xml.JRXmlLoader;
import net.sf.jasperreports.engine.xml.JRXmlWriter;

Expand Down Expand Up @@ -426,7 +427,7 @@ private String generateSubReport(
colHeaderField.setHeight(headerHeight);
colHeaderField.setHorizontalTextAlign(HorizontalTextAlignEnum.LEFT);
colHeaderField.setStyle(columnHeaderStyle);
colHeaderField.setStretchWithOverflow(true);
colHeaderField.setTextAdjust(TextAdjustEnum.STRETCH_HEIGHT);
colHeaderField.setStretchType(StretchTypeEnum.ELEMENT_GROUP_HEIGHT);

JRDesignExpression headerExpression = new JRDesignExpression();
Expand Down Expand Up @@ -495,7 +496,7 @@ private JRDesignTextField createTextField(final String columnName) {
JRDesignExpression expression = new JRDesignExpression();
expression.setText("$F{" + columnName + "}");
textField.setExpression(expression);
textField.setStretchWithOverflow(true);
textField.setTextAdjust(TextAdjustEnum.STRETCH_HEIGHT);
return textField;
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
package org.mapfish.print.servlet;

import org.apache.commons.io.DirectoryWalker;
import org.apache.commons.lang3.StringUtils;
import org.locationtech.jts.util.Assert;
import org.mapfish.print.MapPrinter;
Expand All @@ -16,8 +15,12 @@
import java.net.URI;
import java.net.URISyntaxException;
import java.nio.channels.ClosedByInterruptException;
import java.nio.file.FileVisitResult;
import java.nio.file.Files;
import java.nio.file.Path;
import java.nio.file.SimpleFileVisitor;
import java.nio.file.attribute.BasicFileAttributes;
import java.util.ArrayList;
import java.util.Collection;
import java.util.HashMap;
import java.util.Iterator;
import java.util.List;
Expand Down Expand Up @@ -78,7 +81,7 @@ public final synchronized MapPrinter create(@Nullable final String app) throws N
"There is no configurationFile registered in the {}" +
" bean with the id: '{}' from configurationFiles:\n {}",
getClass().getName(), finalApp,
String.join("\n", this.configurationFiles.keySet())
LOGGER.isErrorEnabled() ? String.join("\n", this.configurationFiles.keySet()) : ""
);
throw new NoSuchAppException(
"There is no configurationFile registered in the " + getClass().getName() +
Expand Down Expand Up @@ -133,14 +136,14 @@ public final synchronized MapPrinter create(@Nullable final String app) throws N
// see also http://bugs.java.com/view_bug.do?bug_id=7043425
Thread.currentThread().interrupt();
LOGGER.error(
"Error occurred while reading configuration file '{}', '{}'", configFile, e.getMessage()
"Error occurred while reading configuration file '{}', '{}'", configFile, e
);
throw new RuntimeException(String.format(
"Error occurred while reading configuration file '%s': ", configFile),
e);
} catch (Throwable e) {
LOGGER.error(
"Error occurred while reading configuration file '{}', '{}'", configFile, e.getMessage()
"Error occurred while reading configuration file '{}', '{}'", configFile, e
);
throw new RuntimeException(String.format(
"Error occurred while reading configuration file '%s'", configFile), e);
Expand Down Expand Up @@ -205,8 +208,7 @@ public final void setAppsRootDirectory(final String directory) throws URISyntaxE
}
}

final AppWalker walker = new AppWalker();
for (File child: walker.getAppDirs(realRoot)) {
for (File child: getAppDirs(realRoot)) {
final File configFile = new File(child, CONFIG_YAML);
String appName = realRoot.toURI().relativize(child.toURI()).getPath().replace('/', ':');
if (appName.endsWith(":")) {
Expand Down Expand Up @@ -267,22 +269,24 @@ private URI checkForAddedApp(@Nonnull final String app) {
return null;
}

private static class AppWalker extends DirectoryWalker<File> {
public List<File> getAppDirs(final File base) throws IOException {
List<File> results = new ArrayList<>();
walk(base, results);
return results;
}

@Override
protected boolean handleDirectory(
final File directory, final int depth,
final Collection<File> results) {
final File configFile = new File(directory, CONFIG_YAML);
if (configFile.exists()) {
results.add(directory);
private static List<File> getAppDirs(final File base) throws IOException {

List<File> results = new ArrayList<>();

Files.walkFileTree(base.toPath(), new SimpleFileVisitor<Path>() {
@Override
public FileVisitResult preVisitDirectory(final Path dir, final BasicFileAttributes attrs)
throws IOException {
final File configFile = new File(dir.toFile(), CONFIG_YAML);
if (configFile.exists()) {
results.add(dir.toFile());
}
return null;
}
return depth < MAX_DEPTH;
}
});

return results;
}

}

0 comments on commit 343e9cd

Please sign in to comment.