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));
});
}
};
}
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();
}
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);
}
}
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());
}
Aggregations