Search in sources :

Example 1 with UnsetInputPropertiesException

use of name.herlin.command.UnsetInputPropertiesException in project pmd-eclipse-plugin by pmd.

the class DetectCutAndPasteCmdTest method testDetectCutAndPasteCmdNullArg1.

/**
 * Test robustness #1
 *
 * @throws CommandException
 */
@Test
public void testDetectCutAndPasteCmdNullArg1() throws CommandException {
    try {
        final DetectCutAndPasteCmd cmd = new DetectCutAndPasteCmd();
        cmd.setProject(null);
        cmd.setRenderer(new SimpleRenderer());
        cmd.setReportName(PMDRuntimeConstants.SIMPLE_CPDREPORT_NAME);
        cmd.performExecute();
        Assert.fail();
    } catch (final UnsetInputPropertiesException e) {
    // yes cool
    }
}
Also used : UnsetInputPropertiesException(name.herlin.command.UnsetInputPropertiesException) SimpleRenderer(net.sourceforge.pmd.cpd.SimpleRenderer) Test(org.junit.Test)

Example 2 with UnsetInputPropertiesException

use of name.herlin.command.UnsetInputPropertiesException in project pmd-eclipse-plugin by pmd.

the class RenderReportCmdTest method testRenderReportCmdNullArg3.

/**
 * Test robustness #3
 *
 * @throws CommandException
 */
@Test
public void testRenderReportCmdNullArg3() throws CommandException {
    try {
        final RenderReportsCmd cmd = new RenderReportsCmd();
        cmd.setProject(this.testProject);
        cmd.registerRenderer(new HTMLRenderer(), null);
        cmd.performExecute();
        Assert.fail();
    } catch (final UnsetInputPropertiesException e) {
    // yes cool
    }
}
Also used : UnsetInputPropertiesException(name.herlin.command.UnsetInputPropertiesException) HTMLRenderer(net.sourceforge.pmd.renderers.HTMLRenderer) Test(org.junit.Test)

Example 3 with UnsetInputPropertiesException

use of name.herlin.command.UnsetInputPropertiesException in project pmd-eclipse-plugin by pmd.

the class RenderReportCmdTest method testRenderReportCmdNullArg1.

/**
 * Test robustness #1
 *
 * @throws CommandException
 */
@Test
public void testRenderReportCmdNullArg1() throws CommandException {
    try {
        final RenderReportsCmd cmd = new RenderReportsCmd();
        cmd.setProject(null);
        cmd.registerRenderer(new HTMLRenderer(), PMDRuntimeConstants.HTML_REPORT_NAME);
        cmd.performExecute();
        Assert.fail();
    } catch (final UnsetInputPropertiesException e) {
    // yes cool
    }
}
Also used : UnsetInputPropertiesException(name.herlin.command.UnsetInputPropertiesException) HTMLRenderer(net.sourceforge.pmd.renderers.HTMLRenderer) Test(org.junit.Test)

Example 4 with UnsetInputPropertiesException

use of name.herlin.command.UnsetInputPropertiesException in project pmd-eclipse-plugin by pmd.

the class RenderReportCmdTest method testRenderReportCmdNullArg5.

/**
 * Test robustness #5
 *
 * @throws CommandException
 */
@Test
public void testRenderReportCmdNullArg5() throws CommandException {
    try {
        final RenderReportsCmd cmd = new RenderReportsCmd();
        cmd.setProject(null);
        cmd.registerRenderer(new HTMLRenderer(), null);
        cmd.performExecute();
        Assert.fail();
    } catch (final UnsetInputPropertiesException e) {
    // yes cool
    }
}
Also used : UnsetInputPropertiesException(name.herlin.command.UnsetInputPropertiesException) HTMLRenderer(net.sourceforge.pmd.renderers.HTMLRenderer) Test(org.junit.Test)

Example 5 with UnsetInputPropertiesException

use of name.herlin.command.UnsetInputPropertiesException in project pmd-eclipse-plugin by pmd.

the class JobCommandProcessor method processCommand.

/**
 * @see name.herlin.command.CommandProcessor#processCommand(name.herlin.command.AbstractProcessableCommand)
 */
public void processCommand(final AbstractProcessableCommand aCommand) throws CommandException {
    LOG.debug("Begining job command " + aCommand.getName());
    if (!aCommand.isReadyToExecute()) {
        throw new UnsetInputPropertiesException();
    }
    final Job job = new Job(aCommand.getName()) {

        @Override
        protected IStatus run(IProgressMonitor monitor) {
            try {
                if (aCommand instanceof AbstractDefaultCommand) {
                    ((AbstractDefaultCommand) aCommand).setMonitor(monitor);
                }
                Timer timer = new Timer();
                aCommand.execute();
                timer.stop();
                PMDPlugin.getDefault().logInformation("Command " + aCommand.getName() + " excecuted in " + timer.getDuration() + "ms");
            } catch (CommandException e) {
                PMDPlugin.getDefault().logError("Error executing command " + aCommand.getName(), e);
            }
            synchronized (outstanding) {
                count.decrementAndGet();
                Job job = outstanding.poll();
                if (job != null) {
                    job.schedule();
                }
            }
            return Status.OK_STATUS;
        }
    };
    if (aCommand instanceof AbstractDefaultCommand) {
        job.setUser(((AbstractDefaultCommand) aCommand).isUserInitiated());
    }
    synchronized (outstanding) {
        if (count.incrementAndGet() > 10) {
            // too many already running, put in a queue to run later
            outstanding.add(job);
        } else {
            job.schedule();
        }
    }
    this.addJob(aCommand, job);
    LOG.debug("Ending job command " + aCommand.getName());
}
Also used : IProgressMonitor(org.eclipse.core.runtime.IProgressMonitor) Timer(name.herlin.command.Timer) UnsetInputPropertiesException(name.herlin.command.UnsetInputPropertiesException) CommandException(name.herlin.command.CommandException) Job(org.eclipse.core.runtime.jobs.Job)

Aggregations

UnsetInputPropertiesException (name.herlin.command.UnsetInputPropertiesException)7 Test (org.junit.Test)6 SimpleRenderer (net.sourceforge.pmd.cpd.SimpleRenderer)3 HTMLRenderer (net.sourceforge.pmd.renderers.HTMLRenderer)3 CommandException (name.herlin.command.CommandException)1 Timer (name.herlin.command.Timer)1 IProgressMonitor (org.eclipse.core.runtime.IProgressMonitor)1 Job (org.eclipse.core.runtime.jobs.Job)1