From 2d19e338287688295f550d39dcb8a37dca5515fc Mon Sep 17 00:00:00 2001 From: "adrian.f.cole" Date: Wed, 13 Jan 2010 06:34:35 +0000 Subject: [PATCH] changed factories to not use varargs as it makes scripting ugly. also added NONE options for the same reason. git-svn-id: http://jclouds.googlecode.com/svn/trunk@2645 3d8758e0-26b5-11de-8745-db77d3ebf521 --- .../java/org/jclouds/aws/ec2/TestLogger.java | 81 ------------------- .../compute/EC2ComputeServiceLiveTest.java | 6 +- .../blobstore/BlobStoreContextFactory.java | 24 ++++-- .../internal/MutableResourceMetadataImpl.java | 6 ++ .../jclouds/blobstore/options/GetOptions.java | 7 +- .../options/ListContainerOptions.java | 2 + .../blobstore/options/ListOptions.java | 4 +- .../compute/ComputeServiceContextFactory.java | 32 ++++++-- .../ant/taskdefs/compute/ComputeTask.java | 9 ++- .../blobstore/BlobStoreFileProvider.java | 5 +- 10 files changed, 70 insertions(+), 106 deletions(-) delete mode 100644 aws/core/src/test/java/org/jclouds/aws/ec2/TestLogger.java diff --git a/aws/core/src/test/java/org/jclouds/aws/ec2/TestLogger.java b/aws/core/src/test/java/org/jclouds/aws/ec2/TestLogger.java deleted file mode 100644 index 3a573e583f..0000000000 --- a/aws/core/src/test/java/org/jclouds/aws/ec2/TestLogger.java +++ /dev/null @@ -1,81 +0,0 @@ -/** - * - * Copyright (C) 2009 Cloud Conscious, LLC. - * - * ==================================================================== - * Licensed 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.aws.ec2; - -import static org.testng.Assert.assertEquals; - -import java.util.List; - -import org.apache.log4j.AppenderSkeleton; -import org.apache.log4j.ConsoleAppender; -import org.apache.log4j.LogManager; -import org.apache.log4j.Logger; -import org.apache.log4j.SimpleLayout; -import org.apache.log4j.spi.LoggingEvent; -import org.testng.annotations.Test; -import org.testng.collections.Lists; - -import com.google.common.collect.ImmutableList; - -/** - * - * @author Adrian Cole - */ -@Test -public class TestLogger { - static class AppenderForTesting extends AppenderSkeleton { - private static List messages = Lists.newArrayList(); - - protected void append(LoggingEvent event) { - messages.add(event.getLoggerName() + ":" + event.getRenderedMessage()); - } - - public void close() { - } - - public boolean requiresLayout() { - return false; - } - - public static List getMessages() { - return messages; - } - - public static void clear() { - messages.clear(); - } - } - - static class LogApples { - final Logger logger = LogManager.getLogger(LogApples.class); - - public void log(String in) { - logger.info(in); - } - } - - @Test - void testFoo() { - Logger.getRootLogger().addAppender(new AppenderForTesting()); - Logger.getRootLogger().addAppender(new ConsoleAppender(new SimpleLayout())); - - new LogApples().log("foo"); - assertEquals(AppenderForTesting.getMessages(), ImmutableList.of("foo")); - } -} diff --git a/aws/core/src/test/java/org/jclouds/aws/ec2/compute/EC2ComputeServiceLiveTest.java b/aws/core/src/test/java/org/jclouds/aws/ec2/compute/EC2ComputeServiceLiveTest.java index 4a06380be4..d7b611c1cb 100644 --- a/aws/core/src/test/java/org/jclouds/aws/ec2/compute/EC2ComputeServiceLiveTest.java +++ b/aws/core/src/test/java/org/jclouds/aws/ec2/compute/EC2ComputeServiceLiveTest.java @@ -48,6 +48,7 @@ import org.testng.annotations.AfterTest; import org.testng.annotations.BeforeGroups; import org.testng.annotations.Test; +import com.google.common.collect.ImmutableSet; import com.google.inject.Guice; import com.google.inject.Injector; @@ -68,11 +69,12 @@ public class EC2ComputeServiceLiveTest { private ComputeServiceContext context; @BeforeGroups(groups = { "live" }) - public void setupClient() throws InterruptedException, ExecutionException, TimeoutException, IOException { + public void setupClient() throws InterruptedException, ExecutionException, TimeoutException, + IOException { String user = checkNotNull(System.getProperty("jclouds.test.user"), "jclouds.test.user"); String password = checkNotNull(System.getProperty("jclouds.test.key"), "jclouds.test.key"); context = new ComputeServiceContextFactory().createContext("ec2", user, password, - new Log4JLoggingModule()); + ImmutableSet.of(new Log4JLoggingModule())); Injector injector = Guice.createInjector(new JschSshClientModule()); sshFactory = injector.getInstance(SshClient.Factory.class); SocketOpen socketOpen = injector.getInstance(SocketOpen.class); diff --git a/blobstore/src/main/java/org/jclouds/blobstore/BlobStoreContextFactory.java b/blobstore/src/main/java/org/jclouds/blobstore/BlobStoreContextFactory.java index 3323494c75..90922fb180 100644 --- a/blobstore/src/main/java/org/jclouds/blobstore/BlobStoreContextFactory.java +++ b/blobstore/src/main/java/org/jclouds/blobstore/BlobStoreContextFactory.java @@ -29,6 +29,8 @@ import javax.inject.Inject; import org.jclouds.domain.Credentials; import org.jclouds.http.HttpPropertiesBuilder; +import com.google.common.collect.ImmutableSet; +import com.google.common.collect.Iterables; import com.google.common.io.Resources; import com.google.inject.Module; @@ -55,18 +57,31 @@ public class BlobStoreContextFactory { this.properties = properties; } - public BlobStoreContext createContext(URI blobStore, Module... modules) { + public BlobStoreContext createContext(URI blobStore, Iterable modules) { return createContext(blobStore, Credentials.parse(blobStore), modules); } - public BlobStoreContext createContext(URI blobStore, Credentials creds, Module... modules) { + public BlobStoreContext createContext(URI blobStore) { + return createContext(blobStore, ImmutableSet. of()); + } + + public BlobStoreContext createContext(URI blobStore, Credentials creds, + Iterable modules) { return createContext(checkNotNull(blobStore.getHost(), "host"), checkNotNull(creds.account, "account"), creds.key, modules); } + public BlobStoreContext createContext(URI blobStore, Credentials creds) { + return createContext(blobStore, creds, ImmutableSet. of()); + } + + public BlobStoreContext createContext(String hint, String account, String key) { + return createContext(hint, account, key, ImmutableSet. of()); + } + @SuppressWarnings("unchecked") public BlobStoreContext createContext(String hint, String account, String key, - Module... modules) { + Iterable modules) { checkNotNull(hint, "hint"); checkNotNull(account, "account"); String propertiesBuilderKey = String.format("%s.propertiesbuilder", hint); @@ -82,11 +97,10 @@ public class BlobStoreContextFactory { .forName(propertiesBuilderClassName); Class> contextBuilderClass = (Class>) Class .forName(contextBuilderClassName); - HttpPropertiesBuilder builder = propertiesBuilderClass.getConstructor(String.class, String.class).newInstance(account, key); return contextBuilderClass.getConstructor(Properties.class).newInstance(builder.build()) - .withModules(modules).buildContext(); + .withModules(Iterables.toArray(modules, Module.class)).buildContext(); } catch (Exception e) { throw new RuntimeException("error instantiating " + contextBuilderClassName, e); } diff --git a/blobstore/src/main/java/org/jclouds/blobstore/domain/internal/MutableResourceMetadataImpl.java b/blobstore/src/main/java/org/jclouds/blobstore/domain/internal/MutableResourceMetadataImpl.java index 6708d05dbb..776f2ef542 100644 --- a/blobstore/src/main/java/org/jclouds/blobstore/domain/internal/MutableResourceMetadataImpl.java +++ b/blobstore/src/main/java/org/jclouds/blobstore/domain/internal/MutableResourceMetadataImpl.java @@ -200,4 +200,10 @@ public class MutableResourceMetadataImpl implements MutableResourceMetadata, Ser this.location = location; } + @Override + public String toString() { + return "[type=" + type + ", id=" + id + ", name=" + name + ", size=" + size + + ", lastModified=" + lastModified + "]"; + } + } \ No newline at end of file diff --git a/blobstore/src/main/java/org/jclouds/blobstore/options/GetOptions.java b/blobstore/src/main/java/org/jclouds/blobstore/options/GetOptions.java index c4f11f4a86..046ee633e5 100644 --- a/blobstore/src/main/java/org/jclouds/blobstore/options/GetOptions.java +++ b/blobstore/src/main/java/org/jclouds/blobstore/options/GetOptions.java @@ -44,6 +44,9 @@ import java.util.List; * */ public class GetOptions { + + public static final GetOptions NONE = new GetOptions(); + private final List ranges = new ArrayList(); private Date ifModifiedSince; private Date ifUnmodifiedSince; @@ -171,8 +174,8 @@ public class GetOptions { /** * For use in the request header: If-None-Match *

- * Return the object only if its payload tag (ETag) is different from the one specified, otherwise - * return a 304 (not modified). + * Return the object only if its payload tag (ETag) is different from the one specified, + * otherwise return a 304 (not modified). * * @see GetOptions#ifETagDoesntMatch(String) */ diff --git a/blobstore/src/main/java/org/jclouds/blobstore/options/ListContainerOptions.java b/blobstore/src/main/java/org/jclouds/blobstore/options/ListContainerOptions.java index 873d14157d..e356302da6 100644 --- a/blobstore/src/main/java/org/jclouds/blobstore/options/ListContainerOptions.java +++ b/blobstore/src/main/java/org/jclouds/blobstore/options/ListContainerOptions.java @@ -38,6 +38,8 @@ import static com.google.common.base.Preconditions.checkNotNull; */ public class ListContainerOptions extends ListOptions { + public static final ListContainerOptions NONE = new ListContainerOptions(); + private String dir; private boolean recursive; diff --git a/blobstore/src/main/java/org/jclouds/blobstore/options/ListOptions.java b/blobstore/src/main/java/org/jclouds/blobstore/options/ListOptions.java index 72c1a1225f..00c172840e 100644 --- a/blobstore/src/main/java/org/jclouds/blobstore/options/ListOptions.java +++ b/blobstore/src/main/java/org/jclouds/blobstore/options/ListOptions.java @@ -37,6 +37,8 @@ import static com.google.common.base.Preconditions.checkNotNull; */ public class ListOptions { + public static final ListOptions NONE = new ListOptions(); + private Integer maxKeys; private String marker; @@ -67,7 +69,6 @@ public class ListOptions { return this; } - public static class Builder { /** @@ -86,6 +87,5 @@ public class ListOptions { return options.maxResults(maxKeys); } - } } diff --git a/core/src/main/java/org/jclouds/compute/ComputeServiceContextFactory.java b/core/src/main/java/org/jclouds/compute/ComputeServiceContextFactory.java index 04ca3ee155..cc0099025b 100644 --- a/core/src/main/java/org/jclouds/compute/ComputeServiceContextFactory.java +++ b/core/src/main/java/org/jclouds/compute/ComputeServiceContextFactory.java @@ -29,6 +29,8 @@ import javax.inject.Inject; import org.jclouds.domain.Credentials; import org.jclouds.http.HttpPropertiesBuilder; +import com.google.common.collect.ImmutableSet; +import com.google.common.collect.Iterables; import com.google.common.io.Resources; import com.google.inject.Module; @@ -45,8 +47,8 @@ public class ComputeServiceContextFactory { static Properties init() throws IOException { Properties properties = new Properties(); - properties.load(Resources.newInputStreamSupplier( - Resources.getResource("compute.properties")).getInput()); + properties.load(Resources.newInputStreamSupplier(Resources.getResource("compute.properties")) + .getInput()); return properties; } @@ -55,18 +57,32 @@ public class ComputeServiceContextFactory { this.properties = properties; } - public ComputeServiceContext createContext(URI computeService, Module... modules) { - return createContext(computeService, Credentials.parse(computeService), modules); + public ComputeServiceContext createContext(URI blobStore, + Iterable modules) { + return createContext(blobStore, Credentials.parse(blobStore), modules); } - public ComputeServiceContext createContext(URI computeService, Credentials creds, Module... modules) { - return createContext(checkNotNull(computeService.getHost(), "host"), checkNotNull(creds.account, + public ComputeServiceContext createContext(URI blobStore) { + return createContext(blobStore, ImmutableSet. of()); + } + + public ComputeServiceContext createContext(URI blobStore, Credentials creds, + Iterable modules) { + return createContext(checkNotNull(blobStore.getHost(), "host"), checkNotNull(creds.account, "account"), creds.key, modules); } + public ComputeServiceContext createContext(URI blobStore, Credentials creds) { + return createContext(blobStore, creds, ImmutableSet. of()); + } + + public ComputeServiceContext createContext(String hint, String account, String key) { + return createContext(hint, account, key, ImmutableSet. of()); + } + @SuppressWarnings("unchecked") public ComputeServiceContext createContext(String hint, String account, String key, - Module... modules) { + Iterable modules) { checkNotNull(hint, "hint"); checkNotNull(account, "account"); String propertiesBuilderKey = String.format("%s.propertiesbuilder", hint); @@ -86,7 +102,7 @@ public class ComputeServiceContextFactory { HttpPropertiesBuilder builder = propertiesBuilderClass.getConstructor(String.class, String.class).newInstance(account, key); return contextBuilderClass.getConstructor(Properties.class).newInstance(builder.build()) - .withModules(modules).buildContext(); + .withModules(Iterables.toArray(modules, Module.class)).buildContext(); } catch (Exception e) { throw new RuntimeException("error instantiating " + contextBuilderClassName, e); } diff --git a/tools/antcontrib/src/main/java/org/jclouds/tools/ant/taskdefs/compute/ComputeTask.java b/tools/antcontrib/src/main/java/org/jclouds/tools/ant/taskdefs/compute/ComputeTask.java index 31a408e7fc..799c11eba9 100644 --- a/tools/antcontrib/src/main/java/org/jclouds/tools/ant/taskdefs/compute/ComputeTask.java +++ b/tools/antcontrib/src/main/java/org/jclouds/tools/ant/taskdefs/compute/ComputeTask.java @@ -45,6 +45,7 @@ import org.jclouds.tools.ant.logging.config.AntLoggingModule; import com.google.common.base.CaseFormat; import com.google.common.base.Function; +import com.google.common.collect.ImmutableSet; import com.google.common.collect.MapMaker; import com.google.common.io.Files; import com.google.common.io.Resources; @@ -52,6 +53,7 @@ import com.google.inject.Module; import com.google.inject.Provider; /** + * @author Adrian Cole * @author Ivan Meredith */ public class ComputeTask extends Task { @@ -61,11 +63,12 @@ public class ComputeTask extends Task { * we don't have a reference to the project during the constructor, so we need to defer expansion * with a Provider. */ - private static Provider defaultModulesProvider = new Provider() { + private static Provider> defaultModulesProvider = new Provider>() { @Override - public Module[] get() { - return new Module[] { new AntLoggingModule(project, ComputeServiceConstants.COMPUTE_LOGGER) }; + public Iterable get() { + return ImmutableSet.of((Module) new AntLoggingModule(project, + ComputeServiceConstants.COMPUTE_LOGGER)); } }; diff --git a/tools/vfs/src/main/java/org/jclouds/vfs/provider/blobstore/BlobStoreFileProvider.java b/tools/vfs/src/main/java/org/jclouds/vfs/provider/blobstore/BlobStoreFileProvider.java index efb8e259aa..3a23744ae4 100644 --- a/tools/vfs/src/main/java/org/jclouds/vfs/provider/blobstore/BlobStoreFileProvider.java +++ b/tools/vfs/src/main/java/org/jclouds/vfs/provider/blobstore/BlobStoreFileProvider.java @@ -41,7 +41,6 @@ import org.jclouds.http.HttpUtils; import org.jclouds.logging.log4j.config.Log4JLoggingModule; import com.google.common.collect.ImmutableList; -import com.google.common.collect.Iterables; import com.google.inject.Module; /** @@ -87,8 +86,8 @@ public class BlobStoreFileProvider extends AbstractOriginatingFileProvider { .toChar(rootName.getUserName()))), UserAuthenticatorUtils .toString(UserAuthenticatorUtils.getData(authData, UserAuthenticationData.PASSWORD, UserAuthenticatorUtils - .toChar(rootName.getPassword())))), - Iterables.toArray(modules, Module.class)).getBlobStore(); + .toChar(rootName.getPassword())))), modules) + .getBlobStore(); } catch (IOException e) { throw new FileSystemException("vfs.provider.blobstore/properties.error", name, e); } finally {