Search in sources :

Example 1 with PomModel

use of com.mulesoft.tools.migration.project.model.pom.PomModel in project mule-migration-assistant by mulesoft.

the class ClientIdEnforcementPomContributionMigrationStepTestCase method pomContributionTest.

@Test
public void pomContributionTest() {
    PomModel pm = new PomModel();
    ClientIdEnforcementPomContributionMigrationStep step = new ClientIdEnforcementPomContributionMigrationStep();
    step.execute(pm, mock(MigrationReport.class));
    assertThat(pm.getDependencies().size(), is(1));
    Dependency clientIdEnforcementDependency = pm.getDependencies().get(0);
    assertThat(clientIdEnforcementDependency.getGroupId(), is(COM_MULESOFT_ANYPOINT_GROUP_ID));
    assertThat(clientIdEnforcementDependency.getArtifactId(), is(MULE_CLIENT_ID_ENFORCEMENT_EXTENSION_ARTIFACT_ID));
    assertThat(clientIdEnforcementDependency.getVersion(), is(notNullValue()));
    assertThat(clientIdEnforcementDependency.getClassifier(), is(MULE_PLUGIN_CLASSIFIER));
}
Also used : ClientIdEnforcementPomContributionMigrationStep(com.mulesoft.tools.migration.library.gateway.steps.policy.clientidenforcement.ClientIdEnforcementPomContributionMigrationStep) PomModel(com.mulesoft.tools.migration.project.model.pom.PomModel) MigrationReport(com.mulesoft.tools.migration.step.category.MigrationReport) Dependency(com.mulesoft.tools.migration.project.model.pom.Dependency) Test(org.junit.Test)

Example 2 with PomModel

use of com.mulesoft.tools.migration.project.model.pom.PomModel 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)

Example 3 with PomModel

use of com.mulesoft.tools.migration.project.model.pom.PomModel in project mule-migration-assistant by mulesoft.

the class UpdateProjectParentTest method executeWithoutProjectParentGavAndWithoutParent.

@Test
public void executeWithoutProjectParentGavAndWithoutParent() throws IOException, XmlPullParserException, URISyntaxException {
    UpdateProjectParent updateProjectParent = new UpdateProjectParent();
    final ApplicationModel applicationModelMock = mock(ApplicationModel.class);
    when(applicationModelMock.getProjectPomParent()).thenReturn(Optional.empty());
    updateProjectParent.setApplicationModel(applicationModelMock);
    Path pomPath = Paths.get(getClass().getResource(POM).toURI());
    PomModel model = new PomModel.PomModelBuilder().withPom(pomPath).build();
    try {
        updateProjectParent.execute(model, report.getReport());
        assertTrue(!model.getParent().isPresent());
    } catch (RuntimeException e) {
        fail("no exception have to be thrown");
    }
}
Also used : Path(java.nio.file.Path) ApplicationModel(com.mulesoft.tools.migration.project.model.ApplicationModel) PomModel(com.mulesoft.tools.migration.project.model.pom.PomModel) Test(org.junit.Test)

Example 4 with PomModel

use of com.mulesoft.tools.migration.project.model.pom.PomModel in project mule-migration-assistant by mulesoft.

the class UpdateProjectParentTest method executeWithGavAndParent.

@Test
public void executeWithGavAndParent() throws URISyntaxException, IOException, XmlPullParserException {
    UpdateProjectParent updateProjectParent = new UpdateProjectParent();
    final ApplicationModel applicationModelMock = mock(ApplicationModel.class);
    Parent parent = new Parent.ParentBuilder().withGroupId("com.mule").withArtifactId("rest-parent").withVersion("2.0.0").build();
    when(applicationModelMock.getProjectPomParent()).thenReturn(Optional.of(parent));
    updateProjectParent.setApplicationModel(applicationModelMock);
    Path pomPath = Paths.get(getClass().getResource(PARENT_POM).toURI());
    PomModel model = new PomModel.PomModelBuilder().withPom(pomPath).build();
    parent = model.getParent().get();
    assertEquals(parent.getGroupId(), "com.mule.parent");
    assertEquals(parent.getArtifactId(), "parent-rest");
    assertEquals(parent.getVersion(), "1.0.0");
    try {
        updateProjectParent.execute(model, report.getReport());
        Parent afterParent = model.getParent().get();
        assertEquals(afterParent.getGroupId(), "com.mule");
        assertEquals(afterParent.getArtifactId(), "rest-parent");
        assertEquals(afterParent.getVersion(), "2.0.0");
    } catch (RuntimeException e) {
        fail("no exception have to be thrown");
    }
}
Also used : Path(java.nio.file.Path) Parent(com.mulesoft.tools.migration.project.model.pom.Parent) ApplicationModel(com.mulesoft.tools.migration.project.model.ApplicationModel) PomModel(com.mulesoft.tools.migration.project.model.pom.PomModel) Test(org.junit.Test)

Example 5 with PomModel

use of com.mulesoft.tools.migration.project.model.pom.PomModel in project mule-migration-assistant by mulesoft.

the class UpdateProjectParentTest method executeWithoutProjectParentGavAndWithParent.

@Test
public void executeWithoutProjectParentGavAndWithParent() throws URISyntaxException, IOException, XmlPullParserException {
    UpdateProjectParent updateProjectParent = new UpdateProjectParent();
    final ApplicationModel applicationModelMock = mock(ApplicationModel.class);
    when(applicationModelMock.getProjectPomParent()).thenReturn(Optional.empty());
    updateProjectParent.setApplicationModel(applicationModelMock);
    Path pomPath = Paths.get(getClass().getResource(PARENT_POM).toURI());
    PomModel model = new PomModel.PomModelBuilder().withPom(pomPath).build();
    try {
        updateProjectParent.execute(model, report.getReport());
        assertTrue(model.getParent().isPresent());
        assertEquals("com.mule.parent", model.getParent().get().getGroupId());
        assertEquals("parent-rest", model.getParent().get().getArtifactId());
        assertEquals("1.0.0", model.getParent().get().getVersion());
    } catch (RuntimeException e) {
        fail("no exception have to be thrown");
    }
}
Also used : Path(java.nio.file.Path) ApplicationModel(com.mulesoft.tools.migration.project.model.ApplicationModel) PomModel(com.mulesoft.tools.migration.project.model.pom.PomModel) Test(org.junit.Test)

Aggregations

PomModel (com.mulesoft.tools.migration.project.model.pom.PomModel)34 Dependency (com.mulesoft.tools.migration.project.model.pom.Dependency)24 Test (org.junit.Test)24 Element (org.jdom2.Element)10 MigrationReport (com.mulesoft.tools.migration.step.category.MigrationReport)9 ApplicationModel (com.mulesoft.tools.migration.project.model.ApplicationModel)6 Path (java.nio.file.Path)4 XMLOutputter (org.jdom2.output.XMLOutputter)3 Parent (com.mulesoft.tools.migration.project.model.pom.Parent)2 Plugin (com.mulesoft.tools.migration.project.model.pom.Plugin)2 ExpressionMigrator (com.mulesoft.tools.migration.util.ExpressionMigrator)2 List (java.util.List)2 StringUtils (org.apache.commons.lang3.StringUtils)2 Xpp3Dom (org.codehaus.plexus.util.xml.Xpp3Dom)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 MigrationStepException (com.mulesoft.tools.migration.exception.MigrationStepException)1 MigrationTaskException (com.mulesoft.tools.migration.exception.MigrationTaskException)1