1
0
Fork 0
mirror of https://github.com/eclipse-cdt/cdt synced 2025-04-29 19:45:01 +02:00

Based on suggestion/patch from James Blackburn we also add more verbosity when going through the folders, this is more reassuring to the user then to see a blank "Binary Thread search"

fixes for PR:149428
 PR74387
This commit is contained in:
Alain Magloire 2006-12-17 00:57:22 +00:00
parent 66948345f0
commit 23ad32e88a
3 changed files with 64 additions and 34 deletions

View file

@ -1,5 +1,5 @@
/******************************************************************************* /*******************************************************************************
* Copyright (c) 2000, 2005 QNX Software Systems and others. * Copyright (c) 2000, 2005, 2006 QNX Software Systems and others.
* All rights reserved. This program and the accompanying materials * All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0 * are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at * which accompanies this distribution, and is available at
@ -83,6 +83,7 @@ public class BinaryRunner {
public void start() { public void start() {
String taskName = CCorePlugin.getResourceString("CoreModel.BinaryRunner.Binary_Search_Thread"); //$NON-NLS-1$ String taskName = CCorePlugin.getResourceString("CoreModel.BinaryRunner.Binary_Search_Thread"); //$NON-NLS-1$
taskName += " (" + cproject.getElementName() + ")";
runner = new Job(taskName) { runner = new Job(taskName) {
/* /*
@ -91,10 +92,10 @@ public class BinaryRunner {
* @see org.eclipse.core.runtime.jobs.Job#run(org.eclipse.core.runtime.IProgressMonitor) * @see org.eclipse.core.runtime.jobs.Job#run(org.eclipse.core.runtime.IProgressMonitor)
*/ */
protected IStatus run(IProgressMonitor monitor) { protected IStatus run(IProgressMonitor monitor) {
IStatus status = Status.OK_STATUS;
if (cproject == null || monitor.isCanceled()) { if (cproject == null || monitor.isCanceled()) {
return Status.CANCEL_STATUS; status = Status.CANCEL_STATUS;
} } else {
try { try {
monitor.beginTask(getName(), IProgressMonitor.UNKNOWN); monitor.beginTask(getName(), IProgressMonitor.UNKNOWN);
@ -109,11 +110,12 @@ public class BinaryRunner {
CModelOperation op = new BinaryRunnerOperation(cproject); CModelOperation op = new BinaryRunnerOperation(cproject);
op.runOperation(monitor); op.runOperation(monitor);
monitor.done();
} catch (CoreException e) { } catch (CoreException e) {
return e.getStatus(); status = e.getStatus();
} }
return Status.OK_STATUS; }
monitor.done();
return status;
} }
}; };
runner.schedule(); runner.schedule();
@ -172,6 +174,8 @@ public class BinaryRunner {
// check against known content types // check against known content types
String name = proxy.getName(); String name = proxy.getName();
vMonitor.subTask(name); // give a hint to the user of what we are doing
IContentType contentType = CCorePlugin.getContentType(project, name); IContentType contentType = CCorePlugin.getContentType(project, name);
if (contentType != null && textContentType != null) { if (contentType != null && textContentType != null) {
if (contentType != null && contentType.isKindOf(textContentType)) { if (contentType != null && contentType.isKindOf(textContentType)) {

View file

@ -13,7 +13,6 @@
package org.eclipse.cdt.internal.core.model; package org.eclipse.cdt.internal.core.model;
import java.io.File;
import java.io.IOException; import java.io.IOException;
import java.io.InputStream; import java.io.InputStream;
import java.util.ArrayList; import java.util.ArrayList;
@ -408,8 +407,7 @@ public class CModelManager implements IResourceChangeListener, ICDescriptorListe
return null; return null;
} }
if (path.isAbsolute()) { if (path.isAbsolute()) {
File file = path.toFile(); if (! Util.isNonZeroLengthFile(path)) {
if (file == null || !file.isFile()) {
return null; return null;
} }
try { try {
@ -434,8 +432,7 @@ public class CModelManager implements IResourceChangeListener, ICDescriptorListe
IIncludeReference[] includeReferences = cproject.getIncludeReferences(); IIncludeReference[] includeReferences = cproject.getIncludeReferences();
for (int i = 0; i < includeReferences.length; i++) { for (int i = 0; i < includeReferences.length; i++) {
IPath includePath = includeReferences[i].getPath().append(path); IPath includePath = includeReferences[i].getPath().append(path);
File file = includePath.toFile(); if (Util.isNonZeroLengthFile(includePath)) {
if (file != null && file.isFile()) {
String id = CoreModel.getRegistedContentTypeId(cproject.getProject(), includePath.lastSegment()); String id = CoreModel.getRegistedContentTypeId(cproject.getProject(), includePath.lastSegment());
if (id == null) { if (id == null) {
// fallbakc to C Header // fallbakc to C Header
@ -567,11 +564,9 @@ public class CModelManager implements IResourceChangeListener, ICDescriptorListe
public IBinaryFile createBinaryFile(IFile file) { public IBinaryFile createBinaryFile(IFile file) {
//Avoid name special devices, empty files and the like //Avoid name special devices, empty files and the like
File f = new File(file.getLocationURI()); if (! Util.isNonZeroLengthFile(file.getLocationURI())) {
if (!f.isFile() || f.length() == 0) {
return null; return null;
} }
BinaryParserConfig[] parsers = getBinaryParser(file.getProject()); BinaryParserConfig[] parsers = getBinaryParser(file.getProject());
int hints = 0; int hints = 0;
@ -659,13 +654,14 @@ public class CModelManager implements IResourceChangeListener, ICDescriptorListe
} }
} }
public BinaryRunner getBinaryRunner(ICProject project, boolean start) { public BinaryRunner getBinaryRunner(ICProject cproject, boolean start) {
BinaryRunner runner = null; BinaryRunner runner = null;
synchronized (binaryRunners) { synchronized (binaryRunners) {
runner = (BinaryRunner)binaryRunners.get(project.getProject()); IProject project = cproject.getProject();
runner = (BinaryRunner)binaryRunners.get(project);
if (runner == null) { if (runner == null) {
runner = new BinaryRunner(project.getProject()); runner = new BinaryRunner(project);
binaryRunners.put(project.getProject(), runner); binaryRunners.put(project, runner);
if (start) { if (start) {
runner.start(); runner.start();
} }

View file

@ -17,6 +17,7 @@ import java.io.ByteArrayInputStream;
import java.io.IOException; import java.io.IOException;
import java.io.InputStream; import java.io.InputStream;
import java.io.InputStreamReader; import java.io.InputStreamReader;
import java.net.URI;
import java.text.MessageFormat; import java.text.MessageFormat;
import org.eclipse.cdt.core.CCorePlugin; import org.eclipse.cdt.core.CCorePlugin;
@ -25,8 +26,12 @@ import org.eclipse.cdt.core.model.CModelException;
import org.eclipse.cdt.core.model.ICModelStatusConstants; import org.eclipse.cdt.core.model.ICModelStatusConstants;
import org.eclipse.cdt.internal.core.model.IDebugLogConstants.DebugLogConstant; import org.eclipse.cdt.internal.core.model.IDebugLogConstants.DebugLogConstant;
import org.eclipse.cdt.internal.core.util.CharArrayBuffer; import org.eclipse.cdt.internal.core.util.CharArrayBuffer;
import org.eclipse.core.filesystem.EFS;
import org.eclipse.core.filesystem.IFileInfo;
import org.eclipse.core.filesystem.URIUtil;
import org.eclipse.core.resources.IFile; import org.eclipse.core.resources.IFile;
import org.eclipse.core.runtime.CoreException; import org.eclipse.core.runtime.CoreException;
import org.eclipse.core.runtime.IPath;
import org.eclipse.core.runtime.IStatus; import org.eclipse.core.runtime.IStatus;
import org.eclipse.core.runtime.Status; import org.eclipse.core.runtime.Status;
@ -423,5 +428,30 @@ public class Util implements ICLogConstants {
return null; return null;
} }
/**
* Return true if the file is not a directory and has length > 0
* @param path
* @return
*/
public static boolean isNonZeroLengthFile(IPath path) {
return isNonZeroLengthFile(URIUtil.toURI(path));
}
/**
* Return true if the file is not a directory and has length > 0
* @param path
* @return
*/
public static boolean isNonZeroLengthFile(URI uri) {
try {
IFileInfo file = EFS.getStore(uri).fetchInfo();
if (file.getLength() == EFS.NONE) {
return false;
}
return true;
} catch (CoreException e) {
// ignore
}
return false;
}
} }