Search in sources :

Example 1 with CompileErrorAction

use of bndtools.preferences.CompileErrorAction in project bndtools by bndtools.

the class BndtoolsBuilder method build.

/**
     * Called from Eclipse when it thinks this project should be build. We're proposed to figure out if we've changed
     * and then build as quickly as possible.
     * <p>
     * We ensure we're called in proper order defined by bnd, if not we will make it be called in proper order.
     *
     * @param kind
     * @param args
     * @param monitor
     * @return List of projects we depend on
     */
@Override
protected IProject[] build(final int kind, Map<String, String> args, final IProgressMonitor monitor) throws CoreException {
    BndPreferences prefs = new BndPreferences();
    buildLog = new BuildLogger(prefs.getBuildLogging());
    final BuildListeners listeners = new BuildListeners();
    final IProject myProject = getProject();
    try {
        listeners.fireBuildStarting(myProject);
        final MarkerSupport markers = new MarkerSupport(myProject);
        if (dependsOn == null) {
            dependsOn = myProject.getDescription().getDynamicReferences();
        }
        if (model == null) {
            try {
                model = Central.getProject(myProject);
            } catch (Exception e) {
                markers.deleteMarkers("*");
            }
            if (model == null)
                return noreport();
        }
        try {
            return Central.bndCall(new Callable<IProject[]>() {

                @Override
                public IProject[] call() throws Exception {
                    boolean force = kind == FULL_BUILD || kind == CLEAN_BUILD;
                    model.clear();
                    DeltaWrapper delta = new DeltaWrapper(model, getDelta(myProject), buildLog);
                    boolean setupChanged = false;
                    if (!postponed && (delta.havePropertiesChanged(model) || delta.hasChangedSubbundles())) {
                        buildLog.basic("project was dirty from changed bnd files postponed = " + postponed);
                        model.forceRefresh();
                        setupChanged = true;
                    }
                    if (dirty.remove(model)) {
                        buildLog.basic("project was dirty from a workspace refresh postponed = " + postponed);
                        setupChanged = true && !postponed;
                    }
                    if (!force && !setupChanged && delta.hasEclipseChanged()) {
                        buildLog.basic("Eclipse project had a buildpath change");
                        setupChanged = true;
                    }
                    if (!force && !setupChanged && suggestClasspathContainerUpdate()) {
                        buildLog.basic("Project classpath may need to be updated");
                        setupChanged = true;
                    }
                    if (force || setupChanged) {
                        model.setChanged();
                        model.setDelayRunDependencies(true);
                        model.prepare();
                        markers.validate(model);
                        markers.setMarkers(model, BndtoolsConstants.MARKER_BND_PATH_PROBLEM);
                        model.clear();
                        dependsOn = calculateDependsOn(model);
                        //
                        // We have a setup change so we MUST check both class path
                        // changes and build order changes. Careful not to use an OR
                        // operation (as I did) because they are shortcutted. Since it
                        // is also nice to see why we had a change, we just collect the
                        // reason of the change so we can report it to the log.
                        //
                        // if empty, no change
                        String changed = "";
                        String del = "";
                        if (requestClasspathContainerUpdate()) {
                            changed += "Classpath container updated";
                            del = " & ";
                        }
                        if (setBuildOrder(monitor)) {
                            changed += del + "Build order changed";
                        }
                        if (!changed.equals("")) {
                            buildLog.basic("Setup changed: " + changed);
                            return postpone();
                        }
                        force = true;
                    }
                    //
                    if (postponed)
                        buildLog.full("Was postponed");
                    force |= postponed;
                    postponed = false;
                    if (!force && delta.hasProjectChanged()) {
                        buildLog.basic("project had changed files");
                        force = true;
                    }
                    if (!force && hasUpstreamChanges()) {
                        buildLog.basic("project had upstream changes");
                        force = true;
                    }
                    if (!force && delta.hasNoTarget(model)) {
                        buildLog.basic("project has no target files");
                        force = true;
                    }
                    if (!force) {
                        buildLog.full("Auto/Incr. build, no changes detected");
                        return noreport();
                    }
                    WorkingSetTracker.doWorkingSets(model, myProject);
                    if (model.isNoBundles()) {
                        buildLog.basic("-nobundles was set, so no build");
                        buildLog.setFiles(0);
                        return report(markers);
                    }
                    if (markers.hasBlockingErrors(delta)) {
                        CompileErrorAction actionOnCompileError = getActionOnCompileError();
                        if (actionOnCompileError != CompileErrorAction.build) {
                            if (actionOnCompileError == CompileErrorAction.delete) {
                                buildLog.basic("Blocking errors, delete build files, quit");
                                deleteBuildFiles(model);
                                model.error("Will not build project %s until the compilation and/or path problems are fixed, output files are deleted.", myProject.getName());
                            } else {
                                buildLog.basic("Blocking errors, leave old build files, quit");
                                model.error("Will not build project %s until the compilation and/or path problems are fixed, output files are kept.", myProject.getName());
                            }
                            return report(markers);
                        }
                        buildLog.basic("Blocking errors, continuing anyway");
                        model.warning("Project %s has blocking errors but requested to continue anyway", myProject.getName());
                    }
                    Central.invalidateIndex();
                    File[] buildFiles = model.build();
                    if (buildFiles != null) {
                        listeners.updateListeners(buildFiles, myProject);
                        buildLog.setFiles(buildFiles.length);
                    }
                    // We can now decorate based on the build we just did.
                    PackageDecorator.updateDecoration(myProject, model);
                    ComponentMarker.updateComponentMarkers(myProject, model);
                    if (model.isCnf()) {
                        // this is for bnd plugins built in cnf
                        model.getWorkspace().refresh();
                    }
                    return report(markers);
                }
            }, monitor);
        } catch (TimeoutException | InterruptedException e) {
            logger.logWarning("Unable to build project " + myProject.getName(), e);
            return postpone();
        }
    } catch (Exception e) {
        throw new CoreException(new Status(IStatus.ERROR, PLUGIN_ID, 0, "Build Error!", e));
    } finally {
        if (buildLog.isActive())
            logger.logInfo(buildLog.toString(myProject.getName()), null);
        listeners.release(myProject);
    }
}
Also used : IStatus(org.eclipse.core.runtime.IStatus) Status(org.eclipse.core.runtime.Status) BndPreferences(bndtools.preferences.BndPreferences) IProject(org.eclipse.core.resources.IProject) TimeoutException(java.util.concurrent.TimeoutException) CoreException(org.eclipse.core.runtime.CoreException) CoreException(org.eclipse.core.runtime.CoreException) CompileErrorAction(bndtools.preferences.CompileErrorAction) TimeoutException(java.util.concurrent.TimeoutException)

Aggregations

BndPreferences (bndtools.preferences.BndPreferences)1 CompileErrorAction (bndtools.preferences.CompileErrorAction)1 TimeoutException (java.util.concurrent.TimeoutException)1 IProject (org.eclipse.core.resources.IProject)1 CoreException (org.eclipse.core.runtime.CoreException)1 IStatus (org.eclipse.core.runtime.IStatus)1 Status (org.eclipse.core.runtime.Status)1