use of aQute.lib.settings.Settings in project bnd by bndtools.
the class Repository method setOptions.
public void setOptions(Options options) {
try {
location = options.location();
if (location == null)
location = "~/.bnd/shacache";
this.name = options.name();
if (options.settings() != null) {
settings = new Settings(options.settings());
}
email = options.email();
if (email == null)
email = settings.getEmail();
url = options.url();
if (url == null)
url = new URI(REPO_DEFAULT_URI);
cacheDir = IO.getFile(IO.home, location);
IO.mkdirs(cacheDir);
if (!cacheDir.isDirectory())
throw new IllegalArgumentException("Not able to create cache directory " + cacheDir);
String indexPath = options.index();
if (indexPath == null)
throw new IllegalArgumentException("Index file not set (index) ");
indexFile = IO.getFile(indexPath);
if (indexFile.isDirectory())
throw new IllegalArgumentException("Index file is a directory instead of a file " + indexFile.getAbsolutePath());
indexRecurse = options.recurse();
if (options.index() == null)
throw new IllegalArgumentException("Index file not set");
canwrite = false;
if (options.depository_group() != null) {
depositoryGroup = options.depository_group();
depositoryName = options.depository_name();
if (depositoryName == null)
depositoryName = "home";
canwrite = email != null;
}
crawl = options.crawl();
} catch (Exception e) {
if (reporter != null)
reporter.exception(e, "Creating options");
throw Exceptions.duck(e);
}
}
use of aQute.lib.settings.Settings in project bnd by bndtools.
the class bnd method _settings.
@Description("Set bnd/jpm global variables")
public void _settings(settingOptions opts) throws Exception {
try {
Settings settings = this.settings;
char[] password = this.password;
if (opts.location() != null) {
password = opts.password();
File f = getFile(opts.location());
settings = new Settings(f.getAbsolutePath());
settings.load(password);
logger.debug("getting settings from {}", f);
}
if (opts.clear()) {
settings.clear();
logger.debug("clear {}", settings.entrySet());
}
if (opts.generate()) {
logger.debug("Generating new key pair");
settings.generate(password);
}
logger.debug("settings {}", opts.clear());
List<String> rest = opts._arguments();
if (opts.publicKey()) {
out.println(tos(!opts.base64(), settings.getPublicKey()));
}
if (opts.secretKey()) {
out.println(tos(!opts.base64(), settings.getPrivateKey()));
}
if (opts.mac()) {
for (String s : rest) {
byte[] data = s.getBytes(UTF_8);
byte[] signature = settings.sign(data);
out.printf("%s\n", tos(!opts.base64(), signature));
}
}
if (rest.isEmpty()) {
list(null, settings);
} else {
boolean set = false;
for (String s : rest) {
s = s.trim();
Matcher m = ASSIGNMENT.matcher(s);
logger.debug("try {}", s);
if (m.matches()) {
String key = m.group(1);
Instructions instr = new Instructions(key);
Collection<String> select = instr.select(settings.keySet(), true);
// check if there is a value a='b'
String value = m.group(4);
if (value == null || value.trim().length() == 0) {
// check '=' presence
if (m.group(2) == null) {
list(select, settings);
} else {
// we have 'a=', remove
for (String k : select) {
logger.debug("remove {}={}", k, settings.get(k));
settings.remove(k);
set = true;
}
}
} else {
logger.debug("assignment {}={}", key, value);
settings.put(key, value);
set = true;
}
} else {
err.printf("Cannot assign %s\n", s);
}
}
if (set) {
logger.debug("saving");
settings.save(password);
}
}
} catch (Exception e) {
e.printStackTrace();
}
}
use of aQute.lib.settings.Settings in project bnd by bndtools.
the class Main method _jpm.
/**
* Initialize the repository and other global vars.
*
* @param opts the options
* @throws IOException
*/
@Description("Just Another Package Manager for Java (\"jpm help jpm\" to see a list of global options)")
public void _jpm(JpmOptions opts) throws IOException {
try {
setExceptions(opts.exceptions());
setTrace(opts.trace());
setPedantic(opts.pedantic());
Platform platform = Platform.getPlatform(this, opts.os());
if (opts.base() != null)
base = IO.getFile(base, opts.base());
if (opts.settings() != null) {
settings = new Settings(opts.settings());
logger.debug("Using settings file: {}", opts.settings());
} else {
settings = new Settings(platform.getConfigFile());
logger.debug("Using settings file: {}", platform.getConfigFile());
}
File homeDir;
File binDir;
String home = settings.get(JPM_CONFIG_HOME);
String bin = settings.get(JPM_CONFIG_BIN);
if (opts.home() != null) {
logger.debug("home set");
homeDir = IO.getFile(base, opts.home());
binDir = new File(homeDir, "bin");
} else if (opts.user()) {
logger.debug("user set");
homeDir = platform.getLocal();
binDir = new File(homeDir, "bin");
} else if (!opts.global() && home != null) {
logger.debug("global or in settings");
homeDir = new File(home);
binDir = new File(bin);
} else {
logger.debug("default");
homeDir = platform.getGlobal();
binDir = platform.getGlobalBinDir();
}
logger.debug("home={}, bin={}", homeDir, binDir);
if (opts.bindir() != null) {
logger.debug("bindir set");
binDir = new File(opts.bindir());
if (!binDir.isAbsolute())
binDir = new File(base, opts.bindir());
binDir = binDir.getAbsoluteFile();
} else if (bin != null && !opts.user() && !opts.global()) {
binDir = new File(bin);
}
logger.debug("home={}, bin={}", homeDir, binDir);
url = opts.library();
if (url == null)
url = settings.get("library.url");
jpm = new JustAnotherPackageManager(this, platform, homeDir, binDir);
platform.setJpm(jpm);
jpm.setLibrary(url == null ? null : new URI(url));
try {
this.options = opts;
if (opts.xtesting())
jpm.setUnderTest();
CommandLine handler = opts._command();
List<String> arguments = opts._arguments();
if (arguments.isEmpty()) {
Justif j = new Justif();
Formatter f = j.formatter();
handler.help(f, this);
err.println(j.wrap());
} else {
String cmd = arguments.remove(0);
String help = handler.execute(this, cmd, arguments);
if (help != null) {
err.println(help);
}
}
if (options.width() > 0)
this.width = options.width();
} finally {
jpm.close();
}
} catch (InvocationTargetException t) {
Throwable tt = t;
while (tt instanceof InvocationTargetException) tt = ((InvocationTargetException) tt).getTargetException();
exception(tt, "%s", tt);
} catch (Throwable t) {
exception(t, "Failed %s", t);
} finally {
// Check if we need to wait for it to finish
if (opts.key()) {
System.out.println("Hit a key to continue ...");
System.in.read();
}
}
if (!check(opts.failok())) {
System.exit(getErrors().size());
}
}
use of aQute.lib.settings.Settings in project bnd by bndtools.
the class BndAuthentication method setProperties.
@Override
public void setProperties(Map<String, String> map) throws Exception {
super.setProperties(map);
String email = map.get(EMAIL);
if (email == null) {
Workspace ws = registry.getPlugin(Workspace.class);
Settings settings = registry.getPlugin(Settings.class);
email = settings.getEmail();
if (email == null) {
error("The bnd authentication URL connection handler has no email set as property, nor have the bnd settings been set");
return;
}
credentials(email, settings.getPublicKey(), settings.getPrivateKey());
} else {
String pub = map.get(PUBLIC_KEY);
String prv = map.get(PRIVATE_KEY);
if (pub == null || !Hex.isHex(pub)) {
error("The bnd authentication URL public key for email %s is not a hex string %s", email, pub);
return;
}
if (prv == null || !Hex.isHex(prv)) {
error("The bnd authentication URL private key for email %s is not a hex string", email);
return;
}
credentials(email, Hex.toByteArray(pub), Hex.toByteArray(prv));
}
machine = map.get(MACHINE);
}
use of aQute.lib.settings.Settings in project bnd by bndtools.
the class JustAnotherPackageManager method deinit.
public void deinit(Appendable out, boolean force) throws Exception {
Settings settings = new Settings(platform.getConfigFile());
if (!force) {
Justif justify = new Justif(80, 40);
StringBuilder sb = new StringBuilder();
try (Formatter f = new Formatter(sb)) {
String list = listFiles(platform.getGlobal());
if (list != null) {
f.format("In global default environment:%n");
f.format(list);
}
list = listFiles(platform.getLocal());
if (list != null) {
f.format("In local default environment:%n");
f.format(list);
}
if (settings.containsKey(JPM_CACHE_GLOBAL)) {
list = listFiles(IO.getFile(settings.get(JPM_CACHE_GLOBAL)));
if (list != null) {
f.format("In global configured environment:%n");
f.format(list);
}
}
if (settings.containsKey(JPM_CACHE_LOCAL)) {
list = listFiles(IO.getFile(settings.get(JPM_CACHE_LOCAL)));
if (list != null) {
f.format("In local configured environment:%n");
f.format(list);
}
}
list = listSupportFiles();
if (list != null) {
f.format("jpm support files:%n");
f.format(list);
}
f.format("%n%n");
f.format("All files listed above will be deleted if deinit is run with the force flag set" + " (\"jpm deinit -f\" or \"jpm deinit --force\"%n%n");
f.flush();
justify.wrap(sb);
out.append(sb.toString());
}
} else {
// i.e. if(force)
int count = 0;
File[] caches = { platform.getGlobal(), platform.getLocal(), null, null };
if (settings.containsKey(JPM_CACHE_LOCAL)) {
caches[2] = IO.getFile(settings.get(JPM_CACHE_LOCAL));
}
if (settings.containsKey(JPM_CACHE_GLOBAL)) {
caches[3] = IO.getFile(settings.get(JPM_CACHE_GLOBAL));
}
ArrayList<File> toDelete = new ArrayList<File>();
for (File cache : caches) {
if (cache == null || !cache.exists()) {
continue;
}
listFiles(cache, toDelete);
if (toDelete.size() > count) {
count = toDelete.size();
if (!cache.canWrite()) {
reporter.error(PERMISSION_ERROR + " (%s)", cache);
return;
}
toDelete.add(cache);
}
}
listSupportFiles(toDelete);
for (File f : toDelete) {
if (f.exists() && !f.canWrite()) {
reporter.error(PERMISSION_ERROR + " (%s)", f);
}
}
if (reporter.getErrors().size() > 0) {
return;
}
for (File f : toDelete) {
if (f.exists()) {
IO.deleteWithException(f);
}
}
}
}
Aggregations