From 6bbeb75bc0dc4c88f41f02dbb290b6888ef37805 Mon Sep 17 00:00:00 2001 From: Doug Schaefer Date: Thu, 25 Jul 2013 15:25:30 -0400 Subject: [PATCH] JI:449069 Add filtering to the PDOM generator Adds a -exclude option to list directories and files that are to be excluded from the pre-built PDOM so we don't get header files that users don't get suggest optional headers. Change-Id: I4e06ccda2207f9955bb743006af8cf947c5d67f3 --- .../export/ExportIndexFileInfoMatcher.java | 65 +++++++++++++++++++ .../export/ExternalExportProjectProvider.java | 27 ++++++-- 2 files changed, 86 insertions(+), 6 deletions(-) create mode 100644 core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/index/export/ExportIndexFileInfoMatcher.java diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/index/export/ExportIndexFileInfoMatcher.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/index/export/ExportIndexFileInfoMatcher.java new file mode 100644 index 00000000000..b979344942f --- /dev/null +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/index/export/ExportIndexFileInfoMatcher.java @@ -0,0 +1,65 @@ +/******************************************************************************* + * Copyright (c) 2013 QNX Software Systems and others. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Doug Schaefer (QNX) - Initial Implementation + *******************************************************************************/ +package org.eclipse.cdt.core.index.export; + +import org.eclipse.core.filesystem.IFileInfo; +import org.eclipse.core.resources.FileInfoMatcherDescription; +import org.eclipse.core.resources.IContainer; +import org.eclipse.core.resources.IProject; +import org.eclipse.core.resources.filtermatchers.AbstractFileInfoMatcher; +import org.eclipse.core.runtime.CoreException; +import org.eclipse.core.runtime.IPath; +import org.eclipse.core.runtime.Path; + +/** + * FileInfoMatcher that will match a given project relative path for a directory we want to exclude. + * + * @author dschaefer + * + */ +public class ExportIndexFileInfoMatcher extends AbstractFileInfoMatcher { + + public static String ID = "org.eclipse.cdt.core.exportIndexFileInfoMatcher"; //$NON-NLS-1$ + + private IProject project; + private IPath excludedFolder; + + public static FileInfoMatcherDescription getDescription(String excludePath) { + return new FileInfoMatcherDescription(ID, excludePath); + } + + public ExportIndexFileInfoMatcher() { + } + + @Override + public boolean matches(IContainer parent, IFileInfo fileInfo) throws CoreException { + if (excludedFolder == null || project == null) + return false; + + if (!project.equals(parent.getProject())) + return false; + + // Remove the project and the linked folder from the path + IPath testPath = parent.getFullPath().removeFirstSegments(2).append(fileInfo.getName()); + boolean matches = excludedFolder.isPrefixOf(testPath); + if (matches) + System.out.println("Filtering: " + testPath); //$NON-NLS-1$ + return matches; + } + + @Override + public void initialize(IProject project, Object arguments) throws CoreException { + this.project = project; + if (arguments instanceof String) + excludedFolder = new Path((String)arguments); + } + +} diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/index/export/ExternalExportProjectProvider.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/index/export/ExternalExportProjectProvider.java index 5bcfcf05be3..dd4d89533b4 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/index/export/ExternalExportProjectProvider.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/index/export/ExternalExportProjectProvider.java @@ -34,10 +34,12 @@ import org.eclipse.cdt.core.settings.model.ICProjectDescription; import org.eclipse.cdt.core.settings.model.extension.impl.CDefaultConfigurationData; import org.eclipse.cdt.internal.core.index.IIndexFragment; import org.eclipse.cdt.internal.core.pdom.indexer.IndexerPreferences; +import org.eclipse.core.resources.FileInfoMatcherDescription; import org.eclipse.core.resources.IFolder; import org.eclipse.core.resources.IProject; import org.eclipse.core.resources.IProjectDescription; import org.eclipse.core.resources.IResource; +import org.eclipse.core.resources.IResourceFilterDescription; import org.eclipse.core.resources.IWorkspace; import org.eclipse.core.resources.IWorkspaceRunnable; import org.eclipse.core.resources.ResourcesPlugin; @@ -61,6 +63,7 @@ public class ExternalExportProjectProvider extends AbstractExportProjectProvider private static final String CONTENT = "content"; //$NON-NLS-1$ public static final String OPT_SOURCE = "-source"; //$NON-NLS-1$ public static final String OPT_INCLUDE = "-include"; //$NON-NLS-1$ + public static final String OPT_EXCLUDE = "-exclude"; //$NON-NLS-1$ public static final String OPT_FRAGMENT_ID = "-id"; //$NON-NLS-1$ private IFolder content; @@ -88,10 +91,16 @@ public class ExternalExportProjectProvider extends AbstractExportProjectProvider includeFiles.addAll(getParameters(OPT_INCLUDE)); } + // -exclude + List excludeFiles = new ArrayList(); + if (isPresent(OPT_EXCLUDE)) { + excludeFiles.addAll(getParameters(OPT_EXCLUDE)); + } + // -id fragmentId= getSingleString(OPT_FRAGMENT_ID); - return createCCProject("__" + System.currentTimeMillis(), source, includeFiles); //$NON-NLS-1$ + return createCCProject("__" + System.currentTimeMillis(), source, includeFiles, excludeFiles); //$NON-NLS-1$ } /** @@ -111,27 +120,33 @@ public class ExternalExportProjectProvider extends AbstractExportProjectProvider * @throws CoreException */ private ICProject createCCProject(final String projectName, final File location, - final List includeFiles) throws CoreException { + final List includeFiles, final List excludeFiles) throws CoreException { final IWorkspace ws = ResourcesPlugin.getWorkspace(); final ICProject newProject[] = new ICProject[1]; ws.run(new IWorkspaceRunnable() { @Override public void run(IProgressMonitor monitor) throws CoreException { - IWorkspace workspace= ResourcesPlugin.getWorkspace(); - IProject project= workspace.getRoot().getProject("__prebuilt_index_temp__" + System.currentTimeMillis()); //$NON-NLS-1$ + IWorkspace workspace = ResourcesPlugin.getWorkspace(); + IProject project = workspace.getRoot().getProject("__prebuilt_index_temp__" + System.currentTimeMillis()); //$NON-NLS-1$ IProjectDescription description = workspace.newProjectDescription(project.getName()); CCorePlugin.getDefault().createCProject(description, project, NPM, PREBUILT_PROJECT_OWNER); CCorePlugin.getDefault().convertProjectFromCtoCC(project, NPM); - ICProjectDescription pd= CCorePlugin.getDefault().getProjectDescription(project, true); + ICProjectDescription pd = CCorePlugin.getDefault().getProjectDescription(project, true); newCfg(pd, project.getName(), "config"); //$NON-NLS-1$ CoreModel.getDefault().setProjectDescription(project, pd, true, new NullProgressMonitor()); + // Add in exclude filters + for (String excludeFile : excludeFiles) { + FileInfoMatcherDescription matcherDescription = ExportIndexFileInfoMatcher.getDescription(excludeFile); + project.createFilter(IResourceFilterDescription.EXCLUDE_ALL | IResourceFilterDescription.FOLDERS | IResourceFilterDescription.INHERITABLE, matcherDescription, 0, NPM); + } + ICProject cproject= CCorePlugin.getDefault().getCoreModel().create(project); // External content appears under a linked folder - content= cproject.getProject().getFolder(CONTENT); + content = project.getFolder(CONTENT); content.createLink(new Path(location.getAbsolutePath()), IResource.NONE, null); // Setup path entries