Skip to content

Commit

Permalink
Revert "CycleFinderTask and TranslateTask Unit Tests"
Browse files Browse the repository at this point in the history
This reverts commit 9331f5a.
  • Loading branch information
brunobowden committed Jun 29, 2015
1 parent fc66add commit 480e8cf
Show file tree
Hide file tree
Showing 8 changed files with 33 additions and 447 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ These are the main tasks for the plugin:
j2objcXcode - Configure Xcode to link to static library and header files

Note that you can use the Gradle shorthand of "$ gradlew jA" to do the j2objcAssemble task.
The other shorthand expressions are `jCF`, `jTr`, `jA`, `jTe`, `jB` and `jX`.
The other shorthand expressions are `jC`, `jTr`, `jA`, `jTe`, `jB` and `jX`.


#### Task Enable and Disable
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,16 +16,13 @@

package com.github.j2objccontrib.j2objcgradle.tasks

import com.google.common.annotations.VisibleForTesting
import org.gradle.api.DefaultTask
import org.gradle.api.Project
import org.gradle.api.file.FileCollection
import org.gradle.api.tasks.Input
import org.gradle.api.tasks.InputFiles
import org.gradle.api.tasks.Optional
import org.gradle.api.tasks.OutputFile
import org.gradle.api.tasks.TaskAction
import org.gradle.process.internal.ExecException

/**
* CycleFinder task checks for memory cycles that can cause memory leaks
Expand Down Expand Up @@ -73,7 +70,7 @@ class CycleFinderTask extends DefaultTask {
int getCycleFinderExpectedCycles() { return project.j2objcConfig.cycleFinderExpectedCycles }

@Input
String getJ2objcHome() { return Utils.j2objcHome(project) }
String getJ2ObjCHome() { return Utils.j2objcHome(project) }

@Input
@Optional
Expand All @@ -97,18 +94,13 @@ class CycleFinderTask extends DefaultTask {

@TaskAction
void cycleFinder() {
cycleFinderWithExec(project)
}

@VisibleForTesting
void cycleFinderWithExec(Project projectExec) {

String cycleFinderExec = "${getJ2objcHome()}/cycle_finder"
String cycleFinderExec = "${getJ2ObjCHome()}/cycle_finder"
List<String> windowsOnlyArgs = new ArrayList<String>()
if (Utils.isWindows()) {
cycleFinderExec = 'java'
windowsOnlyArgs.add('-jar')
windowsOnlyArgs.add("${getJ2objcHome()}/lib/cycle_finder.jar")
windowsOnlyArgs.add("${getJ2ObjCHome()}/lib/cycle_finder.jar")
}

String sourcepath = Utils.sourcepathJava(project)
Expand All @@ -129,27 +121,22 @@ class CycleFinderTask extends DefaultTask {
}

String classPathArg = Utils.getClassPathArg(
project, getJ2objcHome(), getTranslateClassPaths(), getTranslateJ2objcLibs())
project, getJ2ObjCHome(), getTranslateClassPaths(), getTranslateJ2objcLibs())

ByteArrayOutputStream output = new ByteArrayOutputStream()
try {
// Might be injected project, otherwise project.exec {...}
projectExec.exec {
project.exec {
executable cycleFinderExec
windowsOnlyArgs.each { String windowsOnlyArg ->
args windowsOnlyArg
}

// Arguments
args windowsOnlyArgs
args "-sourcepath", sourcepath

if (classPathArg.size() > 0) {
args "-classpath", classPathArg
}
getCycleFinderArgs().each { String cycleFinderArg ->
args cycleFinderArg
}

// File Inputs
args getCycleFinderArgs()

fullSrcFiles.each { File file ->
args file.path
}
Expand All @@ -161,17 +148,15 @@ class CycleFinderTask extends DefaultTask {
logger.debug "CycleFinder found 0 cycles"
assert 0 == getCycleFinderExpectedCycles()


} catch (ExecException exception) {
// Expected exception for non-zero exit of process
} catch (Exception exception) {

String outputStr = output.toString()
// matchNumberRegex throws exception if regex isn't found
int cyclesFound = Utils.matchNumberRegex(outputStr, /(\d+) CYCLES FOUND/)
if (cyclesFound != getCycleFinderExpectedCycles()) {
logger.error outputStr
String message =
"Unexpected number of cycles found:\n" +
"Unexpected number of cycles founder:\n" +
"Expected Cycles: ${getCycleFinderExpectedCycles()}\n" +
"Actual Cycles: $cyclesFound\n" +
"\n" +
Expand All @@ -180,7 +165,7 @@ class CycleFinderTask extends DefaultTask {
"j2objcConfig {\n" +
" cycleFinderExpectedCycles $cyclesFound\n" +
"}\n"
throw new IllegalArgumentException(message)
throw new Exception(message)
}
// Suppress exception when cycles found == cycleFinderExpectedCycles
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,8 @@

package com.github.j2objccontrib.j2objcgradle.tasks

import com.google.common.annotations.VisibleForTesting
import org.gradle.api.Action
import org.gradle.api.DefaultTask
import org.gradle.api.Project
import org.gradle.api.file.FileCollection
import org.gradle.api.tasks.Input
import org.gradle.api.tasks.InputFiles
Expand All @@ -28,7 +26,6 @@ import org.gradle.api.tasks.OutputDirectory
import org.gradle.api.tasks.TaskAction
import org.gradle.api.tasks.incremental.IncrementalTaskInputs
import org.gradle.api.tasks.incremental.InputFileDetails
import org.gradle.process.internal.ExecException

/**
* Translation task for Java to Objective-C using j2objc tool.
Expand Down Expand Up @@ -82,7 +79,7 @@ class TranslateTask extends DefaultTask {

// j2objcConfig dependencies for UP-TO-DATE checks
@Input
String getJ2objcHome() { return Utils.j2objcHome(project) }
String getJ2ObjCHome() { return Utils.j2objcHome(project) }

@Input
List<String> getTranslateArgs() { return project.j2objcConfig.translateArgs }
Expand All @@ -104,11 +101,6 @@ class TranslateTask extends DefaultTask {

@TaskAction
void translate(IncrementalTaskInputs inputs) {
translateWithExec(project, inputs)
}

@VisibleForTesting
void translateWithExec(Project projectExec, IncrementalTaskInputs inputs) {
List<String> translateArgs = getTranslateArgs()
// Don't evaluate this expensive property multiple times.
FileCollection originalSrcFiles = getSrcFiles()
Expand Down Expand Up @@ -213,12 +205,12 @@ class TranslateTask extends DefaultTask {
}
}

String j2objcExecutable = "${getJ2objcHome()}/j2objc"
String j2objcExecutable = "${getJ2ObjCHome()}/j2objc"
List<String> windowsOnlyArgs = new ArrayList<String>()
if (Utils.isWindows()) {
j2objcExecutable = 'java'
windowsOnlyArgs.add('-jar')
windowsOnlyArgs.add("${getJ2objcHome()}/lib/j2objc.jar")
windowsOnlyArgs.add("${getJ2ObjCHome()}/lib/j2objc.jar")
}

String sourcepath = Utils.sourcepathJava(project)
Expand All @@ -238,38 +230,33 @@ class TranslateTask extends DefaultTask {
}

String classPathArg = Utils.getClassPathArg(
project, getJ2objcHome(), getTranslateClassPaths(), getTranslateJ2objcLibs())
project, getJ2ObjCHome(), getTranslateClassPaths(), getTranslateJ2objcLibs())

classPathArg += ":${project.buildDir}/classes"

ByteArrayOutputStream output = new ByteArrayOutputStream()
try {
projectExec.exec {
project.exec {
executable j2objcExecutable
windowsOnlyArgs.each { String windowsArg ->
args windowsOnlyArg
}

// Arguments
args windowsOnlyArgs
args "-d", srcGenDir
args "-sourcepath", sourcepath

if (classPathArg.size() > 0) {
args "-classpath", classPathArg
}
translateArgs.each { String translateArg ->
args translateArg
}

// File Inputs
args translateArgs

srcFilesChanged.each { File file ->
args file.path
}

standardOutput output
errorOutput output
}

} catch (ExecException exception) {
} catch (Exception exception) {
String outputStr = output.toString()
logger.debug 'Translation output:'
logger.debug outputStr
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ class Utils {
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)
}
Expand Down Expand Up @@ -69,8 +70,8 @@ class Utils {
return javaRoots.join(':')
}

// MUST be used only in @Input getJ2objcHome() methods to ensure UP-TO-DATE checks are correct
// @Input getJ2objcHome() method can be used freely inside the task action
// MUST be used only in @Input getJ2ObjCHome() methods to ensure UP-TO-DATE checks are correct
// @Input getJ2ObjCHome() method can be used freely inside the task action
static String j2objcHome(Project proj) {
File localPropertiesFile = new File(proj.rootDir, 'local.properties')
String result = null
Expand Down Expand Up @@ -212,16 +213,16 @@ class Utils {
Matcher matcher = (str =~ regex)
if (!matcher.find()) {
throw new IllegalArgumentException(
"Content:\n" +
"$str\n" +
"Regex couldn't match number: $regex")
"\n" +
"Regex couldn't match number in output: $regex")
} else {
String value = matcher[0][1]
if (!value.isInteger()) {
throw new IllegalArgumentException(
"Content:\n" +
"$str\n" +
"Regex couldn't match number: $regex")
"\n" +
"Regex didn't find number in output: $regex, value: $value")
}
return value.toInteger()
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ class XcodeTask extends DefaultTask {

// j2objcConfig dependencies for UP-TO-DATE checks
@Input
String getJ2objcHome() { return Utils.j2objcHome(project) }
String getJ2ObjCHome() { return Utils.j2objcHome(project) }

@Input @Optional
String getXcodeProjectDir() { return project.j2objcConfig.xcodeProjectDir }
Expand Down Expand Up @@ -106,8 +106,8 @@ class XcodeTask extends DefaultTask {
"s.requires_arc = true\n" +
"s.preserve_paths = '${srcGenDirRelativeToBuildDir}**/*.a'\n" +
"s.libraries = 'ObjC', 'guava', 'javax_inject', 'jre_emul', 'jsr305', 'z', 'icucore', '${project.name}-j2objc'\n" +
"s.xcconfig = { 'HEADER_SEARCH_PATHS' => '${getJ2objcHome()}/include', " +
"'LIBRARY_SEARCH_PATHS' => '${getJ2objcHome()}/lib ${project.buildDir}/j2objcOutputs/lib/iosDebug' }\n" +
"s.xcconfig = { 'HEADER_SEARCH_PATHS' => '${getJ2ObjCHome()}/include', " +
"'LIBRARY_SEARCH_PATHS' => '${getJ2ObjCHome()}/lib ${project.buildDir}/j2objcOutputs/lib/iosDebug' }\n" +
"end\n"
logger.debug 'podspecFileContents creation...\n\n' + podspecFileContents
File podspecFile = getPodspecFile()
Expand Down
Loading

0 comments on commit 480e8cf

Please sign in to comment.