Introduce release staging
authorMathieu Baudier <mbaudier@argeo.org>
Tue, 16 Jul 2013 12:32:47 +0000 (12:32 +0000)
committerMathieu Baudier <mbaudier@argeo.org>
Tue, 16 Jul 2013 12:32:47 +0000 (12:32 +0000)
git-svn-id: https://svn.argeo.org/slc/trunk@6379 4cfe0d0a-d680-48aa-b62c-e0a02a3f76cc

runtime/org.argeo.slc.rpmfactory/src/main/java/org/argeo/slc/rpmfactory/core/BuildInMock.java
runtime/org.argeo.slc.rpmfactory/src/main/java/org/argeo/slc/rpmfactory/core/ReleaseStaging.java [new file with mode: 0644]
runtime/org.argeo.slc.rpmfactory/src/main/java/org/argeo/slc/rpmfactory/core/RpmFactory.java

index 3b4d84a779893e6c9f56c21b68992ef89b9dcbb0..f2b1dbaf3428382f022dba3f730339cb90ade01b 100644 (file)
@@ -39,7 +39,7 @@ public class BuildInMock implements Runnable {
        private String branch = null;
        private String arch = NOARCH;
 
-       private RpmFactory factory;
+       private RpmFactory rpmFactory;
        private Executor executor;
 
        private String debuginfoDirName = "debuginfo";
@@ -48,7 +48,7 @@ public class BuildInMock implements Runnable {
        private List<String> preBuildCommands = new ArrayList<String>();
 
        public void run() {
-               if (!factory.isDeveloperInstance()) {
+               if (!rpmFactory.isDeveloperInstance()) {
                        // clean/init
                        SystemCall mockClean = createBaseMockCall();
                        mockClean.arg("--init");
@@ -73,8 +73,8 @@ public class BuildInMock implements Runnable {
                //
 
                // copy RPMs to target directories
-               File stagingDir = factory
-                               .getWorkspaceDir(factory.getStagingWorkspace());
+               File stagingDir = rpmFactory.getWorkspaceDir(rpmFactory
+                               .getStagingWorkspace());
                File srpmDir = new File(stagingDir, "SRPMS");
                srpmDir.mkdirs();
                File archDir = null;
@@ -86,7 +86,7 @@ public class BuildInMock implements Runnable {
                }
 
                Set<File> reposToRecreate = new HashSet<File>();
-               File resultDir = factory.getResultDir(arch);
+               File resultDir = rpmFactory.getResultDir(arch);
                if (resultDir.exists())
                        rpms: for (File file : resultDir.listFiles()) {
                                if (file.isDirectory())
@@ -102,7 +102,7 @@ public class BuildInMock implements Runnable {
                                        targetDirs = new File[] { archDir };
                                else if (file.getName().contains(".noarch.rpm")) {
                                        List<File> dirs = new ArrayList<File>();
-                                       for (String arch : factory.getArchs())
+                                       for (String arch : rpmFactory.getArchs())
                                                dirs.add(new File(stagingDir, arch));
                                        targetDirs = dirs.toArray(new File[dirs.size()]);
                                } else if (file.getName().contains(".rpm"))
@@ -136,13 +136,13 @@ public class BuildInMock implements Runnable {
                }
 
                // index staging workspace
-               factory.indexWorkspace(factory.getStagingWorkspace());
+               rpmFactory.indexWorkspace(rpmFactory.getStagingWorkspace());
        }
 
        /** Creates a mock call with all the common options such as config file etc. */
        protected SystemCall createBaseMockCall() {
-               String mockCfg = factory.getMockConfig(arch);
-               File mockConfigFile = factory.getMockConfigFile(arch, branch);
+               String mockCfg = rpmFactory.getMockConfig(arch);
+               File mockConfigFile = rpmFactory.getMockConfigFile(arch, branch);
 
                // prepare mock call
                SystemCall mock = new SystemCall();
@@ -186,8 +186,8 @@ public class BuildInMock implements Runnable {
                this.branch = branch;
        }
 
-       public void setFactory(RpmFactory env) {
-               this.factory = env;
+       public void setRpmFactory(RpmFactory env) {
+               this.rpmFactory = env;
        }
 
        public void setExecutor(Executor executor) {
diff --git a/runtime/org.argeo.slc.rpmfactory/src/main/java/org/argeo/slc/rpmfactory/core/ReleaseStaging.java b/runtime/org.argeo.slc.rpmfactory/src/main/java/org/argeo/slc/rpmfactory/core/ReleaseStaging.java
new file mode 100644 (file)
index 0000000..44fb368
--- /dev/null
@@ -0,0 +1,106 @@
+package org.argeo.slc.rpmfactory.core;
+
+import java.io.File;
+import java.io.IOException;
+import java.util.ArrayList;
+import java.util.List;
+
+import org.apache.commons.exec.Executor;
+import org.apache.commons.io.FileUtils;
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+import org.argeo.slc.SlcException;
+import org.argeo.slc.core.execution.tasks.SystemCall;
+
+/** Releases the content of staging to a public repository. */
+public class ReleaseStaging implements Runnable {
+       private final static Log log = LogFactory.getLog(ReleaseStaging.class);
+
+       private RpmFactory rpmFactory;
+       private Executor executor;
+
+       private String debuginfoDirName = "debuginfo";
+
+       @Override
+       public void run() {
+               File stagingDir = rpmFactory.getWorkspaceDir(rpmFactory
+                               .getStagingWorkspace());
+               // TODO deal with testing
+               File targetRepoDir = rpmFactory.getWorkspaceDir(rpmFactory
+                               .getStableWorkspace());
+               List<File> reposToRecreate = new ArrayList<File>();
+
+               stagingChildren: for (File dir : stagingDir.listFiles()) {
+                       if (!dir.isDirectory())
+                               continue stagingChildren;
+                       if (dir.getName().equals("lost+found"))
+                               continue stagingChildren;
+
+                       File targetDir = new File(targetRepoDir, dir.getName());
+                       try {
+                               FileUtils.copyDirectory(dir, targetDir);
+                               if (log.isDebugEnabled())
+                                       log.debug(dir + " => " + targetDir);
+                       } catch (IOException e) {
+                               throw new SlcException(stagingDir
+                                               + " could not be copied properly, check it manually."
+                                               + " Metadata have NOT been updated.", e);
+                       }
+
+                       reposToRecreate.add(dir);
+                       reposToRecreate.add(targetDir);
+                       File debugInfoDir = new File(dir, debuginfoDirName);
+                       if (debugInfoDir.exists())
+                               reposToRecreate.add(debugInfoDir);
+                       File targetDebugInfoDir = new File(targetDir, debuginfoDirName);
+                       if (targetDebugInfoDir.exists())
+                               reposToRecreate.add(targetDebugInfoDir);
+
+               }
+
+               // clear staging
+               for (File dir : stagingDir.listFiles()) {
+                       try {
+                               if (dir.getName().equals("lost+found"))
+                                       continue;
+                               if (dir.isDirectory())
+                                       FileUtils.deleteDirectory(dir);
+                       } catch (IOException e) {
+                               log.error("Could not delete " + dir + ". " + e);
+                       }
+               }
+
+               // recreate changed repos
+               for (File repoToRecreate : reposToRecreate) {
+                       repoToRecreate.mkdirs();
+                       SystemCall createrepo = new SystemCall();
+                       createrepo.arg("createrepo");
+                       // sqllite db
+                       createrepo.arg("-d");
+                       // debuginfo
+                       if (!repoToRecreate.getName().equals(debuginfoDirName))
+                               createrepo.arg("-x").arg(debuginfoDirName + "/*");
+                       // quiet
+                       createrepo.arg("-q");
+                       createrepo.arg(repoToRecreate.getAbsolutePath());
+
+                       createrepo.setExecutor(executor);
+                       createrepo.run();
+                       log.info("Updated repo " + repoToRecreate);
+               }
+
+       }
+
+       public void setRpmFactory(RpmFactory rpmFactory) {
+               this.rpmFactory = rpmFactory;
+       }
+
+       public void setExecutor(Executor executor) {
+               this.executor = executor;
+       }
+
+       public void setDebuginfoDirName(String debuginfoDirName) {
+               this.debuginfoDirName = debuginfoDirName;
+       }
+
+}
index 0a9115395bbfa2b2098d761431598c734b581b3f..c09ed36c3abc0534179eda42ac4b9cf836c09359 100644 (file)
@@ -246,6 +246,7 @@ public class RpmFactory {
 
                for (RpmRepository repository : repositories) {
                        buf.append('[').append(repository.getId()).append("]\n");
+                       buf.append("name=").append(repository.getId()).append('\n');
                        if (repository instanceof ThirdPartyRpmRepository) {
                                buf.append("#baseurl=").append(repository.getUrl())
                                                .append(arch).append('/').append("\n");