]>
git.argeo.org Git - gpl/argeo-slc.git/blob - org.argeo.slc.support/src/org/argeo/slc/lib/linux/rpmfactory/RpmSpecFile.java
2 * Copyright (C) 2007-2012 Argeo GmbH
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
8 * http://www.apache.org/licenses/LICENSE-2.0
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
16 package org
.argeo
.slc
.lib
.linux
.rpmfactory
;
18 import java
.io
.IOException
;
19 import java
.util
.HashMap
;
20 import java
.util
.List
;
23 import org
.apache
.commons
.io
.IOUtils
;
24 import org
.springframework
.core
.io
.Resource
;
26 public class RpmSpecFile
{
27 private Resource specFile
;
30 private String version
;
31 private String release
;
32 private Map
<String
, String
> sources
= new HashMap
<String
, String
>();
33 private Map
<String
, String
> patches
= new HashMap
<String
, String
>();
35 public RpmSpecFile(Resource specFile
) {
36 this.specFile
= specFile
;
44 @SuppressWarnings("unchecked")
45 protected void parseSpecFile() {
47 List
<String
> lines
= (List
<String
>) IOUtils
.readLines(specFile
50 lines
: for (String line
: lines
) {
51 int indexSemiColon
= line
.indexOf(':');
52 if (indexSemiColon
<= 0)
54 String directive
= line
.substring(0, indexSemiColon
).trim();
55 String value
= line
.substring(indexSemiColon
+ 1).trim();
56 if ("name".equals(directive
.toLowerCase()))
58 else if ("version".equals(directive
.toLowerCase()))
60 else if ("release".equals(directive
.toLowerCase()))
62 else if (directive
.toLowerCase().startsWith("source"))
63 sources
.put(directive
, interpret(value
));
64 else if (directive
.toLowerCase().startsWith("patch"))
65 patches
.put(directive
, interpret(value
));
68 } catch (IOException e
) {
69 throw new RuntimeException("Cannot parse spec file " + specFile
, e
);
73 protected String
interpret(String value
) {
74 StringBuffer buf
= new StringBuffer(value
.length());
75 StringBuffer currKey
= null;
76 boolean mayBeKey
= false;
77 chars
: for (char c
: value
.toCharArray()) {
82 currKey
= new StringBuffer();
83 } else if (c
== '}') {
86 String key
= currKey
.toString();
87 if ("name".equals(key
.toLowerCase()))
89 else if ("version".equals(key
.toLowerCase()))
92 buf
.append("%{").append(key
).append('}');
101 return buf
.toString();
104 public Resource
getSpecFile() {
108 public String
getName() {
112 public String
getVersion() {
116 public String
getRelease() {
120 public Map
<String
, String
> getSources() {
124 public Map
<String
, String
> getPatches() {