Skip to content

Commit

Permalink
Add a gradle property com.fidesmo.gradle.javacard.home to take preced…
Browse files Browse the repository at this point in the history
…ence over the JC_HOME environment variable in setting the path to Java card SDK.
  • Loading branch information
minkyn committed Dec 21, 2016
1 parent a4fb552 commit 137c312
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 6 deletions.
16 changes: 10 additions & 6 deletions src/main/groovy/com/fidesmo/gradle/javacard/JavacardPlugin.groovy
Expand Up @@ -26,13 +26,17 @@ import com.fidesmo.gradle.javacard.ConvertJavacardTask

class JavacardPlugin implements Plugin<Project> {

static def getJavacardHomeUnchecked(Project project) {
project.properties['com.fidesmo.gradle.javacard.home'] ?: System.env['JC_HOME']
}

static def getJavacardHome(Project project) {
def javacardHome = System.env['JC_HOME']
def javacardHome = getJavacardHomeUnchecked(project)

if (!javacardHome) {
throw new InvalidUserDataException('JC_HOME must be set in order to use javacard plugin')
throw new InvalidUserDataException('Java card home must be set in order to use javacard plugin')
} else if(! project.file(javacardHome).isDirectory()) {
throw new InvalidUserDataException('JC_HOME must point to a valid directory')
throw new InvalidUserDataException('Java card home must point to a valid directory')
}

javacardHome
Expand All @@ -59,10 +63,10 @@ class JavacardPlugin implements Plugin<Project> {
it.name == 'jcardsim'
}

// check if JC_HOME is not set and if jcardsim was available and in that case use jcardsim api
// check if Java card home is not set and if jcardsim was available and in that case use jcardsim api
// this is used to run tests and compile if no javacard sdk is available (e.g ci systems)
if (jcardsim != null && System.env['JC_HOME'] == null) {
project.logger.info('Using jcardsim as replacement for JC_HOME/lib/api.jar, due to missing JC_HOME.')
if (jcardsim != null && getJavacardHomeUnchecked(project) == null) {
project.logger.info('Using jcardsim as replacement for JC_HOME/lib/api.jar, due to missing Java card home.')
project.dependencies {
compile "com.licel:jcardsim:${jcardsim.version}"
}
Expand Down
5 changes: 5 additions & 0 deletions src/test/groovy/com/fidesmo/JavacardPluginTest.groovy
Expand Up @@ -43,6 +43,11 @@ class JavacardPluginTest {
project.apply plugin: 'javacard'
}

@Test void checkJavacardHomeSetupWithGradleProperties() {
project.ext['com.fidesmo.gradle.javacard.home'] = '..'
def plugin = project.getPlugins().findPlugin('javacard')
assertThat(plugin.getJavacardHome(project), equalTo('..'))
}

@Test void checkJavacardHomeSetup() {
def plugin = project.getPlugins().findPlugin('javacard')
Expand Down

0 comments on commit 137c312

Please sign in to comment.