1
0
Fork 0
mirror of https://github.com/eclipse-cdt/cdt synced 2025-04-23 22:52:11 +02:00

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
This commit is contained in:
Doug Schaefer 2013-07-25 15:25:30 -04:00
parent 33d6e7c0db
commit 6bbeb75bc0
2 changed files with 86 additions and 6 deletions

View file

@ -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);
}
}

View file

@ -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<String> excludeFiles = new ArrayList<String>();
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<String> includeFiles) throws CoreException {
final List<String> includeFiles, final List<String> 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