Method: getAllDirectories(File)

1: /*
2: * #%~
3: * org.overture.ide.debug
4: * %%
5: * Copyright (C) 2008 - 2014 Overture
6: * %%
7: * This program is free software: you can redistribute it and/or modify
8: * it under the terms of the GNU General Public License as
9: * published by the Free Software Foundation, either version 3 of the
10: * License, or (at your option) any later version.
11: *
12: * This program is distributed in the hope that it will be useful,
13: * but WITHOUT ANY WARRANTY; without even the implied warranty of
14: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15: * GNU General Public License for more details.
16: *
17: * You should have received a copy of the GNU General Public
18: * License along with this program. If not, see
19: * <http://www.gnu.org/licenses/gpl-3.0.html>.
20: * #~%
21: */
22: package org.overture.ide.debug.utils;
23:
24: import java.io.File;
25: import java.util.Arrays;
26: import java.util.HashSet;
27: import java.util.List;
28: import java.util.Set;
29: import java.util.Vector;
30:
31: import org.eclipse.core.resources.IProject;
32:
33: public class VdmProjectClassPathCollector extends ClassPathCollector
34: {
35:
36:         public static List<String> getClassPath(IProject project,
37:                         String[] bundleIds, File... vdmProperties)
38:         {
39:                 String[] properties = new String[vdmProperties.length];
40:                 for (int i = 0; i < vdmProperties.length; i++)
41:                 {
42:                         properties[i]=vdmProperties[i].getParentFile().getAbsolutePath();
43:                 }
44:                 return getClassPath(project, bundleIds, properties);
45:         }
46:
47:         public static List<String> getClassPath(IProject project,
48:                         String[] bundleIds, String... additionalCpEntries)
49:         {
50:                 List<String> entries = new Vector<String>();
51:                 // get the class path for all jars in the project lib folder
52:                 File lib = new File(project.getLocation().toFile(), "lib");
53:                 if (lib.exists() && lib.isDirectory())
54:                 {
55:                         for (File f : getAllDirectories(lib))
56:                         {
57:                                 entries.add(f.getAbsolutePath());
58:                         }
59:
60:                         for (File f : getAllFiles(lib, new HashSet<String>(Arrays.asList(new String[] { ".jar" }))))
61:                         {
62:                                 entries.add(f.getAbsolutePath());
63:                         }
64:                 }
65:
66:                 // add custom properties file vdmj.properties
67:                 // entries.add(vdmjPropertiesFile.getParentFile().getAbsolutePath());
68:                 entries.addAll(Arrays.asList(additionalCpEntries));
69:                 return ClassPathCollector.getClassPath(project, bundleIds, entries.toArray(new String[] {}));
70:         }
71:
72:         private static List<File> getAllDirectories(File file)
73:         {
74:                 List<File> files = new Vector<File>();
75:•                if (file.isDirectory())
76:                 {
77:                         files.add(file);
78:•                        for (File f : file.listFiles())
79:                         {
80:                                 files.addAll(getAllDirectories(f));
81:                         }
82:
83:                 }
84:                 return files;
85:         }
86:
87:         private static List<File> getAllFiles(File file, Set<String> extensionFilter)
88:         {
89:                 List<File> files = new Vector<File>();
90:                 if (file.isDirectory())
91:                 {
92:                         for (File f : file.listFiles())
93:                         {
94:                                 files.addAll(getAllFiles(f, extensionFilter));
95:                         }
96:
97:                 } else
98:                 {
99:                         for (String filter : extensionFilter)
100:                         {
101:                                 if (file.getAbsolutePath().endsWith(filter))
102:                                 {
103:                                         files.add(file);
104:                                 }
105:                         }
106:
107:                 }
108:                 return files;
109:         }
110: }