diff --git a/README.md b/README.md index 133cc8bd..71674ae8 100644 --- a/README.md +++ b/README.md @@ -38,9 +38,10 @@ Tracked issue: https://github.com/j2objc-contrib/j2objc-gradle/issues/130** xcodeProjectDir "${projectDir}/../ios" // Xcode workspace directory xcodeTarget "IosApp" // Xcode application target name - // More: https://github.com/j2objc-contrib/j2objc-gradle/blob/master/src/main/groovy/com/github/j2objccontrib/j2objcgradle/J2objcPluginExtension.groovy#L25 + // Help information on other settings: + // https://github.com/j2objc-contrib/j2objc-gradle/blob/master/src/main/groovy/com/github/j2objccontrib/j2objcgradle/J2objcPluginExtension.groovy#L25 - // You must include this call (at the end of the block) even if you do not configure any other settings. + // You must include this call (at the end of j2objcConfig) regardless of settings finalConfigure() } diff --git a/src/main/groovy/com/github/j2objccontrib/j2objcgradle/J2objcPlugin.groovy b/src/main/groovy/com/github/j2objccontrib/j2objcgradle/J2objcPlugin.groovy index d5ad5129..6af6ad8e 100644 --- a/src/main/groovy/com/github/j2objccontrib/j2objcgradle/J2objcPlugin.groovy +++ b/src/main/groovy/com/github/j2objccontrib/j2objcgradle/J2objcPlugin.groovy @@ -37,21 +37,16 @@ class J2objcPlugin implements Plugin { void apply(Project project) { // This avoids a lot of "project." prefixes, such as "project.tasks.create" project.with { - if (!plugins.hasPlugin('java')) { - def message = - "j2objc plugin didn't find the 'java' plugin in the '${project.name}' project.\n"+ - "This is a requirement for using j2objc. Please see usage information at:\n" + - "\n" + - "https://github.com/j2objc-contrib/j2objc-gradle/#usage" - throw new InvalidUserDataException(message) - } - extensions.create('j2objcConfig', J2objcPluginExtension, project) + afterEvaluate { evaluatedProject -> + // Validate minimally required parameters. // j2objcHome() will throw the appropriate exception internally. assert J2objcUtils.j2objcHome(evaluatedProject) + J2objcUtils.throwIfNoJavaPlugin(evaluatedProject) + if (!evaluatedProject.j2objcConfig.isFinalConfigured()) { def message = "You must call finalConfigure() in j2objcConfig, ex:\n" + "j2objcConfig {\n" + diff --git a/src/main/groovy/com/github/j2objccontrib/j2objcgradle/tasks/J2objcUtils.groovy b/src/main/groovy/com/github/j2objccontrib/j2objcgradle/tasks/J2objcUtils.groovy index fc536453..54cf6c3e 100644 --- a/src/main/groovy/com/github/j2objccontrib/j2objcgradle/tasks/J2objcUtils.groovy +++ b/src/main/groovy/com/github/j2objccontrib/j2objcgradle/tasks/J2objcUtils.groovy @@ -40,8 +40,21 @@ class J2objcUtils { return System.getProperty('os.name').toLowerCase().contains('windows') } + static void throwIfNoJavaPlugin(Project proj) { + if (!proj.plugins.hasPlugin('java')) { + String message = + "j2objc plugin didn't find the 'java' plugin in the '${proj.name}' project.\n" + + "This is a requirement for using j2objc. Please see usage information at:\n" + + "\n" + + "https://github.com/j2objc-contrib/j2objc-gradle/#usage" + throw new InvalidUserDataException(message) + } + } + // Retrieves the configured source directories from the Java plugin SourceSets. static SourceDirectorySet srcDirs(Project proj, String sourceSetName, String fileType) { + throwIfNoJavaPlugin(proj) + assert fileType == 'java' || fileType == 'resources' assert sourceSetName == 'main' || sourceSetName == 'test' SourceSet sourceSet = proj.sourceSets.findByName(sourceSetName) diff --git a/src/test/groovy/com/github/j2objccontrib/j2objcgradle/tasks/J2objcUtilsTest.groovy b/src/test/groovy/com/github/j2objccontrib/j2objcgradle/tasks/J2objcUtilsTest.groovy index dc4c5040..a97b8e54 100644 --- a/src/test/groovy/com/github/j2objccontrib/j2objcgradle/tasks/J2objcUtilsTest.groovy +++ b/src/test/groovy/com/github/j2objccontrib/j2objcgradle/tasks/J2objcUtilsTest.groovy @@ -42,6 +42,13 @@ public class J2objcUtilsTest { J2objcUtils.isWindows() } + @Test(expected = InvalidUserDataException.class) + public void testThrowIfNoJavaPlugin_NoJavaPlugin() { + J2objcUtils.throwIfNoJavaPlugin(proj) + } + + // TODO: testThrowIfNoJavaPlugin_JavaPluginExists + // TODO: testSrcDirs() - requires 'java' plugin // TODO: testSourcepathJava() - requires 'java' plugin