]>
git.argeo.org Git - gpl/argeo-slc.git/blob - org.argeo.slc.factory/src/org/argeo/slc/rpmfactory/core/ReleaseStaging.java
1 package org
.argeo
.slc
.rpmfactory
.core
;
4 import java
.io
.IOException
;
5 import java
.util
.ArrayList
;
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
;
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);
20 private RpmFactory rpmFactory
;
21 private Executor executor
;
23 private String debuginfoDirName
= "debuginfo";
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
>();
34 stagingChildren
: for (File dir
: sourceRepoDir
.listFiles()) {
35 if (!dir
.isDirectory())
36 continue stagingChildren
;
37 if (dir
.getName().equals("lost+found"))
38 continue stagingChildren
;
40 File targetDir
= new File(targetRepoDir
, dir
.getName());
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
);
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
);
63 for (File dir
: sourceRepoDir
.listFiles()) {
65 if (dir
.getName().equals("lost+found"))
67 if (dir
.isDirectory())
68 FileUtils
.deleteDirectory(dir
);
69 } catch (IOException e
) {
70 log
.error("Could not delete " + dir
+ ". " + e
);
74 // recreate changed repos
75 for (File repoToRecreate
: reposToRecreate
) {
76 repoToRecreate
.mkdirs();
77 SystemCall createrepo
= new SystemCall();
78 createrepo
.arg("createrepo");
82 if (!repoToRecreate
.getName().equals(debuginfoDirName
))
83 createrepo
.arg("-x").arg(debuginfoDirName
+ "/*");
86 createrepo
.arg(repoToRecreate
.getAbsolutePath());
88 createrepo
.setExecutor(executor
);
90 log
.info("Updated repo " + repoToRecreate
);
93 rpmFactory
.indexWorkspace(sourceWorkspace
);
94 rpmFactory
.indexWorkspace(targetWorkspace
);
97 public void setRpmFactory(RpmFactory rpmFactory
) {
98 this.rpmFactory
= rpmFactory
;
101 public void setExecutor(Executor executor
) {
102 this.executor
= executor
;
105 public void setDebuginfoDirName(String debuginfoDirName
) {
106 this.debuginfoDirName
= debuginfoDirName
;