use of aQute.lib.utf8properties.UTF8Properties in project bnd by bndtools.
the class Analyzer method getManifest.
/**
* Specifically for Maven
*
*/
public static Properties getManifest(File dirOrJar) throws Exception {
try (Analyzer analyzer = new Analyzer()) {
analyzer.setJar(dirOrJar);
Properties properties = new UTF8Properties();
properties.put(IMPORT_PACKAGE, "*");
properties.put(EXPORT_PACKAGE, "*");
analyzer.setProperties(properties);
Manifest m = analyzer.calcManifest();
Properties result = new UTF8Properties();
for (Iterator<Object> i = m.getMainAttributes().keySet().iterator(); i.hasNext(); ) {
Attributes.Name name = (Attributes.Name) i.next();
result.put(name.toString(), m.getMainAttributes().getValue(name));
}
return result;
}
}
use of aQute.lib.utf8properties.UTF8Properties in project bnd by bndtools.
the class PomParser method getProperties.
public Properties getProperties(File pom) throws Exception {
DocumentBuilder db = dbf.newDocumentBuilder();
XPath xpath = xpathf.newXPath();
pom = pom.getAbsoluteFile();
Document doc = db.parse(pom);
Properties p = new UTF8Properties();
// Check if there is a parent pom
String relativePath = xpath.evaluate("project/parent/relativePath", doc);
if (relativePath != null && relativePath.length() != 0) {
File parentPom = IO.getFile(pom.getParentFile(), relativePath);
if (parentPom.isFile()) {
Properties parentProps = getProperties(parentPom);
p.putAll(parentProps);
} else {
error("Parent pom for %s is not an existing file (could be directory): %s", pom, parentPom);
}
}
Element e = doc.getDocumentElement();
traverse("pom", e, p);
String[] scopes = { "provided", "runtime", "test", "system" };
NodeList set = (NodeList) xpath.evaluate("//dependency[not(scope) or scope='compile']", doc, XPathConstants.NODESET);
if (set.getLength() != 0)
p.put("pom.scope.compile", toBsn(set));
for (String scope : scopes) {
set = (NodeList) xpath.evaluate("//dependency[scope='" + scope + "']", doc, XPathConstants.NODESET);
if (set.getLength() != 0)
p.put("pom.scope." + scope, toBsn(set));
}
return p;
}
use of aQute.lib.utf8properties.UTF8Properties in project bnd by bndtools.
the class HttpBasicAuthURLConnector method init.
protected void init() {
if (inited.compareAndSet(false, true)) {
mappings.clear();
StringTokenizer tokenizer = new StringTokenizer(configFileList, ",");
while (tokenizer.hasMoreTokens()) {
String configFileName = tokenizer.nextToken().trim();
File file = new File(configFileName);
if (file.exists()) {
Properties props = new UTF8Properties();
try (InputStream stream = IO.stream(file)) {
props.load(stream);
for (Object key : props.keySet()) {
String name = (String) key;
if (name.startsWith(PREFIX_PATTERN)) {
String id = name.substring(PREFIX_PATTERN.length());
Glob glob = new Glob(props.getProperty(name));
String uid = props.getProperty(PREFIX_USER + id);
String pwd = props.getProperty(PREFIX_PASSWORD + id);
mappings.add(new Mapping(id, glob, uid, pwd));
}
}
} catch (IOException e) {
if (reporter != null)
reporter.error("Failed to load %s", configFileName);
}
}
}
}
}
use of aQute.lib.utf8properties.UTF8Properties in project bnd by bndtools.
the class BndrunResolveContext method findAdditionalAugmentsFromResource.
private void findAdditionalAugmentsFromResource(Processor augments, Capability capability) {
Resource resource = capability.getResource();
Map<URI, String> locations = ResourceUtils.getLocations(resource);
if (locations == null || locations.isEmpty())
return;
Object pathObject = capability.getAttributes().get("path");
if (pathObject == null)
pathObject = "augments.bnd";
if (pathObject instanceof String) {
String path = (String) pathObject;
HttpClient http = registry.getPlugin(HttpClient.class);
for (URI uri : locations.keySet()) try {
logger.debug("loading augments from {}", uri);
File file = http.build().age(24, TimeUnit.HOURS).useCache().go(uri);
try (Jar jar = new Jar(file)) {
aQute.bnd.osgi.Resource rs = jar.getResource(path);
try (InputStream in = rs.openInputStream()) {
UTF8Properties p = new UTF8Properties();
p.load(in, file, project);
augments.getProperties().putAll(p);
return;
}
}
} catch (Exception e) {
project.warning("Failed to handle augment resource from repo %s", uri);
}
}
}
use of aQute.lib.utf8properties.UTF8Properties in project bnd by bndtools.
the class BndMavenPlugin method loadProjectProperties.
private File loadProjectProperties(Builder builder, MavenProject project) throws Exception {
// Load parent project properties first
MavenProject parentProject = project.getParent();
if (parentProject != null) {
loadProjectProperties(builder, parentProject);
}
// Merge in current project properties
Xpp3Dom configuration = project.getGoalConfiguration("biz.aQute.bnd", "bnd-maven-plugin", mojoExecution.getExecutionId(), mojoExecution.getGoal());
File baseDir = project.getBasedir();
if (baseDir != null) {
// file system based pom
File pomFile = project.getFile();
builder.updateModified(pomFile.lastModified(), "POM: " + pomFile);
// check for bnd file
String bndFileName = Project.BNDFILE;
if (configuration != null) {
Xpp3Dom bndfileElement = configuration.getChild("bndfile");
if (bndfileElement != null) {
bndFileName = bndfileElement.getValue();
}
}
File bndFile = IO.getFile(baseDir, bndFileName);
if (bndFile.isFile()) {
logger.debug("loading bnd properties from file: {}", bndFile);
// we use setProperties to handle -include
builder.setProperties(bndFile.getParentFile(), builder.loadProperties(bndFile));
return bndFile;
}
// no bnd file found, so we fall through
}
// check for bnd-in-pom configuration
if (configuration != null) {
Xpp3Dom bndElement = configuration.getChild("bnd");
if (bndElement != null) {
logger.debug("loading bnd properties from bnd element in pom: {}", project);
UTF8Properties properties = new UTF8Properties();
properties.load(bndElement.getValue(), project.getFile(), builder);
if (baseDir != null) {
String here = baseDir.toURI().getPath();
here = Matcher.quoteReplacement(here.substring(0, here.length() - 1));
properties = properties.replaceAll("\\$\\{\\.\\}", here);
}
// we use setProperties to handle -include
builder.setProperties(baseDir, properties);
}
}
return project.getFile();
}
Aggregations