Skip to content

Suppose You Want to Improve The Code Quality of Your Program and List All The Issues Exists and Have a Nice Dashboard of It

Prelude

You woke up to the blaring and painful sound of your alarm. You recognize this tune, it's your third layer in case you slept through the first two. You purposely made it the worst thing posisble to hear, sorting algorithm, though it doesn't sound as bad now that you've grown accustomed to it. "I should really change them.". You haven't really browsed the music of this world all that much, maybe they'll be better. But nevermind that, now you have to force yourself out of the bed.

You went to the kitchen and made some tea. As you take a sip, you realized that you used salt instead of sugar. "Geh, what a bad start." As you continued your morning routine, small but annoying things kept happening. You ran out of shampoo, one of your socks is missing, and your favorite website got blocked by the local government. "Something bad is gonna happen today, won't it? I'm starting to think I'm cursed." You uttered to yourself as you leave for work.

The heavy mood of the office strikes immediately after you arrived. Everyone seems a little busier than usual. Occassionally you would see people running from one corner to another. The thought doesn't concern you, though, as whether there is a problem or not for you, you will deal with it in front of a computer anyway. As you entered your division's office, your eyes landed on Emory. They look... rather normal, surprisingly. Maybe Emory works well under pressure. "I should greet Emory." You thought, but not long after another person came and took your chance. Alas, you concede and retreated back to your desk.

You turned on your PC, everything works fine. You have your tasks for today already laid out on your desk, Rory must've put them earlier. You read and thought it was odd that today's task was just minute things. "There must be a catch here somewhere." You thought. You took a quick glance up at your monitor, and then it dawned on you. "One of those days, huh?" You stare at the timeout errors on all in-house tools the company offer. No one is going to get much done except locally. You begin your shift and type away at your keyboard.

Distress

"Do you, uhh... have some time?" A faint voice broke your concentration. You turned your head. It was one of your co-workers, you remember them from your first day but you don't think you've spoken to them since. "What can I do for you, err..." You stopped mid sentence, you don't remember their name. "Riley. It's okay, barely anyone remembers my name around here." They seem to be the self-deprecating type. While you don't necessarily have a problem, it might be a pain to deal with whatever Riley is going to bring up.

"Riley, okay. Is there a problem?" You continued. "No... I mean, yes! Umm, not really your problem, but..." They paused and seemed to think for a while. "Is it related to why the server is so slow today?" You fire a blind guess. Riley's face lit up, it seems that you've hit the bullseye. "Actually, yes! You see, one of our engineers... Uhh, 'left', a short while ago. They were in charge of the job management system in the company and it seems like that somehow they sabotaged the codebase. It seems to be extremely inefficient and slow now."

Straight out of an action movie, you thought. Actually, is there hollywood equivalent here? Your mind wonders a little bit before Riley interrupted. "So, I was tasked with fixing it but I don't actually know what to do. The code is a mess and I don't think I can completely rewrite it from scratch...". You seem to get the gist of it, Riley wants you to help identify and fix the problem together. If you get it done quick, your tasks can be finished in no time. But there's still a question lingering on your mind.

"Any reason why you asked me in particular?" You don't exactly have much expertise either, and if anything, you're the newest member of the team. "Emory seems to be... warm, to you. So I thought maybe they could also help us." Warm? In what world are those expressionless face 'warm'? Maybe Riley grew so accustomed to it that they can tell the slightest bit of difference. Now that you think about it, Riley is the person you saw at Emory's desk this morning. You guess they might have asked before.

But regardless, you do feel like the only other person you've really interacted with is Emory, so there wasn't a choice to begin with. "Alright, I'll try." You said as you rise from your chair. "...! Thank you!" Contrary to Emory, Riley's face is so honest with their emotions. You felt a sense of refreshment, maybe today won't be so bad after all.

Conflict

"What?" Emory asked you with their usual cold stare. You plopped down them the document Riley gave you earlier. "I've been told someone sabotaged this company service today. That's why we're all working extremely slow right now." You continued. "Yeah. And what about it?" Emory uttered while typing away, seemingly ignoring you. Again, Riley, in what world is this 'warm'? "I thought I could take a look at it, maybe I know something." You replied. Emory stopped for a second. "That's Riley's job, not yours. Don't you have your own tasks today?" Her tone might have slightly changed, but it's really hard to tell.

"Well, if I help Riley maybe we'll get back to speed quicker. So I don't have to slave away at my task for hours on end too." This time Emory did not say anything. You feel a sense of tension, did you say something wrong? It's hard to tell over that steel mask of theirs. "Umm, so-..." Before you can finish your sentence, Emory interjects. "I gave you access, do you what you want." This time you can tell Emory's tone changed. It might be rude to ask more, but you're not sure if you could do it either, so there's only one way.

"You did say that I can bother you again anytime, right? Can I ask for help along the way, or...?" You asked with a timid intonnation. "Why don't you ask Riley instead, there's a reason that that is her task. You're the one helping her, so why are you asking for my help anyway?" Does Emory have a personal vendetta against Riley or something? You have to pick your words carefully, getting Emory's help will be important to your success, you formulated a sentence and prepared for the worst.

"You're a great teacher, Emory. I'm not extremely bright, yet you got me to understand foreign concepts easily. Your tutelage drives me to want to explore a lot more, that's why I want to try my hands at this. It seems like the perfect opportunity to hone my skill and prove that I'm useful to everyone." You took a deep breath and continued. "However, I know my own limitations. I do not have the necessary knowledge yet. But with your kind guidance, I'm sure even someone like me could be a part of something greater. So please, Emory."

You cringed, you've never tried so hard to sway another person before, let alone deliver praises. It is as embrassing as people say, but what you say aren't lies. You took a glance at Emory. "Heh." A weird sound came out of their mouth. Did they just chuckle? The stoic Emory just chuckled at you, how are you ever going to live this down. You feel your confidence dropping, but then...

"Flattery won't get you anywhere with me, but I suppose you're right. This will be a good learning opportunity for you." Emory said with her normal tone, maybe this is the 'warm' Riley mentioned. "Very well, I shall teach you something. But you have to learn how to utilize it yourself." Emory gets up and started walking to your desk. You breathe a sigh of relief. "Come on, we don't have all day."

Sonarqube

Emory took over your PC. "Are you familiar with any code quality measuring tools?". You tried to remember if you've used any in the past. Maybe you did, but alas, you shook your head. "Alright then, let's use my solution." Emory opens your browser then typed something in the address bar. "Meet SonarQube." Emory points at the screen. "SonarQube gives you a dashboard and metrics to measure your code quality. When you push new code to the repository, SonarScan will measure the quality of your code. SonarQube also lists all the issues and recommendations to fix them."

"This tool will help you fix the application. The big problems are fairly obvious, you don't need SonarQube for them as they're more of a system wide problem. I've marked most but it's possible that there may be more you can do. You will need to use SonarQube for the little ones, though." Emory paused and checks if you're still listening. "I'll give you a quick rundown."

Setting Up SonarQube

  1. Log in to SonarQube CSUI with your GitLab CSUI account

loginform

  1. Create a new project by clicking on the + next to your profile

loginform

  1. Set up the project credentials. To make it unique, set up the name with the following format: advprog-practice-[NPM]

loginform

  1. Generate a token, which will be used in the GitLab's CI pipeline environment with the name SONAR_TOKEN. Keep the generated value. You will need it for later. Set up the project as a Java project using Gradle.

loginform

  1. Configure sonar in build.gradle file and add a sonar job in the gitlab-ci.yml file (Example provided below)

Add the sonar configuration in build.gradle.

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
sonarqube {
    properties {
        property "sonar.projectName", "<your project name>"
        property "sonar.projectKey", "<your project key>"
        property "sonar.jacoco.reportPaths", allTestCoverageFile
        property "sonar.host.url", "https://sonarqube.cs.ui.ac.id"
        property("sonar.coverage.exclusions",
            [
                "**/*Application**'"
            ])

    }
}

Add the sonar stages in gitlab-ci

1
2
3
4
stages:
  - build
  - test
  - sonar

Add sonarCheck job in the gitlab-ci

1
2
3
4
5
6
sonarCheck:
  stage: sonar
  needs:
    - job: test
  script:
      - gradle sonarqube -Dsonar.login=$SONAR_TOKEN
  1. Configure your Gitlab CS repository by adding the SONAR_TOKEN from earlier

loginform

loginform

  1. Push the code and see the pipeline!
  2. You’ll see the status of your code at SonarQube CSUI

loginform

Code Smells

"Now, you are familiar with code smells, no?" Emory interjects with a question. "If I recall correctly, code smells are any violation of fundamental design principles that decrease the overall quality of the code. Is that right?" Emory gave you a little nod. "After you think you're done with problems that SonarQube can find, see if you can fix any of the ones I marked. Each mark also have their hints, but in case you need extra material, you can go here."

Emory begins typing another site. "Go to this site if you feel stuck, it should have everything you need." You seem to recognize a few, but you feel the need to review all of them. Emory stands up and start walking away, you assume back to their desk. "...And yes, you can bother me any time. Good luck." Emory then disappears from your sight. Below that emotionless face is still a kind heart, you thought to yourself.

More knowledgable than ever before, you set out to complete your task.

TODO

  • Set up the SonarQube
  • Resolve as many as possible Issues in Sonar Dashboard
  • Answer this question in README.md (or any extension you more prefer)
  • Why do we need SonarQube for refactoring? What does SonarQube offer?
  • What is the relationship between SonarQube Quality Gate and Clean Code?
  • Suppose you asked to deal with a technical issue within the program. What will you prioritize when implementing the fixes? The performance or the code quality?

Bonus

  • Resolve as many TODO as you can. Make sure to write what you think is the problem with each TODO and how you solved them
  • Make the quality gate of SonarQube reaches A
  • Answer this question in the same file as README.md:
  • Is SonarQube the only way to solve the problem? Is there any different way to solve the problem? (hint: Software Quality metrics)

Another one down

It's almost the end of the day when you're done fixing the problems in SonarQube. It was quite the challenge, but nothing as dire as the next thing that comes across your mind. You completely forgot about your own task today, you scramble to find the document, but it's nowhere to be seen. You kept searching until a familiar faint voice calls out to you.

"Umm, excuse me..." You looked towards the source of the voice and sure enough, it's Riley. "I was going to fix the application with you... But I heard your speech earlier, and it amazed me how motivated you are, so I thought I'd help finish your task instead." While it's mostly mundane tasks, it saved you from going overtime today. "Thanks, sorry I forgot to fetch you. Emory kind of took over, so." You feel bad taking all the credit to yourself, but Riley doesn't seem to mind.

"Not at all, you're my savior! Thank you so much for today!" Riley jumped and hugged you. You're not used to this kind of skinskip, but you're more surprised that someone so timid can be so daring, in the workplace no less. "Alright then, I'll catch you tomorrow!" Riley trots back to their desk, leaving you stunned, but not entirely unhappy. "That... might be enough for a bit." You uttered to yourself.

Another job well done. You feel satisfied with todays work as you step out of the building. "Maybe life like this isn't so bad after all". You gaze into the night sky as you walk. Your co-workers might be eccentrict, but they're nice people, at least. As you got back home, you reached into your pocket and felt a cold shiver down your spine. You took off your jacket and sure enough, there was a hole with your keys nowhere in sight.

"I'm starting to think I'm cursed."


Last update: 2022-02-22 22:27:15
Created: 2022-02-22 22:27:15
Back to top