-
Notifications
You must be signed in to change notification settings - Fork 319
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fix custom open and close token not applied to FilteredFile.
- Loading branch information
1 parent
ab3424c
commit df87db8
Showing
8 changed files
with
127 additions
and
15 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -214,7 +214,7 @@ public void visit(TarArchiveEntry entry, byte[] content) throws IOException { | |
if (entry.getName().equals("./control")) { | ||
try { | ||
ControlFile controlFile = new BinaryPackageControlFile(org.apache.commons.io.IOUtils.toString(new ByteArrayInputStream(content), StandardCharsets.UTF_8)); | ||
assertEquals("the encoding is wrong", controlFile.get("Maintainer"), "ジョン Doe <[email protected]>"); | ||
assertEquals("the encoding is wrong", "ジョン Doe <[email protected]>", controlFile.get("Maintainer")); | ||
} catch(Exception e) { | ||
throw new IOException(e); | ||
} | ||
|
@@ -256,6 +256,77 @@ else if (entry.getName().equals("./text.txt")) { | |
}); | ||
} | ||
|
||
@Test | ||
public void testCreationCustomToken() throws Exception { | ||
DataProducer[] data = prepareData(); | ||
File deb = File.createTempFile("jdeb", ".deb"); | ||
|
||
File conffile = new File(getClass().getResource("deb/data.tgz").toURI()); | ||
|
||
Map<String, String> map = new HashMap<>(); | ||
map.put("name", "actualName"); | ||
map.put("version", "actualVersion"); | ||
map.put("maintainer", "John Doe <[email protected]>"); | ||
MapVariableResolver variableResolver = new MapVariableResolver(map); | ||
|
||
Data conffile1 = new Data(); | ||
conffile1.setType("file"); | ||
conffile1.setSrc(conffile); | ||
conffile1.setDst("/absolute/path/to/configuration"); | ||
conffile1.setConffile(true); | ||
Data conffile2 = new Data(); | ||
conffile2.setType("file"); | ||
conffile2.setSrc(conffile); | ||
conffile2.setConffile(true); | ||
|
||
Mapper mapper = new Mapper(); | ||
FieldUtils.writeField(mapper, "type", "perm", true); | ||
FieldUtils.writeField(mapper, "prefix", "/absolute/prefix", true); | ||
FieldUtils.writeField(conffile2, "mapper", mapper, true); | ||
|
||
DebMaker maker = | ||
new DebMaker(new NullConsole(), Arrays.asList(data), Arrays.<DataProducer>asList(conffile1, conffile2)); | ||
maker.setEncoding(StandardCharsets.UTF_8); | ||
maker.setControl(new File(getClass().getResource("deb/controlcustomtoken").toURI())); | ||
maker.setDeb(deb); | ||
maker.setResolver(variableResolver); | ||
maker.setOpenReplaceToken("{[{"); | ||
maker.setCloseReplaceToken("}]}"); | ||
|
||
BinaryPackageControlFile packageControlFile = maker.createDeb(Compression.GZIP); | ||
|
||
assertTrue(packageControlFile.isValid()); | ||
|
||
final Map<String, TarArchiveEntry> filesInDeb = new HashMap<>(); | ||
|
||
final Set<String> actualConffileContent = new HashSet<>(); | ||
|
||
ArchiveWalker.walkControl(deb, new ArchiveVisitor<TarArchiveEntry>() { | ||
@Override | ||
public void visit(TarArchiveEntry entry, byte[] content) throws IOException { | ||
if (entry.getName().equals("./control")) { | ||
try { | ||
ControlFile controlFile = new BinaryPackageControlFile(org.apache.commons.io.IOUtils.toString(new ByteArrayInputStream(content), StandardCharsets.UTF_8)); | ||
assertEquals("variable substitution failed", "John Doe <[email protected]>", controlFile.get("Maintainer")); | ||
} catch(Exception e) { | ||
throw new IOException(e); | ||
} | ||
} | ||
else if (entry.getName().equals("./postinst") || entry.getName().equals("./prerm")) { | ||
try { | ||
for(String line : org.apache.commons.io.IOUtils.readLines(new ByteArrayInputStream(content), StandardCharsets.UTF_8)) { | ||
if(line.startsWith("# P")) { | ||
assertTrue("variable substitution failed", line.endsWith("actualName actualVersion")); | ||
} | ||
} | ||
} catch(Exception e) { | ||
throw new IOException(e); | ||
} | ||
} | ||
} | ||
}); | ||
} | ||
|
||
@Test | ||
public void testControlFilesPermissions() throws Exception { | ||
File deb = new File("target/test-classes/test-control.deb"); | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
13 changes: 13 additions & 0 deletions
13
src/test/resources/org/vafer/jdeb/deb/controlcustomtoken/control
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
Package: test | ||
Version: 1.0.1 | ||
Section: misc | ||
Priority: optional | ||
Architecture: i386 | ||
Depends: some-package | ||
Maintainer: {[{maintainer}]} | ||
Distribution: development | ||
Description: revision @REVISION@, test package | ||
This is a sample package control file. | ||
. | ||
Use for testing purposes only. | ||
XB-UserDefinedField: This is a user defined field. |
4 changes: 4 additions & 0 deletions
4
src/test/resources/org/vafer/jdeb/deb/controlcustomtoken/postinst
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
#!/bin/sh | ||
# | ||
# Post installation script for {[{name}]} {[{version}]} | ||
# |
4 changes: 4 additions & 0 deletions
4
src/test/resources/org/vafer/jdeb/deb/controlcustomtoken/prerm
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
#!/bin/sh | ||
# | ||
# Pre removal script for {[{name}]} {[{version}]} | ||
# |