]> git.argeo.org Git - gpl/argeo-slc.git/blob - runtime/org.argeo.slc.support.simple/src/main/java/org/argeo/slc/lib/linux/rpmfactory/RpmBuildEnvironment.java
a5c1fc7ded02d674480ee5e233a56e0ff21a89aa
[gpl/argeo-slc.git] / runtime / org.argeo.slc.support.simple / src / main / java / org / argeo / slc / lib / linux / rpmfactory / RpmBuildEnvironment.java
1 /*
2 * Copyright (C) 2007-2012 Argeo GmbH
3 *
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
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
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.
15 */
16 package org.argeo.slc.lib.linux.rpmfactory;
17
18 import java.io.File;
19 import java.io.IOException;
20 import java.util.ArrayList;
21 import java.util.HashMap;
22 import java.util.List;
23 import java.util.Map;
24
25 import org.apache.commons.io.FileUtils;
26 import org.argeo.slc.SlcException;
27
28 /**
29 * Defines a build environment. This information is typically used by other
30 * components performing the various actions related to RPM build.
31 */
32 public class RpmBuildEnvironment {
33 static String defaultMacroFiles = "/usr/lib/rpm/macros:/usr/lib/rpm/ia32e-linux/macros:/usr/lib/rpm/redhat/macros:/etc/rpm/macros.*:/etc/rpm/macros:/etc/rpm/ia32e-linux/macros:~/.rpmmacros";
34
35 private Map<String, String> rpmmacros = new HashMap<String, String>();
36
37 private List<String> archs = new ArrayList<String>();
38
39 private String stagingBase = "/mnt/slc/repos/rpm";
40
41 /** Write (topdir)/rpmmacros and (topdir)/rpmrc */
42 public void writeRpmbuildConfigFiles(File topdir) {
43 writeRpmbuildConfigFiles(topdir, new File(topdir, "rpmmacros"),
44 new File(topdir, "rpmrc"));
45 }
46
47 public void writeRpmbuildConfigFiles(File topdir, File rpmmacroFile,
48 File rpmrcFile) {
49 try {
50 List<String> macroLines = new ArrayList<String>();
51 macroLines.add("%_topdir " + topdir.getCanonicalPath());
52 for (String macroKey : rpmmacros.keySet()) {
53 macroLines.add(macroKey + " " + rpmmacros.get(macroKey));
54 }
55 FileUtils.writeLines(rpmmacroFile, macroLines);
56
57 List<String> rpmrcLines = new ArrayList<String>();
58 rpmrcLines.add("include: /usr/lib/rpm/rpmrc");
59 rpmrcLines.add("macrofiles: " + defaultMacroFiles + ":"
60 + rpmmacroFile.getCanonicalPath());
61 FileUtils.writeLines(rpmrcFile, rpmrcLines);
62 } catch (IOException e) {
63 throw new SlcException("Cannot write rpmbuild config files", e);
64 }
65
66 }
67
68 public Map<String, String> getRpmmacros() {
69 return rpmmacros;
70 }
71
72 public void setRpmmacros(Map<String, String> rpmmacros) {
73 this.rpmmacros = rpmmacros;
74 }
75
76 public String getDefaultMacroFiles() {
77 return defaultMacroFiles;
78 }
79
80 public void setDefaultMacroFiles(String defaultMacroFiles) {
81 this.defaultMacroFiles = defaultMacroFiles;
82 }
83
84 public void setArchs(List<String> archs) {
85 this.archs = archs;
86 }
87
88 public List<String> getArchs() {
89 return archs;
90 }
91
92 public String getStagingBase() {
93 return stagingBase;
94 }
95
96 public void setStagingBase(String stagingBase) {
97 this.stagingBase = stagingBase;
98 }
99 }