View Javadoc
1   /*
2    * Copyright (C) 2007-2012 Argeo GmbH
3    *
4    * Licensed under the Apache License, Version 2.0 (the "License");
5    * you may not use this file except in compliance with the License.
6    * You may obtain a copy of the License at
7    *
8    *         http://www.apache.org/licenses/LICENSE-2.0
9    *
10   * Unless required by applicable law or agreed to in writing, software
11   * distributed under the License is distributed on an "AS IS" BASIS,
12   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13   * See the License for the specific language governing permissions and
14   * limitations under the License.
15   */
16  package org.argeo.slc.lib.linux.rpmfactory;
17  
18  import java.io.File;
19  
20  import org.argeo.slc.core.execution.tasks.SystemCall;
21  
22  /** Install an SRPM into a working copy */
23  public class ImportSrpm implements Runnable {
24  	private File baseDir;
25  	private File srpmFile;
26  	private RpmBuildEnvironment rpmBuildEnvironment;
27  
28  	public void run() {
29  		SystemCall rpmQuery = new SystemCall(
30  				"rpm --queryformat '%{NAME}\n' -qp " + srpmFile);
31  		String packageName = rpmQuery.function();
32  
33  		File topdir = new File(baseDir, packageName);
34  
35  		// prepare SVN
36  		// TODO: do it with SVNKit
37  		topdir.mkdirs();
38  		new SystemCall("svn add " + topdir).run();
39  		new SystemCall("svn propset svn:ignore rpm*\nBUILD\nSRPMS\nRPMS " + topdir).run();
40  		File sourcesDir = new File(topdir, "SOURCES");
41  		sourcesDir.mkdirs();
42  		new SystemCall("svn add " + sourcesDir).run();
43  		new SystemCall("svn propset svn:ignore *gz\n*bz2\n*.zip\n*.jar " + sourcesDir).run();
44  		File specsDir = new File(topdir, "SPECS");
45  		specsDir.mkdirs();
46  		new SystemCall("svn add " + specsDir).run();
47  
48  		// Write rpm config files
49  		File rpmmacroFile = new File(topdir, "rpmmacros");
50  		File rpmrcFile = new File(topdir, "rpmrc");
51  		rpmBuildEnvironment.writeRpmbuildConfigFiles(topdir, rpmmacroFile,
52  				rpmrcFile);
53  
54  		// Install SRPM
55  		SystemCall installSrpm = new SystemCall();
56  		installSrpm.arg("rpm");
57  		installSrpm.arg("-Uvh");
58  		installSrpm.arg("--rcfile=" + rpmrcFile.getAbsolutePath());
59  		installSrpm.arg(srpmFile.getAbsolutePath());
60  		installSrpm.setExecDir(topdir.getAbsolutePath());
61  		installSrpm.setLogCommand(true);
62  		installSrpm.run();
63  	}
64  
65  	public void setBaseDir(File basedir) {
66  		this.baseDir = basedir;
67  	}
68  
69  	public void setSrpmFile(File srpmFile) {
70  		this.srpmFile = srpmFile;
71  	}
72  
73  	public void setRpmBuildEnvironment(RpmBuildEnvironment rpmBuildEnvironment) {
74  		this.rpmBuildEnvironment = rpmBuildEnvironment;
75  	}
76  
77  }