Skip to content

Commit

Permalink
Merge pull request #103 from awslabs/develop
Browse files Browse the repository at this point in the history
chore: Release v0.2.1
  • Loading branch information
jfuss authored Mar 19, 2019
2 parents b1e6624 + 8729f21 commit 7151aaa
Show file tree
Hide file tree
Showing 9 changed files with 33 additions and 71 deletions.
2 changes: 1 addition & 1 deletion .appveyor.yml
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ install:

# setup go
- rmdir c:\go /s /q
- "choco install golang --version 1.11.5"
- "choco install golang"
- "choco install bzr"
- "choco install dep"
- setx PATH "C:\go\bin;C:\gopath\bin;C:\Program Files (x86)\Bazaar\;C:\Program Files\Mercurial;%PATH%;"
Expand Down
2 changes: 1 addition & 1 deletion aws_lambda_builders/__init__.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
"""
AWS Lambda Builder Library
"""
__version__ = '0.2.0'
__version__ = '0.2.1'
RPC_PROTOCOL_VERSION = "0.2"
2 changes: 1 addition & 1 deletion aws_lambda_builders/workflows/go_modules/validator.py
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ def validate(self, runtime_path):
out_parts = out.decode().split()
if len(out_parts) >= 3:
version_parts = [int(x) for x in out_parts[2].replace(self.LANGUAGE, "").split('.')]
if len(version_parts) == 3:
if len(version_parts) >= 2:
if version_parts[0] == expected_major_version and version_parts[1] >= min_expected_minor_version:
self._valid_runtime_path = runtime_path
return self._valid_runtime_path
Expand Down
10 changes: 3 additions & 7 deletions aws_lambda_builders/workflows/java_maven/DESIGN.md
Original file line number Diff line number Diff line change
Expand Up @@ -71,21 +71,17 @@ configured to use a different one than can be found on the PATH.

#### Step 3: Build and package

We leverage Maven to do all the heavy lifting for executing the`mvn package` which
We leverage Maven to do all the heavy lifting for executing the`mvn clean install` which
will resolve and download the dependencies and build the project. Built java classes
will be located in `target/classes`. Then we use `mvn dependency:copy-dependenceis` to copy
the dependencies and the dependencies will be located in `target/dependency` under the
source directory.

```bash
MODULE_NAME=$(mvn -q -Dexec.executable=echo -Dexec.args='${project.artifactId}' exec:exec --non-recursive)
mvn clean package -pl :MODULE_NAME -am
mvn dependency:copy-dependencies -DincludeScope=compile -pl :MODULE_NAME
mvn clean install
mvn dependency:copy-dependencies -DincludeScope=compile
```

Here `MODULE_NAME` is the `artifactId` defined in the pom.xml of the project. Maven
will build the dependencies of that project in the reactor and then build the project itself.

#### Step 4: Copy to artifact directory

Built Java classes and dependencies are copied from `scratch_dir/target/classes` and `scratch_dir/target/dependency`
Expand Down
17 changes: 2 additions & 15 deletions aws_lambda_builders/workflows/java_maven/actions.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,17 +20,6 @@ def __init__(self,
subprocess_maven):
self.scratch_dir = scratch_dir
self.subprocess_maven = subprocess_maven
self.artifact_id = None

@property
def module_name(self):
if self.artifact_id is None:
try:
self.artifact_id = self.subprocess_maven.retrieve_module_name(self.scratch_dir)
except MavenExecutionError as ex:
raise ActionFailedError(str(ex))

return self.artifact_id


class JavaMavenBuildAction(JavaMavenBaseAction, BaseAction):
Expand All @@ -48,8 +37,7 @@ def __init__(self,

def execute(self):
try:
self.subprocess_maven.build(self.scratch_dir,
self.module_name)
self.subprocess_maven.build(self.scratch_dir)
except MavenExecutionError as ex:
raise ActionFailedError(str(ex))

Expand All @@ -69,8 +57,7 @@ def __init__(self,

def execute(self):
try:
self.subprocess_maven.copy_dependency(self.scratch_dir,
self.module_name)
self.subprocess_maven.copy_dependency(self.scratch_dir)
except MavenExecutionError as ex:
raise ActionFailedError(str(ex))

Expand Down
25 changes: 9 additions & 16 deletions aws_lambda_builders/workflows/java_maven/maven.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,28 +25,21 @@ def __init__(self, maven_binary, os_utils=None):
raise ValueError("Must provide OSUtils")
self.os_utils = os_utils

def retrieve_module_name(self, scratch_dir):
args = ['-q', '-Dexec.executable=echo', '-Dexec.args=${project.artifactId}',
'exec:exec', '--non-recursive']
ret_code, stdout, stderr = self._run(args, scratch_dir)
if ret_code != 0:
raise MavenExecutionError(message=stderr.decode('utf8').strip())
return stdout.decode('utf8').strip()

def build(self, scratch_dir, module_name):
args = ['clean', 'install', '-pl', ':' + module_name, '-am']
ret_code, stdout, stderr = self._run(args, scratch_dir)
def build(self, scratch_dir):
args = ['clean', 'install']
ret_code, stdout, _ = self._run(args, scratch_dir)

LOG.debug("Maven logs: %s", stdout.decode('utf8').strip())

if ret_code != 0:
raise MavenExecutionError(message=stderr.decode('utf8').strip())
raise MavenExecutionError(message=stdout.decode('utf8').strip())

def copy_dependency(self, scratch_dir):
args = ['dependency:copy-dependencies', '-DincludeScope=compile']
ret_code, stdout, _ = self._run(args, scratch_dir)

def copy_dependency(self, scratch_dir, module_name):
args = ['dependency:copy-dependencies', '-DincludeScope=compile', '-pl', ':' + module_name]
ret_code, _, stderr = self._run(args, scratch_dir)
if ret_code != 0:
raise MavenExecutionError(message=stderr.decode('utf8').strip())
raise MavenExecutionError(message=stdout.decode('utf8').strip())

def _run(self, args, cwd=None):
p = self.os_utils.popen([self.maven_binary.binary_path] + args, cwd=cwd, stdout=subprocess.PIPE,
Expand Down
6 changes: 6 additions & 0 deletions tests/unit/workflows/go_modules/test_validator.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,12 @@ def test_runtime_validate_supported_version_runtime(self):
self.validator.validate(runtime_path="/usr/bin/go")
self.assertTrue(mock_subprocess.call_count, 1)

def test_runtime_validate_supported_higher_than_min_version_runtime(self):
with mock.patch("subprocess.Popen") as mock_subprocess:
mock_subprocess.return_value = MockSubProcess(0, out=b"go version go1.12 test")
self.validator.validate(runtime_path="/usr/bin/go")
self.assertTrue(mock_subprocess.call_count, 1)

def test_runtime_validate_mismatch_nonzero_exit(self):
with mock.patch("subprocess.Popen") as mock_subprocess:
mock_subprocess.return_value = MockSubProcess(1)
Expand Down
8 changes: 2 additions & 6 deletions tests/unit/workflows/java_maven/test_actions.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,14 +14,12 @@ def setUp(self, MockSubprocessMaven):
self.subprocess_maven = MockSubprocessMaven.return_value
self.scratch_dir = os.path.join('scratch_dir')
self.artifacts_dir = os.path.join('artifacts_dir')
self.module_name = "module"

def test_calls_maven_build(self):
self.subprocess_maven.retrieve_module_name.side_effect = lambda scratch: self.module_name
action = JavaMavenBuildAction(self.scratch_dir,
self.subprocess_maven)
action.execute()
self.subprocess_maven.build.assert_called_with(self.scratch_dir, self.module_name)
self.subprocess_maven.build.assert_called_with(self.scratch_dir)

def test_error_building_project_raises_action_error(self):
self.subprocess_maven.build.side_effect = MavenExecutionError(message='Build failed!')
Expand All @@ -39,14 +37,12 @@ def setUp(self, MockSubprocessMaven):
self.subprocess_maven = MockSubprocessMaven.return_value
self.scratch_dir = os.path.join('scratch_dir')
self.artifacts_dir = os.path.join('artifacts_dir')
self.module_name = 'module_name'

def test_calls_maven_copy_dependency(self):
self.subprocess_maven.retrieve_module_name.side_effect = lambda scratch: self.module_name
action = JavaMavenCopyDependencyAction(self.scratch_dir,
self.subprocess_maven)
action.execute()
self.subprocess_maven.copy_dependency.assert_called_with(self.scratch_dir, self.module_name)
self.subprocess_maven.copy_dependency.assert_called_with(self.scratch_dir)

def test_error_building_project_raises_action_error(self):
self.subprocess_maven.copy_dependency.side_effect = MavenExecutionError(message='Build failed!')
Expand Down
32 changes: 8 additions & 24 deletions tests/unit/workflows/java_maven/test_maven.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,48 +43,32 @@ def test_no_maven_exec_init_throws(self):
SubprocessMaven(None)
self.assertEquals(err_assert.exception.args[0], 'Must provide Maven BinaryPath')

def test_retrieve_module_name(self):
maven = SubprocessMaven(maven_binary=self.maven_binary, os_utils=self.os_utils)
maven.retrieve_module_name(self.source_dir)
self.os_utils.popen.assert_called_with(
[self.maven_path, '-q', '-Dexec.executable=echo', '-Dexec.args=${project.artifactId}',
'exec:exec', '--non-recursive'],
cwd=self.source_dir, stderr=subprocess.PIPE, stdout=subprocess.PIPE)

def test_retrieve_module_name_raises_exception_if_retcode_not_0(self):
self.popen = FakePopen(retcode=1, err=b'Some Error Message')
self.os_utils.popen.side_effect = [self.popen]
maven = SubprocessMaven(maven_binary=self.maven_binary, os_utils=self.os_utils)
with self.assertRaises(MavenExecutionError) as err:
maven.retrieve_module_name(self.source_dir)
self.assertEquals(err.exception.args[0], 'Maven Failed: Some Error Message')

def test_build_project(self):
maven = SubprocessMaven(maven_binary=self.maven_binary, os_utils=self.os_utils)
maven.build(self.source_dir, self.module_name)
maven.build(self.source_dir)
self.os_utils.popen.assert_called_with(
[self.maven_path, 'clean', 'install', '-pl', ':' + self.module_name, '-am'],
[self.maven_path, 'clean', 'install'],
cwd=self.source_dir, stderr=subprocess.PIPE, stdout=subprocess.PIPE)

def test_build_raises_exception_if_retcode_not_0(self):
self.popen = FakePopen(retcode=1, err=b'Some Error Message')
self.popen = FakePopen(retcode=1, out=b'Some Error Message')
self.os_utils.popen.side_effect = [self.popen]
maven = SubprocessMaven(maven_binary=self.maven_binary, os_utils=self.os_utils)
with self.assertRaises(MavenExecutionError) as err:
maven.build(self.source_dir, self.module_name)
maven.build(self.source_dir)
self.assertEquals(err.exception.args[0], 'Maven Failed: Some Error Message')

def test_copy_dependency(self):
maven = SubprocessMaven(maven_binary=self.maven_binary, os_utils=self.os_utils)
maven.copy_dependency(self.source_dir, self.module_name)
maven.copy_dependency(self.source_dir)
self.os_utils.popen.assert_called_with(
[self.maven_path, 'dependency:copy-dependencies', '-DincludeScope=compile', '-pl', ':' + self.module_name],
[self.maven_path, 'dependency:copy-dependencies', '-DincludeScope=compile'],
cwd=self.source_dir, stderr=subprocess.PIPE, stdout=subprocess.PIPE)

def test_copy_dependency_raises_exception_if_retcode_not_0(self):
self.popen = FakePopen(retcode=1, err=b'Some Error Message')
self.popen = FakePopen(retcode=1, out=b'Some Error Message')
self.os_utils.popen.side_effect = [self.popen]
maven = SubprocessMaven(maven_binary=self.maven_binary, os_utils=self.os_utils)
with self.assertRaises(MavenExecutionError) as err:
maven.copy_dependency(self.source_dir, self.module_name)
maven.copy_dependency(self.source_dir)
self.assertEquals(err.exception.args[0], 'Maven Failed: Some Error Message')

0 comments on commit 7151aaa

Please sign in to comment.