Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

CopyAppDependenciesTask to copy just the changed dependencies #24

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -16,27 +16,61 @@
package no.tornado.fxlauncher.gradle

import org.gradle.api.DefaultTask
import org.gradle.api.file.FileCollection
import org.gradle.api.tasks.InputFiles
import org.gradle.api.tasks.OutputDirectory
import org.gradle.api.tasks.TaskAction
import org.gradle.api.tasks.incremental.IncrementalTaskInputs

/**
* @author Andres Almiray
*/
public class CopyAppDependenciesTask extends DefaultTask {
@InputFiles
FileCollection dependencies
@OutputDirectory
File directoryToCopyTo


@TaskAction
void copyDependencies() {
File workingDirectory = project.extensions.fxlauncher.resolveWorkingDirectory()
if (!workingDirectory.exists()) workingDirectory.mkdirs()
project.configurations.runtime.resolvedConfiguration.resolvedArtifacts.each { artifact ->
void copyDependencies(IncrementalTaskInputs inputs) {
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The IncrementalTaskInputs, is a way, according to the documentation, to check if each input has changed, and only deal with the changed ones.


if (!directoryToCopyTo.exists()) directoryToCopyTo.mkdirs()

println inputs.incremental ? 'incremental' : 'not incremental'


if (!inputs.incremental)
project.delete(directoryToCopyTo.listFiles())

inputs.outOfDate { artifact ->
if (artifact.file.directory) return

println "Copying ${artifact.file.name} to ${directoryToCopyTo.name}"

project.copy {
from artifact.file
into workingDirectory
into directoryToCopyTo
if (artifact.classifier != null) {
rename { "${artifact.name}-${artifact.classifier}.${artifact.extension}" }
} else {
rename { "${artifact.name}.${artifact.extension}" }
}
}

}

inputs.removed { change ->
if (change.file.directory) return

println "Removing ${change.file.name} from ${directoryToCopyTo.name}"
def targetFile = new File(directoryToCopyTo, change.file.name)
targetFile.delete()
}



// TODO: Do we need to add these as @Inputs, too?
project.copy {
from project.tasks.jar.archivePath
into workingDirectory
Expand All @@ -47,5 +81,6 @@ public class CopyAppDependenciesTask extends DefaultTask {
into workingDirectory
}
}

}
}
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,11 @@ class FXLauncherPlugin implements Plugin<Project> {
type: CopyAppDependenciesTask,
group: 'FXLauncher',
description: 'Copies all application runtime dependencies into working directory',
dependsOn: project.tasks.jar
dependsOn: project.tasks.jar,
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@aalmiray, maybe you can leave one of those newfangled suggestions on how to do this the right way?

{
dependencies = project.configurations.runtime.resolvedConfiguration.resolvedArtifacts
directoryToCopyTo = project.extensions.fxlauncher.resolveWorkingDirectory()
}
)

project.task('generateApplicationManifest',
Expand Down