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

Declare list of files in nuspec programatically #7

Closed
dustinstanley opened this issue Jan 22, 2015 · 2 comments
Closed

Declare list of files in nuspec programatically #7

dustinstanley opened this issue Jan 22, 2015 · 2 comments

Comments

@dustinstanley
Copy link

Is this behavior supported? I'd like to automatically declare all files in a specific directory without having to list each specific one, e.g.

    delegate.files {
        fileTree(msbuild.destinationDir).each { File entry ->
            delegate.file(src: entry, target: 'lib')
        }
    }

When I do this, I get the error below. Using delegate.file on the same files outside the above closure works fine, however.

Caused by: org.gradle.internal.typeconversion.UnsupportedNotationException: Cannot convert the provided notation to a File or URI: {src=build\msbuild\bin\log4net.dll, target=lib}.
The following types/formats are supported:

  • A String or CharSequence path, e.g 'src/main/java' or '/usr/include'
  • A String or CharSequence URI, e.g 'file:/usr/include'
  • A File instance.
  • A URI or URL instance.
    at org.gradle.internal.typeconversion.ErrorHandlingNotationParser.parseNotation(ErrorHandlingNotationParser.java:55)
    at org.gradle.api.internal.file.AbstractFileResolver.convertObjectToFile(AbstractFileResolver.java:184)
    at org.gradle.api.internal.file.BaseDirFileResolver.doResolve(BaseDirFileResolver.java:69)
    at org.gradle.api.internal.file.AbstractFileResolver.resolve(AbstractFileResolver.java:77)
    at org.gradle.api.internal.file.AbstractFileResolver.resolve(AbstractFileResolver.java:60)
    at org.gradle.api.internal.file.DefaultFileOperations.file(DefaultFileOperations.java:72)
    at org.gradle.api.internal.project.AbstractProject.file(AbstractProject.java:637)
    at org.gradle.groovy.scripts.DefaultScript.file(DefaultScript.java:110)
@gluck
Copy link
Contributor

gluck commented Jan 23, 2015

delegate is an implicit variable scoped to the current closure.

Writing:

nuspec { delegate.foo() }

is the same as

nuspec { foo() }

but being explicit about the fact that you want to use the method resolving on the XMLBuilder (that is the XML building DSL).

This is needed as gradle scripts already define some methods (file/files) that'll be called otherwise as they're part of any script scope.

In your case as you got out of the XMLBuilder closure (you're in the each) closure, the XMLBuilder delegate is no longer available and your stack show that you use Script.file instead of XMLBuilder.file.

Try this instead:

delegate.files {
    def filesXmlNode = delegate;
    fileTree(msbuild.destinationDir).each { File entry ->
        filesXmlNode.file(src: entry, target: 'lib')
    }
}

Should work I think.

@dustinstanley
Copy link
Author

Thanks for the explanation! That worked nicely. I will close this issue.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants