@Override public Path save(final Path pomPath, final POM pom, final Metadata metadata, final String comment) { return save(pomPath, pom, metadata, comment, false); }
@Before public void setUp() throws Exception { MockitoAnnotations.initMocks(this); ioServiceSpy = spy(ioService); service = new POMServiceImpl(ioServiceSpy, pomContentHandler, m2RepoService, metadataService); }
private Optional<Module> getModuleIfPomHasChanges(final Path pomPath, final POM pom) { POM load = load(pomPath); if (!load.equals(pom)) { return Optional.of(moduleService.resolveModule(pomPath)); } else { return Optional.empty(); } }
private Path save(final Path path, final POM content, final Metadata metadata) throws IOException, XmlPullParserException { if (metadata == null) { save(path, content); } else { ioService.write(Paths.convert(path), pomContentHandler.toString(content, loadPomXMLString(path)), metadataService.setUpAttributes(path, metadata)); } return path; }
private void saveSubModules(final Path path, final POM content, final boolean updateModules) throws IOException, XmlPullParserException { if (updateModules && content.isMultiModule() && content.getModules() != null) { for (String module : content.getModules()) { org.uberfire.java.nio.file.Path childPath = Paths.convert(path).getParent().resolve(module).resolve("pom.xml"); if (ioService.exists(childPath)) { POM child = load(Paths.convert(childPath)); if (child != null) { child.setParent(content.getGav()); child.getGav().setGroupId(content.getGav().getGroupId()); child.getGav().setVersion(content.getGav().getVersion()); save(Paths.convert(childPath), child); } } } } }
@Override public Path save(final Path path, final POM content, final Metadata metadata, final String comment, final boolean updateModules) { try { ioService.startBatch(new FileSystem[]{Paths.convert(path).getFileSystem()}, optionsFactory.makeCommentedOption(comment != null ? comment : "")); save(path, content, metadata); saveSubModules(path, content, updateModules); return path; } catch (Exception e) { throw ExceptionUtilities.handleException(e); } finally { ioService.endBatch(); } }
@Override public Path create(final Path projectRoot, final POM pomModel) { org.uberfire.java.nio.file.Path pathToPOMXML = null; try { pomModel.addRepository(getRepository()); pathToPOMXML = Paths.convert(projectRoot).resolve("pom.xml"); if (ioService.exists(pathToPOMXML)) { throw new FileAlreadyExistsException(pathToPOMXML.toString()); } write(pomEnhancer.execute(pomContentHandler.convert(pomModel)), pathToPOMXML, ioService); //Don't raise a NewResourceAdded event as this is handled at the Project level in ProjectServices return Paths.convert(pathToPOMXML); } catch (Exception e) { throw ExceptionUtilities.handleException(e); } }
@Override public POM load(final Path pomPath) { try { return pomContentHandler.toModel(loadPomXMLString(pomPath)); } catch (Exception e) { throw ExceptionUtilities.handleException(e); } }
@Test public void testCreate() throws Exception { final Path path = testFileSystem.createTempDirectory("/MyTestProject"); service.create(path, "baseurl?", new POM()); ArgumentCaptor<org.uberfire.java.nio.file.Path> pathArgumentCaptor = ArgumentCaptor.forClass(org.uberfire.java.nio.file.Path.class); ArgumentCaptor<String> stringArgumentCaptor = ArgumentCaptor.forClass(String.class); verify(ioServiceSpy).write(pathArgumentCaptor.capture(), stringArgumentCaptor.capture()); assertEquals(pathArgumentCaptor.getValue().toUri().toString(), path.toURI() + "/pom.xml"); String pomXML = stringArgumentCaptor.getValue(); assertTrue(pomXML.contains("<id>guvnor-m2-repo</id>")); } }
@Override public Path create(final Path projectRoot, final String repositoryWebBaseURL, final POM pomModel) { org.uberfire.java.nio.file.Path pathToPOMXML = null; try { pomModel.addRepository(getRepository(repositoryWebBaseURL)); final org.uberfire.java.nio.file.Path nioRoot = Paths.convert(projectRoot); pathToPOMXML = nioRoot.resolve("pom.xml"); if (ioService.exists(pathToPOMXML)) { throw new FileAlreadyExistsException(pathToPOMXML.toString()); } ioService.write(pathToPOMXML, pomContentHandler.toString(pomModel)); //Don't raise a NewResourceAdded event as this is handled at the Project level in ProjectServices return Paths.convert(pathToPOMXML); } catch (Exception e) { throw ExceptionUtilities.handleException(e); } }
@Override public Path create(final Path projectRoot, final POM pomModel) { org.uberfire.java.nio.file.Path pathToPOMXML = null; try { pomModel.addRepository(getRepository()); pathToPOMXML = Paths.convert(projectRoot).resolve("pom.xml"); if (ioService.exists(pathToPOMXML)) { throw new FileAlreadyExistsException(pathToPOMXML.toString()); } write(pomEnhancer.execute(pomContentHandler.convert(pomModel)), pathToPOMXML, ioService); //Don't raise a NewResourceAdded event as this is handled at the Project level in ProjectServices return Paths.convert(pathToPOMXML); } catch (Exception e) { throw ExceptionUtilities.handleException(e); } }
@Override public POM load(final Path pomPath) { try { return pomContentHandler.toModel(loadPomXMLString(pomPath)); } catch (Exception e) { throw ExceptionUtilities.handleException(e); } }
@Test public void testCreate() throws Exception { final Path path = testFileSystem.createTempDirectory("/MyTestProject"); service.create(path, new POM()); ArgumentCaptor<org.uberfire.java.nio.file.Path> pathArgumentCaptor = ArgumentCaptor.forClass(org.uberfire.java.nio.file.Path.class); ArgumentCaptor<String> stringArgumentCaptor = ArgumentCaptor.forClass(String.class); verify(ioServiceSpy).write(pathArgumentCaptor.capture(), stringArgumentCaptor.capture()); assertEquals(pathArgumentCaptor.getValue().toUri().toString(), path.toURI() + "/pom.xml"); String pomXML = stringArgumentCaptor.getValue(); assertTrue(pomXML.contains("<id>guvnor-m2-repo</id>")); } }
@Override public Path save(final Path pomPath, final POM pom, final Metadata metadata, final String comment) { return save(pomPath, pom, metadata, comment, false); }
@Before public void setUp() throws Exception { MockitoAnnotations.initMocks(this); ioServiceSpy = spy(ioService); service = new POMServiceImpl(ioServiceSpy, pomContentHandler, m2RepoService, metadataService); }
@Override public POM load(final Path path) { try { return pomContentHandler.toModel(loadPomXMLString(path)); } catch (Exception e) { throw ExceptionUtilities.handleException(e); } }
private Optional<Module> getModuleIfPomHasChanges(final Path pomPath, final POM pom) { POM load = load(pomPath); if (!load.equals(pom)) { return Optional.of(moduleService.resolveModule(pomPath)); } else { return Optional.empty(); } }
@Test public void testCreate() throws Exception { final Path path = testFileSystem.createTempDirectory("/MyTestProject"); service.create(path, new POM()); ArgumentCaptor<org.uberfire.java.nio.file.Path> pathArgumentCaptor = ArgumentCaptor.forClass(org.uberfire.java.nio.file.Path.class); ArgumentCaptor<String> stringArgumentCaptor = ArgumentCaptor.forClass(String.class); verify(ioServiceSpy).write(pathArgumentCaptor.capture(), stringArgumentCaptor.capture()); assertEquals(pathArgumentCaptor.getValue().toUri().toString(), path.toURI() + "/pom.xml"); String pomXML = stringArgumentCaptor.getValue(); assertTrue(pomXML.contains("<id>guvnor-m2-repo</id>")); } }
@Override public Path save(final Path path, final POM content, final Metadata metadata, final String comment) { try { return save(path, content, metadata); } catch (Exception e) { throw ExceptionUtilities.handleException(e); } }
@Before public void setUp() throws Exception { MockitoAnnotations.initMocks(this); ioServiceSpy = spy(ioService); service = new POMServiceImpl(ioServiceSpy, pomContentHandler, m2RepoService, metadataService, new EventSourceMock<>(), mock(ModuleService.class), mock(CommentedOptionFactory.class), pomEnhancer); }