Skip to content

Commit

Permalink
Migration Cost JSON report (#601)
Browse files Browse the repository at this point in the history
+ support jdk 13+
+ build with LTS jdks 8, 11 and 17
  • Loading branch information
svacas authored and jesica-fera committed Mar 14, 2022
1 parent 7cb23a6 commit 5718d34
Show file tree
Hide file tree
Showing 72 changed files with 2,509 additions and 693 deletions.
48 changes: 15 additions & 33 deletions .github/workflows/maven.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,37 +10,19 @@ on:
branches: [ master ]

jobs:
build-linux:
build:

runs-on: ubuntu-latest
strategy:
matrix:
os: [ubuntu-latest, windows-latest]
jdk: [1.8, 1.11, 1.17] # LTS versions
include:
- os: ubuntu-latest
mvn-settings: '/home/runner/.m2/settings.xml'
- os: windows-latest
mvn-settings: 'C:\Users\runneradmin\.m2\settings.xml'

steps:
- name: checkout
uses: actions/checkout@v2

- name: maven-settings-xml-action
uses: whelk-io/maven-settings-xml-action@v10
with:
repositories: '[{ "id": "mulesoft-public", "url": "https://repository.mulesoft.org/nexus/content/repositories/public" },
{ "id": "mule-releases", "url": "https://repository.mulesoft.org/releases" }]'

- name: log-settings
run: cat \/home\/runner\/.m2\/settings.xml

- name: Set up JDK 1.8
uses: actions/setup-java@v1
with:
java-version: 1.8

- name: mvn-version
run: mvn --version

- name: Build with Maven
run: mvn --settings /home/runner/.m2/settings.xml clean install --file pom.xml

build-windows:

runs-on: windows-latest
runs-on: ${{ matrix.os }}

steps:
- name: checkout
Expand All @@ -53,15 +35,15 @@ jobs:
{ "id": "mule-releases", "url": "https://repository.mulesoft.org/releases" }]'

- name: log-settings
run: cat C:\Users\runneradmin\.m2\settings.xml
run: cat ${{ matrix.mvn-settings }}

- name: Set up JDK 1.8
- name: Set up JDK ${{ matrix.jdk }}
uses: actions/setup-java@v1
with:
java-version: 1.8
java-version: ${{ matrix.jdk }}

- name: mvn-version
run: mvn --version

- name: Build with Maven
run: mvn --settings C:\Users\runneradmin\.m2\settings.xml clean install --file pom.xml
run: mvn --settings ${{ matrix.mvn-settings }} clean install --file pom.xml
5 changes: 3 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -55,8 +55,8 @@ If you would just like to download/access the MMA tool (compiled version), you c
See the following commands in order to clone, build and run this project

```
$ git clone --recursive [email protected]:mulesoft/mule-migration-tool.git
$ cd mule-migration-tool/
$ git clone --recursive [email protected]:mulesoft/mule-migration-assistant.git
$ cd mule-migration-assistant/
$ mvn clean package
$ cd runner/target
$ java -jar mule-migration-assistant-runner-*CURRENT VERSION*.jar [parameters]
Expand All @@ -72,6 +72,7 @@ $ java -jar mule-migration-assistant-runner-*CURRENT VERSION*.jar [parameters]
| help | Show all the parameters to define on MMA | No |
| cancelOnError | Use cancelOnError = true the MMA stop migration if a exception occurs (default false) | No |
| projectParentGAV | Use projectParentGAV 'groupId:artifactId:version' to migrate your parent inside the pom.xml | No |
| jsonReport | Generate migration report in JSON format | No |


### User Documentation
Expand Down
23 changes: 23 additions & 0 deletions mule-migration-tool-api/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,29 @@
</plugins>
</build>

<profiles>
<profile>
<id>surefire-java15plus</id>
<activation>
<jdk>[1.15,)</jdk>
</activation>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<configuration>
<argLine>
--add-opens java.base/java.io=ALL-UNNAMED
--add-opens java.base/java.lang=ALL-UNNAMED
</argLine>
</configuration>
</plugin>
</plugins>
</build>
</profile>
</profiles>

<dependencies>
<dependency>
<groupId>org.jdom</groupId>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,17 +6,22 @@
package com.mulesoft.tools.migration.step;

import static com.google.common.base.Preconditions.checkArgument;
import static com.mulesoft.tools.migration.step.category.MigrationReport.Level.ERROR;

import com.mulesoft.tools.migration.exception.MigrationStepException;
import com.mulesoft.tools.migration.project.model.ApplicationModel;
import com.mulesoft.tools.migration.step.category.ApplicationModelContribution;
import com.mulesoft.tools.migration.step.category.MigrationReport;

import java.util.ArrayList;
import java.util.List;

import org.jdom2.Element;
import org.jdom2.Namespace;
import org.jdom2.xpath.XPathExpression;
import org.jdom2.xpath.XPathFactory;

import java.util.ArrayList;
import java.util.List;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

/**
* Basic unit of execution.
Expand Down Expand Up @@ -69,4 +74,9 @@ public List<Namespace> getNamespacesContributions() {
public void setNamespacesContributions(List<Namespace> namespaces) {
this.namespacesContribution = namespaces;
}

@Override
public boolean shouldReportMetrics() {
return true;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,128 @@
/*
* Copyright (c) 2020, Mulesoft, LLC. All rights reserved.
* Use of this source code is governed by a BSD 3-Clause License
* license that can be found in the LICENSE.txt file.
*/
package com.mulesoft.tools.migration.step;

import static com.mulesoft.tools.migration.step.category.MigrationReport.Level.ERROR;

import com.mulesoft.tools.migration.project.model.ApplicationModel;
import com.mulesoft.tools.migration.step.category.ApplicationModelContribution;
import com.mulesoft.tools.migration.step.category.MigrationReport;
import com.mulesoft.tools.migration.util.ExpressionMigrator;

import java.util.List;

import org.jdom2.Element;
import org.jdom2.Namespace;
import org.jdom2.xpath.XPathExpression;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

/**
* Wrapper of ApplicationModelContribution steps that enables detailed reporting
* of the element migration result.
*
* @author Mulesoft Inc.
*/
public class ReportingStep implements ApplicationModelContribution, ExpressionMigratorAware {

private static final Logger logger = LoggerFactory.getLogger(ReportingStep.class);

private final ApplicationModelContribution targetStep;

public ReportingStep(ApplicationModelContribution step) {
targetStep = step;
}

/**
* Wraps the step execution in order to report the element migration result
*
* success:
* - report error count not increased OR
* - report error count increased same amount as mel/dw errors
* failure:
* - report error count > mel/dw errors OR
* - exception thrown
*/
@Override
public void execute(Element element, MigrationReport report) {
int entriesBefore = report.getReportEntries(ERROR).size();
int melFailuresBefore = report.getMelExpressionsFailureCount();
int dwFailuresBefore = report.getDwTransformsFailureCount();
try {
targetStep.execute(element, report);
if (targetStep.shouldReportMetrics()) {
if (report.getReportEntries(ERROR).size() <= entriesBefore + (report.getMelExpressionsFailureCount() - melFailuresBefore)
+ (report.getDwTransformsFailureCount() - dwFailuresBefore)) {
report.addComponentSuccess(element);
} else {
report.addComponentFailure(element);
}
}
} catch (Exception e) {
logger.warn("Exception {} -- migrating {}:{}", e, element != null ? element.getNamespacePrefix() : "null",
element != null ? element.getName() : "null");
if (targetStep.shouldReportMetrics()) {
report.addComponentFailure(element);
}
throw e;
}
}

@Override
public String getDescription() {
return targetStep.getDescription();
}

@Override
public XPathExpression getAppliedTo() {
return targetStep.getAppliedTo();
}

@Override
public void setAppliedTo(String xpathExpression) {
targetStep.setAppliedTo(xpathExpression);
}

@Override
public ApplicationModel getApplicationModel() {
return targetStep.getApplicationModel();
}

@Override
public void setApplicationModel(ApplicationModel appModel) {
targetStep.setApplicationModel(appModel);
}

@Override
public List<Namespace> getNamespacesContributions() {
return targetStep.getNamespacesContributions();
}

@Override
public void setNamespacesContributions(List<Namespace> namespaces) {
targetStep.setNamespacesContributions(namespaces);
}

@Override
public boolean shouldReportMetrics() {
return targetStep.shouldReportMetrics();
}

@Override
public void setExpressionMigrator(ExpressionMigrator expressionMigrator) {
if (targetStep instanceof ExpressionMigratorAware) {
((ExpressionMigratorAware) targetStep).setExpressionMigrator(expressionMigrator);
}
}

@Override
public ExpressionMigrator getExpressionMigrator() {
if (targetStep instanceof ExpressionMigratorAware) {
return ((ExpressionMigratorAware) targetStep).getExpressionMigrator();
}
return null;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -63,4 +63,9 @@ public interface ApplicationModelContribution extends MigrationStep<Element> {
* @return a {@link ApplicationModel}
*/
void setNamespacesContributions(List<Namespace> namespaces);

/**
* Whether this step should report migration result metrics or not.
*/
boolean shouldReportMetrics();
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
/*
* Copyright (c) 2020, Mulesoft, LLC. All rights reserved.
* Use of this source code is governed by a BSD 3-Clause License
* license that can be found in the LICENSE.txt file.
*/
package com.mulesoft.tools.migration.step.category;

/**
* Indicates the migration result, either success or failure for all the instances of a given component.
*
* @author Mulesoft Inc.
*/
public class ComponentMigrationStatus {

private int success;
private int failure;

public int getSuccess() {
return success;
}

public int getFailure() {
return failure;
}

public void success() {
success++;
}

public void failure() {
failure++;
}
}
Loading

0 comments on commit 5718d34

Please sign in to comment.