Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
6 changes: 3 additions & 3 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
<modelVersion>4.0.0</modelVersion>
<groupId>software.amazon.cloudformation</groupId>
<artifactId>aws-cloudformation-rpdk-java-plugin</artifactId>
<version>1.0.5</version>
<version>2.0.0</version>
<name>AWS CloudFormation RPDK Java Plugin</name>
<description>The CloudFormation Resource Provider Development Kit (RPDK) allows you to author your own resource providers that can be used by CloudFormation. This plugin library helps to provide runtime bindings for the execution of your providers by CloudFormation.
</description>
Expand Down Expand Up @@ -307,12 +307,12 @@
<limit>
<counter>BRANCH</counter>
<value>COVEREDRATIO</value>
<minimum>0.80</minimum>
<minimum>0.79</minimum>
</limit>
<limit>
<counter>INSTRUCTION</counter>
<value>COVEREDRATIO</value>
<minimum>0.87</minimum>
<minimum>0.89</minimum>
</limit>
</limits>
</rule>
Expand Down
2 changes: 1 addition & 1 deletion python/rpdk/java/__init__.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import logging

__version__ = "0.1.6"
__version__ = "2.0.0"

logging.getLogger(__name__).addHandler(logging.NullHandler())
62 changes: 61 additions & 1 deletion python/rpdk/java/codegen.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,9 @@
# pylint doesn't recognize abstract methods
import logging
import shutil
import xml.etree.ElementTree as ET # nosec
from collections import namedtuple
from xml.etree.ElementTree import ParseError # nosec

from rpdk.core.data_loaders import resource_stream
from rpdk.core.exceptions import InternalError, SysExitRecommendedError
Expand Down Expand Up @@ -37,10 +39,29 @@ def wrapper(*args, **kwargs):
return wrapper


DEFAULT_PROTOCOL_VERSION = "2.0.0"
PROTOCOL_VERSION_SETTING = "protocolVersion"
DEFAULT_SETTINGS = {PROTOCOL_VERSION_SETTING: DEFAULT_PROTOCOL_VERSION}

MINIMUM_JAVA_DEPENDENCY_VERSION = "2.0.0"


class JavaArchiveNotFoundError(SysExitRecommendedError):
pass


class JavaPluginVersionNotSupportedError(SysExitRecommendedError):
pass


class JavaPluginNotFoundError(SysExitRecommendedError):
pass


class InvalidMavenPOMError(SysExitRecommendedError):
pass


class JavaLanguagePlugin(LanguagePlugin):
MODULE_NAME = __name__
RUNTIME = "java8"
Expand All @@ -66,7 +87,7 @@ def _namespace_from_project(self, project):
fallback = ("com",) + project.type_info
namespace = tuple(safe_reserved(s.lower()) for s in fallback)
self.namespace = project.settings["namespace"] = namespace
project._write_settings("java") # pylint: disable=protected-access
project.write_settings()

self.package_name = ".".join(self.namespace)

Expand Down Expand Up @@ -283,6 +304,7 @@ def _init_settings(self, project):
project.runtime = self.RUNTIME
project.entrypoint = self.ENTRY_POINT.format(self.package_name)
project.test_entrypoint = self.TEST_ENTRY_POINT.format(self.package_name)
project.settings.update(DEFAULT_SETTINGS)

@staticmethod
def _get_generated_root(project):
Expand Down Expand Up @@ -377,6 +399,24 @@ def generate(self, project):
)
project.overwrite(path, contents)

# Update settings
java_plugin_dependency_version = self._get_java_plugin_dependency_version(
project
)
if java_plugin_dependency_version < MINIMUM_JAVA_DEPENDENCY_VERSION:
raise JavaPluginVersionNotSupportedError(
"'aws-cloudformation-rpdk-java-plugin' {} is no longer supported."
"Please update it in pom.xml to version {} or above.".format(
java_plugin_dependency_version, MINIMUM_JAVA_DEPENDENCY_VERSION
)
)
protocol_version = project.settings.get(PROTOCOL_VERSION_SETTING)
if protocol_version != DEFAULT_PROTOCOL_VERSION:
project.settings[PROTOCOL_VERSION_SETTING] = DEFAULT_PROTOCOL_VERSION
project.write_settings()

LOG.debug("Generate complete")

@staticmethod
def _find_jar(project):
jar_glob = list(
Expand All @@ -399,6 +439,26 @@ def _find_jar(project):

return jar_glob[0]

@staticmethod
def _get_java_plugin_dependency_version(project):
try:
tree = ET.parse(project.root / "pom.xml")
root = tree.getroot()
namespace = {"mvn": "http://maven.apache.org/POM/4.0.0"}
plugin_dependency_version = root.find(
"./mvn:dependencies/mvn:dependency"
"/[mvn:artifactId='aws-cloudformation-rpdk-java-plugin']/mvn:version",
namespace,
)
if plugin_dependency_version is None:
raise JavaPluginNotFoundError(
"'aws-cloudformation-rpdk-java-plugin' maven dependency "
"not found in pom.xml."
)
return plugin_dependency_version.text
except ParseError:
raise InvalidMavenPOMError("pom.xml is invalid.")

@logdebug
def package(self, project, zip_file):
"""Packaging Java project"""
Expand Down
2 changes: 1 addition & 1 deletion python/rpdk/java/templates/init/shared/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
<dependency>
<groupId>software.amazon.cloudformation</groupId>
<artifactId>aws-cloudformation-rpdk-java-plugin</artifactId>
<version>1.0.5</version>
<version>2.0.0</version>
</dependency>
<!-- https://mvnrepository.com/artifact/org.projectlombok/lombok -->
<dependency>
Expand Down
Loading