forked from SonarSource/sonar-scanner-jenkins
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
SONARJNKNS-374 Fix withSonarQubeEnv step hanging due to symlinks
- Loading branch information
Showing
2 changed files
with
57 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -22,6 +22,7 @@ | |
import com.cloudbees.plugins.credentials.CredentialsProvider; | ||
import hudson.EnvVars; | ||
import hudson.FilePath; | ||
import hudson.Util; | ||
import hudson.model.Action; | ||
import hudson.model.Actionable; | ||
import hudson.model.Result; | ||
|
@@ -31,6 +32,7 @@ | |
import hudson.plugins.sonar.action.SonarAnalysisAction; | ||
import hudson.plugins.sonar.client.HttpClient; | ||
import hudson.plugins.sonar.client.WsClient; | ||
import java.io.File; | ||
import java.io.IOException; | ||
import java.io.InputStream; | ||
import java.io.InputStreamReader; | ||
|
@@ -44,6 +46,9 @@ | |
import java.util.stream.Stream; | ||
import javax.annotation.CheckForNull; | ||
import javax.annotation.Nullable; | ||
import org.apache.tools.ant.DirectoryScanner; | ||
import org.apache.tools.ant.Project; | ||
import org.apache.tools.ant.types.FileSet; | ||
import org.jenkinsci.plugins.plaincredentials.StringCredentials; | ||
|
||
public final class SonarUtils { | ||
|
@@ -94,7 +99,7 @@ public static <T extends Action> T getPersistentAction(Actionable actionable, Cl | |
public static Properties extractReportTask(TaskListener listener, FilePath workspace) throws IOException, InterruptedException { | ||
FilePath[] candidates = null; | ||
if (workspace.exists()) { | ||
candidates = workspace.list("**/" + REPORT_TASK_FILE_NAME); | ||
candidates = find(workspace, "**/" + REPORT_TASK_FILE_NAME); | ||
} | ||
if (candidates == null || candidates.length == 0) { | ||
listener.getLogger().println("WARN: Unable to locate '" + REPORT_TASK_FILE_NAME + "' in the workspace. Did the SonarScanner succeed?"); | ||
|
@@ -114,6 +119,24 @@ public static Properties extractReportTask(TaskListener listener, FilePath works | |
|
||
} | ||
|
||
/** | ||
* This method does the same as {@link FilePath#list(String)} but does not follow symlinks. | ||
*/ | ||
private static FilePath[] find(FilePath workspace, String includes) { | ||
FileSet fs = Util.createFileSet(new File(workspace.getRemote()), includes, null); | ||
fs.setDefaultexcludes(true); | ||
fs.setFollowSymlinks(false); | ||
|
||
DirectoryScanner ds = fs.getDirectoryScanner(new Project()); | ||
This comment has been minimized.
Sorry, something went wrong.
This comment has been minimized.
Sorry, something went wrong.
This comment has been minimized.
Sorry, something went wrong.
ericg138
Author
|
||
String[] includedFiles = ds.getIncludedFiles(); | ||
|
||
FilePath[] candidates = new FilePath[includedFiles.length]; | ||
for (int i = 0; i < candidates.length; i++) { | ||
candidates[i] = new FilePath(new File(workspace.getRemote(), includedFiles[i])); | ||
} | ||
return candidates; | ||
} | ||
|
||
@Nullable | ||
/** | ||
* Collects as much information as it finds from the sonar analysis in the build and adds it as an action to the build. | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
On the built-in node. If not using Jenkins Core API classes are not aware of any remote system.