@Test public void writeTest() { assertThat(editor.getHistory()).isEmpty(); CompilationRequest req = new DefaultCompilationRequest(mavenRepoPath, info, new String[]{MavenCLIArgs.COMPILE, MavenCLIArgs.ALTERNATE_USER_SETTINGS + alternateSettingsAbsPath}, Boolean.FALSE); assertThat(editor.write(Paths.get(tmpRoot.toAbsolutePath() + "/dummy/pom.xml"), req)).isTrue(); }
public boolean write(Path pom, CompilationRequest request) { try { Model model = reader.read(new ByteArrayInputStream(Files.readAllBytes(pom))); if (model == null) { logger.error("Model null from pom file:", pom.toString()); return false; } PomPlaceHolder pomPH = new PomPlaceHolder(pom.toAbsolutePath().toString(), model.getArtifactId(), model.getGroupId(), model.getVersion(), model.getPackaging(), Files.readAllBytes(pom)); if (!history.contains(pomPH)) { PluginPresents plugs = updatePom(model); request.getInfo().lateAdditionKiePluginPresent(plugs.isKiePluginPresent()); if (!request.skipProjectDependenciesCreationList()) { String args[] = addCreateClasspathMavenArgs(request.getKieCliRequest().getArgs(), request); request.getKieCliRequest().setArgs(args); } if (plugs.pomOverwriteRequired()) { ByteArrayOutputStream baos = new ByteArrayOutputStream(); writer.write(baos, model); if (logger.isDebugEnabled()) { logger.debug("Pom changed:{}", new String(baos.toByteArray(), StandardCharsets.UTF_8)); } Path pomParent = Paths.get(URI.create( new StringBuffer(). append(FILE_URI). append(pom.getParent().toAbsolutePath().toString()). append("/"). append(POM_NAME).toString())); Files.delete(pomParent); Files.write(pomParent, baos.toByteArray(), StandardOpenOption.CREATE_NEW); } history.add(pomPH); } return true; } catch (Exception e) { logger.error(e.getMessage()); return false; } }
DefaultPomEditor implements PomEditor { public boolean write(Path pom, CompilationRequest request) { try { Model model = reader.read(new ByteArrayInputStream(Files.readAllBytes(pom))); if (model == null) { logger.error("Model null from pom file:", pom.toString()); return false; } PomPlaceHolder pomPH = new PomPlaceHolder(pom.toAbsolutePath().toString(), model.getArtifactId(), model.getGroupId(), model.getVersion(), model.getPackaging(), Files.readAllBytes(pom)); if (!history.contains(pomPH)) { PluginPresents plugs = updatePom(model); request.getInfo().lateAdditionKiePluginPresent(plugs.isKiePluginPresent()); if (!request.skipProjectDependenciesCreationList()) { String args[] = addCreateClasspathMavenArgs(request.getKieCliRequest().getArgs(), request); request.getKieCliRequest().setArgs(args); } if (plugs.pomOverwriteRequired()) { ByteArrayOutputStream baos = new ByteArrayOutputStream(); writer.write(baos, model); if (logger.isDebugEnabled()) { logger.debug("Pom changed:{}", new String(baos.toByteArray(), StandardCharsets.UTF_8)); } Path pomParent = Paths.get(URI.create( new StringBuffer(). append(FILE_URI). append(pom.getParent().toAbsolutePath().toString()). append("/"). append(POM_NAME).toString())); Files.delete(pomParent); Files.write(pomParent, baos.toByteArray(), StandardOpenOption.CREATE_NEW); } history.add(pomPH); } return true; } catch (Exception e) { logger.error(e.getMessage()); return false; } } }
DefaultPomEditor implements PomEditor { public boolean write(Path pom, CompilationRequest request) { try { Model model = reader.read(new ByteArrayInputStream(Files.readAllBytes(pom))); if (model == null) { logger.error("Model null from pom file:", pom.toString()); return false; } PomPlaceHolder pomPH = new PomPlaceHolder(pom.toAbsolutePath().toString(), model.getArtifactId(), model.getGroupId(), model.getVersion(), model.getPackaging(), Files.readAllBytes(pom)); if (!history.contains(pomPH)) { PluginPresents plugs = updatePom(model); request.getInfo().lateAdditionKiePluginPresent(plugs.isKiePluginPresent()); if (!request.skipProjectDependenciesCreationList()) { String args[] = addCreateClasspathMavenArgs(request.getKieCliRequest().getArgs(), request); request.getKieCliRequest().setArgs(args); } if (plugs.pomOverwriteRequired()) { ByteArrayOutputStream baos = new ByteArrayOutputStream(); writer.write(baos, model); if (logger.isDebugEnabled()) { logger.debug("Pom changed:{}", new String(baos.toByteArray(), StandardCharsets.UTF_8)); } Path pomParent = Paths.get(URI.create( new StringBuffer(). append(FILE_URI). append(pom.getParent().toAbsolutePath().toString()). append("/"). append(POM_NAME).toString())); Files.delete(pomParent); Files.write(pomParent, baos.toByteArray(), StandardOpenOption.CREATE_NEW); } history.add(pomPH); } return true; } catch (Exception e) { logger.error(e.getMessage()); return false; } } DefaultPomEditor(Set<PomPlaceHolder> history,
                            ConfigurationProvider config); }
DefaultPomEditor implements PomEditor { public boolean write(Path pom, CompilationRequest request) { try { Model model = reader.read(new ByteArrayInputStream(Files.readAllBytes(pom))); if (model == null) { logger.error("Model null from pom file:", pom.toString()); return false; } PomPlaceHolder pomPH = new PomPlaceHolder(pom.toAbsolutePath().toString(), model.getArtifactId(), model.getGroupId(), model.getVersion(), model.getPackaging(), Files.readAllBytes(pom)); if (!history.contains(pomPH)) { PluginPresents plugs = updatePom(model); request.getInfo().lateAdditionKiePluginPresent(plugs.isKiePluginPresent()); if (!request.skipProjectDependenciesCreationList()) { String args[] = addCreateClasspathMavenArgs(request.getKieCliRequest().getArgs(), request); request.getKieCliRequest().setArgs(args); } if (plugs.pomOverwriteRequired()) { ByteArrayOutputStream baos = new ByteArrayOutputStream(); writer.write(baos, model); if (logger.isDebugEnabled()) { logger.debug("Pom changed:{}", new String(baos.toByteArray(), StandardCharsets.UTF_8)); } Path pomParent = Paths.get(URI.create( new StringBuffer(). append(FILE_URI). append(pom.getParent().toAbsolutePath().toString()). append("/"). append(POM_NAME).toString())); Files.delete(pomParent); Files.write(pomParent, baos.toByteArray(), StandardOpenOption.CREATE_NEW); } history.add(pomPH); } return true; } catch (Exception e) { logger.error(e.getMessage()); return false; } } DefaultPomEditor(Set<PomPlaceHolder> history,
                            ConfigurationProvider config); Set<PomPlaceHolder> getHistory(); @Override Boolean cleanHistory(); PomPlaceHolder readSingle(Path pom); boolean write(Path pom,
                         CompilationRequest request); }
DefaultPomEditor implements PomEditor { public boolean write(Path pom, CompilationRequest request) { try { Model model = reader.read(new ByteArrayInputStream(Files.readAllBytes(pom))); if (model == null) { logger.error("Model null from pom file:", pom.toString()); return false; } PomPlaceHolder pomPH = new PomPlaceHolder(pom.toAbsolutePath().toString(), model.getArtifactId(), model.getGroupId(), model.getVersion(), model.getPackaging(), Files.readAllBytes(pom)); if (!history.contains(pomPH)) { PluginPresents plugs = updatePom(model); request.getInfo().lateAdditionKiePluginPresent(plugs.isKiePluginPresent()); if (!request.skipProjectDependenciesCreationList()) { String args[] = addCreateClasspathMavenArgs(request.getKieCliRequest().getArgs(), request); request.getKieCliRequest().setArgs(args); } if (plugs.pomOverwriteRequired()) { ByteArrayOutputStream baos = new ByteArrayOutputStream(); writer.write(baos, model); if (logger.isDebugEnabled()) { logger.debug("Pom changed:{}", new String(baos.toByteArray(), StandardCharsets.UTF_8)); } Path pomParent = Paths.get(URI.create( new StringBuffer(). append(FILE_URI). append(pom.getParent().toAbsolutePath().toString()). append("/"). append(POM_NAME).toString())); Files.delete(pomParent); Files.write(pomParent, baos.toByteArray(), StandardOpenOption.CREATE_NEW); } history.add(pomPH); } return true; } catch (Exception e) { logger.error(e.getMessage()); return false; } } DefaultPomEditor(Set<PomPlaceHolder> history,
                            ConfigurationProvider config); Set<PomPlaceHolder> getHistory(); @Override Boolean cleanHistory(); PomPlaceHolder readSingle(Path pom); boolean write(Path pom,
                         CompilationRequest request); final String POM; final String TRUE; final String POM_NAME; final String KJAR_EXT; }