Skip to content

Commit

Permalink
Merge pull request #11 from terry-norbraten/main
Browse files Browse the repository at this point in the history
Bring source code up to JDK 11 target
  • Loading branch information
apease authored Feb 7, 2025
2 parents e8ee7ff + 8488c63 commit c01a2ae
Show file tree
Hide file tree
Showing 12 changed files with 270 additions and 222 deletions.
66 changes: 59 additions & 7 deletions build.xml
Original file line number Diff line number Diff line change
Expand Up @@ -32,11 +32,23 @@
<property name="app.name" value="sigmaUtils"/>
<property name="build.home" value="build"/>
<property name="build.classes" value="${build.home}/classes"/>
<property name="build.test.classes" value="${build.home}/test-classes"/>
<property name="build.test.classes" value="${build.home}/test/classes"/>
<!--<property name="build.lib" value="${build.home}/lib"/>-->
<property environment="env"/>

<property name="javac.release" value="11"/>
<property name="unit.test.suite" value="com.articulate.sigma.UnitTestSuite"/>
<property name="reports.dir" value="${build.home}/test/results"/>
<property name="report.html" value="file:${basedir}/${reports.dir}/html/index.html"/>

<condition property="isUnixNotMac">
<and>
<os family="unix"/>
<not>
<os family="mac"/>
</not>
</and>
</condition>

<target name="init" depends="init-ivy">
<echo>Java Version via Ant: ${ant.java.version}</echo>
Expand Down Expand Up @@ -86,20 +98,60 @@
<src refid="test.sourcepath"/>
<classpath refid="classpath.test"/>
</javac>
<mkdir dir="${reports.dir}"/>
</target>

<target name="test" depends="test-compile">
<junit printsummary="on" haltonfailure="yes" fork="true">
<!--
==========
UNIT TESTS
==========
-->

<target name="test" depends="test.unit"/>
<target name="test.unit" depends="test-compile" description="Runs the UnitTestSuite">
<junit printsummary="on"
showoutput="yes"
haltonfailure="yes"
fork="true">
<formatter type="plain" usefile="false"/>
<classpath>
<path refid="classpath.test"/>
<pathelement location="${build.test.classes}"/>
</classpath>
<formatter type="brief" usefile="false"/>
<batchtest>
<fileset dir="test/unit/java" includes="**/*Test.java"/>
</batchtest>
<test name="${unit.test.suite}" haltonfailure="no" todir="${reports.dir}">
<formatter type="xml"/>
</test>
</junit>
<antcall target="junit.report"/>
</target>
<target name="junit.report" >
<junitreport todir="${reports.dir}">
<fileset dir="${reports.dir}">
<include name="TEST-*.xml"/>
</fileset>
<report format="frames" todir="${reports.dir}/html"/>
</junitreport>
<!--<antcall target="open.junit.report"/>-->
</target>
<target name="open.junit.report" depends="report.mac,report.unix"/>
<target name="report.mac" unless="isUnixNotMac">
<exec executable="sh" osfamily="mac">
<arg value="-c"/>
<arg value="open -u ${report.html}"/>
</exec>
</target>
<target name="report.unix" if="isUnixNotMac">
<exec executable="sh" osfamily="unix">
<arg value="-c"/>
<arg value="xdg-open ${report.html}"/>
</exec>
</target>

<!--
=====
ADMIN
=====
-->

<!-- target name="all" depends="dist, api_doc" -->
<target name="all" depends="clean,test">
Expand Down
34 changes: 0 additions & 34 deletions nbproject/ide-targets.xml
Original file line number Diff line number Diff line change
Expand Up @@ -94,22 +94,6 @@
===================
-->

<target name="test.unit" depends="clean,test-compile" description="Runs the UnitTestSuite">
<junit printsummary="yes"
haltonfailure="yes"
showoutput="yes"
fork="yes">
<jvmarg line="${run.jvmargs}"/>
<formatter type="plain" usefile="false"/>
<classpath>
<path refid="tcp"/>
</classpath>
<test name="${unit.test.suite}" haltonfailure="no" todir="${reports.dir}">
<formatter type="xml"/>
</test>
</junit>
<antcall target="junit.report"/>
</target>
<target name="run-selected-test-in-unit" depends="clean,test-compile">
<fail unless="test.class">Must set property 'test.class'</fail>
<junit printsummary="yes"
Expand All @@ -126,24 +110,6 @@
</test>
</junit>
</target>
<target name="junit.report" >
<junitreport todir="${reports.dir}">
<fileset dir="${reports.dir}">
<include name="TEST-*.xml"/>
</fileset>
<report format="frames" todir="${reports.dir}/html"/>
</junitreport>
<antcall target="open.junit.report"/>
</target>
<target name="open.junit.report">
<exec executable="sh" osfamily="mac">
<arg value="-c"/>
<arg value="open -u ${report.html}"/>
</exec>
<exec executable="sh" osfamily="unix">
<arg value="xdg-open ${report.html}"/>
</exec>
</target>

<!--
=====
Expand Down
1 change: 1 addition & 0 deletions src/java/com/articulate/sigma/utils/AVPair.java
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ public int compareTo(Object avp) throws ClassCastException {

/*****************************************************************
*/
@Override
public String toString() {

return "[" + attribute + "," + value + "]";
Expand Down
49 changes: 16 additions & 33 deletions src/java/com/articulate/sigma/utils/FileUtil.java
Original file line number Diff line number Diff line change
Expand Up @@ -41,8 +41,7 @@ public static List<String> readLines(String filename, boolean separateSentences)
List<String> documents = Lists.newArrayList();
File f = new File(filename);
String line = null;
try {
BufferedReader bf = new BufferedReader(new FileReader(f));
try (BufferedReader bf = new BufferedReader(new FileReader(f))) {
while ((line = bf.readLine()) != null) {
if (!includeBlanks && (line == null || line.equals("")))
continue;
Expand All @@ -51,7 +50,7 @@ public static List<String> readLines(String filename, boolean separateSentences)
}
catch (Exception e) {
e.printStackTrace();
System.out.println("FileUtil.readLines(): " +
System.err.println("FileUtil.readLines(): " +
"Unable to read line in file. Last line successfully read was: " + line);
}
return documents;
Expand All @@ -67,7 +66,7 @@ public static void delete(String filename) {
}
catch (Exception e) {
e.printStackTrace();
System.out.println("FileUtil.delete(): Unable to delete: " + filename);
System.err.println("FileUtil.delete(): Unable to delete: " + filename);
}
}

Expand All @@ -78,20 +77,16 @@ public static void writeLines(String filename, Collection<String> lines) {
System.out.println("FileUtil.writeLines(): filename: " + filename);
System.out.println("FileUtil.writeLines(): " + lines.size());
File f = new File(filename);
PrintWriter pw = null;
try {
pw = new PrintWriter(f);
try (PrintWriter pw = new PrintWriter(f)) {
for (String line : lines) {
pw.println(line);
//System.out.println("FileUtil.writeLines(): line: " + line);
}
}
catch (Exception e) {
e.printStackTrace();
System.out.println("FileUtil.writeLines(): Unable to write line in file " + filename);
System.err.println("FileUtil.writeLines(): Unable to write line in file " + filename);
}
pw.flush();
pw.close();
}

/****************************************************************
Expand All @@ -104,21 +99,21 @@ public static void splitStatements(String filename, String pattern) {

String fnameMinus = filename + ".minus";
String fnameNew = filename + ".new";
PrintWriter pwMinus = null;
PrintWriter pwNew = null;
includeBlanks = true;
try {
pwNew = new PrintWriter(new FileWriter(fnameNew, false));
pwMinus = new PrintWriter(new FileWriter(fnameMinus, false));
ArrayList<String> lines = (ArrayList) readLines(filename, false);
try (PrintWriter pwNew = new PrintWriter(new FileWriter(fnameNew, false));
PrintWriter pwMinus = new PrintWriter(new FileWriter(fnameMinus, false))) {
List<String> lines = (ArrayList) readLines(filename, false);
System.out.println("splitSttaements(): read file " + filename + " with " + lines.size() + " lines");
String s;
int parenLevel;
boolean inQuote;
for (int i = 0; i < lines.size(); i++) {
String s = lines.get(i);
s = lines.get(i);
System.out.println(s);
if (s.contains(pattern) && !s.startsWith(";")) {
pwNew.println(s);
int parenLevel = 0;
boolean inQuote = false;
parenLevel = 0;
inQuote = false;
do {
for (int j = 0; j < s.length(); j++) {
if (s.charAt(j) == '(' && !inQuote)
Expand All @@ -140,21 +135,9 @@ public static void splitStatements(String filename, String pattern) {
}
}
catch (Exception ex) {
System.out.println("Error with " + filename + ": " + ex.getMessage());
System.err.println("Error with " + filename + ": " + ex.getMessage());
ex.printStackTrace();
}
finally {
try {
if (pwNew != null)
pwNew.close();
if (pwMinus != null)
pwMinus.close();
}
catch (Exception ioe) {
ioe.printStackTrace();
System.out.println(ioe.getMessage());
}
}
}

/****************************************************************
Expand Down Expand Up @@ -185,7 +168,7 @@ public static Collection<String> walk(String path) {

File root = new File(path);
File[] list = root.listFiles();
ArrayList<String> result = new ArrayList<>();
List<String> result = new ArrayList<>();
if (list == null) return result;
for (File f : list) {
if (f.isDirectory())
Expand Down
30 changes: 16 additions & 14 deletions src/java/com/articulate/sigma/utils/MBoxReader.java
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,9 @@
import java.util.ArrayList;
import java.util.HashMap;
import java.util.HashSet;
import java.util.List;
import java.util.Map;
import java.util.Set;
import java.util.regex.Matcher;
import java.util.regex.Pattern;

Expand All @@ -27,10 +30,10 @@ public class MBoxReader {
//Enumeration of the property names we'll use:
public static String PROP_NAME_SENDER = "Sender";
public static String PROP_NAME_DATE = "MessageDate";
public static String PROP_NAME_SENDER_INFO = "SenderInfo";
public static String PROP_NAME_SENDER_INFO = "SenderInfo";
public static String PROP_NAME_BODY = "Body";
public static String PROP_NAME_FACTS = "Facts";
public static HashSet<HashMap<String,String>> records = new HashSet<>();
public static Set<Map<String,String>> records = new HashSet<>();

/** ***************************************************************
* This regular expression will be used to extract fields from the From
Expand All @@ -49,7 +52,7 @@ public class MBoxReader {
public void execute(String path) {

//Get the paths of the mbox files to process:
ArrayList<String> mboxFiles = new ArrayList<>();
List<String> mboxFiles = new ArrayList<>();
File folder = new File(path);
if (!folder.exists()) {
System.out.println("Error in MBoxReader.execute(): '" + folder + "' doesn't exist ");
Expand All @@ -62,9 +65,9 @@ public void execute(String path) {
listOfFiles = folder.listFiles();

for (File file : listOfFiles) {
if (file.getName().indexOf(".") == -1)
if (!file.getName().contains("."))
mboxFiles.add(file.getName());
if (file.getName().indexOf(".sbd") != -1)
if (file.getName().contains(".sbd"))
execute(folder.getName() + File.separator + file.getName());
}

Expand All @@ -74,9 +77,9 @@ public void execute(String path) {
// Now that we have processed the configuration, we're ready to
// ;oop over each of the files to parse:
for (String file : mboxFiles) {
try {
try
//Open the current file:
BufferedReader reader = new BufferedReader(new FileReader(file));
(BufferedReader reader = new BufferedReader(new FileReader(file))) {
// Process the current file. The first line of each message should be
// "From <sender> <date> <more info>":
String curFromLine = reader.readLine();
Expand Down Expand Up @@ -104,7 +107,7 @@ public void execute(String path) {

//Create a new Record for this message and add the from line
//fields as properties:
HashMap<String,String> record = new HashMap();
Map<String,String> record = new HashMap();

record.put(PROP_NAME_SENDER, sender);
record.put(PROP_NAME_DATE, date);
Expand All @@ -120,7 +123,6 @@ public void execute(String path) {
curFromLine = processBody(reader, record);
records.add(record); //Emit the completed record.
}
reader.close(); //close the current file.
}
catch (IOException e) {
//There was a problem processing the current file, but maybe the
Expand All @@ -133,7 +135,7 @@ public void execute(String path) {

/** ***************************************************************
*/
private void processHeaders(BufferedReader reader, HashMap<String,String> record) {
private void processHeaders(BufferedReader reader, Map<String,String> record) {

try {
//Loop until we reach a blank line, which indicates the end of the
Expand All @@ -157,7 +159,7 @@ private void processHeaders(BufferedReader reader, HashMap<String,String> record
}
}
catch (IOException ioe) {
System.out.println("Error in MBoxReader.processHeaders()");
System.err.println("Error in MBoxReader.processHeaders()");
ioe.printStackTrace();
}
}
Expand All @@ -178,7 +180,7 @@ private void processHeaders(BufferedReader reader, HashMap<String,String> record
*
* @throws IOException
*/
private String processBody(BufferedReader reader, HashMap record) {
private String processBody(BufferedReader reader, Map<String,String> record) {

String body = "";
String fromLine = null;
Expand All @@ -203,7 +205,7 @@ private String processBody(BufferedReader reader, HashMap record) {
record.put(PROP_NAME_BODY, body); // Add the body to the record:
}
catch (IOException ioe) {
System.out.println("Error in MBoxReader.processBody()");
System.err.println("Error in MBoxReader.processBody()");
ioe.printStackTrace();
}
return fromLine;
Expand All @@ -214,7 +216,7 @@ private String processBody(BufferedReader reader, HashMap record) {
public void extractInfo() {

System.out.println("In MBoxReader.extractInfo()");
for (HashMap<String,String> element : records) {
for (Map<String,String> element : records) {
if (element.keySet().contains(PROP_NAME_BODY)) {
String body = com.articulate.sigma.utils.StringUtil.removeHTML(element.get(PROP_NAME_BODY));
System.out.println("In MBoxReader.extractInfo() from " + body);
Expand Down
Loading

0 comments on commit c01a2ae

Please sign in to comment.