Skip to content

Commit

Permalink
Merge pull request #51 from jochengietzen/master
Browse files Browse the repository at this point in the history
[FIXED JENKINS-33641] Added info about renaming of a job in tooltip s…
  • Loading branch information
Stefan Brausch committed Mar 21, 2016
2 parents c363857 + 74da2d5 commit 6ecee62
Show file tree
Hide file tree
Showing 6 changed files with 117 additions and 23 deletions.
37 changes: 34 additions & 3 deletions src/main/java/hudson/plugins/jobConfigHistory/ConfigInfo.java
Expand Up @@ -60,6 +60,16 @@ public class ConfigInfo implements ParsedDate {
*/
private boolean isJob;

/**
* The current job name after the renaming.
*/
private final String currentJobName;

/**
* The old job name before renaming.
*/
private final String oldJobName;

/**
* Returns a new ConfigInfo object for a system configuration file.
* @param name
Expand All @@ -81,7 +91,9 @@ public static ConfigInfo create(
histDescr.getUser(),
histDescr.getOperation(),
histDescr.getUserID(),
isJob);
isJob,
histDescr.getCurrentJobName(),
histDescr.getOldJobName());
}

/**
Expand All @@ -93,15 +105,16 @@ public static ConfigInfo create(
* @param userID see {@link ConfigInfo#userID}
* @param isJob see {@link ConfigInfo#isJob}
*/
ConfigInfo(String job, boolean configExists, String date, String user, String operation, String userID, boolean isJob) {
ConfigInfo(String job, boolean configExists, String date, String user, String operation, String userID, boolean isJob, String currentJobName, String oldJobName) {
this.job = job;
this.configExists = configExists;
this.date = date;
this.user = user;
this.operation = operation;
this.userID = userID;
this.isJob = isJob;

this.currentJobName = currentJobName;
this.oldJobName = oldJobName;
}

/**
Expand Down Expand Up @@ -187,4 +200,22 @@ public String toString() {
public Date parsedDate() {
return PluginUtils.parsedDate(getDate());
}

/**
* Returns the current job name after renaming.
*/
@Exported
public String getCurrentJobName() {
return currentJobName;
}

/**
* Returns the old job name before renaming.
*/
@Exported
public String getOldJobName() {
return oldJobName;
}


}
31 changes: 16 additions & 15 deletions src/main/java/hudson/plugins/jobConfigHistory/FileHistoryDao.java
Expand Up @@ -136,7 +136,8 @@ File getRootDir(final XmlFile xmlFile, final AtomicReference<Calendar> timestamp
* @throws IOException
* if writing the history fails.
*/
void createHistoryXmlFile(final Calendar timestamp, final File timestampedDir, final String operation) throws IOException {
void createHistoryXmlFile(final Calendar timestamp, final File timestampedDir, final String operation, final AbstractItem item, String oldName) throws IOException {
oldName = ((oldName == null) ? "" : oldName);
final String user;
final String userId;
if (currentUser != null) {
Expand All @@ -146,10 +147,10 @@ void createHistoryXmlFile(final Calendar timestamp, final File timestampedDir, f
user = "Anonym";
userId = Messages.ConfigHistoryListenerHelper_anonymous();
}

final XmlFile historyDescription = getHistoryXmlFile(timestampedDir);
final HistoryDescr myDescr = new HistoryDescr(user, userId, operation, getIdFormatter().format(
timestamp.getTime()));
timestamp.getTime()), (item==null)? "":item.getName(), (item==null) ? "": ((item.getName().equals(oldName)) ? "" : oldName));
historyDescription.write(myDescr);
}

Expand Down Expand Up @@ -240,7 +241,7 @@ static File createNewHistoryDir(final File itemHistoryDir, final AtomicReference
@Override
public void createNewItem(final Item item) {
final AbstractItem aItem = (AbstractItem) item;
createNewHistoryEntryAndCopyConfig(aItem.getConfigFile(), Messages.ConfigHistoryListenerHelper_CREATED());
createNewHistoryEntryAndCopyConfig(aItem.getConfigFile(), Messages.ConfigHistoryListenerHelper_CREATED(), null, null);
}

/**
Expand All @@ -249,8 +250,8 @@ public void createNewItem(final Item item) {
* @param configFile to copy.
* @param operation operation
*/
private void createNewHistoryEntryAndCopyConfig(final XmlFile configFile, final String operation) {
final File timestampedDir = createNewHistoryEntry(configFile, operation);
private void createNewHistoryEntryAndCopyConfig(final XmlFile configFile, final String operation, final AbstractItem item, final String oldName) {
final File timestampedDir = createNewHistoryEntry(configFile, operation, item, oldName);
try {
copyConfigFile(configFile.getFile(), timestampedDir);
} catch (IOException ex) {
Expand All @@ -261,14 +262,14 @@ private void createNewHistoryEntryAndCopyConfig(final XmlFile configFile, final
@Override
public void saveItem(final XmlFile file) {
if (checkDuplicate(file)) {
createNewHistoryEntryAndCopyConfig(file, Messages.ConfigHistoryListenerHelper_CHANGED());
createNewHistoryEntryAndCopyConfig(file, Messages.ConfigHistoryListenerHelper_CHANGED(), null, null);
}
}

@Override
public void deleteItem(final Item item) {
final AbstractItem aItem = (AbstractItem) item;
createNewHistoryEntry(aItem.getConfigFile(), Messages.ConfigHistoryListenerHelper_DELETED());
createNewHistoryEntry(aItem.getConfigFile(), Messages.ConfigHistoryListenerHelper_DELETED(), null, null);
final File configFile = aItem.getConfigFile().getFile();
final File currentHistoryDir = getHistoryDir(configFile);
final SimpleDateFormat buildDateFormat = new SimpleDateFormat("yyyyMMdd_HHmmss_SSS");
Expand Down Expand Up @@ -306,7 +307,7 @@ public void renameItem(final Item item, final String oldName, final String newNa
}

}
createNewHistoryEntryAndCopyConfig(aItem.getConfigFile(), Messages.ConfigHistoryListenerHelper_RENAMED());
createNewHistoryEntryAndCopyConfig(aItem.getConfigFile(), Messages.ConfigHistoryListenerHelper_RENAMED(), aItem, oldName);
}

@Override
Expand Down Expand Up @@ -389,12 +390,12 @@ public boolean hasOldRevision(final XmlFile xmlFile, final String identifier) {
*
* @return timestampedDir
*/
File createNewHistoryEntry(final XmlFile xmlFile, final String operation) {
File createNewHistoryEntry(final XmlFile xmlFile, final String operation, final AbstractItem item, final String oldName) {
try {
final AtomicReference<Calendar> timestampHolder = new AtomicReference<Calendar>();
final File timestampedDir = getRootDir(xmlFile, timestampHolder);
LOG.log(Level.FINE, "{0} on {1}", new Object[] {this, timestampedDir});
createHistoryXmlFile(timestampHolder.get(), timestampedDir, operation);
createHistoryXmlFile(timestampHolder.get(), timestampedDir, operation, item, oldName);
assert timestampHolder.get() != null;
return timestampedDir;
} catch (IOException e) {
Expand Down Expand Up @@ -662,7 +663,7 @@ public void createNewNode(final Node node) {
* @param operation operation.
*/
private void createNewHistoryEntryAndSaveConfig(final Node node, final String content, final String operation) {
final File timestampedDir = createNewHistoryEntry(node, operation);
final File timestampedDir = createNewHistoryEntry(node, operation, null, null);
final File nodeConfigHistoryFile = new File(timestampedDir, "config.xml");
PrintStream stream = null;
try {
Expand All @@ -680,7 +681,7 @@ private void createNewHistoryEntryAndSaveConfig(final Node node, final String co

@Override
public void deleteNode(final Node node) {
createNewHistoryEntry(node, Messages.ConfigHistoryListenerHelper_DELETED());
createNewHistoryEntry(node, Messages.ConfigHistoryListenerHelper_DELETED(), null, null);
// final File configFile = aItem.getConfigFile().getFile();
final File currentHistoryDir = getHistoryDirForNode(node);
final SimpleDateFormat buildDateFormat = new SimpleDateFormat("yyyyMMdd_HHmmss_SSS");
Expand Down Expand Up @@ -752,12 +753,12 @@ private File getRootDir(final Node node, final AtomicReference<Calendar> timesta
}


private File createNewHistoryEntry(final Node node, final String operation) {
private File createNewHistoryEntry(final Node node, final String operation, final AbstractItem item, final String oldName) {
try {
final AtomicReference<Calendar> timestampHolder = new AtomicReference<Calendar>();
final File timestampedDir = getRootDir(node, timestampHolder);
LOG.log(Level.FINE, "{0} on {1}", new Object[] {this, timestampedDir});
createHistoryXmlFile(timestampHolder.get(), timestampedDir, operation);
createHistoryXmlFile(timestampHolder.get(), timestampedDir, operation, item, oldName);
assert timestampHolder.get() != null;
return timestampedDir;
} catch (IOException e) {
Expand Down
27 changes: 24 additions & 3 deletions src/main/java/hudson/plugins/jobConfigHistory/HistoryDescr.java
Expand Up @@ -32,7 +32,7 @@
*/
public class HistoryDescr implements ParsedDate {

static final HistoryDescr EMPTY_HISTORY_DESCR = new HistoryDescr(null, null, null, null);
static final HistoryDescr EMPTY_HISTORY_DESCR = new HistoryDescr(null, null, null, null, null, null);

/** Display name of the user doing the operation. */
private final String user;
Expand All @@ -45,6 +45,12 @@ public class HistoryDescr implements ParsedDate {

/** Timestamp of the operation, see {@link JobConfigHistoryConsts#ID_FORMATTER}. */
private final String timestamp;

/** Current name of the job after renaming. */
private final String currentJobName;

/** Old name of the job before renaming.*/
private final String oldJobName;

/**
* @param user
Expand All @@ -56,12 +62,13 @@ public class HistoryDescr implements ParsedDate {
* @param timestamp
* timestamp of the operation
*/
public HistoryDescr(String user, String userId, String operation, String timestamp) {
public HistoryDescr(String user, String userId, String operation, String timestamp, String currentJobName, String oldJobName) {
this.user = user;
this.userId = userId;
this.operation = operation;
this.timestamp = timestamp;

this.currentJobName = currentJobName;
this.oldJobName = oldJobName;
}

/**
Expand Down Expand Up @@ -109,4 +116,18 @@ public String getTimestamp() {
public Date parsedDate() {
return PluginUtils.parsedDate(getTimestamp());
}

/**
* Returns the current job name after renaming.
*/
public String getCurrentJobName() {
return currentJobName;
}

/**
* Returns the old job name before renaming.
*/
public String getOldJobName() {
return oldJobName;
}
}
Expand Up @@ -42,7 +42,7 @@ public class LazyHistoryDescr extends HistoryDescr {
* @param historyDescriptionFile
*/
public LazyHistoryDescr(XmlFile historyDescriptionFile) {
super(null, null, null, null);
super(null, null, null, null, null, null);
this.historyDescriptionFile = historyDescriptionFile;
}

Expand Down Expand Up @@ -70,6 +70,28 @@ public String getOperation() {
return loadAndGetHistory().getOperation();
}



/**
* {@inheritDoc}.
*/
@Override
public String getCurrentJobName() {
return loadAndGetHistory().getCurrentJobName();
}



/**
* {@inheritDoc}.
*/
@Override
public String getOldJobName() {
return loadAndGetHistory().getOldJobName();
}



/**
* {@inheritDoc}.
*/
Expand Down
Expand Up @@ -5,6 +5,16 @@
<h1>${%Job Configuration History}</h1>
<h2>${it.getProject().getName()}</h2>
<div>
<script type="text/javascript">
function showTooltip(nr) {
console.log(document.getElementById('tooltip' + nr));
document.getElementById('tooltip' + nr).style.visibility = 'visible';
};
function hideTooltip(nr) {
console.log(document.getElementById('tooltip' + nr));
document.getElementById('tooltip' + nr).style.visibility = 'hidden';
};
</script>
<j:set var="configs" value="${it.getJobConfigs()}" />
<j:choose>
<j:when test="${configs.size() == 0}">
Expand Down Expand Up @@ -39,7 +49,16 @@
<j:set var="configNr" value="${configNr + 1}"/>
<tr>
<td>${config.date}</td>
<td>${config.operation}</td>
<td>
<j:if test="${(config.currentJobName!=null) and (! config.currentJobName.isEmpty())}">
<span>${config.operation}</span>
<img onmouseOver="showTooltip(${configNr})" onmouseLeave="hideTooltip(${configNr})" style="height: 16px;margin-left: 10px;width: 16px" src="${resURL}/plugin/jobConfigHistory/img/info.png" alt="${%Info}" />
<div style="margin-top: 15px;visibility: hidden; position: absolute; background-color: beige; padding: 3px; border: 1px solid black;" id="tooltip${configNr}">${%Old name}: ${config.oldJobName}<br />${%New name}: ${config.currentJobName}</div>
</j:if>
<j:if test="${(config.currentJobName==null) || (config.currentJobName.isEmpty())}">
${config.operation}
</j:if>
</td>
<j:if test="${it.hasConfigurePermission() || it.hasJobConfigurePermission()}">
<td><a href="${rootURL}/user/${config.userID}">${config.userID}</a></td>
</j:if>
Expand Down
Binary file added src/main/webapp/img/info.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.

0 comments on commit 6ecee62

Please sign in to comment.