Search in sources :

Example 1 with MigrationTaskException

use of com.mulesoft.tools.migration.exception.MigrationTaskException in project mule-migration-assistant by mulesoft.

the class MigrationJob method execute.

@Override
public void execute(MigrationReport report) throws Exception {
    ApplicationModel applicationModel = generateSourceApplicationModel(project);
    report.initialize(applicationModel.getProjectType(), project.getFileName().toString());
    Path sourceProjectBasePath = applicationModel.getProjectBasePath();
    persistApplicationModel(applicationModel);
    ProjectType targetProjectType = applicationModel.getProjectType().getTargetType();
    applicationModel = generateTargetApplicationModel(outputProject, targetProjectType, sourceProjectBasePath, projectParentGAV, projectGAV);
    try {
        for (AbstractMigrationTask task : migrationTasks) {
            if (task.getApplicableProjectTypes().contains(targetProjectType)) {
                task.setApplicationModel(applicationModel);
                task.setExpressionMigrator(new MelToDwExpressionMigrator(report, applicationModel));
                try {
                    task.execute(report);
                    persistApplicationModel(applicationModel);
                    applicationModel = generateTargetApplicationModel(outputProject, targetProjectType, sourceProjectBasePath, projectParentGAV, projectGAV);
                } catch (MigrationTaskException ex) {
                    if (cancelOnError) {
                        throw ex;
                    } else {
                        logger.error("Failed to apply task, rolling back and continuing with the next one.", ex);
                    }
                } catch (RuntimeException e) {
                    throw new MigrationJobException("Failed to continue executing migration: " + e.getClass().getName() + ": " + e.getMessage(), e);
                }
            }
        }
    } finally {
        generateReport(report, applicationModel);
    }
}
Also used : Path(java.nio.file.Path) MelToDwExpressionMigrator(com.mulesoft.tools.migration.library.tools.MelToDwExpressionMigrator) MigrationJobException(com.mulesoft.tools.migration.engine.exception.MigrationJobException) AbstractMigrationTask(com.mulesoft.tools.migration.task.AbstractMigrationTask) ProjectType(com.mulesoft.tools.migration.project.ProjectType) ApplicationModel(com.mulesoft.tools.migration.project.model.ApplicationModel) MigrationTaskException(com.mulesoft.tools.migration.exception.MigrationTaskException)

Example 2 with MigrationTaskException

use of com.mulesoft.tools.migration.exception.MigrationTaskException in project mule-migration-assistant by mulesoft.

the class AbstractMigrationTask method execute.

@Override
public void execute(MigrationReport report) throws Exception {
    // TODO depending on the project type this may not be true
    checkState(applicationModel != null, "An application model must be provided.");
    List<MigrationStep> steps = enableReporting(getSteps());
    try {
        if (steps != null) {
            MigrationStepSelector stepSelector = new MigrationStepSelector(steps);
            if (shouldExecuteAllSteps(stepSelector)) {
                steps.stream().filter(s -> s instanceof ExpressionMigratorAware).forEach(s -> ((ExpressionMigratorAware) s).setExpressionMigrator(getExpressionMigrator()));
                stepSelector.getNameSpaceContributionSteps().forEach(s -> s.execute(applicationModel, report));
                stepSelector.getApplicationModelContributionSteps().forEach(s -> {
                    s.setApplicationModel(applicationModel);
                    fetchAndProcessNodes(report, s, new ArrayList<>());
                });
                stepSelector.getProjectStructureContributionSteps().forEach(s -> {
                    s.setApplicationModel(applicationModel);
                    s.execute(applicationModel.getProjectBasePath(), report);
                });
                stepSelector.getPomContributionSteps().forEach(s -> {
                    s.setApplicationModel(applicationModel);
                    s.execute(applicationModel.getPomModel().orElse(new PomModel()), report);
                });
            }
        }
    } catch (MigrationAbortException e) {
        throw e;
    } catch (Exception e) {
        throw new MigrationTaskException("Task execution exception. " + e.getMessage(), e);
    }
}
Also used : System.lineSeparator(java.lang.System.lineSeparator) MigrationReport(com.mulesoft.tools.migration.step.category.MigrationReport) Collectors(java.util.stream.Collectors) ApplicationModel(com.mulesoft.tools.migration.project.model.ApplicationModel) Preconditions.checkState(com.google.common.base.Preconditions.checkState) XMLOutputter(org.jdom2.output.XMLOutputter) ArrayList(java.util.ArrayList) ExpressionMigrator(com.mulesoft.tools.migration.util.ExpressionMigrator) Preconditions.checkArgument(com.google.common.base.Preconditions.checkArgument) MigrationStep(com.mulesoft.tools.migration.step.MigrationStep) List(java.util.List) MigrationTaskException(com.mulesoft.tools.migration.exception.MigrationTaskException) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) ExpressionMigratorAware(com.mulesoft.tools.migration.step.ExpressionMigratorAware) MigrationStepException(com.mulesoft.tools.migration.exception.MigrationStepException) MigrationAbortException(com.mulesoft.tools.migration.exception.MigrationAbortException) ReportingStep(com.mulesoft.tools.migration.step.ReportingStep) PomModel(com.mulesoft.tools.migration.project.model.pom.PomModel) ApplicationModelContribution(com.mulesoft.tools.migration.step.category.ApplicationModelContribution) Element(org.jdom2.Element) MigrationAbortException(com.mulesoft.tools.migration.exception.MigrationAbortException) ExpressionMigratorAware(com.mulesoft.tools.migration.step.ExpressionMigratorAware) MigrationStep(com.mulesoft.tools.migration.step.MigrationStep) PomModel(com.mulesoft.tools.migration.project.model.pom.PomModel) MigrationTaskException(com.mulesoft.tools.migration.exception.MigrationTaskException) MigrationStepException(com.mulesoft.tools.migration.exception.MigrationStepException) MigrationAbortException(com.mulesoft.tools.migration.exception.MigrationAbortException) MigrationTaskException(com.mulesoft.tools.migration.exception.MigrationTaskException)

Aggregations

MigrationTaskException (com.mulesoft.tools.migration.exception.MigrationTaskException)2 ApplicationModel (com.mulesoft.tools.migration.project.model.ApplicationModel)2 Preconditions.checkArgument (com.google.common.base.Preconditions.checkArgument)1 Preconditions.checkState (com.google.common.base.Preconditions.checkState)1 MigrationJobException (com.mulesoft.tools.migration.engine.exception.MigrationJobException)1 MigrationAbortException (com.mulesoft.tools.migration.exception.MigrationAbortException)1 MigrationStepException (com.mulesoft.tools.migration.exception.MigrationStepException)1 MelToDwExpressionMigrator (com.mulesoft.tools.migration.library.tools.MelToDwExpressionMigrator)1 ProjectType (com.mulesoft.tools.migration.project.ProjectType)1 PomModel (com.mulesoft.tools.migration.project.model.pom.PomModel)1 ExpressionMigratorAware (com.mulesoft.tools.migration.step.ExpressionMigratorAware)1 MigrationStep (com.mulesoft.tools.migration.step.MigrationStep)1 ReportingStep (com.mulesoft.tools.migration.step.ReportingStep)1 ApplicationModelContribution (com.mulesoft.tools.migration.step.category.ApplicationModelContribution)1 MigrationReport (com.mulesoft.tools.migration.step.category.MigrationReport)1 AbstractMigrationTask (com.mulesoft.tools.migration.task.AbstractMigrationTask)1 ExpressionMigrator (com.mulesoft.tools.migration.util.ExpressionMigrator)1 System.lineSeparator (java.lang.System.lineSeparator)1 Path (java.nio.file.Path)1 ArrayList (java.util.ArrayList)1