1   package com.stateofflow.eclipse.metrics.ant;
2   
3   import java.io.IOException;
4   import java.util.Set;
5   
6   import org.apache.tools.ant.types.FileSet;
7   import org.eclipse.core.runtime.Path;
8   import org.eclipse.jdt.core.ICompilationUnit;
9   import org.eclipse.jdt.core.IJavaProject;
10  import org.eclipse.jdt.core.JavaModelException;
11  
12  import com.stateofflow.eclipse.metrics.builder.list.CompilationUnitList;
13  
14  class CompilationUnitListBuilder {
15      private CompilationUnitList compilationUnits;
16  
17      public CompilationUnitList build(final IJavaProject project, final Set<FileSet> compilationUnitSets) throws JavaModelException, IOException {
18          compilationUnits = new CompilationUnitList();
19          for (final FileSet fileSet : compilationUnitSets) {
20              accumulate(project, fileSet);
21          }
22          return compilationUnits;
23      }
24  
25      private void accumulate(final IJavaProject project, final FileSet fileSet) throws JavaModelException {
26          final String[] files = fileSet.getDirectoryScanner().getIncludedFiles();
27          for (final String file : files) {
28              accumulate(project, file);
29          }
30      }
31  
32      private void accumulate(final IJavaProject project, final String file) throws JavaModelException {
33          final Path path = new Path(file);
34          final ICompilationUnit element = (ICompilationUnit) project.findElement(path);
35          compilationUnits.addCompilationUnit(element);
36      }
37  }
38