Skip to content
Permalink
Browse files

Merge pull request #4 from albert-so/master

[JENKINS-13599] Provided better implementation of  DoxygenDirectoryParser#isDirectoryAbsolute().
  • Loading branch information
gboissinot committed Apr 26, 2012
2 parents f14d86f + 1e5d555 commit 82a31e40096a95b3aed8351e4902aab9c7377fa8
@@ -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))
@@ -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
@@ -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.
You can’t perform that action at this time.