Search in sources :

Example 1 with SubMonitor

use of org.eclipse.core.runtime.SubMonitor in project AutoRefactor by JnRouvignac.

the class SuperCallRatherThanUselessOverridingRefactoring method isMethodUsedInItsPackage.

/** This method is extremely expensive. */
@OnEclipseVersionUpgrade("Replace monitor.newChild(1) by monitor.split(1)")
private boolean isMethodUsedInItsPackage(IMethodBinding methodBinding, MethodDeclaration node) {
    final IPackageBinding methodPackage = methodBinding.getDeclaringClass().getPackage();
    final AtomicBoolean methodIsUsedInPackage = new AtomicBoolean(false);
    final SearchRequestor requestor = new SearchRequestor() {

        @Override
        public void acceptSearchMatch(SearchMatch match) {
            methodIsUsedInPackage.set(true);
        }
    };
    final SubMonitor subMonitor = SubMonitor.convert(ctx.getProgressMonitor(), 1);
    final SubMonitor childMonitor = subMonitor.newChild(1);
    try {
        final SearchEngine searchEngine = new SearchEngine();
        searchEngine.search(createPattern(methodBinding.getJavaElement(), REFERENCES, R_EXACT_MATCH), new SearchParticipant[] { SearchEngine.getDefaultSearchParticipant() }, SearchEngine.createJavaSearchScope(new IJavaElement[] { methodPackage.getJavaElement() }), requestor, childMonitor);
        return methodIsUsedInPackage.get();
    } catch (CoreException e) {
        throw new UnhandledException(node, e);
    } finally {
        childMonitor.done();
    }
}
Also used : SearchRequestor(org.eclipse.jdt.core.search.SearchRequestor) UnhandledException(org.autorefactor.util.UnhandledException) AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) IJavaElement(org.eclipse.jdt.core.IJavaElement) SearchMatch(org.eclipse.jdt.core.search.SearchMatch) SearchEngine(org.eclipse.jdt.core.search.SearchEngine) CoreException(org.eclipse.core.runtime.CoreException) SubMonitor(org.eclipse.core.runtime.SubMonitor) IPackageBinding(org.eclipse.jdt.core.dom.IPackageBinding) OnEclipseVersionUpgrade(org.autorefactor.util.OnEclipseVersionUpgrade)

Example 2 with SubMonitor

use of org.eclipse.core.runtime.SubMonitor in project tesb-studio-se by Talend.

the class StartRuntimeProgress method run.

@Override
public void run(IProgressMonitor parentMonitor) throws InvocationTargetException, InterruptedException {
    SubMonitor subMonitor = SubMonitor.convert(parentMonitor, 10);
    //$NON-NLS-1$
    subMonitor.setTaskName(RunContainerMessages.getString("StartRuntimeAction.Starting"));
    if (!checkRunning()) {
        try {
            IPreferenceStore store = ESBRunContainerPlugin.getDefault().getPreferenceStore();
            Process proc = RuntimeServerController.getInstance().startLocalRuntimeServer(store.getString(RunContainerPreferenceInitializer.P_ESB_RUNTIME_LOCATION));
            int i = 0;
            //$NON-NLS-1$
            String dot = ".";
            while (JMXUtil.createJMXconnection() == null && ++i < 11 && !subMonitor.isCanceled() && proc.isAlive()) {
                //$NON-NLS-1$
                subMonitor.subTask(RunContainerMessages.getString("StartRuntimeAction.Try") + dot);
                //$NON-NLS-1$
                dot += ".";
                subMonitor.worked(1);
                Thread.sleep(3000);
            }
            if (!proc.isAlive()) {
                RuntimeServerController.getInstance().stopLocalRuntimeServer();
                throw new InterruptedException(RunContainerMessages.getString("RunContainerPreferencePage.InitailzeDialog8", proc.exitValue()));
            }
            if (JMXUtil.createJMXconnection() == null) {
                throw new InterruptedException(RunContainerMessages.getString("RunContainerPreferencePage.InitailzeDialog5"));
            }
        } catch (Exception e) {
            ExceptionHandler.process(e);
            throw new InvocationTargetException(e, e.getMessage());
        }
    }
    loadConsole();
}
Also used : SubMonitor(org.eclipse.core.runtime.SubMonitor) IPreferenceStore(org.eclipse.jface.preference.IPreferenceStore) InvocationTargetException(java.lang.reflect.InvocationTargetException) InvocationTargetException(java.lang.reflect.InvocationTargetException)

Example 3 with SubMonitor

use of org.eclipse.core.runtime.SubMonitor in project tesb-studio-se by Talend.

the class StopRuntimeProgress method run.

@Override
public void run(IProgressMonitor parentMonitor) throws InvocationTargetException, InterruptedException {
    SubMonitor subMonitor = SubMonitor.convert(parentMonitor, 10);
    //$NON-NLS-1$
    subMonitor.setTaskName(RunContainerMessages.getString("HaltRuntimeAction.Stoping"));
    if (checkRunning()) {
        if (RuntimeServerController.getInstance().isRunning()) {
            try {
                RuntimeServerController.getInstance().stopRuntimeServer();
                int i = 0;
                //$NON-NLS-1$
                String dot = ".";
                // JMXUtil.connectToRuntime() != null
                while (RuntimeServerController.getInstance().isRunning() && i < 11 && !subMonitor.isCanceled()) {
                    //$NON-NLS-1$
                    subMonitor.setTaskName(RunContainerMessages.getString("HaltRuntimeAction.Task") + dot);
                    //$NON-NLS-1$
                    dot += ".";
                    subMonitor.worked(1);
                    Thread.sleep(3000);
                }
                if (RuntimeServerController.getInstance().isRunning()) {
                    throw new InterruptedException("Stop runtime server failed, please try again or stop it manually.");
                }
            } catch (Exception e) {
                ExceptionHandler.process(e);
                e.printStackTrace();
                throw new InvocationTargetException(e);
            }
        }
    }
}
Also used : SubMonitor(org.eclipse.core.runtime.SubMonitor) InvocationTargetException(java.lang.reflect.InvocationTargetException) InvocationTargetException(java.lang.reflect.InvocationTargetException)

Example 4 with SubMonitor

use of org.eclipse.core.runtime.SubMonitor in project tesb-studio-se by Talend.

the class RuntimeClientProgress method run.

@Override
public void run(IProgressMonitor parentMonitor) throws InvocationTargetException, InterruptedException {
    System.out.println("Running command " + command);
    SubMonitor subMonitor = SubMonitor.convert(parentMonitor, 10);
    //$NON-NLS-1$
    subMonitor.setTaskName("Running script (" + command + ")");
    if (checkRunning()) {
        subMonitor.subTask("Checking runtime bundles...");
        waitForActive(subMonitor);
        subMonitor.worked(2);
        IPreferenceStore store = ESBRunContainerPlugin.getDefault().getPreferenceStore();
        File containerDir = new File(store.getString(RunContainerPreferenceInitializer.P_ESB_RUNTIME_LOCATION));
        try {
            subMonitor.subTask("Script is running to end...");
            executeScript(containerDir);
            subMonitor.worked(8);
            int size = log.size();
            if (!log.get(size - 1).equals("EOF")) {
                System.out.println("initlocal.sh logs: " + getLog());
                StackTraceElement[] stackTrace = new StackTraceElement[size];
                for (int i = 0; i < size; i++) {
                    stackTrace[i] = new StackTraceElement("RuntimeClientProgress", log.get(i), "Unknown source", i);
                }
                InterruptedException e = new InterruptedException("Script initlocal.sh run failed");
                e.setStackTrace(stackTrace);
                throw e;
            }
        } catch (IOException e) {
            throw new InvocationTargetException(e);
        }
    }
}
Also used : SubMonitor(org.eclipse.core.runtime.SubMonitor) IOException(java.io.IOException) IPreferenceStore(org.eclipse.jface.preference.IPreferenceStore) File(java.io.File) InvocationTargetException(java.lang.reflect.InvocationTargetException)

Example 5 with SubMonitor

use of org.eclipse.core.runtime.SubMonitor in project sling by apache.

the class JVMDebuggerConnection method connectInDebugMode.

boolean connectInDebugMode(ILaunch launch, IServer iServer, IProgressMonitor monitor) throws CoreException {
    long start = System.currentTimeMillis();
    this.launch = launch;
    boolean success = false;
    IVMConnector connector = null;
    connector = JavaRuntime.getVMConnector(IJavaLaunchConfigurationConstants.ID_SOCKET_ATTACH_VM_CONNECTOR);
    if (connector == null) {
        connector = JavaRuntime.getDefaultVMConnector();
    }
    if (connector == null) {
        throw new CoreException(new Status(IStatus.ERROR, "org.apache.sling.ide.eclipse.wst", "Could not get jvm connctor"));
    }
    ISlingLaunchpadServer launchpadServer = (ISlingLaunchpadServer) iServer.loadAdapter(SlingLaunchpadServer.class, monitor);
    ISlingLaunchpadConfiguration configuration = launchpadServer.getConfiguration();
    int debugPort = configuration.getDebugPort();
    if (debugPort <= 0) {
        throw new CoreException(new Status(IStatus.ERROR, "org.apache.sling.ide.eclipse.wst", "debug port not configured"));
    }
    Map<String, String> connectMap = new HashMap<>();
    connectMap.put("hostname", iServer.getHost());
    connectMap.put("port", String.valueOf(debugPort));
    //			Map argMap = null;//configuration.getAttribute(IJavaLaunchConfigurationConstants.ATTR_CONNECT_MAP, (Map)null);
    int connectTimeout = JavaRuntime.getPreferences().getInt(JavaRuntime.PREF_CONNECT_TIMEOUT);
    //$NON-NLS-1$
    connectMap.put("timeout", Integer.toString(connectTimeout));
    // set the default source locator if required
    @SuppressWarnings("restriction") ISourceLookupDirector sourceLocator = new JavaSourceLookupDirector();
    sourceLocator.setSourcePathComputer(DebugPlugin.getDefault().getLaunchManager().getSourcePathComputer(//$NON-NLS-1$
    "org.eclipse.jdt.launching.sourceLookup.javaSourcePathComputer"));
    List<IRuntimeClasspathEntry> classpathEntries = new ArrayList<>();
    // 1. add java projects first
    for (IJavaProject javaProject : ProjectHelper.getAllJavaProjects()) {
        classpathEntries.add(JavaRuntime.newProjectRuntimeClasspathEntry(javaProject));
    }
    // 2. add the other modules deployed on server
    // 5/30
    ProgressUtils.advance(monitor, 5);
    // 30 - 5 - 1
    int workTicksForReferences = 24;
    SourceReferenceResolver resolver = Activator.getDefault().getSourceReferenceResolver();
    if (resolver != null && configuration.resolveSourcesInDebugMode()) {
        try {
            List<SourceReference> references = osgiClient.findSourceReferences();
            SubMonitor subMonitor = SubMonitor.convert(monitor, "Resolving source references", workTicksForReferences).setWorkRemaining(references.size());
            for (SourceReference reference : references) {
                try {
                    subMonitor.setTaskName("Resolving source reference: " + reference);
                    IRuntimeClasspathEntry classpathEntry = resolver.resolve(reference);
                    if (classpathEntry != null) {
                        classpathEntries.add(classpathEntry);
                    }
                    ProgressUtils.advance(subMonitor, 1);
                } catch (CoreException e) {
                    // don't fail the debug launch for artifact resolution errors
                    Activator.getDefault().getPluginLogger().warn("Failed resolving source reference", e);
                }
            }
            // 29/30
            subMonitor.done();
        } catch (OsgiClientException e1) {
            throw new CoreException(new Status(Status.ERROR, Activator.PLUGIN_ID, e1.getMessage(), e1));
        }
    } else {
        monitor.worked(workTicksForReferences);
    }
    // 3. add the JRE entry
    classpathEntries.add(JavaRuntime.computeJREEntry(launch.getLaunchConfiguration()));
    IRuntimeClasspathEntry[] resolved = JavaRuntime.resolveSourceLookupPath(classpathEntries.toArray(new IRuntimeClasspathEntry[0]), launch.getLaunchConfiguration());
    sourceLocator.setSourceContainers(JavaRuntime.getSourceContainers(resolved));
    sourceLocator.initializeParticipants();
    launch.setSourceLocator(sourceLocator);
    // connect to remote VM
    try {
        // 30/30
        connector.connect(connectMap, monitor, launch);
        success = true;
        long elapsedMillis = System.currentTimeMillis() - start;
        Activator.getDefault().getPluginLogger().tracePerformance("Debug connection to {0}", elapsedMillis, iServer.getName());
    } catch (Exception e) {
        throw new CoreException(new Status(IStatus.ERROR, "org.apache.sling.ide.eclipse.wst", "could not establish debug connection to " + iServer.getHost() + " : " + debugPort, e));
    }
    return success;
}
Also used : HashMap(java.util.HashMap) JavaSourceLookupDirector(org.eclipse.jdt.internal.launching.JavaSourceLookupDirector) ISourceLookupDirector(org.eclipse.debug.core.sourcelookup.ISourceLookupDirector) ArrayList(java.util.ArrayList) SourceReferenceResolver(org.apache.sling.ide.eclipse.core.launch.SourceReferenceResolver) IVMConnector(org.eclipse.jdt.launching.IVMConnector) SourceReference(org.apache.sling.ide.osgi.SourceReference) OsgiClientException(org.apache.sling.ide.osgi.OsgiClientException) ISlingLaunchpadServer(org.apache.sling.ide.eclipse.core.ISlingLaunchpadServer) IStatus(org.eclipse.core.runtime.IStatus) Status(org.eclipse.core.runtime.Status) SubMonitor(org.eclipse.core.runtime.SubMonitor) IRuntimeClasspathEntry(org.eclipse.jdt.launching.IRuntimeClasspathEntry) CoreException(org.eclipse.core.runtime.CoreException) DebugException(org.eclipse.debug.core.DebugException) OsgiClientException(org.apache.sling.ide.osgi.OsgiClientException) IJavaProject(org.eclipse.jdt.core.IJavaProject) CoreException(org.eclipse.core.runtime.CoreException) ISlingLaunchpadConfiguration(org.apache.sling.ide.eclipse.core.ISlingLaunchpadConfiguration) ISlingLaunchpadServer(org.apache.sling.ide.eclipse.core.ISlingLaunchpadServer)

Aggregations

SubMonitor (org.eclipse.core.runtime.SubMonitor)35 IStatus (org.eclipse.core.runtime.IStatus)14 CoreException (org.eclipse.core.runtime.CoreException)13 Status (org.eclipse.core.runtime.Status)13 IOException (java.io.IOException)8 InvocationTargetException (java.lang.reflect.InvocationTargetException)8 IProgressMonitor (org.eclipse.core.runtime.IProgressMonitor)8 InputStream (java.io.InputStream)7 IFile (org.eclipse.core.resources.IFile)7 File (java.io.File)5 IProject (org.eclipse.core.resources.IProject)4 MultiStatus (org.eclipse.core.runtime.MultiStatus)4 ByteArrayInputStream (java.io.ByteArrayInputStream)3 ArrayList (java.util.ArrayList)3 IContainer (org.eclipse.core.resources.IContainer)3 OperationCanceledException (org.eclipse.core.runtime.OperationCanceledException)3 IRunnableWithProgress (org.eclipse.jface.operation.IRunnableWithProgress)3 ResourceDescriptor (aQute.bnd.service.repository.SearchableRepository.ResourceDescriptor)2 UnsupportedEncodingException (java.io.UnsupportedEncodingException)2 SQLException (java.sql.SQLException)2