10: Create UsesSdkPlugin

This commit is contained in:
Bartłomiej Pluta
2019-04-05 21:23:06 +02:00
parent 84f691a8a5
commit dd859e76f4
3 changed files with 49 additions and 1 deletions

View File

@@ -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);
}
}

View File

@@ -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));
}
}

View File

@@ -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.
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 <uses-sdk> defined in AndroidManifest.xml file.\n\
In order to use this tool, <uses-sdk> should be defined in AndroidManifest.xml with android:minSdkVersion attribute at least.\n\
This element should be placed below the root (<manifest>) level.\n\
For example:\n\
<manifest>\n\
\t<uses-sdk android:minSdkVersion="23">\n\
\t...\n\
</manifest>
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 <uses-sdk> element.\n\
For example: <uses-sdk android:minSdkVersion="23">