use of aQute.lib.utf8properties.UTF8Properties in project bnd by bndtools.
the class Macro method getFlattenedProperties.
/**
* Take all the properties and translate them to actual values. This method
* takes the set properties and traverse them over all entries, including
* the default properties for that properties. The values no longer contain
* macros.
* <p>
* Property names starting with an underscore ('_') are ignored. These are
* reserved for properties that cause an unwanted side effect when expanded
* unnecessary
*
* @return A new Properties with the flattened values
*/
public Properties getFlattenedProperties(boolean ignoreInstructions) {
// Some macros only work in a lower processor, so we
// do not report unknown macros while flattening
flattening = true;
try {
Properties flattened = new UTF8Properties();
Properties source = domain.getProperties();
for (Enumeration<?> e = source.propertyNames(); e.hasMoreElements(); ) {
String key = (String) e.nextElement();
if (!key.startsWith("_")) {
String value = source.getProperty(key);
if (value == null) {
Object raw = source.get(key);
domain.warning("Key '%s' has a non-String value: %s:%s", key, raw == null ? "" : raw.getClass().getName(), raw);
} else {
if (ignoreInstructions && key.startsWith("-"))
flattened.put(key, value);
else
flattened.put(key, process(value));
}
}
}
return flattened;
} finally {
flattening = false;
}
}
use of aQute.lib.utf8properties.UTF8Properties in project bnd by bndtools.
the class ProjectLauncherImpl method executable.
/**
* Create a standalone executable. All entries on the runpath are rolled out
* into the JAR and the runbundles are copied to a directory in the jar. The
* launcher will see that it starts in embedded mode and will automatically
* detect that it should load the bundles from inside. This is drive by the
* launcher.embedded flag.
*
* @throws Exception
*/
@Override
public Jar executable() throws Exception {
// TODO use constants in the future
Parameters packageHeader = OSGiHeader.parseHeader(getProject().getProperty("-package"));
boolean useShas = packageHeader.containsKey("jpm");
logger.debug("useShas {} {}", useShas, packageHeader);
Jar jar = new Jar(getProject().getName());
Builder b = new Builder();
getProject().addClose(b);
if (!getProject().getIncludeResource().isEmpty()) {
b.setIncludeResource(getProject().getIncludeResource().toString());
b.setProperty(Constants.RESOURCEONLY, "true");
b.build();
if (b.isOk()) {
jar.addAll(b.getJar());
}
getProject().getInfo(b);
}
List<String> runpath = getRunpath();
Set<String> runpathShas = new LinkedHashSet<String>();
Set<String> runbundleShas = new LinkedHashSet<String>();
List<String> classpath = new ArrayList<String>();
for (String path : runpath) {
logger.debug("embedding runpath {}", path);
File file = new File(path);
if (file.isFile()) {
if (useShas) {
String sha = SHA1.digest(file).asHex();
runpathShas.add(sha + ";name=\"" + file.getName() + "\"");
} else {
String newPath = nonCollidingPath(file, jar);
jar.putResource(newPath, new FileResource(file));
classpath.add(newPath);
}
}
}
// Copy the bundles to the JAR
List<String> runbundles = (List<String>) getRunBundles();
List<String> actualPaths = new ArrayList<String>();
for (String path : runbundles) {
logger.debug("embedding run bundles {}", path);
File file = new File(path);
if (!file.isFile())
getProject().error("Invalid entry in -runbundles %s", file);
else {
if (useShas) {
String sha = SHA1.digest(file).asHex();
runbundleShas.add(sha + ";name=\"" + file.getName() + "\"");
actualPaths.add("${JPMREPO}/" + sha);
} else {
String newPath = nonCollidingPath(file, jar);
jar.putResource(newPath, new FileResource(file));
actualPaths.add(newPath);
}
}
}
LauncherConstants lc = getConstants(actualPaths, true);
lc.embedded = !useShas;
// cannot use local info
lc.storageDir = null;
final Properties p = lc.getProperties(new UTF8Properties());
ByteArrayOutputStream bout = new ByteArrayOutputStream();
p.store(bout, "");
jar.putResource(LauncherConstants.DEFAULT_LAUNCHER_PROPERTIES, new EmbeddedResource(bout.toByteArray(), 0L));
Manifest m = new Manifest();
Attributes main = m.getMainAttributes();
for (Entry<Object, Object> e : getProject().getFlattenedProperties().entrySet()) {
String key = (String) e.getKey();
if (key.length() > 0 && Character.isUpperCase(key.charAt(0)))
main.putValue(key, (String) e.getValue());
}
Instructions instructions = new Instructions(getProject().getProperty(Constants.REMOVEHEADERS));
Collection<Object> result = instructions.select(main.keySet(), false);
main.keySet().removeAll(result);
if (useShas) {
logger.debug("Use JPM launcher");
m.getMainAttributes().putValue("Main-Class", JPM_LAUNCHER_FQN);
m.getMainAttributes().putValue("JPM-Classpath", Processor.join(runpathShas));
m.getMainAttributes().putValue("JPM-Runbundles", Processor.join(runbundleShas));
URLResource jpmLauncher = new URLResource(this.getClass().getResource("/" + JPM_LAUNCHER));
jar.putResource(JPM_LAUNCHER, jpmLauncher);
doStart(jar, JPM_LAUNCHER_FQN);
} else {
logger.debug("Use Embedded launcher");
m.getMainAttributes().putValue("Main-Class", EMBEDDED_LAUNCHER_FQN);
m.getMainAttributes().putValue(EmbeddedLauncher.EMBEDDED_RUNPATH, Processor.join(classpath));
URLResource embeddedLauncher = new URLResource(this.getClass().getResource("/" + EMBEDDED_LAUNCHER));
jar.putResource(EMBEDDED_LAUNCHER, embeddedLauncher);
doStart(jar, EMBEDDED_LAUNCHER_FQN);
}
if (getProject().getProperty(Constants.DIGESTS) != null)
jar.setDigestAlgorithms(getProject().getProperty(Constants.DIGESTS).trim().split("\\s*,\\s*"));
else
jar.setDigestAlgorithms(new String[] { "SHA-1", "MD-5" });
jar.setManifest(m);
cleanup();
return jar;
}
use of aQute.lib.utf8properties.UTF8Properties in project bnd by bndtools.
the class TestWrapper method augmentTest.
private void augmentTest(InfoRepository repo) throws Exception, IOException {
assertNotNull(repo.get("biz.aQute.jpm.daemon", new Version("1.1.0"), null));
InfoRepositoryWrapper iw = new InfoRepositoryWrapper(tmp, Collections.singleton(repo));
Properties augments = new UTF8Properties();
augments.load(new StringReader("biz.aQute.jpm.daemon: cap=test;test=1\n"));
iw.addAugment(augments);
//
// Get the test and identity capability
//
Requirement testreq = new CapReqBuilder("test").filter("(test=1)").buildSyntheticRequirement();
Requirement identity = new CapReqBuilder("osgi.identity").filter("(osgi.identity=biz.aQute.jpm.daemon)").buildSyntheticRequirement();
Map<Requirement, Collection<Capability>> result = iw.findProviders(Arrays.asList(testreq, identity));
assertNotNull(result);
assertEquals(2, result.size());
//
// Test if they come from the same resource
//
Capability testcap = result.get(testreq).iterator().next();
Capability identitycap = result.get(identity).iterator().next();
assertNotNull(testcap);
assertNotNull(identitycap);
assertEquals(testcap.getResource(), identitycap.getResource());
iw.close();
}
use of aQute.lib.utf8properties.UTF8Properties in project bnd by bndtools.
the class ProjectLauncherImpl method invoke.
//
// Initialize the main class for a local launch start
//
protected int invoke(Class<?> main, String[] args) throws Exception {
LauncherConstants lc = getConstants(getRunBundles(), false);
Method mainMethod = main.getMethod("main", args.getClass(), Properties.class);
Object o = mainMethod.invoke(null, args, lc.getProperties(new UTF8Properties()));
if (o == null)
return 0;
return (Integer) o;
}
use of aQute.lib.utf8properties.UTF8Properties in project bnd by bndtools.
the class MavenCommand method javadoc.
private Jar javadoc(File source, Set<String> exports, Manifest m, Properties p) throws Exception {
File tmp = new File(temp, "javadoc");
IO.mkdirs(tmp);
Command command = new Command();
command.add(getProperty("javadoc", "javadoc"));
command.add("-quiet");
command.add("-protected");
// command.add("-classpath");
// command.add(binary.getAbsolutePath());
command.add("-d");
command.add(tmp.getAbsolutePath());
command.add("-charset");
command.add("UTF-8");
command.add("-sourcepath");
command.add(source.getAbsolutePath());
Attributes attr = m.getMainAttributes();
Properties pp = new UTF8Properties(p);
set(pp, "-doctitle", description(attr));
set(pp, "-header", description(attr));
set(pp, "-windowtitle", name(attr));
set(pp, "-bottom", copyright(attr));
set(pp, "-footer", license(attr));
command.add("-tag");
command.add("Immutable:t:Immutable");
command.add("-tag");
command.add("ThreadSafe:t:ThreadSafe");
command.add("-tag");
command.add("NotThreadSafe:t:NotThreadSafe");
command.add("-tag");
command.add("GuardedBy:mf:Guarded By:");
command.add("-tag");
command.add("security:m:Required Permissions");
command.add("-tag");
command.add("noimplement:t:Consumers of this API must not implement this interface");
for (Enumeration<?> e = pp.propertyNames(); e.hasMoreElements(); ) {
String key = (String) e.nextElement();
String value = pp.getProperty(key);
if (key.startsWith("javadoc")) {
key = key.substring("javadoc".length());
removeDuplicateMarker(key);
command.add(key);
command.add(value);
}
}
for (String packageName : exports) {
command.add(packageName);
}
StringBuilder out = new StringBuilder();
StringBuilder err = new StringBuilder();
System.err.println(command);
int result = command.execute(out, err);
if (result != 0) {
warning("Error during execution of javadoc command: %s\n******************\n%s", out, err);
}
Jar jar = new Jar(tmp);
addClose(jar);
return jar;
}
Aggregations