Skip to content
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

Issues/69/buildpipeline #71

Open
wants to merge 28 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
28 commits
Select commit Hold shift + click to select a range
146295a
Add build pipeline stage for java in yml
SiddharthaAnand Oct 18, 2020
9fe3932
Use openjdk8
SiddharthaAnand Oct 18, 2020
a03cb78
Correct command
SiddharthaAnand Oct 18, 2020
24d4a30
Move out the constants
SiddharthaAnand Oct 18, 2020
d51ffff
Add build sh file and py file and structure
SiddharthaAnand Oct 21, 2020
0667d1e
Build the pipeline methods and classes
SiddharthaAnand Oct 22, 2020
0185df0
Add some content stage name here
SiddharthaAnand Oct 23, 2020
a2415c8
Add skeleton and structure to the build class
SiddharthaAnand Oct 24, 2020
2a186da
Add utils method for the build proces
SiddharthaAnand Oct 24, 2020
af932e4
Remove redundant params| Add documentation string for the method
SiddharthaAnand Oct 24, 2020
f0a0d8d
Use the method written in build_utils here to get hte dirs/files to c…
SiddharthaAnand Oct 24, 2020
0f3e62e
Add some documentation
SiddharthaAnand Oct 24, 2020
c76ad0e
Add a utility method to create a new directory
SiddharthaAnand Oct 26, 2020
efa4d4f
Add the javac compilation stage for the files
SiddharthaAnand Oct 26, 2020
0ad2a93
Pass build object as reference as well
SiddharthaAnand Oct 26, 2020
11b7bb3
Ignore pyc files and pycache dir
SiddharthaAnand Oct 26, 2020
ce5c55e
Add some logging | Write failed compilations into a file to fix those
SiddharthaAnand Oct 26, 2020
d9d7941
Add ignored param to ignore those files for now
SiddharthaAnand Oct 26, 2020
1d3978a
Update the build environment | logging level to error
SiddharthaAnand Oct 26, 2020
c5dc409
Add file for failed compilations
SiddharthaAnand Oct 26, 2020
01a21c3
Add build pipeline code | Add a new file whichs tores the failed comp…
SiddharthaAnand Nov 7, 2020
b306748
file for failed compilations
SiddharthaAnand Nov 7, 2020
5857d0d
ignore log files
SiddharthaAnand Nov 7, 2020
22ca6b2
remvoe unused file
SiddharthaAnand Nov 7, 2020
7caf798
Fix compilation issues
SiddharthaAnand Nov 14, 2020
cfdc88e
Add util method
SiddharthaAnand Nov 14, 2020
15c2861
Failing compilation files to be fixed later
SiddharthaAnand Nov 14, 2020
163343a
Update build_utils.py
SiddharthaAnand Nov 15, 2020
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,4 +1,8 @@
__pychache__/
*pyc
.DS_Store
*iml
*idea
*.class
target/*
*.log
6 changes: 6 additions & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
language: java
jdk: openjdk8
language: python
- "3.7"
script:
- python build.py
3 changes: 2 additions & 1 deletion advanced_java/tests/PlanetsTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand All @@ -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);
}


Expand Down
117 changes: 117 additions & 0 deletions build.py
Original file line number Diff line number Diff line change
@@ -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()
26 changes: 26 additions & 0 deletions build_utils.py
Original file line number Diff line number Diff line change
@@ -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)
39 changes: 39 additions & 0 deletions failed_compilations
Original file line number Diff line number Diff line change
@@ -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