-
Notifications
You must be signed in to change notification settings - Fork 67
Improved SRP and extract classes/methods for better modularity #85
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
Merged
Merged
Changes from all commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
09fa6ab
chore: Improve SRP and extract classes/methods for better modularity
mohammedhashim790 f7dd2fc
chore(refactor): Added CodeSmellDetectors, Introduced Variable, and R…
mohammedhashim790 92ba4e9
chore: delete .idea directory
mohammedhashim790 d51e860
chore: deleted .idea* and removed class comment of ArgumentParser.
mohammedhashim790 db98bbc
chore: deleted .idea* and removed class comment of ArgumentParser.
mohammedhashim790 106ff4e
chore: Update .gitignore to ignore MAC OS files and .DS_Store banished!
mohammedhashim790 be79a8f
fix(tests): Fixed Failing Test Cases on DesigniteJava.
mohammedhashim790 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,30 @@ | ||
| package Designite.ArgumentParser; | ||
|
|
||
| import org.apache.commons.cli.Option; | ||
|
|
||
|
|
||
| public abstract class ArgumentParser { | ||
| /** | ||
| * {@code createRequiredOption}. A method to initialise required {@link Option}. | ||
| * @param shortOpt | ||
| * @param longOpt | ||
| * @param description | ||
| * @return | ||
| */ | ||
| Option createRequiredOption(String shortOpt, String longOpt, String description) { | ||
| Option option = new Option(shortOpt, longOpt, true, description); | ||
| option.setRequired(true); | ||
| return option; | ||
| } | ||
|
|
||
| /** | ||
| * {@code parseArguments} converts the appropriate {@code args} parameter from the system. | ||
| * It extracts the data from system arguments. | ||
| * @param args | ||
| * @return | ||
| */ | ||
| public abstract InputArgs parseArguments(String[] args); | ||
|
|
||
|
|
||
|
|
||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,41 @@ | ||
| package Designite.ArgumentParser; | ||
|
|
||
| import Designite.utils.DJLogger; | ||
| import org.apache.commons.cli.*; | ||
|
|
||
| /** | ||
| * {@code CLIArgumentParser} is a subclass of {@code ArgumentParser} that requires arguments from | ||
| * the console application in order to process the given arguments. | ||
| */ | ||
| public class CLIArgumentParser extends ArgumentParser { | ||
|
|
||
| @Override | ||
| public InputArgs parseArguments(String[] args) { | ||
| Options argOptions = new Options(); | ||
| argOptions.addOption(this.createRequiredOption("i", "Input", "Input source folder path")); | ||
| argOptions.addOption(this.createRequiredOption("o", "Output", "Path to the output folder")); | ||
| CommandLineParser parser = new DefaultParser(); | ||
| HelpFormatter formatter = new HelpFormatter(); | ||
| CommandLine cmd = null; | ||
| try { | ||
| cmd = parser.parse(argOptions, args); | ||
| } catch (ParseException e) { | ||
| System.out.println(e.getMessage()); | ||
| formatter.printHelp("Designite", argOptions); | ||
| DJLogger.log("Quitting.."); | ||
| System.exit(1); | ||
| } | ||
| String inputFolderPath = cmd.getOptionValue("Input"); | ||
| String outputFolderPath = cmd.getOptionValue("Output"); | ||
| try { | ||
| return new InputArgs(inputFolderPath, outputFolderPath); | ||
| } catch (IllegalArgumentException ex) { | ||
| DJLogger.log(ex.getMessage()); | ||
| DJLogger.log("Quitting.."); | ||
| System.err.printf("The specified input path does not exist: %s%n", inputFolderPath); | ||
| System.exit(3); | ||
| } | ||
| return null; | ||
| } | ||
|
|
||
| } |
2 changes: 1 addition & 1 deletion
2
src/Designite/InputArgs.java → src/Designite/ArgumentParser/InputArgs.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,4 +1,4 @@ | ||
| package Designite; | ||
| package Designite.ArgumentParser; | ||
|
|
||
| import java.io.File; | ||
|
|
||
|
|
||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,30 @@ | ||
| package Designite.ArgumentParser; | ||
|
|
||
| import Designite.utils.DJLogger; | ||
|
|
||
| import java.io.File; | ||
|
|
||
|
|
||
| /** | ||
| * {@code RegularArgumentParser} is a subclass of {@code ArgumentParser} that does not require any | ||
| * arguments. By default, it will use the current working directory (cwd) of the Java project | ||
| * to identify or analyze the smells in the current working project itself. | ||
| */ | ||
| public class RegularArgumentParser extends ArgumentParser { | ||
|
|
||
| @Override | ||
| public InputArgs parseArguments(String[] args) { | ||
| String cwd = System.getProperty("user.dir"); | ||
| String inputFolderPath = String.join(File.separator, cwd, "src","Designite"); | ||
| String outputFolderPath = String.join(File.separator, cwd, "output"); | ||
| try { | ||
| return new InputArgs(inputFolderPath, outputFolderPath); | ||
| } catch (IllegalArgumentException ex) { | ||
| DJLogger.log(ex.getMessage()); | ||
| DJLogger.log("Quitting.."); | ||
| System.exit(3); | ||
| } | ||
| return null; | ||
| } | ||
|
|
||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,134 +1,54 @@ | ||
| package Designite; | ||
|
|
||
| import java.io.File; | ||
| import java.io.FileNotFoundException; | ||
| import java.io.IOException; | ||
| import Designite.SourceModel.*; | ||
| import Designite.ArgumentParser.ArgumentParser; | ||
| import Designite.ArgumentParser.CLIArgumentParser; | ||
| import Designite.ArgumentParser.InputArgs; | ||
| import Designite.ArgumentParser.RegularArgumentParser; | ||
| import Designite.SourceModel.SM_Project; | ||
| import Designite.utils.Constants; | ||
| import Designite.utils.Logger; | ||
| import Designite.utils.DJLogger; | ||
|
|
||
| import java.io.FileNotFoundException; | ||
| import java.io.PrintWriter; | ||
| import java.nio.file.Files; | ||
| import java.nio.file.LinkOption; | ||
| import java.nio.file.Path; | ||
| import java.text.SimpleDateFormat; | ||
| import java.util.Calendar; | ||
| import org.apache.commons.cli.*; | ||
|
|
||
| /** | ||
| * | ||
| * This is the start of the project | ||
| */ | ||
| public class Designite { | ||
| public static void main(String[] args) throws IOException { | ||
| InputArgs argsObj = parseArguments(args); | ||
| SM_Project project = new SM_Project(argsObj); | ||
| Logger.logFile = getlogFileName(argsObj); | ||
| //TODO: log the version number | ||
| project.parse(); | ||
| project.resolve(); | ||
| project.computeMetrics(); | ||
| project.detectCodeSmells(); | ||
| if (Constants.DEBUG) | ||
| writeDebugLog(argsObj, project); | ||
| Logger.log("Done."); | ||
| } | ||
|
|
||
| private static void writeDebugLog(InputArgs argsObj, SM_Project project) { | ||
| PrintWriter writer = getDebugLogStream(argsObj); | ||
| project.printDebugLog(writer); | ||
| if (writer != null) | ||
| writer.close(); | ||
| } | ||
|
|
||
| private static InputArgs parseArguments(String[] args) { | ||
| Options argOptions = new Options(); | ||
|
|
||
| Option input = new Option("i", "Input", true, "Input source folder path"); | ||
| input.setRequired(true); | ||
| argOptions.addOption(input); | ||
|
|
||
| Option output = new Option("o", "Output", true, "Path to the output folder"); | ||
| output.setRequired(true); | ||
| argOptions.addOption(output); | ||
|
|
||
| CommandLineParser parser = new DefaultParser(); | ||
| HelpFormatter formatter = new HelpFormatter(); | ||
| CommandLine cmd = null; | ||
|
|
||
| try { | ||
| cmd = parser.parse(argOptions, args); | ||
| } catch (ParseException e) { | ||
| System.out.println(e.getMessage()); | ||
| formatter.printHelp("Designite", argOptions); | ||
| Logger.log("Quitting.."); | ||
| System.exit(1); | ||
| } | ||
| if(cmd==null) | ||
| { | ||
| System.out.println("Couldn't parse the command line arguments."); | ||
| formatter.printHelp("Designite", argOptions); | ||
| Logger.log("Quitting.."); | ||
| System.exit(2); | ||
| public static void main(String[] args) throws FileNotFoundException { | ||
| ArgumentParser argumentParser = (Constants.DEBUG) ? new RegularArgumentParser() : new CLIArgumentParser(); | ||
| InputArgs argsObj = argumentParser.parseArguments(args); | ||
| DJLogger.getInstance().setOutputDirectory(argsObj.getOutputFolder()); | ||
| SM_Project project = new SM_Project(argsObj); | ||
| project.parse(); | ||
| project.resolve(); | ||
| project.computeMetrics(); | ||
| project.detectCodeSmells(); | ||
| writeDebugLog(argsObj, project); | ||
| DJLogger.log("Done."); | ||
| } | ||
|
|
||
| private static void writeDebugLog(InputArgs argsObj, SM_Project project) { | ||
| if (Constants.DEBUG) { | ||
| PrintWriter writer = getDebugLogStream(argsObj); | ||
| project.printDebugLog(writer); | ||
| if (writer != null) writer.close(); | ||
| } | ||
|
|
||
| String inputFolderPath = cmd.getOptionValue("Input"); | ||
| String outputFolderPath = cmd.getOptionValue("Output"); | ||
|
|
||
| InputArgs inputArgs= null; | ||
| try | ||
| { | ||
| inputArgs = new InputArgs(inputFolderPath, outputFolderPath); | ||
| } | ||
|
|
||
| private static PrintWriter getDebugLogStream(InputArgs argsObj) { | ||
| PrintWriter writer = null; | ||
| if (!argsObj.getOutputFolder().equals("")) { | ||
| String timeStamp = new SimpleDateFormat("ddMMyyyy_HHmm").format(Calendar.getInstance().getTime()); | ||
| String filename = argsObj.getOutputFolder() + "DesigniteDebugLog" + timeStamp + ".txt"; | ||
| try { | ||
| writer = new PrintWriter(filename); | ||
| } catch (FileNotFoundException ex) { | ||
| DJLogger.log(ex.getMessage()); | ||
| } | ||
| } | ||
| catch(IllegalArgumentException ex) | ||
| { | ||
| Logger.log(ex.getMessage()); | ||
| Logger.log("Quitting.."); | ||
| System.exit(3); | ||
| } | ||
| return inputArgs; | ||
| } | ||
|
|
||
| private static String getlogFileName(InputArgs argsObj) { | ||
| String file = null; | ||
| String timeStamp = new SimpleDateFormat("ddMMyyyy_HHmm").format(Calendar.getInstance().getTime()); | ||
| file = argsObj.getOutputFolder() + File.separator + "DesigniteLog" + timeStamp + ".txt"; | ||
| ensureOutputFolderExists(argsObj.getOutputFolder()); | ||
| return file; | ||
| } | ||
|
|
||
| private static void ensureOutputFolderExists(String outputFolder) { | ||
| if (outputFolder == null) | ||
| return; | ||
| File folder = new File(outputFolder); | ||
|
|
||
| if (folder.exists() && folder.isDirectory()) | ||
| return; | ||
|
|
||
| try | ||
| { | ||
| boolean isCreated = folder.mkdirs(); | ||
| if (!isCreated) | ||
| { | ||
| System.out.println("Couldn't create output folder."); | ||
| } | ||
| } | ||
| catch (Exception ex) | ||
| { | ||
| System.out.println("Couldn't create output folder. " + ex.getMessage()); | ||
| } | ||
| } | ||
| private static PrintWriter getDebugLogStream(InputArgs argsObj) { | ||
| PrintWriter writer = null; | ||
| if (!argsObj.getOutputFolder().equals("")) { | ||
| String timeStamp = new SimpleDateFormat("ddMMyyyy_HHmm").format(Calendar.getInstance().getTime()); | ||
| String filename = argsObj.getOutputFolder() + "DesigniteDebugLog" + timeStamp + ".txt"; | ||
| try { | ||
| writer = new PrintWriter(filename); | ||
| } catch (FileNotFoundException ex) { | ||
| Logger.log(ex.getMessage()); | ||
| } | ||
| } | ||
| return writer; | ||
| } | ||
| return writer; | ||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.