diff --git a/.gitignore b/.gitignore index 83bfd14..0ac80aa 100644 --- a/.gitignore +++ b/.gitignore @@ -1,4 +1,8 @@ +__pychache__/ +*pyc .DS_Store *iml *idea *.class +target/* +*.log diff --git a/.travis.yml b/.travis.yml new file mode 100644 index 0000000..eed5a40 --- /dev/null +++ b/.travis.yml @@ -0,0 +1,6 @@ +language: java +jdk: openjdk8 +language: python + - "3.7" +script: + - python build.py \ No newline at end of file diff --git a/advanced_java/tests/PlanetsTest.java b/advanced_java/tests/PlanetsTest.java index 5f08382..705edf6 100644 --- a/advanced_java/tests/PlanetsTest.java +++ b/advanced_java/tests/PlanetsTest.java @@ -8,6 +8,7 @@ import java.text.MessageFormat; class PlanetsTest { + private static String EARTH = "earth03"; private static String loggerMsg = "Assertion Failed: Expected {0} but found {1}"; public static void testEarth_WhenPlanetsGiven(Planets planets, String expected) { @@ -16,7 +17,7 @@ public static void testEarth_WhenPlanetsGiven(Planets planets, String expected) } public static void main(String[] args) { - testEarth_WhenPlanetsGiven(Planets.EARTH, "earth03"); + testEarth_WhenPlanetsGiven(Planets.EARTH, EARTH); } diff --git a/build.py b/build.py new file mode 100644 index 0000000..c66a645 --- /dev/null +++ b/build.py @@ -0,0 +1,117 @@ +import logging +import build_utils + +logging.basicConfig(filename='ds.log', level=logging.ERROR) + +################################################################### +# BASE STAGE # +################################################################### +class Stages: + def __init__(self, stage_name): + self.stage_name = stage_name + + def run(self): + pass + + +################################################################### +# BUILD # +################################################################### +class Build(Stages): + __name__ = 'build' + + def __init__(self, _files): + super().__init__(stage_name=__name__) + self._files = _files + + def run(self): + pass + + +################################################################### +# TEST # +################################################################### +class Test(Stages): + def __init__(self): + __name__ = 'test' + super().__init__(__name__) + + def run(self): + pass + + +################################################################### +# COMPILE # +################################################################### +class Compile(Stages): + _name = 'compile' + + def __init__(self, _files, _ignored): + super().__init__(stage_name=__name__) + self._files = _files + self._ignored = _ignored + + def compile(self): + import os + logging.info('Setting current working directory\t{}'.format(os.getcwd())) + try: + failed_files = [] + for _dir in self._files: + for _f in self._files[_dir]: + try: + if '.java' in _f and _f not in self._ignored: + if os.system('javac {} -d target'.format(_f)) != 0: + failed_files.append(_f) + logging.info('failed files length: \t{0}'.format(len(failed_files))) + logging.info('Compiled files:\t {}'.format(_f)) + except Exception as e: + continue + except Exception as e: + raise + finally: + if len(failed_files) != 0: + with open('failed_compilations', 'a') as ff: + ff.write('\n'.join(failed_files)) + logging.error('COMPILATION FAILED FOR {} FILES'.format(len(failed_files))) + + def run(self): + logging.info("RUNNING STAGE:\t {}".format(Compile._name)) + self.compile() + logging.info('COMPILATION COMPLETE') + +################################################################### +# STAGES RUNNER # +################################################################### +class StageRunner: + def __init__(self, *args): + """ + :param kwargs: dictionary of stages inheriting Stages class + """ + assert args is not None and len(args) != 0 + self.stages = [stage(args[1], args[2]) for stage in args[0]] + self._files = args[1] + self.ignored = args[2] + + def run(self): + self.create_dir() + for stage in self.stages: + print('run') + stage.run() + + def validate(self): + for stage in self.stages: + stage.run() + + def create_dir(self): + build_utils.create_dir('target') + +################################################################### +# +################################################################### +if __name__ == '__main__': + _files = build_utils.get_dirs() + _ff = open('failed_compilations', 'r') + _fflist = _ff.readlines() + _ff.close() + stage_runner = StageRunner([Compile], _files, _fflist) + stage_runner.run() \ No newline at end of file diff --git a/build_utils.py b/build_utils.py new file mode 100644 index 0000000..b4445a6 --- /dev/null +++ b/build_utils.py @@ -0,0 +1,26 @@ +import os + +def get_dirs(): + """ + This method expects src/ to be present in the directories which want to + be compiled and tested. + It creates the paths to the files from the current working directory + so that it can be compiled from the current working directory. + :return: dictionary containing directories as keys and the files inside src/. + """ + compilable_files = {} + for a, b, c in os.walk(os.getcwd()): + if "src" in a: + compilable_files[a] = [os.path.join(a, _file) for _file in c] + print(compilable_files) + return compilable_files + + +def create_dir(path=None, name=None): + """ + Create a new directory in the directory given as path. + :param: Path where you want the new directory to be created. + :return: True if the path got created + """ + if not os.path.exists(path): + os.makedirs(path) diff --git a/failed_compilations b/failed_compilations new file mode 100644 index 0000000..18a496d --- /dev/null +++ b/failed_compilations @@ -0,0 +1,39 @@ +/home/sid/github/datastructures/linked_list/src/DeleteNodeClass.java +/home/sid/github/datastructures/disjoint_set/src/FriendCircleQuery.java +/home/sid/github/datastructures/queue/src/QueueImplementer.java +/home/sid/github/datastructures/queue/src/QueueHelper.java +/home/sid/github/datastructures/stacks/src/StackHelper.java +/home/sid/github/datastructures/stacks/src/TwoStackClassHelper.java +/home/sid/github/datastructures/sudoku-solver/src/SudokuTester.java +/home/sid/github/datastructures/binary_tree/src/HeightBalancedTree.java +/home/sid/github/datastructures/binary_tree/src/PathSum.java +/home/sid/github/datastructures/sorts/src/Partitioning.java +/home/sid/github/datastructures/sorts/src/Analysis.java +/home/sid/github/datastructures/sorts/src/MergeSort.java +/home/sid/github/datastructures/arrays/src/MoveZero.java +/home/sid/github/datastructures/arrays/src/MaximumMinimumForm.java +/home/sid/github/datastructures/arrays/src/ReplaceEveryElementWithGreatestOnRight.java +/home/sid/github/datastructures/arrays/src/BinarySearchRotateArray.java +/home/sid/github/datastructures/arrays/src/RotateArrayQuickly.java +/home/sid/github/datastructures/arrays/src/Stub.java +/home/sid/github/datastructures/arrays/src/LarThreeElements.java +/home/sid/github/datastructures/arrays/src/ReplaceElementWithMultiplicationOfPreviousAndNext.java +/home/sid/github/datastructures/arrays/src/SubMatrixSumQuery.java +/home/sid/github/datastructures/arrays/src/MinDistBetweenNumbers.java +/home/sid/github/datastructures/arrays/src/Pivot.java +/home/sid/github/datastructures/arrays/src/ShuffleArray.java +/home/sid/github/datastructures/trie/src/Boggle.java +/home/sid/github/datastructures/trie/src/EnglishDictionary.java +/home/sid/github/datastructures/trie/src/AutoComplete.java +/home/sid/github/datastructures/trie/src/LongestCommonPrefix.java +/home/sid/github/datastructures/trie/src/LongestPrefixMatching.java +/home/sid/github/datastructures/linked_list/src/DeleteNodeClass.java +/home/sid/github/datastructures/problem_solving/src/SudokuTester.java +/home/sid/github/datastructures/problem_solving/src/KruskalMST.java +/home/sid/github/datastructures/problem_solving/src/SnakeAndLadder.java +/home/sid/github/datastructures/problem_solving/src/GCDOfArray.java +/home/sid/github/datastructures/problem_solving/src/MergeNewInterval.java +/home/sid/github/datastructures/problem_solving/src/MinimumCostToConnectCities.java +/home/sid/github/datastructures/heaps/src/PriorityQueue.java +/home/sid/github/datastructures/heaps/src/HeapSort.java +/home/sid/github/datastructures/heaps/src/HeapImplementer.java \ No newline at end of file