]>
git.argeo.org Git - gpl/argeo-slc.git/blob - legacy/org.argeo.slc.support/src/org/argeo/slc/lib/linux/rpmfactory/RpmSpecFile.java
899603a7b93707f3861abde1a3ee5e6e39cf5c51
1 package org
.argeo
.slc
.lib
.linux
.rpmfactory
;
3 import java
.io
.IOException
;
4 import java
.util
.HashMap
;
8 import org
.apache
.commons
.io
.IOUtils
;
9 import org
.springframework
.core
.io
.Resource
;
11 public class RpmSpecFile
{
12 private Resource specFile
;
15 private String version
;
16 private String release
;
17 private Map
<String
, String
> sources
= new HashMap
<String
, String
>();
18 private Map
<String
, String
> patches
= new HashMap
<String
, String
>();
20 public RpmSpecFile(Resource specFile
) {
21 this.specFile
= specFile
;
29 @SuppressWarnings("unchecked")
30 protected void parseSpecFile() {
32 List
<String
> lines
= (List
<String
>) IOUtils
.readLines(specFile
35 lines
: for (String line
: lines
) {
36 int indexSemiColon
= line
.indexOf(':');
37 if (indexSemiColon
<= 0)
39 String directive
= line
.substring(0, indexSemiColon
).trim();
40 String value
= line
.substring(indexSemiColon
+ 1).trim();
41 if ("name".equals(directive
.toLowerCase()))
43 else if ("version".equals(directive
.toLowerCase()))
45 else if ("release".equals(directive
.toLowerCase()))
47 else if (directive
.toLowerCase().startsWith("source"))
48 sources
.put(directive
, interpret(value
));
49 else if (directive
.toLowerCase().startsWith("patch"))
50 patches
.put(directive
, interpret(value
));
53 } catch (IOException e
) {
54 throw new RuntimeException("Cannot parse spec file " + specFile
, e
);
58 protected String
interpret(String value
) {
59 StringBuffer buf
= new StringBuffer(value
.length());
60 StringBuffer currKey
= null;
61 boolean mayBeKey
= false;
62 chars
: for (char c
: value
.toCharArray()) {
67 currKey
= new StringBuffer();
68 } else if (c
== '}') {
71 String key
= currKey
.toString();
72 if ("name".equals(key
.toLowerCase()))
74 else if ("version".equals(key
.toLowerCase()))
77 buf
.append("%{").append(key
).append('}');
86 return buf
.toString();
89 public Resource
getSpecFile() {
93 public String
getName() {
97 public String
getVersion() {
101 public String
getRelease() {
105 public Map
<String
, String
> getSources() {
109 public Map
<String
, String
> getPatches() {