use of com.mulesoft.tools.migration.step.ExpressionMigratorAware 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);
}
}
use of com.mulesoft.tools.migration.step.ExpressionMigratorAware in project mule-migration-assistant by mulesoft.
the class OutboundEndpoint method execute.
@Override
public void execute(Element object, MigrationReport report) throws RuntimeException {
object.getChildren("property", CORE_NAMESPACE).forEach(p -> {
object.setAttribute(p.getAttributeValue("key"), p.getAttributeValue("value"));
});
object.removeChildren("property", CORE_NAMESPACE);
if (object.getAttribute("address") != null) {
String address = object.getAttributeValue("address");
AbstractApplicationModelMigrationStep migrator = null;
// TODO MMT-132 make available migrators discoverable
if (address.startsWith("file://")) {
migrator = new FileOutboundEndpoint();
object.setNamespace(Namespace.getNamespace(FILE_NS_PREFIX, FILE_NS_URI));
} else if (address.startsWith("ftp://")) {
migrator = new FtpEeOutboundEndpoint();
object.setNamespace(Namespace.getNamespace(FTP_NS_PREFIX, FTP_NS_URI));
} else if (address.startsWith("sftp://")) {
migrator = new SftpOutboundEndpoint();
object.setNamespace(Namespace.getNamespace(SFTP_NS_PREFIX, SFTP_NS_URI));
} else if (address.startsWith("http://")) {
migrator = new HttpOutboundEndpoint();
object.setNamespace(Namespace.getNamespace(HTTP_NS_PREFIX, HTTP_NS_URI));
} else if (address.startsWith("https://")) {
migrator = new HttpsOutboundEndpoint();
object.setNamespace(Namespace.getNamespace("https", "http://www.mulesoft.org/schema/mule/https"));
} else if (address.startsWith("smtp://")) {
migrator = new SmtpOutboundEndpoint();
object.setNamespace(Namespace.getNamespace("smtp", "http://www.mulesoft.org/schema/mule/smtp"));
} else if (address.startsWith("smtps://")) {
migrator = new SmtpsOutboundEndpoint();
object.setNamespace(Namespace.getNamespace("smtps", "http://www.mulesoft.org/schema/mule/smtps"));
} else if (address.startsWith("jms://")) {
migrator = new JmsOutboundEndpoint();
object.setNamespace(Namespace.getNamespace(JMS_NS_PREFIX, JMS_NS_URI));
} else if (address.startsWith("vm://")) {
migrator = new VmOutboundEndpoint();
object.setNamespace(Namespace.getNamespace(VM_NS_PREFIX, VM_NS_URI));
}
if (migrator != null) {
migrator.setApplicationModel(getApplicationModel());
if (migrator instanceof ExpressionMigratorAware) {
((ExpressionMigratorAware) migrator).setExpressionMigrator(getExpressionMigrator());
}
migrator.execute(object, report);
}
object.removeAttribute("address");
}
if (object.getAttribute("exchange-pattern") != null) {
object.removeAttribute("exchange-pattern");
}
}
use of com.mulesoft.tools.migration.step.ExpressionMigratorAware in project mule-migration-assistant by mulesoft.
the class InboundEndpoint method execute.
@Override
public void execute(Element object, MigrationReport report) throws RuntimeException {
object.getChildren("property", CORE_NAMESPACE).forEach(p -> {
object.setAttribute(p.getAttributeValue("key"), p.getAttributeValue("value"));
});
object.removeChildren("property", CORE_NAMESPACE);
addMigrationAttributeToElement(object, new Attribute("isMessageSource", "true"));
AbstractApplicationModelMigrationStep migrator = null;
if (object.getAttribute("address") != null) {
String address = object.getAttributeValue("address");
// TODO MMT-132 make available migrators discoverable
if (address.startsWith("file://")) {
migrator = new FileInboundEndpoint();
object.setNamespace(Namespace.getNamespace(FILE_NS_PREFIX, FILE_NS_URI));
} else if (address.startsWith("ftp://")) {
migrator = new FtpEeInboundEndpoint();
object.setNamespace(Namespace.getNamespace(FTP_NS_PREFIX, FTP_NS_URI));
} else if (address.startsWith("sftp://")) {
migrator = new SftpInboundEndpoint();
object.setNamespace(Namespace.getNamespace(SFTP_NS_PREFIX, SFTP_NS_URI));
} else if (address.startsWith("http://")) {
migrator = new HttpInboundEndpoint();
object.setNamespace(Namespace.getNamespace(HTTP_NS_PREFIX, HTTP_NS_URI));
} else if (address.startsWith("https://")) {
migrator = new HttpsInboundEndpoint();
object.setNamespace(Namespace.getNamespace("https", "http://www.mulesoft.org/schema/mule/https"));
} else if (address.startsWith("imap://")) {
migrator = new ImapInboundEndpoint();
object.setNamespace(Namespace.getNamespace("imap", "http://www.mulesoft.org/schema/mule/imap"));
} else if (address.startsWith("imaps://")) {
migrator = new ImapsInboundEndpoint();
object.setNamespace(Namespace.getNamespace("imaps", "http://www.mulesoft.org/schema/mule/imaps"));
} else if (address.startsWith("pop3://")) {
migrator = new Pop3InboundEndpoint();
object.setNamespace(Namespace.getNamespace("pop3", "http://www.mulesoft.org/schema/mule/pop3"));
} else if (address.startsWith("pop3s://")) {
migrator = new Pop3sInboundEndpoint();
object.setNamespace(Namespace.getNamespace("pop3s", "http://www.mulesoft.org/schema/mule/pop3s"));
} else if (address.startsWith("jms://")) {
migrator = new JmsInboundEndpoint();
object.setNamespace(Namespace.getNamespace(JMS_NS_PREFIX, JMS_NS_URI));
} else if (address.startsWith("vm://")) {
migrator = new VmInboundEndpoint();
object.setNamespace(Namespace.getNamespace(VM_NS_PREFIX, VM_NS_URI));
}
if (migrator != null) {
migrator.setApplicationModel(getApplicationModel());
if (migrator instanceof ExpressionMigratorAware) {
((ExpressionMigratorAware) migrator).setExpressionMigrator(getExpressionMigrator());
}
migrator.execute(object, report);
}
object.removeAttribute("address");
} else if (object.getAttribute("ref") != null) {
Element globalEndpoint = getApplicationModel().getNode("/*/*[@name = '" + object.getAttributeValue("ref") + "']");
// TODO MMT-132 make available migrators discoverable
if (globalEndpoint.getAttribute("address") != null) {
String address = globalEndpoint.getAttributeValue("address");
if (address.startsWith("file://")) {
migrator = new FileInboundEndpoint();
object.setNamespace(Namespace.getNamespace(FILE_NS_PREFIX, FILE_NS_URI));
} else if (address.startsWith("ftp://")) {
migrator = new FtpEeInboundEndpoint();
object.setNamespace(Namespace.getNamespace(FTP_NS_PREFIX, FTP_NS_URI));
} else if (address.startsWith("sftp://")) {
migrator = new SftpInboundEndpoint();
object.setNamespace(Namespace.getNamespace(SFTP_NS_PREFIX, SFTP_NS_URI));
} else if (address.startsWith("http://")) {
migrator = new HttpInboundEndpoint();
object.setNamespace(Namespace.getNamespace(HTTP_NS_PREFIX, HTTP_NS_URI));
} else if (address.startsWith("https://")) {
migrator = new HttpsInboundEndpoint();
object.setNamespace(Namespace.getNamespace("https", "http://www.mulesoft.org/schema/mule/https"));
} else if (address.startsWith("imap://")) {
migrator = new ImapInboundEndpoint();
object.setNamespace(Namespace.getNamespace("imap", "http://www.mulesoft.org/schema/mule/imap"));
} else if (address.startsWith("imaps://")) {
migrator = new ImapsInboundEndpoint();
object.setNamespace(Namespace.getNamespace("imaps", "http://www.mulesoft.org/schema/mule/imaps"));
} else if (address.startsWith("pop3://")) {
migrator = new Pop3InboundEndpoint();
object.setNamespace(Namespace.getNamespace("pop3", "http://www.mulesoft.org/schema/mule/pop3"));
} else if (address.startsWith("pop3s://")) {
migrator = new Pop3sInboundEndpoint();
object.setNamespace(Namespace.getNamespace("pop3s", "http://www.mulesoft.org/schema/mule/pop3s"));
} else if (address.startsWith("jms://")) {
migrator = new JmsInboundEndpoint();
object.setNamespace(Namespace.getNamespace(JMS_NS_PREFIX, JMS_NS_URI));
} else if (address.startsWith("vm://")) {
migrator = new VmInboundEndpoint();
object.setNamespace(Namespace.getNamespace(VM_NS_PREFIX, VM_NS_URI));
}
if (migrator != null) {
migrator.setApplicationModel(getApplicationModel());
if (migrator instanceof ExpressionMigratorAware) {
((ExpressionMigratorAware) migrator).setExpressionMigrator(getExpressionMigrator());
}
for (Attribute attribute : globalEndpoint.getAttributes()) {
if (object.getAttribute(attribute.getName()) == null) {
object.setAttribute(attribute.getName(), attribute.getValue());
}
}
migrator.execute(object, report);
}
}
}
if (object.getAttribute("exchange-pattern") != null) {
object.removeAttribute("exchange-pattern");
}
}
use of com.mulesoft.tools.migration.step.ExpressionMigratorAware in project mule-migration-assistant by mulesoft.
the class DomainTest method setUp.
@Before
public void setUp() throws Exception {
originalDomainDoc = getDocument(this.getClass().getClassLoader().getResource(domainConfigPath.toString()).toURI().getPath());
domainDoc = getDocument(this.getClass().getClassLoader().getResource(domainConfigPath.toString()).toURI().getPath());
appDoc = getDocument(this.getClass().getClassLoader().getResource(appConfigPath.toString()).toURI().getPath());
MelToDwExpressionMigrator expressionMigrator = new MelToDwExpressionMigrator(report.getReport(), mock(ApplicationModel.class));
domainModel = mock(ApplicationModel.class);
when(domainModel.getNodes(any(String.class))).thenAnswer(invocation -> getElementsFromDocument(domainDoc, (String) invocation.getArguments()[0], "domain"));
when(domainModel.getNode(any(String.class))).thenAnswer(invocation -> getElementsFromDocument(domainDoc, (String) invocation.getArguments()[0], "domain").iterator().next());
when(domainModel.getNodeOptional(any(String.class))).thenAnswer(invocation -> {
List<Element> elementsFromDocument = getElementsFromDocument(domainDoc, (String) invocation.getArguments()[0], "domain");
if (elementsFromDocument.isEmpty()) {
return empty();
} else {
return of(elementsFromDocument.iterator().next());
}
});
when(domainModel.getProjectBasePath()).thenReturn(temp.newFolder().toPath());
when(domainModel.getPomModel()).thenReturn(of(mock(PomModel.class)));
final Map<Path, Document> domainModelDocs = new HashMap<>();
domainModelDocs.put(domainConfigPath, domainDoc);
when(domainModel.getApplicationDocuments()).thenReturn(domainModelDocs);
doAnswer(invocation -> {
String prefix = invocation.getArgument(0);
String uri = invocation.getArgument(1);
String schemaLocation = invocation.getArgument(2);
Namespace namespace = Namespace.getNamespace(prefix, uri);
addNameSpace(namespace, schemaLocation, domainDoc);
return null;
}).when(domainModel).addNameSpace(anyString(), anyString(), anyString());
appModel = mock(ApplicationModel.class);
when(appModel.getNodes(any(String.class))).thenAnswer(invocation -> getElementsFromDocuments((String) invocation.getArguments()[0]));
when(appModel.getNode(any(String.class))).thenAnswer(invocation -> getElementsFromDocuments((String) invocation.getArguments()[0]).iterator().next());
when(appModel.getNodeOptional(any(String.class))).thenAnswer(invocation -> {
List<Element> elementsFromDocument = getElementsFromDocuments((String) invocation.getArguments()[0]);
if (elementsFromDocument.isEmpty()) {
return empty();
} else {
return of(elementsFromDocument.iterator().next());
}
});
when(appModel.getProjectBasePath()).thenReturn(temp.newFolder().toPath());
when(appModel.getPomModel()).thenReturn(of(mock(PomModel.class)));
final Map<Path, Document> appDomainModelDocs = new HashMap<>();
appDomainModelDocs.put(domainConfigPath, originalDomainDoc);
when(appModel.getDomainDocuments()).thenReturn(appDomainModelDocs);
doAnswer(invocation -> {
String prefix = invocation.getArgument(0);
String uri = invocation.getArgument(1);
String schemaLocation = invocation.getArgument(2);
Namespace namespace = Namespace.getNamespace(prefix, uri);
addNameSpace(namespace, schemaLocation, originalDomainDoc);
addNameSpace(namespace, schemaLocation, appDoc);
return null;
}).when(appModel).addNameSpace(anyString(), anyString(), anyString());
List<AbstractMigrationTask> coreMigrationTasks = new ArrayList<>();
coreMigrationTasks.add(new MuleCoreComponentsMigrationTask());
coreMigrationTasks.add(new HTTPMigrationTask());
coreMigrationTasks.add(new DbMigrationTask());
coreMigrationTasks.add(new EndpointsMigrationTask());
coreMigrationTasks.add(new JmsDomainMigrationTask());
coreMigrationTasks.add(new JmsMigrationTask());
coreMigrationTasks.add(new DomainAppMigrationTask());
coreMigrationTasks.add(new SpringMigrationTask());
coreMigrationTasks.add(new HTTPCleanupTask());
coreMigrationTasks.add(new MigrationCleanTask());
coreMigrationTasks.add(new PostprocessGeneral());
coreMigrationTasks.add(new PostprocessMuleApplication());
appSteps = new ArrayList<>();
domainSteps = new ArrayList<>();
for (AbstractMigrationTask task : coreMigrationTasks) {
if (task.getApplicableProjectTypes().contains(MULE_FOUR_DOMAIN)) {
for (MigrationStep step : task.getSteps()) {
if (step instanceof ExpressionMigratorAware) {
((ExpressionMigratorAware) step).setExpressionMigrator(expressionMigrator);
}
if (step instanceof ApplicationModelContribution) {
((ApplicationModelContribution) step).setApplicationModel(domainModel);
}
domainSteps.add(step);
}
}
if (task.getApplicableProjectTypes().contains(MULE_FOUR_APPLICATION)) {
for (MigrationStep step : task.getSteps()) {
if (step instanceof ExpressionMigratorAware) {
((ExpressionMigratorAware) step).setExpressionMigrator(expressionMigrator);
}
if (step instanceof ApplicationModelContribution) {
((ApplicationModelContribution) step).setApplicationModel(appModel);
}
appSteps.add(step);
}
}
}
}
Aggregations