Is there a Java equivalent of Python’s rpm library? [closed]



There is a problem we want to code in Java. Given an rpm package filename, we need to get the name, version, release and architecture from the following rpm filename format:

<name>-<version>-<release>.<architecture>.rpm

Reference: https://docs.oracle.com/en/database/oracle/oracle-database/18/ladbi/rpm-packages-naming-convention.html#GUID-04FBD99C-77A8-4E31-9C8D-5B6B2EAE68DB

Is there a Java equivalent of Python’s rpm library that could automatically give us name, version, release and architecture attribute values?

Any feedback or hint on how to approach this with Java will be much appreciated. Thank you very much.

Answer

I don’t see why you need a library. Can you not use a simple regex?

    String rpm = "oracle-database-ee-18c-1.0-1.x86_64.rpm";
    Pattern pattern = Pattern.compile("(.+)-(.+)-(.+)\.(.+)\.rpm");
    Matcher matcher = pattern.matcher(rpm);
    if (!matcher.matches()) 
        throw new IllegalStateException("not matching correct format");
    String name = matcher.group(1);
    String version = matcher.group(2);
    String release = matcher.group(3);
    String arch = matcher.group(4);


Source: stackoverflow