Пример #1
0
        private bool TestWithJUnit(string pathToJava, Project project, string outputFilePath)
        {
            bool hasErrors = false;
            int  exitCode;

            var requiredJars = project.References.Compose(new FileInfo(outputFilePath));

            var filesInZip     = EnumerateFilesInZip(outputFilePath);
            var testFilesInZip = filesInZip.Filter(IsTestClassFile);
            var testClasses    = testFilesInZip.Map <string, string>(ConvertClassFilenameToClassName);
            var arguments      = new string[]
            {
                "-classpath",
                requiredJars.Join(";", item => item.FullName),
                "org.junit.runner.JUnitCore"
            }.Compose(testClasses);

            using (ICapturedProcess process = _capturedProcessFactory.Create(
                       pathToJava,
                       arguments.Map(str => (object)str) /* For some reason, IEnumerable<string> is not acceptable */,
                       line => Log(Level.Info, line),
                       line => Log(Level.Error, line)))
            {
                exitCode = process.Run();
            }
            if (exitCode != 0)
            {
                hasErrors = true;
            }
            return(hasErrors);
        }
Пример #2
0
        /// <summary>
        /// Performs the conversion.
        /// </summary>
        protected override void ExecuteTask()
        {
            string mainsoftBinPath = Registry.GetValue(MainsoftForJava25, "basedir", null) as string;

            if (null == mainsoftBinPath)
            {
                throw new BuildException("Unable to find an installation of Mainsoft for Java EE 2.5");
            }
            string converter = Path.Combine(mainsoftBinPath, "Converter.exe");

            string installRoot = Registry.GetValue(NetFramework, "InstallRoot", null) as string;

            if (null == installRoot)
            {
                throw new BuildException("Unable to find an installation of .NET");
            }
            string netfx2 = Path.Combine(installRoot, "v2.0.50727");

            foreach (FileInfo assemblyPath in ParseAssemblyPaths(AssemblyPaths))
            {
                Log(Level.Info, "Converting {0}...", assemblyPath.FullName);
                var outLines = new StringBuilder();
                var errLines = new StringBuilder();
                int exitCode;
                using (ICapturedProcess process = _capturedProcessFactory.Create(
                           converter,
                           new string[]
                {
                    assemblyPath.FullName,
                    "/lib:" + netfx2 + ";" + assemblyPath.DirectoryName,
                    "/out:" + Path.ChangeExtension(assemblyPath.FullName, ".jar"),
                },
                           line => outLines.AppendLine(line),
                           line => errLines.AppendLine(line)))
                {
                    exitCode = process.Run();
                }
                if (exitCode != 0)
                {
                    Log(Level.Error, outLines.ToString());
                    Log(Level.Error, errLines.ToString());
                    var message = String.Format(
                        CultureInfo.InvariantCulture, "Conversion returned exit code {0}.", exitCode);
                    throw new BuildException(message);
                }
                var tempFile = Path.ChangeExtension(assemblyPath.FullName, ".vmwdb");
                if (File.Exists(tempFile))
                {
                    File.Delete(tempFile);
                }
            }
        }