All Downloads are FREE. Search and download functionalities are using the official Maven repository.

org.jbake.launcher.Baker Maven / Gradle / Ivy

Go to download

JBake is a Java based open source static site/blog generator for developers.

There is a newer version: 2.7.0-rc.7
Show newest version
package org.jbake.launcher;

import org.apache.commons.configuration2.CompositeConfiguration;
import org.jbake.app.JBakeException;
import org.jbake.app.Oven;
import org.jbake.app.configuration.JBakeConfiguration;
import org.jbake.app.configuration.JBakeConfigurationFactory;

import java.text.MessageFormat;
import java.util.List;

/**
 * Delegate class responsible for launching a Bake.
 *
 * @author [email protected]
 */
public class Baker {

    /**
     * @param options The given cli options
     * @param config  The project configuration
     * @deprecated use {@link Baker#bake(JBakeConfiguration)} instead
     */
    @Deprecated
    public void bake(final LaunchOptions options, final CompositeConfiguration config) {
        JBakeConfiguration configuration = new JBakeConfigurationFactory().createDefaultJbakeConfiguration(options.getSource(), options.getDestination(), config, options.isClearCache());
        bake(configuration);
    }

    public void bake(final JBakeConfiguration config) {
        final Oven oven = new Oven(config);
        oven.bake();

        final List errors = oven.getErrors();
        if (!errors.isEmpty()) {
            final StringBuilder msg = new StringBuilder();
            // TODO: decide, if we want the all errors here
            msg.append( MessageFormat.format("JBake failed with {0} errors:\n", errors.size()));
            int errNr = 1;
            for (final Throwable error : errors) {
                msg.append(MessageFormat.format("{0}. {1}\n", errNr, error.getMessage()));
                ++errNr;
            }
            throw new JBakeException(SystemExit.ERROR ,msg.toString(), errors.get(0));
        }
    }
}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy