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
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.
Advertisement
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);