clirr-devel Mailing List for Clirr (Page 28)
Status: Alpha
Brought to you by:
lkuehne
You can subscribe to this list here.
2003 |
Jan
|
Feb
|
Mar
|
Apr
|
May
|
Jun
|
Jul
|
Aug
|
Sep
(15) |
Oct
(23) |
Nov
|
Dec
(25) |
---|---|---|---|---|---|---|---|---|---|---|---|---|
2004 |
Jan
(9) |
Feb
|
Mar
|
Apr
|
May
(76) |
Jun
(207) |
Jul
(242) |
Aug
(42) |
Sep
(33) |
Oct
|
Nov
(7) |
Dec
(1) |
2005 |
Jan
|
Feb
|
Mar
(5) |
Apr
|
May
|
Jun
|
Jul
(3) |
Aug
(66) |
Sep
(38) |
Oct
(6) |
Nov
|
Dec
(2) |
2006 |
Jan
(17) |
Feb
(5) |
Mar
(28) |
Apr
(6) |
May
|
Jun
|
Jul
(1) |
Aug
|
Sep
|
Oct
(1) |
Nov
(1) |
Dec
(7) |
2007 |
Jan
|
Feb
|
Mar
|
Apr
(7) |
May
(33) |
Jun
(4) |
Jul
(3) |
Aug
|
Sep
(5) |
Oct
|
Nov
|
Dec
|
2008 |
Jan
(4) |
Feb
(3) |
Mar
(2) |
Apr
|
May
(1) |
Jun
|
Jul
(6) |
Aug
(8) |
Sep
(5) |
Oct
(20) |
Nov
(7) |
Dec
(9) |
2009 |
Jan
(8) |
Feb
(3) |
Mar
(20) |
Apr
(10) |
May
(40) |
Jun
(11) |
Jul
(23) |
Aug
(4) |
Sep
(1) |
Oct
(1) |
Nov
|
Dec
(2) |
2010 |
Jan
(5) |
Feb
(1) |
Mar
|
Apr
|
May
|
Jun
(1) |
Jul
|
Aug
(2) |
Sep
|
Oct
|
Nov
|
Dec
|
2011 |
Jan
|
Feb
|
Mar
|
Apr
(3) |
May
|
Jun
|
Jul
|
Aug
|
Sep
|
Oct
|
Nov
|
Dec
(1) |
2012 |
Jan
|
Feb
|
Mar
|
Apr
|
May
|
Jun
|
Jul
|
Aug
(1) |
Sep
|
Oct
|
Nov
|
Dec
|
2013 |
Jan
|
Feb
|
Mar
|
Apr
(6) |
May
(22) |
Jun
(2) |
Jul
|
Aug
|
Sep
|
Oct
(2) |
Nov
(1) |
Dec
(2) |
2014 |
Jan
(5) |
Feb
|
Mar
|
Apr
|
May
(1) |
Jun
|
Jul
|
Aug
|
Sep
|
Oct
|
Nov
(1) |
Dec
|
2015 |
Jan
(1) |
Feb
(2) |
Mar
(1) |
Apr
|
May
|
Jun
|
Jul
|
Aug
|
Sep
|
Oct
|
Nov
|
Dec
|
2016 |
Jan
|
Feb
|
Mar
|
Apr
|
May
|
Jun
|
Jul
|
Aug
|
Sep
|
Oct
(1) |
Nov
|
Dec
|
2017 |
Jan
|
Feb
|
Mar
(1) |
Apr
|
May
|
Jun
|
Jul
|
Aug
|
Sep
|
Oct
|
Nov
|
Dec
|
From: Simon K. <s_k...@us...> - 2004-07-02 03:02:32
|
Update of /cvsroot/clirr/clirr/src/test/net/sf/clirr/event In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv20017 Modified Files: MessageTest.java Log Message: Checking complete translations now done via new MessageTranslator class Index: MessageTest.java =================================================================== RCS file: /cvsroot/clirr/clirr/src/test/net/sf/clirr/event/MessageTest.java,v retrieving revision 1.1 retrieving revision 1.2 diff -u -r1.1 -r1.2 --- MessageTest.java 28 Jun 2004 06:51:21 -0000 1.1 +++ MessageTest.java 2 Jul 2004 03:02:22 -0000 1.2 @@ -37,8 +37,11 @@ */ public void testComplete() { + java.util.Collection messages = MessageManager.getInstance().getMessages(); + // check the english locale - MessageManager.getInstance().setLocale(new Locale("en")); - MessageManager.getInstance().checkComplete(); + MessageTranslator translator = new MessageTranslator(); + translator.setLocale(new Locale("en")); + translator.checkComplete(messages); } } |
From: Simon K. <s_k...@us...> - 2004-07-02 03:00:51
|
Update of /cvsroot/clirr/clirr/src/test/net/sf/clirr/checks In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv19657 Modified Files: TestDiffListener.java Log Message: Use ExpectedDiff class Index: TestDiffListener.java =================================================================== RCS file: /cvsroot/clirr/clirr/src/test/net/sf/clirr/checks/TestDiffListener.java,v retrieving revision 1.3 retrieving revision 1.4 diff -u -r1.3 -r1.4 --- TestDiffListener.java 31 Dec 2003 09:45:45 -0000 1.3 +++ TestDiffListener.java 2 Jul 2004 03:00:41 -0000 1.4 @@ -6,10 +6,13 @@ import net.sf.clirr.framework.ApiDiffDispatcher; import net.sf.clirr.event.ApiDifference; +import net.sf.clirr.event.MessageTranslator; import junit.framework.TestCase; class TestDiffListener implements ApiDiffDispatcher { + private MessageTranslator translator = new MessageTranslator(); + private Set diffs = new HashSet(); public void fireDiff(ApiDifference difference) @@ -17,24 +20,41 @@ diffs.add(difference); } - public void checkExpected(ApiDifference[] expected) + public void checkExpected(ExpectedDiff[] expectedDiffs) { - HashSet expectedDiffs = new HashSet(expected.length); - for (int i = 0; i < expected.length; i++) { - ApiDifference apiDifference = expected[i]; - expectedDiffs.add(apiDifference); - } - - for (Iterator it = expectedDiffs.iterator(); it.hasNext();) { - ApiDifference apiDifference = (ApiDifference) it.next(); - TestCase.assertTrue("expected diff " + apiDifference + " was not generated: " + diffs, - diffs.contains(apiDifference)); + for (int i=0; i<expectedDiffs.length; ++i) + { + ExpectedDiff expected = expectedDiffs[i]; + + // now see if the expected diff is in fact in the set of + // diffs that occurred during the test comparison + boolean found = false; + for(Iterator j = diffs.iterator(); j.hasNext() && !found;) + { + ApiDifference actual = (ApiDifference) j.next(); + found = expected.matches(actual); + } + + if (!found) + { + TestCase.fail("expected diff " + expected + " was not generated: " + diffs); + } } for (Iterator it = diffs.iterator(); it.hasNext();) { - ApiDifference apiDifference = (ApiDifference) it.next(); - TestCase.assertTrue("unexpected diff " + apiDifference, - expectedDiffs.contains(apiDifference)); + ApiDifference actual = (ApiDifference) it.next(); + + // see if the generated diff is in fact in the expected set + boolean found = false; + for(int i=0; i<expectedDiffs.length && !found; ++i) + { + found = expectedDiffs[i].matches(actual); + } + + if (!found) + { + TestCase.fail("unexpected diff " + actual); + } } } } |
From: Simon K. <s_k...@us...> - 2004-07-02 02:59:40
|
Update of /cvsroot/clirr/clirr/src/test/net/sf/clirr/checks In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv19507 Modified Files: MethodSetCheckTest.java Log Message: Use ExpectedDiff class Index: MethodSetCheckTest.java =================================================================== RCS file: /cvsroot/clirr/clirr/src/test/net/sf/clirr/checks/MethodSetCheckTest.java,v retrieving revision 1.10 retrieving revision 1.11 diff -u -r1.10 -r1.11 --- MethodSetCheckTest.java 29 Jun 2004 06:56:46 -0000 1.10 +++ MethodSetCheckTest.java 2 Jul 2004 02:59:32 -0000 1.11 @@ -1,7 +1,6 @@ package net.sf.clirr.checks; import net.sf.clirr.framework.ClassChangeCheck; -import net.sf.clirr.event.ApiDifference; import net.sf.clirr.event.Severity; import net.sf.clirr.event.ScopeSelector; @@ -14,53 +13,53 @@ { public void testMethodCheck() throws Exception { - ApiDifference[] expected = new ApiDifference[] { + ExpectedDiff[] expected = new ExpectedDiff[] { // method addition and removal - new ApiDifference("Method 'public void removedMethod(java.lang.String)' has been removed", + new ExpectedDiff("Method 'public void removedMethod(java.lang.String)' has been removed", Severity.ERROR, "testlib.MethodsChange", "public void removedMethod(java.lang.String)", null), - new ApiDifference("Accessability of method 'public int getPriv2()' has been decreased from public to private", + new ExpectedDiff("Accessability of method 'public int getPriv2()' has been decreased from public to private", Severity.ERROR, "testlib.MethodsChange", "public int getPriv2()", null), - new ApiDifference("Method 'protected MethodsChange(int, boolean)' has been added", + new ExpectedDiff("Method 'protected MethodsChange(int, boolean)' has been added", Severity.INFO, "testlib.MethodsChange", "protected MethodsChange(int, boolean)", null), - new ApiDifference("Method 'public java.lang.Long getPrivSquare()' has been added", + new ExpectedDiff("Method 'public java.lang.Long getPrivSquare()' has been added", Severity.INFO, "testlib.MethodsChange", "public java.lang.Long getPrivSquare()", null), - new ApiDifference("Method 'public void moveToSuper()' has been added", + new ExpectedDiff("Method 'public void moveToSuper()' has been added", Severity.INFO, "testlib.ComplexMethodMoveBase", "public void moveToSuper()", null), - new ApiDifference("Method 'public void moveToSuper()' is now implemented in superclass testlib.ComplexMethodMoveBase", + new ExpectedDiff("Method 'public void moveToSuper()' is now implemented in superclass testlib.ComplexMethodMoveBase", Severity.INFO, "testlib.ComplexMethodMoveSub", "public void moveToSuper()", null), - new ApiDifference("Abstract method 'public void method()' is now specified by implemented interface testlib.BaseInterface", + new ExpectedDiff("Abstract method 'public void method()' is now specified by implemented interface testlib.BaseInterface", Severity.INFO, "testlib.AbstractImpl", "public void method()", null), // Constructor changes - new ApiDifference("Parameter 1 of 'protected MethodsChange(int)' has changed its type to java.lang.Integer", + new ExpectedDiff("Parameter 1 of 'protected MethodsChange(int)' has changed its type to java.lang.Integer", Severity.ERROR, "testlib.MethodsChange", "protected MethodsChange(int)", null), // return type changes - new ApiDifference("Return type of method 'public java.lang.Number getPrivAsNumber()' has been changed to java.lang.Integer", + new ExpectedDiff("Return type of method 'public java.lang.Number getPrivAsNumber()' has been changed to java.lang.Integer", Severity.ERROR, "testlib.MethodsChange", "public java.lang.Number getPrivAsNumber()", null), // TODO: INFO if method is final - new ApiDifference("Return type of method 'public java.lang.Integer getPrivAsInteger()' has been changed to java.lang.Number", + new ExpectedDiff("Return type of method 'public java.lang.Integer getPrivAsInteger()' has been changed to java.lang.Number", Severity.ERROR, "testlib.MethodsChange", "public java.lang.Integer getPrivAsInteger()", null), // parameter list changes // Note: This is the current behaviour, not necessarily the spec of the desired behaviour // TODO: need to check assignability of types (and check if method or class is final?) - new ApiDifference("In method 'public void printPriv()' the number of arguments has changed", + new ExpectedDiff("In method 'public void printPriv()' the number of arguments has changed", Severity.ERROR, "testlib.MethodsChange", "public void printPriv()", null), - new ApiDifference("Parameter 1 of 'public void strengthenParamType(java.lang.Object)' has changed its type to java.lang.String", + new ExpectedDiff("Parameter 1 of 'public void strengthenParamType(java.lang.Object)' has changed its type to java.lang.String", Severity.ERROR, "testlib.MethodsChange", "public void strengthenParamType(java.lang.Object)", null), - new ApiDifference("Parameter 1 of 'public void weakenParamType(java.lang.String)' has changed its type to java.lang.Object", + new ExpectedDiff("Parameter 1 of 'public void weakenParamType(java.lang.String)' has changed its type to java.lang.Object", Severity.ERROR, "testlib.MethodsChange", "public void weakenParamType(java.lang.String)", null), - new ApiDifference("Parameter 1 of 'public void changeParamType(java.lang.String)' has changed its type to java.lang.Integer", + new ExpectedDiff("Parameter 1 of 'public void changeParamType(java.lang.String)' has changed its type to java.lang.Integer", Severity.ERROR, "testlib.MethodsChange", "public void changeParamType(java.lang.String)", null), // deprecation changes - new ApiDifference("Method 'public void becomesDeprecated()' has been deprecated", + new ExpectedDiff("Method 'public void becomesDeprecated()' has been deprecated", Severity.INFO, "testlib.MethodsChange", "public void becomesDeprecated()", null), - new ApiDifference("Method 'public void becomesUndeprecated()' is no longer deprecated", + new ExpectedDiff("Method 'public void becomesUndeprecated()' is no longer deprecated", Severity.INFO, "testlib.MethodsChange", "public void becomesUndeprecated()", null), // declared exceptions |
From: Simon K. <s_k...@us...> - 2004-07-02 02:58:49
|
Update of /cvsroot/clirr/clirr/src/test/net/sf/clirr/checks In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv19396 Modified Files: GenderChangeCheckTest.java Log Message: Use ExpectedDiff class Index: GenderChangeCheckTest.java =================================================================== RCS file: /cvsroot/clirr/clirr/src/test/net/sf/clirr/checks/GenderChangeCheckTest.java,v retrieving revision 1.3 retrieving revision 1.4 diff -u -r1.3 -r1.4 --- GenderChangeCheckTest.java 27 Jun 2004 14:39:19 -0000 1.3 +++ GenderChangeCheckTest.java 2 Jul 2004 02:58:41 -0000 1.4 @@ -1,6 +1,5 @@ package net.sf.clirr.checks; -import net.sf.clirr.event.ApiDifference; import net.sf.clirr.event.Severity; import net.sf.clirr.framework.ClassChangeCheck; @@ -8,9 +7,9 @@ { public void testGenderChangeCheckTest() throws Exception { - ApiDifference[] expected = new ApiDifference[] { - new ApiDifference("Changed Gender of testlib.ClassBecomesInterface", Severity.ERROR, "testlib.ClassBecomesInterface", null, null), - new ApiDifference("Changed Gender of testlib.InterfaceBecomesClass", Severity.ERROR, "testlib.InterfaceBecomesClass", null, null), + ExpectedDiff[] expected = new ExpectedDiff[] { + new ExpectedDiff("Changed from class to interface", Severity.ERROR, "testlib.ClassBecomesInterface", null, null), + new ExpectedDiff("Changed from interface to class", Severity.ERROR, "testlib.InterfaceBecomesClass", null, null), }; verify(expected); } |
From: Simon K. <s_k...@us...> - 2004-07-02 02:57:35
|
Update of /cvsroot/clirr/clirr/src/test/net/sf/clirr/checks In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv19248 Modified Files: FieldSetCheckTest.java Log Message: Use ExpectedDiff class Index: FieldSetCheckTest.java =================================================================== RCS file: /cvsroot/clirr/clirr/src/test/net/sf/clirr/checks/FieldSetCheckTest.java,v retrieving revision 1.7 retrieving revision 1.8 diff -u -r1.7 -r1.8 --- FieldSetCheckTest.java 27 Jun 2004 14:39:19 -0000 1.7 +++ FieldSetCheckTest.java 2 Jul 2004 02:57:23 -0000 1.8 @@ -1,6 +1,5 @@ package net.sf.clirr.checks; -import net.sf.clirr.event.ApiDifference; import net.sf.clirr.event.Severity; import net.sf.clirr.event.ScopeSelector; import net.sf.clirr.framework.ClassChangeCheck; @@ -14,24 +13,24 @@ { public void testFieldCheck() throws Exception { - ApiDifference[] expected = new ApiDifference[] { - new ApiDifference("Field stat7 has been removed in testlib.MembersChange", Severity.ERROR, "testlib.MembersChange", null, "stat7"), - new ApiDifference("Accessibility of field fin2 has been weakened from public to protected in testlib.MembersChange", Severity.ERROR, "testlib.MembersChange", null, "fin2"), - new ApiDifference("Accessibility of field stat4 has been weakened from public to protected in testlib.MembersChange", Severity.ERROR, "testlib.MembersChange", null, "stat4"), - new ApiDifference("Accessability of field priv2 has been increased from private to public in testlib.MembersChange", Severity.INFO, "testlib.MembersChange", null, "priv2"), - new ApiDifference("Accessibility of field stat5 has been weakened from public to private in testlib.MembersChange", Severity.ERROR, "testlib.MembersChange", null, "stat5"), - new ApiDifference("Field stat2 is now final in testlib.MembersChange", Severity.ERROR, "testlib.MembersChange", null, "stat2"), - new ApiDifference("Field pub3 is now final in testlib.MembersChange", Severity.ERROR, "testlib.MembersChange", null, "pub3"), - new ApiDifference("Accessibility of field stat6 has been weakened from public to package in testlib.MembersChange", Severity.ERROR, "testlib.MembersChange", null, "stat6"), - new ApiDifference("Field stat3 is now non-static in testlib.MembersChange", Severity.ERROR, "testlib.MembersChange", null, "stat3"), - new ApiDifference("Field fin3 is now non-static in testlib.MembersChange", Severity.ERROR, "testlib.MembersChange", null, "fin3"), - new ApiDifference("Added public field stat8 in testlib.MembersChange", Severity.INFO, "testlib.MembersChange", null, "stat8"), - new ApiDifference("Field fin4 is now non-final in testlib.MembersChange", Severity.INFO, "testlib.MembersChange", null, "fin4"), - new ApiDifference("Field pub2 is now static in testlib.MembersChange", Severity.ERROR, "testlib.MembersChange", null, "pub2"), - new ApiDifference("Changed type of field obj1 from java.lang.Object to java.lang.String in testlib.MembersChange", Severity.ERROR, "testlib.MembersChange", null, "obj1"), - new ApiDifference("Changed type of field obj2 from java.lang.Boolean to java.lang.String in testlib.MembersChange", Severity.ERROR, "testlib.MembersChange", null, "obj2"), - new ApiDifference("Value of fin6 is no longer a compile time constant in testlib.MembersChange", Severity.WARNING, "testlib.MembersChange", null, "fin6"), - new ApiDifference("Value of compile time constant fin5 has been changed in testlib.MembersChange", Severity.WARNING, "testlib.MembersChange", null, "fin5"), + ExpectedDiff[] expected = new ExpectedDiff[] { + new ExpectedDiff("Removed field stat7", Severity.ERROR, "testlib.MembersChange", null, "stat7"), + new ExpectedDiff("Accessability of field fin2 has been weakened from public to protected", Severity.ERROR, "testlib.MembersChange", null, "fin2"), + new ExpectedDiff("Accessability of field stat4 has been weakened from public to protected", Severity.ERROR, "testlib.MembersChange", null, "stat4"), + new ExpectedDiff("Accessability of field priv2 has been increased from private to public", Severity.INFO, "testlib.MembersChange", null, "priv2"), + new ExpectedDiff("Accessability of field stat5 has been weakened from public to private", Severity.ERROR, "testlib.MembersChange", null, "stat5"), + new ExpectedDiff("Field stat2 is now final", Severity.ERROR, "testlib.MembersChange", null, "stat2"), + new ExpectedDiff("Field pub3 is now final", Severity.ERROR, "testlib.MembersChange", null, "pub3"), + new ExpectedDiff("Accessability of field stat6 has been weakened from public to package", Severity.ERROR, "testlib.MembersChange", null, "stat6"), + new ExpectedDiff("Field stat3 is now non-static", Severity.ERROR, "testlib.MembersChange", null, "stat3"), + new ExpectedDiff("Field fin3 is now non-static", Severity.ERROR, "testlib.MembersChange", null, "fin3"), + new ExpectedDiff("Added public field stat8", Severity.INFO, "testlib.MembersChange", null, "stat8"), + new ExpectedDiff("Field fin4 is now non-final", Severity.INFO, "testlib.MembersChange", null, "fin4"), + new ExpectedDiff("Field pub2 is now static", Severity.ERROR, "testlib.MembersChange", null, "pub2"), + new ExpectedDiff("Changed type of field obj1 from java.lang.Object to java.lang.String", Severity.ERROR, "testlib.MembersChange", null, "obj1"), + new ExpectedDiff("Changed type of field obj2 from java.lang.Boolean to java.lang.String", Severity.ERROR, "testlib.MembersChange", null, "obj2"), + new ExpectedDiff("Value of field fin6 is no longer a compile-time constant", Severity.WARNING, "testlib.MembersChange", null, "fin6"), + new ExpectedDiff("Value of compile-time constant fin5 has been changed", Severity.WARNING, "testlib.MembersChange", null, "fin5"), }; verify(expected); } |
From: Simon K. <s_k...@us...> - 2004-07-02 02:56:28
|
Update of /cvsroot/clirr/clirr/src/test/net/sf/clirr/checks In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv19124 Modified Files: ClassScopeCheckTest.java Log Message: Use ExpectedDiff class Index: ClassScopeCheckTest.java =================================================================== RCS file: /cvsroot/clirr/clirr/src/test/net/sf/clirr/checks/ClassScopeCheckTest.java,v retrieving revision 1.2 retrieving revision 1.3 diff -u -r1.2 -r1.3 --- ClassScopeCheckTest.java 27 Jun 2004 14:39:19 -0000 1.2 +++ ClassScopeCheckTest.java 2 Jul 2004 02:56:20 -0000 1.3 @@ -1,7 +1,6 @@ package net.sf.clirr.checks; import net.sf.clirr.framework.ClassChangeCheck; -import net.sf.clirr.event.ApiDifference; import net.sf.clirr.event.Severity; import net.sf.clirr.event.ScopeSelector; import net.sf.clirr.framework.ClassSelector; @@ -15,22 +14,22 @@ { public void testAccessChangesAreReported() throws Exception { - ApiDifference[] expected = new ApiDifference[] { - new ApiDifference("Decreased visibility of class from public to protected", Severity.ERROR, "testlib.scope.ClassScopeChange$A2", null, null), - new ApiDifference("Decreased visibility of class from public to package", Severity.ERROR, "testlib.scope.ClassScopeChange$A3", null, null), - new ApiDifference("Decreased visibility of class from public to private", Severity.ERROR, "testlib.scope.ClassScopeChange$A4", null, null), - - new ApiDifference("Increased visibility of class from protected to public", Severity.INFO, "testlib.scope.ClassScopeChange$B2", null, null), - new ApiDifference("Decreased visibility of class from protected to package", Severity.ERROR, "testlib.scope.ClassScopeChange$B3", null, null), - new ApiDifference("Decreased visibility of class from protected to private", Severity.ERROR, "testlib.scope.ClassScopeChange$B4", null, null), - - new ApiDifference("Increased visibility of class from package to public", Severity.INFO, "testlib.scope.ClassScopeChange$C2", null, null), - new ApiDifference("Increased visibility of class from package to protected", Severity.INFO, "testlib.scope.ClassScopeChange$C3", null, null), - new ApiDifference("Decreased visibility of class from package to private", Severity.ERROR, "testlib.scope.ClassScopeChange$C4", null, null), - - new ApiDifference("Increased visibility of class from private to public", Severity.INFO, "testlib.scope.ClassScopeChange$D2", null, null), - new ApiDifference("Increased visibility of class from private to protected", Severity.INFO, "testlib.scope.ClassScopeChange$D3", null, null), - new ApiDifference("Increased visibility of class from private to package", Severity.INFO, "testlib.scope.ClassScopeChange$D4", null, null), + ExpectedDiff[] expected = new ExpectedDiff[] { + new ExpectedDiff("Decreased visibility of class from public to protected", Severity.ERROR, "testlib.scope.ClassScopeChange$A2", null, null), + new ExpectedDiff("Decreased visibility of class from public to package", Severity.ERROR, "testlib.scope.ClassScopeChange$A3", null, null), + new ExpectedDiff("Decreased visibility of class from public to private", Severity.ERROR, "testlib.scope.ClassScopeChange$A4", null, null), + + new ExpectedDiff("Increased visibility of class from protected to public", Severity.INFO, "testlib.scope.ClassScopeChange$B2", null, null), + new ExpectedDiff("Decreased visibility of class from protected to package", Severity.ERROR, "testlib.scope.ClassScopeChange$B3", null, null), + new ExpectedDiff("Decreased visibility of class from protected to private", Severity.ERROR, "testlib.scope.ClassScopeChange$B4", null, null), + + new ExpectedDiff("Increased visibility of class from package to public", Severity.INFO, "testlib.scope.ClassScopeChange$C2", null, null), + new ExpectedDiff("Increased visibility of class from package to protected", Severity.INFO, "testlib.scope.ClassScopeChange$C3", null, null), + new ExpectedDiff("Decreased visibility of class from package to private", Severity.ERROR, "testlib.scope.ClassScopeChange$C4", null, null), + + new ExpectedDiff("Increased visibility of class from private to public", Severity.INFO, "testlib.scope.ClassScopeChange$D2", null, null), + new ExpectedDiff("Increased visibility of class from private to protected", Severity.INFO, "testlib.scope.ClassScopeChange$D3", null, null), + new ExpectedDiff("Increased visibility of class from private to package", Severity.INFO, "testlib.scope.ClassScopeChange$D4", null, null), }; verify(expected); } |
From: Simon K. <s_k...@us...> - 2004-07-02 02:52:24
|
Update of /cvsroot/clirr/clirr/src/test/net/sf/clirr/checks In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv18374 Modified Files: ClassModifierCheckTest.java Log Message: Use ExpectedDiff class Index: ClassModifierCheckTest.java =================================================================== RCS file: /cvsroot/clirr/clirr/src/test/net/sf/clirr/checks/ClassModifierCheckTest.java,v retrieving revision 1.2 retrieving revision 1.3 diff -u -r1.2 -r1.3 --- ClassModifierCheckTest.java 27 Jun 2004 14:39:19 -0000 1.2 +++ ClassModifierCheckTest.java 2 Jul 2004 02:52:15 -0000 1.3 @@ -1,7 +1,6 @@ package net.sf.clirr.checks; import net.sf.clirr.framework.ClassChangeCheck; -import net.sf.clirr.event.ApiDifference; import net.sf.clirr.event.Severity; import net.sf.clirr.framework.ClassSelector; @@ -12,9 +11,9 @@ { public void testAll() throws Exception { - ApiDifference[] expected = new ApiDifference[] { - new ApiDifference("Added final modifier in class testlib.modifiers.NonFinalBecomesFinal", Severity.ERROR, "testlib.modifiers.NonFinalBecomesFinal", null, null), - new ApiDifference("Added final modifier in class testlib.modifiers.EffectivelyFinal (but class was effectively final anyway)", Severity.INFO, "testlib.modifiers.EffectivelyFinal", null, null), + ExpectedDiff[] expected = new ExpectedDiff[] { + new ExpectedDiff("Added final modifier to class", Severity.ERROR, "testlib.modifiers.NonFinalBecomesFinal", null, null), + new ExpectedDiff("Added final modifier to class, but class was effectively final anyway", Severity.INFO, "testlib.modifiers.EffectivelyFinal", null, null), }; verify(expected); } |
From: Simon K. <s_k...@us...> - 2004-07-02 02:51:19
|
Update of /cvsroot/clirr/clirr/src/test/net/sf/clirr/checks In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv18204 Modified Files: ClassHierarchyCheckTest.java Log Message: Use ExpectedDiff class Index: ClassHierarchyCheckTest.java =================================================================== RCS file: /cvsroot/clirr/clirr/src/test/net/sf/clirr/checks/ClassHierarchyCheckTest.java,v retrieving revision 1.3 retrieving revision 1.4 diff -u -r1.3 -r1.4 --- ClassHierarchyCheckTest.java 27 Jun 2004 14:39:19 -0000 1.3 +++ ClassHierarchyCheckTest.java 2 Jul 2004 02:51:11 -0000 1.4 @@ -1,7 +1,6 @@ package net.sf.clirr.checks; import net.sf.clirr.framework.ClassChangeCheck; -import net.sf.clirr.event.ApiDifference; import net.sf.clirr.event.Severity; /** @@ -11,10 +10,10 @@ { public void testHierarchyChangesAreReported() throws Exception { - ApiDifference[] expected = new ApiDifference[] { - new ApiDifference("Added java.util.NoSuchElementException to the list of superclasses of testlib.ApplicationException", Severity.WARNING, "testlib.ApplicationException", null, null), - new ApiDifference("Removed java.awt.event.MouseAdapter from the list of superclasses of testlib.ChangingHierarchy", Severity.ERROR, "testlib.ChangingHierarchy", null, null), - new ApiDifference("Added java.awt.event.WindowAdapter to the list of superclasses of testlib.ChangingHierarchy", Severity.INFO, "testlib.ChangingHierarchy", null, null), + ExpectedDiff[] expected = new ExpectedDiff[] { + new ExpectedDiff("Added java.util.NoSuchElementException to the list of superclasses", Severity.WARNING, "testlib.ApplicationException", null, null), + new ExpectedDiff("Removed java.awt.event.MouseAdapter from the list of superclasses", Severity.ERROR, "testlib.ChangingHierarchy", null, null), + new ExpectedDiff("Added java.awt.event.WindowAdapter to the list of superclasses", Severity.INFO, "testlib.ChangingHierarchy", null, null), }; verify(expected); } |
From: Simon K. <s_k...@us...> - 2004-07-02 02:46:45
|
Update of /cvsroot/clirr/clirr/src/test/net/sf/clirr/checks In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv17514 Modified Files: AbstractCheckTestCase.java Log Message: Use ExpectedDiff class Index: AbstractCheckTestCase.java =================================================================== RCS file: /cvsroot/clirr/clirr/src/test/net/sf/clirr/checks/AbstractCheckTestCase.java,v retrieving revision 1.4 retrieving revision 1.5 diff -u -r1.4 -r1.5 --- AbstractCheckTestCase.java 23 Jun 2004 04:51:10 -0000 1.4 +++ AbstractCheckTestCase.java 2 Jul 2004 02:46:36 -0000 1.5 @@ -45,7 +45,7 @@ }; } - protected void verify(ApiDifference[] expected) + protected void verify(ExpectedDiff[] expected) throws Exception { TestDiffListener tdl = new TestDiffListener(); |
From: Simon K. <s_k...@us...> - 2004-07-02 02:45:54
|
Update of /cvsroot/clirr/clirr/src/test/net/sf/clirr/checks In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv17138 Added Files: ExpectedDiff.java Log Message: Replacement for direct use of ApiDifference class by unit tests for encapsulating expected API difference events. --- NEW FILE --- package net.sf.clirr.checks; import net.sf.clirr.event.MessageTranslator; import net.sf.clirr.event.Severity; import net.sf.clirr.event.ApiDifference; /** * Describes an expected API change. */ public final class ExpectedDiff { private static MessageTranslator translator = new MessageTranslator(); private String report; private Severity binaryCompatibilitySeverity; private Severity sourceCompatibilitySeverity; private String affectedClass; private String affectedMethod; private String affectedField; /** * Create a new API difference representation. * * @param report a human readable string describing the change that was made, must be non-null. * @param severity the severity in terms of binary and source code compatibility, must be non-null. * @param clazz the fully qualified class name where the change occured, must be non-null. * @param method the method signature of the method that changed, <code>null</code> * if no method was affected. * @param field the field name where the change occured, <code>null</code> * if no field was affected. */ public ExpectedDiff(String report, Severity severity, String clazz, String method, String field) { this(report, severity, severity, clazz, method, field); } /** * Create a new API difference representation. * * @param report a human readable string describing the change that was made, must be non-null. * @param binarySeverity the severity in terms of binary compatibility, must be non-null. * @param sourceSeverity the severity in terms of source code compatibility, must be non-null. * @param clazz the fully qualified class name where the change occured, must be non-null. * @param method the method signature of the method that changed, <code>null</code> * if no method was affected. * @param field the field name where the change occured, <code>null</code> * if no field was affected. */ public ExpectedDiff(String report, Severity binarySeverity, Severity sourceSeverity, String clazz, String method, String field) { checkNonNull(report); checkNonNull(binarySeverity); checkNonNull(sourceSeverity); checkNonNull(clazz); this.report = report; this.binaryCompatibilitySeverity = binarySeverity; this.sourceCompatibilitySeverity = sourceSeverity; this.affectedClass = clazz; this.affectedField = field; this.affectedMethod = method; } /** * Trivial utility method to verify that a specific object is non-null. */ private void checkNonNull(Object o) { if (o == null) { throw new IllegalArgumentException(); } } /** * {@inheritDoc} */ public String toString() { return report + " (" + binaryCompatibilitySeverity + ") - " + affectedClass + '[' + affectedField + '/' + affectedMethod + ']'; } /** * Returns true if the provided ApiDifference object matches the * expected value. */ public boolean matches(ApiDifference diff) { if (!report.equals(diff.getReport(translator))) { return false; } if (!binaryCompatibilitySeverity.equals(diff.getBinaryCompatibilitySeverity())) { return false; } if (!sourceCompatibilitySeverity.equals(diff.getSourceCompatibilitySeverity())) { return false; } final String otherClass = diff.getAffectedClass(); if (!affectedClass.equals(otherClass)) { return false; } final String otherMethod = diff.getAffectedMethod(); if (affectedMethod != null ? !affectedMethod.equals(otherMethod) : otherMethod != null) { return false; } final String otherField = diff.getAffectedField(); if (affectedField != null ? !affectedField.equals(otherField) : otherField != null) { return false; } return true; } } |
From: Simon K. <s_k...@us...> - 2004-07-02 02:42:17
|
Update of /cvsroot/clirr/clirr/src/test/net/sf/clirr/ant In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv16843 Modified Files: ChangeCounterTest.java Log Message: Use dummy Message object to be compatible with new ApiDifference API Index: ChangeCounterTest.java =================================================================== RCS file: /cvsroot/clirr/clirr/src/test/net/sf/clirr/ant/ChangeCounterTest.java,v retrieving revision 1.4 retrieving revision 1.5 diff -u -r1.4 -r1.5 --- ChangeCounterTest.java 27 Jun 2004 14:21:35 -0000 1.4 +++ ChangeCounterTest.java 2 Jul 2004 02:42:08 -0000 1.5 @@ -3,18 +3,22 @@ import junit.framework.TestCase; import net.sf.clirr.event.ApiDifference; import net.sf.clirr.event.Severity; +import net.sf.clirr.event.Message; public class ChangeCounterTest extends TestCase { public void testCorrectCounting() { + // a dummy message object + Message msg = new Message(0, false); + ChangeCounter counter = new ChangeCounter(); - counter.reportDiff(new ApiDifference("blah", Severity.WARNING, "Test", null, null)); - counter.reportDiff(new ApiDifference("blah", Severity.ERROR, "Test", null, null)); - counter.reportDiff(new ApiDifference("blah", Severity.INFO, "Test", null, null)); - counter.reportDiff(new ApiDifference("blah", Severity.ERROR, "Test", null, null)); - counter.reportDiff(new ApiDifference("blah", Severity.ERROR, "Test", null, null)); - counter.reportDiff(new ApiDifference("blah", Severity.WARNING, "Test", null, null)); + counter.reportDiff(new ApiDifference(msg, Severity.WARNING, "Test", null, null, null)); + counter.reportDiff(new ApiDifference(msg, Severity.ERROR, "Test", null, null, null)); + counter.reportDiff(new ApiDifference(msg, Severity.INFO, "Test", null, null, null)); + counter.reportDiff(new ApiDifference(msg, Severity.ERROR, "Test", null, null, null)); + counter.reportDiff(new ApiDifference(msg, Severity.ERROR, "Test", null, null, null)); + counter.reportDiff(new ApiDifference(msg, Severity.WARNING, "Test", null, null, null)); assertEquals("number of expected errors", 3, counter.getBinErrors()); assertEquals("number of expected warnings", 2, counter.getBinWarnings()); assertEquals("number of expected infos", 1, counter.getBinInfos()); |
From: Simon K. <s_k...@us...> - 2004-07-02 02:41:01
|
Update of /cvsroot/clirr/clirr/src/java/net/sf/clirr In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv16737 Modified Files: Checker.java Log Message: Use Message class Index: Checker.java =================================================================== RCS file: /cvsroot/clirr/clirr/src/java/net/sf/clirr/Checker.java,v retrieving revision 1.20 retrieving revision 1.21 diff -u -r1.20 -r1.21 --- Checker.java 23 Jun 2004 04:45:16 -0000 1.20 +++ Checker.java 2 Jul 2004 02:40:43 -0000 1.21 @@ -43,6 +43,7 @@ import net.sf.clirr.event.DiffListener; import net.sf.clirr.event.ScopeSelector; import net.sf.clirr.event.Severity; +import net.sf.clirr.event.Message; import net.sf.clirr.framework.ApiDiffDispatcher; import net.sf.clirr.framework.ClassChangeCheck; import net.sf.clirr.framework.ClassSelector; @@ -68,6 +69,8 @@ */ public final class Checker implements ApiDiffDispatcher { + private static final Message MSG_CLASS_ADDED = new Message(8000); + private static final Message MSG_CLASS_REMOVED = new Message(8001); private List listeners = new ArrayList(); @@ -334,14 +337,14 @@ { final String className = currentClass.getClassName(); final ApiDifference diff = new ApiDifference( - "Added " + className, Severity.INFO, className, null, null); + MSG_CLASS_ADDED, Severity.INFO, className, null, null, null); fireDiff(diff); } else if (currentClass == null) { final String className = compatBaselineClass.getClassName(); final ApiDifference diff = new ApiDifference( - "Removed " + className, Severity.ERROR, className, null, null); + MSG_CLASS_REMOVED, Severity.ERROR, className, null, null, null); fireDiff(diff); } else |
From: Simon K. <s_k...@us...> - 2004-07-02 02:39:24
|
Update of /cvsroot/clirr/clirr/src/java/net/sf/clirr/checks In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv16417 Modified Files: InterfaceSetCheck.java Log Message: * Use Message class * Use CoIterator class Index: InterfaceSetCheck.java =================================================================== RCS file: /cvsroot/clirr/clirr/src/java/net/sf/clirr/checks/InterfaceSetCheck.java,v retrieving revision 1.9 retrieving revision 1.10 diff -u -r1.9 -r1.10 --- InterfaceSetCheck.java 18 Jun 2004 06:52:10 -0000 1.9 +++ InterfaceSetCheck.java 2 Jul 2004 02:39:11 -0000 1.10 @@ -20,13 +20,15 @@ package net.sf.clirr.checks; import java.util.HashSet; -import java.util.Iterator; import java.util.Set; import net.sf.clirr.event.Severity; +import net.sf.clirr.event.Message; import net.sf.clirr.framework.AbstractDiffReporter; import net.sf.clirr.framework.ApiDiffDispatcher; import net.sf.clirr.framework.ClassChangeCheck; +import net.sf.clirr.framework.CoIterator; +import net.sf.clirr.framework.JavaClassNameComparator; import org.apache.bcel.classfile.JavaClass; /** @@ -38,6 +40,9 @@ extends AbstractDiffReporter implements ClassChangeCheck { + private static final Message MSG_IFACE_ADDED = new Message(4000); + private static final Message MSG_IFACE_REMOVED = new Message(4001); + /** * Create a new instance of this check. * @param dispatcher the diff dispatcher that distributes the detected changes to the listeners. @@ -53,9 +58,6 @@ JavaClass[] compatInterfaces = compatBaseline.getAllInterfaces(); JavaClass[] currentInterfaces = currentVersion.getAllInterfaces(); - // Note: an interface has itself in the set of all interfaces - // we have to consider that below to avoid funny messages for gender changes - // Note: getAllInterfaces might return multiple array entries with the same // interface, so we need to use sets to remove duplicates... Set compat = createClassSet(compatInterfaces); @@ -63,33 +65,36 @@ final String className = compatBaseline.getClassName(); - for (Iterator it = compat.iterator(); it.hasNext();) + CoIterator iter = new CoIterator( + JavaClassNameComparator.COMPARATOR, compat, current); + + while (iter.hasNext()) { - String compatInterface = (String) it.next(); + iter.next(); + + JavaClass compatInterface = (JavaClass) iter.getLeft(); + JavaClass currentInterface = (JavaClass) iter.getRight(); - if (!current.contains(compatInterface) - && !compatInterface.equals(className)) + if (className.equals(compatInterface.getClassName()) + || className.equals(currentInterface.getClassName())) { - log("Removed " + compatInterface - + " from the set of interfaces implemented by " - + className, - Severity.ERROR, className, null, null); + // This occurs because an interface has itself in the set of all interfaces. + // We can't just let the test below handle this case because that won't + // work when a gender change has occurred. + continue; } - else + + if (compatInterface == null) { - current.remove(compatInterface); + log(MSG_IFACE_ADDED, + Severity.INFO, className, null, null, + new String[] {currentInterface.getClassName()}); } - } - - for (Iterator it = current.iterator(); it.hasNext();) - { - String name = (String) it.next(); - if (!name.equals(className)) + else if (currentInterface == null) { - log("Added " + name - + " to the set of implemented interfaces implemented by " - + className, - Severity.INFO, className, null, null); + log(MSG_IFACE_REMOVED, + Severity.ERROR, className, null, null, + new String[] {compatInterface.getClassName()}); } } |
From: Simon K. <s_k...@us...> - 2004-07-02 02:37:36
|
Update of /cvsroot/clirr/clirr/src/java/net/sf/clirr/checks In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv16205 Modified Files: GenderChangeCheck.java Log Message: Use Message class Index: GenderChangeCheck.java =================================================================== RCS file: /cvsroot/clirr/clirr/src/java/net/sf/clirr/checks/GenderChangeCheck.java,v retrieving revision 1.10 retrieving revision 1.11 diff -u -r1.10 -r1.11 --- GenderChangeCheck.java 21 Jun 2004 09:02:33 -0000 1.10 +++ GenderChangeCheck.java 2 Jul 2004 02:37:28 -0000 1.11 @@ -19,8 +19,8 @@ package net.sf.clirr.checks; -import net.sf.clirr.event.ApiDifference; import net.sf.clirr.event.Severity; +import net.sf.clirr.event.Message; import net.sf.clirr.framework.AbstractDiffReporter; import net.sf.clirr.framework.ApiDiffDispatcher; import net.sf.clirr.framework.ClassChangeCheck; @@ -35,6 +35,8 @@ extends AbstractDiffReporter implements ClassChangeCheck { + private static final Message MSG_GENDER_CLASS_TO_INTERFACE = new Message(2000); + private static final Message MSG_GENDER_INTERFACE_TO_CLASS = new Message(2001); /** * Create a new instance of this check. @@ -49,12 +51,15 @@ /** {@inheritDoc} */ public boolean check(JavaClass baseLine, JavaClass current) { - if (baseLine.isClass() != current.isClass()) + if (baseLine.isClass() && current.isInterface()) { - getApiDiffDispatcher().fireDiff(new ApiDifference( - "Changed Gender of " + baseLine.getClassName(), Severity.ERROR, - baseLine.getClassName(), null, null) - ); + log(MSG_GENDER_CLASS_TO_INTERFACE, + Severity.ERROR, baseLine.getClassName(), null, null, null); + } + else if (baseLine.isInterface() && current.isClass()) + { + log(MSG_GENDER_INTERFACE_TO_CLASS, + Severity.ERROR, baseLine.getClassName(), null, null, null); } return true; |
From: Simon K. <s_k...@us...> - 2004-07-02 02:36:56
|
Update of /cvsroot/clirr/clirr/src/java/net/sf/clirr/checks In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv16096 Modified Files: FieldSetCheck.java Log Message: Use Message class. Index: FieldSetCheck.java =================================================================== RCS file: /cvsroot/clirr/clirr/src/java/net/sf/clirr/checks/FieldSetCheck.java,v retrieving revision 1.12 retrieving revision 1.13 diff -u -r1.12 -r1.13 --- FieldSetCheck.java 21 Jun 2004 07:00:59 -0000 1.12 +++ FieldSetCheck.java 2 Jul 2004 02:36:48 -0000 1.13 @@ -28,6 +28,7 @@ import net.sf.clirr.event.ApiDifference; import net.sf.clirr.event.Severity; import net.sf.clirr.event.ScopeSelector; +import net.sf.clirr.event.Message; import org.apache.bcel.classfile.JavaClass; import org.apache.bcel.classfile.Field; import org.apache.bcel.classfile.ConstantValue; @@ -41,6 +42,18 @@ extends AbstractDiffReporter implements ClassChangeCheck { + private static final Message MSG_FIELD_ADDED = new Message(6000); + private static final Message MSG_FIELD_REMOVED = new Message(6001); + private static final Message MSG_FIELD_NOT_CONSTANT = new Message(6002); + private static final Message MSG_FIELD_CONSTANT_CHANGED = new Message(6003); + private static final Message MSG_FIELD_TYPE_CHANGED = new Message(6004); + private static final Message MSG_FIELD_NOW_NON_FINAL = new Message(6005); + private static final Message MSG_FIELD_NOW_FINAL = new Message(6006); + private static final Message MSG_FIELD_NOW_NON_STATIC = new Message(6007); + private static final Message MSG_FIELD_NOW_STATIC = new Message(6008); + private static final Message MSG_FIELD_MORE_ACCESSABLE = new Message(6009); + private static final Message MSG_FIELD_LESS_ACCESSABLE = new Message(6010); + private static final class FieldNameComparator implements Comparator { public int compare(Object o1, Object o2) @@ -85,7 +98,9 @@ { final String name = cField.getName(); String scope = ScopeSelector.getScopeDesc(cField); - fireDiff("Added " + scope + " field " + name, Severity.INFO, currentClass, cField); + fireDiff(MSG_FIELD_ADDED, + Severity.INFO, currentClass, cField, + new String[] {scope}); } } else if (cField == null) @@ -93,7 +108,8 @@ if (scopeSelector.isSelected(bField)) { final String name = bField.getName(); - fireDiff("Field " + name + " has been removed", Severity.ERROR, baselineClass, bField); + fireDiff(MSG_FIELD_REMOVED, + Severity.ERROR, baselineClass, bField, null); } } else if (scopeSelector.isSelected(bField) || scopeSelector.isSelected(cField)) @@ -123,9 +139,8 @@ final ConstantValue cVal = cField.getConstantValue(); if (cVal == null) { - fireDiff("Value of " + bField.getName() - + " is no longer a compile time constant", - Severity.WARNING, currentClass, cField); + fireDiff(MSG_FIELD_NOT_CONSTANT, + Severity.WARNING, currentClass, cField, null); return; } @@ -134,9 +149,8 @@ { // TODO: print out old and new value // How can that be done with BCEL, esp. for boolean values? - fireDiff("Value of compile time constant " + bField.getName() - + " has been changed", - Severity.WARNING, currentClass, cField); + fireDiff(MSG_FIELD_CONSTANT_CHANGED, + Severity.WARNING, currentClass, cField, null); } } } @@ -147,8 +161,9 @@ final String cSig = cField.getType().toString(); if (!bSig.equals(cSig)) { - fireDiff("Changed type of field " + bField.getName() + " from " + bSig + " to " + cSig, - Severity.ERROR, currentClass, bField); + fireDiff(MSG_FIELD_TYPE_CHANGED, + Severity.ERROR, currentClass, bField, + new String[] {bSig, cSig}); } } @@ -156,22 +171,22 @@ { if (bField.isFinal() && !cField.isFinal()) { - fireDiff("Field " + bField.getName() + " is now non-final", Severity.INFO, clazz, cField); + fireDiff(MSG_FIELD_NOW_NON_FINAL, Severity.INFO, clazz, cField, null); } if (!bField.isFinal() && cField.isFinal()) { - fireDiff("Field " + bField.getName() + " is now final", Severity.ERROR, clazz, cField); + fireDiff(MSG_FIELD_NOW_FINAL, Severity.ERROR, clazz, cField, null); } if (bField.isStatic() && !cField.isStatic()) { - fireDiff("Field " + bField.getName() + " is now non-static", Severity.ERROR, clazz, cField); + fireDiff(MSG_FIELD_NOW_NON_STATIC, Severity.ERROR, clazz, cField, null); } if (!bField.isStatic() && cField.isStatic()) { - fireDiff("Field " + bField.getName() + " is now static", Severity.ERROR, clazz, cField); + fireDiff(MSG_FIELD_NOW_STATIC, Severity.ERROR, clazz, cField, null); } // JLS, 13.4.10: Adding or deleting a transient modifier of a field @@ -187,30 +202,26 @@ if (cScope.isMoreVisibleThan(bScope)) { - fireDiff( - "Accessability of field " + bField.getName() - + " has been increased" - + " from " + bScope.getDesc() - + " to " + cScope.getDesc(), - Severity.INFO, clazz, cField); + fireDiff(MSG_FIELD_MORE_ACCESSABLE, + Severity.INFO, clazz, cField, + new String[] {bScope.getDesc(), cScope.getDesc()}); } else if (cScope.isLessVisibleThan(bScope)) { - fireDiff( - "Accessibility of field " + bField.getName() - + " has been weakened" - + " from " + bScope.getDesc() - + " to " + cScope.getDesc(), - Severity.ERROR, clazz, cField); + fireDiff(MSG_FIELD_LESS_ACCESSABLE, + Severity.ERROR, clazz, cField, + new String[] {bScope.getDesc(), cScope.getDesc()}); } } - private void fireDiff(String report, Severity severity, JavaClass clazz, Field field) + private void fireDiff( + Message msg, + Severity severity, JavaClass clazz, Field field, + String[] args) { final String className = clazz.getClassName(); final ApiDifference diff = - new ApiDifference(report + " in " + className, - severity, className, null, field.getName()); + new ApiDifference(msg, severity, className, null, field.getName(), args); getApiDiffDispatcher().fireDiff(diff); } |
From: Simon K. <s_k...@us...> - 2004-07-02 02:36:12
|
Update of /cvsroot/clirr/clirr/src/java/net/sf/clirr/checks In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv15959 Modified Files: ClassScopeCheck.java Log Message: Use Message class Index: ClassScopeCheck.java =================================================================== RCS file: /cvsroot/clirr/clirr/src/java/net/sf/clirr/checks/ClassScopeCheck.java,v retrieving revision 1.1 retrieving revision 1.2 diff -u -r1.1 -r1.2 --- ClassScopeCheck.java 18 Jun 2004 07:59:22 -0000 1.1 +++ ClassScopeCheck.java 2 Jul 2004 02:36:01 -0000 1.2 @@ -21,6 +21,7 @@ import net.sf.clirr.event.Severity; import net.sf.clirr.event.ScopeSelector; +import net.sf.clirr.event.Message; import net.sf.clirr.framework.AbstractDiffReporter; import net.sf.clirr.framework.ApiDiffDispatcher; import net.sf.clirr.framework.ClassChangeCheck; @@ -49,6 +50,11 @@ extends AbstractDiffReporter implements ClassChangeCheck { + private static final Message MSG_SCOPE_INCREASED = new Message(1000); + private static final Message MSG_SCOPE_DECREASED = new Message(1001); + private static final Message MSG_ERROR_DETERMINING_SCOPE_OLD = new Message(1002); + private static final Message MSG_ERROR_DETERMINING_SCOPE_NEW = new Message(1003); + private ScopeSelector scopeSelector; /** @@ -71,8 +77,9 @@ } catch (CheckerException ex) { - log(ex.getMessage() + " in old class version", - Severity.ERROR, compatBaseline.getClassName(), null, null); + log(MSG_ERROR_DETERMINING_SCOPE_OLD, + Severity.ERROR, compatBaseline.getClassName(), null, null, + new String[] {ex.getMessage()}); return false; } @@ -83,8 +90,9 @@ } catch (CheckerException ex) { - log(ex.getMessage() + " in new class version", - Severity.ERROR, compatBaseline.getClassName(), null, null); + log(MSG_ERROR_DETERMINING_SCOPE_NEW, + Severity.ERROR, compatBaseline.getClassName(), null, null, + new String[] {ex.getMessage()}); return false; } @@ -98,21 +106,25 @@ if (cScope.isMoreVisibleThan(bScope)) { - log( - "Increased visibility of class from " - + bScope.getDesc() - + " to " - + cScope.getDesc(), - Severity.INFO, compatBaseline.getClassName(), null, null); + String[] args = + { + bScope.getDesc(), + cScope.getDesc() + }; + + log(MSG_SCOPE_INCREASED, + Severity.INFO, compatBaseline.getClassName(), null, null, args); } else if (cScope.isLessVisibleThan(bScope)) { - log( - "Decreased visibility of class from " - + bScope.getDesc() - + " to " - + cScope.getDesc(), - Severity.ERROR, compatBaseline.getClassName(), null, null); + String[] args = + { + bScope.getDesc(), + cScope.getDesc() + }; + + log(MSG_SCOPE_DECREASED, + Severity.ERROR, compatBaseline.getClassName(), null, null, args); } // Apply further checks only if both versions of the class have scopes |
From: Simon K. <s_k...@us...> - 2004-07-02 02:35:35
|
Update of /cvsroot/clirr/clirr/src/java/net/sf/clirr/checks In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv15893 Modified Files: ClassModifierCheck.java Log Message: Use Message class Index: ClassModifierCheck.java =================================================================== RCS file: /cvsroot/clirr/clirr/src/java/net/sf/clirr/checks/ClassModifierCheck.java,v retrieving revision 1.10 retrieving revision 1.11 diff -u -r1.10 -r1.11 --- ClassModifierCheck.java 21 Jun 2004 07:26:58 -0000 1.10 +++ ClassModifierCheck.java 2 Jul 2004 02:35:25 -0000 1.11 @@ -20,6 +20,7 @@ package net.sf.clirr.checks; import net.sf.clirr.event.Severity; +import net.sf.clirr.event.Message; import net.sf.clirr.framework.AbstractDiffReporter; import net.sf.clirr.framework.ApiDiffDispatcher; import net.sf.clirr.framework.ClassChangeCheck; @@ -38,6 +39,13 @@ extends AbstractDiffReporter implements ClassChangeCheck { + private static final Message MSG_MODIFIER_UNABLE_TO_DETERMINE_CLASS_SCOPE = new Message(3000); + private static final Message MSG_MODIFIER_REMOVED_FINAL = new Message(3001); + private static final Message MSG_MODIFIER_ADDED_FINAL_TO_EFFECTIVE_FINAL = new Message(3002); + private static final Message MSG_MODIFIER_ADDED_FINAL = new Message(3003); + private static final Message MSG_MODIFIER_REMOVED_ABSTRACT = new Message(3004); + private static final Message MSG_MODIFIER_ADDED_ABSTRACT = new Message(3005); + /** * Create a new instance of this check. * @param dispatcher the diff dispatcher that distributes the detected changes to the listeners. @@ -64,8 +72,8 @@ } catch (CheckerException ex) { - log("Unable to determine whether class is private", - Severity.ERROR, className, null, null); + log(MSG_MODIFIER_UNABLE_TO_DETERMINE_CLASS_SCOPE, + Severity.ERROR, className, null, null, null); return true; } @@ -78,34 +86,33 @@ if (compatIsFinal && !currentIsFinal) { - log("Removed final modifier in class " + className, - Severity.INFO, className, null, null); + log(MSG_MODIFIER_REMOVED_FINAL, + Severity.INFO, className, null, null, null); } else if (!compatIsFinal && currentIsFinal) { if (isEffectivelyFinal(compatBaseLine)) { - log("Added final modifier in class " + className - + " (but class was effectively final anyway)", - Severity.INFO, className, null, null); - } + log(MSG_MODIFIER_ADDED_FINAL_TO_EFFECTIVE_FINAL, + Severity.INFO, className, null, null, null); + } else { - log("Added final modifier in class " + className, - Severity.ERROR, className, null, null); + log(MSG_MODIFIER_ADDED_FINAL, + Severity.ERROR, className, null, null, null); } } // interfaces are always abstract, don't report gender change here if (compatIsAbstract && !currentIsAbstract && !compatIsInterface) { - log("Removed abstract modifier in class " + className, - Severity.INFO, className, null, null); + log(MSG_MODIFIER_REMOVED_ABSTRACT, + Severity.INFO, className, null, null, null); } else if (!compatIsAbstract && currentIsAbstract && !currentIsInterface) { - log("Added abstract modifier in class " + className, - Severity.ERROR, className, null, null); + log(MSG_MODIFIER_ADDED_ABSTRACT, + Severity.ERROR, className, null, null, null); } return true; |
From: Simon K. <s_k...@us...> - 2004-07-02 02:34:45
|
Update of /cvsroot/clirr/clirr/src/java/net/sf/clirr/checks In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv15731 Modified Files: ClassHierarchyCheck.java Log Message: * Converted to use Message class * Removed some unused methods and inner classes * converted ternary expression to more readable if/else Index: ClassHierarchyCheck.java =================================================================== RCS file: /cvsroot/clirr/clirr/src/java/net/sf/clirr/checks/ClassHierarchyCheck.java,v retrieving revision 1.11 retrieving revision 1.12 diff -u -r1.11 -r1.12 --- ClassHierarchyCheck.java 21 Jun 2004 07:09:50 -0000 1.11 +++ ClassHierarchyCheck.java 2 Jul 2004 02:34:37 -0000 1.12 @@ -19,10 +19,8 @@ package net.sf.clirr.checks; -import java.util.ArrayList; -import java.util.List; - import net.sf.clirr.event.Severity; +import net.sf.clirr.event.Message; import net.sf.clirr.framework.AbstractDiffReporter; import net.sf.clirr.framework.ApiDiffDispatcher; import net.sf.clirr.framework.ClassChangeCheck; @@ -39,6 +37,9 @@ extends AbstractDiffReporter implements ClassChangeCheck { + private static final Message MSG_ADDED_CLASS_TO_SUPERCLASSES = new Message(5000); + private static final Message MSG_REMOVED_CLASS_FROM_SUPERCLASSES = new Message(5001); + /** * Create a new instance of this check. * @param dispatcher the diff dispatcher that distributes the detected changes to the listeners. @@ -48,28 +49,6 @@ super(dispatcher); } - private List getSetDifference(JavaClass[] orig, JavaClass[] subtracted) - { - List list1 = getClassNames(orig); - List list2 = getClassNames(subtracted); - - List retval = new ArrayList(list1); - retval.removeAll(list2); - - return retval; - } - - private List getClassNames(JavaClass[] orig) - { - List list = new ArrayList(orig.length); - for (int i = 0; i < orig.length; i++) - { - JavaClass javaClass = orig[i]; - list.add(javaClass.getClassName()); - } - return list; - } - /** {@inheritDoc} */ public boolean check(JavaClass compatBaseline, JavaClass currentVersion) { @@ -99,15 +78,25 @@ if (baselineSuper == null) { - log("Added " + currentSuper.getClassName() - + " to the list of superclasses of " + className, - isThrowable ? Severity.WARNING : Severity.INFO, className, null, null); + Severity severity; + if (isThrowable) + { + severity = Severity.WARNING; + } + else + { + severity = Severity.INFO; + } + + log(MSG_ADDED_CLASS_TO_SUPERCLASSES, + severity, className, null, null, + new String[] {currentSuper.getClassName()}); } else if (currentSuper == null) { - log("Removed " + baselineSuper.getClassName() - + " from the list of superclasses of " + className, - Severity.ERROR, className, null, null); + log(MSG_REMOVED_CLASS_FROM_SUPERCLASSES, + Severity.ERROR, className, null, null, + new String[] {baselineSuper.getClassName()}); } } |
From: Simon K. <s_k...@us...> - 2004-07-02 02:33:20
|
Update of /cvsroot/clirr/clirr/src/java/net/sf/clirr/framework In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv15545 Modified Files: AbstractDiffReporter.java Log Message: Changed log method to suport Message class Index: AbstractDiffReporter.java =================================================================== RCS file: /cvsroot/clirr/clirr/src/java/net/sf/clirr/framework/AbstractDiffReporter.java,v retrieving revision 1.5 retrieving revision 1.6 diff -u -r1.5 -r1.6 --- AbstractDiffReporter.java 22 May 2004 13:26:04 -0000 1.5 +++ AbstractDiffReporter.java 2 Jul 2004 02:33:12 -0000 1.6 @@ -21,6 +21,7 @@ import net.sf.clirr.event.ApiDifference; import net.sf.clirr.event.Severity; +import net.sf.clirr.event.Message; import org.apache.bcel.classfile.Field; import org.apache.bcel.classfile.Method; @@ -39,9 +40,14 @@ return dispatcher; } - protected final void log(String msg, Severity severity, String clazz, Method method, Field field) + protected final void log( + Message msg, + Severity severity, + String clazz, Method method, Field field, + String[] args) { - final ApiDifference diff = new ApiDifference(msg, severity, clazz, null, null); + final ApiDifference diff = new ApiDifference( + msg, severity, clazz, null, null, args); getApiDiffDispatcher().fireDiff(diff); } } |
From: Simon K. <s_k...@us...> - 2004-07-02 02:32:11
|
Update of /cvsroot/clirr/clirr/src/java/net/sf/clirr/ant In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv15357 Modified Files: AntLogger.java Log Message: Added MessageTranslator member, for passing to ApiDifference.getReport method. Index: AntLogger.java =================================================================== RCS file: /cvsroot/clirr/clirr/src/java/net/sf/clirr/ant/AntLogger.java,v retrieving revision 1.8 retrieving revision 1.9 diff -u -r1.8 -r1.9 --- AntLogger.java 29 Jun 2004 07:00:02 -0000 1.8 +++ AntLogger.java 2 Jul 2004 02:32:00 -0000 1.9 @@ -25,6 +25,7 @@ import net.sf.clirr.event.ApiDifference; import net.sf.clirr.event.DiffListenerAdapter; import net.sf.clirr.event.Severity; +import net.sf.clirr.event.MessageTranslator; import org.apache.tools.ant.Project; import org.apache.tools.ant.Task; @@ -32,6 +33,8 @@ { private Task task; + private MessageTranslator translator = new MessageTranslator(); + private Map severityPrioMap = new HashMap(3); AntLogger(Task task) @@ -49,7 +52,7 @@ task.log( severity.toString() + ": " + difference.getAffectedClass() - + ": " + difference.getReport(), + + ": " + difference.getReport(translator), prio.intValue()); } } |
From: Simon K. <s_k...@us...> - 2004-07-02 02:31:14
|
Update of /cvsroot/clirr/clirr/src/java/net/sf/clirr/event In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv15168 Modified Files: XmlDiffListener.java Log Message: Added MessageTranslator member, for passing to ApiDifference.getReport method. Index: XmlDiffListener.java =================================================================== RCS file: /cvsroot/clirr/clirr/src/java/net/sf/clirr/event/XmlDiffListener.java,v retrieving revision 1.11 retrieving revision 1.12 diff -u -r1.11 -r1.12 --- XmlDiffListener.java 27 Jun 2004 14:21:35 -0000 1.11 +++ XmlDiffListener.java 2 Jul 2004 02:31:05 -0000 1.12 @@ -34,6 +34,8 @@ private static final String DIFFREPORT = "diffreport"; private static final String DIFFERENCE = "difference"; + private MessageTranslator translator = new MessageTranslator(); + public XmlDiffListener(String outFile) throws IOException { super(outFile); @@ -55,7 +57,7 @@ out.print(" field=\"" + difference.getAffectedField() + "\""); } out.print(">"); - out.print(difference.getReport()); // TODO: XML escapes?? + out.print(difference.getReport(translator)); // TODO: XML escapes?? out.println("</" + DIFFERENCE + '>'); } |
From: Simon K. <s_k...@us...> - 2004-07-02 02:30:24
|
Update of /cvsroot/clirr/clirr/src/java/net/sf/clirr/event In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv14923 Modified Files: PlainDiffListener.java Log Message: Add MessageTranslator member, for passing to ApiDifference.getReport method. Index: PlainDiffListener.java =================================================================== RCS file: /cvsroot/clirr/clirr/src/java/net/sf/clirr/event/PlainDiffListener.java,v retrieving revision 1.6 retrieving revision 1.7 diff -u -r1.6 -r1.7 --- PlainDiffListener.java 29 Jun 2004 07:06:30 -0000 1.6 +++ PlainDiffListener.java 2 Jul 2004 02:30:14 -0000 1.7 @@ -22,9 +22,9 @@ import java.io.IOException; import java.io.PrintStream; - public final class PlainDiffListener extends FileDiffListener { + private MessageTranslator translator = new MessageTranslator(); public PlainDiffListener(String outFile) throws IOException { @@ -45,7 +45,7 @@ out.print(": "); out.print(difference.getAffectedClass()); out.print(": "); - out.println(difference.getReport()); + out.println(difference.getReport(translator)); } } |
From: Simon K. <s_k...@us...> - 2004-07-02 02:29:04
|
Update of /cvsroot/clirr/clirr/src/java/net/sf/clirr/event In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv14589 Modified Files: ApiDifference.java Log Message: * removed constructors taking a "report" string parameter. All constructors now require a Message parameter. * added MessageTranslator parameter to the getReport method * removed equals and hashCode methods, as they are no longer needed (due to changes in unit tests). Index: ApiDifference.java =================================================================== RCS file: /cvsroot/clirr/clirr/src/java/net/sf/clirr/event/ApiDifference.java,v retrieving revision 1.13 retrieving revision 1.14 diff -u -r1.13 -r1.14 --- ApiDifference.java 29 Jun 2004 07:02:06 -0000 1.13 +++ ApiDifference.java 2 Jul 2004 02:28:54 -0000 1.14 @@ -81,48 +81,11 @@ private String affectedField; /** - * Create a new API differnce representation. - * - * @param report a human readable string describing the change that was made, must be non-null. - * @param severity the severity in terms of binary and source code compatibility, must be non-null. - * @param clazz the fully qualified class name where the change occured, must be non-null. - * @param method the method signature of the method that changed, <code>null</code> - * if no method was affected. - * @param field the field name where the change occured, <code>null</code> - * if no field was affected. + * The set of additional parameters that are available for use + * when building the actual message description. These vary depending + * upon the actual difference being reported. */ - public ApiDifference(String report, Severity severity, String clazz, String method, String field) - { - this(report, severity, severity, clazz, method, field); - } - - /** - * Create a new API differnce representation. - * - * @param report a human readable string describing the change that was made, must be non-null. - * @param binarySeverity the severity in terms of binary compatibility, must be non-null. - * @param sourceSeverity the severity in terms of source code compatibility, must be non-null. - * @param clazz the fully qualified class name where the change occured, must be non-null. - * @param method the method signature of the method that changed, <code>null</code> - * if no method was affected. - * @param field the field name where the change occured, <code>null</code> - * if no field was affected. - */ - public ApiDifference(String report, Severity binarySeverity, Severity sourceSeverity, - String clazz, String method, String field) - { - checkNonNull(report); - checkNonNull(binarySeverity); - checkNonNull(sourceSeverity); - checkNonNull(clazz); - - this.report = report; - this.binaryCompatibilitySeverity = binarySeverity; - this.sourceCompatibilitySeverity = sourceSeverity; - this.affectedClass = clazz; - this.affectedField = field; - this.affectedMethod = method; - } + private String[] extraInfo; /** * Invokes the two-severity-level version of this constructor. @@ -151,7 +114,7 @@ * must be non-null. * * @param clazz is the fully-qualified name of the class in which the - * change occurred. + * change occurred, must be non-null. * * @param method the method signature of the method that changed, * <code>null</code> if no method was affected. @@ -172,30 +135,23 @@ String field, String[] args) { - String desc = MessageManager.getInstance().getDesc(message); - int nArgs = 0; - if (args != null) - { - nArgs = args.length; - } - String[] strings = new String[nArgs + 3]; - strings[0] = clazz; - strings[1] = method; - strings[2] = field; - for (int i = 0; i < nArgs; ++i) - { - strings[i + 3] = args[i]; - } + checkNonNull(message); + checkNonNull(binarySeverity); + checkNonNull(sourceSeverity); + checkNonNull(clazz); this.message = message; - this.report = java.text.MessageFormat.format(desc, strings); this.binaryCompatibilitySeverity = binarySeverity; this.sourceCompatibilitySeverity = sourceSeverity; this.affectedClass = clazz; this.affectedField = field; this.affectedMethod = method; + this.extraInfo = args; } + /** + * Trivial utility method to verify that a specific object is non-null. + */ private void checkNonNull(Object o) { if (o == null) @@ -260,9 +216,29 @@ * * @return a human readable description of this API difference. */ - public String getReport() + public String getReport(MessageTranslator translator) { - return report; + if (report != null) + { + return report; + } + + String desc = translator.getDesc(message); + int nArgs = 0; + if (extraInfo != null) + { + nArgs = extraInfo.length; + } + String[] strings = new String[nArgs + 3]; + strings[0] = affectedClass; + strings[1] = affectedMethod; + strings[2] = affectedField; + for (int i = 0; i < nArgs; ++i) + { + strings[i + 3] = extraInfo[i]; + } + + return java.text.MessageFormat.format(desc, strings); } /** @@ -298,77 +274,6 @@ public String toString() { return report + " (" + binaryCompatibilitySeverity + ") - " - + getAffectedClass() + '[' + getAffectedField() + '/' + getAffectedMethod() + ']'; + + affectedClass + '[' + affectedField + '/' + affectedMethod + ']'; } - - /** - * {@inheritDoc} - */ - public boolean equals(Object o) - { - if (this == o) - { - return true; - } - - if (!(o instanceof ApiDifference)) - { - return false; - } - - final ApiDifference other = (ApiDifference) o; - - if (!report.equals(other.report)) - { - return false; - } - - if (!binaryCompatibilitySeverity.equals(other.binaryCompatibilitySeverity)) - { - return false; - } - - if (!sourceCompatibilitySeverity.equals(other.sourceCompatibilitySeverity)) - { - return false; - } - - - final String otherClass = other.affectedClass; - if (!affectedClass.equals(otherClass)) - { - return false; - } - - final String otherMethod = other.affectedMethod; - if (affectedMethod != null ? !affectedMethod.equals(otherMethod) : otherMethod != null) - { - return false; - } - - final String otherField = other.affectedField; - if (affectedField != null ? !affectedField.equals(otherField) : otherField != null) - { - return false; - } - - return true; - } - - /** - * {@inheritDoc} - */ - public int hashCode() - { - int result; - result = report != null ? report.hashCode() : 0; - result = HASHCODE_MAGIC * result + binaryCompatibilitySeverity.hashCode(); - result = HASHCODE_MAGIC * result + sourceCompatibilitySeverity.hashCode(); - result = HASHCODE_MAGIC * result + affectedClass.hashCode(); - result = HASHCODE_MAGIC * result + (affectedMethod != null ? affectedMethod.hashCode() : 0); - result = HASHCODE_MAGIC * result + (affectedField != null ? affectedField.hashCode() : 0); - return result; - } - - } |
From: Simon K. <s_k...@us...> - 2004-07-02 02:26:03
|
Update of /cvsroot/clirr/clirr/src/java/net/sf/clirr/event In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv14281 Added Files: MessageTranslator.java Log Message: Handles lookup of message text from resource bundles. --- NEW FILE --- ////////////////////////////////////////////////////////////////////////////// // Clirr: compares two versions of a java library for binary compatibility // Copyright (C) 2003 - 2004 Lars Kühne // // This library is free software; you can redistribute it and/or // modify it under the terms of the GNU Lesser General Public // License as published by the Free Software Foundation; either // version 2.1 of the License, or (at your option) any later version. // // This library 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 // Lesser General Public License for more details. // // You should have received a copy of the GNU Lesser General Public // License along with this library; if not, write to the Free Software // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA ////////////////////////////////////////////////////////////////////////////// package net.sf.clirr.event; import java.util.Locale; import java.util.Iterator; import java.util.Collection; import java.util.ResourceBundle; /** * Class which is capable of translating a Message object into a localised * string. */ public final class MessageTranslator { /** * The default base name of the resource bundle from which message * descriptions are read. */ public static final String DFLT_RESOURCE_NAME = "event-messages"; private Locale locale = Locale.getDefault(); private String resourceName = DFLT_RESOURCE_NAME; private ResourceBundle messageText; /** * This is a singleton class; to get an instance of this class, use * the getInstance method. */ public MessageTranslator() { } /** * Define the local language etc. Future calls to the getDesc method * will attempt to use a properties file which is appropriate to that * locale to look the message descriptions up in. * <p> * @param locale may be a valid Locale object, or null to indicate * that the default locale is to be used. */ public void setLocale(Locale locale) { if (locale == null) { locale = Locale.getDefault(); } this.locale = locale; this.messageText = null; } /** * Define the base name of the properties file that message * translations are to be read from. */ public void setResourceName(String resourceName) { this.resourceName = resourceName; this.messageText = null; } /** * Verify that the resource bundle for the currently set locale has * a translation string available for every message object in the provided * collection. This method is expected to be called from the unit tests, * so that if a developer adds a new message the unit tests will fail until * translations are also available for that new message. * <p> * @throws java.util.MissingResourceException if there is a registered * message for which no description is present in the current locale's * resources. */ public void checkComplete(Collection messages) { for (Iterator i = messages.iterator(); i.hasNext();) { Message m = (Message) i.next(); getDesc(m); } } /** * Given a Message object (containing a unique message id), look up * that id in the appropriate resource bundle (properties file) for * the set locale and return the text string associated with that * message id. * <p> * Message ids in the properties file should be prefixed with an 'm', * eg "m1000", "m5003". * <p> * @throws java.util.MissingResourceException if there is no entry in the * message translation resource bundle for the specified message. */ public String getDesc(Message msg) { // load resource bundle if (locale == null) { locale = Locale.getDefault(); } if (messageText == null) { messageText = ResourceBundle.getBundle(resourceName, locale); } return messageText.getString("m" + msg.getId()); } } |
From: Simon K. <s_k...@us...> - 2004-07-02 02:25:34
|
Update of /cvsroot/clirr/clirr/src/java/net/sf/clirr/event In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv14242 Modified Files: MessageManager.java Log Message: Moved all locale & resource related code to new MessageTranslator class. Index: MessageManager.java =================================================================== RCS file: /cvsroot/clirr/clirr/src/java/net/sf/clirr/event/MessageManager.java,v retrieving revision 1.2 retrieving revision 1.3 diff -u -r1.2 -r1.3 --- MessageManager.java 29 Jun 2004 20:22:35 -0000 1.2 +++ MessageManager.java 2 Jul 2004 02:25:26 -0000 1.3 @@ -19,11 +19,10 @@ package net.sf.clirr.event; -import java.util.Locale; import java.util.Iterator; import java.util.ArrayList; import java.util.Comparator; -import java.util.ResourceBundle; +import java.util.Collection; /** * Class which manages API Difference messages, including expanding message @@ -31,16 +30,8 @@ */ public final class MessageManager { - /** - * The base name of the resource bundle from which message descriptions - * are read. - */ - public static final String RESOURCE_NAME = "event-messages"; - private static MessageManager instance; private ArrayList messages = new ArrayList(); - private Locale locale; - private ResourceBundle messageText; /** * Utility class to sort messages by their numeric ids. @@ -84,24 +75,6 @@ } /** - * Define the local language etc. Future calls to the getDesc method - * will attempt to use a properties file which is appropriate to that - * locale to look the message descriptions up in. - * <p> - * @param locale may be a valid Locale object, or null to indicate - * that the default locale is to be used. - */ - public void setLocale(Locale locale) - { - if (locale == null) - { - locale = Locale.getDefault(); - } - this.locale = locale; - this.messageText = null; - } - - /** * Verify that the list of known messages contains no two objects * with the same numeric message id. This method is expected to be * called from the unit tests, so that if a developer adds a new @@ -128,51 +101,10 @@ } /** - * Verify that the resource bundle for the currently set locale has - * a translation string available for every registered message object. - * This method is expected to be called from the unit tests, so that - * if a developer adds a new message the unit tests will fail until - * translations are also available for that new message. - * <p> - * @throws java.util.MissingResourceException if there is a registered - * message for which no description is present in the current locale's - * resources. - */ - public void checkComplete() - { - java.util.Collections.sort(messages, new MessageComparator()); - for (Iterator i = messages.iterator(); i.hasNext();) - { - Message m = (Message) i.next(); - getDesc(m); - } - } - - /** - * Given a Message object (containing a unique message id), look up - * that id in the appropriate resource bundle (properties file) for - * the set locale and return the text string associated with that - * message id. - * <p> - * Message ids in the properties file should be prefixed with an 'm', - * eg "m1000", "m5003". - * <p> - * @throws java.util.MissingResourceException if there is no entry in the - * message translation resource bundle for the specified message. + * Return the complete set of registered messages. */ - public String getDesc(Message msg) + public Collection getMessages() { - // load resource bundle - if (locale == null) - { - locale = Locale.getDefault(); - } - - if (messageText == null) - { - messageText = ResourceBundle.getBundle(RESOURCE_NAME, locale); - } - - return messageText.getString("m" + msg.getId()); + return messages; } } |