def _sigtest_generate(args, suite=None, projects=None): """run sigtest generator for Java projects with API""" sigtestlib = mx.library('SIGTEST').get_path(resolve=True) nonTestProjects = [p for p in mx.projects() if _should_test_project(p)] if not nonTestProjects: return 0 javaCompliance = max([p.javaCompliance for p in nonTestProjects]) for p in nonTestProjects: sigtestResults = p.dir + os.sep + 'snapshot.sigtest' cmd = [ '-cp', mx._cygpathU2W(sigtestlib), 'com.sun.tdk.signaturetest.Setup', '-Static', '-FileName', sigtestResults, '-ClassPath', mx.classpath(p) + os.pathsep + mx.get_jdk(javaCompliance).bootclasspath(), ] for pkg in mx.find_packages(p): cmd = cmd + ['-PackageWithoutSubpackages', pkg] exitcode = mx.run_java(cmd, nonZeroIsFatal=False, jdk=mx.get_jdk(javaCompliance)) if exitcode != 95: mx.abort('Exit code was ' + str(exitcode) + ' while generating ' + sigtestResults) if not exists(sigtestResults): mx.abort('Cannot generate ' + sigtestResults) mx.log("Sigtest snapshot generated to " + sigtestResults) return 0
def _sigtest_check(checktype, args, suite=None, projects=None): """run sigtest against Java projects with API""" sigtestlib = mx.library('SIGTEST').get_path(resolve=True) nonTestProjects = [p for p in mx.projects() if _should_test_project(p)] if not nonTestProjects: return 1 javaCompliance = max([p.javaCompliance for p in nonTestProjects]) class OutputCapture: def __init__(self): self.data = "" def __call__(self, data): self.data += data failed = None for p in nonTestProjects: sigtestResults = p.dir + os.sep + 'snapshot.sigtest' if not os.path.exists(sigtestResults): continue cmd = ['-cp', mx._cygpathU2W(sigtestlib), 'com.sun.tdk.signaturetest.SignatureTest', '-Static', '-Mode', 'bin', '-FileName', sigtestResults, '-ClassPath', mx.classpath(p) + os.pathsep + mx.get_jdk(javaCompliance).bootclasspath(), ] if checktype != 'all': cmd.append('-b') for pkg in mx.find_packages(p): cmd = cmd + ['-PackageWithoutSubpackages', pkg] out = OutputCapture() print 'Checking ' + checktype + ' signature changes against ' + sigtestResults exitcode = mx.run_java(cmd, nonZeroIsFatal=False, jdk=mx.get_jdk(javaCompliance), out=out, err=out) mx.ensure_dir_exists(p.get_output_root()) with open(p.get_output_root() + os.path.sep + 'sigtest-junit.xml', 'w') as f: f.write('<?xml version="1.0" encoding="UTF-8" ?>\n') f.write('<testsuite tests="1" name="' + p.name + '.sigtest.' + checktype + '">\n') f.write('<testcase classname="' + p.name + '" name="sigtest.' + checktype + '">\n') if exitcode != 95: print out.data failed = sigtestResults f.write('<failure type="SignatureCheck"><![CDATA[\n') f.write(out.data) f.write(']]></failure>') else: f.write('<system-err><![CDATA[\n') f.write(out.data) f.write(']]></system-err>') f.write('</testcase>\n') f.write('</testsuite>\n') if failed: mx.abort('Signature error in ' + failed) else: print 'OK.' return 0
def _sigtest_generate(args, suite=None, projects=None): """run sigtest generator for Java projects with API""" sigtestlib = mx.library('SIGTEST').get_path(resolve=True) nonTestProjects = [p for p in mx.projects() if _should_test_project(p)] if not nonTestProjects: return 0 javaCompliance = max([p.javaCompliance for p in nonTestProjects]) for p in nonTestProjects: sigtestResults = p.dir + os.sep + 'snapshot.sigtest' cmd = ['-cp', mx._cygpathU2W(sigtestlib), 'com.sun.tdk.signaturetest.Setup', '-Static', '-FileName', sigtestResults, '-ClassPath', mx.classpath(p) + os.pathsep + mx.get_jdk(javaCompliance).bootclasspath(), ] for pkg in mx.find_packages(p): cmd = cmd + ['-PackageWithoutSubpackages', pkg] exitcode = mx.run_java(cmd, nonZeroIsFatal=False, jdk=mx.get_jdk(javaCompliance)) if exitcode != 95: mx.abort('Exit code was ' + str(exitcode) + ' while generating ' + sigtestResults) if not exists(sigtestResults): mx.abort('Cannot generate ' + sigtestResults) mx.log("Sigtest snapshot generated to " + sigtestResults) return 0
def _should_test_project(p): if not p.isJavaProject(): return False return len(mx.find_packages(p)) > 0
def _sigtest_check(checktype, args, suite=None, projects=None): """run sigtest against Java projects with API""" sigtestlib = mx.library('SIGTEST').get_path(resolve=True) nonTestProjects = [p for p in mx.projects() if _should_test_project(p)] if not nonTestProjects: return 1 javaCompliance = max([p.javaCompliance for p in nonTestProjects]) class OutputCapture: def __init__(self): self.data = "" def __call__(self, data): self.data += data failed = None for p in nonTestProjects: sigtestResults = p.dir + os.sep + 'snapshot.sigtest' if not os.path.exists(sigtestResults): continue cmd = [ '-cp', mx._cygpathU2W(sigtestlib), 'com.sun.tdk.signaturetest.SignatureTest', '-Static', '-Mode', 'bin', '-FileName', sigtestResults, '-ClassPath', mx.classpath(p) + os.pathsep + mx.get_jdk(javaCompliance).bootclasspath(), ] if checktype != 'all': cmd.append('-b') for pkg in mx.find_packages(p): cmd = cmd + ['-PackageWithoutSubpackages', pkg] out = OutputCapture() print 'Checking ' + checktype + ' signature changes against ' + sigtestResults exitcode = mx.run_java(cmd, nonZeroIsFatal=False, jdk=mx.get_jdk(javaCompliance), out=out, err=out) mx.ensure_dir_exists(p.get_output_root()) with open(p.get_output_root() + os.path.sep + 'sigtest-junit.xml', 'w') as f: f.write('<?xml version="1.0" encoding="UTF-8" ?>\n') f.write('<testsuite tests="1" name="' + p.name + '.sigtest.' + checktype + '">\n') f.write('<testcase classname="' + p.name + '" name="sigtest.' + checktype + '">\n') if exitcode != 95: print out.data failed = sigtestResults f.write('<failure type="SignatureCheck"><![CDATA[\n') f.write(out.data) f.write(']]></failure>') else: f.write('<system-err><![CDATA[\n') f.write(out.data) f.write(']]></system-err>') f.write('</testcase>\n') f.write('</testsuite>\n') if failed: mx.abort('Signature error in ' + failed) else: print 'OK.' return 0