Search in sources :

Example 1 with MigrationStepException

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

the class AbstractSpringMigratorStep method resolveSpringFile.

protected Document resolveSpringFile(Document currentDoc, Document springDocument, final Map<Path, Document> artifactDocs) {
    Path beansPath = null;
    // Check if a spring file already exists for this mule config
    for (Entry<Path, Document> entry : artifactDocs.entrySet()) {
        if (currentDoc.equals(entry.getValue())) {
            beansPath = resolveSpringBeansPath(entry);
            if (artifactDocs.containsKey(Paths.get(SPRING_FOLDER + beansPath.getFileName().toString()))) {
                return artifactDocs.get(Paths.get(SPRING_FOLDER + beansPath.getFileName().toString()));
            }
        }
    }
    // If not, create it and link it
    for (Entry<Path, Document> entry : artifactDocs.entrySet()) {
        if (currentDoc.equals(entry.getValue())) {
            beansPath = resolveSpringBeansPath(entry);
            try {
                SAXBuilder saxBuilder = new SAXBuilder();
                springDocument = saxBuilder.build(AbstractSpringMigratorStep.class.getClassLoader().getResourceAsStream("spring/empty-beans.xml"));
            } catch (JDOMException | IOException e) {
                throw new MigrationStepException(e.getMessage(), e);
            }
            addSpringModuleConfig(currentDoc, "spring/" + beansPath.getFileName().toString());
            break;
        }
    }
    if (beansPath == null) {
        return null;
    }
    artifactDocs.put(Paths.get(SPRING_FOLDER + beansPath.getFileName().toString()), springDocument);
    return springDocument;
}
Also used : Path(java.nio.file.Path) SAXBuilder(org.jdom2.input.SAXBuilder) MigrationStepException(com.mulesoft.tools.migration.exception.MigrationStepException) IOException(java.io.IOException) Document(org.jdom2.Document) JDOMException(org.jdom2.JDOMException)

Example 2 with MigrationStepException

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

the class AssertEquals method execute.

@Override
public void execute(Element element, MigrationReport report) throws RuntimeException {
    try {
        changeNodeName("munit-tools", "assert-that").andThen(changeAttribute("expectedValue", of("expression"), empty())).andThen(changeAttribute("actualValue", of("is"), empty())).apply(element);
        updateMUnitAssertionEqualsExpression("is").apply(element);
        migrateExpression(element);
    } catch (Exception e) {
        throw new MigrationStepException("Fail to apply step. " + e.getMessage());
    }
}
Also used : MigrationStepException(com.mulesoft.tools.migration.exception.MigrationStepException) MigrationStepException(com.mulesoft.tools.migration.exception.MigrationStepException)

Example 3 with MigrationStepException

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

the class AssertFalse method execute.

@Override
public void execute(Element element, MigrationReport report) throws RuntimeException {
    try {
        changeNodeName("munit-tools", "assert-that").andThen(changeAttribute("condition", of("expression"), empty())).andThen(addAttribute("is", "#[MunitTools::equalTo(false)]")).apply(element);
        migrateExpression(element);
    } catch (Exception e) {
        throw new MigrationStepException("Fail to apply step. " + e.getMessage());
    }
}
Also used : MigrationStepException(com.mulesoft.tools.migration.exception.MigrationStepException) MigrationStepException(com.mulesoft.tools.migration.exception.MigrationStepException)

Example 4 with MigrationStepException

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

the class MuleAppProperties method execute.

@Override
public void execute(ApplicationModel appModel, MigrationReport report) throws RuntimeException {
    try {
        List<String> properties = resolveProperties(appModel.getProjectBasePath(), MULE_PROPS_FILE);
        if (!properties.isEmpty()) {
            properties.forEach(p -> {
                appModel.getDocumentsContainString("${" + p + "}").forEach(n -> addConfigFileReference(n, appModel));
                appModel.getDocumentsContainString("p(\\\"" + p + "\\\")").forEach(n -> addConfigFileReference(n, appModel));
                appModel.getDocumentsContainString("p('" + p + "')").forEach(n -> addConfigFileReference(n, appModel));
            });
        }
    } catch (IOException e) {
        throw new MigrationStepException("Could not update mule-app.properties references on Files.", e);
    }
}
Also used : MigrationStepException(com.mulesoft.tools.migration.exception.MigrationStepException) IOException(java.io.IOException)

Example 5 with MigrationStepException

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

the class AssertPayload method execute.

@Override
public void execute(Element element, MigrationReport report) throws RuntimeException {
    try {
        changeNodeName("munit-tools", "assert-that").andThen(addAttribute("expression", "#[payload]")).andThen(changeAttribute("expectedValue", of("is"), empty())).apply(element);
        Attribute isAttribute = element.getAttribute("is");
        if (isAttribute != null) {
            String attributeValue = isAttribute.getValue();
            if (getExpressionMigrator().isWrapped(attributeValue)) {
                attributeValue = "#[MunitTools::equalTo(" + getExpressionMigrator().unwrap(attributeValue) + ")]";
            } else {
                attributeValue = "#[MunitTools::equalTo(" + attributeValue + ")]";
            }
            isAttribute.setValue(attributeValue);
        }
    } catch (Exception e) {
        throw new MigrationStepException("Fail to apply step. " + e.getMessage());
    }
}
Also used : Attribute(org.jdom2.Attribute) ApplicationModelUtils.changeAttribute(com.mulesoft.tools.migration.project.model.ApplicationModelUtils.changeAttribute) ApplicationModelUtils.addAttribute(com.mulesoft.tools.migration.project.model.ApplicationModelUtils.addAttribute) MigrationStepException(com.mulesoft.tools.migration.exception.MigrationStepException) MigrationStepException(com.mulesoft.tools.migration.exception.MigrationStepException)

Aggregations

MigrationStepException (com.mulesoft.tools.migration.exception.MigrationStepException)16 Element (org.jdom2.Element)5 MigrationReport (com.mulesoft.tools.migration.step.category.MigrationReport)3 IOException (java.io.IOException)3 Document (org.jdom2.Document)3 ApplicationModel (com.mulesoft.tools.migration.project.model.ApplicationModel)2 ArrayList (java.util.ArrayList)2 List (java.util.List)2 Attribute (org.jdom2.Attribute)2 Namespace (org.jdom2.Namespace)2 Preconditions.checkArgument (com.google.common.base.Preconditions.checkArgument)1 Preconditions.checkState (com.google.common.base.Preconditions.checkState)1 Lists.newArrayList (com.google.common.collect.Lists.newArrayList)1 MigrationAbortException (com.mulesoft.tools.migration.exception.MigrationAbortException)1 MigrationTaskException (com.mulesoft.tools.migration.exception.MigrationTaskException)1 AbstractOSMigrator (com.mulesoft.tools.migration.library.mule.steps.os.AbstractOSMigrator)1 WatermarkSelectorMigrator (com.mulesoft.tools.migration.library.tools.mel.WatermarkSelectorMigrator)1 ApplicationModelUtils.addAttribute (com.mulesoft.tools.migration.project.model.ApplicationModelUtils.addAttribute)1 ApplicationModelUtils.addChildNode (com.mulesoft.tools.migration.project.model.ApplicationModelUtils.addChildNode)1 ApplicationModelUtils.changeAttribute (com.mulesoft.tools.migration.project.model.ApplicationModelUtils.changeAttribute)1