From a1aaf52ce76634f705e438efde2a401b19075012 Mon Sep 17 00:00:00 2001 From: Scott Fennell Date: Wed, 21 Mar 2018 08:27:11 -0500 Subject: [PATCH] #521 preparation for java 10 support for xmls annotation and improved safety of file separator call --- trick_source/java/makefile | 4 ++++ .../java/src/trick/common/TrickApplication.java | 10 +++++----- trick_source/java/src/trick/common/ui/UIUtils.java | 8 ++++---- .../trick/dataproducts/trickdp/TrickDPApplication.java | 6 +++--- .../trick/dataproducts/trickdp/utils/PDFBooklet.java | 6 +++--- .../trickdp/utils/TrickDPActionController.java | 2 +- .../src/trick/simcontrol/SimControlApplication.java | 8 ++++---- trick_source/java/test/Makefile | 3 +++ .../test/src/trick/common/TrickApplicationTest.java | 4 ++-- .../src/trick/common/utils/LogHeaderReaderTest.java | 8 ++++---- .../java/test/src/trick/dre/WaitForDreApplication.java | 2 +- .../java/test/src/trick/sie/WaitForSieApplication.java | 2 +- 12 files changed, 35 insertions(+), 28 deletions(-) diff --git a/trick_source/java/makefile b/trick_source/java/makefile index 2646735d..c9c65760 100644 --- a/trick_source/java/makefile +++ b/trick_source/java/makefile @@ -13,6 +13,10 @@ ifeq ($(JAVAC_VERSION),9) JAVAC_FLAGS += --add-modules java.se.ee endif +ifeq ($(JAVAC_VERSION),10) + JAVAC_FLAGS += --add-modules java.se.ee +endif + SRC_DIR = src SRC_FILES = $(shell find ${SRC_DIR} -type f -name \*.java) BUILD_DIR = build diff --git a/trick_source/java/src/trick/common/TrickApplication.java b/trick_source/java/src/trick/common/TrickApplication.java index c27ac1fa..e5696a7e 100644 --- a/trick_source/java/src/trick/common/TrickApplication.java +++ b/trick_source/java/src/trick/common/TrickApplication.java @@ -110,9 +110,9 @@ public abstract class TrickApplication extends SingleFrameApplication implements // if we want to put the properties into a different location, change here. static { try { - propDirectory = System.getProperty("user.home") + System.getProperty("file.separator") + ".trick"; + propDirectory = System.getProperty("user.home") + java.io.File.separator + ".trick"; } catch (Exception e) { - propDirectory = System.getenv("TRICK_USER_HOME") + System.getProperty("file.separator") + ".trick"; + propDirectory = System.getenv("TRICK_USER_HOME") + java.io.File.separator + ".trick"; } } @@ -319,7 +319,7 @@ public abstract class TrickApplication extends SingleFrameApplication implements applicationName = getContext().getApplicationClass().getSimpleName(); // set directory for session storage - getContext().getLocalStorage().setDirectory(new File(propDirectory + System.getProperty("file.separator") + "." + applicationName)); + getContext().getLocalStorage().setDirectory(new File(propDirectory + java.io.File.separator + "." + applicationName)); // register property for JToggleButton class so that its state can be saved getContext().getSessionStorage().putProperty(JToggleButton.class, this); @@ -330,7 +330,7 @@ public abstract class TrickApplication extends SingleFrameApplication implements // Load any saved user settable properties from properties file trickProperties = new Properties(); try { - FileInputStream in = new FileInputStream(propDirectory + System.getProperty("file.separator") + applicationName + ".properties"); + FileInputStream in = new FileInputStream(propDirectory + java.io.File.separator + applicationName + ".properties"); trickProperties.load(in); in.close(); } @@ -384,7 +384,7 @@ public abstract class TrickApplication extends SingleFrameApplication implements // Save any user settable properties to properties file in user's home directory in .trick dir try { - FileOutputStream out = new FileOutputStream(propDirectory + System.getProperty("file.separator") + applicationName +".properties"); + FileOutputStream out = new FileOutputStream(propDirectory + java.io.File.separator + applicationName +".properties"); trickProperties.store(out, "--- Trick User Properties ---"); out.close(); } catch (IOException e) { diff --git a/trick_source/java/src/trick/common/ui/UIUtils.java b/trick_source/java/src/trick/common/ui/UIUtils.java index c1f419a4..4dbeed51 100644 --- a/trick_source/java/src/trick/common/ui/UIUtils.java +++ b/trick_source/java/src/trick/common/ui/UIUtils.java @@ -748,11 +748,11 @@ public class UIUtils { ImageIcon imgIcon = null; // if the fileName is a full path - if (fileName.indexOf(System.getProperty("file.separator")) != -1) { + if (fileName.indexOf(java.io.File.separator) != -1) { imgIcon = new ImageIcon(fileName); } else { // if only a file name specified, try to find it at common resources folder - URL imgURL = TrickApplication.class.getResource("resources" + System.getProperty("file.separator") + fileName); + URL imgURL = TrickApplication.class.getResource("resources" + java.io.File.separator + fileName); if (imgURL != null) { imgIcon = new ImageIcon(imgURL); } @@ -778,11 +778,11 @@ public class UIUtils { try { InputStream ins = null; // if the fileName is a full path - if (fileName.indexOf(System.getProperty("file.separator")) != -1) { + if (fileName.indexOf(java.io.File.separator) != -1) { ins = new FileInputStream(fileName); } else { // if only a file name, then find it at common resources area - ins = TrickApplication.class.getResourceAsStream("resources" + System.getProperty("file.separator") + fileName); + ins = TrickApplication.class.getResourceAsStream("resources" + java.io.File.separator + fileName); } return ins; } catch (NullPointerException npe) { diff --git a/trick_source/java/src/trick/dataproducts/trickdp/TrickDPApplication.java b/trick_source/java/src/trick/dataproducts/trickdp/TrickDPApplication.java index 71b14453..603401d4 100644 --- a/trick_source/java/src/trick/dataproducts/trickdp/TrickDPApplication.java +++ b/trick_source/java/src/trick/dataproducts/trickdp/TrickDPApplication.java @@ -356,7 +356,7 @@ public class TrickDPApplication extends DataProductsApplication { while (!simFilePath.getName().startsWith("SIM_")) { simFilePath = simFilePath.getParentFile(); } - String simExeArg = eachItem+System.getProperty("file.separator")+"input.py"; + String simExeArg = eachItem+java.io.File.separator+"input.py"; ProcessBuilder pb = new ProcessBuilder(simExe, simExeArg); pb.directory(simFilePath); printStatusMessage("cd " + simFilePath.getPath() + "\n"); @@ -869,7 +869,7 @@ public class TrickDPApplication extends DataProductsApplication { // TODO: use TrickFileFilter FilenameFilter simFilter = new FilenameFilter() { public boolean accept(File path, String filename) { - File myFullPath = new File(path + System.getProperty("file.separator") + filename); + File myFullPath = new File(path + java.io.File.separator + filename); if ( myFullPath.isDirectory() && filename.contains("SIM") ) { return true; } else { @@ -894,7 +894,7 @@ public class TrickDPApplication extends DataProductsApplication { */ private String appendDirsFromPropertyFile(String simDirs) { // prevent the duplicate ones - File myDpPropFile = new File(propDirectory + System.getProperty("file.separator") + applicationName + ".properties"); + File myDpPropFile = new File(propDirectory + java.io.File.separator + applicationName + ".properties"); if ( myDpPropFile.exists() ) { String dpSimDirsProperty = trickProperties.getProperty("TRICK_DP_SIM_DIRS"); // if the property doesn't exist, return the original string diff --git a/trick_source/java/src/trick/dataproducts/trickdp/utils/PDFBooklet.java b/trick_source/java/src/trick/dataproducts/trickdp/utils/PDFBooklet.java index fc1d8cb9..12855e9a 100644 --- a/trick_source/java/src/trick/dataproducts/trickdp/utils/PDFBooklet.java +++ b/trick_source/java/src/trick/dataproducts/trickdp/utils/PDFBooklet.java @@ -300,7 +300,7 @@ public class PDFBooklet extends JDialog implements ActionListener, ListSelection // For PS view private void psView() { - File selectedFirstFile = new File(fileDir + System.getProperty("file.separator") + selectedPSFileList.getSelectedFirstData().toString()); + File selectedFirstFile = new File(fileDir + java.io.File.separator + selectedPSFileList.getSelectedFirstData().toString()); try { if (selectedFirstFile.exists() && Desktop.isDesktopSupported()) { Desktop.getDesktop().open(selectedFirstFile); @@ -324,7 +324,7 @@ public class PDFBooklet extends JDialog implements ActionListener, ListSelection for (Object obj : selectedData) { commandBuf.append(" "); commandBuf.append(fileDir); - commandBuf.append(System.getProperty("file.separator")); + commandBuf.append(java.io.File.separator); commandBuf.append(obj.toString()); } @@ -357,7 +357,7 @@ public class PDFBooklet extends JDialog implements ActionListener, ListSelection for (Object obj : selectedData) { commandBuf.append(" "); commandBuf.append(fileDir); - commandBuf.append(System.getProperty("file.separator")); + commandBuf.append(java.io.File.separator); commandBuf.append(obj.toString()); } diff --git a/trick_source/java/src/trick/dataproducts/trickdp/utils/TrickDPActionController.java b/trick_source/java/src/trick/dataproducts/trickdp/utils/TrickDPActionController.java index 91e7a314..d1c911ae 100644 --- a/trick_source/java/src/trick/dataproducts/trickdp/utils/TrickDPActionController.java +++ b/trick_source/java/src/trick/dataproducts/trickdp/utils/TrickDPActionController.java @@ -408,7 +408,7 @@ public class TrickDPActionController { public void launchQP(String[] initialArgs) { // the command variable program command name and arguments List command = new ArrayList(); - String fileSeparator = System.getProperty("file.separator"); + String fileSeparator = java.io.File.separator; String pathSeparator = System.getProperty("path.separator"); String javaPath = UIUtils.getTrickHome() + fileSeparator + "libexec/trick" + fileSeparator + "java"; diff --git a/trick_source/java/src/trick/simcontrol/SimControlApplication.java b/trick_source/java/src/trick/simcontrol/SimControlApplication.java index 7c6d059e..525e0c64 100644 --- a/trick_source/java/src/trick/simcontrol/SimControlApplication.java +++ b/trick_source/java/src/trick/simcontrol/SimControlApplication.java @@ -487,7 +487,7 @@ public class SimControlApplication extends TrickApplication implements PropertyC for (int i = 0; i < simRunDirField.length; i++) { if (i==0) { - simRunDirField[i] = new JTextField(results[4] + System.getProperty("file.separator") + results[5] + " " + results[6]); + simRunDirField[i] = new JTextField(results[4] + java.io.File.separator + results[5] + " " + results[6]); } else { simRunDirField[i] = new JTextField(); } @@ -495,7 +495,7 @@ public class SimControlApplication extends TrickApplication implements PropertyC overrunField[i].setPreferredSize( new Dimension(60, overrunField[i].getHeight()) ); } simRunDir = results[7]; - simRunDir = results[4] + System.getProperty("file.separator") + simRunDir; + simRunDir = results[4] + java.io.File.separator + simRunDir; simState.setRunPath(simRunDir); @@ -510,7 +510,7 @@ public class SimControlApplication extends TrickApplication implements PropertyC "trick.sim_serives.var_send( ) \n" + "trick.sim_services.var_clear( ) \n"); results = commandSimcom.get().split("\t"); - simRunDirField[i].setText(results[1] + System.getProperty("file.separator") + results[2] + " " + results[2]);*/ + simRunDirField[i].setText(results[1] + java.io.File.separator + results[2] + " " + results[2]);*/ simRunDirField[i].setText("Slave " + i); } @@ -736,7 +736,7 @@ public class SimControlApplication extends TrickApplication implements PropertyC */ private void printSendHS() { if (simState != null) { - File sendHS = new File(simState.getRunPath() + System.getProperty("file.separator") + "send_hs"); + File sendHS = new File(simState.getRunPath() + java.io.File.separator + "send_hs"); if (!sendHS.exists()) { return; } diff --git a/trick_source/java/test/Makefile b/trick_source/java/test/Makefile index e72d4e05..cce524e7 100644 --- a/trick_source/java/test/Makefile +++ b/trick_source/java/test/Makefile @@ -14,6 +14,9 @@ JAVAC_VERSION := $(shell ${JAVAC} -version 2>&1 | perl -ne 'print /(\d+)/') ifeq ($(JAVAC_VERSION),9) JAVAC_FLAGS += --add-modules java.se.ee endif +ifeq ($(JAVAC_VERSION),10) + JAVAC_FLAGS += --add-modules java.se.ee +endif SRC_DIR = src SRC_FILES = $(shell find ${SRC_DIR} -type f -name \*.java) diff --git a/trick_source/java/test/src/trick/common/TrickApplicationTest.java b/trick_source/java/test/src/trick/common/TrickApplicationTest.java index 47983ab9..bb9f7e61 100644 --- a/trick_source/java/test/src/trick/common/TrickApplicationTest.java +++ b/trick_source/java/test/src/trick/common/TrickApplicationTest.java @@ -43,8 +43,8 @@ public class TrickApplicationTest { public void testPropertyLocation() { application(); application(); - boolean rightLocation = (TrickApplication.propDirectory.equals(System.getenv("HOME") + System.getProperty("file.separator") + ".trick")) - || (TrickApplication.propDirectory.equals(System.getenv("TRICK_USER_HOME") + System.getProperty("file.separator") + ".trick")); + boolean rightLocation = (TrickApplication.propDirectory.equals(System.getenv("HOME") + java.io.File.separator + ".trick")) + || (TrickApplication.propDirectory.equals(System.getenv("TRICK_USER_HOME") + java.io.File.separator + ".trick")); assertTrue("The default property location is not at ../.trick!", rightLocation); } diff --git a/trick_source/java/test/src/trick/common/utils/LogHeaderReaderTest.java b/trick_source/java/test/src/trick/common/utils/LogHeaderReaderTest.java index 080b6097..e7b41ecc 100644 --- a/trick_source/java/test/src/trick/common/utils/LogHeaderReaderTest.java +++ b/trick_source/java/test/src/trick/common/utils/LogHeaderReaderTest.java @@ -33,7 +33,7 @@ public class LogHeaderReaderTest { @Test(expected = FileNotFoundException.class) public void testGetContentsWithNotFoundFile() throws FileNotFoundException, IOException { - DataReader reader = new LogHeaderReader("resources" + System.getProperty("file.separator") + "unknowFile.header"); + DataReader reader = new LogHeaderReader("resources" + java.io.File.separator + "unknowFile.header"); reader.processHeader(); } @@ -61,15 +61,15 @@ public class LogHeaderReaderTest { expectedVarList[8].setUnits("N"); // ASCII - DataReader reader = new LogHeaderReader("resources" + System.getProperty("file.separator") + "log_Ball.header"); + DataReader reader = new LogHeaderReader("resources" + java.io.File.separator + "log_Ball.header"); assertArrayEquals("Error in getContents for ASCII in DataReader.java", expectedVarList, reader.getRecordedVarList().toArray()); // HDF5 - reader = new LogHeaderReader("resources" + System.getProperty("file.separator") + "log_Ball2.header"); + reader = new LogHeaderReader("resources" + java.io.File.separator + "log_Ball2.header"); assertArrayEquals("Error in getContents for HDF5 in DataReader.java", expectedVarList, reader.getRecordedVarList().toArray()); // little_endian - reader = new LogHeaderReader("resources" + System.getProperty("file.separator") + "log_Ball3.header"); + reader = new LogHeaderReader("resources" + java.io.File.separator + "log_Ball3.header"); assertArrayEquals("Error in getContents for little_endian in DataReader.java", expectedVarList, reader.getRecordedVarList().toArray()); } diff --git a/trick_source/java/test/src/trick/dre/WaitForDreApplication.java b/trick_source/java/test/src/trick/dre/WaitForDreApplication.java index 28a6d6f7..f501f018 100644 --- a/trick_source/java/test/src/trick/dre/WaitForDreApplication.java +++ b/trick_source/java/test/src/trick/dre/WaitForDreApplication.java @@ -29,7 +29,7 @@ public class WaitForDreApplication extends DreApplication { */ public static void launchAndWait(Class applicationClass) { synchronized(lock) { - sieResourcePath ="resources" + System.getProperty("file.separator") + "S_sie.resource"; + sieResourcePath ="resources" + java.io.File.separator + "S_sie.resource"; Application.launch(applicationClass, new String[]{}); while(true) { try { diff --git a/trick_source/java/test/src/trick/sie/WaitForSieApplication.java b/trick_source/java/test/src/trick/sie/WaitForSieApplication.java index e3db1549..87799b16 100644 --- a/trick_source/java/test/src/trick/sie/WaitForSieApplication.java +++ b/trick_source/java/test/src/trick/sie/WaitForSieApplication.java @@ -29,7 +29,7 @@ public class WaitForSieApplication extends SieApplication { */ public static void launchAndWait(Class applicationClass) { synchronized(lock) { - sieResourcePath = "resources" + System.getProperty("file.separator") + "S_sie.resource"; + sieResourcePath = "resources" + java.io.File.separator + "S_sie.resource"; Application.launch(applicationClass, new String[]{}); while(true) { try {