import java.util.ArrayList;
import java.util.List;
+import org.apache.commons.exec.Executor;
import org.apache.commons.io.FileUtils;
import org.apache.commons.io.IOUtils;
import org.apache.commons.logging.Log;
private File topdir;
- /** Directory where to cache downloaded dsitributions. */
+ /** Directory where to cache downloaded distributions. */
private File distributionCache;
private Resource specFile;
private File srpmFile;
+ private Executor executor;
+
public void run() {
File sourcesDir = new File(topdir, "SOURCES");
sourcesDir.mkdirs();
copyResourceToFile(specFile, targetFile);
// Generate rpmbuild config files
- File rpmmacroFile = new File(topdir, "rpmmacros");
- File rpmrcFile = new File(topdir, "rpmrc");
- rpmBuildEnvironment.writeRpmbuildConfigFiles(topdir, rpmmacroFile,
- rpmrcFile);
+ rpmBuildEnvironment.writeRpmbuildConfigFiles(topdir);
// Build SRPM
srpmsDir.mkdirs();
SystemCall packageSrpm = new SystemCall();
packageSrpm.arg("rpmbuild");
packageSrpm.arg("-bs").arg("--nodeps");
- packageSrpm.arg("--rcfile=" + rpmrcFile.getName());
+ packageSrpm.arg("--rcfile=rpmrc");
+ packageSrpm.arg("--macros=" + RpmBuildEnvironment.defaultMacroFiles
+ + ":rpmmacros");
// buildSrpm.arg("-D", "_topdir " + topdir.getCanonicalPath() + "");
packageSrpm.arg("SPECS/" + specFile.getFilename());
packageSrpm.setExecDir(topdir.getCanonicalPath());
packageSrpm.setLogCommand(true);
// Execute
+ packageSrpm.setExecutor(executor);
String answer = packageSrpm.function();
// Extract generated SRPM path
protected void copyToSources(RpmSpecFile spec, File sourcesDir) {
try {
List<Resource> toCopyToSources = new ArrayList<Resource>();
+ List<Resource> toDownload = new ArrayList<Resource>();
for (String file : spec.getSources().values()) {
try {
Resource res;
} catch (Exception e) {
res = new UrlResource(file);
+ toDownload.add(res);
}
toCopyToSources.add(res);
} catch (Exception e) {
}
} catch (Exception e) {
res = new UrlResource(file);
+ toDownload.add(res);
}
toCopyToSources.add(res);
} catch (Exception e) {
}
// FIXME: we may have missed some files here
- copySources: for (Resource res : toCopyToSources) {
+ for (Resource res : toCopyToSources) {
File targetDir;
- if (distributionCache != null) {
- if (distributionCache.exists())
+ if (distributionCache != null && toDownload.contains(res)) {
+ if (!distributionCache.exists())
distributionCache.mkdirs();
targetDir = distributionCache;
+ if (log.isDebugEnabled())
+ log.debug("Cache " + res + " in " + targetDir);
} else
targetDir = sourcesDir;
File targetFile = new File(targetDir, res.getFilename())
if (!targetFile.exists() || overwriteSources)
copyResourceToFile(res, targetFile);
if (!targetDir.equals(sourcesDir)) {
- File fileInSourcesDir = new File(sourcesDir, targetFile
- .getName());
+ File fileInSourcesDir = new File(sourcesDir,
+ targetFile.getName());
if (!fileInSourcesDir.exists()
|| !(fileInSourcesDir.length() == targetFile
.length()))
this.distributionCache = distributionCache;
}
+ public void setExecutor(Executor executor) {
+ this.executor = executor;
+ }
+
}