Package org.jboss.byteman.rule

Examples of org.jboss.byteman.rule.Rule


     * @param triggerMethodDescriptor
     */
    public void fail(String failMessage, String triggerMethodName, String triggerMethodDescriptor)
    {
        String key = getRuleKey(triggerMethodName, triggerMethodDescriptor);
        Rule rule = ruleMap.get(key);
        String message = failMessage + " for method " + triggerMethodName + TypeHelper.internalizeDescriptor(triggerMethodDescriptor);
        TypeException te = new TypeException(message);
        ruleScript.recordTransform(loader, triggerClassName, triggerMethodName, triggerMethodDescriptor, rule, te);

        purgeRules();
View Full Code Here


        }

        for (String key : ruleMap.keySet()) {
            String triggerMethodName = getKeyTriggerMethodName(key);
            String triggerMethodDescriptor = getKeyTriggerMethodDescriptor(key);
            Rule rule = ruleMap.get(key);
            if (!ruleScript.recordTransform(loader, triggerClassName, triggerMethodName, triggerMethodDescriptor, rule, null))
            {
                // rule script must have been deleted so purge rules and avoid installing the transformed code
                purgeRules();
View Full Code Here

            if (script.hasTransform(targetClass)) {
                List<Transform> transforms = script.getTransformed();
                int numTransforms = transforms.size();
                for (Transform transform : transforms) {
                    Throwable throwable = transform.getThrowable();
                    Rule rule = transform.getRule();
                    String methodName = transform.getTriggerMethodName();

                    if (throwable != null) {
                        if (throwable  instanceof ParseException) {
                            parseError("ERROR : Failed to parse rule \"" + script.getName() + "\" loaded from " + script.getFile() + " line " + script.getLine(), throwable);
                        } else if (throwable instanceof TypeWarningException) {
                            typeWarning("WARNING : Problem type checking rule \"" + script.getName() + "\" loaded from " + script.getFile() + " line " + script.getLine() + (methodName == null ? "" : " against method " + methodName), throwable);
                        } else if (throwable instanceof TypeException) {
                            typeError("ERROR : Failed to type check rule \"" + script.getName() + "\" loaded from " + script.getFile() + " line " + script.getLine() + (methodName == null ? "" : " against method " + methodName), throwable);
                        } else {
                            error("ERROR : Unexpected exception transforming class " + targetClassName + " using  rule \"" + script.getName() + "\" loaded from " + script.getFile() + " line " + script.getLine() + (methodName == null ? "" : " against method " + methodName), throwable);
                        }
                        continue;
                    }

                    infoMessage = "Parsed rule \"" + script.getName() + "\" for class " + transform.getInternalClassName();

                    if (verbose) {
                        infoMessage += "# File " + script.getFile() + " line " + script.getLine() + "\n";
                        infoMessage += rule;
                    }

                    info(infoMessage);

                    // ok, now see if we can type check the rule

                    try {
                        rule.typeCheck();
                        rule.compile();
                    } catch (TypeWarningException te) {
                        typeWarning("WARNING : Unable to type check rule \"" + script.getName() + "\" loaded from " + script.getFile() + " line " + script.getLine() + (methodName == null ? "" : " against method " + methodName), te);
                        continue;
                    } catch (TypeException te) {
                        typeError("ERROR : Failed to type check rule \"" + script.getName() + "\" loaded from " + script.getFile() + " line " + script.getLine() + (methodName == null ? "" : " against method " + methodName), te);
                        continue;
                    } catch (CompileException ce) {
                        typeError("ERROR : Failed to compile rule \"" + script.getName() + "\" loaded from " + script.getFile() + " line " + script.getLine() + (methodName == null ? "" : " against method " + methodName), ce);
                        continue;
                    }

                    if (script.isOverride()) {
                        info("Type checked overriding rule \"" + script.getName() + "\" against method in declared class");
                    } else {
                        info("Type checked rule \"" + script.getName() + "\"");
                    }
                }
            } else if (targetClass.isInterface() || script.isOverride()) {
                // ok, not necessarily a surprise - let's see if we can create a rule and parse/type check it
                final Rule rule;
                try {
                    rule = Rule.create(script, loader, null);
                } catch (ParseException pe) {
                    parseError("ERROR : Failed to type check rule \"" + script.getName() + "\" loaded from " + script.getFile() + " line " + script.getLine(), pe);
                    continue;
View Full Code Here

            return cw.toByteArray();
        }
    }

    public void parseRule() throws Exception {
        Rule rule = Rule.create(ruleScript, loader, helperManager);
        // stash this rule away under the class name so we can reuse it for the first matching method
        ruleMap.put(triggerClassName, rule);
        // keep a handle on the first rule
        firstRule = rule;
    }
View Full Code Here

    {
        String key = getRuleKey(triggerMethodName, triggerMethodDescriptor);

        // use the initially parsed rule if we can otherwise create one

        Rule rule = ruleMap.remove(triggerClassName);

        if (rule == null) {
            try {
                rule = Rule.create(ruleScript, loader, helperManager);
            } catch(Throwable th) {
View Full Code Here

     */
    public void warn(String triggerMethodName, String triggerMethodDescriptor, String warningMessage)
    {
        // remove the rule so that we don't try to inject into this method
        String key = getRuleKey(triggerMethodName, triggerMethodDescriptor);
        Rule rule = ruleMap.remove(key);
        // now attach an exception to the rule script
        String message = warningMessage + " for method " + triggerMethodName + TypeHelper.internalizeDescriptor(triggerMethodDescriptor);
        TypeWarningException tw = new TypeWarningException(message);
        ruleScript.recordTransform(loader, triggerClassName, triggerMethodName, triggerMethodDescriptor, rule, tw);
    }
View Full Code Here

     * @param triggerMethodDescriptor
     */
    public void fail(String failMessage, String triggerMethodName, String triggerMethodDescriptor)
    {
        String key = getRuleKey(triggerMethodName, triggerMethodDescriptor);
        Rule rule = ruleMap.get(key);
        String message = failMessage + " for method " + triggerMethodName + TypeHelper.internalizeDescriptor(triggerMethodDescriptor);
        TypeException te = new TypeException(message);
        ruleScript.recordTransform(loader, triggerClassName, triggerMethodName, triggerMethodDescriptor, rule, te);

        purgeRules();
View Full Code Here

        }

        for (String key : ruleMap.keySet()) {
            String triggerMethodName = getKeyTriggerMethodName(key);
            String triggerMethodDescriptor = getKeyTriggerMethodDescriptor(key);
            Rule rule = ruleMap.get(key);
            if (!ruleScript.recordTransform(loader, triggerClassName, triggerMethodName, triggerMethodDescriptor, rule, null))
            {
                // rule script must have been deleted so purge rules and avoid installing the transformed code
                purgeRules();
View Full Code Here

            if (script.hasTransform(targetClass)) {
                List<Transform> transforms = script.getTransformed();
                int numTransforms = transforms.size();
                for (Transform transform : transforms) {
                    Throwable throwable = transform.getThrowable();
                    Rule rule = transform.getRule();

                    if (throwable != null) {
                        if (throwable  instanceof ParseException) {
                            System.out.println("ERROR : Failed to parse rule \"" + script.getName() + "\" loaded from " + script.getFile() + " line " + script.getLine());
                            System.out.println();
                            parseErrorCount++;
                            errorCount++;
                        } else if (throwable instanceof TypeWarningException) {
                            System.out.println("WARNING : Unable to type check rule \"" + script.getName() + "\" loaded from " + script.getFile() + " line " + script.getLine());
                            System.out.println();
                            typeWarningCount++;
                            warningCount++;
                        } else if (throwable instanceof TypeException) {
                            System.out.println("ERROR : Failed to type check rule \"" + script.getName() + "\" loaded from " + script.getFile() + " line " + script.getLine());
                            System.out.println();
                            typeErrorCount++;
                            errorCount++;
                        } else {
                            System.out.println("ERROR : Unexpected exception transforming class " + targetClassName + " using  rule \"" + script.getName() + "\" loaded from " + script.getFile() + " line " + script.getLine());
                            System.out.println();
                            errorCount++;
                        }
                        throwable.printStackTrace(System.out);
                        System.out.println();
                        continue;
                    }

                    System.out.println("parsed rule \"" + script.getName() + "\" for class " + transform.getInternalClassName());

                    if (verbose) {
                        System.out.println("# File " + script.getFile() + " line " + script.getLine());
                        System.out.println(rule);
                    }

                    // ok, now see if we can type check the rule

                    try {
                        rule.typeCheck();
                    } catch (TypeWarningException te) {
                        System.out.println("WARNING : Unable to type check rule \"" + script.getName() + "\" loaded from " + script.getFile() + " line " + script.getLine());
                        typeWarningCount++;
                        warningCount++;
                        te.printStackTrace(System.out);
                        System.out.println();
                        continue;
                    } catch (TypeException te) {
                        System.out.println("ERROR : Failed to type check rule \"" + script.getName() + "\" loaded from " + script.getFile() + " line " + script.getLine());
                        typeErrorCount++;
                        errorCount++;
                        te.printStackTrace(System.out);
                        System.out.println();
                        continue;
                    }

                    if (script.isOverride()) {
                        System.out.println("type checked overriding rule \"" + script.getName() + "\" against method in declared class");
                    } else {
                        System.out.println("type checked rule \"" + script.getName() + "\"");
                    }
                    System.out.println();
                }
            } else if (targetClass.isInterface() || script.isOverride()) {
                // ok, not necessarily a surprise - let's see if we can create a rule and parse/type check it
                final Rule rule;
                try {
                    rule = Rule.create(script, loader, null);
                } catch (ParseException pe) {
                    System.out.println("ERROR : Failed to type check rule \"" + script.getName() + "\" loaded from " + script.getFile() + " line " + script.getLine());
                    parseErrorCount++;
View Full Code Here

    }

    public void parseRule() throws Throwable
    {
        try {
            Rule rule = Rule.create(ruleScript, loader, helperManager);
            // stash this rule away under the class name so we can reuse it for the first matching method
            ruleMap.put(triggerClass, rule);
        } catch (Throwable th) {
            recordFailedTransform(th);
            throw th;
View Full Code Here

TOP

Related Classes of org.jboss.byteman.rule.Rule

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.