Skip to content

Commit

Permalink
Add property logFile to AbstractPaketTask
Browse files Browse the repository at this point in the history
Allows to set the logoutput for paket tasks to a designated file.
  • Loading branch information
Larusso committed Jul 24, 2017
1 parent 694a78a commit f554d31
Show file tree
Hide file tree
Showing 8 changed files with 147 additions and 23 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -37,4 +37,88 @@ abstract class PaketIntegrationDependencyFileSpec extends PaketIntegrationBaseSp
where:
taskToRun << bootstrapTestCases
}

@Unroll
def "writes paket output to logfile when running #taskToRun"(String taskToRun) {
given: "a paket dependency file"
createFile("paket.dependencies")

and: "a empty lock file"
createFile("paket.lock")

and: "the log file"
def logFile = new File(projectDir, "build/logs/${taskToRun}.log")
assert !logFile.exists()

when:
runTasksSuccessfully(taskToRun)

then:
logFile.exists()

where:
taskToRun << bootstrapTestCases
}

@Unroll
def "can set alternate logout path in task configuration when running #taskToRun"(String taskToRun) {
given: "a paket dependency file"
createFile("paket.dependencies")

and: "a empty lock file"
createFile("paket.lock")

and: "the log file"
def logFile = new File(projectDir, "build/mylogs/${taskToRun}.log")
assert !logFile.exists()

and: "the changed log location"
buildFile << """
project.afterEvaluate {
project.tasks.getByName("${taskToRun}") {
logFile = "${logFile.path.replace('\\', '/')}"
}
}
""".stripIndent()

when:
runTasksSuccessfully(taskToRun)

then:
logFile.exists()

where:
taskToRun << bootstrapTestCases
}

@Unroll
def "can set alternate logout path in task configuration as method when running #taskToRun"(String taskToRun) {
given: "a paket dependency file"
createFile("paket.dependencies")

and: "a empty lock file"
createFile("paket.lock")

and: "the log file"
def logFile = new File(projectDir, "build/mylogs/${taskToRun}.log")
assert !logFile.exists()

and: "the changed log location"
buildFile << """
project.afterEvaluate {
project.tasks.getByName("${taskToRun}") {
logFile("${logFile.path.replace('\\', '/')}")
}
}
""".stripIndent()

when:
runTasksSuccessfully(taskToRun)

then:
logFile.exists()

where:
taskToRun << bootstrapTestCases
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -86,10 +86,4 @@ class PaketInstallIntegrationSpec extends PaketIntegrationDependencyFileSpec {
where:
taskToRun << bootstrapTestCases
}

@Ignore
@Unroll
def "Increment task #taskToRun"(String taskToRun) {

}
}
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,8 @@

package wooga.gradle.paket.pack

import org.gradle.api.file.FileTree
import spock.lang.Unroll
import wooga.gradle.paket.PaketIntegrationDependencyFileSpec
import wooga.gradle.paket.pack.tasks.PaketPack

class PaketPackIntegrationSpec extends PaketIntegrationDependencyFileSpec {

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,10 @@ import org.jfrog.artifactory.client.ArtifactoryClient
import org.jfrog.artifactory.client.model.RepoPath
import spock.lang.Shared
import spock.lang.Unroll
import wooga.gradle.paket.PaketIntegrationDependencyFileSpec
import wooga.gradle.paket.pack.PaketPackPlugin

class PaketPublishIntegrationSpec extends IntegrationSpec {
class PaketPublishIntegrationSpec extends PaketIntegrationDependencyFileSpec {

def paketTemplateFile

Expand Down Expand Up @@ -56,6 +57,11 @@ class PaketPublishIntegrationSpec extends IntegrationSpec {
@Shared
Artifactory artifactory

@Override
Object getBootstrapTestCases() {
["publish-${packageIdToName(packageID)}", "publish${repoName.capitalize()}-${packageIdToName(packageID)}"]
}

def artifactoryRepoName = "atlas-nuget-integrationTest"
def repoUrl = "$artifactoryUrl/api/nuget/atlas-nuget-integrationTest"

Expand Down Expand Up @@ -103,9 +109,6 @@ class PaketPublishIntegrationSpec extends IntegrationSpec {
Empty nuget package.
""".stripIndent()

createFile("paket.lock")
createFile("paket.dependencies")

cleanupArtifactory(artifactoryRepoName,packageName)
}

Expand Down Expand Up @@ -142,6 +145,10 @@ class PaketPublishIntegrationSpec extends IntegrationSpec {
def nugetArtifact = new File(new File(new File(projectDir, 'build'), "outputs"), packageName)
assert !nugetArtifact.exists()

and: "paket.dependencies and paket.lock file"
createFile("paket.lock")
createFile("paket.dependencies")

when: "run the publish task"
def result = runTasksSuccessfully(taskToRun)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,33 +19,35 @@ package wooga.gradle.paket.base.tasks

import org.gradle.api.DefaultTask
import org.gradle.api.GradleException
import org.gradle.api.GradleScriptException
import org.gradle.api.file.FileCollection
import org.gradle.api.internal.ConventionTask
import org.gradle.api.logging.Logger
import org.gradle.api.logging.Logging
import org.gradle.api.tasks.*
import org.gradle.api.tasks.incremental.IncrementalTaskInputs
import org.gradle.internal.Factory
import org.gradle.internal.file.PathToFileResolver
import org.gradle.tooling.exceptions.UnsupportedOperationConfigurationException
import wooga.gradle.paket.base.PaketPluginExtension

import javax.inject.Inject
import java.util.concurrent.Callable

abstract class AbstractPaketTask<T extends AbstractPaketTask> extends DefaultTask {
abstract class AbstractPaketTask<T extends AbstractPaketTask> extends ConventionTask {
static Logger logger = Logging.getLogger(AbstractPaketTask)

private final Class<T> taskType;
private final Class<T> taskType

@Inject
protected PathToFileResolver getFileResolver() {
throw new UnsupportedOperationConfigurationException("file resolver not configured")
}

@SkipWhenEmpty
@InputFiles
FileCollection paketDependencies = project.fileTree(dir: project.projectDir, include: "paket.dependencies")


// {
// project.projectDir.listFiles().find { it.path == "$project.projectDir/paket.dependencies" }
// }

// def getPaketDependencies() {
// project.files(paketDependencies)
// }

@Internal
def stdOut = new ByteArrayOutputStream()

Expand All @@ -60,6 +62,32 @@ abstract class AbstractPaketTask<T extends AbstractPaketTask> extends DefaultTas
this.taskType = taskType
}

@Internal
Boolean supportLogfile = true

private Factory<File> logFile

@Optional
@Internal
@Input
File getLogFile() {
if(logFile)
{
return logFile.create()
}
return null
}

AbstractPaketTask setLogFile(Object file) {
logFile = fileResolver.resolveLater(file)
return this
}

AbstractPaketTask logFile(Object file) {
logFile = fileResolver.resolveLater(file)
return this
}

String executable

String getExecutable() {
Expand Down Expand Up @@ -109,6 +137,15 @@ abstract class AbstractPaketTask<T extends AbstractPaketTask> extends DefaultTas
paketArgs << paketCommand
}

if (!logFile) {
this.setLogFile("${project.buildDir}/logs/${name}.log")
}

if (supportLogfile) {
paketArgs << "--verbose"
paketArgs << "--log-file" << getLogFile().path
}

paketArgs += args

logger.debug("Execute command {}", paketArgs.join(" "))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,10 +33,12 @@ class PaketBootstrap extends AbstractPaketTask {
@Inject
PaketBootstrap() {
super(PaketBootstrap.class)
supportLogfile = false
}

PaketBootstrap(Class<AbstractPaketTask> taskType) {
super(taskType)
supportLogfile = false
}

def outputDir
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ class PaketUnityBootstrap extends PaketBootstrap {

PaketUnityBootstrap() {
super(PaketUnityBootstrap.class)
supportLogfile = false
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,5 +37,6 @@ class PaketUnityInstall extends AbstractPaketTask {
group = PaketUnityPlugin.GROUP
paketCommand = COMMAND
outputs.upToDateWhen {false}
supportLogfile = false
}
}

0 comments on commit f554d31

Please sign in to comment.