diff options
Diffstat (limited to 'app/services/projects/android_target_platform_detector_service.rb')
-rw-r--r-- | app/services/projects/android_target_platform_detector_service.rb | 35 |
1 files changed, 35 insertions, 0 deletions
diff --git a/app/services/projects/android_target_platform_detector_service.rb b/app/services/projects/android_target_platform_detector_service.rb new file mode 100644 index 00000000000..11635ad18d5 --- /dev/null +++ b/app/services/projects/android_target_platform_detector_service.rb @@ -0,0 +1,35 @@ +# frozen_string_literal: true + +module Projects + # Service class to detect if a project is made to run on the Android platform. + # + # This service searches for an AndroidManifest.xml file which all Android app + # project must have. It returns the symbol :android if the given project is an + # Android app project. + # + # Ref: https://developer.android.com/guide/topics/manifest/manifest-intro + # + # Example usage: + # > AndroidTargetPlatformDetectorService.new(a_project).execute + # => nil + # > AndroidTargetPlatformDetectorService.new(an_android_project).execute + # => :android + class AndroidTargetPlatformDetectorService < BaseService + # <manifest> element is required and must occur once inside AndroidManifest.xml + MANIFEST_FILE_SEARCH_QUERY = '<manifest filename:AndroidManifest.xml' + + def execute + detect + end + + private + + def file_finder + @file_finder ||= ::Gitlab::FileFinder.new(project, project.default_branch) + end + + def detect + return :android if file_finder.find(MANIFEST_FILE_SEARCH_QUERY).present? + end + end +end |