Skip to content

Commit

Permalink
Merge pull request #432 from jglick/mkdirs-JENKINS-37482
Browse files Browse the repository at this point in the history
[JENKINS-37482] Make the cache directory, not just its parent
  • Loading branch information
MarkEWaite committed Aug 19, 2016
2 parents e350aa1 + 3515970 commit fc65311
Show file tree
Hide file tree
Showing 2 changed files with 40 additions and 7 deletions.
9 changes: 5 additions & 4 deletions src/main/java/jenkins/plugins/git/AbstractGitSCMSource.java
Expand Up @@ -363,10 +363,11 @@ protected static File getCacheDir(String cacheEntry) {
return null;
}
File cacheDir = new File(new File(jenkins.getRootDir(), "caches"), cacheEntry);
File parentDir = cacheDir.getParentFile();
if (!parentDir.isDirectory()) {
boolean ok = parentDir.mkdirs();
if (!ok) LOGGER.info("Failed mkdirs of " + parentDir.getPath());
if (!cacheDir.isDirectory()) {
boolean ok = cacheDir.mkdirs();
if (!ok) {
LOGGER.log(Level.WARNING, "Failed mkdirs of {0}", cacheDir);
}
}
return cacheDir;
}
Expand Down
38 changes: 35 additions & 3 deletions src/test/java/jenkins/plugins/git/AbstractGitSCMSourceTest.java
@@ -1,10 +1,16 @@
package jenkins.plugins.git;

import hudson.model.TaskListener;
import hudson.util.StreamTaskListener;
import jenkins.scm.api.SCMSource;
import org.junit.Rule;
import org.junit.Test;
import org.jvnet.hudson.test.Issue;
import org.jvnet.hudson.test.JenkinsRule;
import org.jvnet.hudson.test.WithoutJenkins;
import org.mockito.Mockito;

import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertTrue;
import static org.junit.Assert.*;
import static org.mockito.Mockito.when;
import static org.mockito.Mockito.mock;

Expand All @@ -13,11 +19,16 @@
*/
public class AbstractGitSCMSourceTest {

@Rule
public JenkinsRule r = new JenkinsRule();
@Rule
public GitSampleRepoRule sampleRepo = new GitSampleRepoRule();

/*
* Test excluded branches
*
* TODO seems to overlap AbstractGitSCMSourceTrivialTest.testIsExcluded
*/
@WithoutJenkins // unnecessary if moved into, say, AbstractGitSCMSourceTrivialTest
@Test
public void basicTestIsExcluded(){
AbstractGitSCMSource abstractGitSCMSource = mock(AbstractGitSCMSource.class);
Expand Down Expand Up @@ -45,4 +56,25 @@ public void basicTestIsExcluded(){
assertTrue(abstractGitSCMSource.isExcluded("feature/spiffy/private"));
}

// TODO AbstractGitSCMSourceRetrieveHeadsTest *sounds* like it would be the right place, but it does not in fact retrieve any heads!
@Issue("JENKINS-37482")
@Test
public void retrieveHeads() throws Exception {
sampleRepo.init();
sampleRepo.git("checkout", "-b", "dev");
sampleRepo.write("file", "modified");
sampleRepo.git("commit", "--all", "--message=dev");
SCMSource source = new GitSCMSource(null, sampleRepo.toString(), "", "*", "", true);
TaskListener listener = StreamTaskListener.fromStderr();
// SCMHeadObserver.Collector.result is a TreeMap so order is predictable:
assertEquals("[SCMHead{'dev'}, SCMHead{'master'}]", source.fetch(listener).toString());
// And reuse cache:
assertEquals("[SCMHead{'dev'}, SCMHead{'master'}]", source.fetch(listener).toString());
sampleRepo.git("checkout", "-b", "dev2");
sampleRepo.write("file", "modified again");
sampleRepo.git("commit", "--all", "--message=dev2");
// After changing data:
assertEquals("[SCMHead{'dev'}, SCMHead{'dev2'}, SCMHead{'master'}]", source.fetch(listener).toString());
}

}

0 comments on commit fc65311

Please sign in to comment.