Some Eclipse Foundation services are deprecated, or will be soon. Please ensure you've read this important communication.
View | Details | Raw Unified | Return to bug 229989 | Differences between
and this patch

Collapse All | Expand All

(-)parser/org/eclipse/cdt/internal/core/pdom/export/GeneratePDOMApplication.java (-2 / +6 lines)
Lines 1-5 Link Here
1
/*******************************************************************************
1
/*******************************************************************************
2
 * Copyright (c) 2007 Symbian Software Systems and others.
2
 * Copyright (c) 2007, 2008 Symbian Software Systems and others.
3
 * All rights reserved. This program and the accompanying materials
3
 * All rights reserved. This program and the accompanying materials
4
 * are made available under the terms of the Eclipse Public License v1.0
4
 * are made available under the terms of the Eclipse Public License v1.0
5
 * which accompanies this distribution, and is available at
5
 * which accompanies this distribution, and is available at
Lines 116-122 Link Here
116
116
117
		GeneratePDOM generate = new GeneratePDOM(pprovider,	appArgs, targetLocation, indexerID);
117
		GeneratePDOM generate = new GeneratePDOM(pprovider,	appArgs, targetLocation, indexerID);
118
		output(Messages.GeneratePDOMApplication_GenerationStarts);
118
		output(Messages.GeneratePDOMApplication_GenerationStarts);
119
		generate.run();
119
		try {
120
			generate.run();
121
		} catch(CoreException ce) {
122
			CCorePlugin.log(ce);
123
		}
120
		output(Messages.GeneratePDOMApplication_GenerationEnds);
124
		output(Messages.GeneratePDOMApplication_GenerationEnds);
121
		return null;
125
		return null;
122
	}
126
	}
(-)parser/org/eclipse/cdt/internal/core/pdom/export/messages.properties (-1 / +3 lines)
Lines 10-18 Link Here
10
###############################################################################
10
###############################################################################
11
GeneratePDOMApplication_Initializing=== Initializing
11
GeneratePDOMApplication_Initializing=== Initializing
12
GeneratePDOM_GenericGenerationFailed=Generation failed: {0}
12
GeneratePDOM_GenericGenerationFailed=Generation failed: {0}
13
GeneratePDOM_Incomplete=Pre-built index content is incomplete or out of date
13
GeneratePDOM_NullLocationConverter=IExportProjectProvider implementation of getLocationConverter() returned null ({0})
14
GeneratePDOM_NullLocationConverter=IExportProjectProvider implementation of getLocationConverter() returned null ({0})
14
GeneratePDOMApplication_CouldNotFindInitializer=Could not find IExportProjectProvider: {0}
15
GeneratePDOM_ProjectProviderReturnedNullCProject=IExportProjectProvider implementation of createProject() returned null ({0})
15
GeneratePDOM_ProjectProviderReturnedNullCProject=IExportProjectProvider implementation of createProject() returned null ({0})
16
GeneratePDOM_Success=Pre-built index content successfully generated
17
GeneratePDOMApplication_CouldNotFindInitializer=Could not find IExportProjectProvider: {0}
16
GeneratePDOMApplication_UsingDefaultProjectProvider=-pprovider not specified - defaulting to {0}
18
GeneratePDOMApplication_UsingDefaultProjectProvider=-pprovider not specified - defaulting to {0}
17
GeneratePDOMApplication_GenerationStarts=== Generation starts
19
GeneratePDOMApplication_GenerationStarts=== Generation starts
18
GeneratePDOMApplication_InvalidIndexerID={0} takes zero or one argument
20
GeneratePDOMApplication_InvalidIndexerID={0} takes zero or one argument
(-)parser/org/eclipse/cdt/internal/core/pdom/export/GeneratePDOM.java (-20 / +38 lines)
Lines 25-32 Link Here
25
import org.eclipse.cdt.internal.core.pdom.WritablePDOM;
25
import org.eclipse.cdt.internal.core.pdom.WritablePDOM;
26
import org.eclipse.cdt.internal.core.pdom.indexer.IndexerPreferences;
26
import org.eclipse.cdt.internal.core.pdom.indexer.IndexerPreferences;
27
import org.eclipse.core.runtime.CoreException;
27
import org.eclipse.core.runtime.CoreException;
28
import org.eclipse.core.runtime.ISafeRunnable;
28
import org.eclipse.core.runtime.IStatus;
29
import org.eclipse.core.runtime.NullProgressMonitor;
29
import org.eclipse.core.runtime.NullProgressMonitor;
30
import org.eclipse.core.runtime.Status;
30
31
31
/**
32
/**
32
 * An ISafeRunnable which
33
 * An ISafeRunnable which
Lines 36-42 Link Here
36
 * <li>Writes new properties to the PDOM
37
 * <li>Writes new properties to the PDOM
37
 * <ul>
38
 * <ul>
38
 */
39
 */
39
public class GeneratePDOM implements ISafeRunnable {
40
public class GeneratePDOM {
40
	protected IExportProjectProvider pm;
41
	protected IExportProjectProvider pm;
41
	protected String[] applicationArguments;
42
	protected String[] applicationArguments;
42
	protected File targetLocation;
43
	protected File targetLocation;
Lines 59-71 Link Here
59
		this.deleteOnExit= deleteOnExit;
60
		this.deleteOnExit= deleteOnExit;
60
	}
61
	}
61
62
62
	public final void run() throws CoreException {
63
	/**
64
	 * Executes the PDOM generation 
65
	 * @return {@link IStatus#OK} if the generated content is complete, {@link IStatus#ERROR} otherwise.
66
	 * @throws CoreException if an internal or invalid configuration error occurs
67
	 */
68
	public final IStatus run() throws CoreException {
69
		boolean isContentSynced= false;
70
		
71
		// create the project
63
		pm.setApplicationArguments(applicationArguments);
72
		pm.setApplicationArguments(applicationArguments);
64
		final ICProject cproject = pm.createProject();
73
		final ICProject cproject = pm.createProject();
65
		if(cproject==null) {
74
		if(cproject==null) {
66
			fail(MessageFormat.format(Messages.GeneratePDOM_ProjectProviderReturnedNullCProject,
75
			fail(MessageFormat.format(Messages.GeneratePDOM_ProjectProviderReturnedNullCProject,
67
					new Object [] {pm.getClass().getName()}));
76
					new Object [] {pm.getClass().getName()}));
68
			return; // cannot be reached, inform the compiler
77
			return null; // cannot be reached, inform the compiler
69
		}
78
		}
70
		
79
		
71
		IIndexLocationConverter converter= pm.getLocationConverter(cproject);
80
		IIndexLocationConverter converter= pm.getLocationConverter(cproject);
Lines 89-109 Link Here
89
				Thread.sleep(200);
98
				Thread.sleep(200);
90
			}
99
			}
91
		
100
		
92
			CCoreInternals.getPDOMManager().exportProjectPDOM(cproject, targetLocation, converter);
101
			// check status
93
			WritablePDOM exportedPDOM= new WritablePDOM(targetLocation, converter, LanguageManager.getInstance().getPDOMLinkageFactoryMappings());
102
			isContentSynced= CCoreInternals.getPDOMManager().isProjectContentSynced(cproject);
94
			exportedPDOM.acquireWriteLock(0);
103
			
95
			try {
104
			if(isContentSynced) {
96
				Map<String,String> exportProperties= pm.getExportProperties();
105
				// export a .pdom file
97
				if(exportProperties!=null) {
106
				CCoreInternals.getPDOMManager().exportProjectPDOM(cproject, targetLocation, converter);
98
					for(Map.Entry<String,String> entry : exportProperties.entrySet()) {
107
99
						exportedPDOM.setProperty(entry.getKey(), entry.getValue());
108
				// write properties to exported PDOM
109
				WritablePDOM exportedPDOM= new WritablePDOM(targetLocation, converter, LanguageManager.getInstance().getPDOMLinkageFactoryMappings());
110
				exportedPDOM.acquireWriteLock(0);
111
				try {
112
					Map<String,String> exportProperties= pm.getExportProperties();
113
					if(exportProperties!=null) {
114
						for(Map.Entry<String,String> entry : exportProperties.entrySet()) {
115
							exportedPDOM.setProperty(entry.getKey(), entry.getValue());
116
						}
100
					}
117
					}
118
					exportedPDOM.close();
119
				}
120
				finally {
121
					exportedPDOM.releaseWriteLock();
101
				}
122
				}
102
				exportedPDOM.close();
103
			}
104
			finally {
105
				exportedPDOM.releaseWriteLock();
106
			}
123
			}
124
			
107
		} catch(InterruptedException ie) {
125
		} catch(InterruptedException ie) {
108
			String msg= MessageFormat.format(Messages.GeneratePDOM_GenericGenerationFailed, new Object[] {ie.getMessage()});
126
			String msg= MessageFormat.format(Messages.GeneratePDOM_GenericGenerationFailed, new Object[] {ie.getMessage()});
109
			throw new CoreException(CCorePlugin.createStatus(msg, ie));
127
			throw new CoreException(CCorePlugin.createStatus(msg, ie));
Lines 112-121 Link Here
112
				cproject.getProject().delete(true, new NullProgressMonitor());
130
				cproject.getProject().delete(true, new NullProgressMonitor());
113
			}
131
			}
114
		}
132
		}
115
	}
133
		
116
134
		return isContentSynced ?
117
	public void handleException(Throwable exception) {
135
			  new Status(IStatus.OK, CCorePlugin.PLUGIN_ID, Messages.GeneratePDOM_Success)
118
		CCorePlugin.log(exception);
136
			: new Status(IStatus.ERROR, CCorePlugin.PLUGIN_ID, Messages.GeneratePDOM_Incomplete);
119
	}
137
	}
120
	
138
	
121
	private void fail(String message) throws CoreException {
139
	private void fail(String message) throws CoreException {
(-)parser/org/eclipse/cdt/internal/core/pdom/export/Messages.java (+2 lines)
Lines 15-22 Link Here
15
public class Messages extends NLS {
15
public class Messages extends NLS {
16
	private static final String BUNDLE_NAME = "org.eclipse.cdt.internal.core.pdom.export.messages"; //$NON-NLS-1$
16
	private static final String BUNDLE_NAME = "org.eclipse.cdt.internal.core.pdom.export.messages"; //$NON-NLS-1$
17
	public static String GeneratePDOM_GenericGenerationFailed;
17
	public static String GeneratePDOM_GenericGenerationFailed;
18
	public static String GeneratePDOM_Incomplete;
18
	public static String GeneratePDOM_NullLocationConverter;
19
	public static String GeneratePDOM_NullLocationConverter;
19
	public static String GeneratePDOM_ProjectProviderReturnedNullCProject;
20
	public static String GeneratePDOM_ProjectProviderReturnedNullCProject;
21
	public static String GeneratePDOM_Success;
20
	public static String GeneratePDOMApplication_CouldNotFindInitializer;
22
	public static String GeneratePDOMApplication_CouldNotFindInitializer;
21
	public static String GeneratePDOMApplication_GenerationEnds;
23
	public static String GeneratePDOMApplication_GenerationEnds;
22
	public static String GeneratePDOMApplication_GenerationStarts;
24
	public static String GeneratePDOMApplication_GenerationStarts;
(-)parser/org/eclipse/cdt/internal/core/pdom/indexer/TranslationUnitCollector.java (-1 / +1 lines)
Lines 18-24 Link Here
18
import org.eclipse.core.runtime.CoreException;
18
import org.eclipse.core.runtime.CoreException;
19
import org.eclipse.core.runtime.IProgressMonitor;
19
import org.eclipse.core.runtime.IProgressMonitor;
20
20
21
final class TranslationUnitCollector implements ICElementVisitor {
21
final public class TranslationUnitCollector implements ICElementVisitor {
22
	private final Collection<ITranslationUnit> fSources;
22
	private final Collection<ITranslationUnit> fSources;
23
	private final Collection<ITranslationUnit> fHeaders;
23
	private final Collection<ITranslationUnit> fHeaders;
24
	private final IProgressMonitor fProgressMonitor;
24
	private final IProgressMonitor fProgressMonitor;
(-)parser/org/eclipse/cdt/internal/core/pdom/PDOMManager.java (+80 lines)
Lines 10-15 Link Here
10
 *     Markus Schorn (Wind River Systems)
10
 *     Markus Schorn (Wind River Systems)
11
 *     Andrew Ferguson (Symbian)
11
 *     Andrew Ferguson (Symbian)
12
 *     Sergey Prigogin (Google)
12
 *     Sergey Prigogin (Google)
13
 *     Tim Kelly (Nokia)
13
 *******************************************************************************/
14
 *******************************************************************************/
14
package org.eclipse.cdt.internal.core.pdom;
15
package org.eclipse.cdt.internal.core.pdom;
15
16
Lines 29-34 Link Here
29
import java.util.List;
30
import java.util.List;
30
import java.util.Map;
31
import java.util.Map;
31
import java.util.Properties;
32
import java.util.Properties;
33
import java.util.Set;
32
34
33
import org.eclipse.cdt.core.CCorePlugin;
35
import org.eclipse.cdt.core.CCorePlugin;
34
import org.eclipse.cdt.core.CCorePreferenceConstants;
36
import org.eclipse.cdt.core.CCorePreferenceConstants;
Lines 37-45 Link Here
37
import org.eclipse.cdt.core.dom.IPDOMManager;
39
import org.eclipse.cdt.core.dom.IPDOMManager;
38
import org.eclipse.cdt.core.index.IIndex;
40
import org.eclipse.cdt.core.index.IIndex;
39
import org.eclipse.cdt.core.index.IIndexChangeListener;
41
import org.eclipse.cdt.core.index.IIndexChangeListener;
42
import org.eclipse.cdt.core.index.IIndexFile;
43
import org.eclipse.cdt.core.index.IIndexFileLocation;
44
import org.eclipse.cdt.core.index.IIndexInclude;
40
import org.eclipse.cdt.core.index.IIndexLocationConverter;
45
import org.eclipse.cdt.core.index.IIndexLocationConverter;
41
import org.eclipse.cdt.core.index.IIndexManager;
46
import org.eclipse.cdt.core.index.IIndexManager;
42
import org.eclipse.cdt.core.index.IIndexerStateListener;
47
import org.eclipse.cdt.core.index.IIndexerStateListener;
48
import org.eclipse.cdt.core.index.IndexLocationFactory;
43
import org.eclipse.cdt.core.index.IndexerSetupParticipant;
49
import org.eclipse.cdt.core.index.IndexerSetupParticipant;
44
import org.eclipse.cdt.core.model.CModelException;
50
import org.eclipse.cdt.core.model.CModelException;
45
import org.eclipse.cdt.core.model.CoreModel;
51
import org.eclipse.cdt.core.model.CoreModel;
Lines 69-75 Link Here
69
import org.eclipse.cdt.internal.core.pdom.indexer.PDOMRebuildTask;
75
import org.eclipse.cdt.internal.core.pdom.indexer.PDOMRebuildTask;
70
import org.eclipse.cdt.internal.core.pdom.indexer.PDOMUpdateTask;
76
import org.eclipse.cdt.internal.core.pdom.indexer.PDOMUpdateTask;
71
import org.eclipse.cdt.internal.core.pdom.indexer.ProjectIndexerInputAdapter;
77
import org.eclipse.cdt.internal.core.pdom.indexer.ProjectIndexerInputAdapter;
78
import org.eclipse.cdt.internal.core.pdom.indexer.TranslationUnitCollector;
72
import org.eclipse.cdt.internal.core.pdom.indexer.TriggerNotificationTask;
79
import org.eclipse.cdt.internal.core.pdom.indexer.TriggerNotificationTask;
80
import org.eclipse.core.resources.IFile;
73
import org.eclipse.core.resources.IFolder;
81
import org.eclipse.core.resources.IFolder;
74
import org.eclipse.core.resources.IProject;
82
import org.eclipse.core.resources.IProject;
75
import org.eclipse.core.resources.IResource;
83
import org.eclipse.core.resources.IResource;
Lines 82-88 Link Here
82
import org.eclipse.core.runtime.ISafeRunnable;
90
import org.eclipse.core.runtime.ISafeRunnable;
83
import org.eclipse.core.runtime.IStatus;
91
import org.eclipse.core.runtime.IStatus;
84
import org.eclipse.core.runtime.ListenerList;
92
import org.eclipse.core.runtime.ListenerList;
93
import org.eclipse.core.runtime.NullProgressMonitor;
85
import org.eclipse.core.runtime.OperationCanceledException;
94
import org.eclipse.core.runtime.OperationCanceledException;
95
import org.eclipse.core.runtime.Path;
86
import org.eclipse.core.runtime.Platform;
96
import org.eclipse.core.runtime.Platform;
87
import org.eclipse.core.runtime.Preferences;
97
import org.eclipse.core.runtime.Preferences;
88
import org.eclipse.core.runtime.QualifiedName;
98
import org.eclipse.core.runtime.QualifiedName;
Lines 1379-1382 Link Here
1379
	public boolean isProjectRegistered(ICProject project) {
1389
	public boolean isProjectRegistered(ICProject project) {
1380
		return getIndexer(project) != null;
1390
		return getIndexer(project) != null;
1381
	}
1391
	}
1392
	
1393
	/**
1394
	 * @param cproject the project to check
1395
	 * @return whether the content in the project fragment of the specified project's index
1396
	 * is complete (contains all sources) and up to date.
1397
	 * @throws CoreException
1398
	 */
1399
	public boolean isProjectContentSynced(ICProject cproject) throws CoreException {
1400
		Set<ITranslationUnit> sources= new HashSet<ITranslationUnit>();
1401
		cproject.accept(new TranslationUnitCollector(sources, null, new NullProgressMonitor()));
1402
1403
		try {
1404
			IIndex index= getIndex(cproject);
1405
			index.acquireReadLock();
1406
			try {
1407
				for(ITranslationUnit tu : sources) {
1408
					IResource resource= tu.getResource();
1409
					if(resource instanceof IFile) {
1410
						IIndexFileLocation location= IndexLocationFactory.getWorkspaceIFL((IFile)resource);
1411
						if(!areSynchronized(index, resource, location)) {
1412
							return false;
1413
						}
1414
					}
1415
				}
1416
			} finally {
1417
				index.releaseReadLock();
1418
			}
1419
		} catch(InterruptedException ie) {
1420
			CCorePlugin.log(ie);
1421
		}
1422
1423
		return true;
1424
	}
1425
	
1426
	/**
1427
	 * Recursively checks that the specified file, and its include are up-to-date.
1428
	 * @param index the index to check against
1429
	 * @param resource the resource to check from the workspace
1430
	 * @param location the location to check from the index
1431
	 * @return whether the specified file, and its includes are up-to-date.
1432
	 * @throws CoreException
1433
	 */
1434
	private static boolean areSynchronized(IIndex index, IResource resource, IIndexFileLocation location) throws CoreException {
1435
		IIndexFile[] file= index.getFiles(location);
1436
1437
		// pre-includes may be listed twice (191989)
1438
		if(file.length < 1 || file.length > 2)
1439
			return false;
1440
1441
		if(resource.getLocalTimeStamp() != file[0].getTimestamp())
1442
			return false;
1443
		
1444
		// if it is up-to-date, the includes have not changed and may
1445
		// be read from the index.
1446
		IIndexInclude[] includes= index.findIncludes(file[0]);
1447
		for(IIndexInclude inc : includes) {
1448
			IIndexFileLocation newLocation= inc.getIncludesLocation();
1449
			if(newLocation != null) {
1450
				String path= newLocation.getFullPath();
1451
				if(path != null) {
1452
					IResource newResource= ResourcesPlugin.getWorkspace().getRoot().getFile(new Path(path));
1453
					if(!areSynchronized(index, newResource, newLocation)) {
1454
						return false;
1455
					}
1456
				}
1457
			}
1458
		}
1459
		
1460
		return true;
1461
	}
1382
}
1462
}

Return to bug 229989