From 42c7037a59f279ec96c8d71d90f80cdaca477960 Mon Sep 17 00:00:00 2001 From: Adrian Cole Date: Tue, 1 Jan 2013 00:02:07 -0800 Subject: [PATCH] removed unused code or duplicated code; moved code only used once to where its used --- .../jclouds/atmos/filters/SignRequest.java | 4 +- .../config/CloudFilesRestClientModule.java | 26 +++- .../CloudFilesRestClientModuleTest.java | 34 +++-- .../CloudSigmaComputeServiceAdapter.java | 9 +- .../cloudsigma/functions/DriveDataToMap.java | 36 ++++- .../functions/DriveDataToMapTest.java | 11 ++ .../jclouds/ec2/xml/IpPermissionHandler.java | 5 +- .../ElasticStackComputeServiceAdapter.java | 9 +- .../NovaComputeServiceContextModule.java | 4 +- .../java/org/jclouds/s3/util/S3Utils.java | 7 +- ...CloudComputeServiceDependenciesModule.java | 4 +- .../vcloud/config/DefaultOrgForUser.java | 4 +- .../config/DefaultVCloudReferencesModule.java | 8 +- .../vcloud/config/VCloudRestClientModule.java | 31 ++--- .../functions/CatalogItemsInCatalog.java | 9 +- .../vcloud/functions/CatalogsInOrg.java | 16 +-- .../vcloud/functions/NetworksInOrg.java | 17 +-- .../vcloud/functions/OrgsForLocations.java | 21 +-- .../vcloud/functions/OrgsForNames.java | 1 - .../vcloud/functions/VAppTemplatesInOrg.java | 6 +- .../jclouds/vcloud/functions/VDCsInOrg.java | 16 +-- .../blobstore/util/BlobStoreUtils.java | 67 --------- .../internal/BaseBlobIntegrationTest.java | 1 - .../internal/BaseBlobMapIntegrationTest.java | 1 - .../BaseBlobStoreIntegrationTest.java | 17 ++- .../blobstore/util/BlobStoreUtilsTest.java | 20 --- .../openstack/keystone/v1_1/domain/Auth.java | 35 ++++- .../vcloud_0_8/config/DefaultOrgForUser.java | 4 +- .../config/DefaultVCloudReferencesModule.java | 8 +- .../TerremarkVCloudRestClientModule.java | 8 +- .../BaseComputeServiceContextModule.java | 6 +- .../domain/internal/TemplateBuilderImpl.java | 28 +++- .../internal/TemplateBuilderImplTest.java | 14 +- core/src/main/java/org/jclouds/Fallbacks.java | 7 +- .../java/org/jclouds/domain/JsonBall.java | 14 +- .../org/jclouds/domain/LoginCredentials.java | 15 +- .../ExceptionToValueOrPropagate.java | 55 -------- .../java/org/jclouds/functions/JoinOnK2.java | 48 ------- .../functions/ParseContentMD5FromHeaders.java | 77 ----------- .../org/jclouds/http/pool/PoolConstants.java | 53 -------- .../location/config/LocationModule.java | 6 +- .../jclouds/rest/config/RestClientModule.java | 25 +++- .../internal/RestAnnotationProcessor.java | 14 +- .../org/jclouds/util/ClassLoadingUtils.java | 41 ------ .../org/jclouds/util/ConcreteFunction.java | 45 ------ .../org/jclouds/util/CredentialUtils.java | 60 -------- .../org/jclouds/util/InputStreamChain.java | 128 ------------------ .../java/org/jclouds/util/Iterables2.java | 41 ------ .../main/java/org/jclouds/util/Lists2.java | 55 -------- .../src/main/java/org/jclouds/util/Maps2.java | 108 --------------- .../main/java/org/jclouds/util/Modules2.java | 72 ---------- .../java/org/jclouds/util/Multimaps2.java | 33 +---- .../org/jclouds/util/NullSafeCollections.java | 38 ------ .../main/java/org/jclouds/util/Patterns.java | 49 +------ .../java/org/jclouds/util/Preconditions2.java | 10 -- .../java/org/jclouds/util/Predicates2.java | 15 -- .../main/java/org/jclouds/util/SaxUtils.java | 4 - .../main/java/org/jclouds/util/Strings2.java | 40 ++++-- .../java/org/jclouds/util/Suppliers2.java | 68 ---------- .../java/org/jclouds/util/Throwables2.java | 14 +- .../java/org/jclouds/util/TypeTokens2.java | 40 ------ .../java/org/jclouds/domain/JsonBallTest.java | 47 +++++++ .../NullHackJsonLiteralAdapterTest.java | 9 +- .../org/jclouds/util/CredentialUtilsTest.java | 60 -------- .../test/java/org/jclouds/util/Maps2Test.java | 57 -------- .../java/org/jclouds/util/PatternsTest.java | 96 ------------- .../java/org/jclouds/util/Suppliers2Test.java | 16 --- .../jclouds/ssh/jsch/SessionConnection.java | 13 +- .../abiquo/config/AbiquoRestClientModule.java | 4 +- ...oyentCloudComputeServiceContextModule.java | 8 +- .../vpdc/config/VPDCRestClientModule.java | 20 +-- .../VCloudDirectorRestClientModule.java | 8 +- .../org/jclouds/azureblob/AzureBlobUtil.java | 56 -------- 73 files changed, 427 insertions(+), 1629 deletions(-) rename core/src/test/java/org/jclouds/util/Lists2Test.java => apis/cloudfiles/src/test/java/org/jclouds/cloudfiles/config/CloudFilesRestClientModuleTest.java (50%) delete mode 100644 core/src/main/java/org/jclouds/functions/ExceptionToValueOrPropagate.java delete mode 100644 core/src/main/java/org/jclouds/functions/JoinOnK2.java delete mode 100644 core/src/main/java/org/jclouds/http/functions/ParseContentMD5FromHeaders.java delete mode 100644 core/src/main/java/org/jclouds/http/pool/PoolConstants.java delete mode 100644 core/src/main/java/org/jclouds/util/ConcreteFunction.java delete mode 100644 core/src/main/java/org/jclouds/util/CredentialUtils.java delete mode 100644 core/src/main/java/org/jclouds/util/InputStreamChain.java delete mode 100644 core/src/main/java/org/jclouds/util/Iterables2.java delete mode 100644 core/src/main/java/org/jclouds/util/Lists2.java delete mode 100644 core/src/main/java/org/jclouds/util/Modules2.java delete mode 100644 core/src/main/java/org/jclouds/util/NullSafeCollections.java delete mode 100644 core/src/main/java/org/jclouds/util/TypeTokens2.java delete mode 100644 core/src/test/java/org/jclouds/util/CredentialUtilsTest.java delete mode 100644 core/src/test/java/org/jclouds/util/PatternsTest.java delete mode 100644 providers/azureblob/src/main/java/org/jclouds/azureblob/AzureBlobUtil.java diff --git a/apis/atmos/src/main/java/org/jclouds/atmos/filters/SignRequest.java b/apis/atmos/src/main/java/org/jclouds/atmos/filters/SignRequest.java index f97e4539ee..f7b1e728f6 100644 --- a/apis/atmos/src/main/java/org/jclouds/atmos/filters/SignRequest.java +++ b/apis/atmos/src/main/java/org/jclouds/atmos/filters/SignRequest.java @@ -23,10 +23,10 @@ import static com.google.common.io.ByteStreams.readBytes; import static org.jclouds.Constants.LOGGER_SIGNATURE; import static org.jclouds.crypto.Macs.asByteProcessor; import static org.jclouds.util.Patterns.NEWLINE_PATTERN; -import static org.jclouds.util.Patterns.TWO_SPACE_PATTERN; import static org.jclouds.util.Strings2.toInputStream; import java.util.Set; +import java.util.regex.Pattern; import javax.annotation.Resource; import javax.inject.Inject; @@ -140,6 +140,8 @@ public class SignRequest implements HttpRequestFilter { private void appendMethod(HttpRequest request, StringBuilder toSign) { toSign.append(request.getMethod()).append("\n"); } + + private static final Pattern TWO_SPACE_PATTERN = Pattern.compile(" "); private void appendCanonicalizedHeaders(HttpRequest request, StringBuilder toSign) { // TreeSet == Sort the headers alphabetically. diff --git a/apis/cloudfiles/src/main/java/org/jclouds/cloudfiles/config/CloudFilesRestClientModule.java b/apis/cloudfiles/src/main/java/org/jclouds/cloudfiles/config/CloudFilesRestClientModule.java index 7273a4a2ec..c9d43ed792 100644 --- a/apis/cloudfiles/src/main/java/org/jclouds/cloudfiles/config/CloudFilesRestClientModule.java +++ b/apis/cloudfiles/src/main/java/org/jclouds/cloudfiles/config/CloudFilesRestClientModule.java @@ -18,9 +18,8 @@ */ package org.jclouds.cloudfiles.config; -import static org.jclouds.util.Suppliers2.valueForKey; - import java.net.URI; +import java.util.Map; import javax.inject.Singleton; @@ -36,6 +35,7 @@ import org.jclouds.openstack.swift.Storage; import org.jclouds.openstack.swift.config.SwiftRestClientModule; import org.jclouds.rest.ConfiguresRestClient; +import com.google.common.annotations.VisibleForTesting; import com.google.common.base.Supplier; import com.google.common.collect.ImmutableMap; import com.google.common.reflect.TypeToken; @@ -77,6 +77,28 @@ public class CloudFilesRestClientModule extends SwiftRestClientModule Supplier valueForKey(final Supplier>> input, final Supplier key) { + return new Supplier() { + + @Override + public V get() { + K keyToFind = key.get(); + Supplier value = input.get().get(keyToFind); + return value != null ? value.get() : null; + } + + @Override + public String toString() { + return "withKey()"; + } + }; } } diff --git a/core/src/test/java/org/jclouds/util/Lists2Test.java b/apis/cloudfiles/src/test/java/org/jclouds/cloudfiles/config/CloudFilesRestClientModuleTest.java similarity index 50% rename from core/src/test/java/org/jclouds/util/Lists2Test.java rename to apis/cloudfiles/src/test/java/org/jclouds/cloudfiles/config/CloudFilesRestClientModuleTest.java index fbc7e0c118..9aa406e134 100644 --- a/core/src/test/java/org/jclouds/util/Lists2Test.java +++ b/apis/cloudfiles/src/test/java/org/jclouds/cloudfiles/config/CloudFilesRestClientModuleTest.java @@ -16,29 +16,33 @@ * specific language governing permissions and limitations * under the License. */ -package org.jclouds.util; +package org.jclouds.cloudfiles.config; import static org.testng.Assert.assertEquals; +import java.util.Map; + import org.testng.annotations.Test; -import com.google.common.collect.ImmutableList; -import com.google.common.collect.Ordering; +import com.google.common.base.Supplier; +import com.google.common.base.Suppliers; +import com.google.common.collect.ImmutableMap; -/** - * @author Adrian Cole - */ -@Test(groups = "unit") -public class Lists2Test { +public class CloudFilesRestClientModuleTest { - public void testMultiMax() { - Iterable values = ImmutableList.of("1", "2", "2", "3", "3"); - assertEquals(Lists2.multiMax(Ordering.natural(), values), ImmutableList.of("3", "3")); + @Test + public void testWithKey() { + assertEquals( + CloudFilesRestClientModule. valueForKey( + Suppliers.>> ofInstance(ImmutableMap.of("foo", + Suppliers.ofInstance("bar"))), Suppliers.ofInstance("foo")).get(), "bar"); } - public void testMultiMax1() { - Iterable values = ImmutableList.of("1", "2", "2", "3"); - assertEquals(Lists2.multiMax(Ordering.natural(), values), ImmutableList.of("3")); + @Test + public void testWithKeyUnmatchedIsNull() { + assertEquals( + CloudFilesRestClientModule. valueForKey( + Suppliers.>> ofInstance(ImmutableMap.of("boo", + Suppliers.ofInstance("bar"))), Suppliers.ofInstance("foo")).get(), null); } - } diff --git a/apis/cloudsigma/src/main/java/org/jclouds/cloudsigma/compute/CloudSigmaComputeServiceAdapter.java b/apis/cloudsigma/src/main/java/org/jclouds/cloudsigma/compute/CloudSigmaComputeServiceAdapter.java index 36cc88c45f..846fa9aadf 100644 --- a/apis/cloudsigma/src/main/java/org/jclouds/cloudsigma/compute/CloudSigmaComputeServiceAdapter.java +++ b/apis/cloudsigma/src/main/java/org/jclouds/cloudsigma/compute/CloudSigmaComputeServiceAdapter.java @@ -20,7 +20,6 @@ package org.jclouds.cloudsigma.compute; import static com.google.common.base.Preconditions.checkArgument; import static com.google.common.base.Preconditions.checkNotNull; -import static com.google.common.collect.Iterables.filter; import static org.jclouds.concurrent.FutureIterables.transformParallel; import java.util.concurrent.ExecutorService; @@ -43,6 +42,7 @@ import org.jclouds.cloudsigma.domain.ServerInfo; import org.jclouds.cloudsigma.options.CloneDriveOptions; import org.jclouds.cloudsigma.reference.CloudSigmaConstants; import org.jclouds.cloudsigma.util.Servers; +import org.jclouds.compute.ComputeService; import org.jclouds.compute.ComputeServiceAdapter; import org.jclouds.compute.domain.Hardware; import org.jclouds.compute.domain.HardwareBuilder; @@ -55,13 +55,13 @@ import org.jclouds.compute.reference.ComputeServiceConstants; import org.jclouds.domain.Location; import org.jclouds.domain.LoginCredentials; import org.jclouds.logging.Logger; -import org.jclouds.util.Iterables2; import com.google.common.base.Function; import com.google.common.base.Predicate; import com.google.common.base.Predicates; import com.google.common.cache.CacheLoader; import com.google.common.cache.LoadingCache; +import com.google.common.collect.FluentIterable; import com.google.common.collect.ImmutableList; import com.google.common.collect.ImmutableSet; import com.google.common.collect.ImmutableSet.Builder; @@ -170,7 +170,7 @@ public class CloudSigmaComputeServiceAdapter implements */ @Override public Iterable listImages() { - Iterable drives = transformParallel(client.listStandardDrives(), + return FluentIterable.from(transformParallel(client.listStandardDrives(), new Function>() { @Override @@ -189,8 +189,7 @@ public class CloudSigmaComputeServiceAdapter implements public String toString() { return "seedDriveCache()"; } - }, executor, null, logger, "drives"); - return Iterables2.concreteCopy(filter(drives, PREINSTALLED_DISK)); + }, executor, null, logger, "drives")).filter(PREINSTALLED_DISK); } @SuppressWarnings("unchecked") diff --git a/apis/cloudsigma/src/main/java/org/jclouds/cloudsigma/functions/DriveDataToMap.java b/apis/cloudsigma/src/main/java/org/jclouds/cloudsigma/functions/DriveDataToMap.java index de9df722f9..ae98d44cf7 100644 --- a/apis/cloudsigma/src/main/java/org/jclouds/cloudsigma/functions/DriveDataToMap.java +++ b/apis/cloudsigma/src/main/java/org/jclouds/cloudsigma/functions/DriveDataToMap.java @@ -18,7 +18,10 @@ */ package org.jclouds.cloudsigma.functions; -import static org.jclouds.util.Maps2.renameKey; +import static com.google.common.base.Preconditions.checkNotNull; +import static com.google.common.base.Predicates.equalTo; +import static com.google.common.base.Predicates.not; +import static com.google.common.collect.Maps.filterKeys; import java.util.Map; @@ -27,7 +30,10 @@ import javax.inject.Singleton; import org.jclouds.cloudsigma.domain.DriveData; +import com.google.common.annotations.VisibleForTesting; import com.google.common.base.Function; +import com.google.common.collect.ImmutableMap; +import com.google.common.collect.ImmutableMap.Builder; /** * @@ -46,4 +52,32 @@ public class DriveDataToMap implements Function> public Map apply(DriveData from) { return renameKey(baseDriveToMap.apply(from), "use", "use"); } + + /** + * If the supplied map contains the key {@code k1}, its value will be assigned to the key {@code + * k2}. Note that this doesn't modify the input map. + * + * @param + * type of value the map holds + * @param in + * the map you wish to make a copy of + * @param k1 + * old key + * @param k2 + * new key + * @return copy of the map with the value of the key re-routed, or the original, if it {@code k1} + * wasn't present. + */ + @VisibleForTesting + static Map renameKey(Map in, String k1, String k2) { + if (checkNotNull(in, "input map").containsKey(checkNotNull(k1, "old key"))) { + Builder builder = ImmutableMap.builder(); + builder.putAll(filterKeys(in, not(equalTo(k1)))); + V tags = in.get(k1); + builder.put(checkNotNull(k2, "new key"), tags); + in = builder.build(); + } + return in; + } + } diff --git a/apis/cloudsigma/src/test/java/org/jclouds/cloudsigma/functions/DriveDataToMapTest.java b/apis/cloudsigma/src/test/java/org/jclouds/cloudsigma/functions/DriveDataToMapTest.java index 40bdaeb488..58aa3b7677 100644 --- a/apis/cloudsigma/src/test/java/org/jclouds/cloudsigma/functions/DriveDataToMapTest.java +++ b/apis/cloudsigma/src/test/java/org/jclouds/cloudsigma/functions/DriveDataToMapTest.java @@ -21,6 +21,7 @@ package org.jclouds.cloudsigma.functions; import static org.testng.Assert.assertEquals; import java.io.IOException; +import java.util.Map; import org.jclouds.cloudsigma.domain.ClaimType; import org.jclouds.cloudsigma.domain.DriveData; @@ -36,6 +37,16 @@ import com.google.inject.Guice; */ @Test(groups = { "unit" }) public class DriveDataToMapTest { + + public void testRenameKeyWhenNotFound() { + Map nothing = ImmutableMap.of(); + assertEquals(DriveDataToMap.renameKey(nothing, "foo", "bar"), nothing); + } + + public void testRenameKeyWhenFound() { + Map nothing = ImmutableMap.of("foo", "bar"); + assertEquals(DriveDataToMap.renameKey(nothing, "foo", "bar"), ImmutableMap.of("bar", "bar")); + } private static final DriveDataToMap BASEDRIVE_TO_MAP = Guice.createInjector().getInstance(DriveDataToMap.class); diff --git a/apis/ec2/src/main/java/org/jclouds/ec2/xml/IpPermissionHandler.java b/apis/ec2/src/main/java/org/jclouds/ec2/xml/IpPermissionHandler.java index 8045feee40..91749026d8 100644 --- a/apis/ec2/src/main/java/org/jclouds/ec2/xml/IpPermissionHandler.java +++ b/apis/ec2/src/main/java/org/jclouds/ec2/xml/IpPermissionHandler.java @@ -1,6 +1,5 @@ package org.jclouds.ec2.xml; -import static org.jclouds.util.SaxUtils.currentOrNegative; import static org.jclouds.util.SaxUtils.currentOrNull; import static org.jclouds.util.SaxUtils.equalsOrSuffix; @@ -64,6 +63,10 @@ public class IpPermissionHandler extends ParseSax.HandlerForGeneratedRequestWith currentText = new StringBuilder(); } + private static String currentOrNegative(StringBuilder currentText) { + String returnVal = currentText.toString().trim(); + return returnVal.equals("") ? "-1" : returnVal; + } /** * {@inheritDoc} */ diff --git a/apis/elasticstack/src/main/java/org/jclouds/elasticstack/compute/ElasticStackComputeServiceAdapter.java b/apis/elasticstack/src/main/java/org/jclouds/elasticstack/compute/ElasticStackComputeServiceAdapter.java index 01ae6ae476..a3d57d328e 100644 --- a/apis/elasticstack/src/main/java/org/jclouds/elasticstack/compute/ElasticStackComputeServiceAdapter.java +++ b/apis/elasticstack/src/main/java/org/jclouds/elasticstack/compute/ElasticStackComputeServiceAdapter.java @@ -21,7 +21,6 @@ package org.jclouds.elasticstack.compute; import static com.google.common.base.Preconditions.checkArgument; import static com.google.common.base.Preconditions.checkNotNull; import static com.google.common.base.Predicates.notNull; -import static com.google.common.collect.Iterables.filter; import static org.jclouds.concurrent.FutureIterables.transformParallel; import static org.jclouds.elasticstack.util.Servers.small; @@ -35,6 +34,7 @@ import javax.inject.Named; import javax.inject.Singleton; import org.jclouds.Constants; +import org.jclouds.compute.ComputeService; import org.jclouds.compute.ComputeServiceAdapter; import org.jclouds.compute.domain.Hardware; import org.jclouds.compute.domain.HardwareBuilder; @@ -57,12 +57,12 @@ import org.jclouds.elasticstack.domain.ServerStatus; import org.jclouds.elasticstack.domain.WellKnownImage; import org.jclouds.elasticstack.reference.ElasticStackConstants; import org.jclouds.logging.Logger; -import org.jclouds.util.Iterables2; import com.google.common.base.Function; import com.google.common.base.Predicate; import com.google.common.cache.CacheLoader; import com.google.common.cache.LoadingCache; +import com.google.common.collect.FluentIterable; import com.google.common.collect.ImmutableList; import com.google.common.collect.ImmutableSet; import com.google.common.collect.ImmutableSet.Builder; @@ -163,7 +163,7 @@ public class ElasticStackComputeServiceAdapter implements */ @Override public Iterable listImages() { - Iterable drives = transformParallel(preinstalledImages.keySet(), + return FluentIterable.from(transformParallel(preinstalledImages.keySet(), new Function>() { @Override @@ -183,8 +183,7 @@ public class ElasticStackComputeServiceAdapter implements return "seedDriveCache()"; } - }, executor, null, logger, "drives"); - return Iterables2.concreteCopy(filter(drives, notNull())); + }, executor, null, logger, "drives")).filter(notNull()); } @SuppressWarnings("unchecked") diff --git a/apis/openstack-nova/src/main/java/org/jclouds/openstack/nova/v2_0/compute/config/NovaComputeServiceContextModule.java b/apis/openstack-nova/src/main/java/org/jclouds/openstack/nova/v2_0/compute/config/NovaComputeServiceContextModule.java index 9b401d105b..44f202a4d2 100644 --- a/apis/openstack-nova/src/main/java/org/jclouds/openstack/nova/v2_0/compute/config/NovaComputeServiceContextModule.java +++ b/apis/openstack-nova/src/main/java/org/jclouds/openstack/nova/v2_0/compute/config/NovaComputeServiceContextModule.java @@ -73,13 +73,13 @@ import org.jclouds.openstack.nova.v2_0.domain.zonescoped.ZoneSecurityGroupNameAn import org.jclouds.openstack.nova.v2_0.predicates.FindSecurityGroupWithNameAndReturnTrue; import org.jclouds.predicates.PredicateWithResult; import org.jclouds.predicates.RetryablePredicate; -import org.jclouds.util.Suppliers2; import com.google.common.annotations.VisibleForTesting; import com.google.common.base.Function; import com.google.common.base.Optional; import com.google.common.base.Predicate; import com.google.common.base.Supplier; +import com.google.common.base.Suppliers; import com.google.common.cache.CacheBuilder; import com.google.common.cache.CacheLoader; import com.google.common.cache.LoadingCache; @@ -201,7 +201,7 @@ public class NovaComputeServiceContextModule extends @Singleton protected Supplier> createLocationIndexedById( @Memoized Supplier> locations) { - return Suppliers2.compose(new Function, Map>() { + return Suppliers.compose(new Function, Map>() { @SuppressWarnings("unchecked") @Override diff --git a/apis/s3/src/main/java/org/jclouds/s3/util/S3Utils.java b/apis/s3/src/main/java/org/jclouds/s3/util/S3Utils.java index 0f4cb16734..acb8ddefe9 100644 --- a/apis/s3/src/main/java/org/jclouds/s3/util/S3Utils.java +++ b/apis/s3/src/main/java/org/jclouds/s3/util/S3Utils.java @@ -30,7 +30,6 @@ import org.jclouds.http.HttpRequest; import org.jclouds.rest.internal.GeneratedHttpRequest; import org.jclouds.s3.Bucket; import org.jclouds.s3.S3Client; -import org.jclouds.util.Patterns; import com.google.common.base.Predicate; @@ -41,7 +40,9 @@ import com.google.common.base.Predicate; */ public class S3Utils { - public static final Pattern BUCKET_NAME_PATTERN = Pattern.compile("^[a-z0-9][-_.a-z0-9]+"); + private static final Pattern BUCKET_NAME_PATTERN = Pattern.compile("^[a-z0-9][-_.a-z0-9]+"); + private static final Pattern IP_PATTERN = Pattern.compile("b(?:(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?).)" + + "{3}(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)b"); // TODO add validatorparam so that this is actually used public static String validateBucketName(String bucketName) { @@ -51,7 +52,7 @@ public class S3Utils { "bucketName name must start with a number or letter and can only contain lowercase letters, numbers, periods (.), underscores (_), and dashes (-)"); checkArgument(bucketName.length() > 2 && bucketName.length() < 256, "bucketName name must be between 3 and 255 characters long"); - checkArgument(!Patterns.IP_PATTERN.matcher(bucketName).matches(), + checkArgument(!IP_PATTERN.matcher(bucketName).matches(), "bucketName name cannot be ip address style"); return bucketName; } diff --git a/apis/vcloud/src/main/java/org/jclouds/vcloud/compute/config/VCloudComputeServiceDependenciesModule.java b/apis/vcloud/src/main/java/org/jclouds/vcloud/compute/config/VCloudComputeServiceDependenciesModule.java index 815bc079e9..b8a75addef 100644 --- a/apis/vcloud/src/main/java/org/jclouds/vcloud/compute/config/VCloudComputeServiceDependenciesModule.java +++ b/apis/vcloud/src/main/java/org/jclouds/vcloud/compute/config/VCloudComputeServiceDependenciesModule.java @@ -31,7 +31,6 @@ import org.jclouds.compute.domain.TemplateBuilder; import org.jclouds.compute.options.TemplateOptions; import org.jclouds.domain.Location; import org.jclouds.functions.IdentityFunction; -import org.jclouds.util.Suppliers2; import org.jclouds.vcloud.compute.functions.HardwareForVApp; import org.jclouds.vcloud.compute.functions.HardwareForVAppTemplate; import org.jclouds.vcloud.compute.functions.ImageForVAppTemplate; @@ -52,6 +51,7 @@ import org.jclouds.vcloud.functions.VAppTemplatesInOrg; import com.google.common.annotations.VisibleForTesting; import com.google.common.base.Function; import com.google.common.base.Supplier; +import com.google.common.base.Suppliers; import com.google.common.collect.ImmutableMap; import com.google.inject.AbstractModule; import com.google.inject.Provides; @@ -143,7 +143,7 @@ public class VCloudComputeServiceDependenciesModule extends AbstractModule { @Singleton public Supplier networkConfig(@Network Supplier network, final FenceMode defaultFenceMode) { - return Suppliers2.compose(new Function() { + return Suppliers.compose(new Function() { @Override public NetworkConfig apply(ReferenceType input) { diff --git a/apis/vcloud/src/main/java/org/jclouds/vcloud/config/DefaultOrgForUser.java b/apis/vcloud/src/main/java/org/jclouds/vcloud/config/DefaultOrgForUser.java index 3fbfd527e1..53f5fe8a29 100644 --- a/apis/vcloud/src/main/java/org/jclouds/vcloud/config/DefaultOrgForUser.java +++ b/apis/vcloud/src/main/java/org/jclouds/vcloud/config/DefaultOrgForUser.java @@ -26,7 +26,6 @@ import javax.inject.Inject; import javax.inject.Singleton; import org.jclouds.config.ValueOfConfigurationKeyOrNull; -import org.jclouds.util.Suppliers2; import org.jclouds.vcloud.domain.ReferenceType; import org.jclouds.vcloud.domain.VCloudSession; import org.jclouds.vcloud.endpoints.Org; @@ -35,6 +34,7 @@ import org.jclouds.vcloud.suppliers.OnlyReferenceTypeFirstWithNameMatchingConfig import com.google.common.base.Function; import com.google.common.base.Predicate; import com.google.common.base.Supplier; +import com.google.common.base.Suppliers; /** * @@ -57,7 +57,7 @@ public class DefaultOrgForUser implements Function apply(final String user) { - return Suppliers2.compose(new Function() { + return Suppliers.compose(new Function() { @Override public ReferenceType apply(VCloudSession session) { diff --git a/apis/vcloud/src/main/java/org/jclouds/vcloud/config/DefaultVCloudReferencesModule.java b/apis/vcloud/src/main/java/org/jclouds/vcloud/config/DefaultVCloudReferencesModule.java index 099d4e4b33..740c34793f 100644 --- a/apis/vcloud/src/main/java/org/jclouds/vcloud/config/DefaultVCloudReferencesModule.java +++ b/apis/vcloud/src/main/java/org/jclouds/vcloud/config/DefaultVCloudReferencesModule.java @@ -73,7 +73,7 @@ public class DefaultVCloudReferencesModule extends AbstractModule { @Singleton protected Supplier provideDefaultTasksList(DefaultTasksListForOrg defaultTasksListURIForOrg, @org.jclouds.vcloud.endpoints.Org Supplier defaultOrg) { - return Suppliers2.compose(defaultTasksListURIForOrg, defaultOrg); + return Suppliers.compose(defaultTasksListURIForOrg, defaultOrg); } @Provides @@ -81,7 +81,7 @@ public class DefaultVCloudReferencesModule extends AbstractModule { @Singleton protected Supplier provideDefaultCatalog(DefaultCatalogForOrg defaultCatalogURIForOrg, @org.jclouds.vcloud.endpoints.Org Supplier defaultOrg) { - return Suppliers2.compose(defaultCatalogURIForOrg, defaultOrg); + return Suppliers.compose(defaultCatalogURIForOrg, defaultOrg); } @Provides @@ -147,7 +147,7 @@ public class DefaultVCloudReferencesModule extends AbstractModule { @Singleton protected Supplier provideDefaultVDC(DefaultVDCForOrg defaultVDCURIForOrg, @org.jclouds.vcloud.endpoints.Org Supplier defaultOrg) { - return Suppliers2.compose(defaultVDCURIForOrg, defaultOrg); + return Suppliers.compose(defaultVDCURIForOrg, defaultOrg); } @Provides @@ -162,7 +162,7 @@ public class DefaultVCloudReferencesModule extends AbstractModule { @Singleton protected Supplier provideDefaultNetwork(DefaultNetworkForVDC defaultNetworkURIForVDC, @org.jclouds.vcloud.endpoints.VDC Supplier defaultVDC) { - return Suppliers2.compose(defaultNetworkURIForVDC, defaultVDC); + return Suppliers.compose(defaultNetworkURIForVDC, defaultVDC); } @Provides diff --git a/apis/vcloud/src/main/java/org/jclouds/vcloud/config/VCloudRestClientModule.java b/apis/vcloud/src/main/java/org/jclouds/vcloud/config/VCloudRestClientModule.java index 5ef2f30a1e..1552dc757a 100644 --- a/apis/vcloud/src/main/java/org/jclouds/vcloud/config/VCloudRestClientModule.java +++ b/apis/vcloud/src/main/java/org/jclouds/vcloud/config/VCloudRestClientModule.java @@ -26,9 +26,9 @@ import static com.google.common.collect.Iterables.filter; import static com.google.common.collect.Iterables.getLast; import static com.google.common.collect.Iterables.transform; import static com.google.common.collect.Maps.transformValues; +import static com.google.common.collect.Maps.uniqueIndex; import static org.jclouds.Constants.PROPERTY_SESSION_INTERVAL; import static org.jclouds.rest.config.BinderUtils.bindClientAndAsyncClient; -import static org.jclouds.util.Maps2.uniqueIndex; import static org.jclouds.vcloud.reference.VCloudConstants.PROPERTY_VCLOUD_DEFAULT_FENCEMODE; import static org.jclouds.vcloud.reference.VCloudConstants.PROPERTY_VCLOUD_TIMEOUT_TASK_COMPLETED; @@ -58,7 +58,6 @@ import org.jclouds.rest.ConfiguresRestClient; import org.jclouds.rest.annotations.ApiVersion; import org.jclouds.rest.config.RestClientModule; import org.jclouds.rest.suppliers.MemoizedRetryOnTimeOutButNotOnAuthorizationExceptionSupplier; -import org.jclouds.util.Suppliers2; import org.jclouds.vcloud.VCloudAsyncClient; import org.jclouds.vcloud.VCloudClient; import org.jclouds.vcloud.VCloudToken; @@ -95,11 +94,11 @@ import org.jclouds.vcloud.features.VmClient; import org.jclouds.vcloud.functions.CatalogItemsInCatalog; import org.jclouds.vcloud.functions.CatalogItemsInOrg; import org.jclouds.vcloud.functions.CatalogsInOrg; -import org.jclouds.vcloud.functions.VDCsInOrg; import org.jclouds.vcloud.functions.DefaultNetworkNameInTemplate; import org.jclouds.vcloud.functions.OrgsForLocations; import org.jclouds.vcloud.functions.OrgsForNames; import org.jclouds.vcloud.functions.VAppTemplatesForCatalogItems; +import org.jclouds.vcloud.functions.VDCsInOrg; import org.jclouds.vcloud.handlers.ParseVCloudErrorFromHttpResponse; import org.jclouds.vcloud.internal.VCloudLoginAsyncClient; import org.jclouds.vcloud.internal.VCloudLoginClient; @@ -114,6 +113,7 @@ import com.google.common.base.Function; import com.google.common.base.Objects; import com.google.common.base.Predicate; import com.google.common.base.Supplier; +import com.google.common.base.Suppliers; import com.google.common.cache.CacheBuilder; import com.google.common.cache.CacheLoader; import com.google.common.cache.LoadingCache; @@ -224,7 +224,7 @@ public class VCloudRestClientModule extends RestClientModule> provideVDCtoORG(Supplier> orgNameToOrgSupplier) { - return Suppliers2.compose(new Function, Map>() { + return Suppliers.compose(new Function, Map>() { @Override public Map apply(Map arg0) { @@ -252,7 +252,7 @@ public class VCloudRestClientModule extends RestClientModule provideOrgListURI(Supplier sessionSupplier) { - return Suppliers2.compose(new Function() { + return Suppliers.compose(new Function() { @Override public URI apply(VCloudSession arg0) { @@ -304,18 +304,15 @@ public class VCloudRestClientModule extends RestClientModule> get() { - return transformValues( - transformValues(orgSupplier.get(), allCatalogsInOrg), - new Function, - Map>() { + return transformValues(transformValues(orgSupplier.get(), allCatalogsInOrg), + new Function, Map>() { - @Override - public Map apply( - Iterable from) { - return uniqueIndex(from, name); - } + @Override + public Map apply(Iterable from) { + return ImmutableMap.copyOf(uniqueIndex(from, name)); + } - }); + }); } } @@ -323,7 +320,7 @@ public class VCloudRestClientModule extends RestClientModule provideVCloudToken(Supplier cache) { - return Suppliers2.compose(new Function() { + return Suppliers.compose(new Function() { @Override public String apply(VCloudSession input) { @@ -432,7 +429,7 @@ public class VCloudRestClientModule extends RestClientModule provideOrg(final Supplier> orgSupplier, @org.jclouds.vcloud.endpoints.Org Supplier defaultOrg) { - return Suppliers2.compose(new Function() { + return Suppliers.compose(new Function() { @Override public Org apply(ReferenceType input) { diff --git a/apis/vcloud/src/main/java/org/jclouds/vcloud/functions/CatalogItemsInCatalog.java b/apis/vcloud/src/main/java/org/jclouds/vcloud/functions/CatalogItemsInCatalog.java index 4744e9f2c7..cc398303f9 100644 --- a/apis/vcloud/src/main/java/org/jclouds/vcloud/functions/CatalogItemsInCatalog.java +++ b/apis/vcloud/src/main/java/org/jclouds/vcloud/functions/CatalogItemsInCatalog.java @@ -31,7 +31,6 @@ import javax.inject.Singleton; import org.jclouds.Constants; import org.jclouds.logging.Logger; -import org.jclouds.util.Iterables2; import org.jclouds.vcloud.VCloudAsyncClient; import org.jclouds.vcloud.VCloudMediaType; import org.jclouds.vcloud.domain.Catalog; @@ -60,23 +59,17 @@ public class CatalogItemsInCatalog implements Function apply(Catalog from) { - - Iterable catalogItems = transformParallel(filter(from.values(), new Predicate() { - + return transformParallel(filter(from.values(), new Predicate() { @Override public boolean apply(ReferenceType input) { return input.getType().equals(VCloudMediaType.CATALOGITEM_XML); } - }), new Function>() { - @Override public Future apply(ReferenceType from) { return aclient.getCatalogClient().getCatalogItem(from.getHref()); } - }, executor, null, logger, "catalogItems in " + from.getHref()); - return Iterables2.concreteCopy(catalogItems); } } diff --git a/apis/vcloud/src/main/java/org/jclouds/vcloud/functions/CatalogsInOrg.java b/apis/vcloud/src/main/java/org/jclouds/vcloud/functions/CatalogsInOrg.java index e4e0d5f329..78793d8649 100644 --- a/apis/vcloud/src/main/java/org/jclouds/vcloud/functions/CatalogsInOrg.java +++ b/apis/vcloud/src/main/java/org/jclouds/vcloud/functions/CatalogsInOrg.java @@ -30,7 +30,6 @@ import javax.inject.Singleton; import org.jclouds.Constants; import org.jclouds.logging.Logger; -import org.jclouds.util.Iterables2; import org.jclouds.vcloud.VCloudAsyncClient; import org.jclouds.vcloud.domain.Catalog; import org.jclouds.vcloud.domain.Org; @@ -57,14 +56,11 @@ public class CatalogsInOrg implements Function> { @Override public Iterable apply(final Org org) { - Iterable catalogs = transformParallel(org.getCatalogs().values(), - new Function>() { - @Override - public Future apply(ReferenceType from) { - return aclient.getCatalogClient().getCatalog(from.getHref()); - } - - }, executor, null, logger, "catalogs in " + org.getName()); - return Iterables2.concreteCopy(catalogs); + return transformParallel(org.getCatalogs().values(), new Function>() { + @Override + public Future apply(ReferenceType from) { + return aclient.getCatalogClient().getCatalog(from.getHref()); + } + }, executor, null, logger, "catalogs in " + org.getName()); } } diff --git a/apis/vcloud/src/main/java/org/jclouds/vcloud/functions/NetworksInOrg.java b/apis/vcloud/src/main/java/org/jclouds/vcloud/functions/NetworksInOrg.java index fa2028bd3a..4c943fae8a 100644 --- a/apis/vcloud/src/main/java/org/jclouds/vcloud/functions/NetworksInOrg.java +++ b/apis/vcloud/src/main/java/org/jclouds/vcloud/functions/NetworksInOrg.java @@ -30,7 +30,6 @@ import javax.inject.Singleton; import org.jclouds.Constants; import org.jclouds.logging.Logger; -import org.jclouds.util.Iterables2; import org.jclouds.vcloud.VCloudAsyncClient; import org.jclouds.vcloud.domain.Org; import org.jclouds.vcloud.domain.ReferenceType; @@ -57,16 +56,12 @@ public class NetworksInOrg implements Function> { @Override public Iterable apply(final Org org) { - - Iterable networkItems = transformParallel(org.getNetworks().values(), - new Function>() { - @Override - public Future apply(ReferenceType from) { - return aclient.getNetworkClient().getNetwork(from.getHref()); - } - - }, executor, null, logger, "OrgNetworks in org " + org.getName()); - return Iterables2.concreteCopy(networkItems); + return transformParallel(org.getNetworks().values(), new Function>() { + @Override + public Future apply(ReferenceType from) { + return aclient.getNetworkClient().getNetwork(from.getHref()); + } + }, executor, null, logger, "OrgNetworks in org " + org.getName()); } } diff --git a/apis/vcloud/src/main/java/org/jclouds/vcloud/functions/OrgsForLocations.java b/apis/vcloud/src/main/java/org/jclouds/vcloud/functions/OrgsForLocations.java index 0c457e3b40..880fa48da2 100644 --- a/apis/vcloud/src/main/java/org/jclouds/vcloud/functions/OrgsForLocations.java +++ b/apis/vcloud/src/main/java/org/jclouds/vcloud/functions/OrgsForLocations.java @@ -18,8 +18,6 @@ */ package org.jclouds.vcloud.functions; -import static com.google.common.collect.Iterables.filter; -import static com.google.common.collect.Iterables.transform; import static org.jclouds.concurrent.FutureIterables.transformParallel; import java.net.URI; @@ -35,13 +33,12 @@ import org.jclouds.Constants; import org.jclouds.domain.Location; import org.jclouds.domain.LocationScope; import org.jclouds.logging.Logger; -import org.jclouds.util.Iterables2; import org.jclouds.vcloud.VCloudAsyncClient; import org.jclouds.vcloud.domain.Org; import com.google.common.base.Function; import com.google.common.base.Predicate; -import com.google.common.collect.Sets; +import com.google.common.collect.FluentIterable; /** * @author Adrian Cole @@ -65,29 +62,23 @@ public class OrgsForLocations implements Function, Iterable apply(Iterable from) { - - return Iterables2.concreteCopy(transformParallel(Sets.newLinkedHashSet(transform(filter(from, new Predicate() { - + FluentIterable uris = FluentIterable.from(from).filter(new Predicate() { @Override public boolean apply(Location input) { return input.getScope() == LocationScope.ZONE; } - - }), new Function() { - + }).transform(new Function() { @Override public URI apply(Location from) { return URI.create(from.getParent().getId()); } - - })), new Function>() { - + }); + return transformParallel(uris, new Function>() { @Override public Future apply(URI from) { return aclient.getOrgClient().getOrg(from); } - - }, executor, null, logger, "organizations for uris")); + }, executor, null, logger, "organizations for uris"); } } diff --git a/apis/vcloud/src/main/java/org/jclouds/vcloud/functions/OrgsForNames.java b/apis/vcloud/src/main/java/org/jclouds/vcloud/functions/OrgsForNames.java index ee905c7374..0774082467 100644 --- a/apis/vcloud/src/main/java/org/jclouds/vcloud/functions/OrgsForNames.java +++ b/apis/vcloud/src/main/java/org/jclouds/vcloud/functions/OrgsForNames.java @@ -30,7 +30,6 @@ import javax.inject.Singleton; import org.jclouds.Constants; import org.jclouds.logging.Logger; -import org.jclouds.util.Iterables2; import org.jclouds.vcloud.VCloudAsyncClient; import org.jclouds.vcloud.domain.Org; diff --git a/apis/vcloud/src/main/java/org/jclouds/vcloud/functions/VAppTemplatesInOrg.java b/apis/vcloud/src/main/java/org/jclouds/vcloud/functions/VAppTemplatesInOrg.java index 12c1165697..7d28b9e67a 100644 --- a/apis/vcloud/src/main/java/org/jclouds/vcloud/functions/VAppTemplatesInOrg.java +++ b/apis/vcloud/src/main/java/org/jclouds/vcloud/functions/VAppTemplatesInOrg.java @@ -25,7 +25,6 @@ import static com.google.common.collect.Iterables.filter; import javax.inject.Inject; import javax.inject.Singleton; -import org.jclouds.util.Iterables2; import org.jclouds.vcloud.domain.CatalogItem; import org.jclouds.vcloud.domain.Org; import org.jclouds.vcloud.domain.Status; @@ -54,17 +53,14 @@ public class VAppTemplatesInOrg implements Function> @Override public Iterable apply(Org from) { Iterable catalogs = allCatalogItemsInOrg.apply(from); - Iterable vAppTemplates = Iterables2.concreteCopy(vAppTemplatesForCatalogItems.apply(catalogs)); + Iterable vAppTemplates = vAppTemplatesForCatalogItems.apply(catalogs); return filter(vAppTemplates, and(notNull(), new Predicate(){ - - //TODO: test this @Override public boolean apply(VAppTemplate input) { if (input == null) return false; return ImmutableSet.of(Status.RESOLVED, Status.OFF).contains(input.getStatus()); } - })); } diff --git a/apis/vcloud/src/main/java/org/jclouds/vcloud/functions/VDCsInOrg.java b/apis/vcloud/src/main/java/org/jclouds/vcloud/functions/VDCsInOrg.java index 2d82eb57b2..76e77a6c62 100644 --- a/apis/vcloud/src/main/java/org/jclouds/vcloud/functions/VDCsInOrg.java +++ b/apis/vcloud/src/main/java/org/jclouds/vcloud/functions/VDCsInOrg.java @@ -30,7 +30,6 @@ import javax.inject.Singleton; import org.jclouds.Constants; import org.jclouds.logging.Logger; -import org.jclouds.util.Iterables2; import org.jclouds.vcloud.VCloudAsyncClient; import org.jclouds.vcloud.domain.Org; import org.jclouds.vcloud.domain.ReferenceType; @@ -57,16 +56,13 @@ public class VDCsInOrg implements Function> { @Override public Iterable apply(final Org org) { + return transformParallel(org.getVDCs().values(), new Function>() { + @Override + public Future apply(ReferenceType from) { + return aclient.getVDCClient().getVDC(from.getHref()); + } - Iterable catalogItems = transformParallel(org.getVDCs().values(), - new Function>() { - @Override - public Future apply(ReferenceType from) { - return aclient.getVDCClient().getVDC(from.getHref()); - } - - }, executor, null, logger, "vdcs in org " + org.getName()); - return Iterables2.concreteCopy(catalogItems); + }, executor, null, logger, "vdcs in org " + org.getName()); } } diff --git a/blobstore/src/main/java/org/jclouds/blobstore/util/BlobStoreUtils.java b/blobstore/src/main/java/org/jclouds/blobstore/util/BlobStoreUtils.java index dc6acbe933..2801af0122 100644 --- a/blobstore/src/main/java/org/jclouds/blobstore/util/BlobStoreUtils.java +++ b/blobstore/src/main/java/org/jclouds/blobstore/util/BlobStoreUtils.java @@ -20,29 +20,19 @@ package org.jclouds.blobstore.util; import static com.google.common.base.Preconditions.checkNotNull; -import java.io.IOException; -import java.io.InputStream; import java.util.Map; import java.util.regex.Matcher; import java.util.regex.Pattern; import org.jclouds.blobstore.AsyncBlobStore; -import org.jclouds.blobstore.BlobStore; import org.jclouds.blobstore.BlobStoreContext; -import org.jclouds.blobstore.ContainerNotFoundException; -import org.jclouds.blobstore.KeyNotFoundException; import org.jclouds.blobstore.domain.Blob; -import org.jclouds.blobstore.domain.BlobMetadata; import org.jclouds.blobstore.domain.MutableBlobMetadata; -import org.jclouds.blobstore.domain.StorageMetadata; import org.jclouds.blobstore.domain.internal.MutableBlobMetadataImpl; import org.jclouds.blobstore.functions.BlobName; -import org.jclouds.functions.ExceptionToValueOrPropagate; import org.jclouds.http.HttpRequest; import org.jclouds.http.HttpRequestFilter; -import org.jclouds.http.HttpUtils; import org.jclouds.rest.internal.GeneratedHttpRequest; -import org.jclouds.util.Strings2; import com.google.common.collect.Maps; import com.google.common.reflect.TypeToken; @@ -62,50 +52,6 @@ public class BlobStoreUtils { .headers(returnVal.getHeaders()).payload(returnVal.getPayload()).build(); } - public static final ExceptionToValueOrPropagate keyNotFoundToNullOrPropagate = new ExceptionToValueOrPropagate( - KeyNotFoundException.class, null); - - public static final ExceptionToValueOrPropagate containerNotFoundToNullOrPropagate = new ExceptionToValueOrPropagate( - ContainerNotFoundException.class, null); - - @SuppressWarnings("unchecked") - public static T keyNotFoundToNullOrPropagate(Exception e) { - return (T) keyNotFoundToNullOrPropagate.apply(e); - } - - @SuppressWarnings("unchecked") - public static T containerNotFoundToNullOrPropagate(Exception e) { - return (T) containerNotFoundToNullOrPropagate.apply(e); - } - - public static Blob newBlob(BlobStore blobStore, StorageMetadata blobMeta) { - Blob blob = checkNotNull(blobStore, "blobStore").blobBuilder(checkNotNull(blobMeta, "blobMeta").getName()) - .userMetadata(blobMeta.getUserMetadata()).build(); - if (blobMeta instanceof BlobMetadata) { - HttpUtils.copy(((BlobMetadata) blobMeta).getContentMetadata(), blob.getMetadata().getContentMetadata()); - } - blob.getMetadata().setETag(blobMeta.getETag()); - blob.getMetadata().setId(blobMeta.getProviderId()); - blob.getMetadata().setLastModified(blobMeta.getLastModified()); - blob.getMetadata().setLocation(blobMeta.getLocation()); - blob.getMetadata().setUri(blobMeta.getUri()); - return blob; - } - - public static String parseContainerFromPath(String path) { - String container = checkNotNull(path, "path"); - if (path.indexOf('/') != -1) - container = path.substring(0, path.indexOf('/')); - return container; - } - - public static String parsePrefixFromPath(String path) { - String prefix = null; - if (checkNotNull(path, "path").indexOf('/') != -1) - prefix = path.substring(path.indexOf('/') + 1); - return "".equals(prefix) ? null : prefix; - } - public static String parseDirectoryFromPath(String path) { return checkNotNull(path, "path").substring(0, path.lastIndexOf('/')); } @@ -131,19 +77,6 @@ public class BlobStoreUtils { return objectKey; } - public static String getContentAsStringOrNullAndClose(Blob blob) throws IOException { - checkNotNull(blob, "blob"); - checkNotNull(blob.getPayload(), "blob.payload"); - if (blob.getPayload().getInput() == null) - return null; - Object o = blob.getPayload().getInput(); - if (o instanceof InputStream) { - return Strings2.toStringAndClose((InputStream) o); - } else { - throw new IllegalArgumentException("Object type not supported: " + o.getClass().getName()); - } - } - private static final BlobName blobName = new BlobName(); public static ListenableFuture createParentIfNeededAsync(AsyncBlobStore asyncBlobStore, String container, diff --git a/blobstore/src/test/java/org/jclouds/blobstore/integration/internal/BaseBlobIntegrationTest.java b/blobstore/src/test/java/org/jclouds/blobstore/integration/internal/BaseBlobIntegrationTest.java index be6cd6dfb4..ce4fdca825 100644 --- a/blobstore/src/test/java/org/jclouds/blobstore/integration/internal/BaseBlobIntegrationTest.java +++ b/blobstore/src/test/java/org/jclouds/blobstore/integration/internal/BaseBlobIntegrationTest.java @@ -25,7 +25,6 @@ import static org.jclouds.blobstore.options.GetOptions.Builder.ifETagMatches; import static org.jclouds.blobstore.options.GetOptions.Builder.ifModifiedSince; import static org.jclouds.blobstore.options.GetOptions.Builder.ifUnmodifiedSince; import static org.jclouds.blobstore.options.GetOptions.Builder.range; -import static org.jclouds.blobstore.util.BlobStoreUtils.getContentAsStringOrNullAndClose; import static org.jclouds.concurrent.FutureIterables.awaitCompletion; import static org.jclouds.io.ByteSources.asByteSource; import static org.testng.Assert.assertEquals; diff --git a/blobstore/src/test/java/org/jclouds/blobstore/integration/internal/BaseBlobMapIntegrationTest.java b/blobstore/src/test/java/org/jclouds/blobstore/integration/internal/BaseBlobMapIntegrationTest.java index adcc70132b..4b36702c33 100644 --- a/blobstore/src/test/java/org/jclouds/blobstore/integration/internal/BaseBlobMapIntegrationTest.java +++ b/blobstore/src/test/java/org/jclouds/blobstore/integration/internal/BaseBlobMapIntegrationTest.java @@ -21,7 +21,6 @@ package org.jclouds.blobstore.integration.internal; import static com.google.common.base.Preconditions.checkNotNull; import static org.jclouds.blobstore.options.ListContainerOptions.Builder.inDirectory; import static org.jclouds.blobstore.options.ListContainerOptions.Builder.maxResults; -import static org.jclouds.blobstore.util.BlobStoreUtils.getContentAsStringOrNullAndClose; import static org.testng.Assert.assertEquals; import java.io.IOException; diff --git a/blobstore/src/test/java/org/jclouds/blobstore/integration/internal/BaseBlobStoreIntegrationTest.java b/blobstore/src/test/java/org/jclouds/blobstore/integration/internal/BaseBlobStoreIntegrationTest.java index b63cb0768d..e147f0dfeb 100644 --- a/blobstore/src/test/java/org/jclouds/blobstore/integration/internal/BaseBlobStoreIntegrationTest.java +++ b/blobstore/src/test/java/org/jclouds/blobstore/integration/internal/BaseBlobStoreIntegrationTest.java @@ -18,11 +18,12 @@ */ package org.jclouds.blobstore.integration.internal; +import static com.google.common.base.Preconditions.checkNotNull; import static com.google.common.base.Throwables.propagateIfPossible; -import static org.jclouds.blobstore.util.BlobStoreUtils.getContentAsStringOrNullAndClose; import static org.testng.Assert.assertEquals; import java.io.IOException; +import java.io.InputStream; import java.security.SecureRandom; import java.util.Date; import java.util.Map; @@ -48,6 +49,7 @@ import org.jclouds.blobstore.domain.StorageType; import org.jclouds.domain.Location; import org.jclouds.http.config.JavaUrlHttpCommandExecutorServiceModule; import org.jclouds.javax.annotation.Nullable; +import org.jclouds.util.Strings2; import org.testng.ITestContext; import org.testng.annotations.AfterClass; import org.testng.annotations.BeforeClass; @@ -64,6 +66,7 @@ import com.google.common.reflect.TypeToken; import com.google.inject.Module; public class BaseBlobStoreIntegrationTest extends BaseViewLiveTest { + protected static final String LOCAL_ENCODING = System.getProperty("file.encoding"); protected static final String XML_STRING_FORMAT = " "; protected static final String TEST_STRING = String.format(XML_STRING_FORMAT, "apple"); @@ -501,6 +504,18 @@ public class BaseBlobStoreIntegrationTest extends BaseViewLiveTest { public Auth(Token token, Multimap serviceCatalog) { this.token = checkNotNull(token, "token"); - this.serviceCatalog = Multimaps2.toOldSchool(ImmutableMultimap.copyOf(checkNotNull(serviceCatalog, - "serviceCatalog"))); + this.serviceCatalog = toOldSchool(ImmutableMultimap.copyOf(checkNotNull(serviceCatalog, "serviceCatalog"))); } + /** + * The traditional way to represent a graph in Java is Map>, which is awkward in a number of ways. Guava's + * Multimap framework makes it easy to handle a mapping from keys to multiple values. + *

+ * Until we write or discover a gson Multimap deserializer, we may be stuck with this. + * + * TODO: ask on stackoverflow and/or jesse wilson + */ + @Deprecated + private static Map> toOldSchool(Multimap in) { + ImmutableMap.Builder> out = ImmutableMap.builder(); + for (K type : in.keySet()) + out.put(type, ImmutableSet.copyOf(in.get(type))); + return out.build(); + } + + /** + * @see #toOldSchool + */ + @Deprecated + private static ImmutableMultimap fromOldSchool(Map> in) { + ImmutableMultimap.Builder out = ImmutableMultimap.builder(); + for (K type : in.keySet()) + out.putAll(type, ImmutableSet.copyOf(in.get(type))); + return out.build(); + } + /** * TODO */ @@ -106,7 +131,7 @@ public class Auth implements Comparable { * TODO */ public Multimap getServiceCatalog() { - return Multimaps2.fromOldSchool(serviceCatalog); + return fromOldSchool(serviceCatalog); } @Override diff --git a/common/trmk/src/main/java/org/jclouds/trmk/vcloud_0_8/config/DefaultOrgForUser.java b/common/trmk/src/main/java/org/jclouds/trmk/vcloud_0_8/config/DefaultOrgForUser.java index dd974a18c5..b383b803d7 100644 --- a/common/trmk/src/main/java/org/jclouds/trmk/vcloud_0_8/config/DefaultOrgForUser.java +++ b/common/trmk/src/main/java/org/jclouds/trmk/vcloud_0_8/config/DefaultOrgForUser.java @@ -30,11 +30,11 @@ import org.jclouds.trmk.vcloud_0_8.domain.ReferenceType; import org.jclouds.trmk.vcloud_0_8.domain.VCloudSession; import org.jclouds.trmk.vcloud_0_8.endpoints.Org; import org.jclouds.trmk.vcloud_0_8.suppliers.OnlyReferenceTypeFirstWithNameMatchingConfigurationKeyOrDefault; -import org.jclouds.util.Suppliers2; import com.google.common.base.Function; import com.google.common.base.Predicate; import com.google.common.base.Supplier; +import com.google.common.base.Suppliers; /** * @@ -57,7 +57,7 @@ public class DefaultOrgForUser implements Function apply(final String user) { - return Suppliers2.compose(new Function() { + return Suppliers.compose(new Function() { @Override public ReferenceType apply(VCloudSession session) { diff --git a/common/trmk/src/main/java/org/jclouds/trmk/vcloud_0_8/config/DefaultVCloudReferencesModule.java b/common/trmk/src/main/java/org/jclouds/trmk/vcloud_0_8/config/DefaultVCloudReferencesModule.java index c2b2efd86e..2721aa1c55 100644 --- a/common/trmk/src/main/java/org/jclouds/trmk/vcloud_0_8/config/DefaultVCloudReferencesModule.java +++ b/common/trmk/src/main/java/org/jclouds/trmk/vcloud_0_8/config/DefaultVCloudReferencesModule.java @@ -70,7 +70,7 @@ public class DefaultVCloudReferencesModule extends AbstractModule { @Singleton protected Supplier provideDefaultTasksList(DefaultTasksListForOrg defaultTasksListURIForOrg, @org.jclouds.trmk.vcloud_0_8.endpoints.Org Supplier defaultOrg) { - return Suppliers2.compose(defaultTasksListURIForOrg, defaultOrg); + return Suppliers.compose(defaultTasksListURIForOrg, defaultOrg); } @Provides @@ -85,7 +85,7 @@ public class DefaultVCloudReferencesModule extends AbstractModule { @Singleton protected Supplier provideDefaultCatalog(DefaultCatalogForOrg defaultCatalogURIForOrg, @org.jclouds.trmk.vcloud_0_8.endpoints.Org Supplier defaultOrg) { - return Suppliers2.compose(defaultCatalogURIForOrg, defaultOrg); + return Suppliers.compose(defaultCatalogURIForOrg, defaultOrg); } @Provides @@ -122,7 +122,7 @@ public class DefaultVCloudReferencesModule extends AbstractModule { @Singleton protected Supplier provideDefaultVDC(DefaultVDCForOrg defaultVDCURIForOrg, @org.jclouds.trmk.vcloud_0_8.endpoints.Org Supplier defaultOrg) { - return Suppliers2.compose(defaultVDCURIForOrg, defaultOrg); + return Suppliers.compose(defaultVDCURIForOrg, defaultOrg); } @Provides @@ -137,7 +137,7 @@ public class DefaultVCloudReferencesModule extends AbstractModule { @Singleton protected Supplier provideDefaultNetwork(DefaultNetworkForVDC defaultNetworkURIForVDC, @org.jclouds.trmk.vcloud_0_8.endpoints.VDC Supplier defaultVDC) { - return Suppliers2.compose(defaultNetworkURIForVDC, defaultVDC); + return Suppliers.compose(defaultNetworkURIForVDC, defaultVDC); } @Provides diff --git a/common/trmk/src/main/java/org/jclouds/trmk/vcloud_0_8/config/TerremarkVCloudRestClientModule.java b/common/trmk/src/main/java/org/jclouds/trmk/vcloud_0_8/config/TerremarkVCloudRestClientModule.java index 76e662097e..75fefd92f0 100644 --- a/common/trmk/src/main/java/org/jclouds/trmk/vcloud_0_8/config/TerremarkVCloudRestClientModule.java +++ b/common/trmk/src/main/java/org/jclouds/trmk/vcloud_0_8/config/TerremarkVCloudRestClientModule.java @@ -82,12 +82,12 @@ import org.jclouds.trmk.vcloud_0_8.location.DefaultVDC; import org.jclouds.trmk.vcloud_0_8.location.OrgAndVDCToLocationSupplier; import org.jclouds.trmk.vcloud_0_8.predicates.TaskSuccess; import org.jclouds.util.Strings2; -import org.jclouds.util.Suppliers2; import com.google.common.base.Function; import com.google.common.base.Objects; import com.google.common.base.Predicate; import com.google.common.base.Supplier; +import com.google.common.base.Suppliers; import com.google.common.collect.ImmutableMap; import com.google.common.collect.ImmutableMap.Builder; import com.google.common.collect.Maps; @@ -143,7 +143,7 @@ public class TerremarkVCloudRestClientModule extends RestClientModule> provideVDCtoORG( Supplier> orgNameToOrgSupplier) { - return Suppliers2.compose( + return Suppliers.compose( new Function, Map>() { @Override @@ -173,7 +173,7 @@ public class TerremarkVCloudRestClientModule extends RestClientModule provideOrgListURI(Supplier sessionSupplier) { - return Suppliers2.compose(new Function() { + return Suppliers.compose(new Function() { @Override public URI apply(VCloudSession arg0) { @@ -352,7 +352,7 @@ public class TerremarkVCloudRestClientModule extends RestClientModule provideOrg( final Supplier> orgSupplier, @org.jclouds.trmk.vcloud_0_8.endpoints.Org Supplier defaultOrg) { - return Suppliers2.compose(new Function() { + return Suppliers.compose(new Function() { @Override public org.jclouds.trmk.vcloud_0_8.domain.Org apply(ReferenceType input) { diff --git a/compute/src/main/java/org/jclouds/compute/config/BaseComputeServiceContextModule.java b/compute/src/main/java/org/jclouds/compute/config/BaseComputeServiceContextModule.java index e405af259d..849dee13d7 100644 --- a/compute/src/main/java/org/jclouds/compute/config/BaseComputeServiceContextModule.java +++ b/compute/src/main/java/org/jclouds/compute/config/BaseComputeServiceContextModule.java @@ -62,11 +62,11 @@ import org.jclouds.rest.AuthorizationException; import org.jclouds.rest.suppliers.MemoizedRetryOnTimeOutButNotOnAuthorizationExceptionSupplier; import org.jclouds.scriptbuilder.domain.Statement; import org.jclouds.ssh.SshClient; -import org.jclouds.util.Suppliers2; import com.google.common.base.Function; import com.google.common.base.Optional; import com.google.common.base.Supplier; +import com.google.common.base.Suppliers; import com.google.common.collect.ImmutableMap; import com.google.common.collect.Maps; import com.google.inject.AbstractModule; @@ -213,7 +213,7 @@ public abstract class BaseComputeServiceContextModule extends AbstractModule { @Provides @Singleton protected Supplier> provideImageMap(@Memoized Supplier> images) { - return Suppliers2.compose(new Function, Map>() { + return Suppliers.compose(new Function, Map>() { @Override public Map apply(Set from) { @@ -263,7 +263,7 @@ public abstract class BaseComputeServiceContextModule extends AbstractModule { @Provides @Singleton protected Supplier> provideSizeMap(@Memoized Supplier> sizes) { - return Suppliers2.compose(new Function, Map>() { + return Suppliers.compose(new Function, Map>() { @Override public Map apply(Set from) { diff --git a/compute/src/main/java/org/jclouds/compute/domain/internal/TemplateBuilderImpl.java b/compute/src/main/java/org/jclouds/compute/domain/internal/TemplateBuilderImpl.java index 886ce9dd2b..f35ea644fa 100644 --- a/compute/src/main/java/org/jclouds/compute/domain/internal/TemplateBuilderImpl.java +++ b/compute/src/main/java/org/jclouds/compute/domain/internal/TemplateBuilderImpl.java @@ -32,6 +32,8 @@ import static org.jclouds.compute.util.ComputeServiceUtils.getCores; import static org.jclouds.compute.util.ComputeServiceUtils.getCoresAndSpeed; import static org.jclouds.compute.util.ComputeServiceUtils.getSpace; +import java.util.Comparator; +import java.util.Iterator; import java.util.List; import java.util.NoSuchElementException; import java.util.Set; @@ -55,7 +57,6 @@ import org.jclouds.compute.options.TemplateOptions; import org.jclouds.compute.reference.ComputeServiceConstants; import org.jclouds.domain.Location; import org.jclouds.logging.Logger; -import org.jclouds.util.Lists2; import com.google.common.annotations.VisibleForTesting; import com.google.common.base.Function; @@ -800,7 +801,7 @@ public class TemplateBuilderImpl implements TemplateBuilder { Iterable matchingImages = filter(supportedImages, imagePredicate); if (logger.isTraceEnabled()) logger.trace("<< matched images(%s)", transform(matchingImages, imageToId)); - List maxImages = Lists2.multiMax(DEFAULT_IMAGE_ORDERING, matchingImages); + List maxImages = multiMax(DEFAULT_IMAGE_ORDERING, matchingImages); if (logger.isTraceEnabled()) logger.trace("<< best images(%s)", transform(maxImages, imageToId)); return maxImages.get(maxImages.size() - 1); @@ -811,7 +812,28 @@ public class TemplateBuilderImpl implements TemplateBuilder { return null; } } - + + /** + * Like Ordering, but handle the case where there are multiple valid maximums + */ + @SuppressWarnings("unchecked") + @VisibleForTesting + static List multiMax(Comparator ordering, Iterable iterable) { + Iterator iterator = iterable.iterator(); + List maxes = newArrayList(iterator.next()); + E maxSoFar = maxes.get(0); + while (iterator.hasNext()) { + E current = iterator.next(); + int comparison = ordering.compare(maxSoFar, current); + if (comparison == 0) { + maxes.add(current); + } else if (comparison < 0) { + maxes = newArrayList(current); + maxSoFar = current; + } + } + return maxes; + } protected Set getImages() { return images.get(); } diff --git a/compute/src/test/java/org/jclouds/compute/domain/internal/TemplateBuilderImplTest.java b/compute/src/test/java/org/jclouds/compute/domain/internal/TemplateBuilderImplTest.java index 8a585d6d4b..844b0656a1 100644 --- a/compute/src/test/java/org/jclouds/compute/domain/internal/TemplateBuilderImplTest.java +++ b/compute/src/test/java/org/jclouds/compute/domain/internal/TemplateBuilderImplTest.java @@ -33,6 +33,7 @@ import javax.inject.Provider; import org.jclouds.compute.domain.Hardware; import org.jclouds.compute.domain.HardwareBuilder; import org.jclouds.compute.domain.Image; +import org.jclouds.compute.domain.Image.Status; import org.jclouds.compute.domain.ImageBuilder; import org.jclouds.compute.domain.OperatingSystem; import org.jclouds.compute.domain.OsFamily; @@ -40,7 +41,6 @@ import org.jclouds.compute.domain.Processor; import org.jclouds.compute.domain.Template; import org.jclouds.compute.domain.TemplateBuilder; import org.jclouds.compute.domain.Volume; -import org.jclouds.compute.domain.Image.Status; import org.jclouds.compute.options.TemplateOptions; import org.jclouds.compute.predicates.ImagePredicates; import org.jclouds.domain.Location; @@ -52,6 +52,7 @@ import com.google.common.base.Supplier; import com.google.common.base.Suppliers; import com.google.common.collect.ImmutableList; import com.google.common.collect.ImmutableSet; +import com.google.common.collect.Ordering; /** * @@ -59,6 +60,17 @@ import com.google.common.collect.ImmutableSet; */ @Test(groups = "unit", singleThreaded = true, testName = "TemplateBuilderImplTest") public class TemplateBuilderImplTest { + + public void testMultiMax() { + Iterable values = ImmutableList.of("1", "2", "2", "3", "3"); + assertEquals(TemplateBuilderImpl.multiMax(Ordering.natural(), values), ImmutableList.of("3", "3")); + } + + public void testMultiMax1() { + Iterable values = ImmutableList.of("1", "2", "2", "3"); + assertEquals(TemplateBuilderImpl.multiMax(Ordering.natural(), values), ImmutableList.of("3")); + } + protected Location provider = new LocationBuilder().scope(LocationScope.PROVIDER).id("aws-ec2").description("aws-ec2").build(); protected Location region = new LocationBuilder().scope(LocationScope.REGION).id("us-east-1") diff --git a/core/src/main/java/org/jclouds/Fallbacks.java b/core/src/main/java/org/jclouds/Fallbacks.java index b06b80eea7..7947a6e8b3 100644 --- a/core/src/main/java/org/jclouds/Fallbacks.java +++ b/core/src/main/java/org/jclouds/Fallbacks.java @@ -25,12 +25,13 @@ import static com.google.common.primitives.Ints.asList; import static com.google.common.util.concurrent.Futures.immediateFuture; import static org.jclouds.http.HttpUtils.contains404; import static org.jclouds.http.HttpUtils.returnValueOnCodeOrNull; -import static org.jclouds.util.Throwables2.containsResourceNotFoundException; +import static org.jclouds.util.Throwables2.getFirstThrowableOfType; import org.jclouds.collect.IterableWithMarker; import org.jclouds.collect.IterableWithMarkers; import org.jclouds.collect.PagedIterable; import org.jclouds.collect.PagedIterables; +import org.jclouds.rest.ResourceNotFoundException; import com.google.common.base.Optional; import com.google.common.collect.FluentIterable; @@ -157,4 +158,8 @@ public final class Fallbacks { throw propagate(t); } + private static boolean containsResourceNotFoundException(Throwable from) { + return getFirstThrowableOfType(from, ResourceNotFoundException.class) != null; + } + } \ No newline at end of file diff --git a/core/src/main/java/org/jclouds/domain/JsonBall.java b/core/src/main/java/org/jclouds/domain/JsonBall.java index 84e69602f1..a00f84daa5 100644 --- a/core/src/main/java/org/jclouds/domain/JsonBall.java +++ b/core/src/main/java/org/jclouds/domain/JsonBall.java @@ -20,7 +20,7 @@ package org.jclouds.domain; import static com.google.common.base.Preconditions.checkNotNull; -import org.jclouds.util.Patterns; +import java.util.regex.Pattern; /** * @@ -30,7 +30,11 @@ import org.jclouds.util.Patterns; * @see */ public class JsonBall implements Comparable, CharSequence { - + + public static final Pattern JSON_STRING_PATTERN = Pattern.compile("^[^\"\\{\\[].*[^\\{\\[\"]$"); + public static final Pattern JSON_NUMBER_PATTERN = Pattern.compile("^[0-9]*\\.?[0-9]*$"); + public static final Pattern JSON_BOOLEAN_PATTERN = Pattern.compile("^(true|false)$"); + private final String value; @Override @@ -82,10 +86,10 @@ public class JsonBall implements Comparable, CharSequence { public JsonBall(String value) { this.value = quoteStringIfNotNumberOrBoolean(checkNotNull(value, "value")); } - + static String quoteStringIfNotNumberOrBoolean(String in) { - if (Patterns.JSON_STRING_PATTERN.matcher(in).find() && !Patterns.JSON_NUMBER_PATTERN.matcher(in).find() - && !Patterns.JSON_BOOLEAN_PATTERN.matcher(in).find()) { + if (JSON_STRING_PATTERN.matcher(in).find() && !JSON_NUMBER_PATTERN.matcher(in).find() + && !JSON_BOOLEAN_PATTERN.matcher(in).find()) { return "\"" + in + "\""; } return in; diff --git a/core/src/main/java/org/jclouds/domain/LoginCredentials.java b/core/src/main/java/org/jclouds/domain/LoginCredentials.java index 890a74f34e..6f2f4d51a4 100644 --- a/core/src/main/java/org/jclouds/domain/LoginCredentials.java +++ b/core/src/main/java/org/jclouds/domain/LoginCredentials.java @@ -18,8 +18,8 @@ */ package org.jclouds.domain; +import org.jclouds.crypto.Pems; import org.jclouds.javax.annotation.Nullable; -import org.jclouds.util.CredentialUtils; import com.google.common.base.Optional; @@ -27,7 +27,12 @@ import com.google.common.base.Optional; * @author Adrian Cole */ public class LoginCredentials extends Credentials { - + + public static boolean isPrivateKeyCredential(String credential) { + return credential != null + && (credential.startsWith(Pems.PRIVATE_PKCS1_MARKER) || credential.startsWith(Pems.PRIVATE_PKCS8_MARKER)); + } + public static LoginCredentials fromCredentials(Credentials creds) { if (creds == null) return null; @@ -48,7 +53,7 @@ public class LoginCredentials extends Credentials { public static Builder builder() { return new Builder(); } - + public static class Builder extends Credentials.Builder { private boolean authenticateSudo; private Optional password; @@ -87,7 +92,7 @@ public class LoginCredentials extends Credentials { } public Builder credential(String credential) { - if (CredentialUtils.isPrivateKeyCredential(credential)) + if (isPrivateKeyCredential(credential)) return noPassword().privateKey(credential); else if (credential != null) return password(credential).noPrivateKey(); @@ -119,7 +124,7 @@ public class LoginCredentials extends Credentials { } public LoginCredentials(String username, @Nullable Optional password, @Nullable Optional privateKey, boolean authenticateSudo) { - super(username, privateKey != null && privateKey.isPresent() && CredentialUtils.isPrivateKeyCredential(privateKey.get()) + super(username, privateKey != null && privateKey.isPresent() && isPrivateKeyCredential(privateKey.get()) ? privateKey.get() : (password != null && password.isPresent() ? password.get() : null)); this.authenticateSudo = authenticateSudo; diff --git a/core/src/main/java/org/jclouds/functions/ExceptionToValueOrPropagate.java b/core/src/main/java/org/jclouds/functions/ExceptionToValueOrPropagate.java deleted file mode 100644 index acad8a399f..0000000000 --- a/core/src/main/java/org/jclouds/functions/ExceptionToValueOrPropagate.java +++ /dev/null @@ -1,55 +0,0 @@ -/** - * Licensed to jclouds, Inc. (jclouds) under one or more - * contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. jclouds licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - */ -package org.jclouds.functions; - -import static com.google.common.base.Preconditions.checkNotNull; - -import java.util.List; - -import org.jclouds.javax.annotation.Nullable; - -import com.google.common.base.Function; -import com.google.common.base.Throwables; -import com.google.common.collect.Iterables; - -/** - * - * @author Adrian Cole - */ -public class ExceptionToValueOrPropagate implements Function { - - private final Class matchingClass; - private final T value; - - public ExceptionToValueOrPropagate(Class matchingClass, @Nullable T value) { - this.matchingClass = checkNotNull(matchingClass, "matchingClass"); - this.value = value; - } - - @Override - public T apply(Exception from) { - checkNotNull(from, "exception"); - List throwables = Throwables.getCausalChain(from); - Iterable matchingThrowables = Iterables.filter(throwables, matchingClass); - if (Iterables.size(matchingThrowables) >= 1) - return value; - throw Throwables.propagate(from); - } - -} diff --git a/core/src/main/java/org/jclouds/functions/JoinOnK2.java b/core/src/main/java/org/jclouds/functions/JoinOnK2.java deleted file mode 100644 index 630b9467ba..0000000000 --- a/core/src/main/java/org/jclouds/functions/JoinOnK2.java +++ /dev/null @@ -1,48 +0,0 @@ -/** - * Licensed to jclouds, Inc. (jclouds) under one or more - * contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. jclouds licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - */ -package org.jclouds.functions; - -import java.util.Map; -import java.util.Map.Entry; -import java.util.Set; - -import com.google.common.base.Function; -import com.google.common.base.Supplier; -import com.google.common.collect.ImmutableMap; -import com.google.common.collect.ImmutableMap.Builder; - -public class JoinOnK2 implements Function>>, Map>> { - private final Supplier>> regionToEndpointSupplier; - - public JoinOnK2(Supplier>> regionToEndpointSupplier) { - this.regionToEndpointSupplier = regionToEndpointSupplier; - } - - @Override - public Map> apply(Map>> regionToZones) { - Map> regionToEndpoint = regionToEndpointSupplier.get(); - Builder> builder = ImmutableMap.builder(); - for (Entry>> entry : regionToZones.entrySet()) { - for (K2 zone : entry.getValue().get()) { - builder.put(zone, regionToEndpoint.get(entry.getKey())); - } - } - return builder.build(); - } -} diff --git a/core/src/main/java/org/jclouds/http/functions/ParseContentMD5FromHeaders.java b/core/src/main/java/org/jclouds/http/functions/ParseContentMD5FromHeaders.java deleted file mode 100644 index c1447efa67..0000000000 --- a/core/src/main/java/org/jclouds/http/functions/ParseContentMD5FromHeaders.java +++ /dev/null @@ -1,77 +0,0 @@ -/** - * Licensed to jclouds, Inc. (jclouds) under one or more - * contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. jclouds licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - */ -package org.jclouds.http.functions; - -import static org.jclouds.http.HttpUtils.releasePayload; - -import javax.annotation.Resource; - -import org.jclouds.http.HttpRequest; -import org.jclouds.http.HttpResponse; -import org.jclouds.logging.Logger; -import org.jclouds.rest.InvocationContext; - -import com.google.common.base.Function; - -/** - * @author Adrian Cole - */ -public class ParseContentMD5FromHeaders implements Function, - InvocationContext { - - public static class NoContentMD5Exception extends RuntimeException { - - private final HttpRequest request; - private final HttpResponse response; - - public NoContentMD5Exception(HttpRequest request, HttpResponse response) { - super(String.format("no MD5 returned from request: %s; response %s", request, response)); - this.request = request; - this.response = response; - } - - public HttpRequest getRequest() { - return request; - } - - public HttpResponse getResponse() { - return response; - } - - } - - @Resource - protected Logger logger = Logger.NULL; - private HttpRequest request; - - public byte[] apply(HttpResponse from) { - releasePayload(from); - if (from.getPayload() != null) { - return from.getPayload().getContentMetadata().getContentMD5(); - } - throw new NoContentMD5Exception(request, from); - } - - @Override - public ParseContentMD5FromHeaders setContext(HttpRequest request) { - this.request = request; - return this; - } - -} diff --git a/core/src/main/java/org/jclouds/http/pool/PoolConstants.java b/core/src/main/java/org/jclouds/http/pool/PoolConstants.java deleted file mode 100644 index b35e1dd635..0000000000 --- a/core/src/main/java/org/jclouds/http/pool/PoolConstants.java +++ /dev/null @@ -1,53 +0,0 @@ -/** - * Licensed to jclouds, Inc. (jclouds) under one or more - * contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. jclouds licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - */ -package org.jclouds.http.pool; - -/** - * Properties used in pooling http engines - * - * @author Adrian Cole - */ -public interface PoolConstants { - /** - * Integer property. default (12) - *

- * Limits the amount of connections per host. - */ - public static final String PROPERTY_POOL_MAX_CONNECTIONS = "jclouds.pool.max_connections"; - /** - * Integer property. default (12) - *

- * Amount of threads servicing the I/O of http connections - */ - public static final String PROPERTY_POOL_IO_WORKER_THREADS = "jclouds.http.pool.io_worker_threads"; - - /** - * Integer property. default (2) - *

- * Maximum amount of http session failures before a pool is disabled. - */ - public static final String PROPERTY_POOL_MAX_SESSION_FAILURES = "jclouds.http.pool.max_session_failures"; - /** - * Integer property. default (75) - *

- * Maximum amount of times to re-use an http connection. Services like Amazon S3 throw errors if - * connections are reused too many times. - */ - public static final String PROPERTY_POOL_MAX_CONNECTION_REUSE = "jclouds.http.pool.max_connection_reuse"; -} diff --git a/core/src/main/java/org/jclouds/location/config/LocationModule.java b/core/src/main/java/org/jclouds/location/config/LocationModule.java index 57e6231dbd..334799850c 100644 --- a/core/src/main/java/org/jclouds/location/config/LocationModule.java +++ b/core/src/main/java/org/jclouds/location/config/LocationModule.java @@ -52,12 +52,12 @@ import org.jclouds.location.suppliers.ZoneIdsSupplier; import org.jclouds.rest.AuthorizationException; import org.jclouds.rest.functions.ImplicitOptionalConverter; import org.jclouds.rest.suppliers.MemoizedRetryOnTimeOutButNotOnAuthorizationExceptionSupplier; -import org.jclouds.util.Suppliers2; import com.google.common.base.Function; import com.google.common.base.Optional; import com.google.common.base.Predicate; import com.google.common.base.Supplier; +import com.google.common.base.Suppliers; import com.google.common.collect.Sets; import com.google.inject.AbstractModule; import com.google.inject.Provides; @@ -120,7 +120,7 @@ public class LocationModule extends AbstractModule { protected Supplier> regionIdsSupplier(AtomicReference authException, @Named(PROPERTY_SESSION_INTERVAL) long seconds, RegionIdFilter filter, RegionIdsSupplier uncached) { return MemoizedRetryOnTimeOutButNotOnAuthorizationExceptionSupplier.create(authException, - Suppliers2.compose(new FilterStrings(filter), uncached), seconds, TimeUnit.SECONDS); + Suppliers.compose(new FilterStrings(filter), uncached), seconds, TimeUnit.SECONDS); } @Provides @@ -130,7 +130,7 @@ public class LocationModule extends AbstractModule { AtomicReference authException, @Named(PROPERTY_SESSION_INTERVAL) long seconds, ZoneIdFilter filter, ZoneIdsSupplier uncached) { return MemoizedRetryOnTimeOutButNotOnAuthorizationExceptionSupplier.create(authException, - Suppliers2.compose(new FilterStrings(filter), uncached), seconds, TimeUnit.SECONDS); + Suppliers.compose(new FilterStrings(filter), uncached), seconds, TimeUnit.SECONDS); } static class FilterStrings implements Function, Set>{ diff --git a/core/src/main/java/org/jclouds/rest/config/RestClientModule.java b/core/src/main/java/org/jclouds/rest/config/RestClientModule.java index 920afe9a03..d1776f3641 100644 --- a/core/src/main/java/org/jclouds/rest/config/RestClientModule.java +++ b/core/src/main/java/org/jclouds/rest/config/RestClientModule.java @@ -18,10 +18,13 @@ */ package org.jclouds.rest.config; +import static com.google.common.base.Preconditions.checkState; +import static org.jclouds.rest.config.BinderUtils.bindClientAndAsyncClient; + +import java.lang.reflect.TypeVariable; import java.util.Map; -import static org.jclouds.rest.config.BinderUtils.*; + import org.jclouds.rest.ConfiguresRestClient; -import org.jclouds.util.TypeTokens2; import com.google.common.collect.ImmutableMap; import com.google.common.reflect.TypeToken; @@ -41,14 +44,22 @@ public class RestClientModule extends RestModule { */ protected RestClientModule(Map, Class> sync2Async) { super(sync2Async); - this.syncClientType = TypeTokens2.checkBound(new TypeToken(getClass()) { + this.syncClientType = checkBound(new TypeToken(getClass()) { private static final long serialVersionUID = 1L; }); - this.asyncClientType = TypeTokens2.checkBound(new TypeToken(getClass()) { + this.asyncClientType = checkBound(new TypeToken(getClass()) { private static final long serialVersionUID = 1L; }); } - + + /** + * @throws IllegalStateException if the type is an instanceof {@link TypeVariable} + */ + private static TypeToken checkBound(TypeToken type) throws IllegalStateException { + checkState(!(type.getType() instanceof TypeVariable), + "unbound type variable: %s, use ctor that explicitly assigns this", type); + return type; + } /** * @see #RestClientModule(Map) */ @@ -68,8 +79,8 @@ public class RestClientModule extends RestModule { */ public RestClientModule(TypeToken syncClientType, TypeToken asyncClientType, Map, Class> sync2Async) { super(sync2Async); - this.syncClientType = TypeTokens2.checkBound(syncClientType); - this.asyncClientType = TypeTokens2.checkBound(asyncClientType); + this.syncClientType = checkBound(syncClientType); + this.asyncClientType = checkBound(asyncClientType); } @Override diff --git a/core/src/main/java/org/jclouds/rest/internal/RestAnnotationProcessor.java b/core/src/main/java/org/jclouds/rest/internal/RestAnnotationProcessor.java index 45d9511915..8e8a514a66 100644 --- a/core/src/main/java/org/jclouds/rest/internal/RestAnnotationProcessor.java +++ b/core/src/main/java/org/jclouds/rest/internal/RestAnnotationProcessor.java @@ -48,7 +48,6 @@ import static javax.ws.rs.core.MediaType.APPLICATION_JSON; import static javax.ws.rs.core.MediaType.APPLICATION_XML; import static org.jclouds.http.Uris.uriBuilder; import static org.jclouds.io.Payloads.newPayload; -import static org.jclouds.util.Maps2.convertUnsafe; import static org.jclouds.util.Strings2.replaceTokens; import java.io.InputStream; @@ -59,6 +58,7 @@ import java.lang.reflect.ParameterizedType; import java.lang.reflect.Type; import java.lang.reflect.WildcardType; import java.net.URI; +import java.util.LinkedHashMap; import java.util.List; import java.util.Map; import java.util.Map.Entry; @@ -150,11 +150,13 @@ import com.google.common.cache.CacheBuilder; import com.google.common.cache.CacheLoader; import com.google.common.cache.LoadingCache; import com.google.common.collect.ImmutableList; +import com.google.common.collect.ImmutableMap; import com.google.common.collect.ImmutableMultimap; import com.google.common.collect.ImmutableSet; import com.google.common.collect.ImmutableSet.Builder; import com.google.common.collect.LinkedHashMultimap; import com.google.common.collect.LinkedListMultimap; +import com.google.common.collect.Maps; import com.google.common.collect.Multimap; import com.google.common.primitives.Chars; import com.google.common.util.concurrent.ListenableFuture; @@ -527,7 +529,15 @@ public abstract class RestAnnotationProcessor { utils.checkRequestHasRequiredProperties(request); return request; } - + + private static Map convertUnsafe(Multimap in) { + LinkedHashMap out = Maps.newLinkedHashMap(); + for (Entry entry : in.entries()) { + out.put(entry.getKey(), entry.getValue()); + } + return ImmutableMap.copyOf(out); + } + protected org.jclouds.rest.internal.GeneratedHttpRequest.Builder requestBuilder() { return GeneratedHttpRequest.builder(); } diff --git a/core/src/main/java/org/jclouds/util/ClassLoadingUtils.java b/core/src/main/java/org/jclouds/util/ClassLoadingUtils.java index ba093cb8c6..2603fd8e17 100644 --- a/core/src/main/java/org/jclouds/util/ClassLoadingUtils.java +++ b/core/src/main/java/org/jclouds/util/ClassLoadingUtils.java @@ -28,27 +28,6 @@ public class ClassLoadingUtils { //Utility Class } - /** - * Loads a class using the class loader. - * 1. The class loader of the context class is being used. - * 2. The thread context class loader is being used. - * If both approaches fail, returns null. - * - * @param contextClass The name of a context class to use. - * @param className The name of the class to load - * @return The class or null if no class loader could load the class. - */ - public static Class loadClass(Class contextClass, String className) { - Class clazz = null; - if (contextClass.getClassLoader() != null) { - clazz = silentLoadClass(className, contextClass.getClassLoader()); - } - if (clazz == null && Thread.currentThread().getContextClassLoader() != null) { - clazz = silentLoadClass(className, Thread.currentThread().getContextClassLoader()); - } - return clazz; - } - /** * Returns the url of a resource. * 1. The context class is being used. @@ -69,24 +48,4 @@ public class ClassLoadingUtils { } return url; } - - - /** - * Loads a {@link Class} from the specified {@link ClassLoader} without throwing {@ClassNotFoundException}. - * - * @param className - * @param classLoader - * @return - */ - private static Class silentLoadClass(String className, ClassLoader classLoader) { - Class clazz = null; - if (classLoader != null && className != null) { - try { - clazz = classLoader.loadClass(className); - } catch (ClassNotFoundException e) { - //Ignore and proceed to the next class loader. - } - } - return clazz; - } } diff --git a/core/src/main/java/org/jclouds/util/ConcreteFunction.java b/core/src/main/java/org/jclouds/util/ConcreteFunction.java deleted file mode 100644 index 27ac98c67d..0000000000 --- a/core/src/main/java/org/jclouds/util/ConcreteFunction.java +++ /dev/null @@ -1,45 +0,0 @@ -/** - * Licensed to jclouds, Inc. (jclouds) under one or more - * contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. jclouds licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - */ -package org.jclouds.util; - -import com.google.common.base.Function; - - -/** - * For wrapping covariant functions for passing to non-covariant methods - * - * @author danikov - */ -public class ConcreteFunction implements Function { - private final Function delegate; - - public static ConcreteFunction wrap(Function delegate) { - return new ConcreteFunction(delegate); - } - - public ConcreteFunction(Function delegate) { - this.delegate = delegate; - } - - @Override - public T apply(F input) { - return delegate.apply(input); - } - -} diff --git a/core/src/main/java/org/jclouds/util/CredentialUtils.java b/core/src/main/java/org/jclouds/util/CredentialUtils.java deleted file mode 100644 index 1b09fc547f..0000000000 --- a/core/src/main/java/org/jclouds/util/CredentialUtils.java +++ /dev/null @@ -1,60 +0,0 @@ -/** - * Licensed to jclouds, Inc. (jclouds) under one or more - * contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. jclouds licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - */ -package org.jclouds.util; - -import static com.google.common.base.Preconditions.checkNotNull; - -import org.jclouds.crypto.Pems; -import org.jclouds.domain.Credentials; -import org.jclouds.javax.annotation.Nullable; - - -/** - * - * - * @author Adrian Cole - */ -public class CredentialUtils { - - public static Credentials overrideCredentialsIfSupplied(Credentials defaultCredentials, - @Nullable Credentials overridingCredentials) { - if (overridingCredentials == null) - return defaultCredentials; - String identity = overridingCredentials.identity != null ? overridingCredentials.identity : checkNotNull( - defaultCredentials, "defaultCredentials").identity; - String credential = overridingCredentials.credential != null ? overridingCredentials.credential : checkNotNull( - defaultCredentials, "defaultCredentials").credential; - - return new Credentials(identity, credential); - } - - public static boolean isPrivateKeyCredential(Credentials credentials) { - return credentials != null && isPrivateKeyCredential(credentials.credential); - } - - public static boolean isPrivateKeyCredential(String credential) { - return credential != null - && (credential.startsWith(Pems.PRIVATE_PKCS1_MARKER) || credential.startsWith(Pems.PRIVATE_PKCS8_MARKER)); - } - - public static boolean isPrivateKeyEncrypted(byte[] privateKey) { - return new String(privateKey).contains("Proc-Type: 4,ENCRYPTED"); - } - -} diff --git a/core/src/main/java/org/jclouds/util/InputStreamChain.java b/core/src/main/java/org/jclouds/util/InputStreamChain.java deleted file mode 100644 index deb2645d88..0000000000 --- a/core/src/main/java/org/jclouds/util/InputStreamChain.java +++ /dev/null @@ -1,128 +0,0 @@ -/** - * Licensed to jclouds, Inc. (jclouds) under one or more - * contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. jclouds licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - */ -package org.jclouds.util; - -import java.io.IOException; -import java.io.InputStream; -import java.util.LinkedList; - -import com.google.common.collect.Lists; - -/** - * {@link InputStream} implementation that allows chaining of various streams for seamless - * sequential reading - * - * @author Adrian Cole - * @author Tomas Varaneckas - */ -public class InputStreamChain extends InputStream { - - /** - * Input stream chain - */ - private final LinkedList streams = Lists.newLinkedList(); - - /** - * Currently active stream - */ - private InputStream current; - - public InputStreamChain(InputStream... inputStreams) { - for (InputStream stream : inputStreams) { - addInputStream(stream); - } - } - - /** - * Adds input stream to the end of chain - * - * @param stream - * InputStream to add to chain - * @return instance of self (for fluent calls) - */ - public InputStreamChain addInputStream(final InputStream stream) { - streams.addLast(stream); - if (current == null) { - current = streams.removeFirst(); - } - return this; - } - - /** - * Adds a String to the end of chain - * - * @param value - * String to add to the chain - * @return instance of self (for fluent calls) - */ - public InputStreamChain addAsInputStream(final String value) { - return addInputStream(Strings2.toInputStream(value)); - } - - @Override - public int read() throws IOException { - int bit = current.read(); - if (bit == -1 && streams.size() > 0) { - try { - current.close(); - } catch (final IOException e) { - // replace this with a call to logging facility - e.printStackTrace(); - } - current = streams.removeFirst(); - bit = read(); - } - return bit; - } - - @Override - public int available() throws IOException { - int available = current.available(); - for (InputStream stream : streams) { - available += stream.available(); - } - return available; - } - - @Override - public void close() throws IOException { - current.close(); - } - - @Override - public boolean markSupported() { - return current.markSupported(); - } - - @Override - public synchronized void mark(int i) { - current.mark(i); - } - - @Override - public synchronized void reset() throws IOException { - current.reset(); - } - - @Override - public long skip(long l) throws IOException { - return current.skip(l); - } - -} diff --git a/core/src/main/java/org/jclouds/util/Iterables2.java b/core/src/main/java/org/jclouds/util/Iterables2.java deleted file mode 100644 index 7922b6603f..0000000000 --- a/core/src/main/java/org/jclouds/util/Iterables2.java +++ /dev/null @@ -1,41 +0,0 @@ -/** - * Licensed to jclouds, Inc. (jclouds) under one or more - * contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. jclouds licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - */ -package org.jclouds.util; - -import com.google.common.collect.ImmutableSet; - -/** - * General utilities used in jclouds code for {@link Iterable Iterables}. - * - * @author danikov - */ -public class Iterables2 { - - /** - * Copies the contents of a wildcarded {@link Iterable} into a concrete {@link Iterable} of the left bound - * - * @param unboundedValues wildcarded source {@link Iterable} - * @return concrete-typed copy of the source - */ - public static Iterable concreteCopy(Iterable unboundedValues) { - // Please do not attempt to sort, as this is wasteful - return ImmutableSet.copyOf(unboundedValues); - } - -} diff --git a/core/src/main/java/org/jclouds/util/Lists2.java b/core/src/main/java/org/jclouds/util/Lists2.java deleted file mode 100644 index 91e154df38..0000000000 --- a/core/src/main/java/org/jclouds/util/Lists2.java +++ /dev/null @@ -1,55 +0,0 @@ -/** - * Licensed to jclouds, Inc. (jclouds) under one or more - * contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. jclouds licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - */ -package org.jclouds.util; - -import static com.google.common.collect.Lists.newArrayList; - -import java.util.Comparator; -import java.util.Iterator; -import java.util.List; - - -/** - * - * @author Adrian Cole - */ -public class Lists2 { - - /** - * Like Ordering, but handle the case where there are multiple valid maximums - */ - @SuppressWarnings("unchecked") - public static List multiMax(Comparator ordering, Iterable iterable) { - Iterator iterator = iterable.iterator(); - List maxes = newArrayList(iterator.next()); - E maxSoFar = maxes.get(0); - while (iterator.hasNext()) { - E current = iterator.next(); - int comparison = ordering.compare(maxSoFar, current); - if (comparison == 0) { - maxes.add(current); - } else if (comparison < 0) { - maxes = newArrayList(current); - maxSoFar = current; - } - } - return maxes; - } - -} diff --git a/core/src/main/java/org/jclouds/util/Maps2.java b/core/src/main/java/org/jclouds/util/Maps2.java index 324995e9a7..7639c5a975 100644 --- a/core/src/main/java/org/jclouds/util/Maps2.java +++ b/core/src/main/java/org/jclouds/util/Maps2.java @@ -19,21 +19,13 @@ package org.jclouds.util; import static com.google.common.base.Preconditions.checkNotNull; -import static com.google.common.base.Predicates.equalTo; -import static com.google.common.base.Predicates.not; -import static com.google.common.collect.Maps.filterKeys; -import java.util.LinkedHashMap; import java.util.Map; import java.util.Map.Entry; -import java.util.Set; import com.google.common.base.Function; -import com.google.common.base.Supplier; import com.google.common.collect.ImmutableMap; import com.google.common.collect.ImmutableMap.Builder; -import com.google.common.collect.Maps; -import com.google.common.collect.Multimap; /** * General utilities used in jclouds code for {@link Map Maps}. @@ -41,53 +33,6 @@ import com.google.common.collect.Multimap; * @author Adrian Cole */ public class Maps2 { - public static Function, Set> keySetFunction() { - return new Function, Set>() { - - @Override - public Set apply(Map arg0) { - return arg0.keySet(); - } - - public String toString() { - return "keySet()"; - } - }; - } - - public static Map convertUnsafe(Multimap in) { - LinkedHashMap out = Maps.newLinkedHashMap(); - for (Entry entry : in.entries()) { - out.put(entry.getKey(), entry.getValue()); - } - return ImmutableMap.copyOf(out); - } - - /** - * If the supplied map contains the key {@code k1}, its value will be assigned to the key {@code - * k2}. Note that this doesn't modify the input map. - * - * @param - * type of value the map holds - * @param in - * the map you wish to make a copy of - * @param k1 - * old key - * @param k2 - * new key - * @return copy of the map with the value of the key re-routed, or the original, if it {@code k1} - * wasn't present. - */ - public static Map renameKey(Map in, String k1, String k2) { - if (checkNotNull(in, "input map").containsKey(checkNotNull(k1, "old key"))) { - Builder builder = ImmutableMap.builder(); - builder.putAll(filterKeys(in, not(equalTo(k1)))); - V tags = in.get(k1); - builder.put(checkNotNull(k2, "new key"), tags); - in = builder.build(); - } - return in; - } /** * change the keys but keep the values in-tact. @@ -112,57 +57,4 @@ public class Maps2 { returnVal.put(fn.apply(entry.getKey()), entry.getValue()); return returnVal.build(); } - - public static Supplier> composeMapSupplier(Iterable>> suppliers) { - return new ListMapSupplier(suppliers); - } - - static class ListMapSupplier implements Supplier> { - - private final Iterable>> suppliers; - - ListMapSupplier(Iterable>> suppliers) { - this.suppliers = checkNotNull(suppliers, "suppliers"); - } - - @Override - public Map get() { - Map toReturn = Maps.newLinkedHashMap(); - for (Supplier> supplier : suppliers) { - toReturn.putAll(supplier.get()); - } - return toReturn; - } - } - - /** - * Constructs a map with the given keys where values are generated by the given function. - * Supports duplicate and {@code null} values, but {@code null} keys are not allowed. - * - * @param the type of the keys - * @param the type of the values - * @param keys the keys to be included in the map. Keys must be non-null - * @param valueFunction the function that produces values for the keys - * @return a map containing the keys from the given set with values which are generated from - * the keys - * @see Maps#uniqueIndex(Iterable, Function) - */ - public static Map fromKeys(Set keys, Function valueFunction) { - Map result = Maps.newHashMapWithExpectedSize(keys.size()); - for (K key : keys) { - result.put(checkNotNull(key), valueFunction.apply(key)); - } - return result; - } - - /** - * Covariant compatible version - * - * @see {@link Maps#uniqueIndex(Iterable, Function)} - */ - public static ImmutableMap uniqueIndex( - Iterable values, Function keyFunction) { - return ImmutableMap.copyOf(Maps.uniqueIndex(values, keyFunction)); - } - } diff --git a/core/src/main/java/org/jclouds/util/Modules2.java b/core/src/main/java/org/jclouds/util/Modules2.java deleted file mode 100644 index 9a45924a51..0000000000 --- a/core/src/main/java/org/jclouds/util/Modules2.java +++ /dev/null @@ -1,72 +0,0 @@ -/** - * Licensed to jclouds, Inc. (jclouds) under one or more - * contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. jclouds licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - */ -package org.jclouds.util; - -import static com.google.common.base.Splitter.on; -import static com.google.common.collect.Iterables.concat; -import static com.google.common.collect.Iterables.transform; - -import java.util.Properties; - -import com.google.common.base.Function; -import com.google.common.collect.ImmutableList; -import com.google.common.collect.ImmutableSet; -import com.google.inject.Module; - - - -/** - * - * - * @author Adrian Cole - */ -public class Modules2 { - - public static Iterable modulesFromCommaDelimitedString(String moduleClasses) { - Iterable modules = ImmutableSet.of(); - if (moduleClasses != null) { - Iterable transformer = ImmutableList.copyOf(on(',').split(moduleClasses)); - modules = transform(transformer, new Function() { - - @Override - public Module apply(String from) { - try { - return (Module) ClassLoadingUtils.loadClass(Modules2.class, from).newInstance(); - } catch (InstantiationException e) { - throw new RuntimeException("error instantiating " + from, e); - } catch (IllegalAccessException e) { - throw new RuntimeException("error instantiating " + from, e); - } - } - - }); - } - return modules; - } - - public static Iterable modulesForProviderInProperties(String providerName, Properties props) { - return concat(modulesFromProperty(props, "jclouds.modules"), - modulesFromProperty(props, providerName + ".modules")); - } - - public static Iterable modulesFromProperty(Properties props, String property) { - return modulesFromCommaDelimitedString(props.getProperty(property, null)); - } - -} diff --git a/core/src/main/java/org/jclouds/util/Multimaps2.java b/core/src/main/java/org/jclouds/util/Multimaps2.java index 5d82137b83..cab3572f78 100644 --- a/core/src/main/java/org/jclouds/util/Multimaps2.java +++ b/core/src/main/java/org/jclouds/util/Multimaps2.java @@ -20,16 +20,13 @@ package org.jclouds.util; import static com.google.common.base.Preconditions.checkNotNull; -import java.util.Map; -import java.util.Set; import java.util.Map.Entry; +import java.util.Set; import com.google.common.base.Function; import com.google.common.base.Predicates; -import com.google.common.collect.ImmutableMap; import com.google.common.collect.ImmutableMultimap; import com.google.common.collect.ImmutableMultimap.Builder; -import com.google.common.collect.ImmutableSet; import com.google.common.collect.Multimap; import com.google.common.collect.Multimaps; @@ -39,34 +36,6 @@ import com.google.common.collect.Multimaps; */ public class Multimaps2 { - /** - * The traditional way to represent a graph in Java is Map>, which is awkward in a - * number of ways. Guava's Multimap framework makes it easy to handle a mapping from keys to - * multiple values. - *

- * Until we write or discover a gson Multimap deserializer, we may be stuck with this. - * - * TODO: ask on stackoverflow and/or jesse wilson - */ - @Deprecated - public static Map> toOldSchool(Multimap in) { - ImmutableMap.Builder> out = ImmutableMap.builder(); - for (K type : in.keySet()) - out.put(type, ImmutableSet.copyOf(in.get(type))); - return out.build(); - } - - /** - * @see #toOldSchool - */ - @Deprecated - public static ImmutableMultimap fromOldSchool(Map> in) { - Builder out = ImmutableMultimap.builder(); - for (K type : in.keySet()) - out.putAll(type, ImmutableSet.copyOf(in.get(type))); - return out.build(); - } - public static Multimap replaceValue(Multimap fromMultimap, final K key, final V value) { checkNotNull(fromMultimap, "input multimap"); checkNotNull(key, "key"); diff --git a/core/src/main/java/org/jclouds/util/NullSafeCollections.java b/core/src/main/java/org/jclouds/util/NullSafeCollections.java deleted file mode 100644 index d387aa1cb0..0000000000 --- a/core/src/main/java/org/jclouds/util/NullSafeCollections.java +++ /dev/null @@ -1,38 +0,0 @@ -/** - * Licensed to jclouds, Inc. (jclouds) under one or more - * contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. jclouds licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - */ -package org.jclouds.util; - -import java.util.Set; - -import com.google.common.collect.ImmutableSet; - -/** - * - * @author Adrian Cole - */ -public class NullSafeCollections { - - public static Set nullSafeSet(T in) { - if (in == null) { - return ImmutableSet. of(); - } - return ImmutableSet. of(in); - } - -} diff --git a/core/src/main/java/org/jclouds/util/Patterns.java b/core/src/main/java/org/jclouds/util/Patterns.java index 1faf6ae741..34b620186d 100644 --- a/core/src/main/java/org/jclouds/util/Patterns.java +++ b/core/src/main/java/org/jclouds/util/Patterns.java @@ -18,9 +18,6 @@ */ package org.jclouds.util; -import java.io.UnsupportedEncodingException; -import java.net.URLEncoder; -import java.util.concurrent.ExecutionException; import java.util.regex.Pattern; import com.google.common.cache.CacheBuilder; @@ -32,52 +29,8 @@ import com.google.common.cache.LoadingCache; * @author Adrian Cole */ public class Patterns { - public static final Pattern TOKEN_PATTERN = Pattern.compile("\\{(.+?)\\}"); - public static final Pattern TWO_SPACE_PATTERN = Pattern.compile(" "); - public static final Pattern URL_ENCODED_PATTERN = Pattern.compile(".*%[a-fA-F0-9][a-fA-F0-9].*"); - public static final Pattern URI_PATTERN = Pattern.compile("([a-z0-9]+)://([^:]*):(.*)@(.*)"); - public static final Pattern PATTERN_THAT_BREAKS_URI = Pattern.compile("[a-z0-9]+://.*/.*@.*"); - public static final Pattern JSON_STRING_PATTERN = Pattern.compile("^[^\"\\{\\[].*[^\\{\\[\"]$"); - public static final Pattern JSON_NUMBER_PATTERN = Pattern.compile("^[0-9]*\\.?[0-9]*$"); - public static final Pattern JSON_BOOLEAN_PATTERN = Pattern.compile("^(true|false)$"); - public static final Pattern PLUS_PATTERN = Pattern.compile("\\+"); - public static final Pattern STAR_PATTERN = Pattern.compile("\\*"); - public static final Pattern _7E_PATTERN = Pattern.compile("%7E"); + public static final Pattern NEWLINE_PATTERN = Pattern.compile("\r?\n"); - public static final Pattern SLASH_PATTERN = Pattern.compile("[/]"); - public static final Pattern IP_PATTERN = Pattern.compile("b(?:(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?).)" - + "{3}(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)b"); - public static final Pattern LEADING_SLASHES = Pattern.compile("^[/]+"); - public static final Pattern TRAILING_SLASHES = Pattern.compile("[/]*$"); - public static final Pattern REST_CONTEXT_BUILDER = Pattern.compile("(.*ContextBuilder)<([^,]+), ?([^>]+)>"); - - public static final LoadingCache CHAR_TO_ENCODED = CacheBuilder.newBuilder() - . build(new CacheLoader() { - @Override - public String load(Character plain) throws ExecutionException { - try { - return URLEncoder.encode(plain + "", "UTF-8"); - } catch (UnsupportedEncodingException e) { - throw new ExecutionException("Bad encoding on input: " + plain, e); - } - } - }); - - public static final LoadingCache CHAR_TO_ENCODED_PATTERN = CacheBuilder.newBuilder() - . build(new CacheLoader() { - @Override - public Pattern load(Character plain) throws ExecutionException { - return Pattern.compile(CHAR_TO_ENCODED.get(plain)); - } - }); - - public static final LoadingCache CHAR_TO_PATTERN = CacheBuilder.newBuilder() - . build(new CacheLoader() { - @Override - public Pattern load(Character plain) { - return Pattern.compile(plain + ""); - } - }); public static final LoadingCache TOKEN_TO_PATTERN = CacheBuilder.newBuilder() . build(new CacheLoader() { diff --git a/core/src/main/java/org/jclouds/util/Preconditions2.java b/core/src/main/java/org/jclouds/util/Preconditions2.java index 6a11e01bc8..b1c023ea42 100644 --- a/core/src/main/java/org/jclouds/util/Preconditions2.java +++ b/core/src/main/java/org/jclouds/util/Preconditions2.java @@ -28,15 +28,6 @@ import static com.google.common.base.Preconditions.checkArgument; */ public class Preconditions2 { - /** - * Will throw an exception if the argument is null or empty. - * - * @param nullableString - * string to verify. Can be null or empty. - */ - public static void checkNotEmpty(String nullableString) { - Preconditions2.checkNotEmpty(nullableString, "Argument can't be null or empty"); - } /** * Will throw an exception if the argument is null or empty. Accepts a custom error message. @@ -50,5 +41,4 @@ public class Preconditions2 { checkArgument(nullableString != null && nullableString.length() > 0, message); } - } diff --git a/core/src/main/java/org/jclouds/util/Predicates2.java b/core/src/main/java/org/jclouds/util/Predicates2.java index 9872e4b1e0..36f3c2c12c 100644 --- a/core/src/main/java/org/jclouds/util/Predicates2.java +++ b/core/src/main/java/org/jclouds/util/Predicates2.java @@ -35,19 +35,4 @@ public class Predicates2 { } }; } - - /** Returns a predicate that evaluates to true if the String being tested ends with a prefix. */ - public static Predicate endsWith(final String suffix) { - return new Predicate() { - @Override - public boolean apply(final String input) { - return input.endsWith(suffix); - } - - @Override - public String toString() { - return "endsWith(" + suffix + ")"; - } - }; - } } diff --git a/core/src/main/java/org/jclouds/util/SaxUtils.java b/core/src/main/java/org/jclouds/util/SaxUtils.java index 145719a2b0..7d303cdc7a 100644 --- a/core/src/main/java/org/jclouds/util/SaxUtils.java +++ b/core/src/main/java/org/jclouds/util/SaxUtils.java @@ -51,8 +51,4 @@ public class SaxUtils { return returnVal.equals("") ? null : returnVal; } - public static String currentOrNegative(StringBuilder currentText) { - String returnVal = currentText.toString().trim(); - return returnVal.equals("") ? "-1" : returnVal; - } } diff --git a/core/src/main/java/org/jclouds/util/Strings2.java b/core/src/main/java/org/jclouds/util/Strings2.java index 886015e2e0..d6f83afdf2 100644 --- a/core/src/main/java/org/jclouds/util/Strings2.java +++ b/core/src/main/java/org/jclouds/util/Strings2.java @@ -21,10 +21,7 @@ package org.jclouds.util; import static com.google.common.base.Preconditions.checkNotNull; import static com.google.common.io.ByteStreams.toByteArray; import static com.google.common.io.Closeables.closeQuietly; -import static org.jclouds.util.Patterns.CHAR_TO_ENCODED; -import static org.jclouds.util.Patterns.CHAR_TO_PATTERN; import static org.jclouds.util.Patterns.TOKEN_TO_PATTERN; -import static org.jclouds.util.Patterns.URL_ENCODED_PATTERN; import java.io.ByteArrayInputStream; import java.io.IOException; @@ -41,6 +38,9 @@ import java.util.regex.Pattern; import org.jclouds.javax.annotation.Nullable; import com.google.common.base.Charsets; +import com.google.common.cache.CacheBuilder; +import com.google.common.cache.CacheLoader; +import com.google.common.cache.LoadingCache; import com.google.common.collect.Multimap; import com.google.common.io.CharStreams; import com.google.common.io.InputSupplier; @@ -77,6 +77,21 @@ public class Strings2 { throw new IllegalStateException("error creating pattern: " + in, e); } } + + private static final LoadingCache CHAR_TO_ENCODED = CacheBuilder.newBuilder() + . build(new CacheLoader() { + @Override + public String load(Character plain) throws ExecutionException { + try { + return URLEncoder.encode(plain + "", "UTF-8"); + } catch (UnsupportedEncodingException e) { + throw new ExecutionException("Bad encoding on input: " + plain, e); + } + } + }); + + private static final Pattern URL_ENCODED_PATTERN = Pattern.compile(".*%[a-fA-F0-9][a-fA-F0-9].*"); + public static boolean isUrlEncoded(String in) { return URL_ENCODED_PATTERN.matcher(in).matches(); } @@ -106,13 +121,6 @@ public class Strings2 { return returnVal; } - public static String replaceAll(String input, char ifMatch, Pattern pattern, String replacement) { - if (input.indexOf(ifMatch) != -1) { - input = pattern.matcher(input).replaceAll(replacement); - } - return input; - } - public static String replaceAll(String input, char match, String replacement) { if (input.indexOf(match) != -1) { try { @@ -124,6 +132,14 @@ public class Strings2 { return input; } + private static final LoadingCache CHAR_TO_PATTERN = CacheBuilder.newBuilder() + . build(new CacheLoader() { + @Override + public Pattern load(Character plain) { + return Pattern.compile(plain + ""); + } + }); + public static String toString(InputSupplier supplier) throws IOException { return CharStreams.toString(CharStreams.newReaderSupplier(supplier, @@ -157,7 +173,7 @@ public class Strings2 { * token/value pairs */ public static String replaceTokens(String input, Map replacements) { - Matcher matcher = Patterns.TOKEN_PATTERN.matcher(input); + Matcher matcher = TOKEN_PATTERN.matcher(input); StringBuilder builder = new StringBuilder(); int i = 0; while (matcher.find()) { @@ -172,6 +188,8 @@ public class Strings2 { builder.append(input.substring(i, input.length())); return builder.toString(); } + + private static final Pattern TOKEN_PATTERN = Pattern.compile("\\{(.+?)\\}"); public static String replaceTokens(String input, Multimap tokenValues) { for (Entry tokenValue : tokenValues.entries()) { diff --git a/core/src/main/java/org/jclouds/util/Suppliers2.java b/core/src/main/java/org/jclouds/util/Suppliers2.java index b136272aaa..0d492fc456 100644 --- a/core/src/main/java/org/jclouds/util/Suppliers2.java +++ b/core/src/main/java/org/jclouds/util/Suppliers2.java @@ -18,21 +18,15 @@ */ package org.jclouds.util; -import static com.google.common.base.Preconditions.checkNotNull; - -import java.io.IOException; -import java.io.OutputStream; import java.util.Map; import com.google.common.annotations.Beta; import com.google.common.base.Function; import com.google.common.base.Objects; -import com.google.common.base.Preconditions; import com.google.common.base.Supplier; import com.google.common.base.Suppliers; import com.google.common.base.Throwables; import com.google.common.collect.Iterables; -import com.google.common.io.OutputSupplier; /** * @@ -40,26 +34,6 @@ import com.google.common.io.OutputSupplier; */ public class Suppliers2 { - /** - * Supplies a value that corresponds to a particular key in a map, or null, if not found - */ - public static Supplier valueForKey(final Supplier>> input, final Supplier key) { - return new Supplier() { - - @Override - public V get() { - K keyToFind = key.get(); - Supplier value = input.get().get(keyToFind); - return value != null ? value.get() : null; - } - - @Override - public String toString() { - return "withKey()"; - } - }; - } - public static Supplier getLastValueInMap(final Supplier>> input) { return new Supplier() { @Override @@ -90,19 +64,6 @@ public class Suppliers2 { }; } - /** - * converts an {@link OutputStream} to an {@link OutputSupplier} - * - */ - public static OutputSupplier newOutputStreamSupplier(final OutputStream output) { - checkNotNull(output, "output"); - return new OutputSupplier() { - public OutputStream getOutput() throws IOException { - return output; - } - }; - } - /** * returns the value of the first supplier, or the value of the fallback, if the unlessNull is * null. @@ -153,33 +114,4 @@ public class Suppliers2 { }; } - // only here until guava compose gives a toString! - // http://code.google.com/p/guava-libraries/issues/detail?id=1052 - public static Supplier compose(Function function, Supplier supplier) { - Preconditions.checkNotNull(function); - Preconditions.checkNotNull(supplier); - return new SupplierComposition(function, supplier); - } - - private static class SupplierComposition implements Supplier { - - final Function function; - final Supplier supplier; - - SupplierComposition(Function function, Supplier supplier) { - this.function = function; - this.supplier = supplier; - } - - @Override - public T get() { - return function.apply(supplier.get()); - } - - @Override - public String toString() { - return Objects.toStringHelper(this).add("function", function).add("supplier", supplier).toString(); - } - } - } diff --git a/core/src/main/java/org/jclouds/util/Throwables2.java b/core/src/main/java/org/jclouds/util/Throwables2.java index 3d4a61ab58..4e14ea0081 100644 --- a/core/src/main/java/org/jclouds/util/Throwables2.java +++ b/core/src/main/java/org/jclouds/util/Throwables2.java @@ -31,6 +31,7 @@ import org.jclouds.rest.AuthorizationException; import org.jclouds.rest.InsufficientResourcesException; import org.jclouds.rest.ResourceNotFoundException; +import com.google.common.annotations.VisibleForTesting; import com.google.common.base.Predicate; import com.google.common.base.Throwables; import com.google.inject.CreationException; @@ -58,10 +59,6 @@ public class Throwables2 { }; } - public static boolean containsResourceNotFoundException(Throwable from) { - return getFirstThrowableOfType(from, ResourceNotFoundException.class) != null; - } - @SuppressWarnings("unchecked") public static T getFirstThrowableOfType(Throwable from, Class clazz) { if (from instanceof ProvisionException) @@ -77,7 +74,8 @@ public class Throwables2 { } } - public static T getFirstThrowableOfType(TransformParallelException e, Class clazz) { + @VisibleForTesting + static T getFirstThrowableOfType(TransformParallelException e, Class clazz) { for (Exception exception : e.getFromToException().values()) { T cause = getFirstThrowableOfType(exception, clazz); if (cause != null) @@ -86,7 +84,8 @@ public class Throwables2 { return null; } - public static T getFirstThrowableOfType(ProvisionException e, Class clazz) { + @VisibleForTesting + static T getFirstThrowableOfType(ProvisionException e, Class clazz) { for (Message message : e.getErrorMessages()) { if (message.getCause() != null) { T cause = getFirstThrowableOfType(message.getCause(), clazz); @@ -102,7 +101,8 @@ public class Throwables2 { return null; } - public static T getFirstThrowableOfType(CreationException e, Class clazz) { + @VisibleForTesting + static T getFirstThrowableOfType(CreationException e, Class clazz) { for (Message message : e.getErrorMessages()) { if (message.getCause() != null) { T cause = getFirstThrowableOfType(message.getCause(), clazz); diff --git a/core/src/main/java/org/jclouds/util/TypeTokens2.java b/core/src/main/java/org/jclouds/util/TypeTokens2.java deleted file mode 100644 index 05dad33f57..0000000000 --- a/core/src/main/java/org/jclouds/util/TypeTokens2.java +++ /dev/null @@ -1,40 +0,0 @@ -/** - * Licensed to jclouds, Inc. (jclouds) under one or more - * contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. jclouds licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - */ -package org.jclouds.util; - -import static com.google.common.base.Preconditions.checkState; - -import java.lang.reflect.TypeVariable; - -import com.google.common.reflect.TypeToken; - -/** - * - * @author Adrian Cole - */ -public class TypeTokens2 { - /** - * @throws IllegalStateException if the type is an instanceof {@link TypeVariable} - */ - public static TypeToken checkBound(TypeToken type) throws IllegalStateException { - checkState(!(type.getType() instanceof TypeVariable), - "unbound type variable: %s, use ctor that explicitly assigns this", type); - return type; - } -} diff --git a/core/src/test/java/org/jclouds/domain/JsonBallTest.java b/core/src/test/java/org/jclouds/domain/JsonBallTest.java index 143542e3c0..7e72a0fe6a 100644 --- a/core/src/test/java/org/jclouds/domain/JsonBallTest.java +++ b/core/src/test/java/org/jclouds/domain/JsonBallTest.java @@ -22,6 +22,7 @@ import static org.testng.Assert.assertEquals; import java.io.IOException; import java.util.Map; +import java.util.regex.Matcher; import org.jclouds.http.HttpResponse; import org.jclouds.http.functions.ParseJson; @@ -41,6 +42,52 @@ import com.google.inject.TypeLiteral; */ @Test(groups = "unit") public class JsonBallTest { + + public void testJSON_STRING_PATTERN1() { + Matcher matcher = JsonBall.JSON_STRING_PATTERN.matcher("hello"); + assert (matcher.find()); + } + + public void testJSON_STRING_PATTERN2() { + Matcher matcher = JsonBall.JSON_STRING_PATTERN.matcher("hello world!"); + assert (matcher.find()); + } + + public void testJSON_STRING_PATTERN3() { + Matcher matcher = JsonBall.JSON_STRING_PATTERN.matcher("\"hello world!\""); + assert (!matcher.find()); + } + + public void testJSON_STRING_PATTERN4() { + Matcher matcher = JsonBall.JSON_STRING_PATTERN.matcher("[hello world!]"); + assert (!matcher.find()); + } + + public void testJSON_STRING_PATTERN5() { + Matcher matcher = JsonBall.JSON_STRING_PATTERN.matcher("{hello world!}"); + assert (!matcher.find()); + } + + public void testJSON_NUMBER_PATTERN1() { + Matcher matcher = JsonBall.JSON_NUMBER_PATTERN.matcher("1"); + assert (matcher.find()); + } + + public void testJSON_NUMBER_PATTERN2() { + Matcher matcher = JsonBall.JSON_NUMBER_PATTERN.matcher("1.1"); + assert (matcher.find()); + } + + public void testJSON_NUMBER_PATTERN3() { + Matcher matcher = JsonBall.JSON_NUMBER_PATTERN.matcher("\"1.1\""); + assert (!matcher.find()); + } + + public void testJSON_NUMBER_PATTERN4() { + Matcher matcher = JsonBall.JSON_NUMBER_PATTERN.matcher("\"1\""); + assert (!matcher.find()); + } + private ParseJson> handler; private Json mapper; diff --git a/core/src/test/java/org/jclouds/json/internal/NullHackJsonLiteralAdapterTest.java b/core/src/test/java/org/jclouds/json/internal/NullHackJsonLiteralAdapterTest.java index f91965a4be..8914aaa66b 100644 --- a/core/src/test/java/org/jclouds/json/internal/NullHackJsonLiteralAdapterTest.java +++ b/core/src/test/java/org/jclouds/json/internal/NullHackJsonLiteralAdapterTest.java @@ -17,14 +17,15 @@ * under the License. */ package org.jclouds.json.internal; - import static com.google.common.base.Preconditions.checkNotNull; +import static org.jclouds.domain.JsonBall.JSON_BOOLEAN_PATTERN; +import static org.jclouds.domain.JsonBall.JSON_NUMBER_PATTERN; +import static org.jclouds.domain.JsonBall.JSON_STRING_PATTERN; import static org.testng.Assert.assertEquals; import java.lang.reflect.Type; import java.util.Map; -import org.jclouds.util.Patterns; import org.testng.annotations.Test; import com.google.common.base.Objects; @@ -80,8 +81,8 @@ public class NullHackJsonLiteralAdapterTest { } static String quoteStringIfNotNumberOrBoolean(String in) { - if (Patterns.JSON_STRING_PATTERN.matcher(in).find() && !Patterns.JSON_NUMBER_PATTERN.matcher(in).find() - && !Patterns.JSON_BOOLEAN_PATTERN.matcher(in).find()) { + if (JSON_STRING_PATTERN.matcher(in).find() && !JSON_NUMBER_PATTERN.matcher(in).find() + && !JSON_BOOLEAN_PATTERN.matcher(in).find()) { return "\"" + in + "\""; } return in; diff --git a/core/src/test/java/org/jclouds/util/CredentialUtilsTest.java b/core/src/test/java/org/jclouds/util/CredentialUtilsTest.java deleted file mode 100644 index 5801728df6..0000000000 --- a/core/src/test/java/org/jclouds/util/CredentialUtilsTest.java +++ /dev/null @@ -1,60 +0,0 @@ -/** - * Licensed to jclouds, Inc. (jclouds) under one or more - * contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. jclouds licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - */ -package org.jclouds.util; - -import static org.testng.Assert.assertEquals; - -import org.jclouds.domain.Credentials; -import org.testng.annotations.Test; - -/** - * @author Adrian Cole - */ -@Test(groups = "unit") -public class CredentialUtilsTest { - - public void testOverridingCredentialsWhenOverridingIsNull() { - Credentials defaultCredentials = new Credentials("foo", "bar"); - Credentials overridingCredentials = null; - assertEquals(CredentialUtils.overrideCredentialsIfSupplied(defaultCredentials, overridingCredentials), - defaultCredentials); - } - - public void testOverridingCredentialsWhenOverridingLoginIsNull() { - Credentials defaultCredentials = new Credentials("foo", "bar"); - Credentials overridingCredentials = new Credentials(null, "baz"); - assertEquals(CredentialUtils.overrideCredentialsIfSupplied(defaultCredentials, overridingCredentials), - new Credentials("foo", "baz")); - } - - public void testOverridingCredentialsWhenOverridingCredentialIsNull() { - Credentials defaultCredentials = new Credentials("foo", "bar"); - Credentials overridingCredentials = new Credentials("fooble", null); - assertEquals(CredentialUtils.overrideCredentialsIfSupplied(defaultCredentials, overridingCredentials), - new Credentials("fooble", "bar")); - } - - public void testOverridingCredentialsWhenOverridingCredentialsAreNull() { - Credentials defaultCredentials = new Credentials("foo", "bar"); - Credentials overridingCredentials = new Credentials(null, null); - assertEquals(CredentialUtils.overrideCredentialsIfSupplied(defaultCredentials, overridingCredentials), - new Credentials("foo", "bar")); - } - -} diff --git a/core/src/test/java/org/jclouds/util/Maps2Test.java b/core/src/test/java/org/jclouds/util/Maps2Test.java index 8c52536fa7..bf807a7d2f 100644 --- a/core/src/test/java/org/jclouds/util/Maps2Test.java +++ b/core/src/test/java/org/jclouds/util/Maps2Test.java @@ -18,11 +18,7 @@ */ package org.jclouds.util; -import static com.google.common.base.Functions.constant; -import static com.google.common.base.Functions.identity; -import static com.google.common.collect.Sets.newHashSet; import static org.testng.Assert.assertEquals; -import static org.testng.Assert.assertTrue; import java.util.Map; @@ -30,24 +26,12 @@ import org.testng.annotations.Test; import com.google.common.base.Function; import com.google.common.collect.ImmutableMap; -import com.google.common.collect.ImmutableSet; -import com.google.common.collect.Lists; -import com.google.common.collect.Maps; /** * @author Adrian Cole */ @Test(groups = "unit") public class Maps2Test { - public void testRenameKeyWhenNotFound() { - Map nothing = ImmutableMap.of(); - assertEquals(Maps2.renameKey(nothing, "foo", "bar"), nothing); - } - - public void testRenameKeyWhenFound() { - Map nothing = ImmutableMap.of("foo", "bar"); - assertEquals(Maps2.renameKey(nothing, "foo", "bar"), ImmutableMap.of("bar", "bar")); - } public void testTransformKeys() { Map map = ImmutableMap.of("prefix:foo", "bar"); @@ -60,45 +44,4 @@ public class Maps2Test { }), ImmutableMap.of("foo", "bar")); } - - public void testFromKeysEmptyKeys() { - assertTrue(Maps2.fromKeys(ImmutableSet.of(), identity()).isEmpty(), - "Expected returned map to be empty"); - } - - @Test(expectedExceptions = { NullPointerException.class }) - public void testFromKeysNullKey() { - Maps2.fromKeys(newHashSet((Object) null), constant("const")); - } - - public void testFromKeys() { - // ImmutableMap doesn't support null values - Map expected = Maps.newHashMap(); - expected.put("foo", "foo"); - expected.put("bar", "foo"); - expected.put("baz", null); - - assertEquals(Maps2.fromKeys(ImmutableSet.of("foo", "bar", "baz"), - new Function() { - @Override - public String apply(String input) { - return (input.equals("baz") ? null : "foo"); - } - }), expected); - } - - @Test - public void testCovariantUniqueIndex() { - Iterable values = Lists.newArrayList(1, 2, 3, 4, 5); - Map map = Maps2.uniqueIndex(values, new Function() { - - @Override - public Double apply(Object input) { - return (Integer)input + 0.1; - } - }); - - assertEquals(map.get(1.1), 1); - } - } diff --git a/core/src/test/java/org/jclouds/util/PatternsTest.java b/core/src/test/java/org/jclouds/util/PatternsTest.java deleted file mode 100644 index c34739e3a8..0000000000 --- a/core/src/test/java/org/jclouds/util/PatternsTest.java +++ /dev/null @@ -1,96 +0,0 @@ -/** - * Licensed to jclouds, Inc. (jclouds) under one or more - * contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. jclouds licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - */ -package org.jclouds.util; - -import static org.testng.Assert.assertEquals; - -import java.util.regex.Matcher; - -import org.testng.annotations.Test; - -/** - * @author Adrian Cole - */ -@Test(groups = "unit") -public class PatternsTest { - - public void testJSON_STRING_PATTERN1() { - Matcher matcher = Patterns.JSON_STRING_PATTERN.matcher("hello"); - assert (matcher.find()); - } - - public void testJSON_STRING_PATTERN2() { - Matcher matcher = Patterns.JSON_STRING_PATTERN.matcher("hello world!"); - assert (matcher.find()); - } - - public void testJSON_STRING_PATTERN3() { - Matcher matcher = Patterns.JSON_STRING_PATTERN.matcher("\"hello world!\""); - assert (!matcher.find()); - } - - public void testJSON_STRING_PATTERN4() { - Matcher matcher = Patterns.JSON_STRING_PATTERN.matcher("[hello world!]"); - assert (!matcher.find()); - } - - public void testJSON_STRING_PATTERN5() { - Matcher matcher = Patterns.JSON_STRING_PATTERN.matcher("{hello world!}"); - assert (!matcher.find()); - } - - public void testJSON_NUMBER_PATTERN1() { - Matcher matcher = Patterns.JSON_NUMBER_PATTERN.matcher("1"); - assert (matcher.find()); - } - - public void testJSON_NUMBER_PATTERN2() { - Matcher matcher = Patterns.JSON_NUMBER_PATTERN.matcher("1.1"); - assert (matcher.find()); - } - - public void testJSON_NUMBER_PATTERN3() { - Matcher matcher = Patterns.JSON_NUMBER_PATTERN.matcher("\"1.1\""); - assert (!matcher.find()); - } - - public void testJSON_NUMBER_PATTERN4() { - Matcher matcher = Patterns.JSON_NUMBER_PATTERN.matcher("\"1\""); - assert (!matcher.find()); - } - - public void testREST_CONTEXT_BUILDER() { - Matcher matcher = Patterns.REST_CONTEXT_BUILDER - .matcher("org.jclouds.rest.ContextBuilder"); - assert (matcher.find()); - assertEquals(matcher.group(1), "org.jclouds.rest.ContextBuilder"); - assertEquals(matcher.group(2), "java.lang.String"); - assertEquals(matcher.group(3), "java.lang.Integer"); - - } - - public void testREST_CONTEXT_BUILDERwithSpace() { - Matcher matcher = Patterns.REST_CONTEXT_BUILDER - .matcher("org.jclouds.rest.ContextBuilder"); - assert (matcher.find()); - assertEquals(matcher.group(1), "org.jclouds.rest.ContextBuilder"); - assertEquals(matcher.group(2), "java.lang.String"); - assertEquals(matcher.group(3), "java.lang.Integer"); - } -} diff --git a/core/src/test/java/org/jclouds/util/Suppliers2Test.java b/core/src/test/java/org/jclouds/util/Suppliers2Test.java index dc954009a5..612bd5f963 100644 --- a/core/src/test/java/org/jclouds/util/Suppliers2Test.java +++ b/core/src/test/java/org/jclouds/util/Suppliers2Test.java @@ -31,22 +31,6 @@ import com.google.common.collect.ImmutableMap; public class Suppliers2Test { - @Test - public void testWithKey() { - assertEquals( - Suppliers2. valueForKey( - Suppliers.>> ofInstance(ImmutableMap.of("foo", - Suppliers.ofInstance("bar"))), Suppliers.ofInstance("foo")).get(), "bar"); - } - - @Test - public void testWithKeyUnmatchedIsNull() { - assertEquals( - Suppliers2. valueForKey( - Suppliers.>> ofInstance(ImmutableMap.of("boo", - Suppliers.ofInstance("bar"))), Suppliers.ofInstance("foo")).get(), null); - } - @Test public void testGetLastValueInMap() { assertEquals( diff --git a/drivers/jsch/src/main/java/org/jclouds/ssh/jsch/SessionConnection.java b/drivers/jsch/src/main/java/org/jclouds/ssh/jsch/SessionConnection.java index 805f7c7609..d95d53d3dc 100644 --- a/drivers/jsch/src/main/java/org/jclouds/ssh/jsch/SessionConnection.java +++ b/drivers/jsch/src/main/java/org/jclouds/ssh/jsch/SessionConnection.java @@ -19,12 +19,10 @@ package org.jclouds.ssh.jsch; import static com.google.common.base.Objects.equal; - -import java.util.Arrays; +import static com.google.common.base.Preconditions.checkArgument; import org.jclouds.domain.LoginCredentials; import org.jclouds.ssh.jsch.JschSshClient.Connection; -import org.jclouds.util.CredentialUtils; import com.google.common.base.Objects; import com.google.common.net.HostAndPort; @@ -120,13 +118,10 @@ public class SessionConnection implements Connection { if (loginCredentials.getPrivateKey() == null) { session.setPassword(loginCredentials.getPassword()); } else { + checkArgument(!loginCredentials.getPrivateKey().contains("Proc-Type: 4,ENCRYPTED"), + "JschSshClientModule does not support private keys that require a passphrase"); byte[] privateKey = loginCredentials.getPrivateKey().getBytes(); - if (CredentialUtils.isPrivateKeyEncrypted(privateKey)) { - throw new IllegalArgumentException( - "JschSshClientModule does not support private keys that require a passphrase"); - } - jsch.addIdentity(loginCredentials.getUser(), Arrays.copyOf(privateKey, privateKey.length), null, - emptyPassPhrase); + jsch.addIdentity(loginCredentials.getUser(), privateKey, null, emptyPassPhrase); } java.util.Properties config = new java.util.Properties(); config.put("StrictHostKeyChecking", "no"); diff --git a/labs/abiquo/src/main/java/org/jclouds/abiquo/config/AbiquoRestClientModule.java b/labs/abiquo/src/main/java/org/jclouds/abiquo/config/AbiquoRestClientModule.java index 9916623edf..fab3ca1831 100644 --- a/labs/abiquo/src/main/java/org/jclouds/abiquo/config/AbiquoRestClientModule.java +++ b/labs/abiquo/src/main/java/org/jclouds/abiquo/config/AbiquoRestClientModule.java @@ -68,10 +68,10 @@ import org.jclouds.rest.RestContext; import org.jclouds.rest.Utils; import org.jclouds.rest.config.RestClientModule; import org.jclouds.rest.suppliers.MemoizedRetryOnTimeOutButNotOnAuthorizationExceptionSupplier; -import org.jclouds.util.Suppliers2; import com.google.common.base.Function; import com.google.common.base.Supplier; +import com.google.common.base.Suppliers; import com.google.common.collect.ImmutableMap; import com.google.common.collect.Maps; import com.google.inject.Provides; @@ -147,7 +147,7 @@ public class AbiquoRestClientModule extends RestClientModule> getAvailableRegionsIndexedById( final AtomicReference authException, @Named(PROPERTY_SESSION_INTERVAL) final long seconds, @Memoized final Supplier currentEnterprise) { - Supplier> availableRegionsMapSupplier = Suppliers2.compose( + Supplier> availableRegionsMapSupplier = Suppliers.compose( new Function, Map>() { @Override public Map apply(final List datacenters) { diff --git a/labs/joyent-cloudapi/src/main/java/org/jclouds/joyent/cloudapi/v6_5/compute/config/JoyentCloudComputeServiceContextModule.java b/labs/joyent-cloudapi/src/main/java/org/jclouds/joyent/cloudapi/v6_5/compute/config/JoyentCloudComputeServiceContextModule.java index 9017a235cd..b04ff14053 100644 --- a/labs/joyent-cloudapi/src/main/java/org/jclouds/joyent/cloudapi/v6_5/compute/config/JoyentCloudComputeServiceContextModule.java +++ b/labs/joyent-cloudapi/src/main/java/org/jclouds/joyent/cloudapi/v6_5/compute/config/JoyentCloudComputeServiceContextModule.java @@ -54,16 +54,16 @@ import org.jclouds.joyent.cloudapi.v6_5.domain.datacenterscoped.DatacenterAndNam import org.jclouds.joyent.cloudapi.v6_5.domain.datacenterscoped.DatasetInDatacenter; import org.jclouds.joyent.cloudapi.v6_5.domain.datacenterscoped.MachineInDatacenter; import org.jclouds.joyent.cloudapi.v6_5.domain.datacenterscoped.PackageInDatacenter; -import org.jclouds.util.Iterables2; -import org.jclouds.util.Suppliers2; import com.google.common.annotations.VisibleForTesting; import com.google.common.base.Function; import com.google.common.base.Supplier; +import com.google.common.base.Suppliers; import com.google.common.cache.CacheBuilder; import com.google.common.cache.CacheLoader; import com.google.common.cache.LoadingCache; import com.google.common.collect.ImmutableMap; +import com.google.common.collect.ImmutableSet; import com.google.common.collect.Maps; import com.google.common.collect.Multimap; import com.google.inject.Injector; @@ -134,11 +134,11 @@ public class JoyentCloudComputeServiceContextModule extends @Singleton protected Supplier> createLocationIndexedById( @Memoized Supplier> locations) { - return Suppliers2.compose(new Function, Map>() { + return Suppliers.compose(new Function, Map>() { @Override public Map apply(Set arg0) { - return Maps.uniqueIndex(Iterables2.concreteCopy(arg0), new Function() { + return Maps.uniqueIndex(ImmutableSet. copyOf(arg0), new Function() { @Override public String apply(Location arg0) { diff --git a/labs/savvis-symphonyvpdc/src/main/java/org/jclouds/savvis/vpdc/config/VPDCRestClientModule.java b/labs/savvis-symphonyvpdc/src/main/java/org/jclouds/savvis/vpdc/config/VPDCRestClientModule.java index 2e8a106dd1..e25522e6b2 100644 --- a/labs/savvis-symphonyvpdc/src/main/java/org/jclouds/savvis/vpdc/config/VPDCRestClientModule.java +++ b/labs/savvis-symphonyvpdc/src/main/java/org/jclouds/savvis/vpdc/config/VPDCRestClientModule.java @@ -45,30 +45,30 @@ import org.jclouds.rest.ConfiguresRestClient; import org.jclouds.rest.annotations.Identity; import org.jclouds.rest.config.RestClientModule; import org.jclouds.rest.suppliers.MemoizedRetryOnTimeOutButNotOnAuthorizationExceptionSupplier; -import org.jclouds.savvis.vpdc.VPDCAsyncApi; import org.jclouds.savvis.vpdc.VPDCApi; +import org.jclouds.savvis.vpdc.VPDCAsyncApi; import org.jclouds.savvis.vpdc.domain.internal.VCloudSession; -import org.jclouds.savvis.vpdc.features.BrowsingAsyncApi; import org.jclouds.savvis.vpdc.features.BrowsingApi; -import org.jclouds.savvis.vpdc.features.FirewallAsyncApi; +import org.jclouds.savvis.vpdc.features.BrowsingAsyncApi; import org.jclouds.savvis.vpdc.features.FirewallApi; -import org.jclouds.savvis.vpdc.features.ServiceManagementAsyncApi; +import org.jclouds.savvis.vpdc.features.FirewallAsyncApi; import org.jclouds.savvis.vpdc.features.ServiceManagementApi; -import org.jclouds.savvis.vpdc.features.VMAsyncApi; +import org.jclouds.savvis.vpdc.features.ServiceManagementAsyncApi; import org.jclouds.savvis.vpdc.features.VMApi; +import org.jclouds.savvis.vpdc.features.VMAsyncApi; import org.jclouds.savvis.vpdc.handlers.VPDCErrorHandler; -import org.jclouds.savvis.vpdc.internal.LoginAsyncApi; import org.jclouds.savvis.vpdc.internal.LoginApi; +import org.jclouds.savvis.vpdc.internal.LoginAsyncApi; import org.jclouds.savvis.vpdc.internal.VCloudToken; import org.jclouds.savvis.vpdc.location.FirstNetwork; import org.jclouds.savvis.vpdc.predicates.TaskSuccess; import org.jclouds.util.Strings2; -import org.jclouds.util.Suppliers2; import com.google.common.base.Function; import com.google.common.base.Objects; import com.google.common.base.Predicate; import com.google.common.base.Supplier; +import com.google.common.base.Suppliers; import com.google.common.collect.ImmutableMap; import com.google.common.collect.Iterables; import com.google.inject.Injector; @@ -93,7 +93,7 @@ public class VPDCRestClientModule extends RestClientModule provideVCloudToken(Supplier cache) { - return Suppliers2.compose(new Function() { + return Suppliers.compose(new Function() { @Override public String apply(VCloudSession input) { @@ -108,7 +108,7 @@ public class VPDCRestClientModule extends RestClientModule> provideOrgs(Supplier cache, @Identity final String user) { - return Suppliers2.compose(new Function>() { + return Suppliers.compose(new Function>() { @Override public Set apply(VCloudSession input) { @@ -124,7 +124,7 @@ public class VPDCRestClientModule extends RestClientModule provideDefaultOrgId( @org.jclouds.savvis.vpdc.internal.Org Supplier> orgs) { - return Suppliers2.compose(new Function, String>() { + return Suppliers.compose(new Function, String>() { @Override public String apply(Set input) { diff --git a/labs/vcloud-director/src/main/java/org/jclouds/vcloud/director/v1_5/config/VCloudDirectorRestClientModule.java b/labs/vcloud-director/src/main/java/org/jclouds/vcloud/director/v1_5/config/VCloudDirectorRestClientModule.java index 65dd637f93..716cf18a29 100644 --- a/labs/vcloud-director/src/main/java/org/jclouds/vcloud/director/v1_5/config/VCloudDirectorRestClientModule.java +++ b/labs/vcloud-director/src/main/java/org/jclouds/vcloud/director/v1_5/config/VCloudDirectorRestClientModule.java @@ -38,7 +38,6 @@ import org.jclouds.rest.ConfiguresRestClient; import org.jclouds.rest.RestContext; import org.jclouds.rest.config.RestClientModule; import org.jclouds.rest.internal.RestContextImpl; -import org.jclouds.util.Suppliers2; import org.jclouds.vcloud.director.v1_5.admin.VCloudDirectorAdminApi; import org.jclouds.vcloud.director.v1_5.admin.VCloudDirectorAdminAsyncApi; import org.jclouds.vcloud.director.v1_5.annotations.Login; @@ -94,6 +93,7 @@ import org.jclouds.vcloud.director.v1_5.user.VCloudDirectorAsyncApi; import com.google.common.base.Function; import com.google.common.base.Supplier; +import com.google.common.base.Suppliers; import com.google.common.cache.CacheBuilder; import com.google.common.cache.LoadingCache; import com.google.common.collect.ImmutableMap; @@ -172,7 +172,7 @@ public class VCloudDirectorRestClientModule extends RestClientModule loginUrl(@Provider Supplier provider) { // TODO: technically, we should implement version api, but this will work - return Suppliers2.compose(new Function() { + return Suppliers.compose(new Function() { @Override public URI apply(URI arg0) { @@ -184,7 +184,7 @@ public class VCloudDirectorRestClientModule extends RestClientModule currentSession(Supplier in) { - return Suppliers2.compose(new Function() { + return Suppliers.compose(new Function() { @Override public Session apply(SessionWithToken arg0) { @@ -199,7 +199,7 @@ public class VCloudDirectorRestClientModule extends RestClientModule sessionToken(Supplier in) { - return Suppliers2.compose(new Function() { + return Suppliers.compose(new Function() { @Override public String apply(SessionWithToken arg0) { diff --git a/providers/azureblob/src/main/java/org/jclouds/azureblob/AzureBlobUtil.java b/providers/azureblob/src/main/java/org/jclouds/azureblob/AzureBlobUtil.java deleted file mode 100644 index def2c4dcb4..0000000000 --- a/providers/azureblob/src/main/java/org/jclouds/azureblob/AzureBlobUtil.java +++ /dev/null @@ -1,56 +0,0 @@ -/** - * Licensed to jclouds, Inc. (jclouds) under one or more - * contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. jclouds licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - */ -package org.jclouds.azureblob; - -import java.net.URI; - -import javax.ws.rs.GET; -import javax.ws.rs.Path; -import javax.ws.rs.PathParam; - -import org.jclouds.azure.storage.filters.SharedKeyLiteAuthentication; -import org.jclouds.azure.storage.reference.AzureStorageHeaders; -import org.jclouds.blobstore.BlobStoreFallbacks.ThrowKeyNotFoundOn404; -import org.jclouds.http.functions.ParseContentMD5FromHeaders; -import org.jclouds.rest.annotations.EndpointParam; -import org.jclouds.rest.annotations.Fallback; -import org.jclouds.rest.annotations.Headers; -import org.jclouds.rest.annotations.RequestFilters; -import org.jclouds.rest.annotations.ResponseParser; - -/** - * Helper functions needed to to derive BlobStore values - *

- * - * @see - * @author Adrian Cole - */ -@RequestFilters(SharedKeyLiteAuthentication.class) -@Headers(keys = AzureStorageHeaders.VERSION, values = "2009-07-17") -public interface AzureBlobUtil { - - @GET - @Headers(keys = "Range", values = "bytes=0-0") - // should use HEAD, this is a hack per http://code.google.com/p/jclouds/issues/detail?id=92 - @ResponseParser(ParseContentMD5FromHeaders.class) - @Fallback(ThrowKeyNotFoundOn404.class) - @Path("{key}") - byte[] getMD5(@EndpointParam URI container, @PathParam("key") String key); - -}