Reorganizing into subprojects.
libpit - Personal Issue Tracker core libraries (Filter, Issue, Project, Category) pit-cli - Command Line Interface (CLI) to libpit pit-swing - Graphical, Swing interface to libpit (built using Griffon) libpit and pit-swing both build, though pit-swing is just an empty griffon poject.
This commit is contained in:
14
libpit/src/com/jdbernard/pit/Category.groovy
Normal file
14
libpit/src/com/jdbernard/pit/Category.groovy
Normal file
@ -0,0 +1,14 @@
|
||||
package com.jdbernard.pit
|
||||
|
||||
public enum Category {
|
||||
BUG,
|
||||
FEATURE,
|
||||
TASK,
|
||||
CLOSED
|
||||
|
||||
public static Category toCategory(String s) {
|
||||
for(c in Category.values())
|
||||
if (c.toString().startsWith(s.toUpperCase())) return c
|
||||
throw new IllegalArgumentException("No category matches ${s}.")
|
||||
}
|
||||
}
|
28
libpit/src/com/jdbernard/pit/Filter.groovy
Normal file
28
libpit/src/com/jdbernard/pit/Filter.groovy
Normal file
@ -0,0 +1,28 @@
|
||||
package com.jdbernard.pit
|
||||
|
||||
class Filter {
|
||||
|
||||
List<Category> categories = null
|
||||
List<String> projects = null
|
||||
List<String> ids = null
|
||||
int priority = 9
|
||||
boolean acceptProjects = true
|
||||
Closure projectSorter
|
||||
Closure issueSorter
|
||||
|
||||
public boolean accept(Issue i) {
|
||||
return (i.priority <= priority &&
|
||||
(!categories || categories.contains(i.category)) &&
|
||||
(!ids || ids.contains(i.id)))
|
||||
}
|
||||
|
||||
public boolean accept(Project p) {
|
||||
return (acceptProjects &&
|
||||
(!projects || projects.contains(p.name)))
|
||||
}
|
||||
|
||||
public boolean accept(String name) {
|
||||
return (acceptProjects &&
|
||||
(!projects || projects.contains(name)))
|
||||
}
|
||||
}
|
24
libpit/src/com/jdbernard/pit/Issue.groovy
Normal file
24
libpit/src/com/jdbernard/pit/Issue.groovy
Normal file
@ -0,0 +1,24 @@
|
||||
package com.jdbernard.pit
|
||||
|
||||
public class Issue {
|
||||
|
||||
String id
|
||||
Category category
|
||||
int priority
|
||||
String title
|
||||
String text
|
||||
|
||||
Issue(File file) {
|
||||
|
||||
def matcher = file.name =~ /(\d{4})([bftc])(\d).*/
|
||||
if (!matcher) return null
|
||||
|
||||
id = matcher[0][1]
|
||||
category = Category.toCategory(matcher[0][2])
|
||||
priority = matcher[0][3].toInteger()
|
||||
|
||||
file.withReader { title = it.readLine() }
|
||||
text = file.text
|
||||
}
|
||||
|
||||
}
|
73
libpit/src/com/jdbernard/pit/Project.groovy
Normal file
73
libpit/src/com/jdbernard/pit/Project.groovy
Normal file
@ -0,0 +1,73 @@
|
||||
package com.jdbernard.pit
|
||||
|
||||
class Project {
|
||||
|
||||
String name
|
||||
Map<String, Issue> issues = [:]
|
||||
Map<String, Project> projects = [:]
|
||||
|
||||
Project(File dir, Filter filter = null) {
|
||||
dir.eachFile { child ->
|
||||
|
||||
// add sub projects
|
||||
if (child.isDirectory()) {
|
||||
if ( child.name ==~ /\d{4}/ || // just an issue folder
|
||||
(filter && !filter.accept(child.name)))
|
||||
return
|
||||
|
||||
// otherwise build and add to list
|
||||
projects[(child.name)] = new Project(child, filter)
|
||||
} else if (child.isFile()) {
|
||||
def issue
|
||||
|
||||
// if exception, then not an issue
|
||||
try { issue = new Issue(child) } catch (all) { return }
|
||||
|
||||
if (filter && !filter.accept(issue)) return
|
||||
|
||||
issues[(issue.id)] = issue
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public void eachIssue(Closure c) {
|
||||
for (i in issues.values()) c.call(i)
|
||||
for (p in projects.values()) p.eachIssue(c)
|
||||
}
|
||||
|
||||
public void each(Filter filter = null, Closure c) {
|
||||
def is = filter?.issueSorter ?: { it.id.toInteger() }
|
||||
def ps = filter?.projectSorter ?: { it.name }
|
||||
|
||||
for (issue in issues.values().sort(is)) {
|
||||
if (filter && !filter.accept(issue))
|
||||
return
|
||||
|
||||
c.call(issue)
|
||||
}
|
||||
|
||||
for (project in projects.values().sort(ps)) {
|
||||
if (filter && !filter.accept(project))
|
||||
return
|
||||
|
||||
c.call(project)
|
||||
project.each(c)
|
||||
}
|
||||
}
|
||||
|
||||
public void list(Map options = [:]) {
|
||||
if (!options.offset) options.offset = ""
|
||||
if (!options.verbose) options.verbose = false
|
||||
|
||||
each(options.filter) {
|
||||
if (it instanceof Project) {
|
||||
println "\n${options.offset}${it.name}"
|
||||
println "${options.offset}${'-'.multiply(p.name.length())}"
|
||||
} else {
|
||||
println "${options.offset}${it.id}(${it.priority}): " +
|
||||
"${it.category} ${it.title}"
|
||||
if (options.verbose) println "\n${it.text}"
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user