private PomResource createPomFromContextAndManifest(Manifest manifest, Processor context) throws Exception { try (Processor scoped = context == null ? new Processor() : new Processor(context)) { if (scoped.getProperty(Constants.GROUPID) == null) scoped.setProperty(Constants.GROUPID, "osgi-bundle"); return new PomResource(scoped, manifest); } }
@Override public void close() throws IOException { try { reader.close(); } catch (XMLStreamException e) { throw new IOException(e); } finally { super.close(); } }
public void mergeProperties(Properties properties, boolean override) { for (Enumeration< ? > e = properties.propertyNames(); e.hasMoreElements();) { String key = (String) e.nextElement(); String value = properties.getProperty(key); if (override || !getProperties().containsKey(key)) setProperty(key, value); } }
/** * If strict is true, then extra verification is done. */ boolean isStrict() { if (strict == null) strict = isTrue(getProperty(STRICT)); // Used in property access return strict; }
public String mergeLocalProperties(String key) { if (since(About._3_3)) { return getProperty(makeWildcard(key), null, ",", false); } else return mergeProperties(key); }
private static Processor asProcessor(Map<String, String> b) { Processor p = new Processor(); p.addProperties(b); return p; }
public String _range(String args[]) { verifyCommand(args, _rangeHelp, _rangePattern, 2, 3); Version version = null; if (args.length >= 3) { String string = args[2]; if (isLocalTarget(string)) return LITERALVALUE; String v = domain.getProperty("@"); if (v == null) return LITERALVALUE; Matcher m = RANGE_MASK.matcher(spec); m.matches(); String floor = m.group(1); String floorMask = m.group(2); String ceilingMask = m.group(3); String ceiling = m.group(4); String left = version(version, floorMask); String right = version(version, ceilingMask); StringBuilder sb = new StringBuilder(); VersionRange vr = new VersionRange(s); if (!(vr.includes(vr.getHigh()) || vr.includes(vr.getLow()))) { domain.error("${range} macro created an invalid range %s from %s and mask %s", s, version, spec);
public boolean since(Version introduced) { if (upto == null) { String uptov = getProperty(UPTO); if (uptov == null) { upto = Version.HIGHEST; return true; } if (!Version.VERSION.matcher(uptov) .matches()) { error("The %s given version is not a version: %s", UPTO, uptov); upto = Version.HIGHEST; return true; } upto = new Version(uptov); } return upto.compareTo(introduced) >= 0; }
void find(List<String> bsns, Pattern pattern, File base, String name) { if (base.isDirectory()) { String list[] = base.list(); boolean found = false; for (String entry : list) { char c = entry.charAt(0); if (c >= '0' && c <= '9') { if (pattern.matcher(name).matches()) found = true; } else { String nextName = entry; if (name.length() != 0) nextName = name + "." + entry; File next = Processor.getFile(base, entry); find(bsns, pattern, next, nextName); } } if (found) bsns.add(name); } }
private void copy(File workspaceDir, InputStream in, Pattern glob, boolean overwrite) throws Exception { Jar jar = new Jar("dot", in); try { for (Entry<String,Resource> e : jar.getResources().entrySet()) { String path = e.getKey(); bnd.trace("path %s", path); if (glob != null && !glob.matcher(path).matches()) continue; Resource r = e.getValue(); File dest = Processor.getFile(workspaceDir, path); if (overwrite || !dest.isFile() || dest.lastModified() < r.lastModified() || r.lastModified() <= 0) { bnd.trace("copy %s to %s", path, dest); File dp = dest.getParentFile(); if (!dp.exists() && !dp.mkdirs()) { throw new IOException("Could not create directory " + dp); } IO.copy(r.openInputStream(), dest); } } } finally { jar.close(); } }
protected Properties buildProperties(Processor processor, File propertiesFile, File ... extraFiles) throws IOException { Properties properties = new Properties(); for (File extraFile : extraFiles) { properties.putAll(processor.loadProperties(extraFile)); } if (propertiesFile != null) { properties.putAll(processor.loadProperties(propertiesFile)); } return properties; }
/** * Get a property without preprocessing it with a proper default * * @param headerName * @param deflt * @return */ public String getUnprocessedProperty(String key, String deflt) { return getProperties().getProperty(key, deflt); }
/** * Get a property without preprocessing it with a proper default * * @param key * @param deflt */ public String getUnprocessedProperty(String key, String deflt) { if (filter != null && filter.contains(key)) { return (String) getProperties().getOrDefault(key, deflt); } return getProperties().getProperty(key, deflt); }
public void setProperties(Properties properties) { doIncludes(getBase(), properties); getProperties0().putAll(properties); mergeProperties(Constants.INIT); // execute macros in -init getProperties0().remove(Constants.INIT); }
private String doCommands(String key, Link source) { String[] args = commands.split(key); if (args == null || args.length == 0) return null; for (int i = 0; i < args.length; i++) if (args[i].indexOf('\\') >= 0) args[i] = args[i].replaceAll("\\\\;", ";"); if (args[0].startsWith("^")) { String varname = args[0].substring(1).trim(); Processor parent = source.start.getParent(); if (parent != null) return parent.getProperty(varname); return null; } Processor rover = domain; while (rover != null) { String result = doCommand(rover, args[0], args); if (result != null) return result; rover = rover.getParent(); } for (int i = 0; targets != null && i < targets.length; i++) { String result = doCommand(targets[i], args[0], args); if (result != null) return result; } return doCommand(this, args[0], args); }
private void install(File f, RepositoryPlugin repo, Attrs value) throws Exception { try (Processor p = new Processor()) { p.getProperties() .putAll(value); PutOptions options = new PutOptions(); options.context = p; try (InputStream in = IO.stream(f)) { repo.put(in, options); } catch (Exception e) { exception(e, "Cannot install %s into %s because %s", f, repo.getName(), e); } } }
out.printf("Current directory : %s%n", new File("").getAbsolutePath()); out.println("Classpath used"); for (Jar jar : getClasspath()) { out.printf("File : %s%n", jar.getSource()); out.printf("File abs path : %s%n", jar.getSource() .getAbsolutePath()); out.printf("Name : %s%n", jar.getName()); Map<String, Map<String, Resource>> dirs = jar.getDirectories(); for (Map.Entry<String, Map<String, Resource>> entry : dirs.entrySet()) { super.close();
private void add(String name, String value) { if (value == null) return; Processor next = new Processor(analyzer); next.setProperty("@class", current.getFQN()); next.setProperty("@class-short", current.getClassName().getShortName()); PackageRef pref = current.getClassName().getPackageRef(); next.setProperty("@package", pref.getFQN()); Attrs info = analyzer.getClasspathExports().get(pref); if (info == null) info = analyzer.getContained().get(pref); if (info != null && info.containsKey("version")) { next.setProperty("@version", info.get("version")); } Macro macro = next.getReplacer(); /* * These strings come from code, which might also be included from * external parties. So we just do not want to call any system commands * from these sources */ boolean prev = macro.setNosystem(true); try { value = macro.process(value); headers.add(name, value); next.close(); } finally { macro.setNosystem(prev); } }
String bpHeader = analyzer.getProperty( "Service-Component" ); Map<String, ? extends Map<String, String>> map = Processor.parseHeader( bpHeader, null ); for ( String root : map.keySet() ) Resource resource = analyzer.getJar().getResource(root); if ( resource != null ) { process(analyzer, root, resource, headers); if ( idx < 0 ) analyzer.warning( ( new StringBuilder( "Error analyzing services in scr resource: " ) ).append( str ).toString() ); continue;
void doPom(Jar dot) throws Exception, IOException { try (Processor scoped = new Processor(this)) { String bsn = getBsn(); if (bsn != null) scoped.setProperty("@bsn", bsn); String version = getBundleVersion(); if (version != null) scoped.setProperty("@version", version); String pom = scoped.getProperty(POM); if (pom != null && !pom.equalsIgnoreCase("false")) { dot.removePrefix("META-INF/maven/"); scoped.addProperties(OSGiHeader.parseProperties(pom)); PomResource pomXml = new PomResource(scoped, dot.getManifest()); String v = pomXml.validate(); if (v != null) { error("Invalid pom for %s: %s", getBundleSymbolicName(), v); } PomPropertiesResource pomProperties = new PomPropertiesResource(pomXml); dot.putResource(pomXml.getWhere(), pomXml); if (!pomProperties.getWhere() .equals(pomXml.getWhere())) { dot.putResource(pomProperties.getWhere(), pomProperties); } } } }