package org.argeo.init.osgi; import static java.lang.System.Logger.Level.TRACE; import java.io.File; import java.io.IOException; import java.lang.System.Logger; import java.util.ArrayList; import java.util.List; import java.util.StringTokenizer; /** Intermediary structure used by path matching */ class BundlesSet { private final static Logger logger = System.getLogger(BundlesSet.class.getName()); private String baseUrl = "reference:file";// not used yet private final String dir; private List includes = new ArrayList(); private List excludes = new ArrayList(); public BundlesSet(String def) { StringTokenizer st = new StringTokenizer(def, ";"); if (!st.hasMoreTokens()) throw new RuntimeException("Base dir not defined."); try { String dirPath = st.nextToken(); if (dirPath.startsWith("file:")) dirPath = dirPath.substring("file:".length()); dir = new File(dirPath.replace('/', File.separatorChar)).getCanonicalPath(); logger.log(TRACE, () -> "Base dir: " + dir); } catch (IOException e) { throw new RuntimeException("Cannot convert to absolute path", e); } while (st.hasMoreTokens()) { String tk = st.nextToken(); StringTokenizer stEq = new StringTokenizer(tk, "="); String type = stEq.nextToken(); String pattern = stEq.nextToken(); if ("in".equals(type) || "include".equals(type)) { includes.add(pattern); } else if ("ex".equals(type) || "exclude".equals(type)) { excludes.add(pattern); } else if ("baseUrl".equals(type)) { baseUrl = pattern; } else { System.err.println("Unkown bundles pattern type " + type); } } // if (excludeSvn && !excludes.contains(EXCLUDES_SVN_PATTERN)) { // excludes.add(EXCLUDES_SVN_PATTERN); // } } public String getDir() { return dir; } public List getIncludes() { return includes; } public List getExcludes() { return excludes; } public String getBaseUrl() { return baseUrl; } }