Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Implemented feature for JENKINS-34802
  • Loading branch information
Jochen A. Fürbacher committed May 17, 2016
1 parent 9132060 commit 2f972b1
Show file tree
Hide file tree
Showing 7 changed files with 40 additions and 9 deletions.
Expand Up @@ -110,7 +110,7 @@ private void onRemove() {
private void onChange() {
final JobConfigHistoryStrategy hdao = PluginUtils.getHistoryDao();
for (Node node : Jenkins.getInstance().getNodes()) {
if (isTracked(node) && !hdao.hasDuplicateHistory(node)) {
if (!PluginUtils.isUserExcluded(PluginUtils.getPlugin()) && isTracked(node) && !hdao.hasDuplicateHistory(node)) {
PluginUtils.getHistoryDao().saveNode(node);
return;
}
Expand Down
Expand Up @@ -69,6 +69,8 @@ public class JobConfigHistory extends Plugin {

/** Maximum number of days to keep entries. */
private String maxDaysToKeepEntries;

private String excludedUsers;

/**
* Flag to indicate we should save 'system' level configurations. A 'system' level configuration is defined as one stored
Expand Down Expand Up @@ -129,6 +131,7 @@ public void configure(StaplerRequest req, JSONObject formData)
excludePattern = formData.getString("excludePattern");
saveModuleConfiguration = formData.getBoolean("saveModuleConfiguration");
showBuildBadges = formData.getString("showBuildBadges");
excludedUsers = formData.getString("excludedUsers");
save();
loadRegexpPatterns();
}
Expand Down Expand Up @@ -358,6 +361,14 @@ public File getConfigFile(final File historyDir) {
// TODO: refactor away from 'File'
return FileHistoryDao.getConfigFile(historyDir);
}

/**
*
* @return comma separated list of usernames, whose changes should not get detected.
*/
public String getExcludedUsers(){
return excludedUsers;
}

/**
* Returns true if configuration for this item should be saved, based on the
Expand Down
Expand Up @@ -53,7 +53,6 @@ public void onCreated(Item item) {
LOG.log(FINEST, "In onCreated for {0}", item);
switchHistoryDao(item).createNewItem((item));
LOG.log(FINEST, "onCreated for {0} done.", item);
// new Exception("STACKTRACE for double invocation").printStackTrace();
}

/**
Expand Down
Expand Up @@ -49,7 +49,7 @@ public class JobConfigHistorySaveableListener extends SaveableListener {
public void onChange(final Saveable o, final XmlFile file) {
final JobConfigHistory plugin = getPlugin();
LOG.log(FINEST, "In onChange for {0}", o);
if (plugin.isSaveable(o, file)) {
if (plugin.isSaveable(o, file) && !PluginUtils.isUserExcluded(plugin)) {
final HistoryDao configHistoryListenerHelper = getHistoryDao(plugin);
configHistoryListenerHelper.saveItem(file);
}
Expand Down
27 changes: 22 additions & 5 deletions src/main/java/hudson/plugins/jobConfigHistory/PluginUtils.java
Expand Up @@ -33,6 +33,7 @@
import java.util.Date;
import java.util.logging.Level;
import java.util.logging.Logger;
import java.util.regex.Pattern;

/**
* Helper class.
Expand Down Expand Up @@ -123,11 +124,27 @@ public static JobConfigHistoryStrategy getHistoryDao(final JobConfigHistory plug
maxHistoryEntries = 0;
}
return new FileHistoryDao(
plugin.getConfiguredHistoryRootDir(),
new File(Hudson.getInstance().root.getPath()),
user,
maxHistoryEntries,
!plugin.getSkipDuplicateHistory());
plugin.getConfiguredHistoryRootDir(),
new File(Hudson.getInstance().root.getPath()),
user,
maxHistoryEntries,
!plugin.getSkipDuplicateHistory());
}

public static boolean isUserExcluded(final JobConfigHistory plugin){

final User user = User.current();

if(plugin.getExcludedUsers()!= null){
String excludedUsers = plugin.getExcludedUsers().trim();
String[] segs = excludedUsers.split(Pattern.quote(","));
for(String seg : segs){
if(user != null && user.getId() != null && seg.trim().equals(user.getId())){
return true;
}
}
}
return false;
}

/**
Expand Down
Expand Up @@ -36,6 +36,9 @@
<br />
<f:radio name="showBuildBadges" title="${%Only for administrators}" value="adminUser" checked="${it.getShowBuildBadges() == 'adminUser'}"/>
</f:entry>
<f:entry title="${%Exclude users}" help="/plugin/jobConfigHistory/help/help-excludeUsers.html">
<f:textbox name="excludedUsers" value="${it.excludedUsers}" />
</f:entry>
</f:advanced>
</f:section>
</j:jelly>
Expand Up @@ -403,7 +403,8 @@ JSONObject createFormData() {
"\"skipDuplicateHistory\": true," +
"\"excludePattern\": \"5\"," +
"\"saveModuleConfiguration\": true," +
"\"showBuildBadges\": \"5\"" +
"\"showBuildBadges\": \"5\"," +
"\"excludedUsers\": \"\"" +
"}");
}
}

0 comments on commit 2f972b1

Please sign in to comment.