private void addModule(final Module module) { module.setPom(pomService.load(module.getPomXMLPath())); modules.add(module); } }
protected POM getPom(POMService pomService, Path rootPath) { String rootPathUri = rootPath.toURI(); String pomUri = POM_XML; if (!rootPathUri.endsWith("/")) { pomUri = "/" + pomUri; } Path pomPath = PathFactory.newPath(POM_XML, rootPathUri + pomUri); return pomService.load(pomPath); } }
private void addModule(final Module module) { module.setPom(pomService.load(module.getPomXMLPath())); modules.add(module); } }
@Override protected KieModule makeModule(final org.uberfire.java.nio.file.Path nioModuleRootPath) { try { final KieModule module = simpleModuleInstance(nioModuleRootPath); final POM pom = pomService.load(module.getPomXMLPath()); module.setPom(pom); return module; } catch (final Exception e) { return null; } }
@Before public void setUp() { Path path = mock(Path.class); when(path.toURI()).thenReturn("/"); when(this.importProject.getRoot()).thenReturn(path); when(this.pomService.load(any())).thenReturn(this.pom); this.validator = new CheckModulesValidator(this.pomService); }
@Test public void testRenameEventFiredBeforeDeleteEvent() { when(path.getFileName()).thenReturn("pom.xml"); when(path.toURI()).thenReturn("file://project1/pom.xml"); when(resourceResolver.resolveProject(any(Path.class))).thenReturn(project); when(pomService.load(any())).thenReturn(mock(POM.class)); final InOrder inOrder = inOrder(renameProjectEvent, ioService); abstractProjectService.rename(path, "newName", "comment"); inOrder.verify(renameProjectEvent).fire(any()); inOrder.verify(ioService).endBatch(); } }
@Test public void testGetPomWithoutFinalSlash() { Path path = mock(Path.class); when(path.toURI()).thenReturn("/testPath"); when(this.importProject.getRoot()).thenReturn(path); this.importProjectValidator.getPom(this.pomService, path); verify(this.pomService).load(pathCaptor.capture()); assertEquals("/testPath/pom.xml", pathCaptor.getValue().toURI()); }
@Test public void testGetPomWithFinalSlash() { Path path = mock(Path.class); when(path.toURI()).thenReturn("/"); when(this.importProject.getRoot()).thenReturn(path); this.importProjectValidator.getPom(this.pomService, path); verify(this.pomService).load(pathCaptor.capture()); assertEquals("/pom.xml", pathCaptor.getValue().toURI()); }
@Test public void testUseRepoServiceToDeleteRootModule() { when(path.getFileName()).thenReturn("pom.xml"); when(path.toURI()).thenReturn("file:///space/project1/pom.xml"); when(resourceResolver.resolveModule(any(Path.class))).thenReturn(module); when(pomService.load(any())).thenReturn(mock(POM.class)); Repository repo = mock(Repository.class); when(repoService.getRepository(eq(org.uberfire.backend.server.util.Paths.convert(Paths.get("file:///space/project1"))))).thenReturn(repo); String alias = "repo-alias"; when(repo.getAlias()).thenReturn(alias); Space space = new Space("space"); when(repo.getSpace()).thenReturn(space); abstractProjectService.delete(path, ""); verify(repoService).removeRepository(eq(space), eq(alias)); verify(ioService, times(0)).delete(any(), any()); }
@Test public void testUseRepoServiceToDeleteRootModule() { when(path.getFileName()).thenReturn("pom.xml"); when(path.toURI()).thenReturn("file:///space/project1/pom.xml"); when(resourceResolver.resolveModule(any(Path.class))).thenReturn(module); when(pomService.load(any())).thenReturn(mock(POM.class)); Repository repo = mock(Repository.class); when(repoService.getRepository(eq(org.uberfire.backend.server.util.Paths.convert(Paths.get("file:///space/project1"))))).thenReturn(repo); String alias = "repo-alias"; when(repo.getAlias()).thenReturn(alias); Space space = new Space("space"); when(repo.getSpace()).thenReturn(space); abstractProjectService.delete(path, ""); verify(repoService).removeRepository(eq(space), eq(alias)); verify(ioService, times(0)).delete(any(), any()); }
@Test public void testInstall() { KieModule module = mock(KieModule.class); Path pomXMLPath = mock(Path.class); POM pom = mock(POM.class); when(moduleService.resolveModule(eq(root))).thenReturn(module); when(module.getPomXMLPath()).thenReturn(pomXMLPath); when(pomService.load(eq(pomXMLPath))).thenReturn(pom); Dependencies dependencies = new Dependencies(Collections.emptyList()); when(pom.getDependencies()).thenReturn(dependencies); org.guvnor.common.services.shared.metadata.model.Metadata projMetadata = mock(org.guvnor.common.services.shared.metadata.model.Metadata.class); when(metadataService.getMetadata(pomXMLPath)).thenReturn(projMetadata); tested.install(Collections.singleton(WID), this.metadata); verify(pomService, times(1)) .save(eq(pomXMLPath), eq(pom), eq(projMetadata), anyString(), eq(false)); } }
@Test public void testUseIOServiceToDeleteSubModule() { when(path.getFileName()).thenReturn("pom.xml"); when(path.toURI()).thenReturn("file://space/project1/subproject/pom.xml"); when(ioService.exists(any())).thenReturn(true); when(resourceResolver.resolveModule(any(Path.class))).thenReturn(module); when(pomService.load(any())).thenReturn(mock(POM.class)); Repository repo = mock(Repository.class); when(repoService.getRepository(path)).thenReturn(repo); String alias = "repo-alias"; when(repo.getAlias()).thenReturn(alias); Space space = new Space("space"); when(repo.getSpace()).thenReturn(space); abstractProjectService.delete(path, ""); verify(repoService, times(0)).removeRepository(any(), any()); verify(ioService).delete(eq(Paths.get("file://space/project1/subproject")), anyVararg()); } }
@Test public void testUseIOServiceToDeleteSubModule() { when(path.getFileName()).thenReturn("pom.xml"); when(path.toURI()).thenReturn("file://space/project1/subproject/pom.xml"); when(ioService.exists(any())).thenReturn(true); when(resourceResolver.resolveModule(any(Path.class))).thenReturn(module); when(pomService.load(any())).thenReturn(mock(POM.class)); Repository repo = mock(Repository.class); when(repoService.getRepository(path)).thenReturn(repo); String alias = "repo-alias"; when(repo.getAlias()).thenReturn(alias); Space space = new Space("space"); when(repo.getSpace()).thenReturn(space); abstractProjectService.delete(path, ""); verify(repoService, times(0)).removeRepository(any(), any()); verify(ioService).delete(eq(Paths.get("file://space/project1/subproject")), anyVararg()); } }
@Test public void returnModule() throws Exception { doReturn(new POM()).when(pomService).load(pathArgumentCaptor.capture()); assertNotNull(resolver.makeModule(Paths.convert(PathFactory.newPath("testFile", "file:///testFile")))); final String pathThatWasUsedToLoadTheModulePomXml = pathArgumentCaptor.getValue().toURI(); assertThat(pathThatWasUsedToLoadTheModulePomXml).endsWith(":///testFile/pom.xml"); }
private void updateParentPOM() { Path parentPom = Paths.convert(Paths.convert(moduleRoot).resolve("pom.xml")); if (ioService.exists(Paths.convert(parentPom))) { POM parent = pomService.load(parentPom); parent.setPackaging("pom"); parent.getModules().add(pom.getName()); pom.setParent(parent.getGav()); pomService.save(parentPom, parent, null, "Adding child module " + pom.getName()); } }
@Test public void testLoadPom() throws Exception { final POM pom = new POM(); when(pomService.load(pathToPom)).thenReturn(pom); final Metadata metadata = new Metadata(); when(metadataService.getMetadata(pathToPom)).thenReturn(metadata); ProjectScreenModel model = loader.load(pathToPom); assertEquals(pathToPom, model.getPathToPOM()); assertEquals(pom, model.getPOM()); assertEquals(metadata, model.getPOMMetaData()); }
@Override public Module resolveParentModule(final Path resource) { try { //Null resource paths cannot resolve to a Module if (resource == null) { return null; } //Check if resource is the module root final org.uberfire.java.nio.file.Path path = Paths.convert(resource).normalize(); if (hasPom(path)) { final Path moduleRootPath = Paths.convert(path); final Path pomXMLPath = Paths.convert(path.resolve(POM_PATH)); final POM pom = pomService.load(pomXMLPath); return new Module(moduleRootPath, pomXMLPath, pom); } else { return null; } } catch (Exception e) { throw ExceptionUtilities.handleException(e); } }
@Override public Module resolveParentModule(final Path resource) { try { //Null resource paths cannot resolve to a Module if (resource == null) { return null; } //Check if resource is the module root final org.uberfire.java.nio.file.Path path = Paths.convert(resource).normalize(); if (hasPom(path)) { final Path moduleRootPath = Paths.convert(path); final Path pomXMLPath = Paths.convert(path.resolve(POM_PATH)); final POM pom = pomService.load(pomXMLPath); return new Module(moduleRootPath, pomXMLPath, pom); } else { return null; } } catch (Exception e) { throw ExceptionUtilities.handleException(e); } }
@Test public void testLoad() throws Exception { final URL url = this.getClass().getResource("/TestProject/pom.xml"); final Path path = ioService.get(url.toURI()); POM pom = service.load(Paths.convert(path)); assertEquals("org.test", pom.getGav().getGroupId()); assertEquals("my-test", pom.getGav().getArtifactId()); assertEquals("1.0", pom.getGav().getVersion()); assertEquals(2, pom.getDependencies().size()); assertContainsDependency("org.apache.commons", "commons-lang3", "compile", pom.getDependencies()); assertContainsDependency("org.jboss.weld", "weld-core", "test", pom.getDependencies()); }
@Test public void testLoad() throws Exception { final URL url = this.getClass().getResource("/TestProject/pom.xml"); final Path path = ioService.get(url.toURI()); POM pom = service.load(Paths.convert(path)); assertEquals("org.test", pom.getGav().getGroupId()); assertEquals("my-test", pom.getGav().getArtifactId()); assertEquals("1.0", pom.getGav().getVersion()); assertEquals(2, pom.getDependencies().size()); assertContainsDependency("org.apache.commons", "commons-lang3", "compile", pom.getDependencies()); assertContainsDependency("org.jboss.weld", "weld-core", "test", pom.getDependencies()); }