]>
git.argeo.org Git - gpl/argeo-slc.git/blob - BuildInMock.java
50daabce3f3d0c1a5bb1e2cbdf77f8394ac55570
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";
48 String mockCfg
= factory
.getMockConfig(arch
);
49 File mockConfigFile
= factory
.getMockConfigFile(arch
, branch
);
52 SystemCall mock
= new SystemCall();
54 mock
.arg("setarch").arg(arch
);
57 mock
.arg("--configdir=" + mockConfigFile
.getAbsoluteFile().getParent());
59 mock
.arg("--arch=" + arch
);
60 mock
.arg("-r").arg(mockCfg
);
61 mock
.arg("--scm-enable");
62 // mock.arg("--scm-option");
63 // mock.arg("git_get='git clone " + (branch != null ? "-b " + branch :
65 // + " " + factory.getGitBaseUrl() + "/SCM_PKG SCM_PKG'");
66 mock
.arg("--scm-option").arg("package=" + rpmPackage
);
68 mock
.setLogCommand(true);
69 mock
.setExecutor(executor
);
72 // mock command execution
77 File stagingDir
= factory
78 .getWorkspaceDir(factory
.getStagingWorkspace());
79 File srpmDir
= new File(stagingDir
, "SRPMS");
82 File debuginfoDir
= null;
83 if (!arch
.equals(NOARCH
)) {
84 archDir
= new File(stagingDir
, arch
);
85 debuginfoDir
= new File(archDir
, debuginfoDirName
);
86 debuginfoDir
.mkdirs();
90 Set
<File
> reposToRecreate
= new HashSet
<File
>();
91 File resultDir
= factory
.getResultDir(arch
);
92 rpms
: for (File file
: resultDir
.listFiles()) {
93 if (file
.isDirectory())
97 if (file
.getName().contains(".src.rpm"))
98 targetDirs
= new File
[] { srpmDir
};
99 else if (file
.getName().contains("-debuginfo-"))
100 targetDirs
= new File
[] { debuginfoDir
};
101 else if (!arch
.equals(NOARCH
)
102 && file
.getName().contains("." + arch
+ ".rpm"))
103 targetDirs
= new File
[] { archDir
};
104 else if (file
.getName().contains(".noarch.rpm")) {
105 List
<File
> dirs
= new ArrayList
<File
>();
106 for (String arch
: factory
.getArchs())
107 dirs
.add(new File(stagingDir
, arch
));
108 targetDirs
= dirs
.toArray(new File
[dirs
.size()]);
109 } else if (file
.getName().contains(".rpm"))
110 throw new SlcException("Don't know where to copy " + file
);
112 if (log
.isTraceEnabled())
113 log
.trace("Skip " + file
);
117 reposToRecreate
.addAll(Arrays
.asList(targetDirs
));
118 copyToDirs(file
, targetDirs
);
121 // recreate changed repos
122 for (File repoToRecreate
: reposToRecreate
) {
123 SystemCall createrepo
= new SystemCall();
124 createrepo
.arg("createrepo");
126 createrepo
.arg("-d");
128 if (!repoToRecreate
.getName().equals(debuginfoDirName
))
129 createrepo
.arg("-x").arg(debuginfoDirName
+ "/*");
131 createrepo
.arg("-q");
132 createrepo
.arg(repoToRecreate
.getAbsolutePath());
134 createrepo
.setExecutor(executor
);
136 log
.info("Updated repo " + repoToRecreate
);
139 // index staging workspace
140 factory
.indexWorkspace(factory
.getStagingWorkspace());
143 protected void copyToDirs(File file
, File
[] dirs
) {
144 for (File dir
: dirs
) {
146 FileUtils
.copyFileToDirectory(file
, dir
);
147 if (log
.isDebugEnabled())
148 log
.debug(file
+ " => " + dir
);
149 } catch (IOException e
) {
150 throw new SlcException("Cannot copy " + file
+ " to " + dir
, e
);
155 public void setArch(String arch
) {
159 public void setRpmPackage(String rpmPackage
) {
160 this.rpmPackage
= rpmPackage
;
163 public void setBranch(String branch
) {
164 this.branch
= branch
;
167 public void setFactory(RpmFactory env
) {
171 public void setExecutor(Executor executor
) {
172 this.executor
= executor
;