Skip to content

Commit

Permalink
Fix JENKINS-12364
Browse files Browse the repository at this point in the history
  • Loading branch information
gboissinot committed Apr 21, 2012
1 parent dc577db commit e5d5192
Show file tree
Hide file tree
Showing 3 changed files with 85 additions and 3 deletions.
82 changes: 82 additions & 0 deletions src/main/java/org/jenkinsci/CppcheckSourceContainer.java
@@ -0,0 +1,82 @@
package org.jenkinsci;

import com.thalesgroup.hudson.plugins.cppcheck.model.CppcheckFile;
import com.thalesgroup.hudson.plugins.cppcheck.model.CppcheckWorkspaceFile;
import com.thalesgroup.hudson.plugins.cppcheck.util.CppcheckLogger;
import hudson.FilePath;
import hudson.model.BuildListener;

import java.io.IOException;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
* @author Gregory Boissinot
*/
public class CppcheckSourceContainer {

private Map<Integer, CppcheckWorkspaceFile> internalMap = new HashMap<Integer, CppcheckWorkspaceFile>();

public CppcheckSourceContainer(BuildListener listener,
FilePath workspace,
FilePath scmRootDir,
List<CppcheckFile> files) throws IOException, InterruptedException {

int key = 1;
for (CppcheckFile cppcheckFile : files) {
CppcheckWorkspaceFile cppcheckWorkspaceFile = getCppcheckWorkspaceFile(listener, workspace, scmRootDir, cppcheckFile);
//The key must be unique for all the files/errors through the merge
cppcheckFile.setKey(key);
cppcheckWorkspaceFile.setCppcheckFile(cppcheckFile);
internalMap.put(key, cppcheckWorkspaceFile);
key = ++key;
}
}

private CppcheckWorkspaceFile getCppcheckWorkspaceFile(BuildListener listener,
FilePath workspace,
FilePath scmRootDir,
CppcheckFile cppcheckFile) throws IOException, InterruptedException {

String cppcheckFileName = cppcheckFile.getFileName();

if (cppcheckFileName == null) {
CppcheckWorkspaceFile cppcheckWorkspaceFile = new CppcheckWorkspaceFile();
cppcheckWorkspaceFile.setFileName(null);
cppcheckWorkspaceFile.setSourceIgnored(true);
return cppcheckWorkspaceFile;
}

CppcheckWorkspaceFile cppcheckWorkspaceFile = new CppcheckWorkspaceFile();
FilePath sourceFilePath = getSourceFile(workspace, scmRootDir, cppcheckFileName);
if (!sourceFilePath.exists()) {
CppcheckLogger.log(listener, "[WARNING] - The source file '" + sourceFilePath.toURI() + "' doesn't exist on the slave. The ability to display its source code has been removed.");
cppcheckWorkspaceFile.setFileName(null);
cppcheckWorkspaceFile.setSourceIgnored(true);
} else if (sourceFilePath.isDirectory()) {
cppcheckWorkspaceFile.setFileName(sourceFilePath.getRemote());
cppcheckWorkspaceFile.setSourceIgnored(true);
} else {
cppcheckWorkspaceFile.setFileName(sourceFilePath.getRemote());
cppcheckWorkspaceFile.setSourceIgnored(false);
}

return cppcheckWorkspaceFile;
}

private FilePath getSourceFile(FilePath workspace, FilePath scmRootDir, String cppcheckFileName) throws IOException, InterruptedException {
FilePath sourceFilePath = new FilePath(scmRootDir, cppcheckFileName);
if (!sourceFilePath.exists()) {
//try from workspace
sourceFilePath = new FilePath(workspace, cppcheckFileName);
}
return sourceFilePath;
}


public Map<Integer, CppcheckWorkspaceFile> getInternalMap() {
return internalMap;
}

}
@@ -1,6 +1,5 @@
package org.jenkinsci.plugins.cppcheck;

import com.thalesgroup.hudson.plugins.cppcheck.model.CppcheckSourceContainer;
import com.thalesgroup.hudson.plugins.cppcheck.model.CppcheckWorkspaceFile;
import com.thalesgroup.hudson.plugins.cppcheck.util.CppcheckLogger;
import hudson.Extension;
Expand All @@ -13,6 +12,7 @@
import hudson.tasks.BuildStepMonitor;
import hudson.tasks.Publisher;
import net.sf.json.JSONObject;
import org.jenkinsci.CppcheckSourceContainer;
import org.jenkinsci.plugins.cppcheck.config.CppcheckConfig;
import org.jenkinsci.plugins.cppcheck.util.CppcheckBuildResultEvaluator;
import org.kohsuke.stapler.StaplerRequest;
Expand Down Expand Up @@ -68,7 +68,7 @@ public boolean perform(AbstractBuild<?, ?> build, Launcher launcher, BuildListen
return false;
}

CppcheckSourceContainer cppcheckSourceContainer = new CppcheckSourceContainer(listener, build.getModuleRoot(), cppcheckReport.getAllErrors());
CppcheckSourceContainer cppcheckSourceContainer = new CppcheckSourceContainer(listener, build.getWorkspace(), build.getModuleRoot(), cppcheckReport.getAllErrors());

CppcheckResult result = new CppcheckResult(cppcheckReport, cppcheckSourceContainer, build);

Expand Down
@@ -1,12 +1,12 @@
package org.jenkinsci.plugins.cppcheck;

import com.thalesgroup.hudson.plugins.cppcheck.CppcheckSource;
import com.thalesgroup.hudson.plugins.cppcheck.model.CppcheckSourceContainer;
import com.thalesgroup.hudson.plugins.cppcheck.model.CppcheckWorkspaceFile;
import hudson.model.AbstractBuild;
import hudson.model.Api;
import hudson.model.Item;
import org.apache.commons.lang.StringUtils;
import org.jenkinsci.CppcheckSourceContainer;
import org.jenkinsci.plugins.cppcheck.config.CppcheckConfig;
import org.kohsuke.stapler.StaplerRequest;
import org.kohsuke.stapler.StaplerResponse;
Expand Down

0 comments on commit e5d5192

Please sign in to comment.