Skip to content

Commit

Permalink
Merge pull request #4 from albert-so/master
Browse files Browse the repository at this point in the history
[JENKINS-13599] Provided better implementation of  DoxygenDirectoryParser#isDirectoryAbsolute().
  • Loading branch information
gboissinot committed Apr 26, 2012
2 parents f14d86f + 1e5d555 commit 82a31e4
Show file tree
Hide file tree
Showing 2 changed files with 66 additions and 24 deletions.
59 changes: 35 additions & 24 deletions src/main/java/hudson/plugins/doxygen/DoxygenDirectoryParser.java
Expand Up @@ -49,7 +49,6 @@ public DoxygenDirectoryParser(String publishType, String doxyfilePath, String do
}

public FilePath invoke(java.io.File workspace, VirtualChannel channel) throws IOException {

try {
return (DoxygenArchiverDescriptor.DOXYGEN_HTMLDIRECTORY_PUBLISHTYPE).equals(publishType)
? retrieveDoxygenDirectoryFromHudsonConfiguration(doxygenHtmlDirectory, new FilePath(workspace))
Expand Down Expand Up @@ -148,42 +147,54 @@ public Boolean invoke(File f, VirtualChannel channel) throws IOException, Interr

final String finalComputedDoxygenDir = doxyGenDir.replace('\\', '/');
Boolean absolute = isDirectoryAbsolute(base, finalComputedDoxygenDir);

LOGGER.info("Directory is absolute:"+absolute);

FilePath result;
if (absolute) {
result = new FilePath(base.getChannel(), finalComputedDoxygenDir);
LOGGER.info("Creating FilePath using base.getChannel()");
result = new FilePath(base.getChannel(), finalComputedDoxygenDir);
} else {
LOGGER.info("Creating FilePath using base");
result = new FilePath(base, doxyGenDir);
}


LOGGER.info("Created filepath with the following path:"+result.getRemote());
if (!result.exists()) {
LOGGER.info("Computed doxygen generated dir does not exist. Returning null");
return null;
}

return result;
}

protected Boolean isDirectoryAbsolute(FilePath base,
final String finalComputedDoxygenDir) throws IOException,
InterruptedException {
Boolean absolute = false;
absolute = base.act(new FilePath.FileCallable<Boolean>() {
public Boolean invoke(File f, VirtualChannel channel)
throws IOException, InterruptedException {

File parentFile = new File(finalComputedDoxygenDir).getParentFile();
if (parentFile == null) {
// A computed directory with no parent will return null.
// Guard against a NullPointerException
return false;
}

return parentFile.exists();
}
});
return absolute;
}
// See https://issues.jenkins-ci.org/browse/JENKINS-13599
protected boolean isDirectoryAbsolute(String path) {
File file = new File(path);
String absolutePath = file.getAbsolutePath();
LOGGER.info(String.format("passed in path:%s, absolutePath:%s",
path, absolutePath));
if(path.equals(file.getAbsolutePath())) {
return true;
}
else {
return false;
}
}

protected Boolean isDirectoryAbsolute(FilePath base,
final String finalComputedDoxygenDir) throws IOException,
InterruptedException {
Boolean absolute = false;
absolute = base.act(new FilePath.FileCallable<Boolean>() {
public Boolean invoke(File f, VirtualChannel channel)
throws IOException, InterruptedException {

// See https://issues.jenkins-ci.org/browse/JENKINS-13599
return isDirectoryAbsolute(finalComputedDoxygenDir);
}
});
return absolute;
}

/**
* Load the Doxyfile Doxygen file in memory
Expand Down
@@ -0,0 +1,31 @@
package hudson.plugins.doxygen;

import org.junit.Test;

import junit.framework.Assert;

public class DoxygenDirectoryParserTest {

@Test
public void testIsAbsolute() throws Exception {
DoxygenDirectoryParser parser = new DoxygenDirectoryParser("", "", "");
// testData array contains arrays of test data where index 0 is the path
// and index 1 is the expectedResult of isAbsolute
// This test data will currently on work in a Unix environment
System.out.println(System.getProperty("user.dir"));
Object[][] testData = new Object[][] {
{ "doc", false },
{ "/usr", true },
{ "abcd123", false }, // nonexistent relative dir
{ "/foo/bar", true }, // nonexistent absolute dir
{ "/etc/passwd", true },
{ "pom.xml", false }, // since tests are run from the trunk dir
{ "src", false }, // a dir in the trunk dir
};

for(Object[] testPair : testData ) {
Boolean actual = parser.isDirectoryAbsolute((String)testPair[0]);
Assert.assertEquals("For path:" + testPair[0], (Boolean)testPair[1], actual);
}
}
}

0 comments on commit 82a31e4

Please sign in to comment.