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.maven.plugins.ejb;
20  
21  import java.util.Collections;
22  import java.util.List;
23  
24  /**
25   * @author <a href="mailto:khmarbaise@apache.org">Karl Heinz Marbaise</a>
26   */
27  public class IncludesExcludes {
28      private List<String> includes;
29  
30      private List<String> defaultIncludes;
31  
32      private List<String> excludes;
33  
34      private List<String> defaultExcludes;
35  
36      public IncludesExcludes(
37              List<String> includes, List<String> excludes, List<String> defaultIncludes, List<String> defaultExcludes) {
38          this.includes = makeNonNullList(includes);
39          this.excludes = makeNonNullList(excludes);
40          this.defaultIncludes = makeNonNullList(defaultIncludes);
41          this.defaultExcludes = makeNonNullList(defaultExcludes);
42      }
43  
44      public String[] resultingIncludes() {
45          return resultingXcludes(includes, defaultIncludes);
46      }
47  
48      public String[] resultingExcludes() {
49          return resultingXcludes(excludes, defaultExcludes);
50      }
51  
52      private static String[] resultingXcludes(List<String> currentXcludes, List<String> defaultXcludes) {
53          if (currentXcludes.isEmpty()) {
54              return defaultXcludes.toArray(new String[0]);
55          } else {
56              return currentXcludes.toArray(new String[0]);
57          }
58      }
59  
60      private List<String> makeNonNullList(List<String> in) {
61          if (in == null) {
62              return Collections.<String>emptyList();
63          } else {
64              return in;
65          }
66      }
67  }