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

COVERAGE SUMMARY FOR SOURCE FILE [CreateOrOverwriteFile.java]

nameclass, %method, %block, %line, %
CreateOrOverwriteFile.java100% (1/1)75%  (3/4)95%  (116/122)89%  (17/19)

COVERAGE BREAKDOWN BY CLASS AND METHOD

nameclass, %method, %block, %line, %
     
class CreateOrOverwriteFile100% (1/1)75%  (3/4)95%  (116/122)89%  (17/19)
CreateOrOverwriteFile (String, Iterable, String): void 0%   (0/1)0%   (0/6)0%   (0/2)
CreateOrOverwriteFile (String, Iterable): void 100% (1/1)100% (5/5)100% (2/2)
hereFile (String, StringBuilder): void 100% (1/1)100% (39/39)100% (5/5)
render (OsFamily): String 100% (1/1)100% (72/72)100% (10/10)

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 org.jclouds.scriptbuilder.domain.Statements.interpret;
22 
23import java.util.List;
24 
25import com.google.common.collect.Lists;
26 
27/**
28 * Creates a run script
29 * 
30 * @author Adrian Cole
31 */
32public class CreateOrOverwriteFile extends AppendFile {
33 
34   public CreateOrOverwriteFile(String path, Iterable<String> lines) {
35       super(path, lines);
36   }
37 
38   public CreateOrOverwriteFile(String path, Iterable<String> lines, String marker) {
39       super(path, lines, marker);
40   }
41 
42   @Override
43   public String render(OsFamily family) {
44      List<Statement> statements = Lists.newArrayList();
45      if (family == OsFamily.UNIX) {
46         StringBuilder builder = new StringBuilder();
47         hereFile(path, builder);
48         statements.add(interpret(builder.toString()));
49      } else {
50         // Windows:
51         statements.add(interpret(String.format("copy /y CON %s{lf}", path))); // This clears the file
52         for (String line : lines) {
53            statements.add(appendToFile(line, path, family));
54         }
55      }
56      return new StatementList(statements).render(family);
57   }
58 
59   protected void hereFile(String path, StringBuilder builder) {
60      builder.append("cat > ").append(path).append(" <<'").append(marker).append("'\n");
61      for (String line : lines) {
62         builder.append(line).append("\n");
63      }
64      builder.append(marker).append("\n");
65   }
66 
67}

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