All Downloads are FREE. Search and download functionalities are using the official Maven repository.

io.github.devsecops.engine.domain.pom.utils.PomModelUtils Maven / Gradle / Ivy

There is a newer version: 3.4.0
Show newest version
package io.github.devsecops.engine.domain.pom.utils;

import lombok.experimental.UtilityClass;
import org.apache.maven.model.Model;
import org.apache.maven.model.io.xpp3.MavenXpp3Reader;
import org.apache.maven.model.io.xpp3.MavenXpp3Writer;

import java.io.FileReader;
import java.io.FileWriter;
import java.io.IOException;

@UtilityClass
public class PomModelUtils {

    public static Model read() {
        try {
            FileReader fileReader = new FileReader("pom.xml");
            MavenXpp3Reader reader = new MavenXpp3Reader();
            return reader.read(fileReader);
        } catch (Exception e) {
            throw new RuntimeException("Pom model issue");
        }
    }

    public static void update(Model model) {
        MavenXpp3Writer writer = new MavenXpp3Writer();
        try {
            FileWriter fileWriter = new FileWriter("pom.xml");
            writer.write(fileWriter, model);
        } catch (IOException e) {
            throw new RuntimeException("Couldn't update pom file to update version");
        }
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy