Skip to content

Package: Resources

Resources

nameinstructionbranchcomplexitylinemethod
findAllViewFilesInWorkspace(SubMonitor)
M: 28 C: 0
0%
M: 0 C: 0
100%
M: 1 C: 0
0%
M: 7 C: 0
0%
M: 1 C: 0
0%

Coverage

1: /*******************************************************************************
2: * Copyright (c) 2017 EclipseSource Muenchen GmbH and others.
3: *
4: * All rights reserved. This program and the accompanying materials
5: * are made available under the terms of the Eclipse Public License 2.0
6: * which accompanies this distribution, and is available at
7: * https://www.eclipse.org/legal/epl-2.0/
8: *
9: * SPDX-License-Identifier: EPL-2.0
10: *
11: * Contributors:
12: * Edgar Mueller - initial API and implementation
13: ******************************************************************************/
14: package org.eclipse.emf.ecp.ide.internal.migration;
15:
16: import java.util.LinkedHashSet;
17: import java.util.Set;
18:
19: import org.eclipse.core.resources.IFile;
20: import org.eclipse.core.resources.IProject;
21: import org.eclipse.core.resources.IResource;
22: import org.eclipse.core.resources.IResourceVisitor;
23: import org.eclipse.core.resources.IWorkspace;
24: import org.eclipse.core.resources.ResourcesPlugin;
25: import org.eclipse.core.runtime.CoreException;
26: import org.eclipse.core.runtime.SubMonitor;
27:
28: /**
29: * Utility class for handling view model files.
30: *
31: */
32: public final class Resources {
33:
34:         private static final String VIEW_EXT = "view"; //$NON-NLS-1$
35:
36:         private Resources() {
37:                 // private ctor
38:         }
39:
40:         /**
41:          * Find all view model files within the workspace.
42:          *
43:          * @param monitor a {@link SubMonitor} that allow to report progress
44:          *
45:          * @return a set of view model files
46:          */
47:         public static Set<IFile> findAllViewFilesInWorkspace(SubMonitor monitor) {
48:                 final Set<IFile> files = new LinkedHashSet<IFile>();
49:                 final IWorkspace workspace = ResourcesPlugin.getWorkspace();
50:                 final SubMonitor subMonitor = SubMonitor.convert(monitor, workspace.getRoot().getProjects().length);
51:                 try {
52:                         workspace.getRoot().accept(new IResourceVisitor() {
53:                                 @Override
54:                                 public boolean visit(IResource resource) throws CoreException {
55:                                         if (resource.getFileExtension() != null && resource.getFileExtension().equals(VIEW_EXT)
56:                                                 && resource instanceof IFile) { // $NON-NLS-1$
57:                                                 files.add((IFile) resource);
58:
59:                                         }
60:                                         if (resource instanceof IProject) {
61:                                                 subMonitor.worked(1);
62:                                         }
63:                                         if (resource.getType() == IResource.FILE) {
64:                                                 return false;
65:                                         }
66:                                         return true;
67:                                 }
68:                         });
69:                 } catch (final CoreException ex) {
70:                         Activator.log(ex);
71:                 }
72:                 return files;
73:         }
74:
75: }