diff --git a/olcut-config-jini/src/main/java/com/oracle/labs/mlrg/olcut/config/remote/JiniConfigurationManager.java b/olcut-config-jini/src/main/java/com/oracle/labs/mlrg/olcut/config/remote/JiniConfigurationManager.java index 034d5c9c..59e181c1 100644 --- a/olcut-config-jini/src/main/java/com/oracle/labs/mlrg/olcut/config/remote/JiniConfigurationManager.java +++ b/olcut-config-jini/src/main/java/com/oracle/labs/mlrg/olcut/config/remote/JiniConfigurationManager.java @@ -471,6 +471,11 @@ public boolean equals(Object obj) { return cm.getImmutableGlobalProperties().equals(getImmutableGlobalProperties()); } + @Override + public int hashCode() { + return super.hashCode(); + } + @Override protected ServablePropertySheet createPropertySheet(T conf, ConfigurationManager cm, ConfigurationData rpd) { return new ServablePropertySheet<>(conf,(JiniConfigurationManager)cm,rpd); diff --git a/olcut-config-jini/src/main/java/com/oracle/labs/mlrg/olcut/config/remote/ServablePropertySheet.java b/olcut-config-jini/src/main/java/com/oracle/labs/mlrg/olcut/config/remote/ServablePropertySheet.java index e929e059..1a6d41be 100644 --- a/olcut-config-jini/src/main/java/com/oracle/labs/mlrg/olcut/config/remote/ServablePropertySheet.java +++ b/olcut-config-jini/src/main/java/com/oracle/labs/mlrg/olcut/config/remote/ServablePropertySheet.java @@ -111,6 +111,16 @@ public ConfigurationEntry[] getEntries() { return entries; } + @Override + public boolean equals(Object other) { + return super.equals(other); + } + + @Override + public int hashCode() { + return super.hashCode(); + } + @Override public synchronized T getOwner(ComponentListener cl, boolean reuseComponent) { if (!isInstantiated() || !reuseComponent) { diff --git a/olcut-core/src/main/java/com/oracle/labs/mlrg/olcut/command/CommandInterpreter.java b/olcut-core/src/main/java/com/oracle/labs/mlrg/olcut/command/CommandInterpreter.java index 7af46909..c85b5ac6 100644 --- a/olcut-core/src/main/java/com/oracle/labs/mlrg/olcut/command/CommandInterpreter.java +++ b/olcut-core/src/main/java/com/oracle/labs/mlrg/olcut/command/CommandInterpreter.java @@ -32,6 +32,7 @@ import java.io.BufferedReader; import java.io.File; +import java.io.FileInputStream; import java.io.FileReader; import java.io.IOException; import java.io.InputStreamReader; @@ -41,6 +42,7 @@ import java.lang.reflect.InvocationTargetException; import java.lang.reflect.Method; import java.lang.reflect.Parameter; +import java.nio.charset.StandardCharsets; import java.nio.file.Path; import java.util.ArrayList; import java.util.Arrays; @@ -161,7 +163,7 @@ public CommandInterpreter(String inputFile) throws java.io.IOException { if(inputFile == null) { setupJLine(); } else { - in = new BufferedReader(new FileReader(inputFile)); + in = new BufferedReader(new InputStreamReader(new FileInputStream(inputFile), StandardCharsets.UTF_8)); inputIsFile = true; } out = System.out; @@ -200,7 +202,7 @@ protected void setupJLine() { consoleReader = lineBuilder.build(); } catch(IOException e) { logger.info("Failed to load JLine, falling back to System.in"); - in = new BufferedReader(new InputStreamReader(System.in)); + in = new BufferedReader(new InputStreamReader(System.in, StandardCharsets.UTF_8)); } } @@ -1060,7 +1062,7 @@ public boolean load(String filename) { } public boolean load(File file) { - try (BufferedReader br = new BufferedReader(new FileReader(file))){ + try (BufferedReader br = new BufferedReader(new InputStreamReader(new FileInputStream(file), StandardCharsets.UTF_8))){ String inputLine; while((inputLine = br.readLine()) != null) { @@ -1085,7 +1087,7 @@ public boolean pload(String filename, int numThreads) { public boolean pload(File file, int numThreads) { ExecutorService exec = Executors.newFixedThreadPool(numThreads); - try (BufferedReader br = new BufferedReader(new FileReader(file))){ + try (BufferedReader br = new BufferedReader(new InputStreamReader(new FileInputStream(file), StandardCharsets.UTF_8))){ String inputLine; while((inputLine = br.readLine()) != null) { diff --git a/olcut-core/src/main/java/com/oracle/labs/mlrg/olcut/config/ConfigurationManager.java b/olcut-core/src/main/java/com/oracle/labs/mlrg/olcut/config/ConfigurationManager.java index 85ebb800..b5b5977e 100644 --- a/olcut-core/src/main/java/com/oracle/labs/mlrg/olcut/config/ConfigurationManager.java +++ b/olcut-core/src/main/java/com/oracle/labs/mlrg/olcut/config/ConfigurationManager.java @@ -1148,12 +1148,12 @@ public void overrideConfigurableProperty(String componentName, String propertyNa public synchronized void close() { } /** - * Get any unnamed arguments that weren't parsed into an {@link Options} + * Get a copy of any unnamed arguments that weren't parsed into an {@link Options} * instance, or used to override a {@link Configurable} field. * @return A string array of command line arguments. */ public String[] getUnnamedArguments() { - return unnamedArguments; + return Arrays.copyOf(unnamedArguments,unnamedArguments.length); } /** diff --git a/olcut-core/src/main/java/com/oracle/labs/mlrg/olcut/config/DescribeConfigurable.java b/olcut-core/src/main/java/com/oracle/labs/mlrg/olcut/config/DescribeConfigurable.java index 388c9e68..e135e8b9 100644 --- a/olcut-core/src/main/java/com/oracle/labs/mlrg/olcut/config/DescribeConfigurable.java +++ b/olcut-core/src/main/java/com/oracle/labs/mlrg/olcut/config/DescribeConfigurable.java @@ -309,9 +309,11 @@ public static void writeExampleConfig(OutputStream stream, String fileFormat, Cl FieldInfo fi = e.getValue(); switch (fi.type) { case NORMAL: + case ENUM: properties.put(e.getKey(),new SimpleProperty(generateDefaultValue(fi))); break; case LIST: + case ENUM_LIST: properties.put(e.getKey(),new ListProperty(Collections.singletonList(new SimpleProperty(fi.className + "-instance")))); break; case MAP: diff --git a/olcut-core/src/main/java/com/oracle/labs/mlrg/olcut/config/FieldType.java b/olcut-core/src/main/java/com/oracle/labs/mlrg/olcut/config/FieldType.java index 8e6ca224..5c37fd16 100644 --- a/olcut-core/src/main/java/com/oracle/labs/mlrg/olcut/config/FieldType.java +++ b/olcut-core/src/main/java/com/oracle/labs/mlrg/olcut/config/FieldType.java @@ -35,6 +35,8 @@ import java.time.LocalDate; import java.time.OffsetDateTime; import java.time.OffsetTime; +import java.util.Arrays; +import java.util.Collections; import java.util.EnumSet; import java.util.HashMap; import java.util.List; @@ -94,7 +96,7 @@ public enum FieldType { private static final Class configurableArrayClass = Configurable[].class; private static final Class enumClass = Enum.class; - private final Class[] types; + private final List> types; private final static Map,FieldType> m = new HashMap<>(); @@ -115,7 +117,7 @@ public enum FieldType { public final static EnumSet configurableTypes = EnumSet.of(CONFIGURABLE,CONFIGURABLE_ARRAY); FieldType(Class... types) { - this.types = types; + this.types = Collections.unmodifiableList(Arrays.asList(types)); } static { @@ -143,7 +145,7 @@ public static FieldType getFieldType(Field f) { return getFieldType(fieldClass); } - public Class[] getTypes() { + public List> getTypes() { return types; } diff --git a/olcut-core/src/main/java/com/oracle/labs/mlrg/olcut/config/PropertySheet.java b/olcut-core/src/main/java/com/oracle/labs/mlrg/olcut/config/PropertySheet.java index cf8b47bb..103c8a04 100644 --- a/olcut-core/src/main/java/com/oracle/labs/mlrg/olcut/config/PropertySheet.java +++ b/olcut-core/src/main/java/com/oracle/labs/mlrg/olcut/config/PropertySheet.java @@ -60,6 +60,7 @@ import java.util.HashSet; import java.util.List; import java.util.Map; +import java.util.Objects; import java.util.Queue; import java.util.Random; import java.util.Set; @@ -270,8 +271,7 @@ public synchronized T getOwner(ComponentListener cl, boolean reuseComponent) if (serStream != null) { try (ObjectInputStream ois = new ObjectInputStream(new BufferedInputStream(serStream, 1024 * 1024))) { Object deser = ois.readObject(); - owner = ownerClass.cast(deser); - return owner; + return ownerClass.cast(deser); } catch (IOException ex) { throw new PropertyException(ex, instanceName, null, "Error reading serialized form from " + actualLocation); @@ -285,6 +285,7 @@ public synchronized T getOwner(ComponentListener cl, boolean reuseComponent) } ); if (obj != null) { + owner = obj; return obj; } } @@ -899,7 +900,7 @@ public Set getRegisteredProperties() { return Collections.unmodifiableSet(registeredProperties.keySet()); } - public void setCM(ConfigurationManager cm) { + public synchronized void setCM(ConfigurationManager cm) { this.cm = cm; } @@ -917,6 +918,11 @@ public boolean equals(Object obj) { return propValues.equals(ps.propValues); } + @Override + public int hashCode() { + return Objects.hash(propValues); + } + public PropertySheet copy() { return new PropertySheet<>(this); } diff --git a/olcut-core/src/main/java/com/oracle/labs/mlrg/olcut/config/property/GlobalProperty.java b/olcut-core/src/main/java/com/oracle/labs/mlrg/olcut/config/property/GlobalProperty.java index b78c2ac0..07cbce14 100644 --- a/olcut-core/src/main/java/com/oracle/labs/mlrg/olcut/config/property/GlobalProperty.java +++ b/olcut-core/src/main/java/com/oracle/labs/mlrg/olcut/config/property/GlobalProperty.java @@ -83,7 +83,7 @@ public String toString() { @Override public boolean equals(Object o) { if (this == o) return true; - if (o == null || getClass() != o.getClass()) return false; + if (!(o instanceof GlobalProperty)) return false; GlobalProperty that = (GlobalProperty) o; String tmpValue = getValue(); diff --git a/olcut-core/src/main/java/com/oracle/labs/mlrg/olcut/config/property/LazyGlobalProperty.java b/olcut-core/src/main/java/com/oracle/labs/mlrg/olcut/config/property/LazyGlobalProperty.java index 71245a99..80ba8c66 100644 --- a/olcut-core/src/main/java/com/oracle/labs/mlrg/olcut/config/property/LazyGlobalProperty.java +++ b/olcut-core/src/main/java/com/oracle/labs/mlrg/olcut/config/property/LazyGlobalProperty.java @@ -51,4 +51,13 @@ public String toString() { return getValue(); } + @Override + public boolean equals(Object other) { + return super.equals(other); + } + + @Override + public int hashCode() { + return super.hashCode(); + } } diff --git a/olcut-core/src/main/java/com/oracle/labs/mlrg/olcut/config/xml/SAXLoader.java b/olcut-core/src/main/java/com/oracle/labs/mlrg/olcut/config/xml/SAXLoader.java index 4e23bef8..23c3e5e9 100644 --- a/olcut-core/src/main/java/com/oracle/labs/mlrg/olcut/config/xml/SAXLoader.java +++ b/olcut-core/src/main/java/com/oracle/labs/mlrg/olcut/config/xml/SAXLoader.java @@ -409,9 +409,6 @@ public void endElement(String uri, String localName, String qName) rpd = null; overriding = false; break; - case PROPERTY: - // nothing to do - break; case PROPERTYLIST: if (rpd.contains(itemListName) && !overriding) { throw new SAXParseException("Duplicate property: " @@ -444,6 +441,9 @@ public void endElement(String uri, String localName, String qName) entryMap = null; } break; + default: + // Nothing to do + break; } } diff --git a/olcut-core/src/main/java/com/oracle/labs/mlrg/olcut/provenance/ProvenanceUtil.java b/olcut-core/src/main/java/com/oracle/labs/mlrg/olcut/provenance/ProvenanceUtil.java index d2f99cac..7a7558c4 100644 --- a/olcut-core/src/main/java/com/oracle/labs/mlrg/olcut/provenance/ProvenanceUtil.java +++ b/olcut-core/src/main/java/com/oracle/labs/mlrg/olcut/provenance/ProvenanceUtil.java @@ -137,7 +137,7 @@ public static String bytesToHexString(byte[] bytes) { public static String hashList(HashType hashType, List list) { MessageDigest md = hashType.getDigest(); for (String curString : list) { - md.digest(curString.getBytes(StandardCharsets.UTF_8)); + md.update(curString.getBytes(StandardCharsets.UTF_8)); } return bytesToHexString(md.digest()); } diff --git a/olcut-core/src/main/java/com/oracle/labs/mlrg/olcut/util/FileUtil.java b/olcut-core/src/main/java/com/oracle/labs/mlrg/olcut/util/FileUtil.java index a1832de1..d2cec20c 100644 --- a/olcut-core/src/main/java/com/oracle/labs/mlrg/olcut/util/FileUtil.java +++ b/olcut-core/src/main/java/com/oracle/labs/mlrg/olcut/util/FileUtil.java @@ -33,6 +33,7 @@ import java.io.File; import java.io.IOException; import java.io.RandomAccessFile; +import java.util.logging.Level; import java.util.logging.Logger; /** @@ -55,14 +56,20 @@ public static void deleteDirectory(File dir) { return; } File[] fs = dir.listFiles(); - for(File f : fs) { - if(f.isDirectory()) { - deleteDirectory(f); - } else { - f.delete(); + if (fs != null) { + for (File f : fs) { + if (f.isDirectory()) { + deleteDirectory(f); + } else { + if (!f.delete()) { + logger.log(Level.INFO,"Failed to delete file: " + f.getName()); + } + } } } - dir.delete(); + if (!dir.delete()) { + logger.log(Level.INFO, "Failed to delete directory: " + dir.getName()); + } } public static void dirCopier(File source, File target) throws IOException { @@ -82,15 +89,17 @@ public static void dirCopier(File source, File target) throws IOException { private static void copyDir(File sd, File td) throws java.io.IOException { File[] files = sd.listFiles(); - for(File f : files) { - File nt = new File(td, f.getName()); - if(f.isDirectory()) { - if(!nt.mkdir()) { - throw new IOException("Failed to make dir " + nt.getName()); + if (files != null) { + for (File f : files) { + File nt = new File(td, f.getName()); + if (f.isDirectory()) { + if (!nt.mkdir()) { + throw new IOException("Failed to make dir " + nt.getName()); + } + copyDir(f, nt); + } else { + copyFile(f, nt); } - copyDir(f, nt); - } else { - copyFile(f, nt); } } } diff --git a/olcut-core/src/main/java/com/oracle/labs/mlrg/olcut/util/IOUtil.java b/olcut-core/src/main/java/com/oracle/labs/mlrg/olcut/util/IOUtil.java index 735e7f3c..c87a508d 100644 --- a/olcut-core/src/main/java/com/oracle/labs/mlrg/olcut/util/IOUtil.java +++ b/olcut-core/src/main/java/com/oracle/labs/mlrg/olcut/util/IOUtil.java @@ -47,6 +47,7 @@ import java.io.PushbackInputStream; import java.io.Serializable; import java.io.UncheckedIOException; +import java.io.UnsupportedEncodingException; import java.net.MalformedURLException; import java.net.URI; import java.net.URISyntaxException; @@ -167,7 +168,7 @@ public static BufferedReader getReader(File file, String charSet) throws FileNot * @throws IOException If an error occurred when opening the file. */ public static PrintWriter getPrintWriter(String filename, boolean zipped) throws FileNotFoundException, IOException { - return new PrintWriter(new OutputStreamWriter(innerGetOutputStream(filename,zipped))); + return new PrintWriter(new OutputStreamWriter(innerGetOutputStream(filename,zipped),StandardCharsets.UTF_8)); } /** @@ -373,7 +374,11 @@ public static PrintStream getPrintStream(File file, int bufferSize) throws FileN file.getParentFile().mkdirs(); } BufferedOutputStream bos = new BufferedOutputStream(new FileOutputStream(file), bufferSize); - return new PrintStream(bos, false); + try { + return new PrintStream(bos, false, StandardCharsets.UTF_8.name()); + } catch (UnsupportedEncodingException e) { + throw new IllegalStateException("UTF-8 isn't supported. Not sure what's wrong with the world.",e); + } } public static OutputStream getOutputStream(String path) throws FileNotFoundException { diff --git a/olcut-core/src/main/java/com/oracle/labs/mlrg/olcut/util/SortUtil.java b/olcut-core/src/main/java/com/oracle/labs/mlrg/olcut/util/SortUtil.java index 4f9395bd..b15bfd58 100644 --- a/olcut-core/src/main/java/com/oracle/labs/mlrg/olcut/util/SortUtil.java +++ b/olcut-core/src/main/java/com/oracle/labs/mlrg/olcut/util/SortUtil.java @@ -32,6 +32,7 @@ import java.util.Arrays; import java.util.Collections; import java.util.List; +import java.util.Objects; import java.util.function.DoublePredicate; import java.util.function.IntPredicate; import java.util.function.Predicate; @@ -164,6 +165,19 @@ public int compareTo(SortIntegerTuple o) { return Integer.compare(o.value, value); } } + + @Override + public boolean equals(Object o) { + if (this == o) return true; + if (o == null || getClass() != o.getClass()) return false; + SortIntegerTuple that = (SortIntegerTuple) o; + return value == that.value; + } + + @Override + public int hashCode() { + return Objects.hash(value); + } } /** @@ -230,6 +244,19 @@ public int compareTo(SortDoubleTuple o) { return Double.compare(o.value, value); } } + + @Override + public boolean equals(Object o) { + if (this == o) return true; + if (o == null || getClass() != o.getClass()) return false; + SortDoubleTuple that = (SortDoubleTuple) o; + return Double.compare(that.value, value) == 0; + } + + @Override + public int hashCode() { + return Objects.hash(value); + } } /** @@ -344,5 +371,18 @@ public int compareTo(SortTuple o) { return o.value.compareTo(value); } } + + @Override + public boolean equals(Object o) { + if (this == o) return true; + if (o == null || getClass() != o.getClass()) return false; + SortTuple sortTuple = (SortTuple) o; + return value.equals(sortTuple.value); + } + + @Override + public int hashCode() { + return Objects.hash(value); + } } } diff --git a/olcut-extras/src/main/java/com/oracle/labs/mlrg/olcut/extras/completion/GenCompletion.java b/olcut-extras/src/main/java/com/oracle/labs/mlrg/olcut/extras/completion/GenCompletion.java index 9c66ea9a..c6eac49d 100644 --- a/olcut-extras/src/main/java/com/oracle/labs/mlrg/olcut/extras/completion/GenCompletion.java +++ b/olcut-extras/src/main/java/com/oracle/labs/mlrg/olcut/extras/completion/GenCompletion.java @@ -56,7 +56,7 @@ public static OptionsClass processOptionsClass(ClassNode cn) { if (vAnno.desc.equals(OptionCompletion.OPTION_CLASS)) { if(vAnno.values.get(0).equals("charName")) { // charName is optional and may not be present optionsClass.addCompletion( - new OptionCompletion((char) vAnno.values.get(1), (String) vAnno.values.get(3), (String) vAnno.values.get(5))); + new OptionCompletion((Character) vAnno.values.get(1), (String) vAnno.values.get(3), (String) vAnno.values.get(5))); } else { optionsClass.addCompletion( new OptionCompletion((String) vAnno.values.get(1), (String) vAnno.values.get(3))); diff --git a/pom.xml b/pom.xml index b4ea6528..0ca426ec 100644 --- a/pom.xml +++ b/pom.xml @@ -247,6 +247,11 @@ + + org.apache.maven.plugins + maven-deploy-plugin + 3.0.0-M1 +