Refactoring InstallFromWorkspace.cobra
Posted: Wed Apr 29, 2015 5:41 am
Making a package for Cobra, I have read InstallFromWorkspace.cobra. This file makes build and installation in one phase and it superuser mode. It could be easier for people to create more packages in Unix, if this phases can be divided in (maybe configure), build and install. Because the creation of the package in faked in a build directory, superuser privileges are not needed. Some changes could be:
Note that everything can be done patching code and with shell commands, so the benefits are in making easier the creation of packages.
I think that InstallFromWorkspace.cobra need some refactoring https://en.wikipedia.org/wiki/Code_refactoring, before making any change. This are some issues:
This are my ideas to refactor the code, before make any changes. The cons are: new bugs?, understand the new code. The benefits are: easier modification in the future, reusable (maybe) abstractions.
I attach an UML diagram and the refactored code (only tested in Linux). What do you think?
- Enable or disabled the check of superuser privileges
- Destination directory can be changed writing a file named 'install-directory.text' but we can pass an argument instead.
- An optional parameter to where install dll's
- A parameter for destination directory of documentation
Note that everything can be done patching code and with shell commands, so the benefits are in making easier the creation of packages.
I think that InstallFromWorkspace.cobra need some refactoring https://en.wikipedia.org/wiki/Code_refactoring, before making any change. This are some issues:
- The code mix installation in Windows and Unix, saying 'if .isRunningOnUnix do this if .isRunningOnWindows do that' in different places. Is better to "tell, don't ask", separating in two classes UnixInstaller and WindowsInstaller the process and moving common methods to a base class Installer, that acts as a template for the installation.
- The installation use msbuild or xbuild and gacutil. Part of the code is similar, locating the path of the tools in the filesystem and running a command when is found. This can be abstracted in a CommandLineTool class (well, I see some of its methods in Process or ProcessOutput).
- A lot of information about the platform is shown in the installation, this can be reusable in a Platform class, which is a facade for different classes Environment, Assembly, CobraCore.
This are my ideas to refactor the code, before make any changes. The cons are: new bugs?, understand the new code. The benefits are: easier modification in the future, reusable (maybe) abstractions.
I attach an UML diagram and the refactored code (only tested in Linux). What do you think?