#521 preparation for java 10 support for xmls annotation and improved safety of file separator call

This commit is contained in:
Scott Fennell 2018-03-21 08:27:11 -05:00
parent 4030757304
commit a1aaf52ce7
12 changed files with 35 additions and 28 deletions

View File

@ -13,6 +13,10 @@ ifeq ($(JAVAC_VERSION),9)
JAVAC_FLAGS += --add-modules java.se.ee JAVAC_FLAGS += --add-modules java.se.ee
endif endif
ifeq ($(JAVAC_VERSION),10)
JAVAC_FLAGS += --add-modules java.se.ee
endif
SRC_DIR = src SRC_DIR = src
SRC_FILES = $(shell find ${SRC_DIR} -type f -name \*.java) SRC_FILES = $(shell find ${SRC_DIR} -type f -name \*.java)
BUILD_DIR = build BUILD_DIR = build

View File

@ -110,9 +110,9 @@ public abstract class TrickApplication extends SingleFrameApplication implements
// if we want to put the properties into a different location, change here. // if we want to put the properties into a different location, change here.
static { static {
try { try {
propDirectory = System.getProperty("user.home") + System.getProperty("file.separator") + ".trick"; propDirectory = System.getProperty("user.home") + java.io.File.separator + ".trick";
} catch (Exception e) { } 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(); applicationName = getContext().getApplicationClass().getSimpleName();
// set directory for session storage // 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 // register property for JToggleButton class so that its state can be saved
getContext().getSessionStorage().putProperty(JToggleButton.class, this); 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 // Load any saved user settable properties from properties file
trickProperties = new Properties(); trickProperties = new Properties();
try { 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); trickProperties.load(in);
in.close(); 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 // Save any user settable properties to properties file in user's home directory in .trick dir
try { 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 ---"); trickProperties.store(out, "--- Trick User Properties ---");
out.close(); out.close();
} catch (IOException e) { } catch (IOException e) {

View File

@ -748,11 +748,11 @@ public class UIUtils {
ImageIcon imgIcon = null; ImageIcon imgIcon = null;
// if the fileName is a full path // 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); imgIcon = new ImageIcon(fileName);
} else { } else {
// if only a file name specified, try to find it at common resources folder // 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) { if (imgURL != null) {
imgIcon = new ImageIcon(imgURL); imgIcon = new ImageIcon(imgURL);
} }
@ -778,11 +778,11 @@ public class UIUtils {
try { try {
InputStream ins = null; InputStream ins = null;
// if the fileName is a full path // 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); ins = new FileInputStream(fileName);
} else { } else {
// if only a file name, then find it at common resources area // 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; return ins;
} catch (NullPointerException npe) { } catch (NullPointerException npe) {

View File

@ -356,7 +356,7 @@ public class TrickDPApplication extends DataProductsApplication {
while (!simFilePath.getName().startsWith("SIM_")) { while (!simFilePath.getName().startsWith("SIM_")) {
simFilePath = simFilePath.getParentFile(); 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); ProcessBuilder pb = new ProcessBuilder(simExe, simExeArg);
pb.directory(simFilePath); pb.directory(simFilePath);
printStatusMessage("cd " + simFilePath.getPath() + "\n"); printStatusMessage("cd " + simFilePath.getPath() + "\n");
@ -869,7 +869,7 @@ public class TrickDPApplication extends DataProductsApplication {
// TODO: use TrickFileFilter // TODO: use TrickFileFilter
FilenameFilter simFilter = new FilenameFilter() { FilenameFilter simFilter = new FilenameFilter() {
public boolean accept(File path, String filename) { 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") ) { if ( myFullPath.isDirectory() && filename.contains("SIM") ) {
return true; return true;
} else { } else {
@ -894,7 +894,7 @@ public class TrickDPApplication extends DataProductsApplication {
*/ */
private String appendDirsFromPropertyFile(String simDirs) { private String appendDirsFromPropertyFile(String simDirs) {
// prevent the duplicate ones // 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() ) { if ( myDpPropFile.exists() ) {
String dpSimDirsProperty = trickProperties.getProperty("TRICK_DP_SIM_DIRS"); String dpSimDirsProperty = trickProperties.getProperty("TRICK_DP_SIM_DIRS");
// if the property doesn't exist, return the original string // if the property doesn't exist, return the original string

View File

@ -300,7 +300,7 @@ public class PDFBooklet extends JDialog implements ActionListener, ListSelection
// For PS view // For PS view
private void psView() { 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 { try {
if (selectedFirstFile.exists() && Desktop.isDesktopSupported()) { if (selectedFirstFile.exists() && Desktop.isDesktopSupported()) {
Desktop.getDesktop().open(selectedFirstFile); Desktop.getDesktop().open(selectedFirstFile);
@ -324,7 +324,7 @@ public class PDFBooklet extends JDialog implements ActionListener, ListSelection
for (Object obj : selectedData) { for (Object obj : selectedData) {
commandBuf.append(" "); commandBuf.append(" ");
commandBuf.append(fileDir); commandBuf.append(fileDir);
commandBuf.append(System.getProperty("file.separator")); commandBuf.append(java.io.File.separator);
commandBuf.append(obj.toString()); commandBuf.append(obj.toString());
} }
@ -357,7 +357,7 @@ public class PDFBooklet extends JDialog implements ActionListener, ListSelection
for (Object obj : selectedData) { for (Object obj : selectedData) {
commandBuf.append(" "); commandBuf.append(" ");
commandBuf.append(fileDir); commandBuf.append(fileDir);
commandBuf.append(System.getProperty("file.separator")); commandBuf.append(java.io.File.separator);
commandBuf.append(obj.toString()); commandBuf.append(obj.toString());
} }

View File

@ -408,7 +408,7 @@ public class TrickDPActionController {
public void launchQP(String[] initialArgs) { public void launchQP(String[] initialArgs) {
// the command variable program command name and arguments // the command variable program command name and arguments
List<String> command = new ArrayList<String>(); List<String> command = new ArrayList<String>();
String fileSeparator = System.getProperty("file.separator"); String fileSeparator = java.io.File.separator;
String pathSeparator = System.getProperty("path.separator"); String pathSeparator = System.getProperty("path.separator");
String javaPath = UIUtils.getTrickHome() + fileSeparator + "libexec/trick" + fileSeparator + "java"; String javaPath = UIUtils.getTrickHome() + fileSeparator + "libexec/trick" + fileSeparator + "java";

View File

@ -487,7 +487,7 @@ public class SimControlApplication extends TrickApplication implements PropertyC
for (int i = 0; i < simRunDirField.length; i++) { for (int i = 0; i < simRunDirField.length; i++) {
if (i==0) { 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 { } else {
simRunDirField[i] = new JTextField(); simRunDirField[i] = new JTextField();
} }
@ -495,7 +495,7 @@ public class SimControlApplication extends TrickApplication implements PropertyC
overrunField[i].setPreferredSize( new Dimension(60, overrunField[i].getHeight()) ); overrunField[i].setPreferredSize( new Dimension(60, overrunField[i].getHeight()) );
} }
simRunDir = results[7]; simRunDir = results[7];
simRunDir = results[4] + System.getProperty("file.separator") + simRunDir; simRunDir = results[4] + java.io.File.separator + simRunDir;
simState.setRunPath(simRunDir); simState.setRunPath(simRunDir);
@ -510,7 +510,7 @@ public class SimControlApplication extends TrickApplication implements PropertyC
"trick.sim_serives.var_send( ) \n" + "trick.sim_serives.var_send( ) \n" +
"trick.sim_services.var_clear( ) \n"); "trick.sim_services.var_clear( ) \n");
results = commandSimcom.get().split("\t"); 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); simRunDirField[i].setText("Slave " + i);
} }
@ -736,7 +736,7 @@ public class SimControlApplication extends TrickApplication implements PropertyC
*/ */
private void printSendHS() { private void printSendHS() {
if (simState != null) { 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()) { if (!sendHS.exists()) {
return; return;
} }

View File

@ -14,6 +14,9 @@ JAVAC_VERSION := $(shell ${JAVAC} -version 2>&1 | perl -ne 'print /(\d+)/')
ifeq ($(JAVAC_VERSION),9) ifeq ($(JAVAC_VERSION),9)
JAVAC_FLAGS += --add-modules java.se.ee JAVAC_FLAGS += --add-modules java.se.ee
endif endif
ifeq ($(JAVAC_VERSION),10)
JAVAC_FLAGS += --add-modules java.se.ee
endif
SRC_DIR = src SRC_DIR = src
SRC_FILES = $(shell find ${SRC_DIR} -type f -name \*.java) SRC_FILES = $(shell find ${SRC_DIR} -type f -name \*.java)

View File

@ -43,8 +43,8 @@ public class TrickApplicationTest {
public void testPropertyLocation() { public void testPropertyLocation() {
application(); application();
application(); application();
boolean rightLocation = (TrickApplication.propDirectory.equals(System.getenv("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") + System.getProperty("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); assertTrue("The default property location is not at ../.trick!", rightLocation);
} }

View File

@ -33,7 +33,7 @@ public class LogHeaderReaderTest {
@Test(expected = FileNotFoundException.class) @Test(expected = FileNotFoundException.class)
public void testGetContentsWithNotFoundFile() throws FileNotFoundException, IOException { 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(); reader.processHeader();
} }
@ -61,15 +61,15 @@ public class LogHeaderReaderTest {
expectedVarList[8].setUnits("N"); expectedVarList[8].setUnits("N");
// ASCII // 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()); assertArrayEquals("Error in getContents for ASCII in DataReader.java", expectedVarList, reader.getRecordedVarList().toArray());
// HDF5 // 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()); assertArrayEquals("Error in getContents for HDF5 in DataReader.java", expectedVarList, reader.getRecordedVarList().toArray());
// little_endian // 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()); assertArrayEquals("Error in getContents for little_endian in DataReader.java", expectedVarList, reader.getRecordedVarList().toArray());
} }

View File

@ -29,7 +29,7 @@ public class WaitForDreApplication extends DreApplication {
*/ */
public static void launchAndWait(Class<? extends WaitForDreApplication> applicationClass) { public static void launchAndWait(Class<? extends WaitForDreApplication> applicationClass) {
synchronized(lock) { 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[]{}); Application.launch(applicationClass, new String[]{});
while(true) { while(true) {
try { try {

View File

@ -29,7 +29,7 @@ public class WaitForSieApplication extends SieApplication {
*/ */
public static void launchAndWait(Class<? extends WaitForSieApplication> applicationClass) { public static void launchAndWait(Class<? extends WaitForSieApplication> applicationClass) {
synchronized(lock) { 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[]{}); Application.launch(applicationClass, new String[]{});
while(true) { while(true) {
try { try {