Skip to content

Commit

Permalink
detect composer non-recursively
Browse files Browse the repository at this point in the history
[#116521177]

Signed-off-by: John Shahid <[email protected]>
  • Loading branch information
RochesterinNYC authored and cortelyou committed Apr 7, 2016
1 parent d26ce37 commit 681c83a
Show file tree
Hide file tree
Showing 6 changed files with 50 additions and 3 deletions.
12 changes: 12 additions & 0 deletions lib/build_pack_utils/builder.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,13 @@
from cloudfoundry import CloudFoundryUtil
from cloudfoundry import CloudFoundryInstaller
from detecter import TextFileSearch
from detecter import ComposerJsonSearch
from detecter import RegexFileSearch
from detecter import StartsWithFileSearch
from detecter import EndsWithFileSearch
from detecter import ContainsFileSearch
from runner import BuildPack
from utils import rewrite_cfgs
from detecter import RegexFileSearch
from detecter import StartsWithFileSearch
from detecter import EndsWithFileSearch
Expand Down Expand Up @@ -132,6 +139,11 @@ def if_found_output(self, text):
self._output = self._ctx.format(text)
return self

def find_composer_path(self):
self._detecter = self._config(ComposerJsonSearch(self._ctx))
#search for composer.json at that path
return self

def when_not_found_continue(self):
self._continue = True
return self
Expand Down
13 changes: 12 additions & 1 deletion lib/build_pack_utils/detecter.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import os
import re
import logging
import utils
from itertools import chain


class BaseFileSearch(object):
def __init__(self):
self._log = logging.getLogger('detecter')
Expand Down Expand Up @@ -46,6 +46,17 @@ def _match(self, term):
return term == self._text


class ComposerJsonSearch():
def __init__(self, ctx):
extension_path = os.path.abspath(os.path.join(os.path.dirname(__file__), '../../extensions/composer'))
self.extension_module = utils.load_extension(extension_path)
self._ctx = ctx

def search(self, term):
path, _ = self.extension_module.find_composer_paths(self._ctx)
return path is not None


class RegexFileSearch(BaseFileSearch):
def __init__(self, regex):
BaseFileSearch.__init__(self)
Expand Down
3 changes: 1 addition & 2 deletions scripts/detect.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,7 @@
.user_config(step='detect')
.done()
.detect()
.by_name("composer.json")
.recursive()
.find_composer_path()
.if_found_output('php ' + sys.argv[2])
.when_not_found_continue()
.done()
Expand Down
1 change: 1 addition & 0 deletions tests/data/app-asp-net/src/asp-app/Startup.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
not php
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
{"not": "php"}
23 changes: 23 additions & 0 deletions tests/test_detect.py
Original file line number Diff line number Diff line change
Expand Up @@ -132,3 +132,26 @@ def test_detect_with_invalid_json(self):
finally:
if os.path.exists(bp.bp_dir):
shutil.rmtree(bp.bp_dir)

@with_setup(setup=setUp, teardown=tearDown)
def test_detect_with_asp_net_app(self):
shutil.copytree('tests/data/app-asp-net', self.build_dir)
bp = BuildPack({
'BUILD_DIR': self.build_dir,
'CACHE_DIR': self.cache_dir,
'WEBDIR': 'htdocs'
}, '.')
# simulate clone, makes debugging easier
os.rmdir(bp.bp_dir)
shutil.copytree('.', bp.bp_dir,
ignore=shutil.ignore_patterns("binaries",
"env",
"tests"))
try:
bp._detect().strip()
except Exception, e:
print e.output
assert re.match('no', e.output)
finally:
if os.path.exists(bp.bp_dir):
shutil.rmtree(bp.bp_dir)

0 comments on commit 681c83a

Please sign in to comment.