1 package org
.argeo
.slc
.rpmfactory
.core
;
4 import java
.io
.InputStream
;
6 import java
.util
.StringTokenizer
;
9 import javax
.jcr
.Session
;
10 import javax
.jcr
.nodetype
.NodeType
;
12 import org
.apache
.commons
.io
.FilenameUtils
;
13 import org
.apache
.commons
.io
.IOUtils
;
14 import org
.apache
.commons
.logging
.Log
;
15 import org
.apache
.commons
.logging
.LogFactory
;
16 import org
.argeo
.jcr
.JcrUtils
;
17 import org
.argeo
.slc
.SlcException
;
18 import org
.argeo
.slc
.core
.execution
.tasks
.SystemCall
;
19 import org
.argeo
.slc
.rpmfactory
.RpmFactory
;
22 * Gather RPMs from various sources (local builds or third party) into a
23 * consistent distributable set (typically to be used to generate an ISO).
25 public class CreateRpmDistribution
implements Runnable
{
26 private final static Log log
= LogFactory
27 .getLog(CreateRpmDistribution
.class);
29 private RpmFactory rpmFactory
;
30 private RpmDistribution rpmDistribution
;
32 private String arch
= "x86_64";
34 private String repoqueryExecutable
= "/usr/bin/repoquery";
38 Session session
= null;
39 // Reader reader = null;
41 Node baseFolder
= rpmFactory
.newDistribution(rpmDistribution
43 session
= baseFolder
.getSession();
44 Node targetFolder
= baseFolder
.addNode(arch
, NodeType
.NT_FOLDER
);
46 SystemCall repoquery
= new SystemCall();
47 repoquery
.arg(repoqueryExecutable
);
49 File yumConfigFile
= rpmFactory
.getYumRepoFile(arch
);
50 repoquery
.arg("-c", yumConfigFile
.getAbsolutePath());
51 repoquery
.arg("--requires");
52 repoquery
.arg("--resolve");
53 repoquery
.arg("--location");
54 repoquery
.arg("--archlist=" + arch
);
56 for (String rpmPackage
: rpmDistribution
.getPackages())
57 repoquery
.arg(rpmPackage
);
59 if (log
.isDebugEnabled())
60 log
.debug("Command:\n" + repoquery
.asCommand());
62 String output
= repoquery
.function();
64 if (log
.isDebugEnabled())
65 log
.debug(output
+ "\n");
66 // reader = new StringReader(output);
67 StringTokenizer lines
= new StringTokenizer(output
, "\n");
68 // List<String> dependencies = IOUtils.readLines(reader);
69 dependencies
: while (lines
.hasMoreTokens()) {
70 String urlStr
= lines
.nextToken();
71 InputStream in
= null;
73 URL url
= new URL(urlStr
);
74 String fileName
= FilenameUtils
.getName(url
.getFile());
75 String
[] tokens
= fileName
.split("-");
76 if (tokens
.length
< 3)
77 continue dependencies
;
78 StringBuilder buf
= new StringBuilder();
79 for (int i
= 0; i
< tokens
.length
- 2; i
++) {
82 buf
.append(tokens
[i
]);
85 String packageName
= buf
.toString();
86 for (RpmPackageSet excluded
: rpmDistribution
87 .getExcludedPackages()) {
88 if (excluded
.contains(packageName
)) {
89 if (log
.isDebugEnabled())
90 log
.debug("Skipped " + packageName
);
91 continue dependencies
;// skip
94 in
= url
.openStream();
95 JcrUtils
.copyStreamAsFile(targetFolder
, fileName
, in
);
96 targetFolder
.getSession().save();
97 if (log
.isDebugEnabled())
98 log
.debug("Copied " + packageName
);
99 } catch (Exception e
) {
100 log
.error("Cannot copy " + urlStr
, e
);
102 IOUtils
.closeQuietly(in
);
107 File workspaceDir
= rpmFactory
.getWorkspaceDir(rpmDistribution
109 SystemCall createrepo
= new SystemCall();
110 createrepo
.arg("createrepo");
111 createrepo
.arg("-q");
112 createrepo
.arg("-d");
113 File archDir
= new File(workspaceDir
.getPath()
114 + targetFolder
.getPath());
115 createrepo
.arg(archDir
.getAbsolutePath());
117 } catch (Exception e
) {
118 throw new SlcException("Cannot generate distribution "
119 + rpmDistribution
.getId(), e
);
121 JcrUtils
.logoutQuietly(session
);
122 // IOUtils.closeQuietly(reader);
126 public void setRpmDistribution(RpmDistribution rpmDistribution
) {
127 this.rpmDistribution
= rpmDistribution
;
130 public void setRpmFactory(RpmFactory rpmFactory
) {
131 this.rpmFactory
= rpmFactory
;
134 public void setArch(String arch
) {
138 public void setRepoqueryExecutable(String yumdownloaderExecutable
) {
139 this.repoqueryExecutable
= yumdownloaderExecutable
;