1
0
Fork 0
mirror of https://github.com/eclipse-cdt/cdt synced 2025-08-02 05:45:58 +02:00

fix locking bug

This commit is contained in:
Andrew Ferguson 2007-02-28 17:37:24 +00:00
parent 2290002124
commit fc34a9ccbf
4 changed files with 43 additions and 45 deletions

View file

@ -61,37 +61,37 @@ public class ExternalExportProjectProvider extends AbstractExportProjectProvider
protected static final String ARG_SOURCE = "-source"; //$NON-NLS-1$ protected static final String ARG_SOURCE = "-source"; //$NON-NLS-1$
protected static final String ARG_INCLUDE = "-include"; //$NON-NLS-1$ protected static final String ARG_INCLUDE = "-include"; //$NON-NLS-1$
protected static final String ARG_FRAGMENT_ID = "-id"; //$NON-NLS-1$ protected static final String ARG_FRAGMENT_ID = "-id"; //$NON-NLS-1$
private IFolder content; private IFolder content;
private String fragmentId; private String fragmentId;
public ExternalExportProjectProvider() { public ExternalExportProjectProvider() {
super(); super();
} }
/* /*
* (non-Javadoc) * (non-Javadoc)
* @see org.eclipse.cdt.core.index.export.IProjectForExportManager#createProject(java.util.Map) * @see org.eclipse.cdt.core.index.export.IProjectForExportManager#createProject(java.util.Map)
*/ */
public ICProject createProject() throws CoreException { public ICProject createProject() throws CoreException {
// -source // -source
File source= new File(getSingleString(ARG_SOURCE)); File source= new File(getSingleString(ARG_SOURCE));
if(!source.exists()) { if(!source.exists()) {
fail(MessageFormat.format(Messages.ExternalContentPEM_LocationToIndexNonExistent, new Object[] {source})); fail(MessageFormat.format(Messages.ExternalContentPEM_LocationToIndexNonExistent, new Object[] {source}));
} }
// -include // -include
List includeFiles= new ArrayList(); List includeFiles= new ArrayList();
if(isPresent(ARG_INCLUDE)) { if(isPresent(ARG_INCLUDE)) {
includeFiles.addAll(getParameters(ARG_INCLUDE)); includeFiles.addAll(getParameters(ARG_INCLUDE));
} }
// -id // -id
fragmentId= getSingleString(ARG_FRAGMENT_ID); fragmentId= getSingleString(ARG_FRAGMENT_ID);
return createCProject("__"+System.currentTimeMillis(), source, IPDOMManager.ID_FAST_INDEXER, includeFiles); //$NON-NLS-1$ return createCProject("__"+System.currentTimeMillis(), source, IPDOMManager.ID_FAST_INDEXER, includeFiles); //$NON-NLS-1$
} }
/** /**
* Returns the project folder the external content is stored in * Returns the project folder the external content is stored in
* @return the project folder the external content is stored in * @return the project folder the external content is stored in
@ -99,7 +99,7 @@ public class ExternalExportProjectProvider extends AbstractExportProjectProvider
protected IFolder getContentFolder() { protected IFolder getContentFolder() {
return content; return content;
} }
/** /**
* Convenience method for creating a cproject * Convenience method for creating a cproject
* @param projectName the name for the new project * @param projectName the name for the new project
@ -114,14 +114,14 @@ public class ExternalExportProjectProvider extends AbstractExportProjectProvider
final File location, final File location,
final String indexerID, final String indexerID,
final List includeFiles final List includeFiles
) throws CoreException { ) throws CoreException {
final IWorkspace ws = ResourcesPlugin.getWorkspace(); final IWorkspace ws = ResourcesPlugin.getWorkspace();
final ICProject newProject[] = new ICProject[1]; final ICProject newProject[] = new ICProject[1];
ws.run(new IWorkspaceRunnable() { ws.run(new IWorkspaceRunnable() {
public void run(IProgressMonitor monitor) throws CoreException { public void run(IProgressMonitor monitor) throws CoreException {
IWorkspaceRoot root = ws.getRoot(); IWorkspaceRoot root = ws.getRoot();
IProject project = root.getProject(projectName); IProject project = root.getProject(projectName);
if (!project.exists()) { if (!project.exists()) {
project.create(NPM); project.create(NPM);
@ -137,13 +137,13 @@ public class ExternalExportProjectProvider extends AbstractExportProjectProvider
if (!project.hasNature(CCProjectNature.CC_NATURE_ID)) { if (!project.hasNature(CCProjectNature.CC_NATURE_ID)) {
addNatureToProject(project, CCProjectNature.CC_NATURE_ID, NPM); addNatureToProject(project, CCProjectNature.CC_NATURE_ID, NPM);
} }
ICProject cproject = CCorePlugin.getDefault().getCoreModel().create(project); ICProject cproject = CCorePlugin.getDefault().getCoreModel().create(project);
// External content appears under a linked folder // External content appears under a linked folder
content= cproject.getProject().getFolder(CONTENT); content= cproject.getProject().getFolder(CONTENT);
content.createLink(new Path(location.getAbsolutePath()), IResource.NONE, null); content.createLink(new Path(location.getAbsolutePath()), IResource.NONE, null);
// Setup path entries // Setup path entries
List entries= new ArrayList(Arrays.asList(CoreModel.getRawPathEntries(cproject))); List entries= new ArrayList(Arrays.asList(CoreModel.getRawPathEntries(cproject)));
for(Iterator j= includeFiles.iterator(); j.hasNext(); ) { for(Iterator j= includeFiles.iterator(); j.hasNext(); ) {
@ -151,14 +151,14 @@ public class ExternalExportProjectProvider extends AbstractExportProjectProvider
CoreModel.newIncludeFileEntry( CoreModel.newIncludeFileEntry(
cproject.getProject().getFullPath(), cproject.getProject().getFullPath(),
new Path((String) j.next()) new Path((String) j.next())
)); ));
} }
entries.add(CoreModel.newSourceEntry(content.getProjectRelativePath())); entries.add(CoreModel.newSourceEntry(content.getProjectRelativePath()));
cproject.setRawPathEntries( cproject.setRawPathEntries(
(IPathEntry[]) entries.toArray(new IPathEntry[includeFiles.size()]), (IPathEntry[]) entries.toArray(new IPathEntry[includeFiles.size()]),
new NullProgressMonitor() new NullProgressMonitor()
); );
newProject[0]= cproject; newProject[0]= cproject;
} }
}, null); }, null);
@ -167,10 +167,10 @@ public class ExternalExportProjectProvider extends AbstractExportProjectProvider
IndexerPreferences.set(newProject[0].getProject(), IndexerPreferences.KEY_INDEX_ALL_FILES, Boolean.TRUE.toString()); IndexerPreferences.set(newProject[0].getProject(), IndexerPreferences.KEY_INDEX_ALL_FILES, Boolean.TRUE.toString());
IndexerPreferences.set(newProject[0].getProject(), IndexerPreferences.KEY_INDEXER_ID, indexerID); IndexerPreferences.set(newProject[0].getProject(), IndexerPreferences.KEY_INDEXER_ID, indexerID);
} }
return newProject[0]; return newProject[0];
} }
/* /*
* This should be a platform/CDT API * This should be a platform/CDT API
*/ */
@ -183,8 +183,8 @@ public class ExternalExportProjectProvider extends AbstractExportProjectProvider
description.setNatureIds(newNatures); description.setNatureIds(newNatures);
proj.setDescription(description, monitor); proj.setDescription(description, monitor);
} }
/* /*
* (non-Javadoc) * (non-Javadoc)
* @see org.eclipse.cdt.core.index.export.IExportProjectProvider#getLocationConverter(org.eclipse.cdt.core.model.ICProject) * @see org.eclipse.cdt.core.index.export.IExportProjectProvider#getLocationConverter(org.eclipse.cdt.core.model.ICProject)
@ -192,7 +192,7 @@ public class ExternalExportProjectProvider extends AbstractExportProjectProvider
public IIndexLocationConverter getLocationConverter(final ICProject cproject) { public IIndexLocationConverter getLocationConverter(final ICProject cproject) {
return new ResourceContainerRelativeLocationConverter(content); return new ResourceContainerRelativeLocationConverter(content);
} }
/* /*
* (non-Javadoc) * (non-Javadoc)
* @see org.eclipse.cdt.core.index.export.IExportProjectProvider#getExportProperties() * @see org.eclipse.cdt.core.index.export.IExportProjectProvider#getExportProperties()

View file

@ -718,8 +718,7 @@ public class PDOMManager implements IPDOMManager, IWritableIndexManager, IListen
* Exports the project PDOM to the specified location, rewriting locations with * Exports the project PDOM to the specified location, rewriting locations with
* the specified location converter. * the specified location converter.
* <br> * <br>
* Note. this method does not acquire or release any locks. It is expected * Note. This will acquire a write lock while the pdom is exported
* that this will be done by the caller.
* @param targetLocation a location that does not currently exist * @param targetLocation a location that does not currently exist
* @param newConverter * @param newConverter
* @throws CoreException * @throws CoreException

View file

@ -20,7 +20,6 @@ import org.eclipse.cdt.core.index.IIndexLocationConverter;
import org.eclipse.cdt.core.index.export.IExportProjectProvider; import org.eclipse.cdt.core.index.export.IExportProjectProvider;
import org.eclipse.cdt.core.model.ICProject; import org.eclipse.cdt.core.model.ICProject;
import org.eclipse.cdt.internal.core.CCoreInternals; import org.eclipse.cdt.internal.core.CCoreInternals;
import org.eclipse.cdt.internal.core.pdom.PDOM;
import org.eclipse.cdt.internal.core.pdom.WritablePDOM; import org.eclipse.cdt.internal.core.pdom.WritablePDOM;
import org.eclipse.core.runtime.CoreException; import org.eclipse.core.runtime.CoreException;
import org.eclipse.core.runtime.ISafeRunnable; import org.eclipse.core.runtime.ISafeRunnable;
@ -54,11 +53,11 @@ public class GeneratePDOM implements ISafeRunnable {
CCorePlugin.getIndexManager().joinIndexer(Integer.MAX_VALUE, new NullProgressMonitor()); CCorePlugin.getIndexManager().joinIndexer(Integer.MAX_VALUE, new NullProgressMonitor());
IIndexLocationConverter converter= pm.getLocationConverter(cproject); IIndexLocationConverter converter= pm.getLocationConverter(cproject);
try { try {
PDOM pdom = (PDOM) CCoreInternals.getPDOMManager().getPDOM(cproject); CCoreInternals.getPDOMManager().exportProjectPDOM(cproject, targetLocation, converter);
pdom.acquireWriteLock(0); WritablePDOM exportedPDOM= new WritablePDOM(targetLocation, converter);
exportedPDOM.acquireWriteLock(0);
try { try {
CCoreInternals.getPDOMManager().exportProjectPDOM(cproject, targetLocation, converter);
WritablePDOM exportedPDOM= new WritablePDOM(targetLocation, converter);
Map exportProperties= pm.getExportProperties(); Map exportProperties= pm.getExportProperties();
if(exportProperties!=null) { if(exportProperties!=null) {
for(Iterator i = exportProperties.entrySet().iterator(); i.hasNext(); ) { for(Iterator i = exportProperties.entrySet().iterator(); i.hasNext(); ) {
@ -67,7 +66,7 @@ public class GeneratePDOM implements ISafeRunnable {
} }
} }
} finally { } finally {
pdom.releaseWriteLock(0); exportedPDOM.releaseWriteLock(0);
} }
} catch(InterruptedException ie) { } catch(InterruptedException ie) {
String msg= MessageFormat.format(Messages.GeneratePDOM_GenericGenerationFailed, new Object[] {ie.getMessage()}); String msg= MessageFormat.format(Messages.GeneratePDOM_GenericGenerationFailed, new Object[] {ie.getMessage()});

View file

@ -188,7 +188,7 @@ public class GeneratePDOMApplication implements IApplication {
worked += work; worked += work;
int pc = totalWork<1 ? 0 : (int) ((worked*100D)/totalWork); int pc = totalWork<1 ? 0 : (int) ((worked*100D)/totalWork);
if(shouldOutput()) { if(shouldOutput()) {
writer.println(pc+"% "+subTask+" "+worked+" "+totalWork); //$NON-NLS-1$ //$NON-NLS-2$//$NON-NLS-3$ writer.println(pc+"% "+subTask); //$NON-NLS-1$
} }
} }
} }