Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[JENKINS-5347] Added use commit times on files #116

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 22 additions & 2 deletions src/main/java/hudson/scm/SubversionSCM.java
Original file line number Diff line number Diff line change
Expand Up @@ -244,6 +244,7 @@ public class SubversionSCM extends SCM implements Serializable {

private boolean ignoreDirPropChanges;
private boolean filterChangelog;
private boolean useCommitTimes;

/**
* A cache of the svn:externals (keyed by project).
Expand Down Expand Up @@ -334,15 +335,22 @@ public SubversionSCM(List<ModuleLocation> locations, WorkspaceUpdater workspaceU
public SubversionSCM(List<ModuleLocation> locations, WorkspaceUpdater workspaceUpdater,
SubversionRepositoryBrowser browser, String excludedRegions, String excludedUsers, String excludedRevprop, String excludedCommitMessages,
String includedRegions, boolean ignoreDirPropChanges) {
this(locations, workspaceUpdater, browser, excludedRegions, excludedUsers, excludedRevprop, excludedCommitMessages, includedRegions, ignoreDirPropChanges, false, null);
this(locations, workspaceUpdater, browser, excludedRegions, excludedUsers, excludedRevprop, excludedCommitMessages, includedRegions, ignoreDirPropChanges, false, null, false);
}

public SubversionSCM(List<ModuleLocation> locations, WorkspaceUpdater workspaceUpdater,
SubversionRepositoryBrowser browser, String excludedRegions, String excludedUsers, String excludedRevprop, String excludedCommitMessages,
String includedRegions, boolean ignoreDirPropChanges, boolean useCommitTimes) {
this(locations, workspaceUpdater, browser, excludedRegions, excludedUsers, excludedRevprop, excludedCommitMessages, includedRegions, ignoreDirPropChanges, false, null, useCommitTimes);
}

@DataBoundConstructor
public SubversionSCM(List<ModuleLocation> locations, WorkspaceUpdater workspaceUpdater,
SubversionRepositoryBrowser browser, String excludedRegions, String excludedUsers,
String excludedRevprop, String excludedCommitMessages,
String includedRegions, boolean ignoreDirPropChanges, boolean filterChangelog,
List<AdditionalCredentials> additionalCredentials) {
List<AdditionalCredentials> additionalCredentials, boolean useCommitTimes) {
this.useCommitTimes = useCommitTimes;
for (Iterator<ModuleLocation> itr = locations.iterator(); itr.hasNext(); ) {
ModuleLocation ml = itr.next();
String remote = Util.fixEmptyAndTrim(ml.remote);
Expand Down Expand Up @@ -664,6 +672,11 @@ public boolean isIgnoreDirPropChanges() {
public boolean isFilterChangelog() {
return filterChangelog;
}

@Exported
public boolean isUsingCommitTimes() {
return useCommitTimes;
}

/**
* Sets the <tt>SVN_REVISION_n</tt> and <tt>SVN_URL_n</tt> environment variables during the build.
Expand Down Expand Up @@ -947,6 +960,7 @@ private synchronized Map<Job, List<External>> getProjectExternalsCache() {
*/
private static class CheckOutTask extends UpdateTask implements FileCallable<List<External>> {
private final UpdateTask task;
private final boolean isUsingCommitTimes;

public CheckOutTask(Run<?, ?> build, SubversionSCM parent, ModuleLocation location, Date timestamp, TaskListener listener, EnvVars env) {
this.authProvider = parent.createAuthenticationProvider(build.getParent(), location);
Expand All @@ -955,6 +969,7 @@ public CheckOutTask(Run<?, ?> build, SubversionSCM parent, ModuleLocation locati
this.location = location;
this.revisions = build.getAction(RevisionParameterAction.class);
this.task = parent.getWorkspaceUpdater().createTask();
this.isUsingCommitTimes = parent.isUsingCommitTimes();
}

public Set<String> getUnauthenticatedRealms() {
Expand All @@ -966,6 +981,11 @@ public Set<String> getUnauthenticatedRealms() {

public List<External> invoke(File ws, VirtualChannel channel) throws IOException {
clientManager = createClientManager(authProvider);
DefaultSVNOptions defaultSVNOptions = createDefaultSVNOptions();
if (isUsingCommitTimes) {
defaultSVNOptions.setUseCommitTimes(isUsingCommitTimes);
}
clientManager = new SvnClientManager(SVNClientManager.newInstance(defaultSVNOptions, createSvnAuthenticationManager(authProvider)));
manager = clientManager.getCore();
this.ws = ws;
try {
Expand Down
3 changes: 3 additions & 0 deletions src/main/resources/hudson/scm/SubversionSCM/config.jelly
Original file line number Diff line number Diff line change
Expand Up @@ -56,5 +56,8 @@ THE SOFTWARE.
<f:entry title="${%Filter changelog}" field="filterChangelog">
<f:checkbox />
</f:entry>
<f:entry title="${%Set check out file dates to the 'last commit time'}" field="usingCommitTimes">
<f:checkbox />
</f:entry>
</f:advanced>
</j:jelly>
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
<div>
<p>If set Jenkins will set the file timestamps to the last commit time (of each file) when doing a checkout or an update. Otherwise Jenkins will set the current date as the timestamp of each file.</p>
<p>
Normally the working copy files have timestamps that reflect the last time they were touched by any process. This is generally convenient for most build systems as they look at timestamps as a way of deciding which files need to be recompiled.
In other situations, however, it's sometimes nice for the working copy files to have timestamps that reflect the last time they were changed in the repository. The svn export command always places these 'last-commit timestamps' on trees that it produces.
See <a href="http://svnbook.red-bean.com/en/1.7/svn-book.html#svn.advanced.confarea.opts.config">SVN Red Book</a> for more information.
</p>
</div>
45 changes: 44 additions & 1 deletion src/test/java/hudson/scm/SubversionSCMTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,9 @@

import static hudson.scm.SubversionSCM.compareSVNAuthentications;
import static org.jvnet.hudson.test.recipes.PresetData.DataSet.ANONYMOUS_READONLY;
import static org.hamcrest.Matchers.is;
import static org.hamcrest.Matchers.not;
import static org.junit.Assert.assertThat;

/**
* @author Kohsuke Kawaguchi
Expand Down Expand Up @@ -885,7 +888,7 @@ private void verifyChangelogFilter(boolean shouldFilterLog) throws Exception,
File repo = new CopyExisting(getClass().getResource("JENKINS-10449.zip")).allocate();
SubversionSCM scm = new SubversionSCM(ModuleLocation.parse(new String[]{"file://" + repo.toURI().toURL().getPath()},
new String[]{"."},null,null),
new UpdateUpdater(), null, "/z.*", "", "", "", "", false, shouldFilterLog, null);
new UpdateUpdater(), null, "/z.*", "", "", "", "", false, shouldFilterLog, null, false);

FreeStyleProject p = createFreeStyleProject(String.format("testFilterChangelog-%s", shouldFilterLog));
p.setScm(scm);
Expand Down Expand Up @@ -1706,4 +1709,44 @@ private void invokeTestPollingExternalsForFile() throws Exception {
// should detect change
assertTrue(p.poll(StreamTaskListener.fromStdout()).hasChanges());
}

/**
* Test related to https://issues.jenkins-ci.org/browse/JENKINS-5347
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please, use the annotation @Issue

*
* @throws Throwable
*/
public void testUseCommitTimes() throws Throwable {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

When you create tests for a particular JIRA issue, it worth to reference it via comments or @Issue annotation

// Given a subversion workspace where the commit times should be used
// When the workspace is checked out
// Then verify that the last modified time stamp of the format file is 2010-12-31

FreeStyleProject p = createFreeStyleProject();
File repo = new CopyExisting(getClass().getResource("small.zip")).allocate();
SubversionSCM scm = new SubversionSCM(ModuleLocation.parse(new String[]{"file://" + repo.toURI().toURL().getPath()},
new String[]{"."}, null, null), new UpdateUpdater(), null, "/z.*", "", "", "", "", false, false, null, true);
p.setScm(scm);
FreeStyleBuild b = assertBuildStatusSuccess(p.scheduleBuild2(0, new Cause.UserIdCause()).get());
// Using long matching to prevent Timezone issues, divided by 1000 as some OS does not return the exact milliseconds
assertThat(b.getWorkspace().child("b").lastModified() / 1000, is(1293845528l));
}

/**
* Test related to https://issues.jenkins-ci.org/browse/JENKINS-5347
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please, use the annotation @Issue

*
* @throws Throwable
*/
public void testNotUseCommitTimes() throws Throwable {
// Given a subversion workspace where the commit times should NOT be used
// When the workspace is checked out
// Then verify that the last modified time stamp of the format file NOT is 2011-01-01

FreeStyleProject p = createFreeStyleProject();
File repo = new CopyExisting(getClass().getResource("small.zip")).allocate();
SubversionSCM scm = new SubversionSCM(ModuleLocation.parse(new String[]{"file://" + repo.toURI().toURL().getPath()},
new String[]{"."}, null, null), new UpdateUpdater(), null, "/z.*", "", "", "", "", false, false, null, false);
p.setScm(scm);
FreeStyleBuild b = assertBuildStatusSuccess(p.scheduleBuild2(0, new Cause.UserIdCause()).get());
// Using long matching to prevent Timezone issues, divided by 1000 as some OS does not return the exact milliseconds
assertThat(b.getWorkspace().child("b").lastModified() / 1000, not(is(1293845528l)));
}
}