Navigation Menu

Skip to content

Commit

Permalink
Merge pull request #7 from mixalturek/master
Browse files Browse the repository at this point in the history
[JENKINS-22114] CPPCheck - when looking at the source code of an error -...
  • Loading branch information
mixalturek committed Mar 15, 2014
2 parents ce2c74b + 2afb683 commit 5a3e1d3
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 21 deletions.
Expand Up @@ -86,12 +86,13 @@ public CppcheckSource(final AbstractBuild<?, ?> owner, CppcheckWorkspaceFile cpp
private void buildFileContent() {
InputStream is = null;
try {

File tempFile = new File(cppcheckWorkspaceFile.getTempName(owner));
if (tempFile.exists()) {
is = new FileInputStream(tempFile);
} else {

// Reading real workspace file is more incorrect than correct,
// but the code is left here for backward compatibility with
// plugin version 1.14 and less
if (cppcheckWorkspaceFile.getFileName() == null) {
throw new IOException("The file doesn't exist.");
}
Expand Down
Expand Up @@ -31,9 +31,9 @@

public class CppcheckWorkspaceFile {
/**
* Temporary directory holding the workspace files.
* Subdirectory of build directory to store the workspace files.
*/
public static final String WORKSPACE_FILES = "workspace-files";
public static final String DIR_WORKSPACE_FILES = "workspace-files";

private String fileName;

Expand Down Expand Up @@ -100,7 +100,9 @@ public final String getFileName() {

public String getTempName(final AbstractBuild<?, ?> owner) {
if (fileName != null) {
return owner.getRootDir().getAbsolutePath() + "/" + WORKSPACE_FILES + "/" + Integer.toHexString(fileName.hashCode()) + ".tmp";
return owner.getRootDir().getAbsolutePath() + "/"
+ DIR_WORKSPACE_FILES + "/"
+ Integer.toHexString(fileName.hashCode()) + ".tmp";
}
return StringUtils.EMPTY;
}
Expand Down
Expand Up @@ -167,10 +167,8 @@ public boolean perform(AbstractBuild<?, ?> build, Launcher launcher,
XML_FILE_DETAILS));
xmlSourceContainer.write(cppcheckSourceContainer);

if (build.getWorkspace().isRemote()) {
copyFilesFromSlaveToMaster(build.getRootDir(), launcher.getChannel(),
cppcheckSourceContainer.getInternalMap().values());
}
copyFilesToBuildDirectory(build.getRootDir(), launcher.getChannel(),
cppcheckSourceContainer.getInternalMap().values());

CppcheckLogger.log(listener, "Ending the cppcheck analysis.");
}
Expand All @@ -179,7 +177,7 @@ public boolean perform(AbstractBuild<?, ?> build, Launcher launcher,


/**
* Copies all the source files from stave to master for a remote build.
* Copies all the source files from the workspace to the build folder.
*
* @param rootDir directory to store the copied files in
* @param channel channel to get the files from
Expand All @@ -188,21 +186,15 @@ public boolean perform(AbstractBuild<?, ?> build, Launcher launcher,
* @throws java.io.FileNotFoundException if the files could not be written
* @throws InterruptedException if the user cancels the processing
*/
private void copyFilesFromSlaveToMaster(final File rootDir,
private void copyFilesToBuildDirectory(final File rootDir,
final VirtualChannel channel,
final Collection<CppcheckWorkspaceFile> sourcesFiles)
throws IOException, InterruptedException {

File directory = new File(rootDir, CppcheckWorkspaceFile.WORKSPACE_FILES);
if (!directory.exists()) {

if (!directory.delete()) {
//do nothing
}

if (!directory.mkdir()) {
throw new IOException("Can't create directory for remote source files: " + directory.getAbsolutePath());
}
File directory = new File(rootDir, CppcheckWorkspaceFile.DIR_WORKSPACE_FILES);
if (!directory.exists() && !directory.mkdir()) {
throw new IOException("Can't create directory for copy of workspace files: "
+ directory.getAbsolutePath());
}

for (CppcheckWorkspaceFile file : sourcesFiles) {
Expand Down

0 comments on commit 5a3e1d3

Please sign in to comment.