X-Git-Url: http://git.argeo.org/?a=blobdiff_plain;f=runtime%2Forg.argeo.slc.support.simple%2Fsrc%2Fmain%2Fjava%2Forg%2Fargeo%2Fslc%2Flib%2Flinux%2Frpmfactory%2FCreateSrpm.java;h=04680df7b438e77bb0cc603d48d9d86b36f986fb;hb=5fcacdb600e4c9e765cb93b46132932662832c1b;hp=e48df91433127d8921c98348b24aadf81be7c8a1;hpb=8f889799e6a47e28225dd0c9e8f9502f35adb42f;p=gpl%2Fargeo-slc.git diff --git a/runtime/org.argeo.slc.support.simple/src/main/java/org/argeo/slc/lib/linux/rpmfactory/CreateSrpm.java b/runtime/org.argeo.slc.support.simple/src/main/java/org/argeo/slc/lib/linux/rpmfactory/CreateSrpm.java index e48df9143..04680df7b 100644 --- a/runtime/org.argeo.slc.support.simple/src/main/java/org/argeo/slc/lib/linux/rpmfactory/CreateSrpm.java +++ b/runtime/org.argeo.slc.support.simple/src/main/java/org/argeo/slc/lib/linux/rpmfactory/CreateSrpm.java @@ -7,6 +7,7 @@ import java.io.OutputStream; 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; @@ -22,6 +23,9 @@ public class CreateSrpm implements Runnable { private File topdir; + /** Directory where to cache downloaded distributions. */ + private File distributionCache; + private Resource specFile; private RpmBuildEnvironment rpmBuildEnvironment; @@ -30,6 +34,8 @@ public class CreateSrpm implements Runnable { private File srpmFile; + private Executor executor; + public void run() { File sourcesDir = new File(topdir, "SOURCES"); sourcesDir.mkdirs(); @@ -47,23 +53,23 @@ public class CreateSrpm implements Runnable { 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 @@ -79,6 +85,7 @@ public class CreateSrpm implements Runnable { protected void copyToSources(RpmSpecFile spec, File sourcesDir) { try { List toCopyToSources = new ArrayList(); + List toDownload = new ArrayList(); for (String file : spec.getSources().values()) { try { Resource res; @@ -89,6 +96,7 @@ public class CreateSrpm implements Runnable { } catch (Exception e) { res = new UrlResource(file); + toDownload.add(res); } toCopyToSources.add(res); } catch (Exception e) { @@ -105,6 +113,7 @@ public class CreateSrpm implements Runnable { } } catch (Exception e) { res = new UrlResource(file); + toDownload.add(res); } toCopyToSources.add(res); } catch (Exception e) { @@ -113,12 +122,28 @@ public class CreateSrpm implements Runnable { } // FIXME: we may have missed some files here - copySources: for (Resource res : toCopyToSources) { - File targetFile = new File(sourcesDir, res.getFilename()) + for (Resource res : toCopyToSources) { + File targetDir; + 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()) .getCanonicalFile(); - if (targetFile.exists() && !overwriteSources) - continue copySources; - copyResourceToFile(res, targetFile); + if (!targetFile.exists() || overwriteSources) + copyResourceToFile(res, targetFile); + if (!targetDir.equals(sourcesDir)) { + File fileInSourcesDir = new File(sourcesDir, + targetFile.getName()); + if (!fileInSourcesDir.exists() + || !(fileInSourcesDir.length() == targetFile + .length())) + FileUtils.copyFile(targetFile, fileInSourcesDir); + } } } catch (Exception e) { throw new SlcException("Cannot copy to " + sourcesDir, e); @@ -175,4 +200,12 @@ public class CreateSrpm implements Runnable { this.rpmBuildEnvironment = rpmBuildEnvironment; } + public void setDistributionCache(File distributionCache) { + this.distributionCache = distributionCache; + } + + public void setExecutor(Executor executor) { + this.executor = executor; + } + }