]> git.argeo.org Git - gpl/argeo-slc.git/blob - org.argeo.slc.factory/src/org/argeo/slc/rpmfactory/core/ReleaseStaging.java
Remove dependency to Spring.
[gpl/argeo-slc.git] / org.argeo.slc.factory / src / org / argeo / slc / rpmfactory / core / ReleaseStaging.java
1 package org.argeo.slc.rpmfactory.core;
2
3 import java.io.File;
4 import java.io.IOException;
5 import java.util.ArrayList;
6 import java.util.List;
7
8 import org.apache.commons.exec.Executor;
9 import org.apache.commons.io.FileUtils;
10 import org.apache.commons.logging.Log;
11 import org.apache.commons.logging.LogFactory;
12 import org.argeo.slc.SlcException;
13 import org.argeo.slc.core.execution.tasks.SystemCall;
14 import org.argeo.slc.rpmfactory.RpmFactory;
15
16 /** Releases the content of staging to a public repository. */
17 public class ReleaseStaging implements Runnable {
18 private final static Log log = LogFactory.getLog(ReleaseStaging.class);
19
20 private RpmFactory rpmFactory;
21 private Executor executor;
22
23 private String debuginfoDirName = "debuginfo";
24
25 @Override
26 public void run() {
27 String sourceWorkspace = rpmFactory.getStagingWorkspace();
28 File sourceRepoDir = rpmFactory.getWorkspaceDir(sourceWorkspace);
29 String targetWorkspace = rpmFactory.getTestingWorkspace() != null ? rpmFactory
30 .getTestingWorkspace() : rpmFactory.getStableWorkspace();
31 File targetRepoDir = rpmFactory.getWorkspaceDir(targetWorkspace);
32 List<File> reposToRecreate = new ArrayList<File>();
33
34 stagingChildren: for (File dir : sourceRepoDir.listFiles()) {
35 if (!dir.isDirectory())
36 continue stagingChildren;
37 if (dir.getName().equals("lost+found"))
38 continue stagingChildren;
39
40 File targetDir = new File(targetRepoDir, dir.getName());
41 try {
42 FileUtils.copyDirectory(dir, targetDir);
43 if (log.isDebugEnabled())
44 log.debug(dir + " => " + targetDir);
45 } catch (IOException e) {
46 throw new SlcException(sourceRepoDir
47 + " could not be copied properly, check it manually."
48 + " Metadata have NOT been updated.", e);
49 }
50
51 reposToRecreate.add(dir);
52 reposToRecreate.add(targetDir);
53 File debugInfoDir = new File(dir, debuginfoDirName);
54 if (debugInfoDir.exists())
55 reposToRecreate.add(debugInfoDir);
56 File targetDebugInfoDir = new File(targetDir, debuginfoDirName);
57 if (targetDebugInfoDir.exists())
58 reposToRecreate.add(targetDebugInfoDir);
59
60 }
61
62 // clear staging
63 for (File dir : sourceRepoDir.listFiles()) {
64 try {
65 if (dir.getName().equals("lost+found"))
66 continue;
67 if (dir.isDirectory())
68 FileUtils.deleteDirectory(dir);
69 } catch (IOException e) {
70 log.error("Could not delete " + dir + ". " + e);
71 }
72 }
73
74 // recreate changed repos
75 for (File repoToRecreate : reposToRecreate) {
76 repoToRecreate.mkdirs();
77 SystemCall createrepo = new SystemCall();
78 createrepo.arg("createrepo");
79 // sqllite db
80 createrepo.arg("-d");
81 // debuginfo
82 if (!repoToRecreate.getName().equals(debuginfoDirName))
83 createrepo.arg("-x").arg(debuginfoDirName + "/*");
84 // quiet
85 createrepo.arg("-q");
86 createrepo.arg(repoToRecreate.getAbsolutePath());
87
88 createrepo.setExecutor(executor);
89 createrepo.run();
90 log.info("Updated repo " + repoToRecreate);
91 }
92
93 rpmFactory.indexWorkspace(sourceWorkspace);
94 rpmFactory.indexWorkspace(targetWorkspace);
95 }
96
97 public void setRpmFactory(RpmFactory rpmFactory) {
98 this.rpmFactory = rpmFactory;
99 }
100
101 public void setExecutor(Executor executor) {
102 this.executor = executor;
103 }
104
105 public void setDebuginfoDirName(String debuginfoDirName) {
106 this.debuginfoDirName = debuginfoDirName;
107 }
108
109 }