Class: Packages::Maven::FindOrCreatePackageService

Inherits:
BaseService
  • Object
show all
Defined in:
app/services/packages/maven/find_or_create_package_service.rb

Constant Summary collapse

MAVEN_METADATA_FILE =
'maven-metadata.xml'.freeze
SNAPSHOT_TERM =
'-SNAPSHOT'.freeze

Instance Attribute Summary

Attributes inherited from BaseService

#current_user, #params, #project

Instance Method Summary collapse

Methods inherited from BaseService

#initialize

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

#can?

Constructor Details

This class inherits a constructor from BaseService

Instance Method Details

#executeObject


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
# File 'app/services/packages/maven/find_or_create_package_service.rb', line 8

def execute
  package =
    ::Packages::Maven::PackageFinder.new(params[:path], current_user, project: project)
                                    .execute

  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 params[:file_name] == MAVEN_METADATA_FILE && !params[:path]&.ends_with?(SNAPSHOT_TERM)
      package_name, version = params[:path], nil
    else
      package_name, _, version = params[:path].rpartition('/')
    end

    package_params = {
      name: package_name,
      path: params[:path],
      version: version,
      build: params[:build]
    }

    package =
      ::Packages::Maven::CreatePackageService.new(project, current_user, package_params)
                                             .execute
  end

  package
end