package org.erlide.builder; import com.google.common.base.Objects; import com.google.common.eventbus.DeadEvent; import com.google.common.eventbus.EventBus; import com.google.common.eventbus.Subscribe; import com.google.inject.Injector; import com.google.inject.name.Named; import java.util.ArrayList; import java.util.Map; import java.util.function.Consumer; import javax.inject.Inject; import org.eclipse.core.resources.IProject; import org.eclipse.core.resources.IResource; import org.eclipse.core.resources.IResourceDelta; import org.eclipse.core.resources.IncrementalProjectBuilder; import org.eclipse.core.runtime.CoreException; import org.eclipse.core.runtime.IProgressMonitor; import org.eclipse.core.runtime.NullProgressMonitor; import org.eclipse.core.runtime.OperationCanceledException; import org.eclipse.core.runtime.SubMonitor; import org.eclipse.xtext.xbase.lib.CollectionLiterals; import org.eclipse.xtext.xbase.lib.Exceptions; import org.eclipse.xtext.xbase.lib.InputOutput; import org.erlide.builder.BuilderPlugin; import org.erlide.builder.BuildersProvider; import org.erlide.builder.IErlangBuilder; import org.erlide.builder.SgsnBuilder; import org.erlide.builder.markers.BuilderMarkerUpdater; import org.erlide.builder.markers.RemoveMarkersEvent; import org.erlide.common.NatureConstants; import org.erlide.common.util.ErlLogger; @SuppressWarnings("all") public class ErlangBuilder extends IncrementalProjectBuilder { public static String BUILDER_ID = "org.erlide.builder.erlangBuilder"; public static String OLD_BUILDER_ID = "org.erlide.core.erlbuilder"; public static String MARKER_TYPE = "org.erlide.builder.erlangBuildProblem"; @Inject private BuilderMarkerUpdater markerUpdater; @Inject private BuildersProvider builderProvider; @Inject private ErlLogger log; @Inject @Named("erlangBuilder") private EventBus builderEventBus; public ErlangBuilder() { BuilderPlugin _instance = BuilderPlugin.getInstance(); Injector _injector = _instance.getInjector(); _injector.injectMembers(this); this.builderEventBus.register(this); } public ErlangBuilder(final BuilderMarkerUpdater markerUpdater, final BuildersProvider builderProvider, final EventBus eventBus) { this.markerUpdater = markerUpdater; this.builderProvider = builderProvider; this.builderEventBus = eventBus; this.builderEventBus.register(this); } @Override protected IProject[] build(final int kind, final Map<String, String> args, final IProgressMonitor monitor) throws CoreException { final long startTime = System.currentTimeMillis(); IProject _project = this.getProject(); this.cleanXtextMarkers(_project); InputOutput.<IProgressMonitor>println(monitor); final SubMonitor progress = SubMonitor.convert(monitor, 100); try { IProject _project_1 = this.getProject(); final IErlangBuilder builder = this.getProjectBuilder(_project_1); boolean _equals = Objects.equal(builder, null); if (_equals) { IProject _project_2 = this.getProject(); String _plus = ("Project " + _project_2); String _plus_1 = (_plus + " has no Erlang builder"); this.log.warn(_plus_1); } else { switch (kind) { case IncrementalProjectBuilder.FULL_BUILD: SubMonitor _newChild = progress.newChild(100); builder.fullBuild(_newChild); break; default: IProject _project_3 = this.getProject(); IResourceDelta _delta = this.getDelta(_project_3); SubMonitor _newChild_1 = progress.newChild(100); builder.incrementalBuild(_delta, _newChild_1); break; } } } catch (final Throwable _t) { if (_t instanceof CoreException) { final CoreException e = (CoreException)_t; this.log.error(e); throw e; } else if (_t instanceof OperationCanceledException) { final OperationCanceledException e_1 = (OperationCanceledException)_t; this.forgetLastBuiltState(); throw e_1; } else if (_t instanceof Exception) { final Exception e_2 = (Exception)_t; this.log.error(e_2); } else { throw Exceptions.sneakyThrow(_t); } } finally { if (monitor!=null) { monitor.done(); } IProject _project_3 = this.getProject(); String _name = _project_3.getName(); String _plus_2 = ("Build " + _name); String _plus_3 = (_plus_2 + " in "); long _currentTimeMillis = System.currentTimeMillis(); long _minus = (_currentTimeMillis - startTime); String _plus_4 = (_plus_3 + Long.valueOf(_minus)); String _plus_5 = (_plus_4 + " ms"); this.log.info(_plus_5); } IProject _project_4 = this.getProject(); return _project_4.getReferencedProjects(); } @Override protected void clean(final IProgressMonitor monitor) throws CoreException { IProject _project = this.getProject(); this.cleanXtextMarkers(_project); IProject _project_1 = this.getProject(); final IErlangBuilder builder = this.getProjectBuilder(_project_1); try { boolean _equals = Objects.equal(builder, null); if (_equals) { IProject _project_2 = this.getProject(); String _plus = ("Project " + _project_2); String _plus_1 = (_plus + " has no Erlang builder"); this.log.warn(_plus_1); } else { NullProgressMonitor _nullProgressMonitor = new NullProgressMonitor(); builder.clean(_nullProgressMonitor); } IProject _project_3 = this.getProject(); RemoveMarkersEvent _removeMarkersEvent = new RemoveMarkersEvent(_project_3, ErlangBuilder.MARKER_TYPE); this.builderEventBus.post(_removeMarkersEvent); } finally { if (monitor!=null) { monitor.done(); } } } public IErlangBuilder getProjectBuilder(final IProject project) { IErlangBuilder _xblockexpression = null; { final String bId = SgsnBuilder.ID; final IErlangBuilder builder = this.builderProvider.get(bId); builder.setProject(project); builder.loadConfiguration(); _xblockexpression = builder; } return _xblockexpression; } private void cleanXtextMarkers(final IProject project) { try { boolean _hasNature = project.hasNature(NatureConstants.OLD_NATURE_ID); if (_hasNature) { ArrayList<String> _newArrayList = CollectionLiterals.<String>newArrayList("erlang.check.fast", "erlang.check.normal", "erlang.check.expensive"); final Consumer<String> _function = new Consumer<String>() { @Override public void accept(final String it) { try { project.deleteMarkers(("org.erlide.erlang.ui." + it), true, IResource.DEPTH_INFINITE); } catch (Throwable _e) { throw Exceptions.sneakyThrow(_e); } } }; _newArrayList.forEach(_function); } } catch (Throwable _e) { throw Exceptions.sneakyThrow(_e); } } @Subscribe public void noBuilderHandler(final DeadEvent dead) { IProject _project = this.getProject(); String _name = _project.getName(); this.log.warn("No builder configured for project %s", _name); Object _source = dead.getSource(); Object _event = dead.getEvent(); this.log.debug("From: %s Event %s", _source, _event); } }