Skip to content

Commit

Permalink
Issue920 (#921)
Browse files Browse the repository at this point in the history
* Issue 920: Update to Java 10

* Update Travis to JDK 10
  • Loading branch information
gmazza authored Sep 8, 2018
1 parent 12efd9d commit b7d9d0c
Show file tree
Hide file tree
Showing 36 changed files with 410 additions and 608 deletions.
3 changes: 3 additions & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
language: java

jdk: openjdk10

script: ./gradlew clean build

services:
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
Welcome to TightBlog! This project started off in May 2015 as a fork of the Apache Roller project, of which I contributed for about 2 1/2 years
before deciding to go my own way due to differing ideas of what would make the best blogging product. As of 2 September 2018, <a href="https://github.com/gmazza/tightblog/releases">Release 3.2</a> is available.
before deciding to go my own way due to differing ideas of what would make the best blogging product. As of 8 September 2018, <a href="https://github.com/gmazza/tightblog/releases">Release 3.3</a> is available.

Screen shots for the TightBlog UI are [here](https://github.com/gmazza/tightblog/wiki/Screenshots), the twelve-table database model is
[here](https://github.com/gmazza/tightblog/blob/master/app/src/main/resources/dbscripts/createdb.vm), see also [my blog](https://glenmazza.net/blog/) for an example
Expand Down
24 changes: 10 additions & 14 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,12 @@ buildscript {
}
dependencies {
classpath("org.springframework.boot:spring-boot-gradle-plugin:${springBootVersion}")
classpath 'com.bmuschko:gradle-docker-plugin:3.2.5'
classpath 'com.bmuschko:gradle-docker-plugin:3.6.1'
}
}

plugins {
id 'com.bmuschko.docker-remote-api' version '3.2.3'
id 'com.bmuschko.docker-remote-api' version '3.6.1'
}

apply plugin: 'war'
Expand All @@ -23,9 +23,9 @@ apply plugin: 'org.springframework.boot'
apply plugin: 'io.spring.dependency-management'

group = 'org.tightblog'
version = '3.2'
sourceCompatibility = 1.8
targetCompatibility = 1.8
version = '3.3'
sourceCompatibility = 1.10
targetCompatibility = 1.10
tasks.withType(JavaCompile) {
options.encoding = 'UTF-8'
}
Expand Down Expand Up @@ -54,11 +54,7 @@ sourceSets {
}

static def standardCompile(options) {
options.compilerArgs += ["-proc:none"]
}

compileGroovy {
standardCompile(options)
options.compilerArgs += ["-Xlint:unchecked"]
}

compileJava {
Expand Down Expand Up @@ -160,7 +156,6 @@ task integrationTest(type: Test) {
war.dependsOn createDDLScripts
check.dependsOn integrationTest


checkstyle {
toolVersion = "8.9"
config = resources.text.fromFile('checkstyle.xml', 'UTF-8')
Expand All @@ -169,7 +164,6 @@ checkstyle {
}

dependencies {
compile localGroovy()
compile("org.springframework.boot:spring-boot-starter-data-jpa") {
exclude group: "org.hibernate", module: "hibernate-entitymanager"
}
Expand All @@ -178,6 +172,7 @@ dependencies {
compile('org.springframework.boot:spring-boot-starter-security')
compile('org.springframework.boot:spring-boot-starter-thymeleaf')
compile('org.springframework.boot:spring-boot-starter-web')
compile('org.springframework.boot:spring-boot-starter-mail')
compile('org.springframework.boot:spring-boot-starter-log4j2')
compile(group: 'org.springframework.security', name: 'spring-security-taglibs', version:'5.0.7.RELEASE') {
exclude(module: 'spring-web')
Expand All @@ -189,20 +184,21 @@ dependencies {
compile('org.springframework.mobile:spring-mobile-device:1.1.5.RELEASE')
compile('org.apache.lucene:lucene-analyzers-common:7.4.0')
compile('org.apache.lucene:lucene-queryparser:7.4.0')
compile('org.springframework.boot:spring-boot-starter-mail')
compile('org.jsoup:jsoup:1.11.3')
compile('com.github.ben-manes.caffeine:caffeine:2.6.2')
compile('org.thymeleaf:thymeleaf-spring4:3.0.9.RELEASE')
compile('org.jboss.aerogear:aerogear-otp-java:1.0.0')
compile('com.atlassian.commonmark:commonmark:0.11.0')
compile('commons-fileupload:commons-fileupload:1.3.3')

runtime('org.postgresql:postgresql')
// needed for log4j2 application logging to work
runtime group: 'org.apache.logging.log4j', name: 'log4j-jcl', version:'2.11.0'
testCompile('org.springframework.boot:spring-boot-starter-test')
testCompile('org.springframework.security:spring-security-test')
testCompile('org.postgresql:postgresql:42.2.4')
testCompile('org.springframework.boot:spring-boot-starter-test')
compile('javax.servlet:jstl:1.2')
providedCompile localGroovy()
providedCompile('org.apache.tomcat.embed:tomcat-embed-jasper:9.0.11')
// velocity used only when running Groovy task during build
providedCompile('org.apache.velocity:velocity-engine-core:2.0') {
Expand Down
Binary file modified gradle/wrapper/gradle-wrapper.jar
Binary file not shown.
3 changes: 1 addition & 2 deletions gradle/wrapper/gradle-wrapper.properties
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
#Tue Feb 06 12:27:20 CET 2018
distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-4.10-bin.zip
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-4.8.1-bin.zip
6 changes: 3 additions & 3 deletions gradlew
Original file line number Diff line number Diff line change
Expand Up @@ -33,11 +33,11 @@ DEFAULT_JVM_OPTS=""
# Use the maximum available, or set MAX_FD != -1 to use that value.
MAX_FD="maximum"

warn ( ) {
warn () {
echo "$*"
}

die ( ) {
die () {
echo
echo "$*"
echo
Expand Down Expand Up @@ -155,7 +155,7 @@ if $cygwin ; then
fi

# Escape application args
save ( ) {
save () {
for i do printf %s\\n "$i" | sed "s/'/'\\\\''/g;1s/^/'/;\$s/\$/' \\\\/" ; done
echo " "
}
Expand Down
8 changes: 8 additions & 0 deletions src/main/groovy/genDDL.groovy
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,13 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
/**
Groovy script runs the createdb.vm Velocity template to generate database-specific table
creation scripts for TightBlog.
Run "gradle createDDLScripts" from project root folder whenever the database script createdb.vm changes,
allowing for the database-specific scripts in the same folder to get updated.
*/
import org.apache.velocity.VelocityContext
import org.apache.velocity.Template
import org.apache.velocity.app.Velocity
Expand All @@ -29,6 +36,7 @@ def genScript = { String dbName, String foreignKeyIndex, String textType,
context.put("BOOLEAN_SQL_TYPE_TRUE", booleanTrueType)
context.put("TIMESTAMP_SQL_TYPE", timestampType)
context.put("TIMESTAMP_SQL_TYPE_DEFNOW", timestampNow)
context.put("DB_NAME", dbName)

try {
Template template = Velocity.getTemplate("src/main/resources/dbscripts/createdb.vm")
Expand Down
25 changes: 13 additions & 12 deletions src/main/java/org/tightblog/business/ThemeManagerImpl.java
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
*/
package org.tightblog.business;

import com.fasterxml.jackson.databind.ObjectMapper;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
Expand All @@ -31,7 +32,6 @@
import org.tightblog.pojos.Weblog;
import org.tightblog.pojos.WeblogTemplate;
import org.tightblog.pojos.WeblogTheme;
import org.tightblog.util.Utilities;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.web.context.ServletContextAware;
Expand Down Expand Up @@ -64,6 +64,9 @@ public class ThemeManagerImpl implements ThemeManager, ServletContextAware {

private ServletContext servletContext;

@Autowired
private ObjectMapper objectMapper;

static {
// TODO: figure out why PNG is missing from Java MIME types
FileTypeMap map = FileTypeMap.getDefaultFileTypeMap();
Expand Down Expand Up @@ -203,33 +206,35 @@ private Map<String, SharedTheme> loadAllThemesFromDisk() {
} catch (Exception unexpected) {
// shouldn't happen, so let's learn why it did
log.error("Unable to process theme '{}'", themeName, unexpected);
System.out.println("Unable to process theme " + themeName + " error: " + unexpected.getMessage());
unexpected.printStackTrace(System.out);
}
}
}

return sharedThemeMap;
}

private SharedTheme loadThemeData(String themeName) {
private SharedTheme loadThemeData(String themeName) throws Exception {
String themePath = this.themeDir + File.separator + themeName;
log.debug("Parsing theme descriptor for {}", themePath);

SharedTheme sharedTheme = (SharedTheme) Utilities.jaxbUnmarshall(
"/theme.xsd", themePath + File.separator + "theme.xml", false, SharedTheme.class);
sharedTheme.setThemeDir(themePath);
String themeJson = themePath + File.separator + "theme.json";
log.debug("Loading Theme JSON at path {}", themeJson);

log.debug("Loading Theme {}", sharedTheme.getName());
SharedTheme sharedTheme = objectMapper.readValue(new FileInputStream(themeJson), SharedTheme.class);
sharedTheme.setThemeDir(themePath);

// load resource representing preview image
File previewFile = new File(sharedTheme.getThemeDir() + File.separator + sharedTheme.getPreviewImagePath());
if (!previewFile.exists() || !previewFile.canRead()) {
log.warn("Couldn't read theme [{}] preview image file [{}]", sharedTheme.getName(),
log.warn("Couldn't read theme [{}] thumbnail at path [{}]", sharedTheme.getName(),
sharedTheme.getPreviewImagePath());
}

// create the templates based on the theme descriptor data
boolean hasWeblogTemplate = false;
for (SharedTemplate template : sharedTheme.getTempTemplates()) {
for (SharedTemplate template : sharedTheme.getTemplates()) {

// one and only one template with action "weblog" allowed
if (ComponentType.WEBLOG.equals(template.getRole())) {
Expand All @@ -246,16 +251,12 @@ private SharedTheme loadThemeData(String themeName) {

// this template ID used by template resolvers to retrieve the template.
template.setId(sharedTheme.getId() + ":" + template.getName());

// add it to the theme
sharedTheme.addTemplate(template);
}

if (!hasWeblogTemplate) {
throw new IllegalStateException("Theme " + sharedTheme.getName() + " has no template with 'weblog' action");
}

sharedTheme.getTempTemplates().clear();
return sharedTheme;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ public class IndexManagerImpl implements IndexManager {

private ExecutorService serviceScheduler;

private boolean searchEnabled = true;
private boolean searchEnabled;
private boolean indexComments;
private File indexConsistencyMarker;
private String indexDir;
Expand Down Expand Up @@ -200,8 +200,8 @@ public ReadWriteLock getReadWriteLock() {
@Override
public Analyzer getAnalyzer() {
try {
return (Analyzer) Class.forName(luceneAnalyzerName).newInstance();
} catch (ClassNotFoundException | InstantiationException | IllegalAccessException e) {
return (Analyzer) Class.forName(luceneAnalyzerName).getDeclaredConstructor().newInstance();
} catch (Exception e) {
log.error("Cannot instantiate class {}", luceneAnalyzerName, e);
}
return null;
Expand Down
8 changes: 8 additions & 0 deletions src/main/java/org/tightblog/pojos/GlobalRole.java
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@
*/
package org.tightblog.pojos;

import com.fasterxml.jackson.annotation.JsonCreator;

// GlobalRole defines system-wide roles as opposed to individual blog permissions
// Each role includes the roles of those of lower weight as defined in this enum
public enum GlobalRole {
Expand All @@ -38,4 +40,10 @@ public int getWeight() {
GlobalRole(int weight) {
this.weight = weight;
}

@JsonCreator
public static GlobalRole forValue(String value) {
return GlobalRole.valueOf(value);
}

}
7 changes: 5 additions & 2 deletions src/main/java/org/tightblog/pojos/SharedTemplate.java
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@
*/
package org.tightblog.pojos;

import javax.xml.bind.annotation.XmlAttribute;
import java.time.Instant;

/**
Expand Down Expand Up @@ -99,7 +98,6 @@ public ComponentType getRole() {
return role;
}

@XmlAttribute
public void setRole(ComponentType role) {
this.role = role;
}
Expand All @@ -118,4 +116,9 @@ public String getTemplate() {
public void setTemplate(String template) {
this.template = template;
}

// type used during JSON deserialization to determine the ComponentType (role)
public void setType(String type) {
role = ComponentType.valueOf(type.toUpperCase());
}
}
27 changes: 11 additions & 16 deletions src/main/java/org/tightblog/pojos/SharedTheme.java
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,6 @@

import org.tightblog.pojos.Template.ComponentType;

import javax.xml.bind.annotation.XmlElement;
import javax.xml.bind.annotation.XmlElements;
import javax.xml.bind.annotation.XmlRootElement;
import java.time.Instant;
import java.util.HashMap;
import java.util.HashSet;
Expand All @@ -36,7 +33,6 @@
* used mostly to contain all the templates for a theme, but does contain other
* theme related attributes such as name, last modified date, etc.
*/
@XmlRootElement(name = "sharedtheme")
public class SharedTheme {

private String id;
Expand All @@ -50,13 +46,7 @@ public class SharedTheme {
private Instant lastModified;
private boolean enabled = true;

// JAXB loads here; ThemeManagerImpl moves them to the three maps.
@XmlElements(@XmlElement(name = "template"))
private Set<SharedTemplate> tempTemplates = new HashSet<>();

public Set<SharedTemplate> getTempTemplates() {
return tempTemplates;
}
private Set<SharedTemplate> templates = new HashSet<>();

// the filesystem directory where we should read this theme from
private String themeDir;
Expand Down Expand Up @@ -117,11 +107,8 @@ public void setSiteWide(Boolean siteWide) {
this.siteWide = siteWide;
}

/**
* Get the name-keyed map of all templates associated with this Theme.
*/
public Map<String, Template> getTemplatesByName() {
return templatesByName;
public Set<SharedTemplate> getTemplates() {
return templates;
}

public void setTemplates(Set<SharedTemplate> templates) {
Expand All @@ -130,6 +117,13 @@ public void setTemplates(Set<SharedTemplate> templates) {
}
}

/**
* Get the name-keyed map of all templates associated with this Theme.
*/
public Map<String, Template> getTemplatesByName() {
return templatesByName;
}

public String getThemeDir() {
return themeDir;
}
Expand Down Expand Up @@ -182,6 +176,7 @@ public Template getTemplateByAction(ComponentType action) {
* Set the value for a given template name.
*/
public void addTemplate(SharedTemplate template) {
this.templates.add(template);
this.templatesByName.put(template.getName(), template);
this.templatesByLink.put(template.getRelativePath(), template);
if (template.getRole().isSingleton()) {
Expand Down
Loading

0 comments on commit b7d9d0c

Please sign in to comment.