Awaiting testing before releasing 1.1.2
This commit is contained in:
@ -1,5 +1,7 @@
|
||||
package com.jdbernard.pit
|
||||
|
||||
import java.lang.IllegalArgumentException as IAE
|
||||
|
||||
public class Issue {
|
||||
|
||||
final String id
|
||||
@ -24,21 +26,38 @@ public class Issue {
|
||||
text = file.text
|
||||
}
|
||||
|
||||
/**
|
||||
*/
|
||||
void setCategory(Category c) {
|
||||
|
||||
if (category == null)
|
||||
throw new IAE("Category cannot be null.")
|
||||
|
||||
this.category = c
|
||||
source.renameTo(new File(source.canonicalFile.parentFile, getFilename()))
|
||||
}
|
||||
|
||||
void setPriority(int p) {
|
||||
if (p < 0) priority = 0
|
||||
else if (p > 9) priority = 9
|
||||
else priority = p
|
||||
|
||||
// bounds check priority
|
||||
priority = Math.min(9, Math.max(0, priority))
|
||||
|
||||
source.renameTo(new File(source.canonicalFile.parentFile, getFilename()))
|
||||
}
|
||||
|
||||
String getFilename() { return makeFilename(id, category, priority) }
|
||||
|
||||
static String makeFilename(String id, Category category, int priority) {
|
||||
|
||||
// bounds check priority
|
||||
priority = Math.min(9, Math.max(0, priority))
|
||||
|
||||
//check for valid values of cateogry and id
|
||||
if (category == null)
|
||||
throw new IAE("Category must be non-null.")
|
||||
if (!(/\d+/ ==~ id))
|
||||
throw new IAE( "'${id}' is not a legal value for id.")
|
||||
|
||||
return id + category.symbol + priority + ".rst";
|
||||
}
|
||||
|
||||
|
@ -7,7 +7,7 @@ class Project {
|
||||
Map<String, Project> projects = [:]
|
||||
File source
|
||||
|
||||
Project(File dir, Filter filter = null) {
|
||||
Project(File dir) {
|
||||
if (!dir.isDirectory())
|
||||
throw new IllegalArgumentException(
|
||||
"${dir.name} is not a directory.")
|
||||
@ -19,20 +19,16 @@ class Project {
|
||||
|
||||
// add sub projects
|
||||
if (child.isDirectory()) {
|
||||
if ( child.name ==~ /\d{4}/ || // just an issue folder
|
||||
(filter && !filter.accept(child.name)))
|
||||
return
|
||||
if ( child.name ==~ /\d{4}/) return // just an issue folder
|
||||
|
||||
// otherwise build and add to list
|
||||
projects[(child.name)] = new Project(child, filter)
|
||||
projects[(child.name)] = new Project(child)
|
||||
} 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
|
||||
}
|
||||
}
|
||||
@ -47,15 +43,19 @@ class Project {
|
||||
|
||||
public void eachIssue(Filter filter = null, Closure c) {
|
||||
def sorter = filter?.issueSorter ?: Filter.defaultIssueSorter
|
||||
for (i in issues.values().sort(sorter)) c.call(i)
|
||||
for (i in issues.values().sort(sorter))
|
||||
if (!filter || filter.accept(i))
|
||||
c.call(i)
|
||||
}
|
||||
|
||||
public void eachProject(Filter filter = null, Closure c) {
|
||||
def sorter = filter?.projectSorter ?: Filter.defaultProjectSorter
|
||||
for (p in projects.values().sort(sorter)) c.call(p)
|
||||
for (p in projects.values().sort(sorter))
|
||||
if (!filter || filter.accept(p))
|
||||
c.call(p)
|
||||
}
|
||||
|
||||
public void each(Filter filter = null, Closure c) {
|
||||
/*public void each(Filter filter = null, Closure c) {
|
||||
def is = filter?.issueSorter ?: Filter.defaultIssueSorter
|
||||
def ps = filter?.projectSorter ?: Filter.defaultProjectSorter
|
||||
|
||||
@ -72,15 +72,19 @@ class Project {
|
||||
|
||||
c.call(project)
|
||||
}
|
||||
}
|
||||
}*/
|
||||
|
||||
public Issue createNewIssue(Map options) {
|
||||
if (!options.category) options.category = Category.TASK
|
||||
if (!options.priority) options.priority = 5
|
||||
if (!options.text) options.text = "Default issue title.\n" +
|
||||
"====================\n"
|
||||
String id = (issues.values().max { it.id.toInteger() }).id
|
||||
id = (id.toInteger() + 1).toString().padLeft(id.length(), '0')
|
||||
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')
|
||||
}
|
||||
|
||||
def issueFile = new File(source, Issue.makeFilename(id, options.category, options.priority))
|
||||
assert !issueFile.exists()
|
||||
|
Reference in New Issue
Block a user