diff --git a/src/main/java/com/bartek/esa/core/di/PluginModule.java b/src/main/java/com/bartek/esa/core/di/PluginModule.java index c0f59ac..1858beb 100644 --- a/src/main/java/com/bartek/esa/core/di/PluginModule.java +++ b/src/main/java/com/bartek/esa/core/di/PluginModule.java @@ -63,4 +63,10 @@ public class PluginModule { public Plugin sharedUidPlugin(GlobMatcher globMatcher, XmlHelper xmlHelper) { return new SharedUidPlugin(globMatcher, xmlHelper); } + + @Provides + @IntoSet + public Plugin usesSdkPlugin(GlobMatcher globMatcher, XmlHelper xmlHelper) { + return new UsesSdkPlugin(globMatcher, xmlHelper); + } } diff --git a/src/main/java/com/bartek/esa/core/plugin/UsesSdkPlugin.java b/src/main/java/com/bartek/esa/core/plugin/UsesSdkPlugin.java new file mode 100644 index 0000000..a8704cb --- /dev/null +++ b/src/main/java/com/bartek/esa/core/plugin/UsesSdkPlugin.java @@ -0,0 +1,29 @@ +package com.bartek.esa.core.plugin; + +import com.bartek.esa.core.archetype.AndroidManifestPlugin; +import com.bartek.esa.core.model.enumeration.Severity; +import com.bartek.esa.core.xml.XmlHelper; +import com.bartek.esa.file.matcher.GlobMatcher; +import org.w3c.dom.Document; +import org.w3c.dom.Node; + +import javax.inject.Inject; +import javax.xml.xpath.XPathConstants; +import java.util.Optional; + +public class UsesSdkPlugin extends AndroidManifestPlugin { + + @Inject + public UsesSdkPlugin(GlobMatcher globMatcher, XmlHelper xmlHelper) { + super(globMatcher, xmlHelper); + } + + @Override + protected void run(Document xml) { + Optional.ofNullable((Node) xPath(xml, "/manifest/uses-sdk", XPathConstants.NODE)).ifPresentOrElse(usesSdkNode -> { + if(usesSdkNode.getAttributes().getNamedItem("android:minSdkVersion") == null) { + addIssue(Severity.ERROR, ".USES_SDK.NO_MIN_SDK_VERSION", null, null); + } + }, () -> addIssue(Severity.ERROR, ".NO_USES_SDK", null, null)); + } +} diff --git a/src/main/resources/description.properties b/src/main/resources/description.properties index d18b8bf..a19a336 100644 --- a/src/main/resources/description.properties +++ b/src/main/resources/description.properties @@ -50,4 +50,17 @@ com.bartek.esa.core.plugin.ImplicitIntentsPlugin.PENDING_INTENT=Creating pending com.bartek.esa.core.plugin.SharedUidPlugin=Making use of shared UserID.\n\ Shared UserID violates a sandbox nature of Android system. All applications working with the same UID work also \n\ within the same process and share granted permissions, resources and so on.\n\ - Remember, that if you really want to use this feature, after publishing your app, you won't be able to change it anymore. \ No newline at end of file + Remember, that if you really want to use this feature, after publishing your app, you won't be able to change it anymore. + +com.bartek.esa.core.plugin.UsesSdkPlugin.NO_USES_SDK=There is no defined in AndroidManifest.xml file.\n\ + In order to use this tool, should be defined in AndroidManifest.xml with android:minSdkVersion attribute at least.\n\ + This element should be placed below the root () level.\n\ + For example:\n\ + \n\ + \t\n\ + \t...\n\ + + +com.bartek.esa.core.plugin.UsesSdkPlugin.USES_SDK.NO_MIN_SDK_VERSION=There is no minSdkVersion defined in AndroidManifest.xml file.\n\ + In order to use this tool, minimal SDK version should be provided as the attribute of element.\n\ + For example: \ No newline at end of file