[rfc][icedtea-web] closing listener idea

Jiri Vanek jvanek at redhat.com
Mon Sep 24 08:20:35 PDT 2012


On 09/24/2012 04:24 PM, Jiri Vanek wrote:
> On 09/20/2012 04:58 PM, Adam Domurad wrote:
>>
>>>>> inclined to agree. Overall, I'm starting to think that a standard,
>>>>> magic, "**APPLET FINISHED**" string copypasted into every applet is the
> ...
>>
>>
>>> diff -r d23356f8a7a6
>>> tests/reproducers/signed/AppletTestSigned/testcases/AppletTestSignedTests.java
>>> ---
>>> a/tests/reproducers/signed/AppletTestSigned/testcases/AppletTestSignedTests.java    Thu Sep 20
>>> 10:55:16 2012 +0200
>>> +++
>>> b/tests/reproducers/signed/AppletTestSigned/testcases/AppletTestSignedTests.java    Thu Sep 20
>>> 12:03:40 2012 +0200
>>> @@ -43,6 +43,8 @@
>>>   import net.sourceforge.jnlp.browsertesting.BrowserTest;
>>>   import net.sourceforge.jnlp.browsertesting.Browsers;
>>>   import net.sourceforge.jnlp.annotations.TestInBrowsers;
>>> +import net.sourceforge.jnlp.closinglisteners.Rule;
>>> +import
>>> net.sourceforge.jnlp.closinglisteners.RulesFolowingClosingListener;
>>>   import org.junit.Assert;
>>>
>>>   import org.junit.Test;
>>> @@ -50,8 +52,22 @@
>>>   public class AppletTestSignedTests extends BrowserTest {
>>>
>>>       private final List<String> l =
>>> Collections.unmodifiableList(Arrays.asList(new
>>> String[]{"-Xtrustall"}));
>>> +    private static final String ss = "xception";
>>> +    private static final String s0 = "AppletTestSigned was started";
>>> +    private static final String s1 = "value1";
>>> +    private static final String s2 = "value2";
>>> +    private static final String s3 = "AppletTestSigned was
>>> initialised";
>>> +    private static final String s7 = "AppletTestSigned killing
>>> himself after 2000 ms of life";
>>> +    private static final RulesFolowingClosingListener.ContainsRule
>>> crss = new RulesFolowingClosingListener.ContainsRule(ss);
>> Still a bit of verbosity here that is just a little off-putting (mainly
>> because of Java requiring type twice to be honest - once in declaration
>> and once in initialization :).
>
> I would rather stay off renaming of old variables in this patch (not reefactoring one), although I
> agree with ...
>
>> The part that's supposed to be the most
>> meaningful (the variable name) has the least verbosity.
>
> ... ^this :)
>
> So I have refactored ruels name.
>
>> It would be a
>> bit better I think if the line read something like:
>> private static final Rule exceptionRule = new ContainsRule(ss);
>>
>> Note that this doesn't require you to move the ContainsRule class, but
>> simply import RulesFolowingClosingListener.ContainsRule;
>
> sure, done
>
>>
>>> +    private static final RulesFolowingClosingListener.ContainsRule
>>> s0ss = new RulesFolowingClosingListener.ContainsRule(s0);
>>> +    private static final RulesFolowingClosingListener.ContainsRule
>>> s1ss = new RulesFolowingClosingListener.ContainsRule(s1);
>>> +    private static final RulesFolowingClosingListener.ContainsRule
>>> s2ss = new RulesFolowingClosingListener.ContainsRule(s2);
>>> +    private static final RulesFolowingClosingListener.ContainsRule
>>> s3ss = new RulesFolowingClosingListener.ContainsRule(s3);
>>> +    private static final RulesFolowingClosingListener.ContainsRule
>>> s7ss = new RulesFolowingClosingListener.ContainsRule(s7);
>>> +    private static final Rule[] okRules = new Rule[]{s0ss, s1ss,
>>> s2ss, s3ss, s7ss};
>>> +    private static final Rule[] errorRrules = new Rule[]{crss};
>> Rrules -> Rules
>>>
>>> -    @Test
>>> +   // @Test
>>>       public void AppletTestSignedTest() throws Exception {
>>>           ProcessResult pr = server.executeJavawsHeadless(l,
>>> "/AppletTestSigned.jnlp");
>>>           evaluateSignedApplet(pr, true);
>>> @@ -60,18 +76,12 @@
>>>       }
>>>
>>>       private void evaluateSignedApplet(ProcessResult pr, boolean
>>> javawsApplet) {
>>> -        String s3 = "AppletTestSigned was initialised";
>>> -        Assert.assertTrue("AppletTestSigned stdout should contain " +
>>> s3 + " but didn't", pr.stdout.contains(s3));
>>> -        String s0 = "AppletTestSigned was started";
>>> -        Assert.assertTrue("AppletTestSigned stdout should contain " +
>>> s0 + " but didn't", pr.stdout.contains(s0));
>>> -        String s1 = "value1";
>>> -        Assert.assertTrue("AppletTestSigned stdout should contain " +
>>> s1 + " but didn't", pr.stdout.contains(s1));
>>> -        String s2 = "value2";
>>> -        Assert.assertTrue("AppletTestSigned stdout should contain " +
>>> s2 + " but didn't", pr.stdout.contains(s2));
>>> -        String ss = "xception";
>>> -        Assert.assertFalse("AppletTestSigned stderr should not
>>> contain " + ss + " but did", pr.stderr.contains(ss));
>>> -        String s7 = "AppletTestSigned killing himself after 2000 ms
>>> of life";
>>> -        Assert.assertTrue("AppletTestSigned stdout should contain " +
>>> s7 + " but didn't", pr.stdout.contains(s7));
>>> +        Assert.assertTrue("AppletTestSigned stdout " +
>>> s3ss.toString() + " but didn't", s3ss.evaluate(pr.stdout));
>>> +        Assert.assertTrue("AppletTestSigned stdout " +
>>> s0ss.toString() + " but didn't", s0ss.evaluate(pr.stdout));
>>> +        Assert.assertTrue("AppletTestSigned stdout " +
>>> s1ss.toString() + " but didn't", s1ss.evaluate(pr.stdout));
>>> +        Assert.assertTrue("AppletTestSigned stdout " +
>>> s2ss.toString() + " but didn't", s2ss.evaluate(pr.stdout));
>>> +        Assert.assertFalse("AppletTestSigned stderr " +
>>> crss.toNotString() + " but did", crss.evaluate(pr.stderr));
>>> +        Assert.assertTrue("AppletTestSigned stdout " +
>>> s7ss.toString() + " but didn't", s7ss.evaluate(pr.stdout));
>>>           if (!javawsApplet) {
>>>               /*this is working correctly in most browser, but not in
>>> all. temporarily disabling
>>>               String s4 = "AppletTestSigned was stopped";
>>> @@ -87,7 +97,7 @@
>>>       public void AppletTestSignedFirefoxTestXslowX() throws Exception
>>> {
>>>           ServerAccess.PROCESS_TIMEOUT = 30 * 1000;
>>>           try {
>>> -            ProcessResult pr =
>>> server.executeBrowser("/AppletTestSigned2.html");
>>> +            ProcessResult pr =
>>> server.executeBrowser("/AppletTestSigned2.html",new
>>> RulesFolowingClosingListener(okRules),new
>>> RulesFolowingClosingListener(errorRrules));
>>>               evaluateSignedApplet(pr, false);
>>>               //Assert.assertTrue(pr.wasTerminated);
>>>               //Assert.assertEquals((Integer) 0, pr.returnValue); due
>>> to destroy is null
>>> diff -r d23356f8a7a6
>>> tests/reproducers/simple/AppletTest/testcases/AppletTestTests.java
>>> ---
>>> a/tests/reproducers/simple/AppletTest/testcases/AppletTestTests.java        Thu Sep 20 10:55:16
>>> 2012 +0200
>>> +++
>>> b/tests/reproducers/simple/AppletTest/testcases/AppletTestTests.java        Thu Sep 20 12:03:40
>>> 2012 +0200
>>> @@ -35,6 +35,7 @@
>>>   exception statement from your version.
>>>    */
>>>
>>> +import net.sourceforge.jnlp.closinglisteners.CountingClosingListener;
>>>   import net.sourceforge.jnlp.ProcessResult;
>>>   import net.sourceforge.jnlp.ServerAccess;
>>>   import net.sourceforge.jnlp.browsertesting.BrowserTest;
>>> @@ -47,6 +48,24 @@
>>>
>>>   public class AppletTestTests extends BrowserTest {
>>>
>>> +    private final String s7 = "Aplet killing himself after 2000 ms of
>>> life";
>> Aplet -> Applet (Is there another occurence of this typo ?)
>
> I let it be intentionally, it is also in src and more tests depend on it.
>
>>> +    private final String ss = "xception";
>> I'm wondering what case this covers as opposed to "Exception" ? It's
>> fine though, as there are no other english words that end in xception :)
>>> +    private final String s2 = "value2";
>>> +    private final String s1 = "value1";
>>> +    private final String s0 = "applet was started";
>>> +    private final String s3 = "applet was initialised";
>>> +
>>> +    private class CountingClosingListenerImpl extends
>>> CountingClosingListener {
>>> +
>>> +        @Override
>>> +        protected boolean isAlowedToFinish(String s) {
>>> +            if (s.contains(ss)) {
>>> +                return true;
>>> +            }
>>> +            return (s.contains(s0) && s.contains(s1) &&
>>> s.contains(s2) && s.contains(s3) && s.contains(s7));
>>> +        }
>>> +    }
>>> +
>>>       @Test
>>>       @TestInBrowsers(testIn = {Browsers.googleChrome})
>>>       @NeedsDisplay
>>> @@ -55,7 +74,7 @@
>>>           try {
>>>               //System.out.println("connecting AppletInFirefoxTest
>>> request in " + getBrowser().toString());
>>>               //just verify loging is recording browser
>>> -            ProcessResult pr1 =
>>> server.executeBrowser("/appletAutoTests.html");
>>> +            ProcessResult pr1 =
>>> server.executeBrowser("/appletAutoTests2.html", new
>>> CountingClosingListenerImpl(), new CountingClosingListenerImpl());
>>>               if (pr1.process == null) {
>>>                   Assert.assertTrue("If proces was null here, then
>>> google-chrome had to not exist, and so "
>>>                           + ServerAccess.UNSET_BROWSER
>>> @@ -64,12 +83,12 @@
>>>
>>> pr1.deadlyException.getMessage().contains(ServerAccess.UNSET_BROWSER));
>>>                   return;
>>>               }
>>> -            evaluateApplet(pr1,false);
>>> +            evaluateApplet(pr1, false);
>>>               Assert.assertTrue(pr1.wasTerminated);
>>>               //System.out.println("connecting AppletInFirefoxTest
>>> request in " + getBrowser().toString());
>>>               // just verify loging is recording browser
>>> -            ServerAccess.ProcessResult pr =
>>> server.executeBrowser("/appletAutoTests.html");
>>> -            evaluateApplet(pr,false);
>>> +            ServerAccess.ProcessResult pr =
>>> server.executeBrowser("/appletAutoTests2.html", new
>>> CountingClosingListenerImpl(), new CountingClosingListenerImpl());
>>> +            evaluateApplet(pr, false);
>>>               Assert.assertTrue(pr.wasTerminated);
>>>           } finally {
>>>               ServerAccess.PROCESS_TIMEOUT = 20 * 1000; //back to
>>> normal
>>> @@ -80,30 +99,24 @@
>>>       @NeedsDisplay
>>>       public void AppletTest() throws Exception {
>>>           ProcessResult pr = server.executeJavawsHeadless(null,
>>> "/AppletTest.jnlp");
>>> -        evaluateApplet(pr,true);
>>> +        evaluateApplet(pr, true);
>>>           Assert.assertFalse(pr.wasTerminated);
>>>           Assert.assertEquals((Integer) 0, pr.returnValue);
>>>       }
>>>
>>>       private void evaluateApplet(ProcessResult pr, boolean
>>> javawsApplet) {
>>> -        String s3 = "applet was initialised";
>>>           Assert.assertTrue("AppletTest stdout should contains " + s3 +
>>> " bud didn't", pr.stdout.contains(s3));
>>> -        String s0 = "applet was started";
>>>           Assert.assertTrue("AppletTest stdout should contains " + s0 +
>>> " bud didn't", pr.stdout.contains(s0));
>>> -        String s1 = "value1";
>>>           Assert.assertTrue("AppletTest stdout should contains " + s1 +
>>> " bud didn't", pr.stdout.contains(s1));
>>> -        String s2 = "value2";
>>>           Assert.assertTrue("AppletTest stdout should contains " + s2 +
>>> " bud didn't", pr.stdout.contains(s2));
>>> -        String ss = "xception";
>>>           Assert.assertFalse("AppletTest stderr should not contains " +
>>> ss + " but did", pr.stderr.contains(ss));
>>> -        String s7 = "Aplet killing himself after 2000 ms of life";
>>>           Assert.assertTrue("AppletTest stdout should contains " + s7 +
>>> " bud didn't", pr.stdout.contains(s7));
>>>           if (!javawsApplet) {
>>>               /*this is working correctly in most browser, but not in
>>> all. temporarily disabling
>>> -        String s4 = "applet was stopped";
>>> -        Assert.assertTrue("AppletTest stdout should contains " + s4 +
>>> " bud did't", pr.stdout.contains(s4));
>>> -        String s5 = "applet will be destroyed";
>>> -        Assert.assertTrue("AppletTest stdout should contains " + s5 +
>>> " bud did't", pr.stdout.contains(s5));
>>> +            String s4 = "applet was stopped";
>>> +            Assert.assertTrue("AppletTest stdout should contains " +
>>> s4 + " bud did't", pr.stdout.contains(s4));
>>> +            String s5 = "applet will be destroyed";
>>> +            Assert.assertTrue("AppletTest stdout should contains " +
>>> s5 + " bud did't", pr.stdout.contains(s5));
>>>                */
>>>           }
>>>       }
>>> @@ -116,8 +129,8 @@
>>>           //just verify loging is recordingb rowser
>>>           ServerAccess.PROCESS_TIMEOUT = 30 * 1000;
>>>           try {
>>> -            ProcessResult pr =
>>> server.executeBrowser("/appletAutoTests2.html");
>>> -            evaluateApplet(pr,false);
>>> +            ProcessResult pr =
>>> server.executeBrowser("/appletAutoTests2.html", new
>>> CountingClosingListenerImpl(), new CountingClosingListenerImpl());
>>> +            evaluateApplet(pr, false);
>>>               Assert.assertTrue(pr.wasTerminated);
>>>               //Assert.assertEquals((Integer) 0, pr.returnValue); due
>>> to destroy is null
>>>           } finally {
>>> @@ -132,9 +145,9 @@
>>>           //just verify loging is recording browser
>>>           ServerAccess.PROCESS_TIMEOUT = 30 * 1000;
>>>           try {
>>> -            ProcessResult pr =
>>> server.executeBrowser("/appletAutoTests.html");
>>> +            ProcessResult pr =
>>> server.executeBrowser("/appletAutoTests.html", new
>>> CountingClosingListenerImpl(), new CountingClosingListenerImpl());
>>>               pr.process.destroy();
>>> -            evaluateApplet(pr,false);
>>> +            evaluateApplet(pr, false);
>>>               Assert.assertTrue(pr.wasTerminated);
>>>               //Assert.assertEquals((Integer) 0, pr.returnValue); due
>>> to destroy is null
>>>           } finally {
>>> diff -r d23356f8a7a6
>>> tests/test-extensions/net/sourceforge/jnlp/closinglisteners/CountingClosingListener.java
>>> --- /dev/null   Thu Jan 01 00:00:00 1970 +0000
>>> +++
>>> b/tests/test-extensions/net/sourceforge/jnlp/closinglisteners/CountingClosingListener.java  Thu
>>> Sep 20 12:03:40 2012 +0200
>>> @@ -0,0 +1,60 @@
>>> +/* CountingClosingListener.java
>>> +Copyright (C) 2012 Red Hat, Inc.
>>> +
>>> +This file is part of IcedTea.
>>> +
>>> +IcedTea is free software; you can redistribute it and/or
>>> +modify it under the terms of the GNU General Public License as
>>> published by
>>> +the Free Software Foundation, version 2.
>>> +
>>> +IcedTea is distributed in the hope that it will be useful,
>>> +but WITHOUT ANY WARRANTY; without even the implied warranty of
>>> +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
>>> +General Public License for more details.
>>> +
>>> +You should have received a copy of the GNU General Public License
>>> +along with IcedTea; see the file COPYING.  If not, write to
>>> +the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
>>> Boston, MA
>>> +02110-1301 USA.
>>> +
>>> +Linking this library statically or dynamically with other modules is
>>> +making a combined work based on this library.  Thus, the terms and
>>> +conditions of the GNU General Public License cover the whole
>>> +combination.
>>> +
>>> +As a special exception, the copyright holders of this library give
>>> you
>>> +permission to link this library with independent modules to produce
>>> an
>>> +executable, regardless of the license terms of these independent
>>> +modules, and to copy and distribute the resulting executable under
>>> +terms of your choice, provided that you also meet, for each linked
>>> +independent module, the terms and conditions of the license of that
>>> +module.  An independent module is a module which is not derived from
>>> +or based on this library.  If you modify this library, you may extend
>>> +this exception to your version of the library, but you are not
>>> +obligated to do so.  If you do not wish to do so, delete this
>>> +exception statement from your version.
>>> + */
>>> +package net.sourceforge.jnlp.closinglisteners;
>>> +
>>> +import net.sourceforge.jnlp.ClosingListener;
>>> +
>>> +public abstract class CountingClosingListener extends ClosingListener
>>> {
>>> +
>>> +    protected StringBuilder sb = new StringBuilder();
>>> +
>>> +    @Override
>>> +    public void charReaded(char ch) {
>>> +        sb.append(ch);
>>> +        if (isAlowedToFinish(sb.toString())) {
>>> +            terminate();
>>> +        }
>>> +
>>> +    }
>>> +
>>> +    @Override
>>> +    public void lineReaded(String s) {
>>> +        //nothing to do
>>> +    }
>>> +
>>> +    protected abstract boolean isAlowedToFinish(String content);
>>> +}
>>> diff -r d23356f8a7a6
>>> tests/test-extensions/net/sourceforge/jnlp/closinglisteners/Rule.java
>>> --- /dev/null   Thu Jan 01 00:00:00 1970 +0000
>>> +++
>>> b/tests/test-extensions/net/sourceforge/jnlp/closinglisteners/Rule.java     Thu Sep 20 12:03:40
>>> 2012 +0200
>>> @@ -0,0 +1,47 @@
>>> +/* Rule.java
>>> +Copyright (C) 2012 Red Hat, Inc.
>>> +
>>> +This file is part of IcedTea.
>>> +
>>> +IcedTea is free software; you can redistribute it and/or
>>> +modify it under the terms of the GNU General Public License as
>>> published by
>>> +the Free Software Foundation, version 2.
>>> +
>>> +IcedTea is distributed in the hope that it will be useful,
>>> +but WITHOUT ANY WARRANTY; without even the implied warranty of
>>> +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
>>> +General Public License for more details.
>>> +
>>> +You should have received a copy of the GNU General Public License
>>> +along with IcedTea; see the file COPYING.  If not, write to
>>> +the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
>>> Boston, MA
>>> +02110-1301 USA.
>>> +
>>> +Linking this library statically or dynamically with other modules is
>>> +making a combined work based on this library.  Thus, the terms and
>>> +conditions of the GNU General Public License cover the whole
>>> +combination.
>>> +
>>> +As a special exception, the copyright holders of this library give
>>> you
>>> +permission to link this library with independent modules to produce
>>> an
>>> +executable, regardless of the license terms of these independent
>>> +modules, and to copy and distribute the resulting executable under
>>> +terms of your choice, provided that you also meet, for each linked
>>> +independent module, the terms and conditions of the license of that
>>> +module.  An independent module is a module which is not derived from
>>> +or based on this library.  If you modify this library, you may extend
>>> +this exception to your version of the library, but you are not
>>> +obligated to do so.  If you do not wish to do so, delete this
>>> +exception statement from your version.
>>> +*/
>>> +package net.sourceforge.jnlp.closinglisteners;
>>> +
>>> +public interface Rule<S,T> {
>> Oh boy this is so generic it reminds me of the Boost C++ library :). (If
>> you're unfamiliar, almost all their types take <type> parameters.)
>
> Yap, I'm familiar, and I don like it :)
>
> However here it seemed to me useful - kept.
>
>>> +
>>> +    public void setRule(S rule);
>>> +    public boolean evaluate(T upon);
>>> +    @Override
>>> +    public String toString();
>>> +    public String toNotString();
>>> +
>>> +}
>>> diff -r d23356f8a7a6
>>> tests/test-extensions/net/sourceforge/jnlp/closinglisteners/RulesFolowingClosingListener.java
>>> --- /dev/null   Thu Jan 01 00:00:00 1970 +0000
>>> +++
>>> b/tests/test-extensions/net/sourceforge/jnlp/closinglisteners/RulesFolowingClosingListener.java
>>> Thu Sep 20 12:03:40 2012 +0200
>>> @@ -0,0 +1,238 @@
>>> +/* RulesFolowingClosingListener.java
>>> +Copyright (C) 2012 Red Hat, Inc.
>>> +
>>> +This file is part of IcedTea.
>>> +
>>> +IcedTea is free software; you can redistribute it and/or
>>> +modify it under the terms of the GNU General Public License as
>>> published by
>>> +the Free Software Foundation, version 2.
>>> +
>>> +IcedTea is distributed in the hope that it will be useful,
>>> +but WITHOUT ANY WARRANTY; without even the implied warranty of
>>> +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
>>> +General Public License for more details.
>>> +
>>> +You should have received a copy of the GNU General Public License
>>> +along with IcedTea; see the file COPYING.  If not, write to
>>> +the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
>>> Boston, MA
>>> +02110-1301 USA.
>>> +
>>> +Linking this library statically or dynamically with other modules is
>>> +making a combined work based on this library.  Thus, the terms and
>>> +conditions of the GNU General Public License cover the whole
>>> +combination.
>>> +
>>> +As a special exception, the copyright holders of this library give
>>> you
>>> +permission to link this library with independent modules to produce
>>> an
>>> +executable, regardless of the license terms of these independent
>>> +modules, and to copy and distribute the resulting executable under
>>> +terms of your choice, provided that you also meet, for each linked
>>> +independent module, the terms and conditions of the license of that
>>> +module.  An independent module is a module which is not derived from
>>> +or based on this library.  If you modify this library, you may extend
>>> +this exception to your version of the library, but you are not
>>> +obligated to do so.  If you do not wish to do so, delete this
>>> +exception statement from your version.
>>> + */
>>> +package net.sourceforge.jnlp.closinglisteners;
>>> +
>>> +import java.util.ArrayList;
>>> +import java.util.Arrays;
>>> +import java.util.List;
>>> +
>>> +public class RulesFolowingClosingListener extends
>>> CountingClosingListener {
>>> +
>>> +    private List<Rule> rules = new ArrayList<Rule>();
>>> +
>>> +    public static class ContainsRule extends StringRule<String,
>>> String> {
>>> +
>>> +        public ContainsRule(String s) {
>>> +            super(s);
>>> +        }
>> There's considerable overlap between Contains and NotContains, what do
>> you think about an inversion flag ?
>>> +
>>> +        @Override
>>> +        public boolean evaluate(String upon) {
>>> +            return (upon.contains(rule));
>>> +        }
>>> +
>>> +        @Override
>>> +        public String toString() {
>>> +            return "should contains `" + rule + "`";
>>> +        }
>> 'should contains' -> 'should contain'
> fixed in all new code
>
>> Although its a tough call, I'm inclined to say this is a bit of an abuse
>> of toString(). It's a built-in that doesn't have a natural 'opposite'
>> like you're giving it. toPassingString() and to toFailingString() might
>> be better, but feel free to leave it if it feels more natural to you.
>
> I compeltely agree. Refactored as sugested
>>> +
>>> +        @Override
>>> +        public String toNotString() {
>>> +            return "should NOT contains `" + rule + "`";
>> 'should NOT contains' -> 'should NOT contain', similar cases below
> fixed in all new code
>>> +        }
>>> +    }
>>> +
>>> +    public static class NotContainsRule extends StringRule<String,
>>> String> {
>>> +
>>> +        public NotContainsRule(String s) {
>>> +            super(s);
>>> +        }
>>> +
>>> +        @Override
>>> +        public boolean evaluate(String upon) {
>>> +            return !(upon.contains(rule));
>>> +        }
>>> +
>>> +        @Override
>>> +        public String toString() {
>>> +            return "should NOT contains `" + rule + "`";
>>> +        }
>>> +
>>> +        @Override
>>> +        public String toNotString() {
>>> +            return "should contains `" + rule + "`";
>>> +        }
>>> +    }
>>> +
>>> +    public static class MatchesRule extends StringRule<String,
>>> String> {
>>> +
>>> +        public MatchesRule(String s) {
>>> +            super(s);
>>> +        }
>>> +
>>> +        @Override
>>> +        public boolean evaluate(String upon) {
>>> +            return (upon.matches(rule));
>>> +        }
>>> +
>>> +        @Override
>>> +        public String toString() {
>>> +            return "should match `" + rule + "`";
>>> +        }
>>> +
>>> +        @Override
>>> +        public String toNotString() {
>>> +            return "should NOT match `" + rule + "`";
>>> +        }
>>> +    }
>>> +
>>> +    public static class NotMatchesRule extends StringRule<String,
>>> String> {
>>> +
>>> +        public NotMatchesRule(String s) {
>>> +            super(s);
>>> +        }
>>> +
>>> +        @Override
>>> +        public boolean evaluate(String upon) {
>>> +            return !(upon.matches(rule));
>>> +        }
>>> +
>>> +        @Override
>>> +        public String toString() {
>>> +            return "should NOT match`" + rule + "`";
>>> +        }
>>> +
>>> +        @Override
>>> +        public String toNotString() {
>>> +            return "should match`" + rule + "`";
>>> +        }
>>> +    }
>>> +
>>> +    /**
>>> +     *
>>> +     * @param rule
>>> +     * @return self, to alow chaing add(...).add(..)...
>>> +     */
>>> +    public RulesFolowingClosingListener addRule(Rule rule) {
>>> +        this.rules.add(rule);
>>> +        return this;
>>> +    }
>>> +
>>> +    /**
>>> +     *
>>> +     * @param rule
>>> +     * @return self, to alow chaing add(...).add(..)...
>>> +     */
>>> +    public RulesFolowingClosingListener addMatchingRule(String rule)
>>> {
>>> +        this.rules.add(new MatchesRule(rule));
>>> +        return this;
>>> +    }
>>> +
>>> +    /**
>>> +     *
>>> +     * @param rule
>>> +     * @return self, to alow chaing add(...).add(..)...
>>> +     */
>>> +    public RulesFolowingClosingListener addNotMatchingRule(String
>>> rule) {
>>> +        this.rules.add(new NotMatchesRule(rule));
>>> +        return this;
>>> +    }
>>> +
>>> +    /**
>>> +     *
>>> +     * @param rule
>>> +     * @return self, to alow chaing add(...).add(..)...
>>> +     */
>>> +    public RulesFolowingClosingListener addContainsRule(String rule)
>>> {
>>> +        this.rules.add(new ContainsRule(rule));
>>> +        return this;
>>> +    }
>>> +
>>> +    /**
>>> +     *
>>> +     * @param rule
>>> +     * @return self, to alow chaing add(...).add(..)...
>>> +     */
>>> +    public RulesFolowingClosingListener addNotContainsRule(String
>>> rule) {
>>> +        this.rules.add(new NotContainsRule(rule));
>>> +        return this;
>>> +    }
>>> +
>>> +    public RulesFolowingClosingListener() {
>>> +    }
>>> +
>>> +    public RulesFolowingClosingListener(List<Rule> l) {
>>> +        addRules(l);
>>> +    }
>>> +
>>> +    public RulesFolowingClosingListener(Rule[] l) {
>>> +        addRules(l);
>>> +    }
>>> +
>>> +    public void setRules(List<Rule> rules) {
>>> +        if (rules == null) {
>>> +            throw new NullPointerException("rules cant be null");
>>> +        }
>>> +        this.rules = rules;
>>> +    }
>>> +
>>> +    public void setRules(Rule[] rules) {
>>> +        if (rules == null) {
>>> +            throw new NullPointerException("rules cant be null");
>>> +        }
>>> +        this.rules = Arrays.asList(rules);
>>> +    }
>>> +
>>> +     public void addRules(List<Rule> rules) {
>>> +        if (rules == null) {
>>> +            throw new NullPointerException("rules cant be null");
>>> +        }
>>> +        this.rules.addAll(rules);
>>> +    }
>>> +
>>> +    public void addRules(Rule[] rules) {
>> Is there a reason you wouldn't want this as Rule... ? This would still
>> allow for passing an array, but allow more convenience than creating an
>> array explicitly.
>>> +        if (rules == null) {
>>> +            throw new NullPointerException("rules cant be null");
>>> +        }
>>> +        this.rules.addAll(Arrays.asList(rules));
>>> +    }
>>> +
>>> +    @Override
>>> +    protected boolean isAlowedToFinish(String content) {
>>> +        if (rules == null || rules.size() < 1) {
>>> +            throw new IllegalStateException("No rules specified");
>>> +        }
>>> +        for (Rule rule : rules) {
>>> +            if (!rule.evaluate(content)) {
>> So all rules have to match for it to close ?
>
> Yes!  And Imho it is the only correct thing to do (and reason why I'm not 100% for
> Auto*ClsoingListener)
> In case of multithread applet this will become absolutely necessary. (or to make some additional
> sync in applet, which is unnecessary overhead)
>
>>> +                return false;
>>> +            }
>>> +        }
>>> +        return true;
>>> +
>>> +
>>> +    }
>>> +}
>>> diff -r d23356f8a7a6
>>> tests/test-extensions/net/sourceforge/jnlp/closinglisteners/StringRule.java
>>> --- /dev/null   Thu Jan 01 00:00:00 1970 +0000
>>> +++
>>> b/tests/test-extensions/net/sourceforge/jnlp/closinglisteners/StringRule.java       Thu Sep 20
>>> 12:03:40 2012 +0200
>>> @@ -0,0 +1,57 @@
>>> +/* StringRule.java
>>> +Copyright (C) 2012 Red Hat, Inc.
>>> +
>>> +This file is part of IcedTea.
>>> +
>>> +IcedTea is free software; you can redistribute it and/or
>>> +modify it under the terms of the GNU General Public License as
>>> published by
>>> +the Free Software Foundation, version 2.
>>> +
>>> +IcedTea is distributed in the hope that it will be useful,
>>> +but WITHOUT ANY WARRANTY; without even the implied warranty of
>>> +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
>>> +General Public License for more details.
>>> +
>>> +You should have received a copy of the GNU General Public License
>>> +along with IcedTea; see the file COPYING.  If not, write to
>>> +the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
>>> Boston, MA
>>> +02110-1301 USA.
>>> +
>>> +Linking this library statically or dynamically with other modules is
>>> +making a combined work based on this library.  Thus, the terms and
>>> +conditions of the GNU General Public License cover the whole
>>> +combination.
>>> +
>>> +As a special exception, the copyright holders of this library give
>>> you
>>> +permission to link this library with independent modules to produce
>>> an
>>> +executable, regardless of the license terms of these independent
>>> +modules, and to copy and distribute the resulting executable under
>>> +terms of your choice, provided that you also meet, for each linked
>>> +independent module, the terms and conditions of the license of that
>>> +module.  An independent module is a module which is not derived from
>>> +or based on this library.  If you modify this library, you may extend
>>> +this exception to your version of the library, but you are not
>>> +obligated to do so.  If you do not wish to do so, delete this
>>> +exception statement from your version.
>>> +*/
>>> +package net.sourceforge.jnlp.closinglisteners;
>>> +
>>> +public abstract class StringRule<String,T>  implements Rule<String,
>>> T>{
>> I'm confused, why isn't this type simply StringRule<T> ? (Isn't String
>> here being parsed as a generic type ?? I must admit I've never seen
>> concrete types in this location.)
>
> Sure. Fixed
>>> +    protected String rule;
>>> +
>>> +    public StringRule(String rule) {
>>> +        setRule(rule);
>>> +    }
>>> +
>>> +    public StringRule() {
>>> +    }
>>> +
>>> +
>>> +    @Override
>>> +    public void setRule(String rule){
>>> +        this.rule=rule;
>>> +    }
>>> +    @Override
>>> +    public abstract boolean evaluate(T upon);
>>> +
>>> +}
>>>
>
>> Thanks for the patch!
>
> Tahnk yo for review :)
>
>> - Adam
>>
>

Added missing Rule... type support
J.
-------------- next part --------------
A non-text attachment was scrubbed...
Name: closingListener_6_2.diff
Type: text/x-patch
Size: 25416 bytes
Desc: not available
Url : http://mail.openjdk.java.net/pipermail/distro-pkg-dev/attachments/20120924/c6872bbd/closingListener_6_2.diff 


More information about the distro-pkg-dev mailing list