com.adobe.granite.crx2oak.CRX2Oak Maven / Gradle / Ivy
/*************************************************************************
*
* ADOBE CONFIDENTIAL
* ___________________
*
* Copyright 2011 Adobe Systems Incorporated
* All Rights Reserved.
*
* NOTICE: All information contained herein is, and remains
* the property of Adobe Systems Incorporated and its suppliers,
* if any. The intellectual and technical concepts contained
* herein are proprietary to Adobe Systems Incorporated and its
* suppliers and are protected by trade secret or copyright law.
* Dissemination of this information or reproduction of this material
* is strictly forbidden unless prior written permission is obtained
* from Adobe Systems Incorporated.
**************************************************************************/
package com.adobe.granite.crx2oak;
import com.adobe.granite.crx2oak.cli.CRX2OakOption;
import com.adobe.granite.crx2oak.cli.CliTools;
import com.adobe.granite.crx2oak.cli.transformer.CommandLineTransformerEngine;
import com.adobe.granite.crx2oak.logging.LoggingLevelControllerFactory;
import com.adobe.granite.crx2oak.logging.RealSlf4jProvider;
import com.adobe.granite.crx2oak.model.Topics;
import com.adobe.granite.crx2oak.pipeline.PipeData;
import com.adobe.granite.crx2oak.pipeline.Pipeline;
import com.adobe.granite.crx2oak.pipeline.PipelineComponent;
import com.google.common.base.Optional;
import joptsimple.OptionParser;
import org.apache.jackrabbit.oak.upgrade.cli.parser.OptionParserFactory;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import java.util.Arrays;
import java.util.List;
import static com.adobe.granite.crx2oak.CoreComponents.getCoreComponents;
import static com.adobe.granite.crx2oak.MigrationComponents.getMigrationComponents;
import static com.adobe.granite.crx2oak.pipeline.PipeData.put;
import static com.google.common.collect.Iterables.concat;
/**
* The Java executable entry point (a.k.a application Main class).
*/
public class CRX2Oak {
public static final Logger LOGGER = LoggerFactory.getLogger(CRX2Oak.class);
public static void main(String... args) {
processAppOutput(run(args));
}
/**
* Able to invoke CRX2Oak without causing JVM termination in case the exit code needs to be returned.
* Instead
*
* @param args command line argument
* @return the pipe data that should contain exit code in a specific topic: {@linkplain Topics#EXIT_CODE}
*/
public static PipeData run(final String[] args) {
LOGGER.info("started with args: {}", Arrays.asList(args));
final OptionParser parser = CRX2OakOption.passAllOptionsToParser(OptionParserFactory.create());
final PipeData input = put(Topics.OPTION_PARSER, parser).put(Topics.CMD_LINE_ARGS, args).toPipe();
return Pipeline.of(getAppComponents(parser)).run(input);
}
private static Iterable getAppComponents(final OptionParser parser) {
final LoggingLevelControllerFactory logLevelCtrlFactory = new LoggingLevelControllerFactory(
new RealSlf4jProvider());
final CommandLineTransformerEngine cmdlineTransformer = CliTools.getCommandLineTransformerEngine();
return concat(
getCoreComponents(logLevelCtrlFactory, cmdlineTransformer, parser),
getMigrationComponents(logLevelCtrlFactory, cmdlineTransformer)
);
}
private static void processAppOutput(final PipeData output) {
final Optional> optionalWarnings = output.get(Topics.WARNINGS);
if (optionalWarnings.isPresent()) {
outputWarnings(optionalWarnings.get());
}
final Optional exitCode = output.get(Topics.EXIT_CODE);
if (exitCode.isPresent()) {
System.exit(exitCode.get());
}
}
private static void outputWarnings(final List strings) {
for (String warning : strings) {
System.out.println(warning);
LOGGER.warn(warning);
}
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy