bmuschko / gradle-cargo-plugin

Gradle plugin that provides deployment capabilities to local and remote containers via Cargo
Apache License 2.0
258 stars 61 forks source link

Wrong path resolution in local/file closure #80

Closed vvursT closed 10 years ago

vvursT commented 10 years ago

I'm using the file closure inside local to deploy additional libraries to my container instance. My reference is your description

To add binary file(s) you should use file closure(s) instead:

cargo {
    containerId = 'glassfish3x'

    local {
        file {
            file = file('../config/db/mysql-connector-java-5.1.23-bin.jar')
            toDir = file('lib')
        }
    }
}

As i use maven dependencies my cargo configuration looks like this

dependencies {
    cargo "mylib:mylib:1.0.0"
}

def findDependency(name) {
    def filtered = configurations.cargo.filter { it.name.startsWith(name) }
    filtered.singleFile
}

cargo {
    containerId = 'tomcat6x'
    local {
        homeDir = file("$buildDir/install/tomcat-installation")
        configHomeDir = file("$buildDir/install/tomcat-home")

        file {
           file = file(findDependency("mylib"))
           toDir = file('lib')
       }
   }
}

My intention is to put the 3rd party library into the tomcat 'lib' dir but im ending up having a file copy error:

> org.codehaus.cargo.util.CargoException: Failed to copy source file [<pathtogradlecache>\mylib\mylib\1.0.0\xxx\mylib-1.0.0.jar] to [<pathToConfigHomeDir>/<absolutePathToProject>/mylib-1.0.0.jar]

So the given toDir path is prefixed by the configHomeDir-Path. As is searched through your code i'm not sure if this is an gradle-cargo-plugin or an cargo-ant issue.

bmuschko commented 10 years ago

This is something that the Cargo library is doing. My plugin is just passing through the values to the Ant task. I'd ask about this on the Cargo mailing list.

vvursT commented 10 years ago

Yes i suspected that. Thank you for bothering! Meanwhile my workaround will be to use a prepared tomcat installation.

pgaschuetz commented 10 years ago

I was struggling with the same issue today as well. The behaviour seems to be as per Cargos spec.

To get this working with gradle-cargo-plugin, just prepend "/" to the toDir file() ie

  toDir = file('/lib')
bmuschko commented 10 years ago

If you use the file method, Gradle creates a path relative to the project (except if it is an absolute path). This is not a feature added by the plugin. @vvursT Does this answer your question? If yes, please close the issue.

bmuschko commented 10 years ago

Seems like this question was answered.

vvursT commented 10 years ago

Hey guys,

sorry for my late answer and thanks for the fast feedback. But i'm still having trouble with that issue.

@pgaschuetz I did that but the only effect that i have is that every file path i'm configuring is prepended by the given "configHomeDir" from the cargo configuration. Can you send my a bigger snippet of your whole cargo configuration. Maybe i can figure out the differences.

@bmuschko again thanks for your fast response. i upgraded all the given libraries to the suggested and still having this issue:

gradle: 1.11 org.gradle.api.plugins:gradle-cargo-plugin:1.4 org.codehaus.cargo:cargo-core-uberjar:1.4.5 org.codehaus.cargo:cargo-ant:1.4.5

You are right. file creates a path like you described. But as i said, this path is always prepended by the configured configHomeDir from the cargo config. Even if this isn't configured the default value is prepended. I'm with you saying must be a gradle or cargo-ant issue but i can't manage to figure out the real problem.

Maybe you have the time to send me your working example code. Sorry for your inconvenience.

Hey guys,

sorry for my late answer and thanks for the fast feedback. But i'm still having trouble with that issue.

@pgaschuetz I did that but the only effect that i have is that every file path i'm configuring is prepended by the given configHomeDir from the cargo configuration. Can you send my a bigger snippet of your whole cargo configuration. Maybe i can figure out the differences.

@bmuschko again thanks for your fast response. i upgraded all the given libraries to the suggested and still having this issue:

gradle:1.11
org.gradle.api.plugins:gradle-cargo-plugin:1.4
org.codehaus.cargo:cargo-core-uberjar:1.4.5
org.codehaus.cargo:cargo-ant:1.4.5

You are right. file creates a path like you described. But as i said, this path is always prepended by the configured configHomeDir from the cargo config. Even if this isn't configured the default value is prepended. I'm with you saying must be a gradle or cargo-ant issue but i can't manage to figure out the real problem.

At least i figured out, that i made a fault pasting my example code. The file closure is inside the local closure.

Maybe you have the time to send me your working example code. Sorry for your inconvenience.

pgaschuetz commented 10 years ago

Hi,

I think I misunderstood your original question, but in any case, here is an excerpt:

apply plugin: 'cargo'
dependencies {
    def cargoVersion = '1.4.7'
    cargo "org.codehaus.cargo:cargo-core-uberjar:$cargoVersion"
    cargo "org.codehaus.cargo:cargo-ant:$cargoVersion"
}

def wildflyDownloadDir = file("${System.properties['user.home']}/.cargo/download")
def wildflyConfigHomeDir = file("$buildDir/cargoconfig")
def wildflyHomeDir = file("${System.properties['user.home']}/.cargo/extract")

cargo {
    containerId = 'wildfly8x'
    port = 9090

    local { 
        installer {
            installUrl = "http://download.jboss.org/wildfly/8.0.0.Final/wildfly-8.0.0.Final.zip"
            downloadDir = wildflyDownloadDir
            extractDir = wildflyHomeDir
        }

        configHomeDir = wildflyConfigHomeDir
        configFile {
            file = file("src/cargo/resources/configuration/standalone.xml")
            toDir = file('/configuration')
        }
    }
}

However, in order to deploy libraries to your containers lib directory, you may want to look at the extraClasspath option instead of copying them to the containers lib directory:

configurations {
  cargoruntime
}

dependencies {
  cargoruntime 'org.postgresql:postgresql:9.3-1100-jdbc41'
}

cargo {
  ...
  local {
    ...
    extraClasspath = configurations.cargoruntime
  }
}

Hope this helps.

vvursT commented 10 years ago

Hi,

First of all: my initial problem is solved. The extraClasspath configuration did the trick. Thank you!

At least the problem not being able to copy file with the configFile closure still occurs, because the absolute configDirPath is prepended. No idea where it comes from. Can you tell me what cargo plugin version you are using?