Java 类org.kohsuke.stapler.bind.JavaScriptMethod 实例源码

项目:lucene-search-plugin    文件:LuceneManager.java   
@JavaScriptMethod
public JSReturnCollection rebuildDatabase(int workers) {
    JSReturnCollection statement = verifyNotInProgress();
    this.workers = workers;
    if (this.workers <= 0) {
        statement.message = "Invalid number of workers";
        statement.code = 1;
        return statement;
    }

    if (statement.code == 0) {
        progress = new ManagerProgress();
        backendManager.rebuildDatabase(progress, this.workers);

        statement.message = "Work completed succesfully";
        statement.code = 0;
    }
    return statement;
}
项目:lucene-search-plugin    文件:LuceneManager.java   
@JavaScriptMethod
public JSReturnCollection getStatus() {
    JSReturnCollection statement = new JSReturnCollection();
    if (progress != null) {
        statement.progress = progress;
        statement.workers = workers;
        switch (progress.getState()) {
        case COMPLETE:
            statement.message = "Completed without errors";
            break;
        case COMPLETE_WITH_ERROR:
            statement.message = progress.getReasonsAsString();
            statement.code = 2;
            break;
        case PROCESSING:
            statement.running = true;
            statement.message = "processing";
            break;
        }
    } else {
        statement.message = "Never started";
        statement.neverStarted = true;
    }
    return statement;
}
项目:delivery-pipeline-plugin    文件:DeliveryPipelineView.java   
@JavaScriptMethod
@Override
public void triggerManual(String projectName, String upstreamName, String buildId)
        throws TriggerException, AuthenticationException {
    try {
        LOG.fine("Trigger manual build " + projectName + " " + upstreamName + " " + buildId);
        AbstractProject project = ProjectUtil.getProject(projectName, Jenkins.getInstance());
        if (!project.hasPermission(Item.BUILD)) {
            throw new BadCredentialsException("Not authorized to trigger build");
        }
        AbstractProject upstream = ProjectUtil.getProject(upstreamName, Jenkins.getInstance());
        ManualTrigger trigger = ManualTriggerFactory.getManualTrigger(project, upstream);
        if (trigger != null) {
            trigger.triggerManual(project, upstream, buildId, getOwner().getItemGroup());
        } else {
            String message = "Trigger not found for manual build " + projectName + " for upstream "
                    + upstreamName + " id: " + buildId;
            LOG.log(Level.WARNING, message);
            throw new TriggerException(message);
        }
    } catch (TriggerException e) {
        LOG.log(Level.WARNING, triggerExceptionMessage(projectName, upstreamName, buildId), e);
        throw e;
    }
}
项目:restricted-register-plugin    文件:HudsonSecurityRealmRegistration.java   
@SuppressWarnings("unused")
@JavaScriptMethod
public JSONObject checkSecret(String secret) {
    if (SecretKeyChecker.isSecretKeyValid(secret)) {
        return API.success();
    } else {
        return API.errorWithException(new RegistrationException(Messages.RRError_Hudson_Unauthorized()));
    }
}
项目:restricted-register-plugin    文件:HudsonSecurityRealmRegistration.java   
@SuppressWarnings("unused")
@JavaScriptMethod
public JSONObject checkActivationCode(String secret, String activationCode) {
    try {
        if (!SecretKeyChecker.isSecretKeyValid(secret)) {
            throw new RegistrationException(Messages.RRError_Hudson_Unauthorized());
        }
        validateActivationCode(activationCode);
    } catch (Exception e) {
        return API.errorWithException(e);
    }
    return API.success();
}
项目:lucene-search-plugin    文件:LuceneManager.java   
@JavaScriptMethod
public JSReturnCollection abort() throws Exception {
    JSReturnCollection statement = new JSReturnCollection();
    statement.message = "Not implemented";
    statement.code = 1;
    return statement;
}
项目:sauce-health-check    文件:SauceStatusPageDecorator.java   
/**
 * Method which is invoked as an AJAX call when the 'Check Now' link is clicked. This method waits for 5 seconds
 * before executing the Sauce REST API call to simulate server activity.
 *
 * @return the Sauce system status via the Sauce REST API
 */
@JavaScriptMethod
public String checkStatusNow() {
    //Wait for 5 seconds to simulate some server activity
    try {
        Thread.sleep(5000);
    } catch (InterruptedException e) {
        logger.log(Level.WARNING, "Thread interrupted");
    }
    return getsauceStatus();
}
项目:leroy_jenkins    文件:NewProject.java   
@JavaScriptMethod
public List<Stat> getBuildsByEnvironment(String env) {
    RunList<B> builds = getBuilds();
    if (env == null) {
        env = "null";
    }
    List<Stat> stats = StatsHelper.getBuildsByEnvironment(builds, env);
    Collections.sort(stats, new Comparator<Stat>() {
        @Override
        public int compare(Stat o1, Stat o2) {
            return o2.timestamp.compareTo(o1.timestamp);
        }
    });
    return stats;
}
项目:leroy_jenkins    文件:NewProject.java   
@JavaScriptMethod
public List<Stat> getBuildsByWorkflow(String workflow) {
    RunList<B> builds = getBuilds();
    if (workflow == null) {
        workflow = "null";
    }
    List<Stat> stats = StatsHelper.getBuildByWorkflow(builds, workflow);
    Collections.sort(stats, new Comparator<Stat>() {
        @Override
        public int compare(Stat o1, Stat o2) {
            return o2.timestamp.compareTo(o1.timestamp);
        }
    });
    return stats;
}
项目:ccr-parameter-plugin    文件:DynamicConfigurationDefinition.java   
/**
 * @param fileDestination destination of file on local dist
 * @return String with contents of file
 * @throws IOException file was not found
 */
@JavaScriptMethod
private String getJSONFile(String fileDestination) throws IOException {
    FileInputStream inputStream = null;
    try {
        File jsonFile = new File(fileDestination);
        inputStream = new FileInputStream(jsonFile);
        return IOUtils.toString(inputStream);
    } finally {
        IOUtils.closeQuietly(inputStream);
    }
}
项目:rabbitmq-consumer-plugin    文件:GlobalRabbitmqConfiguration.java   
/**
 * Gets specified queue is consumed or not. Note that this is called by
 * Ajax.
 *
 * @param queueName
 *            the queue name.
 * @return true if specified queue is already consumed.
 */
@JavaScriptMethod
public boolean isConsume(String queueName) {
    RMQManager manager = RMQManager.getInstance();
    if (manager.isOpen()) {
        return manager.getChannelStatus(queueName);
    }
    return false;
}
项目:Jenkins-Plugin-Examples    文件:JavaScriptProxy.java   
/**
 * The annotation exposes this method to JavaScript proxy.
 */
@JavaScriptMethod
public int increment(int n) {
    return i+=n;
}
项目:browserstack-integration-plugin    文件:AutomateTestAction.java   
@JavaScriptMethod
public void iframeLoadTime(int time) {
    Analytics.trackIframeLoad(time);
}
项目:jenkins-deployment-dashboard-plugin    文件:DashboardView.java   
@JavaScriptMethod
public String deploy(String version, String environment) {
    LOGGER.info("Deploy version " + version + " to environment " + environment);

    // Get the environment with corresponding build-job
    Environment buildEnvironment = null;
    for (Environment env : environments) {
        if (env.getAwsInstance().equals(environment)) {
            buildEnvironment = env;
            break;
        }
    }

    final AbstractProject buildJob = Jenkins.getInstance().getItemByFullName(buildEnvironment.getBuildJob(), AbstractProject.class);
    LOGGER.info("Executing job: " + buildJob);

    if (buildJob == null) {
        return String.format(Messages.DashboardView_buildJobNotFound(), buildEnvironment.getName());
    }

    if ((!buildJob.isBuildable()) || (!buildJob.isParameterized())) {
        return Messages.DashboardView_deploymentCannotBeExecuted();
    }

    final ParametersAction versionParam = new ParametersAction(new StringParameterValue(PARAM_VERSION, version));
    final ParametersAction environmentParam = new ParametersAction(new StringParameterValue(PARAM_ENVIRONMENT, environment));
    final ParametersAction ec2RegionParam = new ParametersAction(new StringParameterValue(PARAM_EC2_REGION, environment));
    final ParametersAction awsKeyParam = new ParametersAction(new StringParameterValue(PARAM_AWS_KEY, environment));

    List<ParametersAction> actions = Arrays.asList(versionParam, environmentParam, ec2RegionParam, awsKeyParam);
    QueueTaskFuture<AbstractBuild> scheduledBuild = buildJob.scheduleBuild2(2, new Cause.UserIdCause(), actions);

    Result result = Result.FAILURE;
    try {
        AbstractBuild finishedBuild = scheduledBuild.get();
        result = finishedBuild.getResult();
        LOGGER.info("Build finished with result: " + result + " completed in: " + finishedBuild.getDurationString() + ". ");
    } catch (Exception e) {
        LOGGER.severe("Error while waiting for build " + scheduledBuild.toString() + ".");
        LOGGER.severe(e.getMessage());
        LOGGER.severe(ExceptionUtils.getFullStackTrace(e));
        return String.format(Messages.DashboardView_buildJobFailed(), buildJob.getName());
    }
    if (result == Result.SUCCESS) {
        return String.format(Messages.DashboardView_buildJobScheduledSuccessfully(), buildJob.getName());
    }
    return String.format(Messages.DashboardView_buildJobSchedulingFailed(), buildJob.getName());
}
项目:uno-choice-plugin    文件:DynamicReferenceParameter.java   
@JavaScriptMethod
public String getChoicesAsStringForUI() {
    String result = getChoicesAsString(getParameters());
    return result;
}
项目:uno-choice-plugin    文件:AbstractCascadableParameter.java   
@Override
@JavaScriptMethod
public List<Object> getChoicesForUI() {
    Map<Object, Object> mapResult = getChoices(getParameters());
    return Arrays.<Object>asList(mapResult.values(), mapResult.keySet());
}
项目:jenkins-build-monitor-plugin    文件:BuildMonitorView.java   
/**
 * Because of how org.kohsuke.stapler.HttpResponseRenderer is implemented
 * it can only work with net.sf.JSONObject in order to produce correct application/json output
 *
 * @return Json representation of JobViews
 * @throws Exception
 */
@JavaScriptMethod
public JSONObject fetchJobViews() throws Exception {
    return Respond.withSuccess(jobViews());
}
项目:rabbitmq-consumer-plugin    文件:GlobalRabbitmqConfiguration.java   
/**
 * Gets connection to service is established. Note that this is called by
 * Ajax.
 *
 * @return true if connection is established.
 */
@JavaScriptMethod
public boolean isOpen() {
    return RMQManager.getInstance().isOpen();
}