public void JarBuilder_Build() { // Arrange IJdkWrapper jdkWrapper = new JdkWrapper(); TestLogger logger = new TestLogger(); string inputsDir = TestUtils.CreateTestDirectory(this.TestContext, "in"); string outputsDir = TestUtils.CreateTestDirectory(this.TestContext, "out"); string file1 = TestUtils.CreateTextFile("file1.txt", inputsDir, "file1 content"); string file2 = TestUtils.CreateTextFile("file2.txt", inputsDir, "file2 content"); // Act JarBuilder builder = new JarBuilder(logger, jdkWrapper); builder.SetManifestPropety("prop1", "prop1 value"); builder.AddFile(file1, null); builder.AddFile(file2, "myorg\\myapp\\f2.txt"); string finalJarPath = Path.Combine(outputsDir, "newJar.jar"); bool success = builder.Build(finalJarPath); // Assert Assert.IsTrue(success, "Failed to build the jar file"); new JarChecker(this.TestContext, finalJarPath) .JarContainsFiles( "META-INF\\MANIFEST.MF", "file1.txt", "myorg\\myapp\\f2.txt"); }
private bool BuildJar(string classesDirectory) { JarBuilder jarBuilder = new JarBuilder(logger, this.jdkWrapper); // Set the manifest properties jarBuilder.SetManifestPropety("Sonar-Version", SONARQUBE_API_VERSION); foreach (KeyValuePair <string, string> nameValuePair in this.properties) { jarBuilder.SetManifestPropety(nameValuePair.Key, nameValuePair.Value); } // Add the generated classes int lenClassPath = classesDirectory.Length + 1; foreach (string classFile in Directory.GetFiles(classesDirectory, "*.class", SearchOption.AllDirectories)) { jarBuilder.AddFile(classFile, classFile.Substring(lenClassPath)); } // Add any other content files foreach (KeyValuePair <string, string> pathToFilePair in this.fileToRelativePathMap) { jarBuilder.AddFile(pathToFilePair.Key, pathToFilePair.Value); } // Embed all referenced jars into the jar // NB not all jars need to be added StringBuilder sb = new StringBuilder(); foreach (string refJar in this.referencedJars) { if (IsJarAvailable(refJar)) { continue; } string jarName = "META-INF/lib/" + Path.GetFileName(refJar); jarBuilder.AddFile(refJar, jarName); sb.Append(jarName); sb.Append(" "); } jarBuilder.SetManifestPropety("Plugin-Dependencies", sb.ToString()); return(jarBuilder.Build(this.outputJarFilePath)); }
public void JarBuilder_Layout() { // Arrange TestLogger logger = new TestLogger(); string inputsDir = TestUtils.CreateTestDirectory(this.TestContext, "inputs"); string rootTempDir = TestUtils.CreateTestDirectory(this.TestContext, "temp"); string contentDir = Path.Combine(rootTempDir, JarBuilder.JAR_CONTENT_DIRECTORY_NAME); string file1 = TestUtils.CreateTextFile("file1.txt", inputsDir, "file1 content"); string file2 = TestUtils.CreateTextFile("file2.txt", inputsDir, "file2 content"); string file3 = TestUtils.CreateTextFile("file3.txt", inputsDir, "file3 content"); // Act JarBuilder builder = new JarBuilder(logger, new MockJdkWrapper()); builder.SetManifestPropety("prop1", "prop1 value"); builder.SetManifestPropety("prop2", "prop2 value"); builder.SetManifestPropety("prop3", "prop3 value"); builder.AddFile(file1, null); builder.AddFile(file2, "myorg\\myapp\\f2.txt"); builder.AddFile(file3, "resources\\f3.txt"); builder.LayoutFiles(rootTempDir); // Assert string content = TestUtils.AssertFileExists(JdkWrapper.MANIFEST_FILE_NAME, rootTempDir); AssertManifestPropertyExists(content, "prop1", "prop1 value"); AssertManifestPropertyExists(content, "prop2", "prop2 value"); AssertManifestPropertyExists(content, "prop3", "prop3 value"); content = TestUtils.AssertFileExists("file1.txt", contentDir); Assert.AreEqual("file1 content", content, "Unexpected file content"); content = TestUtils.AssertFileExists("myorg\\myapp\\f2.txt", contentDir); Assert.AreEqual("file2 content", content, "Unexpected file content"); content = TestUtils.AssertFileExists("resources\\f3.txt", contentDir); Assert.AreEqual("file3 content", content, "Unexpected file content"); }
private bool BuildJar(string classesDirectory) { JarBuilder jarBuilder = new JarBuilder(logger, this.jdkWrapper); // Set the manifest properties jarBuilder.SetManifestPropety("Sonar-Version", SONARQUBE_API_VERSION); foreach (KeyValuePair<string, string> nameValuePair in this.properties) { jarBuilder.SetManifestPropety(nameValuePair.Key, nameValuePair.Value); } // Add the generated classes int lenClassPath = classesDirectory.Length + 1; foreach (string classFile in Directory.GetFiles(classesDirectory, "*.class", SearchOption.AllDirectories)) { jarBuilder.AddFile(classFile, classFile.Substring(lenClassPath)); } // Add any other content files foreach(KeyValuePair<string, string> pathToFilePair in this.fileToRelativePathMap) { jarBuilder.AddFile(pathToFilePair.Key, pathToFilePair.Value); } // Embed all referenced jars into the jar // NB not all jars need to be added StringBuilder sb = new StringBuilder(); foreach (string refJar in this.referencedJars) { if (IsJarAvailable(refJar)) { continue; } string jarName = "META-INF/lib/" + Path.GetFileName(refJar); jarBuilder.AddFile(refJar, jarName); sb.Append(jarName); sb.Append(" "); } jarBuilder.SetManifestPropety("Plugin-Dependencies", sb.ToString()); return jarBuilder.Build(this.outputJarFilePath); }