Java Code Examples for org.apache.maven.model.io.xpp3.MavenXpp3Writer#write()
The following examples show how to use
org.apache.maven.model.io.xpp3.MavenXpp3Writer#write() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: LibrarySuggestionModel.java From scava with Eclipse Public License 2.0 | 6 votes |
public void installPickedLibraries() throws FileNotFoundException, IOException, XmlPullParserException { MavenXpp3Reader reader = new MavenXpp3Reader(); org.apache.maven.model.Model model = reader.read(new FileReader(pomLocation)); pickedLibraries.forEach(library -> { Dependency dependency = new Dependency(); dependency.setGroupId(library.getGroupId()); dependency.setArtifactId(library.getArtifactId()); dependency.setVersion(library.getVersion()); model.addDependency(dependency); }); MavenXpp3Writer writer = new MavenXpp3Writer(); writer.write(new FileWriter(pomLocation), model); }
Example 2
Source File: DefaultFileUploadService.java From archiva with Apache License 2.0 | 6 votes |
private StorageAsset createPom(StorageAsset targetPath, String filename, FileMetadata fileMetadata, String groupId, String artifactId, String version, String packaging) throws IOException { Model projectModel = new Model(); projectModel.setModelVersion("4.0.0"); projectModel.setGroupId(groupId); projectModel.setArtifactId(artifactId); projectModel.setVersion(version); projectModel.setPackaging(packaging); StorageAsset pomFile = targetPath.resolve(filename); MavenXpp3Writer writer = new MavenXpp3Writer(); try (Writer w = new OutputStreamWriter(pomFile.getWriteStream(true))) { writer.write(w, projectModel); } return pomFile; }
Example 3
Source File: PomGenerator.java From minnal with Apache License 2.0 | 6 votes |
@Override public void generate() { logger.info("Creating the pom file {}", POM_FILE); File pom = new File(baseDir, POM_FILE); OutputStreamWriter fileWriter = null; try { fileWriter = new OutputStreamWriter(new FileOutputStream(pom), Charsets.UTF_8); logger.debug("Writing the generated pom file {}", POM_FILE); MavenXpp3Writer writer = new MavenXpp3Writer(); writer.write(fileWriter, model); } catch (Exception e) { throw new MinnalGeneratorException("Failed while writing the pom - " + pom.getName(), e); } finally { closeStream(fileWriter); } }
Example 4
Source File: PomUtils.java From helidon-build-tools with Apache License 2.0 | 5 votes |
/** * Writes the pom model. * * @param pomFile The pom file. * @param model The model. * @throws RuntimeException on error. */ public static void writePomModel(File pomFile, Model model) { try { try (FileWriter fw = new FileWriter(pomFile)) { MavenXpp3Writer mvnWriter = new MavenXpp3Writer(); mvnWriter.write(fw, model); } } catch (Exception e) { throw new RuntimeException(e); } }
Example 5
Source File: SetupMojo.java From vertx-maven-plugin with Apache License 2.0 | 5 votes |
private void save(File pomFile, Model model) throws MojoExecutionException { MavenXpp3Writer xpp3Writer = new MavenXpp3Writer(); try (FileWriter pomFileWriter = new FileWriter(pomFile)) { xpp3Writer.write(pomFileWriter, model); pomFileWriter.flush(); } catch (IOException e) { throw new MojoExecutionException("Unable to write the pom.xml file", e); } }
Example 6
Source File: PomGenerator.java From raptor with Apache License 2.0 | 5 votes |
public void writeTo(OutputStream outputStream, Model model) { MavenXpp3Writer mavenXpp3Writer = new MavenXpp3Writer(); try { mavenXpp3Writer.write(outputStream, model); } catch (IOException e) { log.error("write pom model error", e); throw new RuntimeException("write pom model error", e); } }
Example 7
Source File: MavenCreator.java From microprofile-starter with Apache License 2.0 | 5 votes |
private void writePOMFile(Model pomFile, JessieModel model, boolean mainProject) { String content; MavenXpp3Writer pomWriter = new MavenXpp3Writer(); try { ByteArrayOutputStream out = new ByteArrayOutputStream(); pomWriter.write(out, pomFile); out.close(); content = new String(out.toByteArray()); } catch (IOException e) { throw new TechnicalException(e); } fileCreator.writeContents(model.getDirectory(mainProject), "pom.xml", content); }
Example 8
Source File: BuildManager.java From scava with Eclipse Public License 2.0 | 5 votes |
private void rewritePOM(File pomFile) throws BuildException { try (Reader reader = new FileReader(pomFile)) { MavenXpp3Reader pomReader = new MavenXpp3Reader(); Model model = pomReader.read(reader); reader.close(); model.addRepository(createRepo("maven_central", "http://repo.maven.apache.org/maven2/", "default")); for (String id: eclipseRepos.keySet()) { model.addRepository(createRepo(id, eclipseRepos.get(id), "p2")); } Build modelBuild = model.getBuild(); if (modelBuild == null) { model.setBuild(new Build()); } model.getBuild().addPlugin(createPlugin("org.eclipse.tycho", "tycho-maven-plugin", "0.21.0", true)); model.getBuild().addPlugin(createPlugin("org.eclipse.tycho", "target-platform-configuration", "0.21.0", false)); model.getBuild().addPlugin(createPlugin("org.apache.maven.plugins", "maven-dependency-plugin", "2.8", false)); MavenXpp3Writer pomWriter = new MavenXpp3Writer(); pomWriter.write(new FileWriter(pomFile), model); } catch (Exception e) { throw new BuildException("POM rewriting (to add plugin dependencies, cause) failed unexpectedly", e); } }
Example 9
Source File: SetupMojo.java From vertx-maven-plugin with Apache License 2.0 | 5 votes |
private void save(File pomFile, Model model) throws MojoExecutionException { MavenXpp3Writer xpp3Writer = new MavenXpp3Writer(); FileWriter pomFileWriter = null; try { pomFileWriter = new FileWriter(pomFile); xpp3Writer.write(pomFileWriter, model); pomFileWriter.flush(); } catch (IOException e) { throw new MojoExecutionException("Unable to write the pom.xml file", e); } finally { IOUtils.closeQuietly(pomFileWriter); } }
Example 10
Source File: PomUpdater.java From multi-module-maven-release-plugin with MIT License | 5 votes |
public UpdateResult updateVersion() { List<File> changedPoms = new ArrayList<File>(); List<String> errors = new ArrayList<String>(); for (ReleasableModule module : reactor.getModulesInBuildOrder()) { try { MavenProject project = module.getProject(); if (module.willBeReleased()) { log.info("Going to release " + module.getArtifactId() + " " + module.getNewVersion()); } List<String> errorsForCurrentPom = alterModel(project, module.getNewVersion()); errors.addAll(errorsForCurrentPom); File pom = project.getFile().getCanonicalFile(); changedPoms.add(pom); Writer fileWriter = WriterFactory.newXmlWriter(pom); Model originalModel = project.getOriginalModel(); try { MavenXpp3Writer pomWriter = new MavenXpp3Writer(); pomWriter.write(fileWriter, originalModel); } finally { fileWriter.close(); } } catch (Exception e) { return new UpdateResult(changedPoms, errors, e); } } return new UpdateResult(changedPoms, errors, null); }
Example 11
Source File: AddMavenDependency.java From ogham with Apache License 2.0 | 5 votes |
private void write(Project<?> project, Model model) throws AddDependencyException { try { MavenXpp3Writer writer = new MavenXpp3Writer(); writer.write(new FileWriter(project.getPath().resolve("pom.xml").toFile()), model); } catch(IOException e) { throw new AddDependencyException("Failed to write pom.xml", e); } }
Example 12
Source File: MavenUtils.java From developer-studio with Apache License 2.0 | 5 votes |
public static void saveMavenProject(MavenProject project, File file) throws IOException { if (file.getParentFile()!=null){ file.getParentFile().mkdirs(); } MavenXpp3Writer mavenXpp3writer = new MavenXpp3Writer(); FileWriter fileWriter = new FileWriter(file); mavenXpp3writer.write(fileWriter, project.getModel()); fileWriter.close(); }
Example 13
Source File: ModelUtils.java From quarkus with Apache License 2.0 | 4 votes |
public static void persistModel(Path pomFile, Model model) throws IOException { final MavenXpp3Writer xpp3Writer = new MavenXpp3Writer(); try (BufferedWriter pomFileWriter = Files.newBufferedWriter(pomFile)) { xpp3Writer.write(pomFileWriter, model); } }
Example 14
Source File: FlattenMojo.java From flatten-maven-plugin with Apache License 2.0 | 4 votes |
/** * Writes the given POM {@link Model} to the given {@link File}. * * @param pom the {@link Model} of the POM to write. * @param pomFile the {@link File} where to write the given POM will be written to. {@link File#getParentFile() * Parent directories} are {@link File#mkdirs() created} automatically. * @param headerComment is the content of a potential XML comment at the top of the XML (after XML declaration and * before root tag). May be <code>null</code> if not present and to be omitted in target POM. * @throws MojoExecutionException if the operation failed (e.g. due to an {@link IOException}). */ protected void writePom( Model pom, File pomFile, String headerComment ) throws MojoExecutionException { File parentFile = pomFile.getParentFile(); if ( !parentFile.exists() ) { boolean success = parentFile.mkdirs(); if ( !success ) { throw new MojoExecutionException( "Failed to create directory " + pomFile.getParent() ); } } // MavenXpp3Writer could internally add the comment but does not expose such feature to API! // Instead we have to write POM XML to String and do post processing on that :( MavenXpp3Writer pomWriter = new MavenXpp3Writer(); StringWriter stringWriter = new StringWriter( INITIAL_POM_WRITER_SIZE ); try { pomWriter.write( stringWriter, pom ); } catch ( IOException e ) { throw new MojoExecutionException( "Internal I/O error!", e ); } StringBuffer buffer = stringWriter.getBuffer(); if ( !StringUtils.isEmpty( headerComment ) ) { int projectStartIndex = buffer.indexOf( "<project" ); if ( projectStartIndex >= 0 ) { buffer.insert( projectStartIndex, "<!--" + headerComment + "-->\n" ); } else { getLog().warn( "POM XML post-processing failed: no project tag found!" ); } } writeStringToFile( buffer.toString(), pomFile, pom.getModelEncoding() ); }
Example 15
Source File: RunnerUtils.java From ogham with Apache License 2.0 | 4 votes |
private static void write(Path rootPom, Model model) throws IOException { MavenXpp3Writer writer = new MavenXpp3Writer(); writer.write(new FileWriter(rootPom.toFile()), model); }