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

com.adobe.granite.crx2oak.core.DryModeBreaker 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.core;

import com.adobe.granite.crx2oak.model.MigrationMode;
import com.adobe.granite.crx2oak.pipeline.PipeData;
import com.adobe.granite.crx2oak.pipeline.Pipeline;
import com.adobe.granite.crx2oak.pipeline.PipelineComponent;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import static com.adobe.granite.crx2oak.cli.CRX2OakOption.DRY;
import static com.adobe.granite.crx2oak.cli.CRX2OakOption.MIGRATE;
import static com.adobe.granite.crx2oak.model.MigrationMode.DRY_PREPARE_MIGRATION_MODE;
import static com.adobe.granite.crx2oak.model.MigrationMode.WET_MIGRATE_MIGRATION_MODE;
import static com.adobe.granite.crx2oak.model.Topics.MIGRATION_MODE;
import static com.adobe.granite.crx2oak.model.Topics.OPTION_SET;

/**
 * Breaks the processing if dry option has been added to command line.
 */
public class DryModeBreaker implements PipelineComponent {
    private static final Logger LOGGER = LoggerFactory.getLogger(DryModeBreaker.class);

    @Override
    public PipeData process(final PipeData input) {
        return shouldAppBeAborted(input) ? abortProcessing(input) : input;
    }

    private PipeData abortProcessing(final PipeData input) {
        LOGGER.info("The tool is running in {} and real migration is skipped for this invocation.",
                getMigrationMode(input));
        LOGGER.info("If you have backup and you are sure what you are doing please remove: {} option", DRY.dashedOption);
        LOGGER.info("or pass {} if you haven't specified any other command line argument to use default " +
                "migration profile", MIGRATE.dashedOption);
        return Pipeline.streamClosed(input);
    }

    private boolean shouldAppBeAborted(final PipeData input) {
        return getMigrationMode(input) != WET_MIGRATE_MIGRATION_MODE || input.require(OPTION_SET).has(DRY.option);
    }

    private MigrationMode getMigrationMode(final PipeData input) {
        return input.get(MIGRATION_MODE).or(DRY_PREPARE_MIGRATION_MODE);
    }
}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy