Incremental work on XML implementation.

This commit is contained in:
Jonathan Bernard committed 2011-05-27 10:25:57 -05:00
1 parent 482330d02a
commit 6c36d78b7d
106 files changed
+287 -9

No files matched your search

Regular → Executable
View File
File mode changed.
Regular → Executable
View File
File mode changed.
Regular → Executable
View File
File mode changed.
Regular → Executable
View File
File mode changed.
Regular → Executable
View File
File mode changed.
Regular → Executable
View File
File mode changed.
View File
File mode changed.
View File
File mode changed.
View File
File mode changed.
+3 -2
View File
@@ -63,7 +63,8 @@ public abstract class Issue {
public void setDeliveryDate(Date dd) { deliveryDate = dd }
@Override
public String toString() { return "${id}(${priority}-${status}): ${category} ${title}" }
public String toString() {
return "${id}(${priority}-${status}): ${category} ${title}"
}
public abstract boolean delete()
}
+3 -1
View File
@@ -33,5 +33,7 @@ public abstract class Project {
public abstract Project createNewProject(String name)
public abstract boolean delete()
public abstract boolean deleteIssue(Issue issue)
public abstract boolean deleteProject(Project project)
}
+8
View File
@@ -0,0 +1,8 @@
package com.jdbernard.pit
public abstract class Repository {
public abstract void persist()
public abstract Project[] getRootProjects()
public abstract Project createNewProject(String name)
}
View File
File mode changed.
+1 -1
View File
@@ -84,7 +84,7 @@ public class FileIssue extends Issue {
super.setText(text)
}
public boolean delete() { return source.delete() }
boolean deleteFile() { return source.deleteDir() }
public static boolean isValidFilename(String name) {
return name ==~ fileExp
+19 -1
View File
@@ -74,7 +74,25 @@ class FileProject extends Project {
return new FileProject(newDir)
}
public boolean delete() { return source.deleteDir() }
public boolean deleteIssue(Issue issue) {
if (!issues[(issue.id)]) return false
issues.remove(issue.id)
if (issue instanceof FileIssue)
return issue.deleteFile()
else return true
}
public boolean deleteProject(Project project) {
if (!projects[(project.name)]) return false
projects.remove(project.name)
if (project instanceof FileProject)
return project.source.delete()
return true
}
@Override
public String toString() { return name }
+22
View File
@@ -0,0 +1,22 @@
package com.jdbernard.pit.file
import com.jdbernard.pit.*
public class FileRepository extends Repository {
@Delegate FileProject fileProject
public FileRepository(File dir) {
assert dir.isDirectory()
fileProject = new FileProject(dir)
}
public void persist() {} // nothing to do
public Project[] getRootProjects() {
return fileProject.proejcts.values() as Project[]
}
public FileProject createNewProject(String name) {
return fileProject.createNewProject()
}
}
View File
File mode changed.
+64
View File
@@ -0,0 +1,64 @@
package com.jdbernard.pit.xml
import com.jdbernard.pit.*
public class XmlIssue extends Issue {
def issueNode
XmlProject project
XmlRepository repository
XmlIssue(def issueNode, XmlRepository repository, XmlProject project) {
super(issueNode.@id, issueNode.@category ?: Category.TASK,
issueNode.@status ?: Status.NEW, issueNode.@priority ?: 9)
this.issueNode = issueNode
this.project = project
this.repository = repository
}
XmlIssue(String id, Category c = Category.TASK, Status s = Status.NEW,
int p = 9, String text, XmlRepository repository, XmlProject project) {
super(id, c, s, p)
this.project = project
this.repository = repository
// Node constructor adds the node to the parent node
issueNode = new Node(project.projectNode, "Issue",
[id: id, category: c, status: s, priority: p])
this.text = text
issueNode.value = text
repository.persist()
}
public void setCategory(Category c) {
super.setCategory(c)
issueNode.@category = c.name()
repository.persist()
}
public void setStatus(Status s) {
super.setStatus(s)
issueNode.@status = s.name()
repository.persist()
}
public void setPriority(int p) {
super(p)
issueNode.@priority = p
repository.persist()
public void setText(String t) {
super.setText(t)
issueNode.value = t
repository.persist()
}
}
+75
View File
@@ -4,5 +4,80 @@ import com.jdbernard.pit.*
public class XmlProject extends Project {
def projectNode
XmlRepository repository
XmlProject(def projectNode, XmlRepository repository) {
super(projectName.@name)
this.projectNode = projectNode
this.repository = repository
}
XmlProject(String name, def parentProject, XmlRepository repository) {
super(name)
// Node constructor adds the node to the parent node
projectNode = new Node(parentProject.projectNode, "Project",
[name: name])
repository.persist()
}
public void setName(String name) {
super(name)
projectNode.@name = name
repository.persist()
}
public XmlIssue createNewIssue(Map options) {
if (!options) options = [:]
if (!options.category) options.category = Category.TASK
if (!options.status) options.status = Status.NEW
if (!options.priority) options.priority = 5
if (!options.text) options.text = "Default issue title.\n" +
"====================\n"
String id
if (issues.size() == 0) id = "0000"
else {
id = (issues.values().max { it.id.toInteger() }).id
id = (id.toInteger() + 1).toString().padLeft(id.length(), '0')
}
// XmlIssue constructor will persist XML data
issues[(id)] = new XmlIssue(id, options.category, options.status,
options.priority, options.text, repository, this)
return issues[(id)]
}
public XmlProject createNewProject(String name) {
// XmlProject constructor persists the XML data
projects[(name)] = new XmlProject(name, this, repository)
return projects[(name)]
}
public boolean deleteIssue(Issue issue) {
if (!issues[(issue.id)]) return false
issues.remove(issue.id)
if (issue instanceof XmlIssue)
projectNode.remove(issue.issueNode)
repository.persist()
return true
}
public boolean deleteProject(Project project) {
if (!projects[(project.name)]) return false
projects.remove(project.name)
if (project instanceof XmlProject)
projectNode.remove(project.projectNode)
repository.persist()
}
}
+47
View File
@@ -0,0 +1,47 @@
package com.jdbernard.pit.xml
import com.jdbernard.pit.*
import groovy.xml.XmlUtil
public class XmlRepository extends Repository {
def repository
def projects = []
File repoFile
public XmlRepository(File repoFile) {
this.repoFile = repoFile
repository = new XmlParser().parse(repoFile)
repository.Project.each { projectNode ->
projects << new XmlProject(projectNode)
}
}
public synchronized void persist() {
repoFile.withOutputStream { XmlUtil.serialize(repository, it) }
}
public XmlProject[] getRootProjects() {
return projects as XmlProject[]
}
public XmlProject createNewProject(String name) {
def newProject = new XmlProject(name, this, null)
repository << newProject.projectNode
persist()
return newProject
}
public boolean deleteProject(Project p) {
if (!projects.contains(p)) return false
projects.remove(p)
repository.remove(p.projectNode)
return true
}
}
View File
File mode changed.
View File
File mode changed.
View File
File mode changed.
+4 -2
View File
@@ -5,11 +5,13 @@ class MockProject extends Project {
public MockProject(String name) { super(name) }
public Issue createNewIssue(Map options) {
throw new UnsupportedOperationException()
return new MockIssue(options.id ?: 'n/a',
options.c ?: Category.TASK, options.s ?: Status.NEW,
options.p ?: 5)
}
public Project createNewProject(String name) {
throw new UnsupportedOperationException()
return new MockProject(name)
}
public boolean delete() { return true }
+12
View File
@@ -0,0 +1,12 @@
package com.jdbernard.pit
class MockRepository extends Repository {
public void persist() {}
public Project[] getRootProjects() { return [] as Project[] }
public Project createNewProject(String name) {
return new MockProject(name)
}
}
View File
File mode changed.
@@ -1,5 +1,6 @@
package com.jdbernard.pit
package com.jdbernard.pit.file
import com.jdbernard.pit.*
import org.junit.*
import static org.junit.Assert.assertTrue
import static org.junit.Assert.assertFalse
@@ -1,5 +1,6 @@
package com.jdbernard.pit
package com.jdbernard.pit.file
import com.jdbernard.pit.*
import org.junit.After
import org.junit.Before
import org.junit.Test
+25
View File
@@ -0,0 +1,25 @@
package com.jdbernard.pit.xml
import com.jdbernard.pit.*
import groovy.util.Node
import org.junit.Test
import static org.junit.Assert.assertEquals
import static org.junit.Assert.assertFalse
import static org.junit.Assert.assertTrue
public class XmlIssueTest {
Node issueNode = new Node(null, 'Issue',
[id: '0000', category: 'BUG', status: 'RESOLVED', priority: 1],
'Test Issue')
@Test public void testNodeConstructor() {
XmlIssue issue = new XmlIssue(issueNode,
assertEquals issue.text, 'Test Issue'
assertEquals issue.id, '0000'
assertEquals issue.category, Category.BUG
assertEquals issue.status, Status.RESOLVED
assertEquals issue.priority, 1
}
}
Regular → Executable
View File
File mode changed.
Regular → Executable
View File
File mode changed.
Regular → Executable
View File
File mode changed.
Regular → Executable
View File
File mode changed.
View File
File mode changed.
View File
File mode changed.
Regular → Executable
View File
File mode changed.
View File
File mode changed.
View File
File mode changed.
View File
File mode changed.
View File
File mode changed.
View File
File mode changed.
View File
File mode changed.
View File
File mode changed.
View File
File mode changed.
View File
File mode changed.

Before

Width:  |  Height:  |  Size: 14 KiB

After

Width:  |  Height:  |  Size: 14 KiB

View File
File mode changed.

Before

Width:  |  Height:  |  Size: 1.0 KiB

After

Width:  |  Height:  |  Size: 1.0 KiB

View File
File mode changed.

Before

Width:  |  Height:  |  Size: 1.9 KiB

After

Width:  |  Height:  |  Size: 1.9 KiB

View File
File mode changed.

Before

Width:  |  Height:  |  Size: 31 KiB

After

Width:  |  Height:  |  Size: 31 KiB

View File
File mode changed.

Before

Width:  |  Height:  |  Size: 2.5 KiB

After

Width:  |  Height:  |  Size: 2.5 KiB

View File
File mode changed.

Before

Width:  |  Height:  |  Size: 5.1 KiB

After

Width:  |  Height:  |  Size: 5.1 KiB

View File
File mode changed.

Before

Width:  |  Height:  |  Size: 5.8 KiB

After

Width:  |  Height:  |  Size: 5.8 KiB

View File
File mode changed.

Before

Width:  |  Height:  |  Size: 15 KiB

After

Width:  |  Height:  |  Size: 15 KiB

File mode changed.
File mode changed.
File mode changed.
View File
File mode changed.
View File
File mode changed.
View File
File mode changed.
View File
File mode changed.
View File
File mode changed.
View File
File mode changed.
File mode changed.
View File
File mode changed.
File mode changed.
View File
File mode changed.

Before

Width:  |  Height:  |  Size: 1.2 KiB

After

Width:  |  Height:  |  Size: 1.2 KiB

View File
File mode changed.
View File
File mode changed.

Before

Width:  |  Height:  |  Size: 306 B

After

Width:  |  Height:  |  Size: 306 B

View File
File mode changed.

Before

Width:  |  Height:  |  Size: 411 B

After

Width:  |  Height:  |  Size: 411 B

View File
File mode changed.

Before

Width:  |  Height:  |  Size: 822 B

After

Width:  |  Height:  |  Size: 822 B

View File
File mode changed.
View File
File mode changed.

Before

Width:  |  Height:  |  Size: 146 B

After

Width:  |  Height:  |  Size: 146 B

View File
File mode changed.
View File
File mode changed.

Before

Width:  |  Height:  |  Size: 40 KiB

After

Width:  |  Height:  |  Size: 40 KiB

View File
File mode changed.
File mode changed.
View File
File mode changed.
File mode changed.
Regular → Executable
View File
File mode changed.
Regular → Executable
View File
File mode changed.
View File
File mode changed.
View File
File mode changed.
View File
File mode changed.
Regular → Executable
View File
File mode changed.
Regular → Executable
View File
File mode changed.
Regular → Executable
View File
File mode changed.
Regular → Executable
View File
File mode changed.
View File
File mode changed.
View File
File mode changed.
Regular → Executable
View File
File mode changed.
View File
File mode changed.
View File
File mode changed.
Regular → Executable
View File
File mode changed.
Regular → Executable
View File
File mode changed.
View File
File mode changed.
File mode changed.
File mode changed.
View File
File mode changed.
View File
File mode changed.
View File
File mode changed.
View File
File mode changed.
Loaded 100 of 106 files, more files were not shown because too many files have changed in this diff. Show more