Skip to content

Make apex-common accessable over shared namespace 2nd gen packages#520

Open
nwcm wants to merge 6 commits intoapex-enterprise-patterns:masterfrom
nwcm:namespaceAccessible
Open

Make apex-common accessable over shared namespace 2nd gen packages#520
nwcm wants to merge 6 commits intoapex-enterprise-patterns:masterfrom
nwcm:namespaceAccessible

Conversation

@nwcm
Copy link
Contributor

@nwcm nwcm commented Nov 10, 2025

Annotate public and protected with @NamespaceAccessible

Open for discussion, still validating these changes.


This change is Reviewable

@nwcm nwcm marked this pull request as ready for review November 13, 2025 22:32
@afawcett
Copy link
Contributor

afawcett commented Jan 8, 2026

@nwcm how did this go for you?? any gotchas?

@nwcm
Copy link
Contributor Author

nwcm commented Jan 8, 2026

@nwcm how did this go for you?? any gotchas?

Have validated this with a base 2GP package with extension package with dependency. All working without issue

Copy link
Contributor

@daveespo daveespo left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@daveespo made 1 comment.
Reviewable status: 0 of 21 files reviewed, 1 unresolved discussion (waiting on @john-storey-devops and @nwcm).


a discussion (no related file):
@john-storey-devops It looks like this PR also has a tabs vs. spaces problem. A lot of the changes you introduced replaced whitespace. Can you restore the whitespace as it was so that this PR is solely about adding the @namespaceaccessible

Separately, we'd like the same treatment applied to fflib-apex-mocks so that 2GP developers that want to move AEP into its own package can use Mocks as well. Do you have time to propose that PR for fflib-apex-mocks?

Down the road, we'll do force-di and at4dx but those projects are less adopted than fflib-apex-common (and it's required dependency fflib-apex-mocks) so we'll defer that work for another day.

@nwcm
Copy link
Contributor Author

nwcm commented Jan 18, 2026

@daveespo made 1 comment.
Reviewable status: 0 of 21 files reviewed, 1 unresolved discussion (waiting on @john-storey-devops and @nwcm).

a discussion (no related file): @john-storey-devops It looks like this PR also has a tabs vs. spaces problem. A lot of the changes you introduced replaced whitespace. Can you restore the whitespace as it was so that this PR is solely about adding the @namespaceaccessible

Separately, we'd like the same treatment applied to fflib-apex-mocks so that 2GP developers that want to move AEP into its own package can use Mocks as well. Do you have time to propose that PR for fflib-apex-mocks?

Down the road, we'll do force-di and at4dx but those projects are less adopted than fflib-apex-common (and it's required dependency fflib-apex-mocks) so we'll defer that work for another day.

I have addressed the spaces. However, as this project does not have a unified formatter the existing files already have a mix of spaces and tabs. So, there are now diffs converting spaces to tabs. I would suggest implementing prettier with the "@prettier/plugin-xml", "prettier-plugin-apex" plugins

@nwcm
Copy link
Contributor Author

nwcm commented Jan 19, 2026

I don't have too much time, but here is a start at custom PMD rules for flagging missing annotations. Will need some work

<?xml version="1.0" encoding="UTF-8"?>
<ruleset name="Namespace Accessible" xmlns="http://pmd.sourceforge.net/ruleset/2.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://pmd.sourceforge.net/ruleset/2.0.0 https://pmd.sourceforge.io/ruleset_2_0_0.xsd">

    <description>Ensure source supports access over namespace for 2GP packages</description>

    <rule name="ClassesMustBeNamespaceAccessible" language="apex" message="Public or protected classes must be annotated with @namespaceAccessiable" class="net.sourceforge.pmd.lang.rule.xpath.XPathRule">
        <description>Public or protected classes must be annotated as @NamespaceAccessible</description>
        <priority>2</priority>
        <properties>
            <property name="xpath">
                <value>
<![CDATA[
//UserClass[ModifierNode[@Public=true() or @Protected=true()][not(Annotation[@Image = 'NamespaceAccessible'])]]
]]>
         </value>
            </property>
        </properties>
    </rule>

    <rule name="MethodsMustBeNamespaceAccessible"
      language="apex"
      message="Public or protected class methods must be annotated as @NamespaceAccessible"
      class="net.sourceforge.pmd.lang.rule.xpath.XPathRule">
   <description>

   </description>
   <priority>2</priority>
   <properties>
      <property name="xpath">
         <value>
<![CDATA[
//UserClass[ModifierNode[@Public=true() or @Protected=true()]]/Method[ModifierNode[@Public=true() or @Protected=true()]]
[not(ModifierNode/Annotation[@Image = 'NamespaceAccessible'])]
]]>
         </value>
      </property>
   </properties>
</rule>

</ruleset>

@afawcett
Copy link
Contributor

afawcett commented Mar 9, 2026

Thanks @nwcm for the above - looking to get this one through soon for you - thanks for your patience.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants