View Javadoc
1   package org.argeo.osgi.boot;
2   
3   import java.io.File;
4   import java.io.IOException;
5   import java.util.ArrayList;
6   import java.util.List;
7   import java.util.StringTokenizer;
8   
9   /** Intermediary structure used by path matching */
10  class BundlesSet {
11  	private String baseUrl = "reference:file";// not used yet
12  	private final String dir;
13  	private List<String> includes = new ArrayList<String>();
14  	private List<String> excludes = new ArrayList<String>();
15  
16  	public BundlesSet(String def) {
17  		StringTokenizer st = new StringTokenizer(def, ";");
18  
19  		if (!st.hasMoreTokens())
20  			throw new RuntimeException("Base dir not defined.");
21  		try {
22  			String dirPath = st.nextToken();
23  
24  			if (dirPath.startsWith("file:"))
25  				dirPath = dirPath.substring("file:".length());
26  
27  			dir = new File(dirPath.replace('/', File.separatorChar)).getCanonicalPath();
28  			if (OsgiBootUtils.debug)
29  				OsgiBootUtils.debug("Base dir: " + dir);
30  		} catch (IOException e) {
31  			throw new RuntimeException("Cannot convert to absolute path", e);
32  		}
33  
34  		while (st.hasMoreTokens()) {
35  			String tk = st.nextToken();
36  			StringTokenizer stEq = new StringTokenizer(tk, "=");
37  			String type = stEq.nextToken();
38  			String pattern = stEq.nextToken();
39  			if ("in".equals(type) || "include".equals(type)) {
40  				includes.add(pattern);
41  			} else if ("ex".equals(type) || "exclude".equals(type)) {
42  				excludes.add(pattern);
43  			} else if ("baseUrl".equals(type)) {
44  				baseUrl = pattern;
45  			} else {
46  				System.err.println("Unkown bundles pattern type " + type);
47  			}
48  		}
49  
50  		// if (excludeSvn && !excludes.contains(EXCLUDES_SVN_PATTERN)) {
51  		// excludes.add(EXCLUDES_SVN_PATTERN);
52  		// }
53  	}
54  
55  	public String getDir() {
56  		return dir;
57  	}
58  
59  	public List<String> getIncludes() {
60  		return includes;
61  	}
62  
63  	public List<String> getExcludes() {
64  		return excludes;
65  	}
66  
67  	public String getBaseUrl() {
68  		return baseUrl;
69  	}
70  
71  }