use of org.apache.commons.lang3.tuple.ImmutablePair in project azure-tools-for-java by Microsoft.
the class StorageModule method refreshItems.
@Override
protected void refreshItems() throws AzureCmdException {
List<Pair<String, String>> failedSubscriptions = new ArrayList<>();
try {
AzureManager azureManager = AuthMethodManager.getInstance().getAzureManager();
// not signed in
if (azureManager == null) {
return;
}
SubscriptionManager subscriptionManager = azureManager.getSubscriptionManager();
Set<String> sidList = subscriptionManager.getAccountSidList();
for (String sid : sidList) {
try {
Azure azure = azureManager.getAzure(sid);
List<com.microsoft.azure.management.storage.StorageAccount> storageAccounts = azure.storageAccounts().list();
for (StorageAccount sm : storageAccounts) {
addChildNode(new StorageNode(this, sid, sm));
}
} catch (Exception ex) {
failedSubscriptions.add(new ImmutablePair<>(sid, ex.getMessage()));
continue;
}
}
} catch (Exception ex) {
DefaultLoader.getUIHelper().logError("An error occurred when trying to load Storage Accounts\n\n" + ex.getMessage(), ex);
}
// load External Accounts
for (ClientStorageAccount clientStorageAccount : ExternalStorageHelper.getList(getProject())) {
ClientStorageAccount storageAccount = StorageClientSDKManager.getManager().getStorageAccount(clientStorageAccount.getConnectionString());
// addChildNode(new ExternalStorageNode(this, storageAccount));
}
if (!failedSubscriptions.isEmpty()) {
StringBuilder errorMessage = new StringBuilder("An error occurred when trying to load Storage Accounts for the subscriptions:\n\n");
for (Pair error : failedSubscriptions) {
errorMessage.append(error.getKey()).append(": ").append(error.getValue()).append("\n");
}
DefaultLoader.getUIHelper().logError("An error occurred when trying to load Storage Accounts\n\n" + errorMessage.toString(), null);
}
}
use of org.apache.commons.lang3.tuple.ImmutablePair in project asterixdb by apache.
the class LicenseMojo method addDependencyToLicenseMap.
private void addDependencyToLicenseMap(MavenProject depProject, List<Pair<String, String>> depLicenses, String depLocation) {
final String depGav = toGav(depProject);
getLog().debug("adding " + depGav + ", location: " + depLocation);
final MutableBoolean usedMetric = new MutableBoolean(false);
if (depLicenses.size() > 1) {
Collections.sort(depLicenses, (o1, o2) -> {
final int metric1 = getLicenseMetric(o1.getLeft());
final int metric2 = getLicenseMetric(o2.getLeft());
usedMetric.setValue(usedMetric.booleanValue() || metric1 != LicenseSpec.UNDEFINED_LICENSE_METRIC || metric2 != LicenseSpec.UNDEFINED_LICENSE_METRIC);
return Integer.compare(metric1, metric2);
});
if (usedMetric.booleanValue()) {
getLog().info("Multiple licenses for " + depGav + ": " + depLicenses + "; taking lowest metric: " + depLicenses.get(0));
} else {
getLog().warn("Multiple licenses for " + depGav + ": " + depLicenses + "; taking first listed: " + depLicenses.get(0));
}
} else if (depLicenses.isEmpty()) {
getLog().info("no license defined in model for " + depGav);
depLicenses.add(new ImmutablePair<>("MISSING_LICENSE", null));
}
Pair<String, String> key = depLicenses.get(0);
String licenseUrl = key.getLeft();
final String displayName = key.getRight();
if (!urlToLicenseMap.containsKey(licenseUrl)) {
// assuming we've not already mapped it, annotate the URL with artifact info, if not an actual URL
try {
getLog().debug("- URL: " + new URL(licenseUrl));
// life is good
} catch (MalformedURLException e) {
// we encounter this a lot. Log a warning, and use an annotated key
final String fakeLicenseUrl = depGav.replaceAll(":", "--") + "_" + licenseUrl;
getLog().info("- URL for " + depGav + " is malformed: " + licenseUrl + "; using: " + fakeLicenseUrl);
licenseUrl = fakeLicenseUrl;
}
}
addProject(new Project(depProject, depLocation, depProject.getArtifact().getFile()), new LicenseSpec(licenseUrl, displayName), true);
}
use of org.apache.commons.lang3.tuple.ImmutablePair in project asterixdb by apache.
the class LicenseMojo method gatherProjectDependencies.
private void gatherProjectDependencies(MavenProject project, Map<MavenProject, List<Pair<String, String>>> dependencyLicenseMap, Map<String, MavenProject> dependencyGavMap) throws ProjectBuildingException {
final Set dependencyArtifacts = project.getArtifacts();
if (dependencyArtifacts != null) {
for (Object depArtifactObj : dependencyArtifacts) {
final Artifact depArtifact = (Artifact) depArtifactObj;
if (!excludedScopes.contains(depArtifact.getScope())) {
MavenProject dep = resolveDependency(depArtifact);
dep.setArtifact(depArtifact);
dependencyGavMap.put(toGav(dep), dep);
List<Pair<String, String>> licenseUrls = new ArrayList<>();
for (Object license : dep.getLicenses()) {
final License license1 = (License) license;
String url = license1.getUrl() != null ? license1.getUrl() : (license1.getName() != null ? license1.getName() : "LICENSE_EMPTY_NAME_URL");
licenseUrls.add(new ImmutablePair<>(url, license1.getName()));
}
dependencyLicenseMap.put(dep, licenseUrls);
}
}
}
}
use of org.apache.commons.lang3.tuple.ImmutablePair in project asterixdb by apache.
the class ZookeeperUtil method getProcessStreams.
private Pair<CharSequence, CharSequence> getProcessStreams(Process process) throws IOException {
StringWriter stdout = new StringWriter();
StringWriter stderr = new StringWriter();
IOUtils.copy(process.getInputStream(), stdout, Charset.defaultCharset());
IOUtils.copy(process.getErrorStream(), stderr, Charset.defaultCharset());
return new ImmutablePair<>(stdout.getBuffer(), stderr.getBuffer());
}
use of org.apache.commons.lang3.tuple.ImmutablePair in project disunity by ata4.
the class BundleHeader method read.
@Override
public void read(DataReader in) throws IOException {
signature = in.readStringNull();
streamVersion = in.readInt();
unityVersion = new UnityVersion(in.readStringNull());
unityRevision = new UnityVersion(in.readStringNull());
if (signature.equals(SIGNATURE_FS)) {
// FS signature
// Expect streamVersion == 6
completeFileSize = in.readLong();
compressedDataHeaderSize = in.readInt();
dataHeaderSize = in.readInt();
flags = in.readInt();
headerSize = (int) in.position();
if ((flags & 0x80) == 0) {
// The data header is part of the bundle header
headerSize += compressedDataHeaderSize;
}
// else it's at the end of the file
} else {
// Web or Raw signature
minimumStreamedBytes = in.readUnsignedInt();
headerSize = in.readInt();
numberOfLevelsToDownload = in.readInt();
int numberOfLevels = in.readInt();
levelByteEnd.clear();
for (int i = 0; i < numberOfLevels; i++) {
levelByteEnd.add(new ImmutablePair(in.readUnsignedInt(), in.readUnsignedInt()));
}
if (streamVersion >= 2) {
completeFileSize = in.readUnsignedInt();
}
if (streamVersion >= 3) {
dataHeaderSize = in.readUnsignedInt();
}
in.readByte();
}
}
Aggregations