All Downloads are FREE. Search and download functionalities are using the official Maven repository.

META-INF.jqassistant-rules.osgi-bundle.xml Maven / Gradle / Ivy

<jqa:jqassistant-rules xmlns:jqa="http://www.buschmais.com/jqassistant/core/analysis/rules/schema/v1.0">

    <concept id="osgi-bundle:Bundle">
        <description>Labels all artifacts with a manifest declaring a bundle name as "Osgi" and "Bundle" and adds the
            properties "bundleSymbolicName" and "bundleVersion".
        </description>
        <cypher><![CDATA[
            MATCH
              (bundle:Artifact)-[:CONTAINS]->(manifest:Manifest:File),
              (manifest)-[DECLARES]->(section:ManifestSection),
              (section)-[:HAS]->(nameEntry:ManifestEntry),
              (section)-[:HAS]->(versionEntry:ManifestEntry)
            WHERE
              nameEntry.name = "Bundle-SymbolicName"
              AND versionEntry.name = "Bundle-Version"
            SET
              bundle:Osgi:Bundle,
              bundle.bundleSymbolicName = nameEntry.value,
              bundle.bundleVersion = versionEntry.value
            RETURN
              bundle as Bundle, bundle.bundleSymbolicName as BundleSymbolicName, bundle.bundleVersion as BundleVersion
        ]]></cypher>
    </concept>

    <concept id="osgi-bundle:ExportPackage">
        <requiresConcept refId="osgi-bundle:Bundle"/>
        <description>Creates an EXPORTS relation from a bundle artifact to all packages which are declared as
            "Export-Package" in the bundle manifest.
        </description>
        <cypher><![CDATA[
            match
             (bundle:Osgi:Bundle)-[:CONTAINS]->(package:Package)
            with
              bundle, package, "(^|.*,)\\s*"+ replace(package.fqn, ".", "\\.")+"\\s*((;|,).*|$)" as pattern
            match
              (bundle)-[:CONTAINS]->(manifest:File:Manifest),
              (manifest)-[:DECLARES]->(section:ManifestSection),
              (section)-[:HAS]->(entry:ManifestEntry)
            where
              entry.name = "Export-Package"
              AND entry.value=~ pattern
            create unique
              (bundle)-[:EXPORTS]->(package)
            return
              bundle as Bundle, collect(package) as ExportedPackages
        ]]></cypher>
    </concept>

    <concept id="osgi-bundle:ImportPackage">
        <requiresConcept refId="osgi-bundle:Bundle"/>
        <description>Creates an IMPORTS relation from a bundle artifact to all packages which are declared as
            "Import-Package" in the bundle manifest.
        </description>
        <cypher><![CDATA[
            match
             (package:Package)
            with
              package, "(^|.*,)\\s*"+ replace(package.fqn, ".", "\\.")+"\\s*((;|,).*|$)" as pattern
            match
              (bundle:Osgi:Bundle)-[:CONTAINS]->(manifest:File:Manifest),
              (manifest)-[:DECLARES]->(section:ManifestSection),
              (section)-[:HAS]->(entry:ManifestEntry)
            where
              entry.name = "Import-Package"
              and entry.value =~ pattern
            create unique
              (bundle)-[:IMPORTS]->(package)
            return
              bundle as Bundle, collect(package) as ImportedPackages
        ]]></cypher>
    </concept>

    <concept id="osgi-bundle:Activator">
        <requiresConcept refId="osgi-bundle:Bundle"/>
        <description>Creates an ACTIVATES relation between a class and the bundle artifact if the class is declared as
            "Bundle-Activator" in the bundle
            manifest.
        </description>
        <cypher><![CDATA[
            match
              (bundle:Osgi:Bundle)-[:CONTAINS]->(manifest:File:Manifest),
              (manifest)-[:DECLARES]->(section:ManifestSection),
              (section)-[:HAS]->(entry:ManifestEntry),
              (bundle)-[:CONTAINS]->(activator:Class)
            where
              entry.name = "Bundle-Activator"
              and entry.value = activator.fqn
            create unique
              (activator)-[:ACTIVATES]->(bundle)
            return
              activator as Activator, bundle as Bundle
        ]]></cypher>
    </concept>

    <concept id="osgi-bundle:InternalType">
        <requiresConcept refId="osgi-bundle:ExportPackage"/>
        <description>Labels all internal types (i.e. which are not located in an exported package) as "Internal".
        </description>
        <cypher><![CDATA[
            match
              (bundle:Bundle:Osgi)-[:CONTAINS]->(internalPackage:Package),
              (bundle)-[:CONTAINS]->(internalType:Type),
              (internalPackage)-[:CONTAINS]->(internalType:Type)
            where not
                (bundle)-[:EXPORTS]->(internalPackage)
            set
              internalType:Internal
            return bundle as Bundle, collect(internalType) as InternalTypes
        ]]></cypher>
    </concept>

    <constraint id="osgi-bundle:UnusedInternalType">
        <requiresConcept refId="osgi-bundle:InternalType"/>
        <requiresConcept refId="osgi-bundle:Activator"/>
        <description>A bundle must not contain internal types which are not used by other types in the bundle.
        </description>
        <cypher><![CDATA[
            match
              (bundle:Osgi:Bundle)-[:CONTAINS]->(internalType:Type:Internal)
            where not (
                (internalType)-[:ACTIVATES]->(bundle)
              or
                (bundle)-[:CONTAINS]->(:Type)-[:DEPENDS_ON]->(internalType)
            )
            return
              bundle as Bundle, internalType as InternalType
        ]]></cypher>
    </constraint>

    <constraint id="osgi-bundle:InternalTypeMustNotBePublic">
        <requiresConcept refId="osgi-bundle:InternalType"/>
        <requiresConcept refId="osgi-bundle:Activator"/>
        <description>Internal types must not be public if no depending types exist in other packages of the bundle.
        </description>
        <cypher><![CDATA[
            match
              (bundle:Osgi:Bundle)-[:CONTAINS]->(internalType:Type:Internal),
              (internalPackage:Package)-[:CONTAINS]->(internalType)
            optional match
              (bundle)-[:CONTAINS]->(otherPackage:Package),
              (otherPackage)-[:CONTAINS]->()-[:DEPENDS_ON]->(internalType)
            where
              internalType.visibility='public'
            with
              bundle, internalPackage, internalType, collect(otherPackage) as otherPackages
            where
              all(otherPackage in otherPackages where internalPackage = otherPackage)
              and not
                (internalType)-[:ACTIVATES]->(bundle)
            return
              bundle as Bundle, internalType as InternalType
        ]]></cypher>
    </constraint>

</jqa:jqassistant-rules>




© 2015 - 2024 Weber Informatics LLC | Privacy Policy