Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Language IDEs » Java Development Tools (JDT) » Suspending auto-build
Suspending auto-build [message #1831391] Wed, 19 August 2020 01:49 Go to next message
Tony Lavinio is currently offline Tony LavinioFriend
Messages: 2
Registered: August 2020
Junior Member
I have a plugin that generates, or regenerates, a large amount of Java code based on complex configuration files. As it writes each file, Eclipse appears to start an auto-build, and this results in sometimes hundreds of incremental builds, which bogs everything down.
How can I save the state of auto-build, turn it off, write or overwrite the files, and then restart auto-build and have it rebuild the projects involved? Or am I thinking about this the wrong way?
Re: Suspending auto-build [message #1831394 is a reply to message #1831391] Wed, 19 August 2020 04:41 Go to previous messageGo to next message
Ed Willink is currently offline Ed WillinkFriend
Messages: 7655
Registered: July 2009
Senior Member
Hi

That would seem correct, but in recent years I have become convinced that there are many sections of the platform that do not respect the no-auto-build setting. In particular checking out a GIT commit affecting multi-projects can be bad. Comments on Bugzillas suggest that scheduling rules are more important.

There may be a different way. If the platform is unaware that the files have changed, no builds will happen, so even if you do successfully disable auto-build, you may change the files on disk by using File.write, rather than IFile.setContents and then when you are done do deep IResource refreshes in inverse dependency order.

Regards

Ed Willink

Re: Suspending auto-build [message #1831395 is a reply to message #1831391] Wed, 19 August 2020 04:49 Go to previous messageGo to next message
Ed Merks is currently offline Ed MerksFriend
Messages: 33142
Registered: July 2009
Senior Member
In this class:

https://git.eclipse.org/c/oomph/org.eclipse.oomph.git/tree/plugins/org.eclipse.oomph.setup.core/src/org/eclipse/oomph/setup/internal/core/SetupTaskPerformer.java

You'll find a nested class WorkspaceUtil that shows how to enable and disable auto build:
  private static class WorkspaceUtil
  {
    private static boolean disableAutoBuilding() throws CoreException
    {
      boolean autoBuilding = ResourcesPlugin.getWorkspace().isAutoBuilding();
      if (autoBuilding)
      {
        restoreAutoBuilding(false);
      }

      return autoBuilding;
    }

    private static void restoreAutoBuilding(boolean autoBuilding) throws CoreException
    {
      if (autoBuilding != ResourcesPlugin.getWorkspace().isAutoBuilding())
      {
        IWorkspaceDescription description = ResourcesPlugin.getWorkspace().getDescription();
        description.setAutoBuilding(autoBuilding);

        ResourcesPlugin.getWorkspace().setDescription(description);
      }
    }

    private static void performNeededSetupTasks(final SetupTaskPerformer performer, IProgressMonitor monitor) throws Exception
    {
      ResourcesPlugin.getWorkspace().run(new IWorkspaceRunnable()
      {
        public void run(IProgressMonitor monitor) throws CoreException
        {
          try
          {
            performer.doPerformNeededSetupTasks(monitor);
          }
          catch (Throwable t)
          {
            SetupCorePlugin.INSTANCE.coreException(t);
          }
        }
      }, null, IWorkspace.AVOID_UPDATE, monitor);
    }
  }
Note too though the performNeededSetupTasks where the operations that modify the workspace are done within an IWorkspaceRunnable which avoids producing a resource delta for each and every change to a resource in workspace but rather gathers them up for a single notification at the end of the operation. It may be the case that if you generate within such an operation that you won't need to disable and re-enable the auto build. I'd try that first because in EMF's generator we to generate a whole whack of Java files and even new project without needing to disable auto build.


Ed Merks
Professional Support: https://www.macromodeling.com/
Re: Suspending auto-build [message #1831430 is a reply to message #1831395] Wed, 19 August 2020 16:34 Go to previous message
Tony Lavinio is currently offline Tony LavinioFriend
Messages: 2
Registered: August 2020
Junior Member
The IWorkspaceRunnable solution was exactly what I was after. Thank you! This has tremendously improved the performance of our plugin.
Previous Topic:Raspbian Installation
Next Topic:Can't run java project with module warning
Goto Forum:
  


Current Time: Fri Apr 26 07:26:46 GMT 2024

Powered by FUDForum. Page generated in 0.02874 seconds
.:: Contact :: Home ::.

Powered by: FUDforum 3.0.2.
Copyright ©2001-2010 FUDforum Bulletin Board Software

Back to the top