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              if (secondFailureReport == null) {
37                  result = null;
38              } else {
39                  result = secondFailureReport;
40              }
41          } else {
42              if (secondFailureReport == null) {
43                  result = firstFailureReport;
44              } else {
45                  result = firstFailureReport + "\n\n" + secondFailureReport;
46              }
47          }
48          return result;
49      }
50  
51      public static Check aLineContainsResource(String name) {
52          return new AnyLineContainsCheck(name);
53      }
54  
55      public static Check aLineContainsCopyrightNotice(String copyrightNotice) {
56          return new AnyLineContainsCheck(copyrightNotice);
57      }
58  
59      public static Check aLineContainsAL2() {
60          return containsBothLines("Apache License", "Version 2.0, January 2004");
61      }
62  
63      public static Check aLineContainsMIT() {
64          return containsBothLines(
65                  "Permission is hereby granted, free of charge, to any person",
66                  "The above copyright notice and this permission notice");
67      }
68  
69      public static Check aLineContainsCDDL1() {
70          return aLineContainsEither(
71                  "COMMON DEVELOPMENT AND DISTRIBUTION LICENSE (CDDL) Version 1.0",
72                  "COMMON DEVELOPMENT AND DISTRIBUTION LICENSE Version 1.0 (CDDL-1.0)");
73      }
74  
75      public static Check noLineContains(String value) {
76          return new NoLineContainsCheck(value);
77      }
78  
79      public static Check aLineContains(String value) {
80          return new AnyLineContainsCheck(value);
81      }
82  
83      public static boolean noticeIsMissing(File basedir) {
84          return fileIsMissing(basedir, PATH_TO_NOTICE_FILE);
85      }
86  
87      private static boolean fileIsMissing(File basedir, final String string) {
88          return not(new File(basedir, string).exists());
89      }
90  
91      public static boolean licenseIsMissing(File basedir) {
92          return fileIsMissing(basedir, PATH_TO_LICENSE_FILE);
93      }
94  
95      public static FileVerifier licenseIn(File basedir) {
96          return new FileVerifier(new File(basedir, PATH_TO_LICENSE_FILE), "LICENSE");
97      }
98  
99      public static FileVerifier noticeIn(File basedir) {
100         return new FileVerifier(new File(basedir, PATH_TO_NOTICE_FILE), "NOTICE");
101     }
102 
103     public static Results results() {
104         return new Results();
105     }
106 }