From 4f03086a36c82f84e1258880b2a574ca566b5094 Mon Sep 17 00:00:00 2001 From: Bradlee Speice Date: Mon, 5 May 2014 00:53:32 -0400 Subject: [PATCH] Tweaks to the jsword conditional build Also add a FilterUtil class to JSword --- build.gradle | 13 ++--- build.xml | 2 - .../org/crosswire/jsword/book/FilterUtil.java | 51 +++++++++++++++++++ 3 files changed, 56 insertions(+), 10 deletions(-) create mode 100644 src/main/java/jsword/org/crosswire/jsword/book/FilterUtil.java diff --git a/build.gradle b/build.gradle index 58d730b..dbf24f7 100644 --- a/build.gradle +++ b/build.gradle @@ -6,17 +6,14 @@ task doBuildJSword (type: GradleBuild) { buildFile = 'jsword-stub.gradle' tasks = ['clean', 'ivy.check', 'ivy.download', 'ivy.task', 'ivy', 'init', 'mergeCode', 'compile', 'jar'] //, 'copyJarsToMinimalBible'] - - ext.outputJar = file('distribution/jsword.jar') -} - -task conditionalBuildJSword () { - if(!file(doBuildJSword.ext.outputJar).exists()) - doBuildJSword + ext.outputJar = file('distribution/jsword.jar') + outputs.upToDateWhen { + ext.outputJar.exists() + } } artifacts { buildJSword(doBuildJSword.ext.outputJar) { - builtBy conditionalBuildJSword + builtBy doBuildJSword } } diff --git a/build.xml b/build.xml index d70dde5..095f3d5 100644 --- a/build.xml +++ b/build.xml @@ -64,11 +64,9 @@ - diff --git a/src/main/java/jsword/org/crosswire/jsword/book/FilterUtil.java b/src/main/java/jsword/org/crosswire/jsword/book/FilterUtil.java new file mode 100644 index 0000000..752cc30 --- /dev/null +++ b/src/main/java/jsword/org/crosswire/jsword/book/FilterUtil.java @@ -0,0 +1,51 @@ +package org.crosswire.jsword.book; + +import org.crosswire.jsword.book.BookCategory; +import org.crosswire.jsword.book.BookFilter; +import org.crosswire.jsword.book.BookFilters; + +import java.util.Arrays; + +/** + * Module to help with some conversions between BookCategories and BookFilters + * Makes more sense to move it to JSword than incorporate in MinimalBible + */ +public class FilterUtil { + + private static final BookCategory[] MAPPABLE_CATEGORIES = {BookCategory.BIBLE, + BookCategory.COMMENTARY, BookCategory.DAILY_DEVOTIONS, BookCategory.DICTIONARY, + BookCategory.GENERAL_BOOK, BookCategory.GLOSSARY, BookCategory.MAPS, + BookCategory.OTHER + }; + private static final BookFilter[] MAPPABLE_FILTERS = {BookFilters.getBibles(), + BookFilters.getCommentaries(), BookFilters.getDailyDevotionals(), BookFilters.getDictionaries(), + BookFilters.getGeneralBooks(), BookFilters.getGlossaries(), BookFilters.getMaps(), + BookFilters.getNonBibles() + }; + + public static BookCategory categoryFromFilter(BookFilter f) + throws InvalidFilterCategoryMappingException { + int index = Arrays.asList(MAPPABLE_FILTERS).indexOf(f); + if (index != -1) { + return MAPPABLE_CATEGORIES[index]; + } else { + throw new InvalidFilterCategoryMappingException("Can not map from filter: " + f.toString() + " to category."); + } + } + + public static BookFilter filterFromCategory(BookCategory c) + throws InvalidFilterCategoryMappingException { + int index = Arrays.asList(MAPPABLE_CATEGORIES).indexOf(c); + if (index != -1) { + return MAPPABLE_FILTERS[index]; + } else { + throw new InvalidFilterCategoryMappingException("Can not map from category: " + c.toString() + " to filter."); + } + } + + public static class InvalidFilterCategoryMappingException extends Exception { + public InvalidFilterCategoryMappingException(String message) { + super(message); + } + } +} \ No newline at end of file