Re: [macker-user] <Allow> tag doesn't consider my patterns?
Brought to you by:
barredijkstra,
melquiades
From: Paul C. <can...@po...> - 2007-09-25 19:50:40
|
Hi, Jeremy. The misunderstanding is the meaning of the access-rule. The Macker guide mentions that: > When the first item in [a pattern] is an include, everything starts > out excluded; conversely, when the first item is an exclude, > everything starts out included. ...and similarly, when the first item in an access-rule is "deny", everything starts out allowed; when it is "allow," everything starts out denied. In order words, every access rule starts out with an implicit element that either allows or denies everything. So your access rule: <access-rule> <allow> <from pattern="patternWorld3" /> <to class="java.**" /> </allow> </access-rule> ...is equivalent to: <access-rule> <deny> <!-- implicit rule --> <from class="**" /> <to class="**" /> </deny> <allow> <from pattern="patternWorld3" /> <to class="java.**" /> </allow> </access-rule> ...which means that the only dependencies in the universe that are allowed are from patternWorld3 to java.**. The rule will fail on any class not matched by patternWorld3, no matter what it does. Does that make any sense? To say, "if the class matches patternWorld3, it may only access java.**", do this: <access-rule> <deny> <from pattern="patternWorld3" /> </deny> <allow> <to class="java.**" /> </allow> </access-rule> Here that implicit first rule allows everything, because the first explicit rule is a deny. We then deny everything from patternWorld3, then allow back in the references we want. There are numerous other ways to do it. This is probably the most straightforward. In general, it is unusual for access rules to start with an <allow> element. Not necessarily bad, but unusual that it's really what you want. Incidentally, I'm adding SweetXML support to the next version of Macker, which would let you optionally write the above as: access-rule deny from pattern="patternWorld3" allow to class="java.**" Cheers, Paul On Sep 25, 2007, at 10:23 AM, copernic Jeremy wrote: > Hi all, > I am facing a strange behaviour with Macker. > > I have a project containing three PrintHelloWorld classes: > - PrintHelloWorld1 > - PrintHelloWorld2 > - PrintHelloWorld3 > > My macker.xml rules file contain a pattern that only includes my > PrintHelloWorld3 class. And I only have one access-rule that state > that the classes contained by my pattern "patternWorld3" has to > only access the "java.**" classes. > > So my macker.xml file looks like that: > > > <macker> > <ruleset name="Simple example"> > <pattern name="patternWorld3"> > <include class="PrintHelloWorld"/> > </pattern> > > <access-rule> > <allow> > <from pattern="patternWorld3" /> > <to class="java.**" /> > </allow> > </access-rule> > </ruleset> > </macker> > > The problem is that when I check the rules with the command ant > macker , Macker tells me that the other classes (PrintHelloWorld1 > and PrintHelloWorld2) , that aren't supposed to be included in the > pattern "patternWorld3", are also violating my access-rule. > > This is the trace I get: > > macker: > [macker] > [macker] (Checking ruleset: Simple example ...) > [macker] > [macker] Illegal reference > [macker] from PrintHelloWorld > [macker] to void > [macker] > [macker] Illegal reference > [macker] from PrintHelloWorld2 > [macker] to java.io.PrintStream > [macker] > [macker] Illegal reference > [macker] from PrintHelloWorld2 > [macker] to java.lang.Object > [macker] > [macker] Illegal reference > [macker] from PrintHelloWorld2 > [macker] to java.lang.String > [macker] > [macker] Illegal reference > [macker] from PrintHelloWorld2 > [macker] to java.lang.System > [macker] > [macker] Illegal reference > [macker] from PrintHelloWorld2 > [macker] to void > [macker] > [macker] Illegal reference > [macker] from PrintHelloWorld3 > [macker] to java.io.PrintStream > [macker] > [macker] Illegal reference > [macker] from PrintHelloWorld3 > [macker] to java.lang.Object > [macker] > [macker] Illegal reference > [macker] from PrintHelloWorld3 > [macker] to java.lang.String > [macker] > [macker] Illegal reference > [macker] from PrintHelloWorld3 > [macker] to java.lang.System > [macker] > [macker] Illegal reference > [macker] from PrintHelloWorld3 > [macker] to void > [macker] > [macker] (11 errors) > [macker] > [macker] Macker rules checking failed > > BUILD FAILED > > This is strange because I thought that normally I only should get > errors from PrintHelloWorld3, defined my the pattern. > The <allow> rule tag doesn't seems to take into consideration my > pattern and in fact apply the rule checking on all of the primary > classes (PrintHelloWorld1, PrintHelloWorld2 and PrintHelloWorld3). > The only way to currently bypass that issue is to use a subset on > the patternWorld3 so by adding this line to the macker.xml file: > > <subset pattern="patternWorld3"/> > > then I get the what I was looking for: > > macker: > [macker] > [macker] (Checking ruleset: Simple example ...) > [macker] > [macker] Illegal reference > [macker] from PrintHelloWorld > [macker] to void > [macker] > [macker] (1 error) > [macker] > [macker] Macker rules checking failed > > BUILD FAILED > > > Why is my patternWorld3 isn't consider without a subset tag in my > allow statement? > Have I understood wrongly the semantic of the <allow> tag, or the > pattern? > > thanks in advance, > > Cheers, > Jeremy > > > ---------------------------------------------------------------------- > --- > This SF.net email is sponsored by: Microsoft > Defy all challenges. Microsoft(R) Visual Studio 2005. > http://clk.atdmt.com/MRT/go/vse0120000070mrt/direct/01/ > _______________________________________________ > Macker-user mailing list > Mac...@li... > https://lists.sourceforge.net/lists/listinfo/macker-user > > Macker home page: http://innig.net/macker/ |