My eclipse plugin creates endless workspace build loops, possibly work related

I created a plug-in to hook into the save action and create a miniature javascript file for the editable javascript file. You can see the full code in this question: the eclipse plugin does not work after upgrading to juno (eclipse 4)

The problem is that with Juno, this plugin creates endless loops in the process of building a workspace. First, it starts to reduce the file, which I did not change at all. This file creates an endless loop in the assembly. When he finished the file thumbnail, he will start a new build of the workspace and close the file again and so on. But after a while it gets worse, especially at the new eclipse. Suddenly there are a dozen files that it reduces, I never touched. If I remove my plugin, let eclipse build the workspace, reconnect its plug-in again. But after some time it all begins.

I think this is due to the way I process the task to create the file, as shown below. Maybe something has changed here with Juno? But I can not find any information about this.

Job compileJob = new Job("Compile .min.js") { public IStatus run(IProgressMonitor monitor) { public IStatus run(IProgressMonitor monitor) { byte[] bytes = null; try { bytes = CallCompiler.compile(fullLocation.toString(), CallCompiler.SIMPLE_OPTIMIZATION).getBytes(); InputStream source = new ByteArrayInputStream(bytes); if (!newFile.exists()) { newFile.create(source, IResource.NONE, null); } else { newFile.setContents(source, IResource.NONE, null); } } catch (IOException e) { e.printStackTrace(); } catch (CoreException e) { e.printStackTrace(); } return Status.OK_STATUS; } }; compileJob.setRule(newFile.getProject()); compileJob.schedule(); 
+4
source share
1 answer

You need to set newFile to derivative. The output file is the one that is created implicitly in the workspace during assembly and should be erased during cleaning (since it can be restored during the next build).

You can call the setDerived method on IResource :

 org.eclipse.core.resources.IResource.setDerived(boolean, IProgressMonitor) 

or when you create a file, it can be created as output, although the call looks like this:

newFile.create (stream, IResource.DERIVED, monitor);

But you cannot set the DERIVED flag through setContents, you must explicitly call setDerived(true) in this case.

From the docs:

A received resource is a regular file or folder that is created during the translation, compilation, copying or processing of other files. Derived resources are not source data and can be recreated from other resources. It is generally accepted to exclude derivative resources from version control and configuration because they otherwise clutter up the command repository with a version of these ever-changing files, as each user regenerates them.

+2
source

All Articles