Exemplo n.º 1
0
def findbugs(args, fbArgs=None, suite=None, projects=None):
    """run FindBugs against non-test Java projects"""
    findBugsHome = mx.get_env('FINDBUGS_HOME', None)
    if suite is None:
        suite = mx._primary_suite
    if findBugsHome:
        findbugsJar = join(findBugsHome, 'lib', 'findbugs.jar')
    else:
        findbugsLib = join(mx._mx_suite.get_output_root(), 'findbugs-3.0.0')
        if not exists(findbugsLib):
            tmp = tempfile.mkdtemp(prefix='findbugs-download-tmp',
                                   dir=mx._mx_suite.dir)
            try:
                findbugsDist = mx.library('FINDBUGS_DIST').get_path(
                    resolve=True)
                with zipfile.ZipFile(findbugsDist) as zf:
                    candidates = [
                        e for e in zf.namelist()
                        if e.endswith('/lib/findbugs.jar')
                    ]
                    assert len(candidates) == 1, candidates
                    libDirInZip = os.path.dirname(candidates[0])
                    zf.extractall(tmp)
                shutil.copytree(join(tmp, libDirInZip), findbugsLib)
            finally:
                shutil.rmtree(tmp)
        findbugsJar = join(findbugsLib, 'findbugs.jar')
    assert exists(findbugsJar)
    nonTestProjects = [p for p in mx.projects() if _should_test_project(p)]
    if not nonTestProjects:
        return 0
    outputDirs = map(mx._cygpathU2W, [p.output_dir() for p in nonTestProjects])
    javaCompliance = max([p.javaCompliance for p in nonTestProjects])
    jdk = mx.get_jdk(javaCompliance)
    if jdk.javaCompliance >= "1.9":
        mx.log('FindBugs does not yet support JDK9 - skipping')
        return 0

    findbugsResults = join(suite.dir, 'findbugs.results')

    if fbArgs is None:
        fbArgs = defaultFindbugsArgs()
    cmd = ['-jar', mx._cygpathU2W(findbugsJar)] + fbArgs
    cmd = cmd + [
        '-auxclasspath',
        mx._separatedCygpathU2W(
            mx.classpath([p.name
                          for p in nonTestProjects], jdk=jdk)), '-output',
        mx._cygpathU2W(findbugsResults), '-exitcode'
    ] + args + outputDirs
    exitcode = mx.run_java(cmd, nonZeroIsFatal=False, jdk=jdk)
    if exitcode != 0:
        with open(findbugsResults) as fp:
            mx.log(fp.read())
    os.unlink(findbugsResults)
    return exitcode
Exemplo n.º 2
0
def igv(args):
    """run the Ideal Graph Visualizer"""
    logFile = '.ideal_graph_visualizer.log'
    with open(join(_suite.dir, logFile), 'w') as fp:
        mx.logv('[Ideal Graph Visualizer log is in ' + fp.name + ']')
        nbplatform = join(_suite.dir, 'src', 'share', 'tools',
                          'IdealGraphVisualizer', 'nbplatform')

        # Remove NetBeans platform if it is earlier than the current supported version
        if exists(nbplatform):
            updateTrackingFile = join(nbplatform, 'platform',
                                      'update_tracking',
                                      'org-netbeans-core.xml')
            if not exists(updateTrackingFile):
                mx.log('Could not find \'' + updateTrackingFile +
                       '\', removing NetBeans platform')
                shutil.rmtree(nbplatform)
            else:
                dom = xml.dom.minidom.parse(updateTrackingFile)
                currentVersion = mx.VersionSpec(
                    dom.getElementsByTagName('module_version')[0].getAttribute(
                        'specification_version'))
                supportedVersion = mx.VersionSpec('3.43.1')
                if currentVersion < supportedVersion:
                    mx.log('Replacing NetBeans platform version ' +
                           str(currentVersion) + ' with version ' +
                           str(supportedVersion))
                    shutil.rmtree(nbplatform)
                elif supportedVersion < currentVersion:
                    mx.log(
                        'Supported NetBeans version in igv command should be updated to '
                        + str(currentVersion))

        if not exists(nbplatform):
            mx.logv(
                '[This execution may take a while as the NetBeans platform needs to be downloaded]'
            )

        env = _igvBuildEnv()
        # make the jar for Batik 1.7 available.
        env['IGV_BATIK_JAR'] = mx.library('BATIK').get_path(True)
        if mx.run([
                'ant', '-f',
                mx._cygpathU2W(
                    join(_suite.dir, 'src', 'share', 'tools',
                         'IdealGraphVisualizer', 'build.xml')), '-l',
                mx._cygpathU2W(fp.name), 'run'
        ],
                  env=env,
                  nonZeroIsFatal=False):
            mx.abort(
                "IGV ant build & launch failed. Check '" + logFile +
                "'. You can also try to delete 'src/share/tools/IdealGraphVisualizer/nbplatform'."
            )
Exemplo n.º 3
0
def _jvmci_gate_runner(args, tasks):
    # Build release server VM now so we can run the unit tests
    with Task('BuildHotSpotJVMCIHosted: release', tasks) as t:
        if t:
            _runmultimake([
                '--jdk-jvm-variants', 'server', '--jdk-debug-levels', 'release'
            ])

    # Run unit tests in hosted mode
    with VM(jvmVariant='server', debugLevel='release', jvmciMode='hosted'):
        with Task('JVMCI UnitTests: hosted-release', tasks) as t:
            if t:
                unittest([
                    '--suite', 'jvmci', '--enable-timing', '--verbose',
                    '--fail-fast'
                ])

    # Build the other VM flavors
    with Task('BuildHotSpotJVMCIOthers: fastdebug', tasks) as t:
        if t:
            _runmultimake([
                '--jdk-jvm-variants', 'server', '--jdk-debug-levels',
                'fastdebug'
            ])

    with Task('CleanAndBuildIdealGraphVisualizer', tasks,
              disableJacoco=True) as t:
        if t and platform.processor() != 'sparc':
            buildxml = mx._cygpathU2W(
                join(_suite.dir, 'src', 'share', 'tools',
                     'IdealGraphVisualizer', 'build.xml'))
            mx.run(['ant', '-f', buildxml, '-q', 'clean', 'build'],
                   env=_igvBuildEnv())
Exemplo n.º 4
0
def jackpot(args, suite=None, nonZeroIsFatal=False):
    """run Jackpot 3.0 against non-test Java projects"""
    jackpotHome = mx.get_env('JACKPOT_HOME', None)
    if jackpotHome:
        jackpotJar = join(jackpotHome, 'jackpot.jar')
    else:
        jackpotJar = mx.library('JACKPOT').get_path(resolve=True)
    assert exists(jackpotJar)
    if suite is None:
        suite = mx.primary_suite()
    nonTestProjects = [p for p in mx.projects() if _should_test_project(p)]
    if not nonTestProjects:
        return 0
    groups = []
    for p in nonTestProjects:
        javacClasspath = []

        deps = []
        p.walk_deps(visit=lambda dep, edge: deps.append(dep)
                    if dep.isLibrary() or dep.isJavaProject() else None)
        annotationProcessorOnlyDeps = []
        if len(p.annotation_processors()) > 0:
            for apDep in p.annotation_processors():
                if not apDep in deps:
                    deps.append(apDep)
                    annotationProcessorOnlyDeps.append(apDep)

        for dep in deps:
            if dep == p:
                continue

            if dep in annotationProcessorOnlyDeps:
                continue

            javacClasspath.append(dep.classpath_repr(resolve=True))

        sourceLevel = min(p.javaCompliance.value, 9)

        groups = groups + [
            '--group', "--classpath " + mx._separatedCygpathU2W(
                _escape_string(os.pathsep.join(javacClasspath))) +
            " --source " + str(sourceLevel) + " " +
            " ".join([_escape_string(d) for d in p.source_dirs()])
        ]

    cmd = [
        '-classpath',
        mx._cygpathU2W(jackpotJar),
        'org.netbeans.modules.jackpot30.cmdline.Main'
    ]
    cmd = cmd + ['--fail-on-warnings', '--progress'] + args + groups

    jdk = mx.get_jdk(mx.JavaCompliance("8"),
                     cancel='cannot run Jackpot',
                     purpose="run Jackpot")
    if jdk is None:
        mx.warn('Skipping Jackpot since JDK 8 is not available')
        return 0
    else:
        return mx.run_java(cmd, nonZeroIsFatal=nonZeroIsFatal, jdk=jdk)
Exemplo n.º 5
0
def igv(args):
    """run the Ideal Graph Visualizer"""
    logFile = '.ideal_graph_visualizer.log'
    with open(join(_suite.dir, logFile), 'w') as fp:
        mx.logv('[Ideal Graph Visualizer log is in ' + fp.name + ']')
        nbplatform = join(_suite.dir, 'src', 'share', 'tools', 'IdealGraphVisualizer', 'nbplatform')

        # Remove NetBeans platform if it is earlier than the current supported version
        if exists(nbplatform):
            updateTrackingFile = join(nbplatform, 'platform', 'update_tracking', 'org-netbeans-core.xml')
            if not exists(updateTrackingFile):
                mx.log('Could not find \'' + updateTrackingFile + '\', removing NetBeans platform')
                shutil.rmtree(nbplatform)
            else:
                dom = xml.dom.minidom.parse(updateTrackingFile)
                currentVersion = mx.VersionSpec(dom.getElementsByTagName('module_version')[0].getAttribute('specification_version'))
                supportedVersion = mx.VersionSpec('3.43.1')
                if currentVersion < supportedVersion:
                    mx.log('Replacing NetBeans platform version ' + str(currentVersion) + ' with version ' + str(supportedVersion))
                    shutil.rmtree(nbplatform)
                elif supportedVersion < currentVersion:
                    mx.log('Supported NetBeans version in igv command should be updated to ' + str(currentVersion))

        if not exists(nbplatform):
            mx.logv('[This execution may take a while as the NetBeans platform needs to be downloaded]')

        env = _igvBuildEnv()
        # make the jar for Batik 1.7 available.
        env['IGV_BATIK_JAR'] = mx.library('BATIK').get_path(True)
        if mx.run(['ant', '-f', mx._cygpathU2W(join(_suite.dir, 'src', 'share', 'tools', 'IdealGraphVisualizer', 'build.xml')), '-l', mx._cygpathU2W(fp.name), 'run'], env=env, nonZeroIsFatal=False):
            mx.abort("IGV ant build & launch failed. Check '" + logFile + "'. You can also try to delete 'src/share/tools/IdealGraphVisualizer/nbplatform'.")
Exemplo n.º 6
0
def getDacapo(name, dacapoArgs=None, extraVmArguments=None):
    dacapo = mx.get_env('DACAPO_CP')
    if dacapo is None:
        l = mx.library('DACAPO', False)
        if l is not None:
            dacapo = l.get_path(True)
        else:
            mx.abort('DaCapo 9.12 jar file must be specified with DACAPO_CP environment variable or as DACAPO library')

    if not isfile(dacapo) or not dacapo.endswith('.jar'):
        mx.abort('Specified DaCapo jar file does not exist or is not a jar file: ' + dacapo)

    dacapoSuccess = re.compile(r"^===== DaCapo 9\.12 ([a-zA-Z0-9_]+) PASSED in ([0-9]+) msec =====", re.MULTILINE)
    dacapoFail = re.compile(r"^===== DaCapo 9\.12 ([a-zA-Z0-9_]+) FAILED (warmup|) =====", re.MULTILINE)
    dacapoTime = re.compile(r"===== DaCapo 9\.12 (?P<benchmark>[a-zA-Z0-9_]+) PASSED in (?P<time>[0-9]+) msec =====")
    dacapoTime1 = re.compile(r"===== DaCapo 9\.12 (?P<benchmark>[a-zA-Z0-9_]+) completed warmup 1 in (?P<time>[0-9]+) msec =====")

    dacapoMatcher = ValuesMatcher(dacapoTime, {'group' : 'DaCapo', 'name' : '<benchmark>', 'score' : '<time>'})
    dacapoMatcher1 = ValuesMatcher(dacapoTime1, {'group' : 'DaCapo-1stRun', 'name' : '<benchmark>', 'score' : '<time>'})

    # Use ipv4 stack for dacapos; tomcat+solaris+ipv6_interface fails (see also: JDK-8072384)
    return Test("DaCapo-" + name, ['-jar', mx._cygpathU2W(dacapo), name] + _noneAsEmptyList(dacapoArgs), [dacapoSuccess], [dacapoFail],
                [dacapoMatcher, dacapoMatcher1],
                ['-Xms2g', '-XX:+' + gc, '-XX:-UseCompressedOops', "-Djava.net.preferIPv4Stack=true", '-G:+ExitVMOnException'] +
                _noneAsEmptyList(extraVmArguments))
Exemplo n.º 7
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'
        jdk = mx.get_jdk(javaCompliance)
        cmd = [
            '-cp',
            mx._cygpathU2W(sigtestlib),
            'com.sun.tdk.signaturetest.Setup',
            '-Static',
            '-FileName',
            sigtestResults,
            '-ClassPath',
            mx.classpath(p, jdk=jdk) + os.pathsep + jdk.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
Exemplo n.º 8
0
    def harness(unittestDeps, vmLauncher, vmArgs):
        prefixArgs = ['-esa', '-ea']
        if gc_after_test:
            prefixArgs.append('-XX:-DisableExplicitGC')
        with open(testfile) as fp:
            testclasses = [l.rstrip() for l in fp.readlines()]

        jdk = vmLauncher.jdk()
        vmArgs += mx.get_runtime_jvm_args(unittestDeps, cp_prefix=prefixCp+coreCp, jdk=jdk)

        # suppress menubar and dock when running on Mac
        vmArgs = prefixArgs + ['-Djava.awt.headless=true'] + vmArgs

        if jdk.javaCompliance > '1.8':
            # This is required to access jdk.internal.module.Modules for supporting
            # the @AddExports annotation.
            vmArgs = vmArgs + ['--add-exports=java.base/jdk.internal.module=ALL-UNNAMED']

        # Execute Junit directly when one test is being run. This simplifies
        # replaying the VM execution in a native debugger (e.g., gdb).
        mainClassArgs = coreArgs + (testclasses if len(testclasses) == 1 else ['@' + mx._cygpathU2W(testfile)])

        config = (vmArgs, mainClass, mainClassArgs)
        for p in _config_participants:
            config = p(config)
        vmLauncher.launcher(*config)
Exemplo n.º 9
0
    def harness(unittestDeps, vmLauncher, vmArgs):
        prefixArgs = ['-esa', '-ea']
        if gc_after_test:
            prefixArgs.append('-XX:-DisableExplicitGC')
        with open(testfile) as fp:
            testclasses = [l.rstrip() for l in fp.readlines()]

        jdk = vmLauncher.jdk()
        vmArgs += mx.get_runtime_jvm_args(unittestDeps,
                                          cp_prefix=prefixCp + coreCp,
                                          jdk=jdk)

        # suppress menubar and dock when running on Mac
        vmArgs = prefixArgs + ['-Djava.awt.headless=true'] + vmArgs

        if jdk.javaCompliance > '1.8':
            # This is required to access jdk.internal.module.Modules for supporting
            # the @AddExports annotation.
            vmArgs = vmArgs + [
                '--add-exports=java.base/jdk.internal.module=ALL-UNNAMED'
            ]

        # Execute Junit directly when one test is being run. This simplifies
        # replaying the VM execution in a native debugger (e.g., gdb).
        mainClassArgs = coreArgs + (testclasses if len(testclasses) == 1 else
                                    ['@' + mx._cygpathU2W(testfile)])

        config = (vmArgs, mainClass, mainClassArgs)
        for p in _config_participants:
            config = p(config)
        vmLauncher.launcher(*config)
Exemplo n.º 10
0
def jackpot(args, suite=None, nonZeroIsFatal=False):
    """run Jackpot 11.1 against non-test Java projects"""

    jackpotHome = mx.get_env('JACKPOT_HOME', None)
    if jackpotHome:
        jackpotJar = join(jackpotHome, 'jackpot.jar')
    else:
        jackpotJar = mx.library('JACKPOT').get_path(resolve=True)
    assert exists(jackpotJar)
    if suite is None:
        suite = mx.primary_suite()
    nonTestProjects = [p for p in mx.projects() if _should_test_project(p)]
    if not nonTestProjects:
        return 0
    groups = []
    for p in nonTestProjects:
        javacClasspath = []

        deps = []
        p.walk_deps(visit=lambda dep, edge: deps.append(dep) if dep.isLibrary() or dep.isJavaProject() else None)
        annotationProcessorOnlyDeps = []
        if len(p.annotation_processors()) > 0:
            for apDep in p.annotation_processors():
                if not apDep in deps:
                    deps.append(apDep)
                    annotationProcessorOnlyDeps.append(apDep)

        for dep in deps:
            if dep == p:
                continue

            if dep in annotationProcessorOnlyDeps:
                continue

            javacClasspath.append(dep.classpath_repr(resolve=True))

        sourceLevel = min(p.javaCompliance.value, 9)

        groups = groups + ['--group', "--classpath " + mx._separatedCygpathU2W(_escape_string(os.pathsep.join(javacClasspath))) + " --source " + str(sourceLevel) + " " + " ".join([_escape_string(d) for d in p.source_dirs()])]

    cmd = ['--add-exports=jdk.compiler/com.sun.tools.javac.code=ALL-UNNAMED', '--add-opens=java.base/java.net=ALL-UNNAMED', '--add-opens=java.desktop/sun.awt=ALL-UNNAMED']
    cmd = cmd + ['-classpath', mx._cygpathU2W(jackpotJar), 'org.netbeans.modules.jackpot30.cmdline.Main']
    jackCmd = ['--fail-on-warnings', '--progress'] + args + groups

    jdk = mx.get_jdk(mx.JavaCompliance("11+"), cancel='cannot run Jackpot', purpose="run Jackpot")
    if jdk is None:
        mx.warn('Skipping Jackpot since JDK 11+ is not available')
        return 0
    else:
        with tempfile.NamedTemporaryFile(mode='w', suffix='.jackpot') as f:
            for c in jackCmd:
                print(c, file=f)
            f.flush()
            ret = mx.run_java(cmd + ['@' + f.name], nonZeroIsFatal=nonZeroIsFatal, jdk=jdk)
            if ret != 0:
                mx.warn('To simulate the failure execute `mx -p {0} jackpot`.'.format(suite.dir))
                mx.warn('To fix the error automatically try `mx -p {0} jackpot --apply`'.format(suite.dir))
            return ret
Exemplo n.º 11
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
        jdk = mx.get_jdk(javaCompliance)
        cmd = ['-cp', mx._cygpathU2W(sigtestlib), 'com.sun.tdk.signaturetest.SignatureTest',
            '-Static', '-Mode', 'bin', '-FileName', sigtestResults,
            '-ClassPath', mx.classpath(p, jdk=jdk) + os.pathsep + jdk.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
Exemplo n.º 12
0
def getDacapo(name, dacapoArgs=None, extraVmArguments=None):
    dacapo = mx.get_env('DACAPO_CP')
    if dacapo is None:
        l = mx.library('DACAPO', False)
        if l is not None:
            dacapo = l.get_path(True)
        else:
            mx.abort(
                'DaCapo 9.12 jar file must be specified with DACAPO_CP environment variable or as DACAPO library'
            )

    if not isfile(dacapo) or not dacapo.endswith('.jar'):
        mx.abort(
            'Specified DaCapo jar file does not exist or is not a jar file: ' +
            dacapo)

    dacapoSuccess = re.compile(
        r"^===== DaCapo 9\.12 ([a-zA-Z0-9_]+) PASSED in ([0-9]+) msec =====",
        re.MULTILINE)
    dacapoFail = re.compile(
        r"^===== DaCapo 9\.12 ([a-zA-Z0-9_]+) FAILED (warmup|) =====",
        re.MULTILINE)
    dacapoTime = re.compile(
        r"===== DaCapo 9\.12 (?P<benchmark>[a-zA-Z0-9_]+) PASSED in (?P<time>[0-9]+) msec ====="
    )
    dacapoTime1 = re.compile(
        r"===== DaCapo 9\.12 (?P<benchmark>[a-zA-Z0-9_]+) completed warmup 1 in (?P<time>[0-9]+) msec ====="
    )

    dacapoMatcher = ValuesMatcher(dacapoTime, {
        'group': 'DaCapo',
        'name': '<benchmark>',
        'score': '<time>'
    })
    dacapoMatcher1 = ValuesMatcher(dacapoTime1, {
        'group': 'DaCapo-1stRun',
        'name': '<benchmark>',
        'score': '<time>'
    })

    # Use ipv4 stack for dacapos; tomcat+solaris+ipv6_interface fails (see also: JDK-8072384)
    return Test("DaCapo-" + name,
                ['-jar', mx._cygpathU2W(dacapo), name] +
                _noneAsEmptyList(dacapoArgs), [dacapoSuccess], [dacapoFail],
                [dacapoMatcher, dacapoMatcher1], [
                    '-Xms2g', '-XX:+' + gc, '-XX:-UseCompressedOops',
                    "-Djava.net.preferIPv4Stack=true", '-G:+ExitVMOnException'
                ] + _noneAsEmptyList(extraVmArguments))
Exemplo n.º 13
0
def findbugs(args, fbArgs=None, suite=None, projects=None):
    """run FindBugs against non-test Java projects"""
    findBugsHome = mx.get_env('FINDBUGS_HOME', None)
    if suite is None:
        suite = mx._primary_suite
    if findBugsHome:
        findbugsJar = join(findBugsHome, 'lib', 'findbugs.jar')
    else:
        findbugsLib = join(mx._mx_suite.get_output_root(), 'findbugs-3.0.0')
        if not exists(findbugsLib):
            tmp = tempfile.mkdtemp(prefix='findbugs-download-tmp', dir=mx._mx_suite.dir)
            try:
                findbugsDist = mx.library('FINDBUGS_DIST').get_path(resolve=True)
                with zipfile.ZipFile(findbugsDist) as zf:
                    candidates = [e for e in zf.namelist() if e.endswith('/lib/findbugs.jar')]
                    assert len(candidates) == 1, candidates
                    libDirInZip = os.path.dirname(candidates[0])
                    zf.extractall(tmp)
                shutil.copytree(join(tmp, libDirInZip), findbugsLib)
            finally:
                shutil.rmtree(tmp)
        findbugsJar = join(findbugsLib, 'findbugs.jar')
    assert exists(findbugsJar)
    nonTestProjects = [p for p in mx.projects() if _should_test_project(p)]
    if not nonTestProjects:
        return 0
    outputDirs = map(mx._cygpathU2W, [p.output_dir() for p in nonTestProjects])
    javaCompliance = max([p.javaCompliance for p in nonTestProjects])
    jdk = mx.get_jdk(javaCompliance)
    if jdk.javaCompliance >= "1.9":
        mx.log('FindBugs does not yet support JDK9 - skipping')
        return 0

    findbugsResults = join(suite.dir, 'findbugs.results')

    if fbArgs is None:
        fbArgs = defaultFindbugsArgs()
    cmd = ['-jar', mx._cygpathU2W(findbugsJar)] + fbArgs
    cmd = cmd + ['-auxclasspath', mx._separatedCygpathU2W(mx.classpath([p.name for p in nonTestProjects], jdk=jdk)), '-output', mx._cygpathU2W(findbugsResults), '-exitcode'] + args + outputDirs
    exitcode = mx.run_java(cmd, nonZeroIsFatal=False, jdk=jdk)
    if exitcode != 0:
        with open(findbugsResults) as fp:
            mx.log(fp.read())
    os.unlink(findbugsResults)
    return exitcode
Exemplo n.º 14
0
def getDacapo(name, dacapoArgs=None):
    dacapo = mx.get_env('DACAPO_CP')
    if dacapo is None:
        l = mx.library('DACAPO', False)
        if l is not None:
            dacapo = l.get_path(True)
        else:
            mx.abort(
                'DaCapo 9.12 jar file must be specified with DACAPO_CP environment variable or as DACAPO library'
            )

    if not isfile(dacapo) or not dacapo.endswith('.jar'):
        mx.abort(
            'Specified DaCapo jar file does not exist or is not a jar file: ' +
            dacapo)

    dacapoSuccess = re.compile(
        r"^===== DaCapo 9\.12 ([a-zA-Z0-9_]+) PASSED in ([0-9]+) msec =====",
        re.MULTILINE)
    dacapoFail = re.compile(
        r"^===== DaCapo 9\.12 ([a-zA-Z0-9_]+) FAILED (warmup|) =====",
        re.MULTILINE)
    dacapoTime = re.compile(
        r"===== DaCapo 9\.12 (?P<benchmark>[a-zA-Z0-9_]+) PASSED in (?P<time>[0-9]+) msec ====="
    )
    dacapoTime1 = re.compile(
        r"===== DaCapo 9\.12 (?P<benchmark>[a-zA-Z0-9_]+) completed warmup 1 in (?P<time>[0-9]+) msec ====="
    )

    dacapoMatcher = ValuesMatcher(dacapoTime, {
        'group': 'DaCapo',
        'name': '<benchmark>',
        'score': '<time>'
    })
    dacapoMatcher1 = ValuesMatcher(dacapoTime1, {
        'group': 'DaCapo-1stRun',
        'name': '<benchmark>',
        'score': '<time>'
    })

    return Test("DaCapo-" + name,
                ['-jar', mx._cygpathU2W(dacapo), name] +
                _noneAsEmptyList(dacapoArgs), [dacapoSuccess], [dacapoFail],
                [dacapoMatcher, dacapoMatcher1],
                ['-Xms2g', '-XX:+' + gc, '-XX:-UseCompressedOops'])
Exemplo n.º 15
0
def _jvmci_gate_runner(args, tasks):
    # Build release server VM now so we can run the unit tests
    with Task('BuildHotSpotJVMCIHosted: release', tasks) as t:
        if t: _runmultimake(['--jdk-jvm-variants', 'server', '--jdk-debug-levels', 'release'])

    # Run unit tests in hosted mode
    with VM(jvmVariant='server', debugLevel='release', jvmciMode='hosted'):
        with Task('JVMCI UnitTests: hosted-release', tasks) as t:
            if t: unittest(['--suite', 'jvmci', '--enable-timing', '--verbose', '--fail-fast'])

    # Build the other VM flavors
    with Task('BuildHotSpotJVMCIOthers: fastdebug', tasks) as t:
        if t: _runmultimake(['--jdk-jvm-variants', 'server', '--jdk-debug-levels', 'fastdebug'])

    with Task('CleanAndBuildIdealGraphVisualizer', tasks, disableJacoco=True) as t:
        if t and platform.processor() != 'sparc':
            buildxml = mx._cygpathU2W(join(_suite.dir, 'src', 'share', 'tools', 'IdealGraphVisualizer', 'build.xml'))
            mx.run(['ant', '-f', buildxml, '-q', 'clean', 'build'], env=_igvBuildEnv())
Exemplo n.º 16
0
def getScalaDacapo(name, dacapoArgs=None, extraVmArguments=None):
    dacapo = mx.get_env('DACAPO_SCALA_CP')
    if dacapo is None:
        l = mx.library('DACAPO_SCALA', False)
        if l is not None:
            dacapo = l.get_path(True)
        else:
            mx.abort('Scala DaCapo 0.1.0 jar file must be specified with DACAPO_SCALA_CP environment variable or as DACAPO_SCALA library')

    if not isfile(dacapo) or not dacapo.endswith('.jar'):
        mx.abort('Specified Scala DaCapo jar file does not exist or is not a jar file: ' + dacapo)

    dacapoSuccess = re.compile(r"^===== DaCapo 0\.1\.0(-SNAPSHOT)? ([a-zA-Z0-9_]+) PASSED in ([0-9]+) msec =====", re.MULTILINE)
    dacapoFail = re.compile(r"^===== DaCapo 0\.1\.0(-SNAPSHOT)? ([a-zA-Z0-9_]+) FAILED (warmup|) =====", re.MULTILINE)
    dacapoTime = re.compile(r"===== DaCapo 0\.1\.0(-SNAPSHOT)? (?P<benchmark>[a-zA-Z0-9_]+) PASSED in (?P<time>[0-9]+) msec =====")

    dacapoMatcher = ValuesMatcher(dacapoTime, {'group' : "Scala-DaCapo", 'name' : '<benchmark>', 'score' : '<time>'})

    return Test("Scala-DaCapo-" + name, ['-jar', mx._cygpathU2W(dacapo), name] + _noneAsEmptyList(dacapoArgs), [dacapoSuccess], [dacapoFail], [dacapoMatcher], ['-Xms2g', '-XX:+' + gc, '-XX:-UseCompressedOops'] + _noneAsEmptyList(extraVmArguments))
Exemplo n.º 17
0
def jackpot(args, suite=None, nonZeroIsFatal=False):
    """run Jackpot 3.0 against non-test Java projects"""
    jackpotHome = mx.get_env('JACKPOT_HOME', None)
    if jackpotHome:
        jackpotJar = join(jackpotHome, 'jackpot.jar')
    else:
        jackpotJar = mx.library('JACKPOT').get_path(resolve=True)
    assert exists(jackpotJar)
    if suite is None:
        suite = mx._primary_suite
    nonTestProjects = [p for p in mx.projects() if _should_test_project(p)]
    if not nonTestProjects:
        return 0
    groups = []
    for p in nonTestProjects:
        javacClasspath = []

        deps = []
        p.walk_deps(visit=lambda dep, edge: deps.append(dep) if dep.isLibrary() or dep.isJavaProject() else None)
        annotationProcessorOnlyDeps = []
        if len(p.annotation_processors()) > 0:
            for apDep in p.annotation_processors():
                if not apDep in deps:
                    deps.append(apDep)
                    annotationProcessorOnlyDeps.append(apDep)

        for dep in deps:
            if dep == p:
                continue

            if dep in annotationProcessorOnlyDeps:
                continue

            javacClasspath.append(dep.classpath_repr(resolve=True))

        javaCompliance = p.javaCompliance

        groups = groups + ['--group', "--classpath " + mx._separatedCygpathU2W(_escape_string(os.pathsep.join(javacClasspath))) + " --source " + str(p.javaCompliance) + " " + " ".join([_escape_string(d) for d in p.source_dirs()])]

    cmd = ['-classpath', mx._cygpathU2W(jackpotJar), 'org.netbeans.modules.jackpot30.cmdline.Main']
    cmd = cmd + ['--fail-on-warnings', '--progress'] + args + groups

    return mx.run_java(cmd, nonZeroIsFatal=nonZeroIsFatal, jdk=mx.get_jdk(javaCompliance))
Exemplo n.º 18
0
    def harness(projectsCp, vmLauncher, vmArgs):
        prefixArgs = ['-esa', '-ea']
        if gc_after_test:
            prefixArgs.append('-XX:-DisableExplicitGC')
        with open(testfile) as fp:
            testclasses = [l.rstrip() for l in fp.readlines()]

        # Run the VM in a mode where application/test classes can
        # access classes normally hidden behind the JVMCI class loader
        cp = prefixCp + coreCp + os.pathsep + projectsCp

        # suppress menubar and dock when running on Mac
        vmArgs = prefixArgs + ['-Djava.awt.headless=true'] + vmArgs + ['-cp', mx._separatedCygpathU2W(cp)]
        mainClass = 'com.oracle.mxtool.junit.MxJUnitWrapper'
        # Execute Junit directly when one test is being run. This simplifies
        # replaying the VM execution in a native debugger (e.g., gdb).
        mainClassArgs = coreArgs + (testclasses if len(testclasses) == 1 else ['@' + mx._cygpathU2W(testfile)])

        vmLauncher(vmArgs, mainClass, mainClassArgs)
Exemplo n.º 19
0
    def harness(unittestCp, vmLauncher, vmArgs):
        prefixArgs = ['-esa', '-ea']
        if gc_after_test:
            prefixArgs.append('-XX:-DisableExplicitGC')
        with open(testfile) as fp:
            testclasses = [l.rstrip() for l in fp.readlines()]

        cp = prefixCp + coreCp + os.pathsep + unittestCp

        # suppress menubar and dock when running on Mac
        vmArgs = prefixArgs + ['-Djava.awt.headless=true'] + vmArgs + ['-cp', mx._separatedCygpathU2W(cp)]
        # Execute Junit directly when one test is being run. This simplifies
        # replaying the VM execution in a native debugger (e.g., gdb).
        mainClassArgs = coreArgs + (testclasses if len(testclasses) == 1 else ['@' + mx._cygpathU2W(testfile)])

        config = (vmArgs, mainClass, mainClassArgs)
        for p in _config_participants:
            config = p(config)

        vmLauncher.launcher(*config)
Exemplo n.º 20
0
def getDacapo(name, dacapoArgs=None):
    dacapo = mx.get_env('DACAPO_CP')
    if dacapo is None:
        l = mx.library('DACAPO', False)
        if l is not None:
            dacapo = l.get_path(True)
        else:
            mx.abort('DaCapo 9.12 jar file must be specified with DACAPO_CP environment variable or as DACAPO library')

    if not isfile(dacapo) or not dacapo.endswith('.jar'):
        mx.abort('Specified DaCapo jar file does not exist or is not a jar file: ' + dacapo)

    dacapoSuccess = re.compile(r"^===== DaCapo 9\.12 ([a-zA-Z0-9_]+) PASSED in ([0-9]+) msec =====", re.MULTILINE)
    dacapoFail = re.compile(r"^===== DaCapo 9\.12 ([a-zA-Z0-9_]+) FAILED (warmup|) =====", re.MULTILINE)
    dacapoTime = re.compile(r"===== DaCapo 9\.12 (?P<benchmark>[a-zA-Z0-9_]+) PASSED in (?P<time>[0-9]+) msec =====")
    dacapoTime1 = re.compile(r"===== DaCapo 9\.12 (?P<benchmark>[a-zA-Z0-9_]+) completed warmup 1 in (?P<time>[0-9]+) msec =====")

    dacapoMatcher = ValuesMatcher(dacapoTime, {'group' : 'DaCapo', 'name' : '<benchmark>', 'score' : '<time>'})
    dacapoMatcher1 = ValuesMatcher(dacapoTime1, {'group' : 'DaCapo-1stRun', 'name' : '<benchmark>', 'score' : '<time>'})

    return Test("DaCapo-" + name, ['-jar', mx._cygpathU2W(dacapo), name] + _noneAsEmptyList(dacapoArgs), [dacapoSuccess], [dacapoFail], [dacapoMatcher, dacapoMatcher1], ['-Xms2g', '-XX:+' + gc, '-XX:-UseCompressedOops'])
Exemplo n.º 21
0
def getScalaDacapo(name, dacapoArgs=None, extraVmArguments=None):
    dacapo = mx.get_env('DACAPO_SCALA_CP')
    if dacapo is None:
        l = mx.library('DACAPO_SCALA', False)
        if l is not None:
            dacapo = l.get_path(True)
        else:
            mx.abort(
                'Scala DaCapo 0.1.0 jar file must be specified with DACAPO_SCALA_CP environment variable or as DACAPO_SCALA library'
            )

    if not isfile(dacapo) or not dacapo.endswith('.jar'):
        mx.abort(
            'Specified Scala DaCapo jar file does not exist or is not a jar file: '
            + dacapo)

    dacapoSuccess = re.compile(
        r"^===== DaCapo 0\.1\.0(-SNAPSHOT)? ([a-zA-Z0-9_]+) PASSED in ([0-9]+) msec =====",
        re.MULTILINE)
    dacapoFail = re.compile(
        r"^===== DaCapo 0\.1\.0(-SNAPSHOT)? ([a-zA-Z0-9_]+) FAILED (warmup|) =====",
        re.MULTILINE)
    dacapoTime = re.compile(
        r"===== DaCapo 0\.1\.0(-SNAPSHOT)? (?P<benchmark>[a-zA-Z0-9_]+) PASSED in (?P<time>[0-9]+) msec ====="
    )

    dacapoMatcher = ValuesMatcher(dacapoTime, {
        'group': "Scala-DaCapo",
        'name': '<benchmark>',
        'score': '<time>'
    })

    return Test("Scala-DaCapo-" + name,
                ['-jar', mx._cygpathU2W(dacapo), name] +
                _noneAsEmptyList(dacapoArgs), [dacapoSuccess], [dacapoFail],
                [dacapoMatcher],
                ['-Xms2g', '-XX:+' + gc, '-XX:-UseCompressedOops'] +
                _noneAsEmptyList(extraVmArguments))
Exemplo n.º 22
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
Exemplo n.º 23
0
    def harness(unittestCp, vmLauncher, vmArgs):
        prefixArgs = ['-esa', '-ea']
        if gc_after_test:
            prefixArgs.append('-XX:-DisableExplicitGC')
        with open(testfile) as fp:
            testclasses = [l.rstrip() for l in fp.readlines()]

        cp = prefixCp + coreCp + os.pathsep + unittestCp

        # suppress menubar and dock when running on Mac
        vmArgs = prefixArgs + ['-Djava.awt.headless=true'] + vmArgs + [
            '-cp', mx._separatedCygpathU2W(cp)
        ]
        # Execute Junit directly when one test is being run. This simplifies
        # replaying the VM execution in a native debugger (e.g., gdb).
        mainClassArgs = coreArgs + (testclasses if len(testclasses) == 1 else
                                    ['@' + mx._cygpathU2W(testfile)])

        config = (vmArgs, mainClass, mainClassArgs)
        for p in _config_participants:
            config = p(config)

        vmLauncher.launcher(*config)
Exemplo n.º 24
0
def findbugs(args, fbArgs=None, suite=None, projects=None):
    """run FindBugs against non-test Java projects"""
    findBugsHome = mx.get_env('FINDBUGS_HOME', None)
    if suite is None:
        suite = mx.primary_suite()
    if findBugsHome:
        findbugsJar = join(findBugsHome, 'lib', 'findbugs.jar')
    else:
        findbugsLib = join(mx._mx_suite.get_output_root(), 'findbugs-3.0.0')
        if not exists(findbugsLib):
            tmp = tempfile.mkdtemp(prefix='findbugs-download-tmp', dir=mx._mx_suite.dir)
            try:
                findbugsDist = mx.library('FINDBUGS_DIST').get_path(resolve=True)
                with zipfile.ZipFile(findbugsDist) as zf:
                    candidates = [e for e in zf.namelist() if e.endswith('/lib/findbugs.jar')]
                    assert len(candidates) == 1, candidates
                    libDirInZip = os.path.dirname(candidates[0])
                    zf.extractall(tmp)
                shutil.copytree(join(tmp, libDirInZip), findbugsLib)
            finally:
                shutil.rmtree(tmp)
        findbugsJar = join(findbugsLib, 'findbugs.jar')
    assert exists(findbugsJar)
    projectsToTest = [p for p in mx.projects() if _should_test_project(p)]
    if not projectsToTest:
        return 0

    ignoredClasses = set()
    for p in projectsToTest:
        ignore = getattr(p, 'findbugsIgnoresGenerated', False)
        if not isinstance(ignore, bool):
            mx.abort('Value of attribute "findbugsIgnoresGenerated" must be True or False', context=p)
        if ignore is True:
            sourceDir = p.source_gen_dir()
            for root, _, files in os.walk(sourceDir):
                for name in files:
                    if name.endswith('.java') and '-info' not in name:
                        pkg = root[len(sourceDir) + 1:].replace(os.sep, '.')
                        cls = pkg + '.' + name[:-len('.java')]
                        ignoredClasses.add(cls)

    with tempfile.NamedTemporaryFile(suffix='.xml', prefix='findbugs_exclude_filter.', mode='w', delete=False) as fp:
        findbugsExcludeFilterFile = fp.name
        xmlDoc = mx.XMLDoc()
        xmlDoc.open('FindBugsFilter')
        # Javac from JDK11 might have been used to compile the classes so
        # disable the check for redundant null tests since FindBugs does
        # not (yet) detect and suppress warnings about patterns generated by
        # this version of javac. This will be removed once
        # https://github.com/spotbugs/spotbugs/issues/600 is resolved.
        xmlDoc.open('Match')
        xmlDoc.element('Bug', attributes={'pattern' : 'RCN_REDUNDANT_NULLCHECK_WOULD_HAVE_BEEN_A_NPE'})
        xmlDoc.close('Match')
        for cls in ignoredClasses:
            xmlDoc.open('Match')
            xmlDoc.element('Class', attributes={'name' : '~' + cls + '.*'})
            xmlDoc.close('Match')
        xmlDoc.close('FindBugsFilter')
        xml = xmlDoc.xml(indent='  ', newl='\n')
        print >> fp, xml

    outputDirs = map(mx._cygpathU2W, [p.output_dir() for p in projectsToTest])
    javaCompliance = max([p.javaCompliance for p in projectsToTest])
    jdk = mx.get_jdk(javaCompliance)
    if jdk.javaCompliance >= '9':
        mx.log('FindBugs does not yet support JDK9 - skipping')
        return 0

    findbugsResults = join(suite.dir, 'findbugs.results')

    if fbArgs is None:
        fbArgs = defaultFindbugsArgs()
    cmd = ['-jar', mx._cygpathU2W(findbugsJar)] + fbArgs
    cmd = cmd + ['-exclude', findbugsExcludeFilterFile]
    cmd = cmd + ['-auxclasspath', mx._separatedCygpathU2W(mx.classpath([p.name for p in projectsToTest], jdk=jdk)), '-output', mx._cygpathU2W(findbugsResults), '-exitcode'] + args + outputDirs
    try:
        exitcode = mx.run_java(cmd, nonZeroIsFatal=False, jdk=jdk)
    finally:
        os.unlink(findbugsExcludeFilterFile)
    if exitcode != 0:
        with open(findbugsResults) as fp:
            mx.log(fp.read())
    os.unlink(findbugsResults)
    return exitcode
Exemplo n.º 25
0
def _sigtest_check(checktype, args, suite=None, projects=None):
    """run sigtest against Java projects with API"""
    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:
        sigtestlib = p.suite.getMxCompatibility().get_sigtest_jar()
        sigtestResults = p.dir + os.sep + 'snapshot.sigtest'
        if not os.path.exists(sigtestResults):
            continue
        jdk = mx.get_jdk(javaCompliance)
        cmd = [
            '-cp',
            mx._cygpathU2W(sigtestlib),
            'com.sun.tdk.signaturetest.SignatureTest',
            '-BootCP',
            '-Static',
            '-Mode',
            'bin',
            '-FileName',
            sigtestResults,
            '-ClassPath',
            mx.classpath(p, jdk=jdk),
        ]
        if args.human:
            cmd.append('-H')
        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:
        print(
            '\nThe signature check detected changes in the API by comparing it with previous signature files.'
        )
        print(
            'To fix this restore the original API or regenerate the signature files with:'
        )
        print('mx sigtest --generate')
        mx.abort('Signature error in ' + failed)
    else:
        print('OK.')
    return 0
Exemplo n.º 26
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
        jdk = mx.get_jdk(javaCompliance)
        cmd = [
            '-cp',
            mx._cygpathU2W(sigtestlib),
            'com.sun.tdk.signaturetest.SignatureTest',
            '-Static',
            '-Mode',
            'bin',
            '-FileName',
            sigtestResults,
            '-ClassPath',
            mx.classpath(p, jdk=jdk) + os.pathsep + jdk.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
Exemplo n.º 27
0
def _sigtest_generate(args, suite=None, projects=None):
    """run sigtest generator for Java projects with API"""
    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:
        sigtestlib = p.suite.getMxCompatibility().get_sigtest_jar()
        sigtestResults = p.dir + os.sep + 'snapshot.sigtest'
        jdk = mx.get_jdk(javaCompliance)
        cp = mx.classpath(p, jdk=jdk)
        cmd = [
            '-cp',
            mx._cygpathU2W(sigtestlib),
            'com.sun.tdk.signaturetest.Setup',
            '-BootCP',
            '-Static',
            '-FileName',
            sigtestResults,
            '-ClassPath',
            cp,
        ]
        if args.human:
            cmd.append('-H')

        infos = set()
        packages = mx._find_packages(p, packageInfos=infos)
        for pkg in packages:
            cmd = cmd + ['-PackageWithoutSubpackages', pkg]

        javapExe = jdk.javap
        if not exists(javapExe):
            mx.abort('The javap executable does not exist: ' + javapExe)

        class OutputCapture:
            def __init__(self):
                self.data = ""

            def __call__(self, data):
                self.data += data

        for pkg in infos:
            oc = OutputCapture()
            ignore = OutputCapture()
            code = mx.run([
                javapExe, '-private', '-verbose', '-classpath', cp,
                pkg + '.package-info'
            ],
                          out=oc,
                          err=ignore,
                          nonZeroIsFatal=False)
            if code == 0:
                if oc.data.find('\nRuntimeVisibleAnnotations:\n'
                                ) == -1 and oc.data.find(
                                    '\nRuntimeInvisibleAnnotations:\n') == -1:
                    mx.abort(
                        'GR-22788: ecj generated an empty {}.package-info: rebuild with javac!'
                        .format(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
Exemplo n.º 28
0
 def cmd():
     if isinstance(dacapo, mx.Library):
         path = dacapo.get_path(True)
     else:
         path = dacapo
     return ['-jar', mx._cygpathU2W(path), name] + _noneAsEmptyList(dacapoArgs)