-
Notifications
You must be signed in to change notification settings - Fork 363
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
limit report line number #611
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -20,6 +20,10 @@ | |
package org.sonar.plugins.cxx.utils; | ||
|
||
import java.io.File; | ||
import java.io.FileNotFoundException; | ||
import java.io.FileReader; | ||
import java.io.IOException; | ||
import java.io.LineNumberReader; | ||
|
||
import org.slf4j.Logger; | ||
import org.slf4j.LoggerFactory; | ||
|
@@ -49,7 +53,7 @@ public static String fileToAbsolutePath(File file) { | |
} | ||
return file.getAbsolutePath(); | ||
} | ||
|
||
/** | ||
* Normalize the given path to pass it to sonar. Return null if normalization | ||
* has failed. | ||
|
@@ -78,8 +82,32 @@ public static String normalizePathFull(String filename, String baseDir) { | |
return filePath; | ||
} | ||
|
||
|
||
/** | ||
* @return returns true for Reactor Projects | ||
*/ | ||
public static boolean isReactorProject(Project project) { | ||
return project.isRoot() && !project.getModules().isEmpty(); | ||
} | ||
|
||
/** | ||
* @return returns number of Lines of a File | ||
*/ | ||
public static int countLines(String normalPath) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Is there no core metric we can use to get the line number? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. There is a line number in the size section of the metrics. |
||
LineNumberReader reader; | ||
int cnt = 0; | ||
try { | ||
reader = new LineNumberReader(new FileReader(normalPath)); | ||
String lineRead = ""; | ||
while ((lineRead = reader.readLine()) != null) {} | ||
cnt = reader.getLineNumber() + 1; | ||
reader.close(); | ||
} catch (FileNotFoundException e) { | ||
LOG.error("countLines of '{}' failed: '{}'", normalPath, e.toString()); | ||
} catch (IOException e1) { | ||
LOG.error("countLines of '{}' failed: '{}'", normalPath, e1.toString()); | ||
} | ||
return cnt; | ||
} | ||
} | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
fromIOFile is deprecated, see http://javadocs.sonarsource.org/4.5.2/apidocs/deprecated-list.html. So we should use something like:
InputFile has method lines.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
performance needs to be measured...
On Thu, 3 Sep 2015 at 14:52 Günter Wirth [email protected] wrote: