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

COVERAGE SUMMARY FOR SOURCE FILE [Call.java]

nameclass, %method, %block, %line, %
Call.java100% (1/1)67%  (4/6)52%  (78/150)38%  (12/32)

COVERAGE BREAKDOWN BY CLASS AND METHOD

nameclass, %method, %block, %line, %
     
class Call100% (1/1)67%  (4/6)52%  (78/150)38%  (12/32)
equals (Object): boolean 0%   (0/1)0%   (0/45)0%   (0/15)
hashCode (): int 0%   (0/1)0%   (0/27)0%   (0/5)
<static initializer> 100% (1/1)100% (7/7)100% (1/1)
Call (String, String []): void 100% (1/1)100% (15/15)100% (4/4)
functionDependencies (OsFamily): Iterable 100% (1/1)100% (4/4)100% (1/1)
render (OsFamily): String 100% (1/1)100% (52/52)100% (6/6)

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.domain;
20 
21import static com.google.common.base.Preconditions.checkNotNull;
22 
23import java.util.Arrays;
24import java.util.Map;
25 
26import org.jclouds.scriptbuilder.util.Utils;
27 
28import com.google.common.collect.ImmutableList;
29import com.google.common.collect.ImmutableMap;
30 
31/**
32 * Statement used in a shell script
33 * 
34 * @author Adrian Cole
35 */
36public class Call implements Statement {
37 
38   public static final Map<OsFamily, String> OS_TO_CALL = ImmutableMap.of(OsFamily.UNIX,
39            "{function}{args} || return 1\n", OsFamily.WINDOWS,
40            "call :{function}{args}\r\nif errorlevel 1 goto abort\r\n");
41 
42   private String function;
43   private String[] args;
44 
45   public Call(String function, String... args) {
46      this.function = checkNotNull(function, "function");
47      this.args = checkNotNull(args, "args");
48   }
49 
50   public String render(OsFamily family) {
51      StringBuilder args = new StringBuilder();
52      for (String arg : this.args) {
53         args.append(" ").append(Utils.replaceTokens(arg, ShellToken.tokenValueMap(family)));
54      }
55      StringBuilder call = new StringBuilder();
56      call.append(Utils.replaceTokens(OS_TO_CALL.get(family), ImmutableMap.of("function", function,
57               "args", args.toString())));
58      return call.toString();
59   }
60 
61   @Override
62   public int hashCode() {
63      final int prime = 31;
64      int result = 1;
65      result = prime * result + Arrays.hashCode(args);
66      result = prime * result + ((function == null) ? 0 : function.hashCode());
67      return result;
68   }
69 
70   @Override
71   public boolean equals(Object obj) {
72      if (this == obj)
73         return true;
74      if (obj == null)
75         return false;
76      if (getClass() != obj.getClass())
77         return false;
78      Call other = (Call) obj;
79      if (!Arrays.equals(args, other.args))
80         return false;
81      if (function == null) {
82         if (other.function != null)
83            return false;
84      } else if (!function.equals(other.function))
85         return false;
86      return true;
87   }
88 
89   @Override
90   public Iterable<String> functionDependencies(OsFamily family) {
91      return ImmutableList.of(function);
92   }
93}

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