use of aQute.libg.tuple.Pair in project bnd by bndtools.
the class Analyzer method divideRegularAndDynamicImports.
Pair<Packages, Parameters> divideRegularAndDynamicImports() {
Packages regularImports = new Packages(imports);
Parameters dynamicImports = getDynamicImportPackage();
Iterator<Entry<PackageRef, Attrs>> regularImportsIterator = regularImports.entrySet().iterator();
while (regularImportsIterator.hasNext()) {
Entry<PackageRef, Attrs> packageEntry = regularImportsIterator.next();
PackageRef packageRef = packageEntry.getKey();
Attrs attrs = packageEntry.getValue();
String resolution = attrs.get(Constants.RESOLUTION_DIRECTIVE);
if (Constants.RESOLUTION_DYNAMIC.equals(resolution)) {
attrs.remove(Constants.RESOLUTION_DIRECTIVE);
dynamicImports.put(packageRef.fqn, attrs);
regularImportsIterator.remove();
}
}
return new Pair<>(regularImports, dynamicImports);
}
use of aQute.libg.tuple.Pair in project bnd by bndtools.
the class Project method getBundlesWildcard.
/**
* Get all bundles matching a wildcard expression.
*
* @param bsnPattern A bsn wildcard, e.g. "osgi*" or just "*".
* @param range A range to narrow the versions of bundles found, or null to
* return any version.
* @param strategyx The version selection strategy, which may be 'HIGHEST'
* or 'LOWEST' only -- 'EXACT' is not permitted.
* @param attrs Additional search attributes.
* @throws Exception
*/
public List<Container> getBundlesWildcard(String bsnPattern, String range, Strategy strategyx, Map<String, String> attrs) throws Exception {
if (VERSION_ATTR_SNAPSHOT.equals(range) || VERSION_ATTR_PROJECT.equals(range))
return Collections.singletonList(new Container(this, bsnPattern, range, TYPE.ERROR, null, "Cannot use snapshot or project version with wildcard matches", null, null));
if (strategyx == Strategy.EXACT)
return Collections.singletonList(new Container(this, bsnPattern, range, TYPE.ERROR, null, "Cannot use exact version strategy with wildcard matches", null, null));
VersionRange versionRange;
if (range == null || VERSION_ATTR_LATEST.equals(range))
versionRange = new VersionRange("0");
else
versionRange = new VersionRange(range);
RepoFilter repoFilter = parseRepoFilter(attrs);
if (bsnPattern != null) {
bsnPattern = bsnPattern.trim();
if (bsnPattern.length() == 0 || bsnPattern.equals("*"))
bsnPattern = null;
}
SortedMap<String, Pair<Version, RepositoryPlugin>> providerMap = new TreeMap<String, Pair<Version, RepositoryPlugin>>();
List<RepositoryPlugin> plugins = workspace.getRepositories();
for (RepositoryPlugin plugin : plugins) {
if (repoFilter != null && !repoFilter.match(plugin))
continue;
List<String> bsns = plugin.list(bsnPattern);
if (bsns != null)
for (String bsn : bsns) {
SortedSet<Version> versions = plugin.versions(bsn);
if (versions != null && !versions.isEmpty()) {
Pair<Version, RepositoryPlugin> currentProvider = providerMap.get(bsn);
Version candidate;
switch(strategyx) {
case HIGHEST:
candidate = versions.last();
if (currentProvider == null || candidate.compareTo(currentProvider.getFirst()) > 0) {
providerMap.put(bsn, new Pair<Version, RepositoryPlugin>(candidate, plugin));
}
break;
case LOWEST:
candidate = versions.first();
if (currentProvider == null || candidate.compareTo(currentProvider.getFirst()) < 0) {
providerMap.put(bsn, new Pair<Version, RepositoryPlugin>(candidate, plugin));
}
break;
default:
// we shouldn't have reached this point!
throw new IllegalStateException("Cannot use exact version strategy with wildcard matches");
}
}
}
}
List<Container> containers = new ArrayList<Container>(providerMap.size());
for (Entry<String, Pair<Version, RepositoryPlugin>> entry : providerMap.entrySet()) {
String bsn = entry.getKey();
Version version = entry.getValue().getFirst();
RepositoryPlugin repo = entry.getValue().getSecond();
DownloadBlocker downloadBlocker = new DownloadBlocker(this);
File bundle = repo.get(bsn, version, attrs, downloadBlocker);
if (bundle != null && !bundle.getName().endsWith(".lib")) {
containers.add(new Container(this, bsn, range, Container.TYPE.REPO, bundle, null, attrs, downloadBlocker));
}
}
return containers;
}
use of aQute.libg.tuple.Pair in project bnd by bndtools.
the class RSA method generate.
public static Pair<RSAPrivateKey, RSAPublicKey> generate() throws NoSuchAlgorithmException {
KeyPairGenerator kpg = KeyPairGenerator.getInstance(ALGORITHM);
KeyPair keypair = kpg.generateKeyPair();
return new Pair<RSAPrivateKey, RSAPublicKey>((RSAPrivateKey) keypair.getPrivate(), (RSAPublicKey) keypair.getPublic());
}
use of aQute.libg.tuple.Pair in project bndtools by bndtools.
the class Cache method download.
public byte[] download(URI uri) throws IOException {
byte[] data;
try (HttpClient client = new HttpClient()) {
Pair<String, byte[]> cachedTag = cache.get(uri);
if (cachedTag == null) {
// Not previously cached
TaggedData td = client.connectTagged(uri.toURL());
if (td == null || td.isNotFound())
throw new FileNotFoundException("Not found");
data = IO.read(td.getInputStream());
if (td.getTag() != null)
cache.put(uri, new Pair<String, byte[]>(td.getTag(), data));
} else {
// Previously cached with an ETag
TaggedData td = client.connectTagged(uri.toURL(), cachedTag.getFirst());
if (td == null || td.isNotFound())
throw new FileNotFoundException("Not found");
if (td.getResponseCode() == 304) {
// unchanged
data = cachedTag.getSecond();
} else {
// changed
data = IO.read(td.getInputStream());
if (td.getTag() == null) {
// server now not giving an etag -> remove from cache
cache.remove(uri);
} else {
// replace cache entry with new tag
cache.put(uri, new Pair<String, byte[]>(td.getTag(), data));
}
}
}
return data;
} catch (IOException e) {
throw e;
} catch (Exception e) {
throw new IOException(e);
}
}
use of aQute.libg.tuple.Pair in project bndtools by bndtools.
the class EditableParametersPart method createControl.
public Control createControl(Composite parent) {
this.parent = parent;
Composite composite = new Composite(parent, SWT.NONE);
GridLayout layout = new GridLayout(2, false);
composite.setLayout(layout);
Label titleLabel = new Label(composite, SWT.NONE);
titleLabel.setText(title);
titleLabel.setLayoutData(new GridData(SWT.FILL, SWT.FILL, false, false, 2, 1));
Table table = new Table(composite, SWT.BORDER | SWT.MULTI);
viewer = new TableViewer(table);
viewer.setContentProvider(ArrayContentProvider.getInstance());
final Image iconImg = imageDescriptor.createImage(parent.getDisplay());
viewer.setLabelProvider(new StyledCellLabelProvider() {
@Override
public void update(ViewerCell cell) {
@SuppressWarnings("unchecked") Pair<String, Attrs> entry = (Pair<String, Attrs>) cell.getElement();
StyledString label = new StyledString(entry.getFirst(), BoldStyler.INSTANCE_DEFAULT);
for (Entry<String, String> attribEntry : entry.getSecond().entrySet()) {
label.append("; " + attribEntry.getKey() + "=", StyledString.QUALIFIER_STYLER);
label.append(attribEntry.getValue());
}
cell.setText(label.toString());
cell.setStyleRanges(label.getStyleRanges());
cell.setImage(iconImg);
}
});
viewer.setInput(entries);
GridData gd = new GridData(SWT.FILL, SWT.CENTER, true, false);
gd.widthHint = 280;
gd.heightHint = 80;
table.setLayoutData(gd);
final AddRemoveButtonBarPart buttonBarPart = new AddRemoveButtonBarPart();
ToolBar buttonBar = buttonBarPart.createControl(composite, SWT.FLAT | SWT.VERTICAL);
buttonBar.setLayoutData(new GridData(SWT.FILL, SWT.TOP, false, false));
final Image imgEdit = ImageDescriptor.createFromURL(BUNDLE.getEntry("icons/edit.gif")).createImage(parent.getDisplay());
final Image imgEditDisabled = ImageDescriptor.createFromURL(BUNDLE.getEntry("icons/edit-disabled.gif")).createImage(parent.getDisplay());
final ToolItem btnEdit = new ToolItem(buttonBar, SWT.PUSH);
btnEdit.setImage(imgEdit);
btnEdit.setDisabledImage(imgEditDisabled);
buttonBarPart.setRemoveEnabled(false);
btnEdit.setEnabled(false);
buttonBarPart.addListener(new AddRemoveListener() {
@Override
public void addSelected() {
doAdd();
}
@Override
public void removeSelected() {
doRemove();
}
});
btnEdit.addSelectionListener(new SelectionAdapter() {
@Override
public void widgetSelected(SelectionEvent e) {
doEdit();
}
});
viewer.addSelectionChangedListener(new ISelectionChangedListener() {
@Override
public void selectionChanged(SelectionChangedEvent event) {
boolean enabled = !viewer.getSelection().isEmpty();
buttonBarPart.setRemoveEnabled(enabled);
btnEdit.setEnabled(enabled);
}
});
viewer.addOpenListener(new IOpenListener() {
@Override
public void open(OpenEvent event) {
doEdit();
}
});
table.addKeyListener(new KeyAdapter() {
@Override
public void keyPressed(KeyEvent e) {
if (e.keyCode == SWT.DEL && e.stateMask == 0)
doRemove();
}
});
composite.addDisposeListener(new DisposeListener() {
@Override
public void widgetDisposed(DisposeEvent ev) {
iconImg.dispose();
imgEdit.dispose();
imgEditDisabled.dispose();
}
});
return composite;
}
Aggregations