1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
|
/*******************************************************************************
* Copyright (c) 2007, 2008 Symbian 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:
* Andrew Ferguson (Symbian) - Initial implementation
* Markus Schorn (Wind River Systems)
*******************************************************************************/
package org.eclipse.cdt.internal.core.pdom.export;
import java.io.File;
import java.text.MessageFormat;
import java.util.Map;
import org.eclipse.cdt.core.CCorePlugin;
import org.eclipse.cdt.core.index.IIndexLocationConverter;
import org.eclipse.cdt.core.index.IIndexManager;
import org.eclipse.cdt.core.index.export.IExportProjectProvider;
import org.eclipse.cdt.core.model.ICProject;
import org.eclipse.cdt.core.model.LanguageManager;
import org.eclipse.cdt.internal.core.CCoreInternals;
import org.eclipse.cdt.internal.core.pdom.WritablePDOM;
import org.eclipse.cdt.internal.core.pdom.indexer.IndexerPreferences;
import org.eclipse.core.runtime.CoreException;
import org.eclipse.core.runtime.ISafeRunnable;
import org.eclipse.core.runtime.NullProgressMonitor;
/**
* An ISafeRunnable which
* <ul>
* <li>Creates a project for export
* <li>Exports the PDOM
* <li>Writes new properties to the PDOM
* <ul>
*/
public class GeneratePDOM implements ISafeRunnable {
protected IExportProjectProvider pm;
protected String[] applicationArguments;
protected File targetLocation;
protected String indexerID;
public GeneratePDOM(IExportProjectProvider pm, String[] applicationArguments, File targetLocation, String indexerID) {
this.pm= pm;
this.applicationArguments= applicationArguments;
this.targetLocation= targetLocation;
this.indexerID= indexerID;
}
public final void run() throws CoreException {
pm.setApplicationArguments(applicationArguments);
final ICProject cproject = pm.createProject();
if(cproject==null) {
fail(MessageFormat.format(Messages.GeneratePDOM_ProjectProviderReturnedNullCProject,
new Object [] {pm.getClass().getName()}));
return; // cannot be reached, inform the compiler
}
IIndexLocationConverter converter= pm.getLocationConverter(cproject);
if(converter==null) {
fail(MessageFormat.format(Messages.GeneratePDOM_NullLocationConverter,
new Object [] {pm.getClass().getName()}));
}
// index the project
IndexerPreferences.set(cproject.getProject(), IndexerPreferences.KEY_INDEXER_ID, indexerID);
try {
final IIndexManager im = CCorePlugin.getIndexManager();
for (int i = 0; i < 20; i++) {
if(CCoreInternals.getPDOMManager().isProjectRegistered(cproject)) {
im.joinIndexer(Integer.MAX_VALUE, new NullProgressMonitor());
if (!im.isIndexerSetupPostponed(cproject)) {
break;
}
}
Thread.sleep(200);
}
CCoreInternals.getPDOMManager().exportProjectPDOM(cproject, targetLocation, converter);
WritablePDOM exportedPDOM= new WritablePDOM(targetLocation, converter, LanguageManager.getInstance().getPDOMLinkageFactoryMappings());
exportedPDOM.acquireWriteLock(0);
try {
Map<String,String> exportProperties= pm.getExportProperties();
if(exportProperties!=null) {
for(Map.Entry<String,String> entry : exportProperties.entrySet()) {
exportedPDOM.setProperty(entry.getKey(), entry.getValue());
}
}
exportedPDOM.close();
}
finally {
exportedPDOM.releaseWriteLock();
}
} catch(InterruptedException ie) {
String msg= MessageFormat.format(Messages.GeneratePDOM_GenericGenerationFailed, new Object[] {ie.getMessage()});
throw new CoreException(CCorePlugin.createStatus(msg, ie));
}
}
public void handleException(Throwable exception) {
CCorePlugin.log(exception);
}
private void fail(String message) throws CoreException {
GeneratePDOMApplication.fail(message);
}
}
|