Fixed FileProject.delete() bug. Preparing for libpit 1.1.6

This commit is contained in:
Jonathan Bernard 2010-02-24 07:58:37 -06:00
parent 240329aaef
commit 978f1f0d3e
16 changed files with 113 additions and 13 deletions

12
issues/libpit/0018c4.rst Normal file
View File

@ -0,0 +1,12 @@
FileProject.delete() does not handle sub-projects correctly.
============================================================
FileProject.delete() deletes the project directory if the directory is empty,
but fails to do so if the directory is not empty.
Initial Recommendation
----------------------
Loop through the issues and delete the files, loop through the projects and
call Project.delete(). Alternatively, use File.deleteDir() rather than
File.delete()

2
issues/libpit/0019t4.rst Normal file
View File

@ -0,0 +1,2 @@
Add unit tests for FileIssue.delete()
=====================================

2
issues/libpit/0020t4.rst Normal file
View File

@ -0,0 +1,2 @@
Add unit tests for FileProject.delete()
=======================================

View File

@ -1,10 +1,10 @@
#Wed Feb 24 03:03:11 CST 2010
#Wed Feb 24 04:27:18 CST 2010
build.dir=build
src.dir=src
lib.shared.dir=../shared-libs
test.dir=test
build.number=4
expected.application.version=1.1.5
build.number=5
expected.application.version=1.1.6
lib.dir=lib
release.dir=release
release.jar=pit-${application.version}.jar

View File

@ -41,6 +41,8 @@ public class FileIssue extends Issue {
source.write(text)
}
public boolean delete() { return source.delete() }
public static boolean isValidFilename(String name) {
return name ==~ /(\d+)([bcft])(\d).*/
}

View File

@ -72,7 +72,7 @@ class FileProject extends Project {
return new FileProject(newDir)
}
public boolean delete() { return source.delete() }
public boolean delete() { return source.deleteDir() }
@Override
public String toString() { return name }

View File

@ -2,7 +2,7 @@ package com.jdbernard.pit
import java.lang.IllegalArgumentException as IAE
public class Issue {
public abstract class Issue {
protected String id
protected Category category
@ -38,4 +38,6 @@ public class Issue {
@Override
public String toString() { return "${id}(${priority}): ${category} ${title}" }
public abstract boolean delete()
}

View File

@ -121,6 +121,8 @@ class FileProjectTest {
assertEquals rootProj.name, 'renamedTestDir'
assertTrue new File('renamedTestDir').exists()
assert rootProj.source.deleteDir()
}
@Test void testCreateNewIssue() {

View File

@ -15,16 +15,16 @@ class FilterTest {
proj = new MockProject('proj1')
def issue = new Issue( '0000', Category.TASK, 5)
def issue = new MockIssue( '0000', Category.TASK, 5)
proj.issues['0000'] = issue
issue = new Issue('0001', Category.BUG, 3)
issue = new MockIssue('0001', Category.BUG, 3)
proj.issues['0001'] = issue
issue = new Issue('0002', Category.CLOSED, 9)
issue = new MockIssue('0002', Category.CLOSED, 9)
proj.issues['0002'] = issue
issue = new Issue('0003', Category.FEATURE, 0)
issue = new MockIssue('0003', Category.FEATURE, 0)
proj.issues['0003'] = issue
def subProj = new MockProject('subproj1')

View File

@ -0,0 +1,6 @@
package com.jdbernard.pit
public class MockIssue extends Issue {
public MockIssue(String id, Category c, int p) { super (id, c, p) }
public boolean delete() { return true }
}

View File

@ -6,6 +6,7 @@ import com.jdbernard.pit.Issue
import com.jdbernard.pit.Project
import com.jdbernard.pit.FileProject
import groovy.beans.Bindable
import java.awt.Point
import java.awt.event.MouseEvent
import javax.swing.DefaultListModel
import javax.swing.JFileChooser
@ -31,7 +32,9 @@ categoryIcons = [:]
// filter for projects and issues
filter = new Filter(categories: [])
@Bindable def popupProject = null
popupProject = null
popupIssue = null
// initialize category-related view data
Category.values().each {
@ -71,11 +74,20 @@ showProjectPopup = { project, x, y ->
projectPopupMenu.show(projectTree, x, y)
}
showIssuePopup = { issue, x, y ->
popupIssue = issue
issuePopupMenu.eachWithIndex { menuItem, idx ->
if (idx != 0) menuItem.enabled = issue != null }
issuePopupMenu.show(issueList, x, y)
}
/* ****************
* GUI components
* ****************/
openDialog = fileChooser(fileSelectionMode: JFileChooser.DIRECTORIES_ONLY)
//newIssueDialog = dialog()
projectPopupMenu = popupMenu() {
menuItem('New Project...',
actionPerformed: {
@ -85,15 +97,64 @@ projectPopupMenu = popupMenu() {
if (!popupProject) popupProject = model.rootProject
def newProject = popupProject.createNewProject(name)
popupProject.projects[(newProject.name)] = newProject
projectTree.model = new DefaultTreeModel(
makeNodes(model.rootProject))
})
menuItem('Delete Project',
actionPerformed: { popupProject.delete() })
actionPerformed: {
if (!popupProject) return
popupProject.delete()
// do not like, tied to Project implementation
model.rootProject = new FileProject(model.rootProject.source)
})
}
issuePopupMenu = popupMenu() {
menuItem('New Issue...',
actionPerformed: { })
menuItem('Delete Issue',
actionPerformed: {
if (!popupIssue) return
popupIssue.delete()
})
separator()
menu('Change Category') {
Category.values().each { category ->
menuItem(category.toString(),
icon: categoryIcons[(category)],
actionPerformed: {
if (!popupIssue) return
popupIssue.category = category
issueList.invalidate()
})
}
}
menuItem('Change Priority...',
actionPerformed: {
if (!popupIssue) return
def newPriority = JOptionPane.showInputDialog(frame,
'New priority (0-9)', 'Change Priority...',
JOptionPane.QUESTION_MESSAGE)
try { popupIssue.priority = newPriority.toInteger() }
catch (exception) {
JOptionPane.showMessage(frame, 'The priority value must ' +
'be an integer in [0-9].', 'Change Priority...',
JOptionPane.ERROR_MESSAGE)
return
}
issueList.invalidate()
})
}
frame = application(title:'Personal Issue Tracker',
locationRelativeTo: null,
minimumSize: [600, 400],
//size:[320,480],
pack:true,
//location:[50,50],
@ -186,7 +247,16 @@ frame = application(title:'Personal Issue Tracker',
cellRenderer: new IssueListCellRenderer(
issueIcons: categoryIcons),
selectionMode: ListSelectionModel.SINGLE_SELECTION,
valueChanged: { displayIssue(issueList.selectedValue) })
valueChanged: { displayIssue(issueList.selectedValue) },
mouseClicked: { evt ->
if (evt.button == MouseEvent.BUTTON3) {
issueList.selectedIndex = issueList.locationToIndex(
[evt.x, evt.y] as Point)
showIssuePopup(issueList.selectedValue,
evt.x, evt.y)
}
})
}
scrollPane(constraints: "bottom") {
issueTextArea = textArea()

Binary file not shown.

Binary file not shown.

View File

@ -15,6 +15,8 @@ public class IssueListCellRenderer extends DefaultListCellRenderer {
selected, hasFocus)
if (issueIcons[(value.category)])
component.setIcon(issueIcons[(value.category)])
component.text = "<html><tt>${value.id} (${value.priority}): </tt>" +
"${value.title}</html>"
return component
}
}

View File

@ -1 +1 @@
application.version=1.1.5
application.version=1.1.6