use of aQute.bnd.header.Parameters in project bnd by bndtools.
the class CapReqBuilderTest method testAliasedRequirementWithVersion.
public void testAliasedRequirementWithVersion() throws Exception {
Parameters params = OSGiHeader.parseHeader("bnd.identity; id=org.example.foo; version=1.2");
Requirement req = CapReqBuilder.getRequirementsFrom(params).get(0);
assertEquals("osgi.identity", req.getNamespace());
assertEquals("(&(osgi.identity=org.example.foo)(version>=1.2.0))", req.getDirectives().get("filter"));
}
use of aQute.bnd.header.Parameters in project bnd by bndtools.
the class Domain method getIcon.
/**
* Find an icon with the requested size in the list of icons.
*
* @param requestedSize the number of pixels desired
* @return null or a the selected URI (which may be relative)
*/
public String getIcon(int requestedSize) throws Exception {
String spec = get(Constants.BUNDLE_ICON);
if (spec == null)
return null;
Parameters p = OSGiHeader.parseHeader(spec);
int dist = Integer.MAX_VALUE;
String selected = null;
for (Entry<String, Attrs> e : p.entrySet()) {
String url = e.getKey();
if (selected == null)
selected = url;
if (e.getValue() != null) {
String s = e.getValue().get("size");
if (s != null) {
int size = Converter.cnv(Integer.class, s);
if (size != 0 && Math.abs(requestedSize - size) < dist) {
dist = Math.abs(requestedSize - size);
selected = url;
}
}
}
}
return selected;
}
use of aQute.bnd.header.Parameters in project bnd by bndtools.
the class Processor method fixupMessages.
/**
* Move errors and warnings to their proper place by scanning the fixup
* messages property.
*/
private void fixupMessages() {
if (fixupMessages)
return;
fixupMessages = true;
Parameters fixup = getMergedParameters(Constants.FIXUPMESSAGES);
if (fixup.isEmpty())
return;
Instructions instrs = new Instructions(fixup);
doFixup(instrs, errors, warnings, FIXUPMESSAGES_IS_ERROR);
doFixup(instrs, warnings, errors, FIXUPMESSAGES_IS_WARNING);
}
use of aQute.bnd.header.Parameters in project bnd by bndtools.
the class Domain method getPrivatePackage.
public Parameters getPrivatePackage() {
Parameters p = getParameters(PRIVATE_PACKAGE);
p.putAll(getParameters(PRIVATEPACKAGE));
return p;
}
use of aQute.bnd.header.Parameters 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;
}
Aggregations