Search in sources :

Example 1 with InvalidPomException

use of org.kie.workbench.common.screens.projecteditor.model.InvalidPomException in project kie-wb-common by kiegroup.

the class PomEditor method saveErrorCallbackConfig.

private Map<Class<? extends Throwable>, CommandWithThrowable> saveErrorCallbackConfig(final String commitMessage) {
    return new HashMap<Class<? extends Throwable>, CommandWithThrowable>() {

        {
            put(GAVAlreadyExistsException.class, t -> {
                view.hideBusyIndicator();
                final GAVAlreadyExistsException e = (GAVAlreadyExistsException) t;
                conflictingRepositoriesPopup.setContent(e.getGAV(), e.getRepositories(), () -> {
                    conflictingRepositoriesPopup.hide();
                    doSave(commitMessage, FORCED);
                });
                conflictingRepositoriesPopup.show();
            });
            put(InvalidPomException.class, t -> {
                view.hideBusyIndicator();
                final InvalidPomException e = (InvalidPomException) t;
                final String message = translationService.format(LibraryConstants.InvalidPom, e.getLineNumber(), e.getColumnNumber());
                notificationEvent.fire(new NotificationEvent(message, ERROR));
            });
        }
    };
}
Also used : GAVAlreadyExistsException(org.guvnor.common.services.project.service.GAVAlreadyExistsException) HashMap(java.util.HashMap) InvalidPomException(org.kie.workbench.common.screens.projecteditor.model.InvalidPomException) NotificationEvent(org.uberfire.workbench.events.NotificationEvent)

Example 2 with InvalidPomException

use of org.kie.workbench.common.screens.projecteditor.model.InvalidPomException in project kie-wb-common by kiegroup.

the class PomEditorServiceImplTest method testSaveInvalidPom.

@Test
public void testSaveInvalidPom() throws IOException, XmlPullParserException {
    final InvalidPomException invalidPomException = new InvalidPomException(10, 10);
    try {
        doThrow(invalidPomException).when(pomContentHandler).toModel(pomXml);
        service.save(pomPath, pomXml, metaData, comment, DeploymentMode.VALIDATED);
        Assert.fail("Exception should've been thrown");
    } catch (final InvalidPomException e) {
        Assert.assertEquals(invalidPomException, e);
    }
    verify(moduleService, times(1)).resolveModule(pomPath);
    verify(moduleRepositoriesService, never()).load(moduleRepositoriesPath);
    verify(repositoryResolver, never()).getRepositoriesResolvingArtifact(eq(pomXml), any(MavenRepositoryMetadata.class));
    verify(ioService, never()).startBatch(any());
    verify(ioService, never()).write(Mockito.<org.uberfire.java.nio.file.Path>any(), eq(pomXml), eq(attributes), Mockito.<CommentedOption>any());
    verify(ioService, never()).endBatch();
}
Also used : MavenRepositoryMetadata(org.guvnor.common.services.project.model.MavenRepositoryMetadata) InvalidPomException(org.kie.workbench.common.screens.projecteditor.model.InvalidPomException) Test(org.junit.Test)

Example 3 with InvalidPomException

use of org.kie.workbench.common.screens.projecteditor.model.InvalidPomException in project kie-wb-common by kiegroup.

the class PomEditorServiceImpl method checkRepositories.

private void checkRepositories(final Path pomPath, final String pomXml) {
    // Check is the POM's GAV has been changed.
    final KieModule module = moduleService.resolveModule(pomPath);
    POM pom = new POM(GAV_UNDETERMINED);
    try {
        pom = pomContentHandler.toModel(pomXml);
        if (pom.getGav().equals(module.getPom().getGav())) {
            return;
        }
        // If GAV is snapshot we can freely override the module
        if (pom.getGav().isSnapshot()) {
            return;
        }
    } catch (final XmlPullParserException e) {
        throw new InvalidPomException(e.getLineNumber(), e.getColumnNumber());
    } catch (final IOException e) {
        logger.warn("Unable to load pom.xml. It is therefore impossible to ascertain GAV.", e);
    }
    // Check is the POM's GAV resolves to any pre-existing artifacts.
    // Filter resolved Repositories by those enabled for the Module.
    final ModuleRepositories moduleRepositories = moduleRepositoriesService.load(module.getRepositoriesPath());
    final Set<MavenRepositoryMetadata> repositories = repositoryResolver.getRepositoriesResolvingArtifact(pomXml, moduleRepositories.filterByIncluded());
    if (repositories.size() > 0) {
        throw new GAVAlreadyExistsException(pom.getGav(), repositories);
    }
}
Also used : ModuleRepositories(org.guvnor.common.services.project.model.ModuleRepositories) MavenRepositoryMetadata(org.guvnor.common.services.project.model.MavenRepositoryMetadata) GAVAlreadyExistsException(org.guvnor.common.services.project.service.GAVAlreadyExistsException) InvalidPomException(org.kie.workbench.common.screens.projecteditor.model.InvalidPomException) XmlPullParserException(org.codehaus.plexus.util.xml.pull.XmlPullParserException) IOException(java.io.IOException) KieModule(org.kie.workbench.common.services.shared.project.KieModule) POM(org.guvnor.common.services.project.model.POM)

Example 4 with InvalidPomException

use of org.kie.workbench.common.screens.projecteditor.model.InvalidPomException in project kie-wb-common by kiegroup.

the class PomEditorTest method testSaveInvalid.

@Test
public void testSaveInvalid() {
    doThrow(new InvalidPomException(10, 10)).when(service).save(Mockito.<ObservablePath>any(), eq(pomXml), Mockito.<Metadata>any(), eq(comment), eq(DeploymentMode.VALIDATED));
    presenter.save(comment);
    verify(service, times(1)).save(Mockito.<ObservablePath>any(), eq(pomXml), Mockito.<Metadata>any(), eq(comment), eq(DeploymentMode.VALIDATED));
    verify(view, times(1)).showBusyIndicator(eq(CommonConstants.INSTANCE.Saving()));
    verify(view, times(1)).hideBusyIndicator();
    verify(notificationEvent, times(1)).fire(any());
}
Also used : InvalidPomException(org.kie.workbench.common.screens.projecteditor.model.InvalidPomException) Test(org.junit.Test)

Aggregations

InvalidPomException (org.kie.workbench.common.screens.projecteditor.model.InvalidPomException)4 MavenRepositoryMetadata (org.guvnor.common.services.project.model.MavenRepositoryMetadata)2 GAVAlreadyExistsException (org.guvnor.common.services.project.service.GAVAlreadyExistsException)2 Test (org.junit.Test)2 IOException (java.io.IOException)1 HashMap (java.util.HashMap)1 XmlPullParserException (org.codehaus.plexus.util.xml.pull.XmlPullParserException)1 ModuleRepositories (org.guvnor.common.services.project.model.ModuleRepositories)1 POM (org.guvnor.common.services.project.model.POM)1 KieModule (org.kie.workbench.common.services.shared.project.KieModule)1 NotificationEvent (org.uberfire.workbench.events.NotificationEvent)1