/** * A macro to convert a maven version to an OSGi version */ public String _maven_version(String args[]) { if (args.length > 2) error("${maven_version} macro receives too many arguments " + Arrays.toString(args)); else if (args.length < 2) error("${maven_version} macro has no arguments, use ${maven_version;1.2.3-SNAPSHOT}"); else { return cleanupVersion(args[1]); } return null; }
/** * A macro to convert a maven version to an OSGi version */ public String _maven_version(String args[]) { if (args.length > 2) error("${maven_version} macro receives too many arguments " + Arrays.toString(args)); else if (args.length < 2) error("${maven_version} macro has no arguments, use ${maven_version;1.2.3-SNAPSHOT}"); else { return cleanupVersion(args[1]); } return null; }
private int getSplitStrategy(String type) { if (type == null) return SPLIT_DEFAULT; if (type.equals("merge-last")) return SPLIT_MERGE_LAST; if (type.equals("merge-first")) return SPLIT_MERGE_FIRST; if (type.equals("error")) return SPLIT_ERROR; if (type.equals("first")) return SPLIT_FIRST; error("Invalid strategy for split-package: " + type); return SPLIT_DEFAULT; }
private int getSplitStrategy(String type) { if (type == null) return SPLIT_DEFAULT; if (type.equals("merge-last")) return SPLIT_MERGE_LAST; if (type.equals("merge-first")) return SPLIT_MERGE_FIRST; if (type.equals("error")) return SPLIT_ERROR; if (type.equals("first")) return SPLIT_FIRST; error("Invalid strategy for split-package: " + type); return SPLIT_DEFAULT; }
public Pattern getDoNotCopy() { if (xdoNotCopy == null) { String string = null; try { string = getProperty(DONOTCOPY, DEFAULT_DO_NOT_COPY); xdoNotCopy = Pattern.compile(string); } catch (Exception e) { error("Invalid value for %s, value is %s", DONOTCOPY, string); xdoNotCopy = Pattern.compile(DEFAULT_DO_NOT_COPY); } } return xdoNotCopy; }
private Pattern wildcard(String spec) { StringBuffer sb = new StringBuffer(); for (int j = 0; j < spec.length(); j++) { char c = spec.charAt(j); switch (c) { case '.': sb.append("\\."); break; case '*': // test for ** (all directories) if (j < spec.length() - 1 && spec.charAt(j + 1) == '*') { sb.append(".*"); j++; } else sb.append("[^/]*"); break; default: sb.append(c); break; } } String s = sb.toString(); try { return Pattern.compile(s); } catch (Exception e) { error("Invalid regular expression on wildcarding: " + spec + " used *"); } return null; }
public String _permissions(String args[]) throws IOException { StringBuilder sb = new StringBuilder(); for (String arg : args) { if ("packages".equals(arg) || "all".equals(arg)) { for (String imp : getImports().keySet()) { if (!imp.startsWith("java.")) { sb.append("(org.osgi.framework.PackagePermission \""); sb.append(imp); sb.append("\" \"import\")\r\n"); } } for (String exp : getExports().keySet()) { sb.append("(org.osgi.framework.PackagePermission \""); sb.append(exp); sb.append("\" \"export\")\r\n"); } } else if ("admin".equals(arg) || "all".equals(arg)) { sb.append("(org.osgi.framework.AdminPermission)"); } else if ("permissions".equals(arg)) ; else error("Invalid option in ${permissions}: %s", arg); } return sb.toString(); }
public String _permissions(String args[]) throws IOException { StringBuilder sb = new StringBuilder(); for (String arg : args) { if ("packages".equals(arg) || "all".equals(arg)) { for (String imp : getImports().keySet()) { if (!imp.startsWith("java.")) { sb.append("(org.osgi.framework.PackagePermission \""); sb.append(imp); sb.append("\" \"import\")\r\n"); } } for (String exp : getExports().keySet()) { sb.append("(org.osgi.framework.PackagePermission \""); sb.append(exp); sb.append("\" \"export\")\r\n"); } } else if ("admin".equals(arg) || "all".equals(arg)) { sb.append("(org.osgi.framework.AdminPermission)"); } else if ("permissions".equals(arg)) ; else error("Invalid option in ${permissions}: %s", arg); } return sb.toString(); }
public Collection<File> getSourcePath() { if (firstUse) { firstUse = false; String sp = getProperty(SOURCEPATH); if (sp != null) { Map<String, Map<String, String>> map = parseHeader(sp); for (Iterator<String> i = map.keySet().iterator(); i.hasNext();) { String file = i.next(); if (!isDuplicate(file)) { File f = getFile(file); if (!f.isDirectory()) { error("Adding a sourcepath that is not a directory: " + f); } else { sourcePath.add(f); } } } } } return sourcePath; }
public Collection<File> getSourcePath() { if (firstUse) { firstUse = false; String sp = getProperty(SOURCEPATH); if (sp != null) { Map<String, Map<String, String>> map = parseHeader(sp); for (Iterator<String> i = map.keySet().iterator(); i.hasNext();) { String file = i.next(); if (!isDuplicate(file)) { File f = getFile(file); if (!f.isDirectory()) { error("Adding a sourcepath that is not a directory: " + f); } else { sourcePath.add(f); } } } } } return sourcePath; }
private void copy(Jar jar, String path, File from, boolean preprocess, Map<String, String> extra) throws Exception { if (doNotCopy.matcher(from.getName()).matches()) return; if (from.isDirectory()) { File files[] = from.listFiles(); for (int i = 0; i < files.length; i++) { copy(jar, appendPath(path,files[i].getName()), files[i], preprocess, extra); } } else { if (from.exists()) { Resource resource = new FileResource(from); if (preprocess) { resource = new PreprocessResource(this, resource); } String x = extra.get("extra"); if (x != null) resource.setExtra(x); if (path.endsWith("/")) path = path + from.getName(); jar.putResource(path, resource); } else { error("Input file does not exist: " + from); } } }
/** * Extra resources from a Jar and add them to the given jar. The clause is * the * * @param jar * @param clauses * @param i * @throws ZipException * @throws IOException */ private void extractFromJar(Jar jar, String name) throws ZipException, IOException { // Inline all resources and classes from another jar // optionally appended with a modified regular expression // like @zip.jar!/META-INF/MANIFEST.MF int n = name.lastIndexOf("!/"); Pattern filter = null; if (n > 0) { String fstring = name.substring(n + 2); name = name.substring(0, n); filter = wildcard(fstring); } Jar sub = getJarFromName(name, "extract from jar"); if (sub == null) error("Can not find JAR file " + name); else jar.addAll(sub, filter); }
error("Can not find JAR file " + source); else { jar.addAll(sub, instr, destination);
private void copy(Jar jar, String path, File from, boolean preprocess, Map<String, String> extra) throws Exception { if (doNotCopy(from.getName())) return; if (from.isDirectory()) { File files[] = from.listFiles(); for (int i = 0; i < files.length; i++) { copy(jar, appendPath(path, files[i].getName()), files[i], preprocess, extra); } } else { if (from.exists()) { Resource resource = new FileResource(from); if (preprocess) { resource = new PreprocessResource(this, resource); } String x = extra.get("extra"); if (x != null) resource.setExtra(x); if (path.endsWith("/")) path = path + from.getName(); jar.putResource(path, resource); if (isTrue(extra.get(LIB_DIRECTIVE))) { setProperty(BUNDLE_CLASSPATH, append(getProperty(BUNDLE_CLASSPATH), path)); } } else { error("Input file does not exist: " + from); } } }
private void noSuchFile(Jar jar, String clause, Map<String, String> extra, String source, String destinationPath) throws Exception { Jar src = getJarFromName(source, "Include-Resource " + source); if (src != null) { JarResource jarResource = new JarResource(src); jar.putResource(destinationPath, jarResource); } else { Resource lastChance = make.process(source); if (lastChance != null) { String x = extra.get("extra"); if (x != null) lastChance.setExtra(x); jar.putResource(destinationPath, lastChance); } else error("Input file does not exist: " + source); } }
error("WAB lib does not exist %s", f);
public Resource process(String source) { Map<Instruction, Map<String, String>> make = getMakeHeader(); builder.trace("make " + source); for (Map.Entry<Instruction, Map<String, String>> entry : make .entrySet()) { Instruction instr = entry.getKey(); Matcher m = instr.getMatcher(source); if (m.matches() || instr.isNegated()) { Map<String, String> arguments = replace(m, entry.getValue()); List<MakePlugin> plugins = builder.getPlugins(MakePlugin.class); for (MakePlugin plugin : plugins) { try { Resource resource = plugin.make(builder, source, arguments); if (resource != null) { builder.trace("Made " + source + " from args " + arguments + " with " + plugin); return resource; } } catch (Exception e) { builder.error("Plugin " + plugin + " generates error when use in making " + source + " with args " + arguments, e); } } } } return null; }
private void noSuchFile(Jar jar, String clause, Map<String, String> extra, String source, String destinationPath) throws Exception { Jar src = getJarFromName(source, "Include-Resource " + source); if (src != null) { JarResource jarResource = new JarResource(src); jar.putResource(destinationPath, jarResource); } else { Resource lastChance = make.process(source); if (lastChance != null) { String x = extra.get("extra"); if (x != null) lastChance.setExtra(x); jar.putResource(destinationPath, lastChance); } else error("Input file does not exist: " + source); } }
public Resource process(String source) { Map<Instruction, Map<String, String>> make = getMakeHeader(); builder.trace("make " + source); for (Map.Entry<Instruction, Map<String, String>> entry : make .entrySet()) { Instruction instr = (Instruction) entry.getKey(); Matcher m = instr.getMatcher(source); if (m.matches() || instr.isNegated()) { Map<String, String> arguments = replace(m, entry.getValue()); List<MakePlugin> plugins = builder.getPlugins(MakePlugin.class); for (MakePlugin plugin : plugins) { try { Resource resource = plugin.make(builder, source, arguments); if (resource != null) { builder.trace("Made " + source + " from args " + arguments + " with " + plugin); return resource; } } catch (Exception e) { builder.error("Plugin " + plugin + " generates error when use in making " + source + " with args " + arguments, e); } } } } return null; }
} catch (Exception e) { e.printStackTrace(); error("Sub Building " + builder.getBsn(), e);