We all tend to do our work faster because time costs money. I realized that we lose a lot of time waiting for IDE to start. I use Netbeans IDE and all our work is related to it. For Java modules, we use Maven and, of course, we have some custom goals. Some goals are pure Java, though we have some goals that use SVN for committing, logging, reverting and so on. And some of them are related to our RDBMS as we load a DB.
But the main problem is that we can do all of this only when Netbeans IDE finishes its class path scanning and other indexing background processes. This, depending on your hardware, could sometimes take up to 3-5 minutes. I didnβt like it, so I decided to make this process a bit faster.
The following main features we use, which I could improve:
- Load database
- SonarQube scanning
- Clean and build
- Pull the source code aka Git but this is for SVN
- Push the source code aka Git but this is for SVN
- SVN reset
- SVN log
- Java Deploy
All these features are related to Maven, therefore, we can write Maven commands. Here is where the BASH comes in! We all know that bash is a very popular and flexible scripting language used by many people around the world. I decided to install and use it instead of the default CMD from Windows. However, it is really hard to remember and write a command like:
|
|
I could have used some plugins from GitHub that provide some features, like fast running a command. But, since I am not a terminal at this moment person, I decided to write my own bash scripts so I could get a taste of it. This would introduce me to the bash world and give me a brief view of its commands. As starting point I installed Git that provides, by default, the Bash terminal and its environment.
Bash aliases
Bash terminal can be configured to load a file at startup. This file is called .bash_profile
. You can create it in the %USER_PROFILE%
directory. In this file, you can write your own bash scripts and they will be available in the terminal at runtime. I added some aliases that are bound to some functions I could run. Example:
Each alias value is a Bash function that is responsible for doing something. Taking in consideration that all commands are Maven based, I defined three aliases I would need:
M
β Run a maven command based on a pom.xml fileR
β Stands for register. I use it to add a directory with a directory alias, list them or remove oneJ
β Jump to a directory using a directory alias
Core and customer structure
Before we go through the implementation, I have to explain why I defined these specific aliases. Internally, we build a product for clients that hold warehouses. More or less, they all have mostly the same functionality, so we have divided our product in 2 parts:
- The Core (common functionality)
- The Client (customer specific functionality)
Because of this, we have different versions for these components. The Core is based on branches and tags like 1.0-SNAPSHOT
or 1.0.1
.
The Client component is based on environments:
Development-SNAPSHOT
, where it may have a dependency on1.0-SNAPSHOT
Acceptance-SNAPSHOT
Production-SNAPSHOT
This structure creates some patterns for accessing specific project folder, like:
Commands
R β Register
Now letβs see what was optimized by using Bash. Using the above mentioned aliases, I can run the commands. As I mentioned r
stands for register, which holds different aliases for different paths. Using r
I can run:
a
β add alias;ls
β list aliases;r
β remove an alias.
Main function:
Delegated function:
|
|
ββNow I go to the pom.xml file of the project and run: r a test
β which means - register add for the current path the alias test
|
|
This command creates in background a file .pathDir
which will be used as a storage for all the aliases. Now I have an alias inside it.
In order to see what other aliases I have, I can write: r ls
β this command will display all the aliases I have in the .pathDir
And of course, I can remove an alias by writing: r r test
β which means: register remove the alias test
linked to any path. Now I can use test
for any other path from the system.
J β Jump
After we added an alias for a path, we can now directly jump to that directory by typing: j iut
β itβs a simple cd
to the referenced path.
Main function:
However, this does not bring you a lot of magic since we might have tags, branches and environments for a project. Well, jump supports additional parameters to the command, like: j iut 1.0.2
β this way we can jump specifically inside the needed folder. But in this case iut
alias should be linked to βD:\ProjectA\β , because this will be the root folder of the project. We can also jump to a tag or an environment if it exists, by writing the following command: j iut 1.0.2
or j iut d
where d
stands for development environment.
|
|
M β Maven
Now, when we are able to jump faster from one project to another, we can run maven goals over the pom.xml files, like this:
m ldb
β loads databasem pull
β SVN update goalm push
β SVN commit goalm reset
β SVN revert goalm log
β SVN log goalm deploy
β deploym sonar
β sonar goal
|
|
Conclusion
Having all of this configured, we can run the load the database or any command over a pom.xml
file without even having to start the Netbeans IDE. The .bash_profile
can be customized per developer, so everyone can add commands of their own. The most important thing is that using Bash we can gain a lot of power due to its internal commands that Windows does not have. We save a lot of time. And while Netbeans starts, you could already have 3-4 terminals working:
- One loading the DB
- Another loading logs
- Third updating another project