]>
git.argeo.org Git - gpl/argeo-jcr.git/blob - org.argeo.slc.rpmfactory/src/org/argeo/slc/rpmfactory/core/RpmSpecFile.java
1 package org
.argeo
.slc
.rpmfactory
.core
;
3 import java
.io
.IOException
;
4 import java
.nio
.file
.Files
;
5 import java
.nio
.file
.Path
;
6 import java
.util
.HashMap
;
10 public class RpmSpecFile
{
11 private Path specFile
;
14 private String version
;
15 private String release
;
16 private Map
<String
, String
> sources
= new HashMap
<String
, String
>();
17 private Map
<String
, String
> patches
= new HashMap
<String
, String
>();
19 public RpmSpecFile(Path specFile
) {
20 this.specFile
= specFile
;
28 protected void parseSpecFile() {
30 List
<String
> lines
= (List
<String
>) Files
.readAllLines(specFile
);
32 lines
: for (String line
: lines
) {
33 int indexSemiColon
= line
.indexOf(':');
34 if (indexSemiColon
<= 0)
36 String directive
= line
.substring(0, indexSemiColon
).trim();
37 String value
= line
.substring(indexSemiColon
+ 1).trim();
38 if ("name".equals(directive
.toLowerCase()))
40 else if ("version".equals(directive
.toLowerCase()))
42 else if ("release".equals(directive
.toLowerCase()))
44 else if (directive
.toLowerCase().startsWith("source"))
45 sources
.put(directive
, interpret(value
));
46 else if (directive
.toLowerCase().startsWith("patch"))
47 patches
.put(directive
, interpret(value
));
50 } catch (IOException e
) {
51 throw new RuntimeException("Cannot parse spec file " + specFile
, e
);
55 protected String
interpret(String value
) {
56 StringBuffer buf
= new StringBuffer(value
.length());
57 StringBuffer currKey
= null;
58 boolean mayBeKey
= false;
59 chars
: for (char c
: value
.toCharArray()) {
64 currKey
= new StringBuffer();
65 } else if (c
== '}') {
68 String key
= currKey
.toString();
69 if ("name".equals(key
.toLowerCase()))
71 else if ("version".equals(key
.toLowerCase()))
74 buf
.append("%{").append(key
).append('}');
83 return buf
.toString();
86 public Path
getSpecFile() {
90 public String
getName() {
94 public String
getVersion() {
98 public String
getRelease() {
102 public Map
<String
, String
> getSources() {
106 public Map
<String
, String
> getPatches() {