Package org.eclipse.core.runtime

Examples of org.eclipse.core.runtime.SubMonitor


    private static final String pseudo[] = {
            "0", "1", "2", "3", "4", "5", "6", "7", "8", "9", "a", "b", "c", "d", "e", "f"
    };

    private static SubMonitor createProgressMonitor(ZipEntry entry, long limit, IProgressMonitor monitor) {
        SubMonitor progress;
        long size = entry.getSize();
        if (size == -1) {
            progress = SubMonitor.convert(monitor);
        } else {
            long ticks = (limit == -1) ? size : Math.min(size, limit);
View Full Code Here


        }
        return progress;
    }

    protected static void readAsText(ZipFile zipFile, ZipEntry entry, String encoding, Writer out, long limit, IProgressMonitor monitor) throws IOException {
        SubMonitor progress = createProgressMonitor(entry, limit, monitor);

        boolean limitReached = false;
        InputStream stream = zipFile.getInputStream(entry);
        try {
            long total = 0;

            byte[] buffer = new byte[1024];
            while (true) {
                if (progress.isCanceled())
                    return;
                int bytesRead = stream.read(buffer, 0, 1024);
                if (bytesRead < 0)
                    break;
                String string = new String(buffer, 0, bytesRead, encoding);
                out.write(string);

                total += bytesRead;
                progress.worked(bytesRead);
                if (limit >= 0 && total >= limit) {
                    limitReached = true;
                    return;
                }
            }
View Full Code Here

        return (char) b;
    }

    protected static void readAsHex(ZipFile zipFile, ZipEntry entry, Writer out, long limit, int groupsOf8BytesPerLine, IProgressMonitor monitor) throws IOException {
        SubMonitor progress = createProgressMonitor(entry, limit, monitor);

        boolean limitReached = false;
        long offsetInFile = 0;
        int bytesPerLine = groupsOf8BytesPerLine * 8;
        int asciiPosition = 0;
        char[] asciiBuffer = new char[bytesPerLine + (2 * (groupsOf8BytesPerLine - 1))];
        int bytePosition = 0;
        byte[] buffer = new byte[1024];

        InputStream stream = zipFile.getInputStream(entry);
        try {
            long total = 0;

            while (true) {
                if (progress.isCanceled())
                    return;
                int bytesRead = stream.read(buffer, 0, 1024);
                if (bytesRead < 0)
                    break;

                for (int i = 0; i < bytesRead; i++) {
                    if (bytePosition == 0) {
                        String s = String.format("0x%04x ", offsetInFile);
                        out.write(s);
                        offsetInFile += bytesPerLine;
                    }

                    asciiBuffer[asciiPosition] = byteToChar(buffer[i]);
                    asciiPosition++;

                    out.write(pseudo[(buffer[i] & 0xf0) >>> 4]); // Convert to a string character
                    out.write(pseudo[(buffer[i] & 0x0f)]); // convert the nibble to a String Character
                    out.write(' ');
                    bytePosition++;

                    /* do a linebreak after the required number of bytes */
                    if (bytePosition >= bytesPerLine) {
                        out.write(' ');
                        out.write(asciiBuffer);
                        out.write('\n');
                        asciiPosition = 0;
                        bytePosition = 0;
                    }

                    /* put 2 extra spaces between bytes */
                    if ((bytePosition > 0) && (bytePosition % 8 == 0)) {
                        asciiBuffer[asciiPosition++] = ' ';
                        asciiBuffer[asciiPosition++] = ' ';
                        out.write(' ');
                    }
                }

                total += bytesRead;
                progress.worked(bytesRead);
                if (limit >= 0 && total >= limit) {
                    limitReached = true;
                    return;
                }
            }
View Full Code Here

        }
        return null;
    }

    public static void recurseCreate(IContainer container, IProgressMonitor monitor) throws CoreException {
        SubMonitor progress = SubMonitor.convert(monitor, 2);
        if (container == null || container.exists())
            return;

        recurseCreate(container.getParent(), progress.newChild(1, SubMonitor.SUPPRESS_NONE));

        if (container instanceof IFolder)
            ((IFolder) container).create(false, true, progress.newChild(1, SubMonitor.SUPPRESS_NONE));
        else
            throw new CoreException(new Status(IStatus.ERROR, BundleUtils.getBundleSymbolicName(FileUtils.class), 0, "Cannot create new projects or workspace roots automatically.", null));
    }
View Full Code Here

                throw new CoreException(new Status(IStatus.ERROR, NewBuilder.PLUGIN_ID, 0, "Error rebuilding bnd projects after creating workspace configuration.", e));
            }
            if (projects == null || projects.isEmpty())
                return Status.OK_STATUS;

            SubMonitor progress = SubMonitor.convert(monitor, projects.size());
            for (Project project : projects) {
                IJavaProject eclipseProject = Central.getJavaProject(project);
                eclipseProject.getProject().build(IncrementalProjectBuilder.FULL_BUILD, progress.newChild(1, SubMonitor.SUPPRESS_NONE));
            }
            return Status.OK_STATUS;
        }
View Full Code Here

            indirectResources = Collections.<ResourceDescriptor> emptySet();
        }
        final MultiStatus status = new MultiStatus(Plugin.PLUGIN_ID, 0, "Errors occurred while processing JPM4J dependencies.", null);
        IRunnableWithProgress runnable = new IRunnableWithProgress() {
            public void run(IProgressMonitor monitor) throws InvocationTargetException, InterruptedException {
                SubMonitor progress = SubMonitor.convert(monitor, result.size() + indirectResources.size());
                progress.setTaskName("Processing dependencies...");

                // Process all resources (including non-selected ones) into the repository
                for (ResourceDescriptor resource : result)
                    processResource(resource, status, progress.newChild(1));
                for (ResourceDescriptor resource : indirectResources)
                    processResource(resource, status, progress.newChild(1));
            }
        };

        try {
            getContainer().run(true, true, runnable);
View Full Code Here

    }

    @Override
    public IStatus runInWorkspace(IProgressMonitor monitor) {
        List<Project> projects;
        SubMonitor progress;
        try {
            projects = new ArrayList<Project>(Central.getWorkspace().getAllProjects());
            progress = SubMonitor.convert(monitor, projects.size());
        } catch (Exception e) {
            return Status.CANCEL_STATUS;
        }

        IWorkspaceRoot wsroot = ResourcesPlugin.getWorkspace().getRoot();
        while (!projects.isEmpty()) {
            Project project = projects.remove(0);
            IProject eclipseProject = WorkspaceUtils.findOpenProject(wsroot, project);
            if (eclipseProject != null && !eclipseProject.equals(addedProject)) {
                List<String> errors = new LinkedList<String>();
                try {
                    project.propertiesChanged();
                    BndContainerInitializer.resetClasspaths(project, eclipseProject, errors);
                    BndContainerInitializer.replaceClasspathProblemMarkers(eclipseProject, errors);
                } catch (CoreException e) {
                    logger.logStatus(e.getStatus());
                    return Status.CANCEL_STATUS;
                }
                progress.worked(1);
            }
            if (progress.isCanceled())
                return Status.CANCEL_STATUS;
        }
        return Status.OK_STATUS;
    }
View Full Code Here

                throw new CoreException(new Status(IStatus.ERROR, NewBuilder.PLUGIN_ID, 0, "Error rebuilding bnd projects after creating workspace configuration.", e));
            }
            if (projects == null || projects.isEmpty())
                return Status.OK_STATUS;

            SubMonitor progress = SubMonitor.convert(monitor, projects.size());
            for (Project project : projects) {
                IJavaProject eclipseProject = Central.getJavaProject(project);
                eclipseProject.getProject().build(IncrementalProjectBuilder.FULL_BUILD, progress.newChild(1, SubMonitor.SUPPRESS_NONE));
            }
            return Status.OK_STATUS;
        }
View Full Code Here

public class ResourceCopier {
    public static IFile copy(URL url, IFile dst, Map<String,String> replaceRegularExpressions, IProgressMonitor monitor) throws IOException, CoreException {
        InputStream is = null;
        try {
            SubMonitor progress = SubMonitor.convert(monitor, 2);

            if (url.getPath().endsWith("/")) {
                File file = dst.getProjectRelativePath().toFile();

                if (file.isDirectory())
                    return dst; // already done

                if (file.isFile())
                    throw new IllegalArgumentException("Expected no file or a directory, but was a file: " + file);

                file.mkdirs();
                return dst; // already done
            }

            ResourceReplacer replacer = null;
            if ((replaceRegularExpressions == null) || replaceRegularExpressions.isEmpty()) {
                is = url.openStream();
            } else {
                replacer = new ResourceReplacer(replaceRegularExpressions, url);
                replacer.start();
                is = replacer.getStream();
            }

            if (dst.exists()) {
                dst.setContents(is, false, true, progress.newChild(2, SubMonitor.SUPPRESS_NONE));
            } else {
                FileUtils.recurseCreate(dst.getParent(), progress.newChild(1, SubMonitor.SUPPRESS_NONE));
                dst.create(is, false, progress.newChild(1, SubMonitor.SUPPRESS_NONE));
            }

            if (replacer != null) {
                try {
                    replacer.join();
View Full Code Here

    private static final String pseudo[] = {
            "0", "1", "2", "3", "4", "5", "6", "7", "8", "9", "a", "b", "c", "d", "e", "f"
    };

    private static SubMonitor createProgressMonitor(ZipEntry entry, long limit, IProgressMonitor monitor) {
        SubMonitor progress;
        long size = entry.getSize();
        if (size == -1) {
            progress = SubMonitor.convert(monitor);
        } else {
            long ticks = (limit == -1) ? size : Math.min(size, limit);
View Full Code Here

TOP

Related Classes of org.eclipse.core.runtime.SubMonitor

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.