PageRenderTime 314ms CodeModel.GetById 181ms app.highlight 4ms RepoModel.GetById 127ms app.codeStats 0ms

/src/org/ooc/frontend/pkgconfig/PkgConfigFrontend.java

http://github.com/nddrylliog/ooc
Java | 51 lines | 29 code | 11 blank | 11 comment | 6 complexity | 3bd65175fe9dd6920ef284f680de3175 MD5 | raw file
 1package org.ooc.frontend.pkgconfig;
 2
 3import java.io.File;
 4import java.util.HashMap;
 5import java.util.Map;
 6
 7import org.ooc.utils.ShellUtils;
 8import org.ubi.CompilationFailedError;
 9
10/**
11 * A frontend to pkgconfig, to retrieve information for packages,
12 * like gtk+-2.0, gtkgl-2.0, or imlib2
13 * 
14 * @author Amos Wenger
15 */
16public class PkgConfigFrontend {
17
18	protected static Map<String, PkgInfo> cache = new HashMap<String, PkgInfo>();
19	
20	/**
21	 * 
22	 * @param pkgName
23	 * @return the information concerning a package managed by pkg-manager
24	 */
25	public static PkgInfo getInfo(String pkgName) {
26		
27		PkgInfo cached = cache.get(pkgName);
28		if(cached != null) {
29			return cached;
30		}
31		
32		File path = ShellUtils.findExecutable("pkg-config");
33		if(path == null) {
34			throw new Error("Error! the 'pkg-config' tool, necessary to resolve package '"
35					+pkgName+"' couldn't be find in the $PATH, which is "+System.getenv("PATH"));
36		}
37		String libs = ShellUtils.getOutput(path.getPath(), "--libs", pkgName);
38		String cflags = ShellUtils.getOutput(path.getPath(), "--cflags", pkgName);
39		
40		if(libs == null) {
41			throw new CompilationFailedError(null, "Can't find package '"+pkgName
42					+"' in PKG_CONFIG_PATH. Have you configured pkg-config correctly?");
43		}
44		
45		PkgInfo pkgInfo = new PkgInfo(pkgName, libs, cflags);
46		cache.put(pkgName, pkgInfo);
47		return pkgInfo;
48		
49	}
50	
51}