]>
git.argeo.org Git - gpl/argeo-slc.git/blob - runtime/org.argeo.slc.rpmfactory/src/main/java/org/argeo/slc/rpmfactory/core/BuildInMock.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
.rpmfactory
.core
;
19 import java
.io
.IOException
;
20 import java
.util
.ArrayList
;
21 import java
.util
.Arrays
;
22 import java
.util
.HashSet
;
23 import java
.util
.List
;
26 import org
.apache
.commons
.exec
.Executor
;
27 import org
.apache
.commons
.io
.FileUtils
;
28 import org
.apache
.commons
.logging
.Log
;
29 import org
.apache
.commons
.logging
.LogFactory
;
30 import org
.argeo
.slc
.SlcException
;
31 import org
.argeo
.slc
.core
.execution
.tasks
.SystemCall
;
33 /** Build an RPM in mock. */
34 public class BuildInMock
implements Runnable
{
35 private final static Log log
= LogFactory
.getLog(BuildInMock
.class);
36 private final static String NOARCH
= "noarch";
38 private String rpmPackage
= null;
39 private String branch
= null;
40 private String arch
= NOARCH
;
42 private RpmFactory factory
;
43 private Executor executor
;
45 private String debuginfoDirName
= "debuginfo";
46 private String mockExecutable
= "/usr/bin/mock";
49 String mockCfg
= factory
.getMockConfig(arch
);
50 File mockConfigFile
= factory
.getMockConfigFile(arch
, branch
);
53 SystemCall mock
= new SystemCall();
55 mock
.arg("setarch").arg(arch
);
56 mock
.arg(mockExecutable
);
58 mock
.arg("--configdir=" + mockConfigFile
.getAbsoluteFile().getParent());
60 mock
.arg("--arch=" + arch
);
61 mock
.arg("-r").arg(mockCfg
);
62 mock
.arg("--scm-enable");
63 // mock.arg("--scm-option");
64 // mock.arg("git_get='git clone " + (branch != null ? "-b " + branch :
66 // + " " + factory.getGitBaseUrl() + "/SCM_PKG SCM_PKG'");
67 mock
.arg("--scm-option").arg("package=" + rpmPackage
);
69 mock
.setLogCommand(true);
70 mock
.setExecutor(executor
);
73 // mock command execution
78 File stagingDir
= factory
79 .getWorkspaceDir(factory
.getStagingWorkspace());
80 File srpmDir
= new File(stagingDir
, "SRPMS");
83 File debuginfoDir
= null;
84 if (!arch
.equals(NOARCH
)) {
85 archDir
= new File(stagingDir
, arch
);
86 debuginfoDir
= new File(archDir
, debuginfoDirName
);
87 debuginfoDir
.mkdirs();
91 Set
<File
> reposToRecreate
= new HashSet
<File
>();
92 File resultDir
= factory
.getResultDir(arch
);
93 if (resultDir
.exists())
94 rpms
: for (File file
: resultDir
.listFiles()) {
95 if (file
.isDirectory())
99 if (file
.getName().contains(".src.rpm"))
100 targetDirs
= new File
[] { srpmDir
};
101 else if (file
.getName().contains("-debuginfo-"))
102 targetDirs
= new File
[] { debuginfoDir
};
103 else if (!arch
.equals(NOARCH
)
104 && file
.getName().contains("." + arch
+ ".rpm"))
105 targetDirs
= new File
[] { archDir
};
106 else if (file
.getName().contains(".noarch.rpm")) {
107 List
<File
> dirs
= new ArrayList
<File
>();
108 for (String arch
: factory
.getArchs())
109 dirs
.add(new File(stagingDir
, arch
));
110 targetDirs
= dirs
.toArray(new File
[dirs
.size()]);
111 } else if (file
.getName().contains(".rpm"))
112 throw new SlcException("Don't know where to copy " + file
);
114 if (log
.isTraceEnabled())
115 log
.trace("Skip " + file
);
119 reposToRecreate
.addAll(Arrays
.asList(targetDirs
));
120 copyToDirs(file
, targetDirs
);
123 // recreate changed repos
124 for (File repoToRecreate
: reposToRecreate
) {
125 SystemCall createrepo
= new SystemCall();
126 createrepo
.arg("createrepo");
128 createrepo
.arg("-d");
130 if (!repoToRecreate
.getName().equals(debuginfoDirName
))
131 createrepo
.arg("-x").arg(debuginfoDirName
+ "/*");
133 createrepo
.arg("-q");
134 createrepo
.arg(repoToRecreate
.getAbsolutePath());
136 createrepo
.setExecutor(executor
);
138 log
.info("Updated repo " + repoToRecreate
);
141 // index staging workspace
142 factory
.indexWorkspace(factory
.getStagingWorkspace());
145 protected void copyToDirs(File file
, File
[] dirs
) {
146 for (File dir
: dirs
) {
148 FileUtils
.copyFileToDirectory(file
, dir
);
149 if (log
.isDebugEnabled())
150 log
.debug(file
+ " => " + dir
);
151 } catch (IOException e
) {
152 throw new SlcException("Cannot copy " + file
+ " to " + dir
, e
);
157 public void setArch(String arch
) {
161 public void setRpmPackage(String rpmPackage
) {
162 this.rpmPackage
= rpmPackage
;
165 public void setBranch(String branch
) {
166 this.branch
= branch
;
169 public void setFactory(RpmFactory env
) {
173 public void setExecutor(Executor executor
) {
174 this.executor
= executor
;
177 public void setMockExecutable(String mockExecutable
) {
178 this.mockExecutable
= mockExecutable
;