Skip to content

Commit

Permalink
Merge pull request #358 from orchidhq/dev
Browse files Browse the repository at this point in the history
Release 0.19.0
  • Loading branch information
cjbrooks12 authored Feb 23, 2020
2 parents 725f703 + 426ad5d commit b8e600a
Show file tree
Hide file tree
Showing 286 changed files with 5,192 additions and 3,771 deletions.
4 changes: 4 additions & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,19 +16,23 @@ branches:
- dev

jobs:
allow_failures:
- jdk: openjdk13
include:
- { stage: testDebug, os: linux, jdk: openjdk8, script: './test.sh debug', }
- { stage: testDebug, os: linux, jdk: oraclejdk8, script: './test.sh debug', }
# - { stage: testDebug, os: linux, jdk: oraclejdk9, script: './test.sh debug', }
- { stage: testDebug, os: linux, jdk: openjdk10, script: './test.sh debug', }
- { stage: testDebug, os: linux, jdk: openjdk11, script: './test.sh debug', }
- { stage: testDebug, os: linux, jdk: openjdk13, script: './test.sh debug', }
- { stage: testDebug, os: osx, osx_image: xcode8.3, script: './test.sh debug', }

- { stage: testRelease, os: linux, jdk: openjdk8, script: './test.sh release', }
- { stage: testRelease, os: linux, jdk: oraclejdk8, script: './test.sh release', }
# - { stage: testRelease, os: linux, jdk: oraclejdk9, script: './test.sh release', }
- { stage: testRelease, os: linux, jdk: openjdk10, script: './test.sh release', }
- { stage: testRelease, os: linux, jdk: openjdk11, script: './test.sh release', }
- { stage: testRelease, os: linux, jdk: openjdk13, script: './test.sh release', }
- { stage: testRelease, os: osx, osx_image: xcode8.3, script: './test.sh release', }

- { stage: afterTests, os: linux, jdk: openjdk8, script: './afterTests.sh', }
Expand Down
1 change: 0 additions & 1 deletion OrchidCore/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,6 @@ dependencies {
implementation(Libs.flexmark_ext_aside)
implementation(Libs.flexmark_ext_attributes)
implementation(Libs.flexmark_ext_enumerated_reference)
implementation(Libs.flexmark_ext_gfm_tables)
implementation(Libs.flexmark_ext_gfm_tasklist)
implementation(Libs.flexmark_ext_toc)
implementation(Libs.flexmark_ext_anchorlink)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@ public void finish() {
}

@Override
@SuppressWarnings(SuppressedWarnings.UNCHECKED_JAVA)
@SuppressWarnings("unchecked")
public <T extends OrchidService> T getService(Class<T> serviceClass) {
return (T) services.get(serviceClass);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,10 @@

import com.eden.common.util.EdenPair;
import com.eden.orchid.api.OrchidService;
import com.eden.orchid.api.resources.resource.OrchidResource;
import com.google.inject.ImplementedBy;

import javax.annotation.Nullable;
import java.util.List;
import java.util.Map;
import java.util.Set;
Expand Down Expand Up @@ -66,19 +68,6 @@ default Set<String> getParserExtensions() {
return getService(CompilerService.class).getParserExtensions();
}

/**
* Finds an OrchidCompiler capable of evaluating input with a given file extension.
*
* @param extension the extension representing content that needs to be compiled
* @return an appropriate OrchidCompiler if once was found that matches the extension, null otherwise
*
* @since v1.0.0
* @see OrchidCompiler
*/
default OrchidCompiler compilerFor(String extension) {
return getService(CompilerService.class).compilerFor(extension);
}

/**
* Finds an OrchidParser capable of evaluating input with a given file extension.
*
Expand All @@ -96,21 +85,7 @@ default OrchidParser parserFor(String extension) {
* Compiles input against a given Compiler identified by file extension. Additional data may be passed in that
* individual Compilers may use to render into the resulting output.
*
* @param extension the extension to find a Compiler for
* @param input the input to compile
* @return the compiled output data if an appropriate Compiler could be found, otherwise the unprocessed input
*
* @since v1.0.0
* @see OrchidCompiler
*/
default String compile(String extension, String input) {
return getService(CompilerService.class).compile(extension, input);
}

/**
* Compiles input against a given Compiler identified by file extension. Additional data may be passed in that
* individual Compilers may use to render into the resulting output.
*
* @param resource the source resource where the content is coming from
* @param extension the extension to find a Compiler for
* @param input the input to compile
* @param data additional data to pass to the OrchidCompiler
Expand All @@ -119,8 +94,8 @@ default String compile(String extension, String input) {
* @since v1.0.0
* @see OrchidCompiler
*/
default String compile(String extension, String input, Object data) {
return getService(CompilerService.class).compile(extension, input, data);
default String compile(@Nullable OrchidResource resource, String extension, String input, Object data) {
return getService(CompilerService.class).compile(resource, extension, input, data);
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,15 @@
import com.eden.orchid.api.options.annotations.Option;
import com.eden.orchid.api.options.annotations.StringDefault;
import com.eden.orchid.api.options.archetypes.ConfigArchetype;
import com.eden.orchid.api.resources.resource.OrchidResource;
import kotlin.Lazy;
import kotlin.LazyKt;
import org.json.JSONObject;

import javax.inject.Singleton;
import java.io.ByteArrayOutputStream;
import java.io.OutputStream;
import java.nio.charset.StandardCharsets;
import java.util.ArrayList;
import java.util.Collections;
import java.util.HashMap;
Expand Down Expand Up @@ -147,7 +151,7 @@ public Set<String> getParserExtensions() {
return parserExtensions;
}

public OrchidCompiler compilerFor(String extension) {
private OrchidCompiler compilerFor(String extension) {
if (customCompilerMap != null && customCompilerMap.containsKey(extension)) {
return customCompilerMap.get(extension);
}
Expand All @@ -158,15 +162,15 @@ public OrchidParser parserFor(String extension) {
return parserMap.getOrDefault(extension, null);
}

public String compile(String extension, String input) {
return this.compile(extension, input, null);
}

public String compile(String extension, String input, Object data) {
@Override
public String compile(OrchidResource resource, String extension, String input, Object data) {
OrchidCompiler compiler = compilerFor(extension);
if (compiler != null) {
synchronized (compiler) {
return compiler.compile(extension, input, context.getSiteData(data));
ByteArrayOutputStream os = new ByteArrayOutputStream();
compiler.compile(os, resource, extension, input, context.getSiteData(data));

return new String(os.toByteArray(), StandardCharsets.UTF_8);
}
} else {
return input;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,12 @@

import com.eden.orchid.api.options.OptionsHolder;
import com.eden.orchid.api.registration.Prioritized;
import com.eden.orchid.api.resources.resource.OrchidResource;

import javax.annotation.Nullable;
import java.io.OutputStream;
import java.io.OutputStreamWriter;
import java.nio.charset.StandardCharsets;
import java.util.Map;

/**
Expand Down Expand Up @@ -37,7 +42,7 @@ public OrchidCompiler(int priority) {
*
* @since v1.0.0
*/
public abstract String compile(String extension, String input, Map<String, Object> data);
public abstract void compile(OutputStream os, @Nullable OrchidResource resource, String extension, String input, Map<String, Object> data);

/**
* Gets the file extension representing the type of the output content.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@

import javax.inject.Inject;
import javax.inject.Singleton;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.HashMap;
import java.util.List;
import java.util.Objects;
Expand All @@ -40,6 +42,7 @@ public final class GeneratorServiceImpl implements GeneratorService {

private OrchidContext context;
private BuildMetrics metrics;
private OrchidGenerator.Stage currentGeneratorStage = null;

@Option
@Description("Whitelist the generators in this array, only indexing and generating these generators.")
Expand Down Expand Up @@ -75,6 +78,7 @@ public String[] getGeneratorKeys(String[] include, String[] exclude) {

@Override
public void startIndexing() {
Clog.i("Indexing Generators");
try {
context.popInjector("generating");
}
Expand All @@ -87,12 +91,18 @@ public void startIndexing() {

metrics.startIndexing(allGenerators.getValue());
context.clearIndex();
currentGeneratorStage = null;
getFilteredGenerators().forEach(this::indexGenerator);
metrics.stopIndexing();
}

private <T extends OrchidGenerator.Model> void indexGenerator(OrchidGenerator<T> generator) {
Clog.i("Indexing [{}: {}]", generator.getPriority(), generator.getKey());
if(generator.getStage() != currentGeneratorStage) {
currentGeneratorStage = generator.getStage();
Clog.i(" {} Stage", currentGeneratorStage);
}

Clog.i(" Indexing [{}]", generator.getKey());
context.broadcast(Orchid.Lifecycle.IndexGeneratorStart.fire(generator));
metrics.startIndexingGenerator(generator.getKey());
JSONElement el = context.query(generator.getKey());
Expand All @@ -118,8 +128,8 @@ private <T extends OrchidGenerator.Model> void indexGenerator(OrchidGenerator<T>
}
context.getIndex().addChildIndex(generator.getKey(), index, generatorModel);
// get the collections from a generator
List<? extends OrchidCollection> generatorCollections = generator.getCollections(context, generatorModel);
if (generatorCollections != null && generatorCollections.size() > 0) {
List<? extends OrchidCollection> generatorCollections = generatorModel.getCollections();
if (generatorCollections.size() > 0) {
context.addCollections(generatorCollections);
}
// notify the generator is finished indexing
Expand All @@ -136,6 +146,7 @@ private <T extends OrchidGenerator.Model> void indexGenerator(OrchidGenerator<T>

@Override
public void startGeneration() {
Clog.i("Rendering Pages");
List<Pair<String, ?>> generatorModelPairs = context
.getIndex()
.getAllIndexedPages()
Expand All @@ -147,12 +158,18 @@ public void startGeneration() {
context.pushInjector("generating", generatorModelPairs);

metrics.startGeneration();
currentGeneratorStage = null;
getFilteredGenerators().forEach(this::useGenerator);
metrics.stopGeneration();
}

private <T extends OrchidGenerator.Model> void useGenerator(OrchidGenerator<T> generator) {
Clog.i("Generating [{}: {}]", generator.getPriority(), generator.getKey());
if(generator.getStage() != currentGeneratorStage) {
currentGeneratorStage = generator.getStage();
Clog.i(" {} Stage",currentGeneratorStage);
}

Clog.i(" Generating [{}]", generator.getKey());
metrics.startGeneratingGenerator(generator.getKey());
OrchidGenerator.Model generatorModel = context.getIndex().getChildIndex(generator.getKey());
if (generatorModel == null) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ public boolean validate(OptionsHolder optionsHolder) {
return true;
}
catch (Exception e) {
Clog.e("{} did not pass validation", optionsHolder, e);
Clog.e("{} did not pass validation", e, optionsHolder);
return false;
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,11 @@

import com.caseyjbrooks.clog.Clog;
import com.eden.orchid.api.OrchidContext;
import com.eden.orchid.api.resources.resourcesource.OrchidResourceSource;
import com.eden.orchid.api.resources.resourcesource.PluginResourceSource;
import com.eden.orchid.api.server.admin.AdminList;
import com.eden.orchid.api.server.annotations.Extensible;
import com.eden.orchid.impl.resources.PluginJarResourceSource;
import com.eden.orchid.impl.resources.resourcesource.PluginJarResourceSource;
import com.google.inject.AbstractModule;
import com.google.inject.Module;
import com.google.inject.binder.AnnotatedBindingBuilder;
Expand Down Expand Up @@ -130,7 +131,7 @@ public final void withResources(int priority) {
if(hasResources) {
throw new IllegalStateException(Clog.format("Resources already added to {}", this.getClass().getName()));
}
addToSet(PluginResourceSource.class, new PluginJarResourceSource(this.getClass(), priority));
addToSet(OrchidResourceSource.class, PluginJarResourceSource.INSTANCE.create(this.getClass(), priority, PluginResourceSource.INSTANCE));
hasResources = true;
resourcePriority = priority;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,23 +25,17 @@ public FileRenderer(@Named("dest") String destination) {
public boolean render(OrchidPage page, InputStream content) {
boolean success;

String outputPath = OrchidUtils.normalizePath(page.getReference().getPath());
String outputName;
if(EdenUtils.isEmpty(OrchidUtils.normalizePath(page.getReference().getOutputExtension()))) {
outputName = OrchidUtils.normalizePath(page.getReference().getFileName());
}
else {
outputName = OrchidUtils.normalizePath(page.getReference().getFileName()) + "." + OrchidUtils.normalizePath(page.getReference().getOutputExtension());
}
// get the file that this page will be written to
File outputFile = new File(this.destination + "/" + page.getReference().getPathOnDisk());

File outputFile = new File(this.destination + "/" + outputPath);
if (!outputFile.exists()) {
outputFile.mkdirs();
// if its parent directory does not exist, make sure to create it
if (!outputFile.getParentFile().exists()) {
outputFile.getParentFile().mkdirs();
}

// write the page's contents to disk
try {
Path destinationFile = Paths.get(this.destination + "/" + outputPath + "/" + outputName);
Files.write(destinationFile, IOUtils.toByteArray(content));
Files.write(outputFile.toPath(), IOUtils.toByteArray(content));
success = true;
}
catch (Exception e) {
Expand Down
Loading

0 comments on commit b8e600a

Please sign in to comment.