<commit_before>package org.openbakery

import org.apache.commons.configuration.plist.XMLPropertyListConfiguration
import org.apache.commons.io.FileUtils
import org.gradle.api.Project
import org.gradle.testfixtures.ProjectBuilder
import org.openbakery.testdouble.PlistHelperStub
import org.openbakery.xcode.Type
import spock.lang.Specification

class XcodeBuildArchiveTaskOSXSpecification extends Specification {

	Project project

	XcodeBuildArchiveTask xcodeBuildArchiveTask;

	File projectDir
	File buildOutputDirectory
	File appDirectory

	CommandRunner commandRunner = Mock(CommandRunner)

	def setup() {
		projectDir = new File(System.getProperty("java.io.tmpdir"), "gradle-xcodebuild")
		project = ProjectBuilder.builder().withProjectDir(projectDir).build()
		project.buildDir = new File(projectDir, 'build').absoluteFile
		project.apply plugin: org.openbakery.XcodePlugin
		project.xcodebuild.infoPlist = 'Info.plist'
		project.xcodebuild.productName = 'Example'
		project.xcodebuild.productType = 'app'
		project.xcodebuild.type = Type.macOS
		project.xcodebuild.signing.keychain = "/var/tmp/gradle.keychain"
		project.xcodebuild.signing.identity = "my identity"

		xcodeBuildArchiveTask = project.getTasks().getByPath(XcodePlugin.ARCHIVE_TASK_NAME)
		xcodeBuildArchiveTask.commandRunner = commandRunner
		xcodeBuildArchiveTask.parameters.type = Type.macOS

		buildOutputDirectory = new File(project.xcodebuild.symRoot, project.xcodebuild.configuration)
		buildOutputDirectory.mkdirs()

		appDirectory = new File(buildOutputDirectory, "Example.app")
		appDirectory.mkdirs()

		File infoPlist = new File("../example/OSX/ExampleOSX/ExampleOSX/Info.plist")
		FileUtils.copyFile(infoPlist, new File(appDirectory, "" + "Contents/Info.plist"))
	}


	def cleanup() {
		FileUtils.deleteDirectory(projectDir)
	}


	def "copyOSXApp"() {
		when:
		xcodeBuildArchiveTask.archive()

		File appFile = new File(projectDir, "build/archive/Example.xcarchive/Products/Applications/Example.app")

		then:
		appFile.exists()

	}

	def "createInfoPlist"() {
		given:

		project.xcodebuild.signing.identity = "iPhone Developer: <NAME> (AAAAAAAAAA)"

		when:
		xcodeBuildArchiveTask.archive()

		File infoPlist = new File(projectDir, "build/archive/Example.xcarchive/Info.plist")

		XMLPropertyListConfiguration config = new XMLPropertyListConfiguration(infoPlist)

		then:
		infoPlist.exists()
		config.getString("ApplicationProperties.ApplicationPath") == "Applications/Example.app"
		config.getString("ApplicationProperties.CFBundleIdentifier") == "com.cocoanetics.ExampleOSX"
		config.getString("ApplicationProperties.CFBundleShortVersionString") == "1.0"
		config.getString("ApplicationProperties.CFBundleVersion") == "1"
		config.getString("ApplicationProperties.SigningIdentity") == "iPhone Developer: <NAME> (AAAAAAAAAA)"
		config.getString("Name") == "Example"
		config.getString("SchemeName") == "Example"

	}

	def "get Icon Path OSX"() {
		given:
		xcodeBuildArchiveTask.parameters = project.xcodebuild.xcodebuildParameters
		// Info.plist from Example.app
		File infoPlistInAppFile = new File(projectDir, "/build/sym/Debug/Example.app/Contents/Info.plist")

		// add key CFBundleIconFile
		xcodeBuildArchiveTask.plistHelper.setValueForPlist(infoPlistInAppFile, "CFBundleIconFile", "icon")

		when:
		def macOSXIcons = xcodeBuildArchiveTask.getMacOSXIcons()

		then:
		macOSXIcons.size() == 1
		macOSXIcons.get(0) == "Applications/Example.app/Contents/Resources/icon.icns"
	}<commit_msg>fixed unit test<commit_after>package org.openbakery

import org.apache.commons.configuration.plist.XMLPropertyListConfiguration
import org.apache.commons.io.FileUtils
import org.gradle.api.Project
import org.gradle.testfixtures.ProjectBuilder
import org.openbakery.testdouble.PlistHelperStub
import org.openbakery.xcode.Type
import spock.lang.Specification

class XcodeBuildArchiveTaskOSXSpecification extends Specification {

	Project project

	XcodeBuildArchiveTask xcodeBuildArchiveTask;

	File projectDir
	File buildOutputDirectory
	File appDirectory

	CommandRunner commandRunner = Mock(CommandRunner)

	def setup() {
		projectDir = new File(System.getProperty("java.io.tmpdir"), "gradle-xcodebuild")
		project = ProjectBuilder.builder().withProjectDir(projectDir).build()
		project.buildDir = new File(projectDir, 'build').absoluteFile
		project.apply plugin: org.openbakery.XcodePlugin
		project.xcodebuild.infoPlist = 'Info.plist'
		project.xcodebuild.productName = 'Example'
		project.xcodebuild.productType = 'app'
		project.xcodebuild.type = Type.macOS
		project.xcodebuild.signing.keychain = "/var/tmp/gradle.keychain"
		project.xcodebuild.signing.identity = "my <PASSWORD>"

		xcodeBuildArchiveTask = project.getTasks().getByPath(XcodePlugin.ARCHIVE_TASK_NAME)
		xcodeBuildArchiveTask.commandRunner = commandRunner
		xcodeBuildArchiveTask.parameters.type = Type.macOS

		buildOutputDirectory = new File(project.xcodebuild.symRoot, project.xcodebuild.configuration)
		buildOutputDirectory.mkdirs()

		appDirectory = new File(buildOutputDirectory, "Example.app")
		appDirectory.mkdirs()

		File infoPlist = new File("../example/OSX/ExampleOSX/ExampleOSX/Info.plist")
		FileUtils.copyFile(infoPlist, new File(appDirectory, "" + "Contents/Info.plist"))
	}


	def cleanup() {
		FileUtils.deleteDirectory(projectDir)
	}


	def "copyOSXApp"() {
		when:
		xcodeBuildArchiveTask.archive()

		File appFile = new File(projectDir, "build/archive/Example.xcarchive/Products/Applications/Example.app")

		then:
		appFile.exists()

	}

	def "createInfoPlist"() {
		given:

		project.xcodebuild.signing.identity = "iPhone Developer: <NAME> (AAAAAAAAAA)"

		when:
		xcodeBuildArchiveTask.archive()

		File infoPlist = new File(projectDir, "build/archive/Example.xcarchive/Info.plist")

		XMLPropertyListConfiguration config = new XMLPropertyListConfiguration(infoPlist)

		then:
		infoPlist.exists()
		config.getString("ApplicationProperties.ApplicationPath") == "Applications/Example.app"
		config.getString("ApplicationProperties.CFBundleIdentifier") == "\$(PRODUCT_BUNDLE_IDENTIFIER)"
		config.getString("ApplicationProperties.CFBundleShortVersionString") == "1.0"
		config.getString("ApplicationProperties.CFBundleVersion") == "1"
		config.getString("ApplicationProperties.SigningIdentity") == "iPhone Developer: <NAME> (AAAAAAAAAA)"
		config.getString("Name") == "Example"
		config.getString("SchemeName") == "Example"

	}

	def "get Icon Path OSX"() {
		given:
		xcodeBuildArchiveTask.parameters = project.xcodebuild.xcodebuildParameters
		// Info.plist from Example.app
		File infoPlistInAppFile = new File(projectDir, "/build/sym/Debug/Example.app/Contents/Info.plist")

		// add key CFBundleIconFile
		xcodeBuildArchiveTask.plistHelper.setValueForPlist(infoPlistInAppFile, "CFBundleIconFile", "icon")

		when:
		def macOSXIcons = xcodeBuildArchiveTask.getMacOSXIcons()

		then:
		macOSXIcons.size() == 1
		macOSXIcons.get(0) == "Applications/Example.app/Contents/Resources/icon.icns"
	}
{'fraction_non_alphanumeric': 0.11154121863799284, 'fraction_numerical': 0.0014336917562724014, 'mean_word_length': 5.866141732283465, 'pattern_counts': {'":': 0, '<': 8, '<?xml version=': 0, '>': 8, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 4, 'word_list_counts': {'cursed_substrings.json': 4, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3406651', 'n_tokens_mistral': 2344, 'n_tokens_neox': 2113, 'n_words': 338}