Skip to content

Commit

Permalink
#58: handle executable flag properly
Browse files Browse the repository at this point in the history
  • Loading branch information
ypujante committed Jun 30, 2013
1 parent 3388304 commit cc361fc
Show file tree
Hide file tree
Showing 6 changed files with 23 additions and 1 deletion.
Empty file.
Empty file.
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,8 @@ import org.pongasoft.glu.packaging.setup.PackagerContext
import org.pongasoft.glu.provisioner.core.metamodel.GluMetaModel
import org.pongasoft.glu.provisioner.core.metamodel.impl.builder.GluMetaModelBuilder

import java.nio.file.Files

/**
* @author yan@pongasoft.com */
public abstract class BasePackagerTest extends GroovyTestCase
Expand Down Expand Up @@ -107,7 +109,7 @@ public abstract class BasePackagerTest extends GroovyTestCase

protected File getTestModelFile()
{
new File('../org.linkedin.glu.packaging-all/src/cmdline/resources/conf/tutorial/glu-meta-model.json.groovy').canonicalFile
new File('../org.linkedin.glu.packaging-all/src/cmdline/resources/models/tutorial/glu-meta-model.json.groovy').canonicalFile
}

protected File getConfigsRoot()
Expand Down Expand Up @@ -181,6 +183,9 @@ public abstract class BasePackagerTest extends GroovyTestCase
rootShell.sha1(expectedValue.resource), rootShell.sha1(r))
else
assertEquals("mismatch content for ${r}", expectedValue, r.file.text)

if(r.path.endsWith('.sh'))
assertTrue("${r} is executable", Files.isExecutable(r.file.toPath()))
}
}
catch(AssertionFailedError ex)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,8 @@ public class TestAgentServerPackager extends BasePackagerTest

shell.saveContent(inputPackage.createRelative('version.txt'), GLU_VERSION)
shell.saveContent(inputPackage.createRelative("${GLU_VERSION}/lib/acme.jar"), "this is the jar")
def shellScript = shell.saveContent(inputPackage.createRelative("${GLU_VERSION}/bin/acme.sh"), "this is the shell script")
shell.chmodPlusX(shellScript) // make executable

def packager = new AgentServerPackager(packagerContext: createPackagerContext(shell),
outputFolder: shell.mkdirs('/out'),
Expand All @@ -51,6 +53,8 @@ public class TestAgentServerPackager extends BasePackagerTest
[
'/version.txt': GLU_VERSION,
"/${GLU_VERSION}": DIRECTORY,
"/${GLU_VERSION}/bin": DIRECTORY,
"/${GLU_VERSION}/bin/acme.sh": "this is the shell script",
"/${GLU_VERSION}/lib": DIRECTORY,
"/${GLU_VERSION}/lib/acme.jar": 'this is the jar',
"/${GLU_VERSION}/conf": DIRECTORY,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1095,6 +1095,9 @@ def class ShellImpl implements Shell
break
}

if(Files.isExecutable(templateResource.file.toPath()))
chmodPlusX(toResource)

return toResource
}
catch(Throwable th)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -620,12 +620,22 @@ line 3 abcdef
def p1 = shell.processTemplate(t1, '/out1/foo', [token1: 'foo', token2: 'bar'])
assertEquals('/out1/foo', p1.path)
assertEquals('abc foo efg bar hij foo', shell.cat(p1))
assertFalse(Files.isExecutable(p1.file.toPath()))

shell.mkdirs('/out')
// in an existing dir
def p2 = shell.processTemplate(t1, '/out', [token1: 'foo', token2: 'bar'])
assertEquals('/out/foo', p2.path)
assertEquals('abc foo efg bar hij foo', shell.cat(p2))
assertFalse(Files.isExecutable(p2.file.toPath()))

// make it executable
shell.chmodPlusX(t1)

def p1x = shell.processTemplate(t1, '/out1x/foo', [token1: 'foo', token2: 'bar'])
assertEquals('/out1x/foo', p1x.path)
assertEquals('abc foo efg bar hij foo', shell.cat(p1x))
assertTrue(Files.isExecutable(p1x.file.toPath()))

// .gtmpl
def t2 = shell.saveContent(templates.createRelative('/foo.gtmpl'),
Expand Down

0 comments on commit cc361fc

Please sign in to comment.