use of org.apache.meecrowave.Meecrowave in project meecrowave by apache.
the class ListeningTest method events.
@Test
public void events() throws LifecycleException {
final Listener listener;
final String base;
int count = 0;
try (final Meecrowave meecrowave = new Meecrowave(new Meecrowave.Builder().randomHttpPort().includePackages(ListeningTest.class.getName())).bake()) {
count++;
listener = CDI.current().select(Listener.class).get();
assertEquals(count, listener.getEvents().size());
base = "http://localhost:" + meecrowave.getConfiguration().getHttpPort();
assertEquals(base, listener.getEvents().iterator().next().getFirstBase());
}
count++;
assertEquals(count, listener.getEvents().size());
assertEquals(base, listener.getEvents().get(count - 1).getFirstBase());
}
use of org.apache.meecrowave.Meecrowave in project component-runtime by Talend.
the class EnhancedCli method run.
@Override
public void run() {
try {
try (final Meecrowave meecrowave = new Meecrowave(create(args))) {
this.instance = meecrowave;
meecrowave.start();
meecrowave.deployClasspath(new Meecrowave.DeploymentMeta("", null, stdCtx -> {
stdCtx.setResources(new StandardRoot() {
@Override
protected void registerURLStreamHandlerFactory() {
// no-op: not supported into OSGi since there is already one and it must set a
// single time
}
});
}));
doWait(meecrowave, null);
}
} catch (final Exception e) {
throw new IllegalStateException(e);
}
}
use of org.apache.meecrowave.Meecrowave in project meecrowave by apache.
the class JBake method main.
// if you want to switch off PDF generation use as arguments: src/main/jbake target/site-tmp true false
public static void main(final String[] args) throws Exception {
// try to have parallelStream better than default
System.setProperty("java.util.concurrent.ForkJoinPool.common.parallelism", "64");
final File source = args == null || args.length < 1 ? new File("src/main/jbake") : new File(args[0]);
final File pdfSource = new File(source, "content");
final File destination = args == null || args.length < 2 ? new File("target/site-tmp") : new File(args[1]);
// by default we dev
final boolean startHttp = args == null || args.length < 2 || Boolean.parseBoolean(args[2]);
// by default...too slow sorry
final boolean skipPdf = args != null && args.length > 3 && !Boolean.parseBoolean(args[3]);
// grabs central
final boolean updateDownloads = args != null && args.length > 4 && Boolean.parseBoolean(args[4]);
// generation of dynamic content
new Configuration().run();
new CliConfiguration().run();
new ArquillianConfiguration().run();
new MavenConfiguration().run();
new OAuth2Configuration().run();
new LetsEncryptConfiguration().run();
new GradleConfiguration().run();
new ProxyConfiguration().run();
if (updateDownloads) {
final ByteArrayOutputStream tableContent = new ByteArrayOutputStream();
try (final PrintStream stream = new PrintStream(tableContent)) {
Downloads.doMain(stream);
}
try (final Writer writer = new FileWriter(new File(source, "content/download.adoc"))) {
writer.write("= Downloads\n" + ":jbake-generated: true\n" + ":jbake-date: 2017-07-24\n" + ":jbake-type: page\n" + ":jbake-status: published\n" + ":jbake-meecrowavepdf:\n" + ":jbake-meecrowavecolor: body-blue\n" + ":icons: font\n" + "\n" + "License under Apache License v2 (ALv2).\n" + "\n" + "[.table.table-bordered,options=\"header\"]\n" + "|===\n" + "|Name|Version|Date|Size|Type|Links\n");
writer.write(new String(tableContent.toByteArray(), StandardCharsets.UTF_8));
writer.write("\n|===\n");
}
}
final Runnable build = () -> {
System.out.println("Building Meecrowave website in " + destination);
final Orient orient = Orient.instance();
try {
final Oven oven = new Oven(new JBakeConfigurationFactory().createDefaultJbakeConfiguration(source, destination, new CompositeConfiguration() {
{
final CompositeConfiguration config = new CompositeConfiguration();
config.addConfiguration(new MapConfiguration(new HashMap<String, Object>() {
{
put("asciidoctor.attributes", new ArrayList<String>() {
{
add("source-highlighter=highlightjs");
add("highlightjs-theme=idea");
add("context_rootpath=/meecrowave");
add("icons=font");
}
});
}
}));
config.addConfiguration(DefaultJBakeConfiguration.class.cast(new ConfigUtil().loadConfig(source)).getCompositeConfiguration());
addConfiguration(config);
}
}, true));
System.out.println(" > baking");
oven.bake();
if (!skipPdf) {
System.out.println(" > pdfifying");
PDFify.generatePdf(pdfSource, destination);
}
System.out.println(" > done :)");
} catch (final Exception e) {
e.printStackTrace();
} finally {
orient.shutdown();
}
};
build.run();
if (startHttp) {
final Path watched = source.toPath();
final WatchService watchService = watched.getFileSystem().newWatchService();
watched.register(watchService, ENTRY_CREATE, ENTRY_DELETE, ENTRY_MODIFY);
final AtomicBoolean run = new AtomicBoolean(true);
final AtomicLong render = new AtomicLong(-1);
final Thread renderingThread = new Thread() {
{
setName("jbake-renderer");
}
@Override
public void run() {
long last = System.currentTimeMillis();
while (run.get()) {
if (render.get() > last) {
last = System.currentTimeMillis();
try {
build.run();
} catch (final Throwable oops) {
oops.printStackTrace();
}
}
try {
sleep(TimeUnit.SECONDS.toMillis(1));
} catch (final InterruptedException e) {
Thread.currentThread().interrupt();
break;
}
}
System.out.println("Exiting renderer");
}
};
final Thread watcherThread = new Thread() {
{
setName("jbake-file-watcher");
}
@Override
public void run() {
while (run.get()) {
try {
final WatchKey key = watchService.poll(1, TimeUnit.SECONDS);
if (key == null) {
continue;
}
for (final WatchEvent<?> event : key.pollEvents()) {
final WatchEvent.Kind<?> kind = event.kind();
if (kind != ENTRY_CREATE && kind != ENTRY_DELETE && kind != ENTRY_MODIFY) {
// unlikely but better to protect ourself
continue;
}
final Path updatedPath = Path.class.cast(event.context());
if (kind == ENTRY_DELETE || updatedPath.toFile().isFile()) {
final String path = updatedPath.toString();
if (!path.contains("___jb") && !path.endsWith("~")) {
render.set(System.currentTimeMillis());
}
}
}
key.reset();
} catch (final InterruptedException e) {
Thread.currentThread().interrupt();
run.compareAndSet(true, false);
} catch (final ClosedWatchServiceException cwse) {
if (!run.get()) {
throw new IllegalStateException(cwse);
}
}
}
System.out.println("Exiting file watcher");
}
};
renderingThread.start();
watcherThread.start();
final Runnable onQuit = () -> {
run.compareAndSet(true, false);
Stream.of(watcherThread, renderingThread).forEach(thread -> {
try {
thread.join();
} catch (final InterruptedException e) {
Thread.currentThread().interrupt();
}
});
try {
watchService.close();
} catch (final IOException ioe) {
// not important
}
};
try (final Meecrowave container = new Meecrowave(new Meecrowave.Builder() {
{
setWebResourceCached(false);
property("proxy-skip", "true");
}
}) {
{
start();
getTomcat().getServer().setParentClassLoader(Thread.currentThread().getContextClassLoader());
deployWebapp("/meecrowave", destination);
}
}) {
System.out.println("Started on http://localhost:" + container.getConfiguration().getHttpPort() + "/meecrowave");
final Scanner console = new Scanner(System.in);
String cmd;
while (((cmd = console.nextLine())) != null) {
if ("quit".equals(cmd)) {
break;
} else if ("r".equals(cmd) || "rebuild".equals(cmd) || "build".equals(cmd) || "b".equals(cmd)) {
render.set(System.currentTimeMillis());
} else {
System.err.println("Ignoring " + cmd + ", please use 'build' or 'quit'");
}
}
}
onQuit.run();
}
}
use of org.apache.meecrowave.Meecrowave in project meecrowave by apache.
the class Cli method run.
public void run() {
final ParsedCommand parsedCommand = new ParsedCommand(args).invoke();
if (parsedCommand.isFailed()) {
return;
}
final Meecrowave.Builder builder = parsedCommand.getBuilder();
final CommandLine line = parsedCommand.getLine();
try (final Meecrowave meecrowave = new Meecrowave(builder)) {
synchronized (this) {
if (closed) {
return;
}
this.instance = meecrowave;
}
final String ctx = line.getOptionValue("context", "");
final String fixedCtx = !ctx.isEmpty() && !ctx.startsWith("/") ? '/' + ctx : ctx;
final String war = line.getOptionValue("webapp");
meecrowave.start();
if (war == null) {
meecrowave.deployClasspath(new Meecrowave.DeploymentMeta(ctx, ofNullable(line.getOptionValue("docbase")).map(File::new).orElseGet(() -> Stream.of("base", "home").map(it -> System.getProperty("meecrowave." + it)).filter(Objects::nonNull).map(it -> new File(it, "docBase")).filter(File::isDirectory).findFirst().orElse(null)), null, null));
} else {
meecrowave.deployWebapp(fixedCtx, new File(war));
}
doWait(meecrowave, line);
}
}
use of org.apache.meecrowave.Meecrowave in project meecrowave by apache.
the class JohnzonBufferTest method test.
@Test
public void test() {
DebugJohnzonBufferStrategy.resetCounter();
try (final Meecrowave meecrowave = new Meecrowave(new Meecrowave.Builder().randomHttpPort().jsonpBufferStrategy(DebugJohnzonBufferStrategy.class.getName()).includePackages("org.superbiz.app.TestJsonEndpoint")).bake()) {
final Client client = ClientBuilder.newClient();
try {
String jsonResponse = client.target("http://localhost:" + meecrowave.getConfiguration().getHttpPort() + "/testjsonendpoint/book").request(MediaType.APPLICATION_JSON).get(String.class);
assertEquals("{\"isbn\":\"dummyisbn\"}", jsonResponse);
// reader fact -> parser fact (2 buffers) + writer -> generator (1 buffer)
assertEquals(3, DebugJohnzonBufferStrategy.getCounter());
} finally {
client.close();
}
}
}
Aggregations