hudson.model.Saveable Java Examples

The following examples show how to use hudson.model.Saveable. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: SaveableChangeListener.java    From audit-log-plugin with MIT License 6 votes vote down vote up
/**
 * Fired when a saveable object is created. But for now this is customized to only log
 * the saveable fingerprint instances.
 *
 * @param o the saveable object.
 * @param file the XmlFile for this saveable object.
 */
@Override
public void onChange(Saveable o, XmlFile file) {

    if(o instanceof Fingerprint){
        UseCredentials useCredentials = LogEventFactory.getEvent(UseCredentials.class);
        Fingerprint fp = (Fingerprint) o;
        useCredentials.setFileName(fp.getFileName());
        useCredentials.setName(fp.getDisplayName());
        useCredentials.setTimestamp(formatDateISO(fp.getTimestamp().getTime()));
        Hashtable<String, Fingerprint.RangeSet> usages = fp.getUsages();
        if (usages != null) {
            usages.values().forEach(value -> {
                useCredentials.setUsage(value.toString());
                useCredentials.logEvent();
            });
        }
    }


}
 
Example #2
Source File: GiteaWebhookListener.java    From gitea-plugin with MIT License 6 votes vote down vote up
/**
 * {@inheritDoc}
 */
@Override
public void onChange(Saveable o, XmlFile file) {
    if (!(o instanceof Item)) {
        // must be an Item
        return;
    }
    SCMTriggerItem item = SCMTriggerItem.SCMTriggerItems.asSCMTriggerItem((Item) o);
    if (item == null) {
        // more specifically must be an SCMTriggerItem
        return;
    }
    SCMTrigger trigger = item.getSCMTrigger();
    if (trigger == null || trigger.isIgnorePostCommitHooks()) {
        // must have the trigger enabled and not opted out of post commit hooks
        return;
    }
    for (SCM scm : item.getSCMs()) {
        if (scm instanceof GitSCM) {
            // we have a winner
            GiteaWebhookListener.register(item, (GitSCM) scm);
        }
    }
}
 
Example #3
Source File: BaseConfigurator.java    From configuration-as-code-plugin with MIT License 6 votes vote down vote up
@NonNull
@Override
public T configure(CNode c, ConfigurationContext context) throws ConfiguratorException {
    final Mapping mapping = (c != null ? c.asMapping() : Mapping.EMPTY);
    final T instance = instance(mapping, context);
    if (instance instanceof Saveable) {
        try (BulkChange bc = new BulkChange((Saveable) instance) ){
            configure(mapping, instance, false, context);
            bc.commit();
        } catch (IOException e) {
            throw new ConfiguratorException("Failed to save "+instance, e);
        }
    } else {
        configure(mapping, instance, false, context);
    }

    return instance;
}
 
Example #4
Source File: ConfigChangedEventImpl.java    From jenkins-datadog-plugin with MIT License 6 votes vote down vote up
public ConfigChangedEventImpl(Saveable config, XmlFile file, Map<String, Set<String>> tags) {
    super(tags);

    String fileName = DatadogUtilities.getFileName(file);
    String userId = DatadogUtilities.getUserId();
    setAggregationKey(fileName);

    String title = "User " + userId + " changed file " + fileName;
    setTitle(title);

    String text = "%%% \nUser " + userId + " changed file " + fileName + " \n%%%";
    setText(text);

    if (userId != null && "system".equals(userId.toLowerCase())){
        setPriority(Priority.LOW);
        setAlertType(AlertType.INFO);
    }else{
        setPriority(Priority.NORMAL);
        setAlertType(AlertType.WARNING);
    }
}
 
Example #5
Source File: DescribableListConverter.java    From DotCi with MIT License 6 votes vote down vote up
@Override
public Object decode(Class targetClass, Object fromDBObject, MappedField optionalExtraInfo) {
    if (fromDBObject == null) return null;

    BasicDBList rawList = (BasicDBList) fromDBObject;

    List list = new ArrayList();
    for (Object obj : rawList) {
        DBObject dbObj = (DBObject) obj;
        list.add(getMapper().fromDBObject(optionalExtraInfo.getSubClass(), dbObj, getMapper().createEntityCache()));
    }

    Saveable owner = null; // TODO figure out how to associate the deserialized project here

    return new DescribableList(owner, list);
}
 
Example #6
Source File: DatadogSaveableListener.java    From jenkins-datadog-plugin with MIT License 5 votes vote down vote up
@Override
public void onChange(Saveable config, XmlFile file) {
    try {
        final boolean emitSystemEvents = DatadogUtilities.getDatadogGlobalDescriptor().isEmitSystemEvents();
        if (!emitSystemEvents) {
            return;
        }
        logger.fine("Start DatadogSaveableListener#onChange");

        // Get Datadog Client Instance
        DatadogClient client = ClientFactory.getClient();

        // Get the list of global tags to apply
        Map<String, Set<String>> tags = DatadogUtilities.getTagsFromGlobalTags();

        // Send event
        DatadogEvent event = new ConfigChangedEventImpl(config, file, tags);
        client.event(event);

        // Submit counter
        String hostname = DatadogUtilities.getHostname("null");
        client.incrementCounter("jenkins.config.changed", hostname, tags);

        logger.fine("End DatadogSaveableListener#onChange");
    } catch (Exception e) {
        logger.warning("Unexpected exception occurred - " + e.getMessage());
    }
}
 
Example #7
Source File: JiraExtPublisherStep.java    From jira-ext-plugin with Apache License 2.0 4 votes vote down vote up
@DataBoundConstructor
public JiraExtPublisherStep(IssueStrategyExtension issueStrategy, List<JiraOperationExtension> extensions)
{
    this.issueStrategy = issueStrategy;
    this.extensions = new DescribableList<>(Saveable.NOOP, Util.fixNull(extensions));
}
 
Example #8
Source File: PodTemplateToolLocation.java    From kubernetes-plugin with Apache License 2.0 4 votes vote down vote up
public PodTemplateToolLocation(Saveable owner) {
    super(owner);
}
 
Example #9
Source File: PodTemplateToolLocation.java    From kubernetes-plugin with Apache License 2.0 4 votes vote down vote up
public PodTemplateToolLocation(Saveable owner, Collection<? extends NodeProperty<?>> initialList) {
    super(owner,initialList);
}
 
Example #10
Source File: TemplateDrivenMultiBranchProject.java    From multi-branch-project-plugin with MIT License 4 votes vote down vote up
@Override
public void onChange(Saveable o, XmlFile file) {
    if (o instanceof Item) {
        enforceProjectStateOnUpdated((Item) o);
    }
}
 
Example #11
Source File: JUnitResultsStep.java    From junit-plugin with MIT License 2 votes vote down vote up
/**
 * @param testDataPublishers Test data publishers.
 *
 * @since 1.2
 */
@DataBoundSetter public final void setTestDataPublishers(@Nonnull List<TestDataPublisher> testDataPublishers) {
    this.testDataPublishers = new DescribableList<TestDataPublisher,Descriptor<TestDataPublisher>>(Saveable.NOOP);
    this.testDataPublishers.addAll(testDataPublishers);
}
 
Example #12
Source File: JUnitResultArchiver.java    From junit-plugin with MIT License 2 votes vote down vote up
/**
 * @param testDataPublishers Test data publishers.
 *
 * @since 1.2
 */
@DataBoundSetter public final void setTestDataPublishers(@Nonnull List<TestDataPublisher> testDataPublishers) {
    this.testDataPublishers = new DescribableList<TestDataPublisher,Descriptor<TestDataPublisher>>(Saveable.NOOP);
    this.testDataPublishers.addAll(testDataPublishers);
}