Skip to content

Commit

Permalink
0003989: Java versions 11 and 12 should work with SymmetricDS
Browse files Browse the repository at this point in the history
  • Loading branch information
philipmarzullo64 committed Jun 5, 2019
1 parent 336ee02 commit 0e0e92b
Show file tree
Hide file tree
Showing 96 changed files with 759 additions and 541 deletions.
Expand Up @@ -36,13 +36,12 @@
import java.util.Properties;

import org.apache.commons.cli.CommandLine;
import org.apache.commons.cli.DefaultParser;
import org.apache.commons.cli.HelpFormatter;
import org.apache.commons.cli.Option;
import org.apache.commons.cli.Options;
import org.apache.commons.cli.ParseException;
import org.apache.commons.cli.PosixParser;
import org.apache.commons.dbcp.BasicDataSource;
import org.apache.commons.io.IOUtils;
import org.apache.commons.lang.ArrayUtils;
import org.apache.commons.lang.exception.ExceptionUtils;
import org.apache.log4j.Appender;
Expand Down Expand Up @@ -134,9 +133,7 @@ protected static void initFromServerProperties() {
TypedProperties serverProperties = new TypedProperties();

if (serverPropertiesFile.exists() && serverPropertiesFile.isFile()) {
FileInputStream fis = null;
try {
fis = new FileInputStream(serverPropertiesFile);
try(FileInputStream fis = new FileInputStream(serverPropertiesFile)) {
serverProperties.load(fis);

/* System properties always override */
Expand All @@ -150,8 +147,6 @@ protected static void initFromServerProperties() {

} catch (IOException ex) {
log.error("Failed to load " + DEFAULT_SERVER_PROPERTIES, ex);
} finally {
IOUtils.closeQuietly(fis);
}
} else if (!serverPropertiesFile.exists()) {
log.debug("Failed to load " + DEFAULT_SERVER_PROPERTIES + ". File does not exist.");
Expand All @@ -167,7 +162,7 @@ protected static void initFromServerProperties() {
abstract protected boolean requiresPropertiesFile(CommandLine line);

public void execute(String args[]) {
PosixParser parser = new PosixParser();
DefaultParser parser = new DefaultParser();
Options options = new Options();
buildOptions(options);
try {
Expand Down Expand Up @@ -321,16 +316,12 @@ public File findPropertiesFileForEngineWithName(String engineName) {
for (int i = 0; i < files.length; i++) {
File file = files[i];
Properties properties = new Properties();
FileInputStream is = null;
try {
is = new FileInputStream(file);
try(FileInputStream is = new FileInputStream(file)) {
properties.load(is);
if (engineName.equals(properties.getProperty(ParameterConstants.ENGINE_NAME))) {
return file;
}
} catch (IOException ex) {
} finally {
IOUtils.closeQuietly(is);
}
}
return null;
Expand Down Expand Up @@ -374,7 +365,7 @@ protected void configureCrypto(CommandLine line) throws Exception {

if (line.hasOption(OPTION_JCE_PROVIDER)) {
Provider provider = (Provider) Class.forName(line.getOptionValue(OPTION_JCE_PROVIDER))
.newInstance();
.getDeclaredConstructor().newInstance();
Security.addProvider(provider);
}
}
Expand Down
Expand Up @@ -143,7 +143,7 @@ protected boolean executeWithOptions(CommandLine line) throws Exception {
String[] strWeight = line.getOptionValue(OPTION_WEIGHTS).split(",");
if (strWeight != null && strWeight.length == 3) {
for (int i=0; i<3; i++) {
dmlWeight[i] = new Integer(strWeight[i]);
dmlWeight[i] = Integer.valueOf(strWeight[i]);
}
dbFill.setDmlWeight(dmlWeight);
}
Expand Down
Expand Up @@ -155,7 +155,7 @@ protected boolean executeWithOptions(CommandLine line) throws Exception {
for (String clazz : clazzes) {
if (StringUtils.isNotBlank(clazz)) {
IDatabaseWriterFilter databaseWriterFilter = (IDatabaseWriterFilter) Class
.forName(clazz.trim()).newInstance();
.forName(clazz.trim()).getDeclaredConstructor().newInstance();
dbImport.addDatabaseWriterFilter(databaseWriterFilter);
}
}
Expand Down
Expand Up @@ -43,7 +43,6 @@
import org.apache.commons.cli.Options;
import org.apache.commons.cli.ParseException;
import org.apache.commons.io.FileUtils;
import org.apache.commons.io.IOUtils;
import org.apache.commons.lang.ArrayUtils;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
Expand Down Expand Up @@ -283,7 +282,6 @@ protected void buildOptions(Options options) {
buildCryptoOptions(options);
}

@SuppressWarnings("unchecked")
@Override
protected boolean executeWithOptions(CommandLine line) throws Exception {
List<String> args = line.getArgList();
Expand Down Expand Up @@ -374,16 +372,12 @@ private void listEngines(CommandLine line, List<String> args) {
File[] files = findEnginePropertiesFiles();
for (File file : files) {
Properties properties = new Properties();
FileInputStream is = null;
try {
is = new FileInputStream(file);
try(FileInputStream is = new FileInputStream(file)) {
properties.load(is);
String name = properties.getProperty(ParameterConstants.ENGINE_NAME);
System.out.println(name + " -> " + file.getAbsolutePath());
count++;
} catch (IOException ex) {
} finally {
IOUtils.closeQuietly(is);
}
}
System.out.println(count + " engines returned");
Expand Down Expand Up @@ -519,7 +513,7 @@ private void syncTrigger(CommandLine line, List<String> args) throws IOException
}
}
if (file != null) {
FileUtils.writeStringToFile(file, sqlBuffer.toString());
FileUtils.writeStringToFile(file, sqlBuffer.toString(), Charset.defaultCharset(), false);
}
}

Expand Down Expand Up @@ -645,7 +639,7 @@ private void sendSchema(CommandLine line, List<String> args) {

private void sendScript(CommandLine line, List<String> args) throws Exception {
String scriptName = popArg(args, "Script Name");
String scriptData = FileUtils.readFileToString(new File(scriptName));
String scriptData = FileUtils.readFileToString(new File(scriptName), Charset.defaultCharset());
for (Node node : getNodes(line)) {
System.out.println("Sending script to node '" + node.getNodeId() + "'");
getSymmetricEngine().getDataService().sendScript(node.getNodeId(), scriptData, false);
Expand Down
Expand Up @@ -78,7 +78,7 @@ public IDataWriter getDataWriter(String sourceNodeId, ISymmetricDialect symmetri
List<IDatabaseWriterErrorHandler> errorHandlers,
List<? extends Conflict> conflictSettings, List<ResolvedData> resolvedData) {
try {
FtpDataWriter ftpWriter = (FtpDataWriter) Class.forName(clazzName).newInstance();
FtpDataWriter ftpWriter = (FtpDataWriter) Class.forName(clazzName).getDeclaredConstructor().newInstance();
ftpWriter.setFormat(format);
ftpWriter.setProtocol(protocol);
ftpWriter.setServer(server);
Expand Down
Expand Up @@ -72,7 +72,7 @@ public IDataWriter getDataWriter(String sourceNodeId, ISymmetricDialect symmetri
List<? extends Conflict> conflictSettings, List<ResolvedData> resolvedData) {
try {
if (objectMapper == null) {
objectMapper = (IDBObjectMapper)Class.forName("org.jumpmind.symmetric.io.SimpleDBObjectMapper").newInstance();
objectMapper = (IDBObjectMapper)Class.forName("org.jumpmind.symmetric.io.SimpleDBObjectMapper").getDeclaredConstructor().newInstance();
}
Method method = objectMapper.getClass().getMethod("setDefaultDatabaseName", String.class);
if (method != null) {
Expand Down
Expand Up @@ -75,7 +75,7 @@ protected AbstractJob instantiateJavaJob(JobDefinition jobDefinition, ISymmetric
}
}

return (AbstractJob) jobClass.newInstance(); // try default constructor.
return (AbstractJob) jobClass.getDeclaredConstructor().newInstance(); // try default constructor.
} catch (Exception ex) {
throw new SymmetricException("Failed to load and instantiate job class '" + className + "'", ex);
}
Expand Down
Expand Up @@ -23,6 +23,7 @@
import java.io.BufferedWriter;
import java.io.File;
import java.io.FileWriter;
import java.io.IOException;
import java.io.Writer;
import java.text.DateFormat;
import java.text.NumberFormat;
Expand All @@ -32,7 +33,6 @@
import javax.sql.DataSource;

import org.apache.commons.dbcp.BasicDataSource;
import org.apache.commons.io.IOUtils;
import org.apache.commons.lang.StringUtils;
import org.jumpmind.extension.IBuiltInExtensionPoint;
import org.jumpmind.security.SecurityConstants;
Expand Down Expand Up @@ -296,17 +296,13 @@ public boolean extractBatcheRange(String fileName, String nodeId, String startTi
Date endBatchTime = FormatUtils.parseDate(endTime, FormatUtils.TIMESTAMP_PATTERNS);
String[] channelIds = channelIdList.split(",");
IDataExtractorService dataExtractorService = engine.getDataExtractorService();
BufferedWriter writer = null;
try {
writer = new BufferedWriter(new FileWriter(file));
try(BufferedWriter writer = new BufferedWriter(new FileWriter(file))) {
dataExtractorService.extractBatchRange(writer, nodeId, startBatchTime, endBatchTime,
channelIds);
return true;
} catch (Exception ex) {
log.error("Failed to write batch range to file", ex);
return false;
} finally {
IOUtils.closeQuietly(writer);
}
}

Expand Down Expand Up @@ -390,7 +386,9 @@ public void writeBatchRangeToFile(String nodeId, String startBatchId, String end
Writer writer = new FileWriter(new File(fileName));
engine.getDataExtractorService().extractBatchRange(writer, nodeId,
Long.valueOf(startBatchId), Long.valueOf(endBatchId));
IOUtils.closeQuietly(writer);
try {
writer.close();
} catch(IOException e) { }
}

@ManagedOperation(description = "Encrypts plain text for use with db.user and db.password properties")
Expand Down

0 comments on commit 0e0e92b

Please sign in to comment.