EMMA Coverage Report (generated Mon Oct 17 05:41:20 EDT 2011)
[all classes][org.jclouds.scriptbuilder]

COVERAGE SUMMARY FOR SOURCE FILE [EnvBuilder.java]

nameclass, %method, %block, %line, %
EnvBuilder.java100% (1/1)100% (3/3)100% (97/97)100% (15/15)

COVERAGE BREAKDOWN BY CLASS AND METHOD

nameclass, %method, %block, %line, %
     
class EnvBuilder100% (1/1)100% (3/3)100% (97/97)100% (15/15)
EnvBuilder (): void 100% (1/1)100% (6/6)100% (2/2)
build (OsFamily): String 100% (1/1)100% (79/79)100% (11/11)
export (String, String): EnvBuilder 100% (1/1)100% (12/12)100% (2/2)

1/**
2 * Licensed to jclouds, Inc. (jclouds) under one or more
3 * contributor license agreements.  See the NOTICE file
4 * distributed with this work for additional information
5 * regarding copyright ownership.  jclouds licenses this file
6 * to you under the Apache License, Version 2.0 (the
7 * "License"); you may not use this file except in compliance
8 * with the License.  You may obtain a copy of the License at
9 *
10 *   http://www.apache.org/licenses/LICENSE-2.0
11 *
12 * Unless required by applicable law or agreed to in writing,
13 * software distributed under the License is distributed on an
14 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15 * KIND, either express or implied.  See the License for the
16 * specific language governing permissions and limitations
17 * under the License.
18 */
19package org.jclouds.scriptbuilder;
20 
21import static com.google.common.base.Preconditions.checkNotNull;
22 
23import java.util.Map;
24 
25import org.jclouds.scriptbuilder.domain.OsFamily;
26import org.jclouds.scriptbuilder.domain.ShellToken;
27import org.jclouds.scriptbuilder.util.Utils;
28 
29import com.google.common.annotations.VisibleForTesting;
30import com.google.common.collect.ImmutableMap;
31import com.google.common.collect.Maps;
32 
33/**
34 * Creates an environment file
35 * 
36 * @author Adrian Cole
37 */
38public class EnvBuilder {
39 
40   @VisibleForTesting
41   Map<String, String> variables = Maps.newHashMap();
42 
43   /**
44    * Exports a variable inside the script
45    */
46   public EnvBuilder export(String name, String value) {
47      variables.put(checkNotNull(name, "name"), checkNotNull(value, "value"));
48      return this;
49   }
50 
51   /**
52    * builds the environment file, by adding the following
53    * <ol>
54    * <li>example usage</li>
55    * <li>variable exports</li>
56    * <li>return statement</li>
57    * </ol>
58    * 
59    * @param osFamily
60    *           whether to write a cmd or bash script.
61    */
62   public String build(final OsFamily osFamily) {
63      StringBuilder builder = new StringBuilder();
64      builder.append(Utils.writeComment(" Env file: please do not confuse people by making this executable", osFamily));
65      builder.append(Utils.writeComment("", osFamily));
66      builder.append(Utils.writeComment(" Example usage to set a variable", osFamily));
67      builder.append(Utils.writeComment("", osFamily));
68      builder.append(Utils.writeComment(" "
69               + Utils.writeVariableExporters(ImmutableMap.of("mavenOpts", "-Xms64m -Xmx128m"),
70                        osFamily), osFamily));
71      builder.append(Utils.writeVariableExporters(variables, osFamily));
72      builder.append(ShellToken.LF.to(osFamily));
73      builder.append(Utils.writeComment(
74               " Please retain this statement so that the script can be validated", osFamily));
75      builder.append(ShellToken.RETURN.to(osFamily)).append(" 0")
76               .append(ShellToken.LF.to(osFamily));
77      return builder.toString();
78   }
79}

[all classes][org.jclouds.scriptbuilder]
EMMA 2.0.5312 (C) Vladimir Roubtsov