View Javadoc
1   /*
2    * Copyright 2013 the original author or authors.
3    *
4    * Licensed under the Apache License, Version 2.0 (the "License");
5    * You may not use this file except in compliance with the License.
6    * You may obtain a copy of the License at
7    *
8    * http://www.apache.org/licenses/LICENSE-2.0
9    *
10   * Unless required by applicable law or agreed to in writing, software
11   * distributed under the License is distributed on an "AS IS" BASIS,
12   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13   * See the License for the specific language governing permissions and
14   * limitations under the License.
15   */
16  
17  package org.codehaus.gmavenplus.mojo;
18  
19  import org.apache.maven.shared.model.fileset.FileSet;
20  import org.apache.maven.shared.model.fileset.util.FileSetManager;
21  
22  import java.io.File;
23  import java.util.HashSet;
24  import java.util.Set;
25  
26  import static java.util.Collections.singletonList;
27  
28  
29  /**
30   * This mojo provides access to the Groovy sources (including stubs).
31   *
32   * @author Keegan Witt
33   * @since 1.0-beta-3
34   */
35  public abstract class AbstractGroovyStubSourcesMojo extends AbstractGroovySourcesMojo {
36  
37      /**
38       * Gets the set of stub files in specified directory.
39       *
40       * @param outputDirectory the directory to write stubs to
41       * @return The set of stub files in specified directory
42       */
43      protected Set<File> getStubs(File outputDirectory) {
44          Set<File> files = new HashSet<>();
45          FileSetManager fileSetManager = new FileSetManager();
46  
47          FileSet fileSet = new FileSet();
48          fileSet.setDirectory(outputDirectory.getAbsolutePath());
49          fileSet.setIncludes(singletonList(JAVA_SOURCES_PATTERN));
50          for (String file : fileSetManager.getIncludedFiles(fileSet)) {
51              files.add(new File(outputDirectory, file));
52          }
53  
54          return files;
55      }
56  
57  }