View Javadoc
1   /**
2    * Licensed to the Apache Software Foundation (ASF) under one
3    * or more contributor license agreements.  See the NOTICE file
4    * distributed with this work for additional information
5    * regarding copyright ownership.  The ASF 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   */
19  package org.apache.creadur.whisker.it;
20  
21  import static org.apache.creadur.whisker.it.Not.not;
22  import static org.apache.creadur.whisker.it.CheckHelpers.*;
23  
24  import java.io.File;
25  
26  public class Helpers {
27  
28      private static final String PATH_TO_LICENSE_FILE = "target/LICENSE";
29  
30      private static final String PATH_TO_NOTICE_FILE = "target/NOTICE";
31  
32      public static String aggregate(final String firstFailureReport,
33              final String secondFailureReport) {
34          final String result;
35          if (firstFailureReport == null) {
36              result = secondFailureReport;
37          } else {
38              if (secondFailureReport == null) {
39                  result = firstFailureReport;
40              } else {
41                  result = firstFailureReport + "\n\n" + secondFailureReport;
42              }
43          }
44          return result;
45      }
46  
47      public static Check aLineContainsResource(String name) {
48          return new AnyLineContainsCheck(name);
49      }
50  
51      public static Check aLineContainsCopyrightNotice(String copyrightNotice) {
52          return new AnyLineContainsCheck(copyrightNotice);
53      }
54  
55      public static Check aLineContainsAL2() {
56          return containsBothLines("Apache License", "Version 2.0, January 2004");
57      }
58  
59      public static Check aLineContainsMIT() {
60          return containsBothLines(
61                  "Permission is hereby granted, free of charge, to any person",
62                  "The above copyright notice and this permission notice");
63      }
64  
65      public static Check aLineContainsCDDL1() {
66          return aLineContainsEither(
67                  "COMMON DEVELOPMENT AND DISTRIBUTION LICENSE (CDDL) Version 1.0",
68                  "COMMON DEVELOPMENT AND DISTRIBUTION LICENSE Version 1.0 (CDDL-1.0)");
69      }
70  
71      public static Check noLineContains(String value) {
72          return new NoLineContainsCheck(value);
73      }
74  
75      public static Check aLineContains(String value) {
76          return new AnyLineContainsCheck(value);
77      }
78  
79      public static boolean noticeIsMissing(File basedir) {
80          return fileIsMissing(basedir, PATH_TO_NOTICE_FILE);
81      }
82  
83      private static boolean fileIsMissing(File basedir, final String string) {
84          return not(new File(basedir, string).exists());
85      }
86  
87      public static boolean licenseIsMissing(File basedir) {
88          return fileIsMissing(basedir, PATH_TO_LICENSE_FILE);
89      }
90  
91      public static FileVerifier licenseIn(File basedir) {
92          return new FileVerifier(new File(basedir, PATH_TO_LICENSE_FILE), "LICENSE");
93      }
94  
95      public static FileVerifier noticeIn(File basedir) {
96          return new FileVerifier(new File(basedir, PATH_TO_NOTICE_FILE), "NOTICE");
97      }
98  
99      public static Results results() {
100         return new Results();
101     }
102 }