Skip to content

Commit

Permalink
monorepo treatment
Browse files Browse the repository at this point in the history
  • Loading branch information
paul-hammant committed Feb 8, 2017
1 parent 8e03c38 commit c04edee
Show file tree
Hide file tree
Showing 88 changed files with 546 additions and 0 deletions.
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -20,3 +20,6 @@ bin
*.versionsBackup
pom.xml.versionsBackup
jacoco.exec

# Monorepo tech needs us to hide
pom.xml
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
84 changes: 84 additions & 0 deletions mr/all_poms.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,84 @@
./coverage-report/pom-template.xml
./jooby/pom-template.xml
./jooby-akka/pom-template.xml
./jooby-archetype/pom-template.xml
./jooby-archetype/src/main/resources/archetype-resources/pom-template.xml
./jooby-assets/pom-template.xml
./jooby-assets-autoprefixer/pom-template.xml
./jooby-assets-babel/pom-template.xml
./jooby-assets-clean-css/pom-template.xml
./jooby-assets-closure-compiler/pom-template.xml
./jooby-assets-csslint/pom-template.xml
./jooby-assets-j2v8/pom-template.xml
./jooby-assets-jscs/pom-template.xml
./jooby-assets-jshint/pom-template.xml
./jooby-assets-less/pom-template.xml
./jooby-assets-less4j/pom-template.xml
./jooby-assets-ng-annotate/pom-template.xml
./jooby-assets-nodejs/pom-template.xml
./jooby-assets-requirejs/pom-template.xml
./jooby-assets-rollup/pom-template.xml
./jooby-assets-sass/pom-template.xml
./jooby-assets-svg-sprites/pom-template.xml
./jooby-assets-svg-symbol/pom-template.xml
./jooby-assets-uglify/pom-template.xml
./jooby-assets-yui-compressor/pom-template.xml
./jooby-aws/pom-template.xml
./jooby-banner/pom-template.xml
./jooby-bom/pom-template.xml
./jooby-caffeine/pom-template.xml
./jooby-camel/pom-template.xml
./jooby-cassandra/pom-template.xml
./jooby-commons-email/pom-template.xml
./jooby-couchbase/pom-template.xml
./jooby-crash/pom-template.xml
./jooby-csl/pom-template.xml
./jooby-dist/pom-template.xml
./jooby-ebean/pom-template.xml
./jooby-ehcache/pom-template.xml
./jooby-elasticsearch/pom-template.xml
./jooby-executor/pom-template.xml
./jooby-flyway/pom-template.xml
./jooby-ftl/pom-template.xml
./jooby-gradle-plugin/pom-template.xml
./jooby-gson/pom-template.xml
./jooby-guava-cache/pom-template.xml
./jooby-hazelcast/pom-template.xml
./jooby-hbm/pom-template.xml
./jooby-hbm4/pom-template.xml
./jooby-hbs/pom-template.xml
./jooby-hbv/pom-template.xml
./jooby-jackson/pom-template.xml
./jooby-jade/pom-template.xml
./jooby-jdbc/pom-template.xml
./jooby-jdbi/pom-template.xml
./jooby-jedis/pom-template.xml
./jooby-jetty/pom-template.xml
./jooby-jongo/pom-template.xml
./jooby-jooq/pom-template.xml
./jooby-maven-plugin/pom-template.xml
./jooby-metrics/pom-template.xml
./jooby-mongodb/pom-template.xml
./jooby-mongodb-rx/pom-template.xml
./jooby-morphia/pom-template.xml
./jooby-netty/pom-template.xml
./jooby-pac4j/pom-template.xml
./jooby-pebble/pom-template.xml
./jooby-quartz/pom-template.xml
./jooby-querydsl/pom-template.xml
./jooby-raml/pom-template.xml
./jooby-reactor/pom-template.xml
./jooby-run/pom-template.xml
./jooby-rxjava/pom-template.xml
./jooby-rxjava-jdbc/pom-template.xml
./jooby-scanner/pom-template.xml
./jooby-servlet/pom-template.xml
./jooby-sitemap/pom-template.xml
./jooby-spec/pom-template.xml
./jooby-spymemcached/pom-template.xml
./jooby-swagger/pom-template.xml
./jooby-thymeleaf/pom-template.xml
./jooby-unbescape/pom-template.xml
./jooby-undertow/pom-template.xml
./jooby-whoops/pom-template.xml
./pom-template.xml
130 changes: 130 additions & 0 deletions mr/checkout.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,130 @@
#!/usr/bin/python
import os
import sys
import shutil
from subprocess import call

def needThis(neededModule, depMap, neededModules2):
if neededModule in depMap:
for dependency in depMap[neededModule]:
needThis(dependency, depMap, neededModules2)
neededModules2[neededModule] = True

def writepom(pom_template):
dirname = os.path.dirname(pom_template)
with open(pom_template) as f:
if os.path.exists(dirname + '/pom.xml'):
os.chmod(dirname + '/pom.xml', 0755)
with open(dirname + '/pom.xml', 'w') as the_pom:
lines = f.readlines()
for line in lines:
if line.strip().startswith("<module>") and line.strip().endswith("</module>"):
sub_project = line.strip()[8:]
sub_project = sub_project[:sub_project.index("<")]
f_path = dirname + "/" + sub_project
if os.path.exists(f_path + '/pom.xml') or os.path.exists(f_path + '/pom-template.xml'):
the_pom.write(line)
else:
the_pom.write(line)
os.chmod(dirname + '/pom.xml', 0444)

def recursive_delete_if_empty(path):
"""Recursively delete empty directories; return True
if everything was deleted."""

if not os.path.isdir(path):
# If you also want to delete some files like desktop.ini, check
# for that here, and return True if you delete them.
return False

# Note that the list comprehension here is necessary, a
# generator expression would shortcut and we don't want that!
if all([recursive_delete_if_empty(os.path.join(path, filename))
for filename in os.listdir(path)]):
# Either there was nothing here or it was all deleted
os.rmdir(path)
return True
else:
return False

neededModules = {}
depMap = {}

# passed in args into dict
for ix, arg in enumerate(sys.argv):
if ix > 0:
neededModules[arg] = True

# crunch dot graph into Python dict
with open("mr/dependency-graph.dot") as dot:
lines = dot.readlines()
for line in lines:
line = line.replace("\"","")
if " -> " in line:
parts = line.split(" -> ")
lpart = parts[0].split(":")[1]
rpart = parts[1].split(":")[1]
if lpart not in depMap:
depMap[lpart] = {}
depMap[lpart][rpart] = True

# penultimate list of deps we need, tree into flat
neededModules2 = {}
for neededModule in neededModules:
needThis(neededModule, depMap, neededModules2)

# we always need these
sparse_checkout = "/.gitignore\n/.gitattributes\n/checkstyle.xml\n/LICENSE\n/mr/*\n/README.md\n/pom-template.xml\n"

with open("mr/all_poms.txt") as allpoms:
lines = allpoms.readlines()
for line in lines:
hit = False
for neededModule in neededModules2:
if "/"+neededModule+"/" in line:
sparse_checkout += line[1:]
sparse_checkout += line[1:].replace("pom-template.xml","src/*")

# Redo sparse-checkout file
with open('.git/info/sparse-checkout', 'w') as sc:
if len(sys.argv) == 1:
sc.write("/*")
else:
sc.write(sparse_checkout)

# Remove old pom files
for root, dirs, files in os.walk("."):
for currentFile in files:
path_join = os.path.join(root, currentFile)
if path_join.endswith("/pom.xml"):
os.remove(path_join)

# sparse re-checkout
call(["git", "checkout", "--"])

# Write new pom files if approriate
for root, dirs, files in os.walk("."):
for currentFile in files:
fullpath = os.path.join(root, currentFile)
if fullpath.endswith("/pom-template.xml"):
writepom(fullpath)

# Delete orphaned target folders and Intellij .iml files
dirs_to_delete = []
files_to_delete = []
for root, dirs, files in os.walk("."):
for currentDir in dirs:
fullpath = os.path.join(root, currentDir)
if fullpath.endswith("/target") and not os.path.exists(os.path.dirname(fullpath) + '/pom.xml'):
dirs_to_delete.append(fullpath)
for currentFile in files:
fullpath = os.path.join(root, currentFile)
if fullpath.endswith(".iml") and not os.path.exists(os.path.dirname(fullpath) + '/pom.xml'):
files_to_delete.append(fullpath)

for fullpath in dirs_to_delete:
shutil.rmtree(fullpath)
for fullpath in files_to_delete:
os.remove(fullpath)

recursive_delete_if_empty(".")
Loading

0 comments on commit c04edee

Please sign in to comment.