Class: Packages::Maven::FindOrCreatePackageService
- Inherits:
-
BaseService
- Object
- BaseService
- Packages::Maven::FindOrCreatePackageService
- Defined in:
- app/services/packages/maven/find_or_create_package_service.rb
Constant Summary collapse
- SNAPSHOT_TERM =
'-SNAPSHOT'
- MAX_FILE_NAME_LENGTH =
5000
Instance Attribute Summary
Attributes inherited from BaseService
#current_user, #params, #project
Instance Method Summary collapse
Methods inherited from BaseService
Methods included from BaseServiceUtility
#deny_visibility_level, #event_service, #log_error, #log_info, #notification_service, #system_hook_service, #todo_service, #visibility_level
Methods included from Gitlab::Allowable
Constructor Details
This class inherits a constructor from BaseService
Instance Method Details
#execute ⇒ Object
8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 |
# File 'app/services/packages/maven/find_or_create_package_service.rb', line 8 def execute return ServiceResponse.error(message: 'File name is too long') if file_name_too_long? package = ::Packages::Maven::PackageFinder.new(current_user, project, path: path) .execute unless Namespace::PackageSetting.duplicates_allowed?(package) return ServiceResponse.error(message: 'Duplicate package is not allowed') if target_package_is_duplicate?(package) end unless package # Maven uploads several files during `mvn deploy` in next order: # - my-company/my-app/1.0-SNAPSHOT/my-app.jar # - my-company/my-app/1.0-SNAPSHOT/my-app.pom # - my-company/my-app/1.0-SNAPSHOT/maven-metadata.xml # - my-company/my-app/maven-metadata.xml # # The last xml file does not have VERSION in URL because it contains # information about all versions. When uploading such file, we create # a package with a version set to `nil`. The xml file with a version # is only created and uploaded for snapshot versions. # # Gradle has a different upload order: # - my-company/my-app/1.0-SNAPSHOT/maven-metadata.xml # - my-company/my-app/1.0-SNAPSHOT/my-app.jar # - my-company/my-app/1.0-SNAPSHOT/my-app.pom # - my-company/my-app/maven-metadata.xml # # The first upload has to create the proper package (the one with the version set). if file_name == Packages::Maven::Metadata.filename && !snapshot_version? package_name = path version = nil else package_name, _, version = path.rpartition('/') end package_params = { name: package_name, path: path, status: params[:status], version: version } package = ::Packages::Maven::CreatePackageService.new(project, current_user, package_params) .execute end package.create_build_infos!(params[:build]) ServiceResponse.success(payload: { package: package }) end |