You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

IgnoreNodeTest.java 17KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552
  1. /*
  2. * Copyright (C) 2010, Red Hat Inc.
  3. * and other copyright owners as documented in the project's IP log.
  4. *
  5. * This program and the accompanying materials are made available
  6. * under the terms of the Eclipse Distribution License v1.0 which
  7. * accompanies this distribution, is reproduced below, and is
  8. * available at http://www.eclipse.org/org/documents/edl-v10.php
  9. *
  10. * All rights reserved.
  11. *
  12. * Redistribution and use in source and binary forms, with or
  13. * without modification, are permitted provided that the following
  14. * conditions are met:
  15. *
  16. * - Redistributions of source code must retain the above copyright
  17. * notice, this list of conditions and the following disclaimer.
  18. *
  19. * - Redistributions in binary form must reproduce the above
  20. * copyright notice, this list of conditions and the following
  21. * disclaimer in the documentation and/or other materials provided
  22. * with the distribution.
  23. *
  24. * - Neither the name of the Eclipse Foundation, Inc. nor the
  25. * names of its contributors may be used to endorse or promote
  26. * products derived from this software without specific prior
  27. * written permission.
  28. *
  29. * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND
  30. * CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES,
  31. * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
  32. * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
  33. * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
  34. * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
  35. * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
  36. * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
  37. * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
  38. * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
  39. * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
  40. * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
  41. * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  42. */
  43. package org.eclipse.jgit.ignore;
  44. import static java.nio.charset.StandardCharsets.UTF_8;
  45. import static org.eclipse.jgit.junit.Assert.assertEquals;
  46. import static org.junit.Assert.assertEquals;
  47. import static org.junit.Assert.assertFalse;
  48. import static org.junit.Assert.assertNotNull;
  49. import static org.junit.Assert.assertTrue;
  50. import java.io.ByteArrayInputStream;
  51. import java.io.File;
  52. import java.io.IOException;
  53. import java.io.InputStream;
  54. import java.util.ArrayList;
  55. import java.util.Arrays;
  56. import org.eclipse.jgit.ignore.IgnoreNode.MatchResult;
  57. import org.eclipse.jgit.junit.RepositoryTestCase;
  58. import org.eclipse.jgit.lib.FileMode;
  59. import org.eclipse.jgit.treewalk.FileTreeIterator;
  60. import org.eclipse.jgit.treewalk.TreeWalk;
  61. import org.eclipse.jgit.treewalk.WorkingTreeIterator;
  62. import org.eclipse.jgit.util.FileUtils;
  63. import org.eclipse.jgit.util.SystemReader;
  64. import org.junit.Test;
  65. /**
  66. * Tests ignore node behavior on the local filesystem.
  67. */
  68. public class IgnoreNodeTest extends RepositoryTestCase {
  69. private static final FileMode D = FileMode.TREE;
  70. private static final FileMode F = FileMode.REGULAR_FILE;
  71. private static final boolean ignored = true;
  72. private static final boolean tracked = false;
  73. private TreeWalk walk;
  74. @Test
  75. public void testRules() throws IOException {
  76. writeIgnoreFile(".git/info/exclude", "*~", "/out");
  77. writeIgnoreFile(".gitignore", "*.o", "/config");
  78. writeTrashFile("config/secret", "");
  79. writeTrashFile("mylib.c", "");
  80. writeTrashFile("mylib.c~", "");
  81. writeTrashFile("mylib.o", "");
  82. writeTrashFile("out/object/foo.exe", "");
  83. writeIgnoreFile("src/config/.gitignore", "lex.out");
  84. writeTrashFile("src/config/lex.out", "");
  85. writeTrashFile("src/config/config.c", "");
  86. writeTrashFile("src/config/config.c~", "");
  87. writeTrashFile("src/config/old/lex.out", "");
  88. beginWalk();
  89. assertEntry(F, tracked, ".gitignore");
  90. assertEntry(D, ignored, "config");
  91. assertEntry(F, ignored, "config/secret");
  92. assertEntry(F, tracked, "mylib.c");
  93. assertEntry(F, ignored, "mylib.c~");
  94. assertEntry(F, ignored, "mylib.o");
  95. assertEntry(D, ignored, "out");
  96. assertEntry(D, ignored, "out/object");
  97. assertEntry(F, ignored, "out/object/foo.exe");
  98. assertEntry(D, tracked, "src");
  99. assertEntry(D, tracked, "src/config");
  100. assertEntry(F, tracked, "src/config/.gitignore");
  101. assertEntry(F, tracked, "src/config/config.c");
  102. assertEntry(F, ignored, "src/config/config.c~");
  103. assertEntry(F, ignored, "src/config/lex.out");
  104. assertEntry(D, tracked, "src/config/old");
  105. assertEntry(F, ignored, "src/config/old/lex.out");
  106. endWalk();
  107. }
  108. @Test
  109. public void testNegation() throws IOException {
  110. // ignore all *.o files and ignore all "d" directories
  111. writeIgnoreFile(".gitignore", "*.o", "d");
  112. // negate "ignore" for a/b/keep.o file only
  113. writeIgnoreFile("src/a/b/.gitignore", "!keep.o");
  114. writeTrashFile("src/a/b/keep.o", "");
  115. writeTrashFile("src/a/b/nothere.o", "");
  116. // negate "ignore" for "d"
  117. writeIgnoreFile("src/c/.gitignore", "!d");
  118. // negate "ignore" for c/d/keep.o file only
  119. writeIgnoreFile("src/c/d/.gitignore", "!keep.o");
  120. writeTrashFile("src/c/d/keep.o", "");
  121. writeTrashFile("src/c/d/nothere.o", "");
  122. beginWalk();
  123. assertEntry(F, tracked, ".gitignore");
  124. assertEntry(D, tracked, "src");
  125. assertEntry(D, tracked, "src/a");
  126. assertEntry(D, tracked, "src/a/b");
  127. assertEntry(F, tracked, "src/a/b/.gitignore");
  128. assertEntry(F, tracked, "src/a/b/keep.o");
  129. assertEntry(F, ignored, "src/a/b/nothere.o");
  130. assertEntry(D, tracked, "src/c");
  131. assertEntry(F, tracked, "src/c/.gitignore");
  132. assertEntry(D, tracked, "src/c/d");
  133. assertEntry(F, tracked, "src/c/d/.gitignore");
  134. assertEntry(F, tracked, "src/c/d/keep.o");
  135. // must be ignored: "!d" should not negate *both* "d" and *.o rules!
  136. assertEntry(F, ignored, "src/c/d/nothere.o");
  137. endWalk();
  138. }
  139. /*
  140. * See https://bugs.eclipse.org/bugs/show_bug.cgi?id=407475
  141. */
  142. @Test
  143. public void testNegateAllExceptJavaInSrc() throws IOException {
  144. // ignore all files except from src directory
  145. writeIgnoreFile(".gitignore", "/*", "!/src/");
  146. writeTrashFile("nothere.o", "");
  147. // ignore all files except java
  148. writeIgnoreFile("src/.gitignore", "*", "!*.java");
  149. writeTrashFile("src/keep.java", "");
  150. writeTrashFile("src/nothere.o", "");
  151. writeTrashFile("src/a/nothere.o", "");
  152. beginWalk();
  153. assertEntry(F, ignored, ".gitignore");
  154. assertEntry(F, ignored, "nothere.o");
  155. assertEntry(D, tracked, "src");
  156. assertEntry(F, ignored, "src/.gitignore");
  157. assertEntry(D, ignored, "src/a");
  158. assertEntry(F, ignored, "src/a/nothere.o");
  159. assertEntry(F, tracked, "src/keep.java");
  160. assertEntry(F, ignored, "src/nothere.o");
  161. endWalk();
  162. }
  163. /*
  164. * See https://bugs.eclipse.org/bugs/show_bug.cgi?id=407475
  165. */
  166. @Test
  167. public void testNegationAllExceptJavaInSrcAndExceptChildDirInSrc()
  168. throws IOException {
  169. // ignore all files except from src directory
  170. writeIgnoreFile(".gitignore", "/*", "!/src/");
  171. writeTrashFile("nothere.o", "");
  172. // ignore all files except java in src folder and all children folders.
  173. // Last ignore rule breaks old jgit via bug 407475
  174. writeIgnoreFile("src/.gitignore", "*", "!*.java", "!*/");
  175. writeTrashFile("src/keep.java", "");
  176. writeTrashFile("src/nothere.o", "");
  177. writeTrashFile("src/a/keep.java", "");
  178. writeTrashFile("src/a/keep.o", "");
  179. beginWalk();
  180. assertEntry(F, ignored, ".gitignore");
  181. assertEntry(F, ignored, "nothere.o");
  182. assertEntry(D, tracked, "src");
  183. assertEntry(F, ignored, "src/.gitignore");
  184. assertEntry(D, tracked, "src/a");
  185. assertEntry(F, tracked, "src/a/keep.java");
  186. assertEntry(F, tracked, "src/a/keep.o");
  187. assertEntry(F, tracked, "src/keep.java");
  188. assertEntry(F, ignored, "src/nothere.o");
  189. endWalk();
  190. }
  191. /*
  192. * See https://bugs.eclipse.org/bugs/show_bug.cgi?id=448094
  193. */
  194. @Test
  195. public void testRepeatedNegation() throws IOException {
  196. writeIgnoreFile(".gitignore", "e", "!e", "e", "!e", "e");
  197. writeTrashFile("e/nothere.o", "");
  198. beginWalk();
  199. assertEntry(F, tracked, ".gitignore");
  200. assertEntry(D, ignored, "e");
  201. assertEntry(F, ignored, "e/nothere.o");
  202. endWalk();
  203. }
  204. /*
  205. * See https://bugs.eclipse.org/bugs/show_bug.cgi?id=448094
  206. */
  207. @Test
  208. public void testRepeatedNegationInDifferentFiles1() throws IOException {
  209. writeIgnoreFile(".gitignore", "*.o", "e");
  210. writeIgnoreFile("e/.gitignore", "!e");
  211. writeTrashFile("e/nothere.o", "");
  212. beginWalk();
  213. assertEntry(F, tracked, ".gitignore");
  214. assertEntry(D, ignored, "e");
  215. assertEntry(F, ignored, "e/.gitignore");
  216. assertEntry(F, ignored, "e/nothere.o");
  217. endWalk();
  218. }
  219. /*
  220. * See https://bugs.eclipse.org/bugs/show_bug.cgi?id=448094
  221. */
  222. @Test
  223. public void testRepeatedNegationInDifferentFiles2() throws IOException {
  224. writeIgnoreFile(".gitignore", "*.o", "e");
  225. writeIgnoreFile("a/.gitignore", "!e");
  226. writeTrashFile("a/e/nothere.o", "");
  227. beginWalk();
  228. assertEntry(F, tracked, ".gitignore");
  229. assertEntry(D, tracked, "a");
  230. assertEntry(F, tracked, "a/.gitignore");
  231. assertEntry(D, tracked, "a/e");
  232. assertEntry(F, ignored, "a/e/nothere.o");
  233. endWalk();
  234. }
  235. /*
  236. * See https://bugs.eclipse.org/bugs/show_bug.cgi?id=448094
  237. */
  238. @Test
  239. public void testRepeatedNegationInDifferentFiles3() throws IOException {
  240. writeIgnoreFile(".gitignore", "*.o");
  241. writeIgnoreFile("a/.gitignore", "e");
  242. writeIgnoreFile("a/b/.gitignore", "!e");
  243. writeTrashFile("a/b/e/nothere.o", "");
  244. beginWalk();
  245. assertEntry(F, tracked, ".gitignore");
  246. assertEntry(D, tracked, "a");
  247. assertEntry(F, tracked, "a/.gitignore");
  248. assertEntry(D, tracked, "a/b");
  249. assertEntry(F, tracked, "a/b/.gitignore");
  250. assertEntry(D, tracked, "a/b/e");
  251. assertEntry(F, ignored, "a/b/e/nothere.o");
  252. endWalk();
  253. }
  254. @Test
  255. public void testRepeatedNegationInDifferentFiles4() throws IOException {
  256. writeIgnoreFile(".gitignore", "*.o");
  257. writeIgnoreFile("a/.gitignore", "e");
  258. // Rules are never empty: WorkingTreeIterator optimizes empty rules away
  259. // paranoia check in case this optimization will be removed
  260. writeIgnoreFile("a/b/.gitignore", "#");
  261. writeIgnoreFile("a/b/c/.gitignore", "!e");
  262. writeTrashFile("a/b/c/e/nothere.o", "");
  263. beginWalk();
  264. assertEntry(F, tracked, ".gitignore");
  265. assertEntry(D, tracked, "a");
  266. assertEntry(F, tracked, "a/.gitignore");
  267. assertEntry(D, tracked, "a/b");
  268. assertEntry(F, tracked, "a/b/.gitignore");
  269. assertEntry(D, tracked, "a/b/c");
  270. assertEntry(F, tracked, "a/b/c/.gitignore");
  271. assertEntry(D, tracked, "a/b/c/e");
  272. assertEntry(F, ignored, "a/b/c/e/nothere.o");
  273. endWalk();
  274. }
  275. @Test
  276. public void testEmptyIgnoreNode() {
  277. // Rules are never empty: WorkingTreeIterator optimizes empty files away
  278. // So we have to test it manually in case third party clients use
  279. // IgnoreNode directly.
  280. IgnoreNode node = new IgnoreNode();
  281. assertEquals(MatchResult.CHECK_PARENT, node.isIgnored("", false));
  282. assertEquals(MatchResult.CHECK_PARENT, node.isIgnored("", false, false));
  283. assertEquals(MatchResult.CHECK_PARENT_NEGATE_FIRST_MATCH,
  284. node.isIgnored("", false, true));
  285. }
  286. @Test
  287. public void testEmptyIgnoreRules() throws IOException {
  288. IgnoreNode node = new IgnoreNode();
  289. node.parse(writeToString("", "#", "!", "[[=a=]]"));
  290. assertEquals(new ArrayList<>(), node.getRules());
  291. node.parse(writeToString(" ", " / "));
  292. assertEquals(2, node.getRules().size());
  293. }
  294. @Test
  295. public void testSlashOnlyMatchesDirectory() throws IOException {
  296. writeIgnoreFile(".gitignore", "out/");
  297. writeTrashFile("out", "");
  298. beginWalk();
  299. assertEntry(F, tracked, ".gitignore");
  300. assertEntry(F, tracked, "out");
  301. FileUtils.delete(new File(trash, "out"));
  302. writeTrashFile("out/foo", "");
  303. beginWalk();
  304. assertEntry(F, tracked, ".gitignore");
  305. assertEntry(D, ignored, "out");
  306. assertEntry(F, ignored, "out/foo");
  307. endWalk();
  308. }
  309. @Test
  310. public void testSlashMatchesDirectory() throws IOException {
  311. writeIgnoreFile(".gitignore", "out2/");
  312. writeTrashFile("out1/out1", "");
  313. writeTrashFile("out1/out2", "");
  314. writeTrashFile("out2/out1", "");
  315. writeTrashFile("out2/out2", "");
  316. beginWalk();
  317. assertEntry(F, tracked, ".gitignore");
  318. assertEntry(D, tracked, "out1");
  319. assertEntry(F, tracked, "out1/out1");
  320. assertEntry(F, tracked, "out1/out2");
  321. assertEntry(D, ignored, "out2");
  322. assertEntry(F, ignored, "out2/out1");
  323. assertEntry(F, ignored, "out2/out2");
  324. endWalk();
  325. }
  326. @Test
  327. public void testWildcardWithSlashMatchesDirectory() throws IOException {
  328. writeIgnoreFile(".gitignore", "out2*/");
  329. writeTrashFile("out1/out1.txt", "");
  330. writeTrashFile("out1/out2", "");
  331. writeTrashFile("out1/out2.txt", "");
  332. writeTrashFile("out1/out2x/a", "");
  333. writeTrashFile("out2/out1.txt", "");
  334. writeTrashFile("out2/out2.txt", "");
  335. writeTrashFile("out2x/out1.txt", "");
  336. writeTrashFile("out2x/out2.txt", "");
  337. beginWalk();
  338. assertEntry(F, tracked, ".gitignore");
  339. assertEntry(D, tracked, "out1");
  340. assertEntry(F, tracked, "out1/out1.txt");
  341. assertEntry(F, tracked, "out1/out2");
  342. assertEntry(F, tracked, "out1/out2.txt");
  343. assertEntry(D, ignored, "out1/out2x");
  344. assertEntry(F, ignored, "out1/out2x/a");
  345. assertEntry(D, ignored, "out2");
  346. assertEntry(F, ignored, "out2/out1.txt");
  347. assertEntry(F, ignored, "out2/out2.txt");
  348. assertEntry(D, ignored, "out2x");
  349. assertEntry(F, ignored, "out2x/out1.txt");
  350. assertEntry(F, ignored, "out2x/out2.txt");
  351. endWalk();
  352. }
  353. @Test
  354. public void testWithSlashDoesNotMatchInSubDirectory() throws IOException {
  355. writeIgnoreFile(".gitignore", "a/b");
  356. writeTrashFile("a/a", "");
  357. writeTrashFile("a/b", "");
  358. writeTrashFile("src/a/a", "");
  359. writeTrashFile("src/a/b", "");
  360. beginWalk();
  361. assertEntry(F, tracked, ".gitignore");
  362. assertEntry(D, tracked, "a");
  363. assertEntry(F, tracked, "a/a");
  364. assertEntry(F, ignored, "a/b");
  365. assertEntry(D, tracked, "src");
  366. assertEntry(D, tracked, "src/a");
  367. assertEntry(F, tracked, "src/a/a");
  368. assertEntry(F, tracked, "src/a/b");
  369. endWalk();
  370. }
  371. @Test
  372. public void testNoPatterns() throws IOException {
  373. writeIgnoreFile(".gitignore", "", " ", "# comment", "/");
  374. writeTrashFile("a/a", "");
  375. beginWalk();
  376. assertEntry(F, tracked, ".gitignore");
  377. assertEntry(D, tracked, "a");
  378. assertEntry(F, tracked, "a/a");
  379. endWalk();
  380. }
  381. @Test
  382. public void testLeadingSpaces() throws IOException {
  383. writeTrashFile(" a/ a", "");
  384. writeTrashFile(" a/ a", "");
  385. writeTrashFile(" a/a", "");
  386. writeTrashFile(" a/ a", "");
  387. writeTrashFile(" a/ a", "");
  388. writeTrashFile(" a/a", "");
  389. writeIgnoreFile(".gitignore", " a", " a");
  390. writeTrashFile("a/ a", "");
  391. writeTrashFile("a/ a", "");
  392. writeTrashFile("a/a", "");
  393. beginWalk();
  394. assertEntry(D, ignored, " a");
  395. assertEntry(F, ignored, " a/ a");
  396. assertEntry(F, ignored, " a/ a");
  397. assertEntry(F, ignored, " a/a");
  398. assertEntry(D, ignored, " a");
  399. assertEntry(F, ignored, " a/ a");
  400. assertEntry(F, ignored, " a/ a");
  401. assertEntry(F, ignored, " a/a");
  402. assertEntry(F, tracked, ".gitignore");
  403. assertEntry(D, tracked, "a");
  404. assertEntry(F, ignored, "a/ a");
  405. assertEntry(F, ignored, "a/ a");
  406. assertEntry(F, tracked, "a/a");
  407. endWalk();
  408. }
  409. @Test
  410. public void testTrailingSpaces() throws IOException {
  411. // Windows can't create files with trailing spaces
  412. // If this assumption fails the test is halted and ignored.
  413. org.junit.Assume.assumeFalse(SystemReader.getInstance().isWindows());
  414. writeTrashFile("a /a", "");
  415. writeTrashFile("a /a ", "");
  416. writeTrashFile("a /a ", "");
  417. writeTrashFile("a /a", "");
  418. writeTrashFile("a /a ", "");
  419. writeTrashFile("a /a ", "");
  420. writeTrashFile("a/a", "");
  421. writeTrashFile("a/a ", "");
  422. writeTrashFile("a/a ", "");
  423. writeTrashFile("b/c", "");
  424. writeIgnoreFile(".gitignore", "a\\ ", "a \\ ", "b/ ");
  425. beginWalk();
  426. assertEntry(F, tracked, ".gitignore");
  427. assertEntry(D, ignored, "a ");
  428. assertEntry(F, ignored, "a /a");
  429. assertEntry(F, ignored, "a /a ");
  430. assertEntry(F, ignored, "a /a ");
  431. assertEntry(D, ignored, "a ");
  432. assertEntry(F, ignored, "a /a");
  433. assertEntry(F, ignored, "a /a ");
  434. assertEntry(F, ignored, "a /a ");
  435. assertEntry(D, tracked, "a");
  436. assertEntry(F, tracked, "a/a");
  437. assertEntry(F, ignored, "a/a ");
  438. assertEntry(F, ignored, "a/a ");
  439. assertEntry(D, ignored, "b");
  440. assertEntry(F, ignored, "b/c");
  441. endWalk();
  442. }
  443. @Test
  444. public void testToString() throws Exception {
  445. assertEquals(Arrays.asList("").toString(), new IgnoreNode().toString());
  446. assertEquals(Arrays.asList("hello").toString(),
  447. new IgnoreNode(Arrays.asList(new FastIgnoreRule("hello")))
  448. .toString());
  449. }
  450. private void beginWalk() {
  451. walk = new TreeWalk(db);
  452. walk.addTree(new FileTreeIterator(db));
  453. }
  454. private void endWalk() throws IOException {
  455. assertFalse("Not all files tested", walk.next());
  456. }
  457. private void assertEntry(FileMode type, boolean entryIgnored,
  458. String pathName) throws IOException {
  459. assertTrue("walk has entry", walk.next());
  460. assertEquals(pathName, walk.getPathString());
  461. assertEquals(type, walk.getFileMode(0));
  462. WorkingTreeIterator itr = walk.getTree(0, WorkingTreeIterator.class);
  463. assertNotNull("has tree", itr);
  464. assertEquals("is ignored", entryIgnored, itr.isEntryIgnored());
  465. if (D.equals(type))
  466. walk.enterSubtree();
  467. }
  468. private void writeIgnoreFile(String name, String... rules)
  469. throws IOException {
  470. StringBuilder data = new StringBuilder();
  471. for (String line : rules)
  472. data.append(line + "\n");
  473. writeTrashFile(name, data.toString());
  474. }
  475. private InputStream writeToString(String... rules) {
  476. StringBuilder data = new StringBuilder();
  477. for (String line : rules) {
  478. data.append(line + "\n");
  479. }
  480. return new ByteArrayInputStream(data.toString().getBytes(UTF_8));
  481. }
  482. }