Skip to content
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

SONARJAVA-5158 update issue message #4964

Open
wants to merge 12 commits into
base: master
Choose a base branch
from
Open

Conversation

erwan-serandour
Copy link
Contributor

@erwan-serandour erwan-serandour commented Dec 16, 2024

SONARJAVA-5158

Part of

String issueMessage = MessageFormat.format(MESSAGE, javaFile.getName(), packageName, dir);
int srcIndex = dir.indexOf("src");
String truncatedPath = dir.substring(srcIndex == -1 ? 0 : srcIndex);
String issueMessage = MessageFormat.format(MESSAGE, truncatedPath, packageName.replace(File.separator, "."));

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we replace MessageFormat and use String.format? Or is there a specific reason to use the former?

Comment on lines 50 to 51
int srcIndex = dir.indexOf("src");
String truncatedPath = dir.substring(srcIndex == -1 ? 0 : srcIndex);

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I understand that by convention, java files should be placed under src/{main|test}/java, but users can customize the location where their sources are located. Can we use the module specific source directory to match?

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

After discussion, a simpler approach is to use sonar.projectBaseDir as the base root

Copy link

Quality Gate failed Quality Gate failed

Failed conditions
1 New issue
82.6% Coverage on New Code (required ≥ 95%)

See analysis details on SonarQube

Catch issues before they fail your Quality Gate with our IDE extension SonarQube IDE SonarQube IDE

Copy link

sonarqube-next bot commented Jan 7, 2025

Quality Gate failed Quality Gate failed

Failed conditions
2 New issues

See analysis details on SonarQube

Catch issues before they fail your Quality Gate with our IDE extension SonarQube IDE SonarQube IDE

@Test
void mismatch_with_root_directory() {
CheckVerifier.newVerifier()
.onFile("src/test/files/checks/mismatchPackage/Mismatch.java")

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this might be a good time to move the test files to the java-checks-test-sources module

});

assertThat(e)
.isInstanceOf(UnsupportedOperationException.class);

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

it might be worth checking the exception message here

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍

Comment on lines 192 to 206
@Rule(key = "VerifyProjectLevelWorkDir")
protected static final class VerifyProjectLevelWorkDir implements JavaFileScanner {
private final String projectLevelWorkDir;

public VerifyProjectLevelWorkDir(String projectLevelWorkDir){
this.projectLevelWorkDir = projectLevelWorkDir;
}

@Override
public void scanFile(JavaFileScannerContext context) {
if(!projectLevelWorkDir.equals(context.getRootProjectWorkingDirectory().getPath())){
throw new RuntimeException("This checks fails if project level does not match context.getRootProjectWorkingDirectory");
}
}
}

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What is this class and where is it used in the code?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is a mock java check with the purpose to test that property root project directory corresponds to what is expected. But indeed the message and the variable name is confusing.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍

Comment on lines 65 to 73
String rootName = rootDirectory.getName();
List<String> path = new ArrayList<>();

while (fileDirectory != null && !fileDirectory.getName().equals(rootName)) {
path.add(0, fileDirectory.getName());
fileDirectory = fileDirectory.getParentFile();
}

truncatedPath = String.join(File.separator, path);

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We should extract part of the code could leave in its own method. Right now, it is using and re-assigning variables defined outside of the try block, which are also used outside of the try block

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍

Copy link

This PR is stale because it has been open 7 days with no activity. If there is no activity in the next 7 days it will be closed automatically

@github-actions github-actions bot added the stale label Jan 18, 2025
Copy link

Quality Gate failed Quality Gate failed

Failed conditions
3 New issues

See analysis details on SonarQube

Catch issues before they fail your Quality Gate with our IDE extension SonarQube IDE SonarQube IDE

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants