Skip to content

Commit

Permalink
Merge pull request #449 from jonbullock/ancho-feature/sonarcloud-travis
Browse files Browse the repository at this point in the history
Manually merged in #430
  • Loading branch information
jonbullock authored Apr 15, 2018
2 parents 2573851 + 84a9e36 commit f8db6d6
Show file tree
Hide file tree
Showing 15 changed files with 128 additions and 59 deletions.
49 changes: 33 additions & 16 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,31 +5,45 @@ dist: trusty

addons:
hosts:
- jbake-builder
- jbake-builder
hostname: jbake-builder

matrix:
include:
- jdk: oraclejdk9
- jdk: oraclejdk8
- jdk: openjdk8
- jdk: openjdk7
dist: precise
- os: osx

before_install:
- unset _JAVA_OPTIONS

install: true

script:
- ./gradlew check -i
- "./gradlew check -i"

after_failure:
- "./gradlew clean check -debug --stacktrace"

after_success:
- ./gradlew -PskipSigning jacocoRootReport coveralls || ./gradlew clean
- "./gradlew -PskipSigning jacocoRootReport coveralls || ./gradlew clean"

after_failure:
- ./gradlew clean check --debug
jdk:
- oraclejdk9
- oraclejdk8
- openjdk8

jobs:
include:

- script: "./gradlew check"
jdk: openjdk7
dist: precise

- script: "./gradlew check"
jdk:
os: osx

- stage: Quality Check
jdk: oraclejdk8
script:
- "./gradlew jacocoRootReport"
after_success:
- "./gradlew sonarqube -i --stacktrace"

notifications:
irc: "irc.freenode.org#jbake"
Expand All @@ -46,5 +60,8 @@ before_cache:

cache:
directories:
- $HOME/.gradle/caches/
- $HOME/.gradle/wrapper/
- "$HOME/.m2/repository"
- "$HOME/.gradle/caches/"
- "$HOME/.gradle/wrapper/"
- "$HOME/.sonar/cache"
- ".gradle"
11 changes: 11 additions & 0 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ plugins {
id "io.sdkman.vendors" version "1.1.1" apply false
id "com.jfrog.bintray" version "1.8.0" apply false
id "com.github.kt3k.coveralls" version "2.8.2" apply false
id "org.sonarqube" version "2.6.2" apply false
id 'com.github.ben-manes.versions' version '0.17.0'
id "nebula.optional-base" version "3.3.0" apply false
}
Expand Down Expand Up @@ -31,6 +32,16 @@ ext {
jade4jVersion = '1.2.7'
mockitoVersion = '2.16.0'
jsoupVersion = '1.11.2'

isTravis = (System.getenv("TRAVIS") == "true")
isTravisPullRequest = (System.getenv("TRAVIS_PULL_REQUEST")) != "false"
pullRequestId = System.getenv("TRAVIS_PULL_REQUEST")
hasGithub = System.getenv("GITHUBTOKEN") && System.getenv("GITHUBREPO")
hasSonar = System.getenv("SONARORG") && System.getenv("SONARLOGIN")
sonarDefaultURL = "https://sonarcloud.io"
sonarDefaultProjectKey = "org.jbake:jbake-base:jbake-core"
sonarURL = System.getenv("SONARHOST") ?: sonarDefaultURL
sonarProjectKey = System.getenv("SONARPROJECTKEY") ?: sonarDefaultProjectKey
}

/**
Expand Down
34 changes: 34 additions & 0 deletions gradle/sonarqube.gradle
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
if ( JavaVersion.current().isJava8Compatible() ) {
apply plugin: "org.sonarqube"

println "configured sonar url: $sonarURL"
sonarqube {
if (!hasSonar) {
skipProject = true

logger.error("Skipping sonar analysis. Missing environment variables SONARLOGIN or SONARORG. See https://docs.sonarqube.org/display/SCAN/Analyzing+with+SonarQube+Scanner+for+Gradle")
}

properties {

property "sonar.host.url", sonarURL
property "sonar.organization", System.getenv('SONARORG')
property "sonar.login", System.getenv('SONARLOGIN')
property "sonar.projectKey", sonarProjectKey


if (isTravis && isTravisPullRequest) {

if (hasGithub) {
property "sonar.analysis.mode", "preview"
property "sonar.github.oauth", System.getenv("GITHUBTOKEN")
property "sonar.github.repository", System.getenv("GITHUBREPO")
property "sonar.github.pullRequest", pullRequestId
} else {
logger.error("Cannot use sonar github plugin without GITHUBTOKEN (oauth token) and GITHUBREPO (e.g. jbake-org/jbake) environment variables. See https://docs.sonarqube.org/display/PLUG/GitHub+Plugin")
}
}

}
}
}
6 changes: 4 additions & 2 deletions jbake-core/build.gradle
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
import java.text.SimpleDateFormat

apply from: "$rootDir/gradle/sonarqube.gradle"

description = "The core library of JBake"

dependencies {
Expand Down Expand Up @@ -28,8 +30,8 @@ dependencies {
processResources {
from("src/main/resources") {
include 'default.properties'
expand jbakeVersion: project.version,
timestamp: new SimpleDateFormat("yyyy-MM-dd HH:mm:ssa").format( new Date() )
expand jbakeVersion: project.version,
timestamp: new SimpleDateFormat("yyyy-MM-dd HH:mm:ssa").format(new Date())
}
}

2 changes: 1 addition & 1 deletion jbake-core/src/main/java/org/jbake/app/Crawler.java
Original file line number Diff line number Diff line change
Expand Up @@ -153,7 +153,7 @@ private String buildURI(final File sourceFile) {
}

private String createUri(String uri) {
return uri.substring(0, uri.lastIndexOf(".")) + config.getString(Keys.OUTPUT_EXTENSION);
return uri.substring(0, uri.lastIndexOf('.')) + config.getString(Keys.OUTPUT_EXTENSION);
}

private String createNoExtensionUri(String uri) {
Expand Down
3 changes: 0 additions & 3 deletions jbake-core/src/main/java/org/jbake/app/DocumentList.java
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,4 @@ public static DocumentList wrap(Iterator<ODocument> docs) {
return list;
}

public DocumentList() {
}

}
2 changes: 1 addition & 1 deletion jbake-core/src/main/java/org/jbake/app/Parser.java
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
* @author Jonathan Bullock <a href="mailto:[email protected]">[email protected]</a>
*/
public class Parser {
private final static Logger LOGGER = LoggerFactory.getLogger(Parser.class);
private static final Logger LOGGER = LoggerFactory.getLogger(Parser.class);

private Configuration config;
private String contentPath;
Expand Down
25 changes: 15 additions & 10 deletions jbake-core/src/main/java/org/jbake/app/Renderer.java
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,11 @@
*/
public class Renderer {

private static final String MASTERINDEX_TEMPLATE_NAME = "masterindex";
private static final String SITEMAP_TEMPLATE_NAME = "sitemap";
private static final String FEED_TEMPLATE_NAME = "feed";
private static final String ARCHIVE_TEMPLATE_NAME = "archive";

private interface RenderingConfig {

File getPath();
Expand Down Expand Up @@ -178,8 +183,8 @@ private String findTemplateName(String docType) {
public void render(Map<String, Object> content) throws Exception {
String docType = (String) content.get(Crawler.Attributes.TYPE);
String outputFilename = destination.getPath() + File.separatorChar + ((String)content.get(Attributes.URI)).replace("/",File.separator);
if (outputFilename.lastIndexOf(".") > outputFilename.lastIndexOf(File.separatorChar)) {
outputFilename = outputFilename.substring(0, outputFilename.lastIndexOf("."));
if (outputFilename.lastIndexOf('.') > outputFilename.lastIndexOf(File.separatorChar)) {
outputFilename = outputFilename.substring(0, outputFilename.lastIndexOf('.'));
}

// delete existing versions if they exist in case status has changed either way
Expand Down Expand Up @@ -243,7 +248,7 @@ private void render(RenderingConfig renderConfig) throws Exception {
*/
public void renderIndex(String indexFile) throws Exception {

render(new DefaultRenderingConfig(indexFile, "masterindex"));
render(new DefaultRenderingConfig(indexFile, MASTERINDEX_TEMPLATE_NAME));
}

public void renderIndexPaging(String indexFile) throws Exception {
Expand All @@ -267,12 +272,12 @@ public void renderIndexPaging(String indexFile) throws Exception {

db.setStart(pageStart);
model.put("currentPageNumber", page);
String previous = pagingHelper.getPreviousFileName(page, fileName);
String previous = pagingHelper.getPreviousFileName(page);
model.put("previousFileName", previous);
String nextFileName = pagingHelper.getNextFileName(page, fileName);
String nextFileName = pagingHelper.getNextFileName(page);
model.put("nextFileName", nextFileName);

Map<String, Object> contentModel = buildSimpleModel("masterindex");
Map<String, Object> contentModel = buildSimpleModel(MASTERINDEX_TEMPLATE_NAME);

if(page > 1){
contentModel.put(Attributes.ROOTPATH, "../");
Expand All @@ -281,7 +286,7 @@ public void renderIndexPaging(String indexFile) throws Exception {

// Add page number to file name
fileName = pagingHelper.getCurrentFileName(page, fileName);
ModelRenderingConfig renderConfig = new ModelRenderingConfig(fileName, model, "masterindex");
ModelRenderingConfig renderConfig = new ModelRenderingConfig(fileName, model, MASTERINDEX_TEMPLATE_NAME);
render(renderConfig);
}
db.resetPagination();
Expand All @@ -301,7 +306,7 @@ public void renderIndexPaging(String indexFile) throws Exception {
* @see <a href="http://www.sitemaps.org/">Sitemap protocol</a>
*/
public void renderSitemap(String sitemapFile) throws Exception {
render(new DefaultRenderingConfig(sitemapFile, "sitemap"));
render(new DefaultRenderingConfig(sitemapFile, SITEMAP_TEMPLATE_NAME));
}

/**
Expand All @@ -311,7 +316,7 @@ public void renderSitemap(String sitemapFile) throws Exception {
* @throws Exception if default rendering configuration is not loaded correctly
*/
public void renderFeed(String feedFile) throws Exception {
render(new DefaultRenderingConfig(feedFile, "feed"));
render(new DefaultRenderingConfig(feedFile, FEED_TEMPLATE_NAME));
}

/**
Expand All @@ -321,7 +326,7 @@ public void renderFeed(String feedFile) throws Exception {
* @throws Exception if default rendering configuration is not loaded correctly
*/
public void renderArchive(String archiveFile) throws Exception {
render(new DefaultRenderingConfig(archiveFile, "archive"));
render(new DefaultRenderingConfig(archiveFile, ARCHIVE_TEMPLATE_NAME));
}

/**
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
package org.jbake.model;

public class DocumentTypeUtils {

private DocumentTypeUtils() {}

public static String unpluralize(String pluralized) {

if ((pluralized == null) || (pluralized.length() == 0)) {
Expand Down
8 changes: 5 additions & 3 deletions jbake-core/src/main/java/org/jbake/model/DocumentTypes.java
Original file line number Diff line number Diff line change
Expand Up @@ -16,13 +16,15 @@
*/
public class DocumentTypes {

private static final Set<String> DEFAULT_DOC_TYPES = new LinkedHashSet<String>();
private static final Set<DocumentTypeListener> LISTENERS = new HashSet<DocumentTypeListener>();
private static final Set<String> DEFAULT_DOC_TYPES = new LinkedHashSet<>();
private static final Set<DocumentTypeListener> LISTENERS = new HashSet<>();

static {
resetDocumentTypes();
}


private DocumentTypes() {}

public static void resetDocumentTypes() {
DEFAULT_DOC_TYPES.clear();
DEFAULT_DOC_TYPES.addAll(Arrays.asList("page", "post", "masterindex", "archive", "feed"));
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package org.jbake.render;

import org.apache.commons.configuration.CompositeConfiguration;
import org.jbake.app.ConfigUtil;
import org.jbake.app.ConfigUtil.Keys;
import org.jbake.app.ContentStore;
import org.jbake.app.Renderer;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,13 @@


/**
*
*
* @author ndx
*
* @param Type the type of data returned by this model extractor
* T the type of data returned by this model extractor
*/
public interface ModelExtractor<Type extends Object> {
public interface ModelExtractor<T extends Object> {

Type get(ContentStore db, Map model, String key);
T get(ContentStore db, Map model, String key);

}
Original file line number Diff line number Diff line change
Expand Up @@ -19,15 +19,14 @@ public DocumentList get(ContentStore db, Map model, String key) {
String tagPath = config.get(Keys.TAG_PATH.replace(".", "_")).toString();

for (String tag : db.getAllTags()){
Map<String, Object> newTag = new HashMap<String, Object>();
String tagName = tag;
newTag.put("name",tagName);
Map<String, Object> newTag = new HashMap<>();
newTag.put("name", tag);

String uri = tagPath + File.separator + tag + config.get(Keys.OUTPUT_EXTENSION.replace(".", "_")).toString();

newTag.put("uri", uri);
newTag.put("tagged_posts", db.getPublishedPostsByTag(tagName));
newTag.put("tagged_documents", db.getPublishedDocumentsByTag(tagName));
newTag.put("tagged_posts", db.getPublishedPostsByTag(tag));
newTag.put("tagged_documents", db.getPublishedDocumentsByTag(tag));
dl.push(newTag);
}
return dl;
Expand Down
15 changes: 8 additions & 7 deletions jbake-core/src/main/java/org/jbake/util/PagingHelper.java
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,9 @@
import java.net.URISyntaxException;

public class PagingHelper {
long totalDocuments;
int postsPerPage;
private static final String URI_SEPARATOR = "/";
private long totalDocuments;
private int postsPerPage;

public PagingHelper(long totalDocuments, int postsPerPage) {
this.totalDocuments = totalDocuments;
Expand All @@ -16,15 +17,15 @@ public int getNumberOfPages() {
return (int) Math.ceil((totalDocuments * 1.0) / (postsPerPage * 1.0));
}

public String getNextFileName(int currentPageNumber, String fileName) throws URISyntaxException {
public String getNextFileName(int currentPageNumber) throws URISyntaxException {
if (currentPageNumber < getNumberOfPages()) {
return new URI((currentPageNumber + 1) + "/").toString();
return new URI((currentPageNumber + 1) + URI_SEPARATOR).toString();
} else {
return null;
}
}

public String getPreviousFileName(int currentPageNumber, String fileName) throws URISyntaxException {
public String getPreviousFileName(int currentPageNumber) throws URISyntaxException {

if (isFirstPage(currentPageNumber)) {
return null;
Expand All @@ -34,7 +35,7 @@ public String getPreviousFileName(int currentPageNumber, String fileName) throws
return "";
}
else {
return new URI((currentPageNumber - 1) + "/").toString();
return new URI((currentPageNumber - 1) + URI_SEPARATOR).toString();
}
}
}
Expand All @@ -48,7 +49,7 @@ public String getCurrentFileName(int page, String fileName) throws URISyntaxExce
return fileName;
}
else {
return new URI(page + "/" + fileName).toString();
return new URI(page + URI_SEPARATOR + fileName).toString();
}
}

Expand Down
Loading

0 comments on commit f8db6d6

Please sign in to comment.