Search in sources :

Example 1 with BuildProjectJob

use of net.sf.eclipsecs.core.jobs.BuildProjectJob in project eclipse-cs by checkstyle.

the class CheckstyleBuilder method buildProject.

/**
 * Runs the Checkstyle builder on a project.
 *
 * @param project
 *          Project to be built.
 */
public static void buildProject(final IProject project) {
    // uses the new Jobs API to run the build in the background
    BuildProjectJob buildJob = new BuildProjectJob(project, IncrementalProjectBuilder.FULL_BUILD);
    buildJob.setRule(ResourcesPlugin.getWorkspace().getRoot());
    buildJob.schedule();
}
Also used : BuildProjectJob(net.sf.eclipsecs.core.jobs.BuildProjectJob)

Example 2 with BuildProjectJob

use of net.sf.eclipsecs.core.jobs.BuildProjectJob in project eclipse-cs by checkstyle.

the class CheckstyleBuilder method buildProjects.

/**
 * Builds all checkstyle enabled projects that are open from the given collection of projects.
 *
 * @param projects
 *          the projects to build
 * @throws CheckstylePluginException
 *           Error during the build
 */
public static void buildProjects(final Collection<IProject> projects) throws CheckstylePluginException {
    // Build only open projects with Checkstyle enabled
    List<IProject> checkstyleProjects = new ArrayList<>();
    for (IProject project : projects) {
        try {
            if (project.exists() && project.isOpen() && project.hasNature(CheckstyleNature.NATURE_ID)) {
                checkstyleProjects.add(project);
            }
        } catch (CoreException e) {
            CheckstylePluginException.rethrow(e);
        }
    }
    // uses the new Jobs API to run the build in the background
    BuildProjectJob buildJob = new BuildProjectJob(checkstyleProjects.toArray(new IProject[checkstyleProjects.size()]), IncrementalProjectBuilder.FULL_BUILD);
    buildJob.setRule(ResourcesPlugin.getWorkspace().getRoot());
    buildJob.schedule();
}
Also used : CoreException(org.eclipse.core.runtime.CoreException) ArrayList(java.util.ArrayList) BuildProjectJob(net.sf.eclipsecs.core.jobs.BuildProjectJob) IProject(org.eclipse.core.resources.IProject)

Example 3 with BuildProjectJob

use of net.sf.eclipsecs.core.jobs.BuildProjectJob in project eclipse-cs by checkstyle.

the class CheckstylePropertyPage method performOk.

@Override
public boolean performOk() {
    try {
        IProject project = mProjectConfig.getProject();
        // save the edited project configuration
        if (mProjectConfig.isDirty()) {
            mProjectConfig.store();
        }
        boolean checkstyleEnabled = mChkEnable.getSelection();
        boolean needRebuild = mProjectConfig.isRebuildNeeded();
        // check if checkstyle nature has to be configured/deconfigured
        if (checkstyleEnabled != mCheckstyleInitiallyActivated) {
            ConfigureDeconfigureNatureJob configOperation = new ConfigureDeconfigureNatureJob(project, CheckstyleNature.NATURE_ID);
            configOperation.setRule(ResourcesPlugin.getWorkspace().getRoot());
            configOperation.schedule();
            needRebuild = needRebuild || !mCheckstyleInitiallyActivated;
        }
        if (checkstyleEnabled && mProjectConfig.isSyncFormatter()) {
            TransformCheckstyleRulesJob transFormJob = new TransformCheckstyleRulesJob(project);
            transFormJob.schedule();
        }
        // really be done.
        if (checkstyleEnabled && needRebuild) {
            String promptRebuildPref = CheckstyleUIPluginPrefs.getString(CheckstyleUIPluginPrefs.PREF_ASK_BEFORE_REBUILD);
            boolean doRebuild = MessageDialogWithToggle.ALWAYS.equals(promptRebuildPref) && needRebuild;
            // 
            if (MessageDialogWithToggle.PROMPT.equals(promptRebuildPref) && needRebuild) {
                MessageDialogWithToggle dialog = MessageDialogWithToggle.openYesNoQuestion(getShell(), Messages.CheckstylePropertyPage_titleRebuild, Messages.CheckstylePropertyPage_msgRebuild, Messages.CheckstylePropertyPage_nagRebuild, false, CheckstyleUIPlugin.getDefault().getPreferenceStore(), CheckstyleUIPluginPrefs.PREF_ASK_BEFORE_REBUILD);
                doRebuild = dialog.getReturnCode() == IDialogConstants.YES_ID;
            }
            // check if a rebuild is necessary
            if (checkstyleEnabled && doRebuild) {
                BuildProjectJob rebuildOperation = new BuildProjectJob(project, IncrementalProjectBuilder.FULL_BUILD);
                rebuildOperation.setRule(ResourcesPlugin.getWorkspace().getRoot());
                rebuildOperation.schedule();
            }
        }
    } catch (CheckstylePluginException e) {
        CheckstyleUIPlugin.errorDialog(getShell(), e, true);
    }
    return true;
}
Also used : TransformCheckstyleRulesJob(net.sf.eclipsecs.core.jobs.TransformCheckstyleRulesJob) ConfigureDeconfigureNatureJob(net.sf.eclipsecs.core.jobs.ConfigureDeconfigureNatureJob) MessageDialogWithToggle(org.eclipse.jface.dialogs.MessageDialogWithToggle) CheckstylePluginException(net.sf.eclipsecs.core.util.CheckstylePluginException) BuildProjectJob(net.sf.eclipsecs.core.jobs.BuildProjectJob) IProject(org.eclipse.core.resources.IProject)

Aggregations

BuildProjectJob (net.sf.eclipsecs.core.jobs.BuildProjectJob)3 IProject (org.eclipse.core.resources.IProject)2 ArrayList (java.util.ArrayList)1 ConfigureDeconfigureNatureJob (net.sf.eclipsecs.core.jobs.ConfigureDeconfigureNatureJob)1 TransformCheckstyleRulesJob (net.sf.eclipsecs.core.jobs.TransformCheckstyleRulesJob)1 CheckstylePluginException (net.sf.eclipsecs.core.util.CheckstylePluginException)1 CoreException (org.eclipse.core.runtime.CoreException)1 MessageDialogWithToggle (org.eclipse.jface.dialogs.MessageDialogWithToggle)1