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

com.adobe.granite.crx2oak.model.ModelInitializer Maven / Gradle / Ivy

/*************************************************************************
 *
 * ADOBE CONFIDENTIAL
 * ___________________
 *
 * Copyright 2016 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.model;

import com.adobe.granite.crx2oak.cli.CRX2OakOption;
import com.adobe.granite.crx2oak.pipeline.InputAggregatingComponent;
import com.adobe.granite.crx2oak.pipeline.PipeData;
import com.adobe.granite.crx2oak.pipeline.Pipeline;
import com.adobe.granite.crx2oak.pipeline.PipelineComponent;
import com.adobe.granite.crx2oak.profile.model.osgi.OsgiConfiguration;
import joptsimple.OptionParser;
import joptsimple.OptionSet;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import java.util.ArrayList;

import static com.adobe.granite.crx2oak.model.ExitCode.UNABLE_TO_PROCESS_OPTION_ERROR_EXIT_CODE;
import static java.lang.String.format;
import static org.apache.jackrabbit.oak.upgrade.cli.parser.OptionParserFactory.HELP;

public class ModelInitializer extends InputAggregatingComponent {
    private static final Logger LOGGER = LoggerFactory.getLogger(ModelInitializer.class);

    @Override
    public PipeData preprocess(final PipeData input) {
        try {
            return initialize(input);
        } catch (RuntimeException e) {
            return abortInitialization(e);
        }
    }

    private PipeData abortInitialization(final RuntimeException e) {
        final String message = format("%s. Use %s option to see a full usage",
                e.getMessage(), CRX2OakOption.getDashedOptionFor(HELP));
        LOGGER.error(message);
        return Pipeline.streamClosed(PipeData
                .put(Topics.EXIT_CODE, UNABLE_TO_PROCESS_OPTION_ERROR_EXIT_CODE)
                .toPipe());
    }

    private PipeData initialize(final PipeData input) {
        final OptionParser parser = input.require(Topics.OPTION_PARSER);
        final String[] args = input.require(Topics.CMD_LINE_ARGS);
        final OptionSet optionSet = parser.parse(args);
        return PipeData
                .put(Topics.RUN_MODE, RunMode.STANDALONE)
                .put(Topics.MIGRATION_MODE, MigrationMode.DRY_PREPARE_MIGRATION_MODE)
                .put(Topics.ORIGINAL_CMD_LINE_ARGS, args)
                .put(Topics.INSTALLABLE_OSGI_CONFIGS, new ArrayList())
                .put(Topics.PRE_MIGRATION_ACTIONS, new ArrayList())
                .put(Topics.POST_MIGRATION_ACTIONS, new ArrayList())
                .put(Topics.OPTION_SET, optionSet)
                .put(Topics.WARNINGS, new ArrayList())
                .toPipe();
    }
}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy