diff --git a/libpit/build.xml b/libpit/build.xml index 916c7a6..e1c284e 100644 --- a/libpit/build.xml +++ b/libpit/build.xml @@ -82,7 +82,7 @@ classpathref="groovyc.classpath"/> </target> - <target name="run-tests" depends="compile-tests"> + <target name="test" depends="compile-tests"> <junit fork="yes" haltonfailure="yes"> <classpath refid="test.classpath"/> <formatter type="brief" usefile="false" /> @@ -94,7 +94,7 @@ </junit> </target> - <target name="build" depends="compile,run-tests"> + <target name="build" depends="compile,test"> <mkdir dir="${build.dir}/jar"/> <jar destfile="${build.dir}/jar/pit-${application.version}.${build.number.final}.jar" diff --git a/libpit/project.properties b/libpit/project.properties index 7d449b9..afcc55b 100644 --- a/libpit/project.properties +++ b/libpit/project.properties @@ -1,10 +1,11 @@ +#Wed, 19 May 2010 08:06:01 -0500 #Sat Apr 24 17:08:00 CDT 2010 build.dir=build src.dir=src lib.shared.dir=../shared-libs test.dir=test -build.number=8 -expected.application.version=2.3.0 +build.number=1 +expected.application.version=2.3.1 lib.dir=lib release.dir=release release.jar=pit-${application.version}.jar diff --git a/libpit/release/pit-2.3.0.jar b/libpit/release/pit-2.3.0.jar deleted file mode 100644 index ba56089..0000000 Binary files a/libpit/release/pit-2.3.0.jar and /dev/null differ diff --git a/libpit/release/pit-2.3.1.jar b/libpit/release/pit-2.3.1.jar new file mode 100644 index 0000000..bf362a5 Binary files /dev/null and b/libpit/release/pit-2.3.1.jar differ diff --git a/libpit/src/com/jdbernard/pit/FileIssue.groovy b/libpit/src/com/jdbernard/pit/FileIssue.groovy index 91016d9..eeabe55 100644 --- a/libpit/src/com/jdbernard/pit/FileIssue.groovy +++ b/libpit/src/com/jdbernard/pit/FileIssue.groovy @@ -23,31 +23,64 @@ public class FileIssue extends Issue { this.source = file - text = file.text + super.@text = file.text } - public void setCategory(Category c) { - super.setCategory(c) - source.renameTo(new File(source.canonicalFile.parentFile, getFilename())) + public void setCategory(Category c) throws IOException { + boolean renamed + renamed = source.renameTo(new File(source.canonicalFile.parentFile, + makeFilename(id, c, status, priority))) + + if (!renamed) + throw new IOException("I was unable to set the category. " + + "I need to rename the file for this issue, but something is " + + "preventing me from doing so (maybe the path to the file is " + + "no longer valid, or maybe the file is currently open in " + + "some other program).") + else super.setCategory(c) } - public void setStatus(Status s) { - super.setStatus(s) - source.renameTo(new File(source.canonicalFile.parentFile, getFilename())) + public void setStatus(Status s) throws IOException { + boolean renamed + renamed = source.renameTo(new File(source.canonicalFile.parentFile, + makeFilename(id, category, s, priority))) + + if (!renamed) + throw new IOException("I was unable to set the status. " + + "I need to rename the file for this issue, but something is " + + "preventing me from doing so (maybe the path to the file is " + + "no longer valid, or maybe the file is currently open in " + + "some other program).") + else super.setStatus(s) } - public void setPriority(int p) { - super.setPriority(p) - source.renameTo(new File(source.canonicalFile.parentFile, getFilename())) + public void setPriority(int p) throws IOException { + boolean renamed + renamed = source.renameTo(new File(source.canonicalFile.parentFile, + makeFilename(id, category, status, p))) + + if (!renamed) + throw new IOException("I was unable to set the priority. " + + "I need to rename the file for this issue, but something is " + + "preventing me from doing so (maybe the path to the file is " + + "no longer valid, or maybe the file is currently open in " + + "some other program).") + else super.setPriority(p) } public String getFilename() { return makeFilename(id, category, status, priority) } - public void setText(String text) { + public void setText(String text) throws IOException { + try { source.write(text) } + catch (IOException ioe) { + throw new IOException("I could not save the new text for this " + + "issue. I can not write to the file for this issue. I do not" + + " know why, I am sorry (maybe the file can not be reached).") + } + super.setText(text) - source.write(text) } public boolean delete() { return source.delete() } diff --git a/libpit/src/com/jdbernard/pit/Issue.groovy b/libpit/src/com/jdbernard/pit/Issue.groovy index 688b1e8..2d12877 100644 --- a/libpit/src/com/jdbernard/pit/Issue.groovy +++ b/libpit/src/com/jdbernard/pit/Issue.groovy @@ -26,7 +26,7 @@ public abstract class Issue { public Category getCategory() { return category } - public void setCategory(Category c) { + public void setCategory(Category c) throws IOException { if (c == null) throw new IAE("Category cannot be null.") @@ -35,7 +35,7 @@ public abstract class Issue { public Status getStatus() { return status } - public void setStatus(Status s) { + public void setStatus(Status s) throws IOException { if (s == null) throw new IAE("Status cannot be null.") @@ -44,13 +44,15 @@ public abstract class Issue { public int getPriority() { return priority } - public void setPriority(int p) { priority = Math.min(9, Math.max(0, p)) } + public void setPriority(int p) throws IOException { + priority = Math.min(9, Math.max(0, p)) + } public String getTitle() { return text.readLines()[0] } public String getText() { return text } - public void setText(String t) { text = t } + public void setText(String t) throws IOException { text = t } public boolean hasDelivery() { return deliveryDate == null } diff --git a/libpit/test/com/jdbernard/pit/FileIssueTest.groovy b/libpit/test/com/jdbernard/pit/FileIssueTest.groovy index 932df49..7c9b392 100644 --- a/libpit/test/com/jdbernard/pit/FileIssueTest.groovy +++ b/libpit/test/com/jdbernard/pit/FileIssueTest.groovy @@ -42,8 +42,13 @@ class FileIssueTest { assertEquals issues[0].category, Category.FEATURE assertEquals issues[1].category, Category.TASK - issues[0].category = Category.TASK - issues[1].category = Category.BUG + try { + issues[0].category = Category.TASK + issues[1].category = Category.BUG + } catch (Exception e) { + Assert.fail("An unexpected Exception occurred: " + + e.getLocalizedMessage()) + } assertEquals issues[0].category, Category.TASK assertEquals issues[1].category, Category.BUG @@ -52,6 +57,27 @@ class FileIssueTest { assertTrue new File(testDir, '0002bs5.rst').exists() assertFalse new File(testDir, '0001fn1.rst').exists() assertFalse new File(testDir, '0002ts5.rst').exists() + + } + + @Test void testSetCategoryFails() { + FileInputStream fin + try { + // get a lock to the file to prevent the rename + def issueFile = new File('0001fn1.rst') + fin = new FileInputStream(issueFile) + + // try to set the category + issues[0].category = Category.TASK + + // should throw IOE before here + Assert.fail() + } catch (IOException ioe) { + } catch (Exception e) { + Assert.fail("Unexpected exception: " + e.getLocalizedMessage()) + } finally { + if (fin != null) fin.close() + } } @Test void testSetStatus() { @@ -59,8 +85,13 @@ class FileIssueTest { assertEquals issues[0].status, Status.NEW assertEquals issues[1].status, Status.RESOLVED - issues[0].status = Status.RESOLVED - issues[1].status = Status.REJECTED + try { + issues[0].status = Status.RESOLVED + issues[1].status = Status.REJECTED + } catch (Exception e) { + Assert.fail("An unexpected Exception occurred: " + + e.getLocalizedMessage()) + } assertTrue new File(testDir, '0001fs1.rst').exists() assertTrue new File(testDir, '0002tj5.rst').exists() @@ -68,13 +99,38 @@ class FileIssueTest { assertFalse new File(testDir, '0002ts5.rst').exists() } + @Test void testSetStatusFails() { + FileInputStream fin + try { + // get a lock to the file to prevent the rename + def issueFile = new File('0001fn1.rst') + fin = new FileInputStream(issueFile) + + // try to set the status + issues[0].status = Status.REJECTED + + // should throw IOE before here + Assert.fail() + } catch (IOException ioe) { + } catch (Exception e) { + Assert.fail("Unexpected exception: " + e.getLocalizedMessage()) + } finally { + if (fin != null) fin.close() + } + } + @Test void testSetPriority() { assertEquals issues[0].priority, 1 assertEquals issues[1].priority, 5 - issues[0].priority = 2 - issues[1].priority = 9 + try { + issues[0].priority = 2 + issues[1].priority = 9 + } catch (Exception e) { + Assert.fail("An unexpected Exception occurred: " + + e.getLocalizedMessage()) + } assertEquals issues[0].priority, 2 assertEquals issues[1].priority, 9 @@ -85,6 +141,26 @@ class FileIssueTest { assertFalse new File(testDir, '0002ts5.rst').exists() } + @Test void testSetPriorityFails() { + FileInputStream fin + try { + // get a lock to the file to prevent the rename + def issueFile = new File('0001fn1.rst') + fin = new FileInputStream(issueFile) + + // try to set the priority + issues[0].priority = 9 + + // should throw IOE before here + Assert.fail() + } catch (IOException ioe) { + } catch (Exception e) { + Assert.fail("Unexpected exception: " + e.getLocalizedMessage()) + } finally { + if (fin != null) fin.close() + } + } + @Test void testConstruction() { File issueFile = new File(testDir, '0001fn1.rst') Issue issue = new FileIssue(issueFile) @@ -100,6 +176,27 @@ class FileIssueTest { assertEquals issue.source , issueFile } + @Test void testSetTextFails() { + try { + // make the issue file un-writable + def issueFile = new File('0001fn1.rst') + if (issueFile.setReadOnly()) { + + // try to write something + issues[0].text = "This should fail to be written." + + // should throw IOE before here + Assert.fail() + } else { + println "Could not run testSetTextFails, unable to change " + + "the test isseu file's permissions." + } + } catch (IOException ioe) { + } catch (Exception e) { + Assert.fail("Unexpected exception: " + e.getLocalizedMessage()) + } + } + @Test void testMakeFilename() { assertEquals FileIssue.makeFilename('0001', Category.BUG, Status.NEW, 5), '0001bn5.rst' diff --git a/release/lib/pit-2.3.0.jar b/release/lib/pit-2.3.0.jar deleted file mode 100644 index ba56089..0000000 Binary files a/release/lib/pit-2.3.0.jar and /dev/null differ diff --git a/release/lib/pit-2.3.1.jar b/release/lib/pit-2.3.1.jar new file mode 100644 index 0000000..bf362a5 Binary files /dev/null and b/release/lib/pit-2.3.1.jar differ diff --git a/release/pit-swing-2.3.0.jar b/release/pit-swing-2.3.0.jar deleted file mode 100644 index ba32e1c..0000000 Binary files a/release/pit-swing-2.3.0.jar and /dev/null differ diff --git a/version.properties b/version.properties index f54e06c..5f32ed4 100644 --- a/version.properties +++ b/version.properties @@ -1 +1 @@ -application.version=2.3.0 +application.version=2.3.1