Skip to content
This repository was archived by the owner on Feb 26, 2023. It is now read-only.

Conversation

@smaugho
Copy link
Contributor

@smaugho smaugho commented Oct 2, 2016

#1860 .

Copy link
Member

@WonderCsabo WonderCsabo left a comment

Choose a reason for hiding this comment

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

Thanks for this pull request!

Can you address my comments and squash your commits into a single commit?

This will collect all <meta-data> elements from all components into a single map. Is this okay for the general use-case?

}

public Map<String, String> getMetaDataQualifiedNames() {
return metaDataQualifiedNames;
Copy link
Member

@WonderCsabo WonderCsabo Oct 3, 2016

Choose a reason for hiding this comment

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

Please use Collections.unmodifiableMap(metaDataQualifiedNames) here.

Node nameAttribute = node.getAttributes().getNamedItem("android:name");
Node valueAttribute = node.getAttributes().getNamedItem("android:value");

if (nameAttribute == null || valueAttribute == null) {
Copy link
Member

@WonderCsabo WonderCsabo Oct 3, 2016

Choose a reason for hiding this comment

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

Can you flatten this if?

if (nameAttribute == null && valueAttribute == null) {
  // malformed
} else if (nameAttribute != null) {
  // malformed with name
} else {
  // add it
}

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Hi, I will make a review, and I will check directly the docs https://developer.android.com/guide/topics/manifest/meta-data-element.html, in General, I solved it to the needs of collecting the tags from within the manifest, and following the general structure:

<meta-data android:name="zoo" android:value="@string/kangaroo" />

I used also a Key-Value (a Map) to store and read all the elements. Checking in the docs, there's also a 3rd attribute that can be written in the Manifest, android:resource, never use it before to be honest, but in the general case should be included.

Maybe return a Map<String, SomeObject>, with SomeObject being a pair Value, Resource?.

On the other hands, I'm collecting the Metadata at the root level (Application), but it can be applied to:

    <activity>
    <activity-alias>
    <application>
    <provider>
    <receiver>
    <service>

In a general scenario, a reference to the parent tag should be also stored.

Any suggestion about this?
.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Checking now the code, I see that also a specific method is called to collect other tasks, I will do the same, to follow the same "rules". This was something I did like 1year ago, so probably the structure of the file was different for then, I will review this too.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Ah, about "flatting the if", now checking, I followed same structure for collecting other tags.. Do I flag them all?

private List<String> extractComponentNames(String applicationPackage, NodeList componentNodes) {
        List<String> componentQualifiedNames = new ArrayList<>();

        for (int i = 0; i < componentNodes.getLength(); i++) {
            Node activityNode = componentNodes.item(i);
            Node nameAttribute = activityNode.getAttributes().getNamedItem("android:name");

            String qualifiedName = manifestNameToValidQualifiedName(applicationPackage, nameAttribute);

            if (qualifiedName != null) {
                componentQualifiedNames.add(qualifiedName);
            } else {
                if (nameAttribute != null) {
                    LOGGER.warn("A class activity declared in the AndroidManifest.xml cannot be found in the compile path: [{}]", nameAttribute.getNodeValue());
                } else {
                    LOGGER.warn("The {} activity node in the AndroidManifest.xml has no android:name attribute", i);
                }
            }
        }
        return componentQualifiedNames;
    }

Copy link
Member

Choose a reason for hiding this comment

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

OOps, i missed the already existing ifs. In this case, i think you did the right thing, this way the code is consistent. We can refactor all ifs later.

Copy link
Member

Choose a reason for hiding this comment

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

i think documentElement.getElementsByTagName() will traverse this recursively and return all <meta-data> in components as well, doesn't it?

Copy link
Contributor Author

@smaugho smaugho Oct 3, 2016

Choose a reason for hiding this comment

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

Yes it returns all the tags....

@smaugho smaugho force-pushed the 1860_reading_metadata_from_manifest branch from 2103b7f to 508bf6c Compare October 3, 2016 16:38
@smaugho
Copy link
Contributor Author

smaugho commented Oct 3, 2016

Hi, I updated the requested changes, and merged all into a single commit.

@WonderCsabo WonderCsabo changed the title 1860 reading metadata from manifest Reading metadata from manifest Oct 4, 2016
@WonderCsabo WonderCsabo merged commit a0ecbce into androidannotations:develop Oct 4, 2016
@WonderCsabo
Copy link
Member

Thanks for your work!

@WonderCsabo WonderCsabo added this to the 4.2 milestone Oct 4, 2016
@smaugho smaugho deleted the 1860_reading_metadata_from_manifest branch October 16, 2016 14:27
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants