packagecloud-maven-importer 0.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +7 -0
- data/.gitignore +13 -0
- data/.rspec +3 -0
- data/.travis.yml +7 -0
- data/CODE_OF_CONDUCT.md +74 -0
- data/Gemfile +6 -0
- data/Gemfile.lock +41 -0
- data/LICENSE.txt +21 -0
- data/README.md +72 -0
- data/Rakefile +6 -0
- data/bin/console +14 -0
- data/bin/packagecloud-maven-importer +119 -0
- data/bin/setup +8 -0
- data/lib/packagecloud/maven/importer.rb +12 -0
- data/lib/packagecloud/maven/importer/database.rb +61 -0
- data/lib/packagecloud/maven/importer/main.rb +136 -0
- data/lib/packagecloud/maven/importer/patterns.rb +32 -0
- data/lib/packagecloud/maven/importer/version.rb +7 -0
- data/packagecloud-maven-importer.gemspec +32 -0
- metadata +146 -0
checksums.yaml
ADDED
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
---
|
|
2
|
+
SHA1:
|
|
3
|
+
metadata.gz: 53baa5cdde40fc42677e6e25a0a36071342e6e53
|
|
4
|
+
data.tar.gz: a90cd55d67de46727a5041013e7e01905109732a
|
|
5
|
+
SHA512:
|
|
6
|
+
metadata.gz: e7fa785d252769677e76fed1f41c33aadd5b5dad2b3e8fa2fb889afb22b4a5ae97704c52c09c2c97f30def0c0cd2f77f7cab058ff1595a2eac7ebc894550fc33
|
|
7
|
+
data.tar.gz: e5f52af6adaf6f3ce343c954191ca9a1a3e7ded5564224e111e18ce113b2a778f8de67f7d601cd88c026bde243f90b22d9b9fa87a106595f4169d5e638818f4e
|
data/.gitignore
ADDED
data/.rspec
ADDED
data/.travis.yml
ADDED
data/CODE_OF_CONDUCT.md
ADDED
|
@@ -0,0 +1,74 @@
|
|
|
1
|
+
# Contributor Covenant Code of Conduct
|
|
2
|
+
|
|
3
|
+
## Our Pledge
|
|
4
|
+
|
|
5
|
+
In the interest of fostering an open and welcoming environment, we as
|
|
6
|
+
contributors and maintainers pledge to making participation in our project and
|
|
7
|
+
our community a harassment-free experience for everyone, regardless of age, body
|
|
8
|
+
size, disability, ethnicity, gender identity and expression, level of experience,
|
|
9
|
+
nationality, personal appearance, race, religion, or sexual identity and
|
|
10
|
+
orientation.
|
|
11
|
+
|
|
12
|
+
## Our Standards
|
|
13
|
+
|
|
14
|
+
Examples of behavior that contributes to creating a positive environment
|
|
15
|
+
include:
|
|
16
|
+
|
|
17
|
+
* Using welcoming and inclusive language
|
|
18
|
+
* Being respectful of differing viewpoints and experiences
|
|
19
|
+
* Gracefully accepting constructive criticism
|
|
20
|
+
* Focusing on what is best for the community
|
|
21
|
+
* Showing empathy towards other community members
|
|
22
|
+
|
|
23
|
+
Examples of unacceptable behavior by participants include:
|
|
24
|
+
|
|
25
|
+
* The use of sexualized language or imagery and unwelcome sexual attention or
|
|
26
|
+
advances
|
|
27
|
+
* Trolling, insulting/derogatory comments, and personal or political attacks
|
|
28
|
+
* Public or private harassment
|
|
29
|
+
* Publishing others' private information, such as a physical or electronic
|
|
30
|
+
address, without explicit permission
|
|
31
|
+
* Other conduct which could reasonably be considered inappropriate in a
|
|
32
|
+
professional setting
|
|
33
|
+
|
|
34
|
+
## Our Responsibilities
|
|
35
|
+
|
|
36
|
+
Project maintainers are responsible for clarifying the standards of acceptable
|
|
37
|
+
behavior and are expected to take appropriate and fair corrective action in
|
|
38
|
+
response to any instances of unacceptable behavior.
|
|
39
|
+
|
|
40
|
+
Project maintainers have the right and responsibility to remove, edit, or
|
|
41
|
+
reject comments, commits, code, wiki edits, issues, and other contributions
|
|
42
|
+
that are not aligned to this Code of Conduct, or to ban temporarily or
|
|
43
|
+
permanently any contributor for other behaviors that they deem inappropriate,
|
|
44
|
+
threatening, offensive, or harmful.
|
|
45
|
+
|
|
46
|
+
## Scope
|
|
47
|
+
|
|
48
|
+
This Code of Conduct applies both within project spaces and in public spaces
|
|
49
|
+
when an individual is representing the project or its community. Examples of
|
|
50
|
+
representing a project or community include using an official project e-mail
|
|
51
|
+
address, posting via an official social media account, or acting as an appointed
|
|
52
|
+
representative at an online or offline event. Representation of a project may be
|
|
53
|
+
further defined and clarified by project maintainers.
|
|
54
|
+
|
|
55
|
+
## Enforcement
|
|
56
|
+
|
|
57
|
+
Instances of abusive, harassing, or otherwise unacceptable behavior may be
|
|
58
|
+
reported by contacting the project team at jcapote@gmail.com. All
|
|
59
|
+
complaints will be reviewed and investigated and will result in a response that
|
|
60
|
+
is deemed necessary and appropriate to the circumstances. The project team is
|
|
61
|
+
obligated to maintain confidentiality with regard to the reporter of an incident.
|
|
62
|
+
Further details of specific enforcement policies may be posted separately.
|
|
63
|
+
|
|
64
|
+
Project maintainers who do not follow or enforce the Code of Conduct in good
|
|
65
|
+
faith may face temporary or permanent repercussions as determined by other
|
|
66
|
+
members of the project's leadership.
|
|
67
|
+
|
|
68
|
+
## Attribution
|
|
69
|
+
|
|
70
|
+
This Code of Conduct is adapted from the [Contributor Covenant][homepage], version 1.4,
|
|
71
|
+
available at [http://contributor-covenant.org/version/1/4][version]
|
|
72
|
+
|
|
73
|
+
[homepage]: http://contributor-covenant.org
|
|
74
|
+
[version]: http://contributor-covenant.org/version/1/4/
|
data/Gemfile
ADDED
data/Gemfile.lock
ADDED
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
PATH
|
|
2
|
+
remote: .
|
|
3
|
+
specs:
|
|
4
|
+
packagecloud-maven-importer (0.1.0)
|
|
5
|
+
excon (= 0.62.0)
|
|
6
|
+
mustermann (= 1.0.3)
|
|
7
|
+
sqlite3 (= 1.3.13)
|
|
8
|
+
|
|
9
|
+
GEM
|
|
10
|
+
remote: https://rubygems.org/
|
|
11
|
+
specs:
|
|
12
|
+
diff-lcs (1.3)
|
|
13
|
+
excon (0.62.0)
|
|
14
|
+
mustermann (1.0.3)
|
|
15
|
+
rake (10.5.0)
|
|
16
|
+
rspec (3.8.0)
|
|
17
|
+
rspec-core (~> 3.8.0)
|
|
18
|
+
rspec-expectations (~> 3.8.0)
|
|
19
|
+
rspec-mocks (~> 3.8.0)
|
|
20
|
+
rspec-core (3.8.0)
|
|
21
|
+
rspec-support (~> 3.8.0)
|
|
22
|
+
rspec-expectations (3.8.2)
|
|
23
|
+
diff-lcs (>= 1.2.0, < 2.0)
|
|
24
|
+
rspec-support (~> 3.8.0)
|
|
25
|
+
rspec-mocks (3.8.0)
|
|
26
|
+
diff-lcs (>= 1.2.0, < 2.0)
|
|
27
|
+
rspec-support (~> 3.8.0)
|
|
28
|
+
rspec-support (3.8.0)
|
|
29
|
+
sqlite3 (1.3.13)
|
|
30
|
+
|
|
31
|
+
PLATFORMS
|
|
32
|
+
ruby
|
|
33
|
+
|
|
34
|
+
DEPENDENCIES
|
|
35
|
+
bundler (~> 1.17)
|
|
36
|
+
packagecloud-maven-importer!
|
|
37
|
+
rake (~> 10.0)
|
|
38
|
+
rspec (~> 3.0)
|
|
39
|
+
|
|
40
|
+
BUNDLED WITH
|
|
41
|
+
1.17.3
|
data/LICENSE.txt
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
The MIT License (MIT)
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2019 Computology, LLC
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in
|
|
13
|
+
all copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
|
21
|
+
THE SOFTWARE.
|
data/README.md
ADDED
|
@@ -0,0 +1,72 @@
|
|
|
1
|
+
# packagecloud Maven Importer
|
|
2
|
+
|
|
3
|
+
Command line utility to import/mirror artifacts from a local Maven repository to a [packagecloud.io maven repository](https://packagecloud.io/l/maven-repository).
|
|
4
|
+
|
|
5
|
+
NOTE: This tool is currently in __beta__, it is recommended to try it out on a new packagecloud repository first.
|
|
6
|
+
|
|
7
|
+
## Features
|
|
8
|
+
|
|
9
|
+
* Supports JAR, WAR, POM, AAR and APK artifacts (along with their checksums, signatures, sources, and javadocs). However, `-SNAPSHOT` artifacts are __not__ supported.
|
|
10
|
+
|
|
11
|
+
* Only imports newly seen artifacts, can be run from cron to periodically mirror new artifacts.
|
|
12
|
+
|
|
13
|
+
* Import can be resumed if it fails.
|
|
14
|
+
|
|
15
|
+
## Installation
|
|
16
|
+
|
|
17
|
+
This gem requires that the `sqlite3` development libraries be present on your system prior to installation. To install these, try running `brew install sqlite3`, `yum install sqlite-devel` or `apt-get install libsqlite3-dev`.
|
|
18
|
+
|
|
19
|
+
gem install packagecloud-maven-importer
|
|
20
|
+
|
|
21
|
+
## Examples
|
|
22
|
+
|
|
23
|
+
To import a repository located at `~/.m2/repository` into a packagecloud repository `capotej/mvntest`, you would run:
|
|
24
|
+
|
|
25
|
+
packagecloud-maven-importer --username capotej \
|
|
26
|
+
--repository mvntest \
|
|
27
|
+
--api-token 101010101 \
|
|
28
|
+
--maven-repository-path ~/.m2/repository
|
|
29
|
+
|
|
30
|
+
For automation (such as periodic mirroring to a packagecloud repository), make sure to pass `--yes` to skip any confirmations and a path to `--database-path` that will persist between runs.
|
|
31
|
+
|
|
32
|
+
packagecloud-maven-importer --username capotej \
|
|
33
|
+
--repository mvntest \
|
|
34
|
+
--api-token 101010101 \
|
|
35
|
+
--yes \
|
|
36
|
+
--database-path /opt/artifact-database \
|
|
37
|
+
--maven-repository-path ~/.m2/repository
|
|
38
|
+
|
|
39
|
+
To blow away the local artifact database and process/upload everything again, pass `--force-start-over`.
|
|
40
|
+
|
|
41
|
+
## How it works
|
|
42
|
+
|
|
43
|
+
packagecloud Maven Importer builds a database of supported artifacts found at `--maven-repository-path`, then tries to upload them all one by one. On subsequent runs, it uses this database to only upload newly found artifacts (if any).
|
|
44
|
+
|
|
45
|
+
|
|
46
|
+
## Usage
|
|
47
|
+
|
|
48
|
+
Usage: packagecloud-maven-importer [options]
|
|
49
|
+
-m PATH_TO_MAVEN_REPOSITORY, Path to local Maven repository (Example: ~/.m2/repository)
|
|
50
|
+
--maven-repository-path
|
|
51
|
+
-u, --username USERNAME packagecloud username
|
|
52
|
+
-h, --hostname HOSTNAME packagecloud hostname
|
|
53
|
+
-p, --port PORT packagecloud port
|
|
54
|
+
-s, --scheme SCHEME packagecloud scheme (http/https)
|
|
55
|
+
-r, --repository REPOSITORY packagecloud repository
|
|
56
|
+
-a, --api-token API_TOKEN packagecloud API token
|
|
57
|
+
-y, --yes Answer yes to any questions
|
|
58
|
+
-f, --force-start-over Clear local artifact database and start over
|
|
59
|
+
-d PATH_TO_DATABASE, Path to local artifact database (for resuming uploads/incremental sync)
|
|
60
|
+
--database-path
|
|
61
|
+
|
|
62
|
+
## License
|
|
63
|
+
|
|
64
|
+
The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
|
|
65
|
+
|
|
66
|
+
## Code of Conduct
|
|
67
|
+
|
|
68
|
+
Everyone interacting in this project's issue trackers, chat rooms and mailing lists is expected to follow the [code of conduct](https://github.com/[USERNAME]/packagecloud-maven-importer/blob/master/CODE_OF_CONDUCT.md).
|
|
69
|
+
|
|
70
|
+
## Copyright
|
|
71
|
+
|
|
72
|
+
Copyright 2019 Computology, LLC
|
data/Rakefile
ADDED
data/bin/console
ADDED
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
#!/usr/bin/env ruby
|
|
2
|
+
|
|
3
|
+
require "bundler/setup"
|
|
4
|
+
require "packagecloud/maven/importer"
|
|
5
|
+
|
|
6
|
+
# You can add fixtures and/or initialization code here to make experimenting
|
|
7
|
+
# with your gem easier. You can also use a different console, if you like.
|
|
8
|
+
|
|
9
|
+
# (If you use this, don't forget to add pry to your Gemfile!)
|
|
10
|
+
# require "pry"
|
|
11
|
+
# Pry.start
|
|
12
|
+
|
|
13
|
+
require "irb"
|
|
14
|
+
IRB.start(__FILE__)
|
|
@@ -0,0 +1,119 @@
|
|
|
1
|
+
#!/usr/bin/env ruby
|
|
2
|
+
|
|
3
|
+
require "bundler/setup"
|
|
4
|
+
require "packagecloud/maven/importer"
|
|
5
|
+
require 'optparse'
|
|
6
|
+
|
|
7
|
+
options = {}
|
|
8
|
+
OptionParser.new do |opts|
|
|
9
|
+
opts.banner = "Usage: packagecloud-maven-importer [options]"
|
|
10
|
+
|
|
11
|
+
opts.on("-m", "--maven-repository-path PATH_TO_MAVEN_REPOSITORY", "Path to local Maven repository (Example: ~/.m2/repository)") do |m|
|
|
12
|
+
options[:maven_repository_path] = m
|
|
13
|
+
end
|
|
14
|
+
|
|
15
|
+
opts.on("-u","--username USERNAME","packagecloud username") do |u|
|
|
16
|
+
options[:username] = u
|
|
17
|
+
end
|
|
18
|
+
|
|
19
|
+
opts.on("-h","--hostname HOSTNAME","packagecloud hostname") do |h|
|
|
20
|
+
options[:hostname] = h
|
|
21
|
+
end
|
|
22
|
+
|
|
23
|
+
opts.on("-p","--port PORT","packagecloud port") do |p|
|
|
24
|
+
options[:port] = p
|
|
25
|
+
end
|
|
26
|
+
|
|
27
|
+
opts.on("-s","--scheme SCHEME","packagecloud scheme (http/https)") do |s|
|
|
28
|
+
options[:scheme] = s
|
|
29
|
+
end
|
|
30
|
+
|
|
31
|
+
opts.on("-r","--repository REPOSITORY","packagecloud repository") do |r|
|
|
32
|
+
options[:repository] = r
|
|
33
|
+
end
|
|
34
|
+
|
|
35
|
+
opts.on("-a","--api-token API_TOKEN","packagecloud API token") do |a|
|
|
36
|
+
options[:api_token] = a
|
|
37
|
+
end
|
|
38
|
+
|
|
39
|
+
opts.on("-y","--yes","Answer yes to any questions") do |y|
|
|
40
|
+
options[:yes] = y
|
|
41
|
+
end
|
|
42
|
+
|
|
43
|
+
opts.on("-f","--force-start-over", "Clear local artifact database and start over") do |f|
|
|
44
|
+
options[:force] = f
|
|
45
|
+
end
|
|
46
|
+
|
|
47
|
+
opts.on("-d","--database-path PATH_TO_DATABASE", "Path to local artifact database (for resuming/incremental importing)") do |d|
|
|
48
|
+
options[:database] = d
|
|
49
|
+
end
|
|
50
|
+
|
|
51
|
+
end.parse!
|
|
52
|
+
|
|
53
|
+
##
|
|
54
|
+
## Default arguments handling
|
|
55
|
+
##
|
|
56
|
+
if options[:port].nil?
|
|
57
|
+
options[:port] = "443"
|
|
58
|
+
end
|
|
59
|
+
|
|
60
|
+
if options[:hostname].nil?
|
|
61
|
+
options[:hostname] = "packagecloud.io"
|
|
62
|
+
end
|
|
63
|
+
|
|
64
|
+
if options[:scheme].nil?
|
|
65
|
+
options[:scheme] = "https"
|
|
66
|
+
end
|
|
67
|
+
|
|
68
|
+
if options[:database].nil?
|
|
69
|
+
options[:database] = "packagecloud-artifact-database.db"
|
|
70
|
+
end
|
|
71
|
+
|
|
72
|
+
if options[:yes].nil?
|
|
73
|
+
options[:yes] = false
|
|
74
|
+
else
|
|
75
|
+
options[:yes] = true
|
|
76
|
+
end
|
|
77
|
+
|
|
78
|
+
if options[:force].nil?
|
|
79
|
+
options[:force] = false
|
|
80
|
+
else
|
|
81
|
+
options[:force] = true
|
|
82
|
+
end
|
|
83
|
+
|
|
84
|
+
##
|
|
85
|
+
## Required argument handling
|
|
86
|
+
##
|
|
87
|
+
if options[:username].nil?
|
|
88
|
+
puts "username not found! Please pass packagecloud username with --username"
|
|
89
|
+
exit 1
|
|
90
|
+
end
|
|
91
|
+
|
|
92
|
+
if options[:repository].nil?
|
|
93
|
+
puts "repository not found! Please pass packagecloud repository with --repository"
|
|
94
|
+
exit 1
|
|
95
|
+
end
|
|
96
|
+
|
|
97
|
+
if options[:api_token].nil?
|
|
98
|
+
puts "API token not found! Please pass packagecloud API token with --api-token"
|
|
99
|
+
exit 1
|
|
100
|
+
end
|
|
101
|
+
|
|
102
|
+
if options[:maven_repository_path].nil?
|
|
103
|
+
puts "Maven path not supplied! Please pass path to Maven repository with --maven-repository-path"
|
|
104
|
+
exit 1
|
|
105
|
+
end
|
|
106
|
+
|
|
107
|
+
|
|
108
|
+
# Note: By here all options[] should have a default or blow up if required argument is missing!
|
|
109
|
+
|
|
110
|
+
importer = Packagecloud::Maven::Importer::Main.new(username: options[:username],
|
|
111
|
+
api_token: options[:api_token],
|
|
112
|
+
hostname: options[:hostname],
|
|
113
|
+
port: options[:port],
|
|
114
|
+
scheme: options[:scheme],
|
|
115
|
+
repository: options[:repository],
|
|
116
|
+
database_path: options[:database],
|
|
117
|
+
maven_repository_path: options[:maven_repository_path])
|
|
118
|
+
|
|
119
|
+
importer.run!(yes: options[:yes], force: options[:force])
|
data/bin/setup
ADDED
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
require "packagecloud/maven/importer/version"
|
|
2
|
+
require "packagecloud/maven/importer/main"
|
|
3
|
+
require "packagecloud/maven/importer/database"
|
|
4
|
+
require "packagecloud/maven/importer/patterns"
|
|
5
|
+
|
|
6
|
+
module Packagecloud
|
|
7
|
+
module Maven
|
|
8
|
+
module Importer
|
|
9
|
+
class Error < StandardError; end
|
|
10
|
+
end
|
|
11
|
+
end
|
|
12
|
+
end
|
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
require 'sqlite3'
|
|
2
|
+
|
|
3
|
+
module Packagecloud
|
|
4
|
+
module Maven
|
|
5
|
+
module Importer
|
|
6
|
+
class Database
|
|
7
|
+
attr_accessor :database
|
|
8
|
+
|
|
9
|
+
CREATE_SCHEMA = <<-SQL
|
|
10
|
+
CREATE TABLE IF NOT EXISTS artifacts (full_path TEXT PRIMARY KEY, base_path TEXT, state TEXT);
|
|
11
|
+
SQL
|
|
12
|
+
|
|
13
|
+
def initialize(path:)
|
|
14
|
+
self.database = SQLite3::Database.new(path)
|
|
15
|
+
self.database.execute(CREATE_SCHEMA)
|
|
16
|
+
end
|
|
17
|
+
|
|
18
|
+
def clear!
|
|
19
|
+
self.database.execute <<-SQL
|
|
20
|
+
DELETE FROM artifacts;
|
|
21
|
+
SQL
|
|
22
|
+
end
|
|
23
|
+
|
|
24
|
+
def push(full_path, base_path)
|
|
25
|
+
self.database.execute <<-SQL
|
|
26
|
+
INSERT OR IGNORE INTO artifacts VALUES('#{full_path}', '#{base_path}', 'queued');
|
|
27
|
+
SQL
|
|
28
|
+
end
|
|
29
|
+
|
|
30
|
+
def finish!(full_path)
|
|
31
|
+
self.database.execute <<-SQL
|
|
32
|
+
UPDATE artifacts SET state='uploaded' WHERE (full_path='#{full_path}');
|
|
33
|
+
SQL
|
|
34
|
+
end
|
|
35
|
+
|
|
36
|
+
def reset!
|
|
37
|
+
self.database.execute("DROP TABLE artifacts;")
|
|
38
|
+
self.database.execute(CREATE_SCHEMA)
|
|
39
|
+
end
|
|
40
|
+
|
|
41
|
+
def queued_count
|
|
42
|
+
self.database.get_first_value "SELECT COUNT(*) FROM artifacts where state='queued';"
|
|
43
|
+
end
|
|
44
|
+
|
|
45
|
+
def total_count
|
|
46
|
+
self.database.get_first_value "SELECT COUNT(*) FROM artifacts;"
|
|
47
|
+
end
|
|
48
|
+
|
|
49
|
+
def peek
|
|
50
|
+
full_path, base_path = self.database.get_first_row("SELECT * from artifacts where state='queued';")
|
|
51
|
+
if full_path
|
|
52
|
+
[full_path, base_path]
|
|
53
|
+
else
|
|
54
|
+
nil
|
|
55
|
+
end
|
|
56
|
+
end
|
|
57
|
+
|
|
58
|
+
end
|
|
59
|
+
end
|
|
60
|
+
end
|
|
61
|
+
end
|
|
@@ -0,0 +1,136 @@
|
|
|
1
|
+
require 'mustermann'
|
|
2
|
+
require 'json'
|
|
3
|
+
require 'excon'
|
|
4
|
+
|
|
5
|
+
module Packagecloud
|
|
6
|
+
module Maven
|
|
7
|
+
module Importer
|
|
8
|
+
class Main
|
|
9
|
+
attr_accessor :database, :hostname, :port, :scheme, :username, :repository, :api_token, :maven_repository_path
|
|
10
|
+
|
|
11
|
+
def initialize(username:,
|
|
12
|
+
repository:,
|
|
13
|
+
api_token:,
|
|
14
|
+
scheme:,
|
|
15
|
+
port:,
|
|
16
|
+
hostname:,
|
|
17
|
+
database_path:,
|
|
18
|
+
maven_repository_path:)
|
|
19
|
+
|
|
20
|
+
self.username = username
|
|
21
|
+
self.scheme = scheme
|
|
22
|
+
self.port = port
|
|
23
|
+
self.hostname = hostname
|
|
24
|
+
self.repository = repository
|
|
25
|
+
self.api_token = api_token
|
|
26
|
+
self.maven_repository_path = maven_repository_path
|
|
27
|
+
self.database = Packagecloud::Maven::Importer::Database.new(path: database_path)
|
|
28
|
+
end
|
|
29
|
+
|
|
30
|
+
def parse_artifact(full_path)
|
|
31
|
+
base_path = full_path.gsub(maven_repository_path, '')
|
|
32
|
+
|
|
33
|
+
sanitized_base_path = ::File.join('/', base_path.gsub(/\\+/, '/'))
|
|
34
|
+
result = nil
|
|
35
|
+
Packagecloud::Maven::Importer::PATTERNS.each do |pattern, artifact_type|
|
|
36
|
+
result = pattern.params(sanitized_base_path)
|
|
37
|
+
if result
|
|
38
|
+
return { full_path: full_path, base_path: sanitized_base_path }
|
|
39
|
+
end
|
|
40
|
+
end
|
|
41
|
+
nil
|
|
42
|
+
end
|
|
43
|
+
|
|
44
|
+
def connection
|
|
45
|
+
@connection ||= Excon.new("#{scheme}://#{api_token}:@#{hostname}:#{port}", :persistent => true)
|
|
46
|
+
end
|
|
47
|
+
|
|
48
|
+
def run!(yes:false, force:false)
|
|
49
|
+
puts "Starting packagecloud-maven-importer v#{Packagecloud::Maven::Importer::VERSION}"
|
|
50
|
+
|
|
51
|
+
if force == true
|
|
52
|
+
if yes == false
|
|
53
|
+
print "Delete local artifact database and start over? [y/N]:"
|
|
54
|
+
answer = gets
|
|
55
|
+
if answer.chomp != "y"
|
|
56
|
+
puts 'Aborting!'
|
|
57
|
+
exit 1
|
|
58
|
+
end
|
|
59
|
+
end
|
|
60
|
+
database.reset!
|
|
61
|
+
end
|
|
62
|
+
|
|
63
|
+
unknown_files = []
|
|
64
|
+
files_scanned = 0
|
|
65
|
+
artifacts_scanned = 0
|
|
66
|
+
initial_database_count = database.queued_count
|
|
67
|
+
|
|
68
|
+
if !File.exists?(maven_repository_path)
|
|
69
|
+
$stderr.puts "#{maven_repository_path} does not exist, aborting!"
|
|
70
|
+
exit 1
|
|
71
|
+
end
|
|
72
|
+
|
|
73
|
+
puts "Building database of uploadable artifacts in #{maven_repository_path}..."
|
|
74
|
+
Dir[File.join(maven_repository_path, "/**/*")].each do |possible_artifact|
|
|
75
|
+
next if possible_artifact.end_with?('lastUpdated')
|
|
76
|
+
next if possible_artifact.end_with?('repositories')
|
|
77
|
+
next if possible_artifact.include?('-SNAPSHOT')
|
|
78
|
+
|
|
79
|
+
if File.file?(possible_artifact)
|
|
80
|
+
result = parse_artifact(possible_artifact)
|
|
81
|
+
if result
|
|
82
|
+
database.push(result[:full_path], result[:base_path])
|
|
83
|
+
artifacts_scanned += 1
|
|
84
|
+
else
|
|
85
|
+
unknown_files << possible_artifact
|
|
86
|
+
end
|
|
87
|
+
files_scanned += 1
|
|
88
|
+
end
|
|
89
|
+
end
|
|
90
|
+
|
|
91
|
+
if initial_database_count == 0
|
|
92
|
+
puts "Found #{artifacts_scanned} total uploadable artifacts out of #{files_scanned} scanned files in #{maven_repository_path}"
|
|
93
|
+
else
|
|
94
|
+
new_artifacts_scanned = initial_database_count - database.queued_count
|
|
95
|
+
puts "Found #{artifacts_scanned} total uploadable artifacts (#{new_artifacts_scanned} previously unseen) out of #{files_scanned} scanned files in #{maven_repository_path}"
|
|
96
|
+
end
|
|
97
|
+
|
|
98
|
+
if database.queued_count == 0
|
|
99
|
+
puts "Nothing left to upload"
|
|
100
|
+
else
|
|
101
|
+
puts "#{database.queued_count} artifacts left to upload..."
|
|
102
|
+
if yes == false
|
|
103
|
+
print "Continue? [y/N]:"
|
|
104
|
+
answer = gets
|
|
105
|
+
if answer.chomp != "y"
|
|
106
|
+
puts 'Aborting!'
|
|
107
|
+
exit 1
|
|
108
|
+
end
|
|
109
|
+
end
|
|
110
|
+
end
|
|
111
|
+
|
|
112
|
+
while path_pair = database.peek do
|
|
113
|
+
full_path, base_path = path_pair
|
|
114
|
+
print "Uploading #{base_path}..."
|
|
115
|
+
|
|
116
|
+
# This will safely ignore any 422's for already existing artifacts and retry on errors (5xx)
|
|
117
|
+
connection.put(path: "/api/v1/repos/#{username}/#{repository}/artifacts.json",
|
|
118
|
+
body: File.read(full_path),
|
|
119
|
+
expects: [201, 422],
|
|
120
|
+
idempotent: true,
|
|
121
|
+
retry_limit: 5,
|
|
122
|
+
retry_interval: 5,
|
|
123
|
+
headers: {'User-Agent' => "packagecloud-maven-importer v#{Packagecloud::Maven::Importer::VERSION} (#{RUBY_PLATFORM})"},
|
|
124
|
+
query: { key: base_path })
|
|
125
|
+
|
|
126
|
+
puts "Done"
|
|
127
|
+
database.finish!(full_path)
|
|
128
|
+
end
|
|
129
|
+
puts "Finished"
|
|
130
|
+
|
|
131
|
+
exit 0
|
|
132
|
+
end
|
|
133
|
+
end
|
|
134
|
+
end
|
|
135
|
+
end
|
|
136
|
+
end
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
module Packagecloud
|
|
2
|
+
module Maven
|
|
3
|
+
module Importer
|
|
4
|
+
PATTERNS = {
|
|
5
|
+
Mustermann.new('/*/:artifact_id/:version/:name_version.aar') => 'aar',
|
|
6
|
+
Mustermann.new('/*/:artifact_id/:version/:name_version.aar.md5') => 'aar_md5',
|
|
7
|
+
Mustermann.new('/*/:artifact_id/:version/:name_version.aar.sha1') => 'aar_sha1',
|
|
8
|
+
Mustermann.new('/*/:artifact_id/:version/:name_version.aar.asc') => 'aar_asc',
|
|
9
|
+
|
|
10
|
+
Mustermann.new('/*/:artifact_id/:version/:name_version.apk') => 'apk',
|
|
11
|
+
Mustermann.new('/*/:artifact_id/:version/:name_version.apk.md5') => 'apk_md5',
|
|
12
|
+
Mustermann.new('/*/:artifact_id/:version/:name_version.apk.sha1') => 'apk_sha1',
|
|
13
|
+
Mustermann.new('/*/:artifact_id/:version/:name_version.apk.asc') => 'apk_asc',
|
|
14
|
+
|
|
15
|
+
Mustermann.new('/*/:artifact_id/:version/:name_version.war') => 'war',
|
|
16
|
+
Mustermann.new('/*/:artifact_id/:version/:name_version.war.md5') => 'war_md5',
|
|
17
|
+
Mustermann.new('/*/:artifact_id/:version/:name_version.war.sha1') => 'war_sha1',
|
|
18
|
+
Mustermann.new('/*/:artifact_id/:version/:name_version.war.asc') => 'war_asc',
|
|
19
|
+
|
|
20
|
+
Mustermann.new('/*/:artifact_id/:version/:name_version.jar') => 'jar',
|
|
21
|
+
Mustermann.new('/*/:artifact_id/:version/:name_version.jar.md5') => 'jar_md5',
|
|
22
|
+
Mustermann.new('/*/:artifact_id/:version/:name_version.jar.sha1') => 'jar_sha1',
|
|
23
|
+
Mustermann.new('/*/:artifact_id/:version/:name_version.jar.asc') => 'jar_asc',
|
|
24
|
+
|
|
25
|
+
Mustermann.new('/*/:artifact_id/:version/:name_version.pom') => 'pom',
|
|
26
|
+
Mustermann.new('/*/:artifact_id/:version/:name_version.pom.md5') => 'pom_md5',
|
|
27
|
+
Mustermann.new('/*/:artifact_id/:version/:name_version.pom.sha1') => 'pom_sha1',
|
|
28
|
+
Mustermann.new('/*/:artifact_id/:version/:name_version.pom.asc') => 'pom_asc',
|
|
29
|
+
}
|
|
30
|
+
end
|
|
31
|
+
end
|
|
32
|
+
end
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
|
|
2
|
+
lib = File.expand_path("../lib", __FILE__)
|
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
|
4
|
+
require "packagecloud/maven/importer/version"
|
|
5
|
+
|
|
6
|
+
Gem::Specification.new do |spec|
|
|
7
|
+
spec.name = "packagecloud-maven-importer"
|
|
8
|
+
spec.version = Packagecloud::Maven::Importer::VERSION
|
|
9
|
+
spec.authors = ["Julio Capote"]
|
|
10
|
+
spec.email = ["julio@packagecloud.io"]
|
|
11
|
+
|
|
12
|
+
spec.summary = %q{Imports/Mirrors a local Maven repository to packagecloud.io}
|
|
13
|
+
spec.homepage = "https://github.com/computology/packagecloud-maven-importer"
|
|
14
|
+
spec.license = "MIT"
|
|
15
|
+
|
|
16
|
+
# Specify which files should be added to the gem when it is released.
|
|
17
|
+
# The `git ls-files -z` loads the files in the RubyGem that have been added into git.
|
|
18
|
+
spec.files = Dir.chdir(File.expand_path('..', __FILE__)) do
|
|
19
|
+
`git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
|
|
20
|
+
end
|
|
21
|
+
spec.bindir = "exe"
|
|
22
|
+
spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
|
|
23
|
+
spec.require_paths = ["lib"]
|
|
24
|
+
|
|
25
|
+
spec.add_runtime_dependency "mustermann", "1.0.3"
|
|
26
|
+
spec.add_runtime_dependency "sqlite3", "1.3.13"
|
|
27
|
+
spec.add_runtime_dependency "excon", "0.62.0"
|
|
28
|
+
|
|
29
|
+
spec.add_development_dependency "bundler", "~> 1.17"
|
|
30
|
+
spec.add_development_dependency "rake", "~> 10.0"
|
|
31
|
+
spec.add_development_dependency "rspec", "~> 3.0"
|
|
32
|
+
end
|
metadata
ADDED
|
@@ -0,0 +1,146 @@
|
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
|
2
|
+
name: packagecloud-maven-importer
|
|
3
|
+
version: !ruby/object:Gem::Version
|
|
4
|
+
version: 0.1.0
|
|
5
|
+
platform: ruby
|
|
6
|
+
authors:
|
|
7
|
+
- Julio Capote
|
|
8
|
+
autorequire:
|
|
9
|
+
bindir: exe
|
|
10
|
+
cert_chain: []
|
|
11
|
+
date: 2019-02-04 00:00:00.000000000 Z
|
|
12
|
+
dependencies:
|
|
13
|
+
- !ruby/object:Gem::Dependency
|
|
14
|
+
name: mustermann
|
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
|
16
|
+
requirements:
|
|
17
|
+
- - '='
|
|
18
|
+
- !ruby/object:Gem::Version
|
|
19
|
+
version: 1.0.3
|
|
20
|
+
type: :runtime
|
|
21
|
+
prerelease: false
|
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
|
23
|
+
requirements:
|
|
24
|
+
- - '='
|
|
25
|
+
- !ruby/object:Gem::Version
|
|
26
|
+
version: 1.0.3
|
|
27
|
+
- !ruby/object:Gem::Dependency
|
|
28
|
+
name: sqlite3
|
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
|
30
|
+
requirements:
|
|
31
|
+
- - '='
|
|
32
|
+
- !ruby/object:Gem::Version
|
|
33
|
+
version: 1.3.13
|
|
34
|
+
type: :runtime
|
|
35
|
+
prerelease: false
|
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
|
37
|
+
requirements:
|
|
38
|
+
- - '='
|
|
39
|
+
- !ruby/object:Gem::Version
|
|
40
|
+
version: 1.3.13
|
|
41
|
+
- !ruby/object:Gem::Dependency
|
|
42
|
+
name: excon
|
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
|
44
|
+
requirements:
|
|
45
|
+
- - '='
|
|
46
|
+
- !ruby/object:Gem::Version
|
|
47
|
+
version: 0.62.0
|
|
48
|
+
type: :runtime
|
|
49
|
+
prerelease: false
|
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
|
51
|
+
requirements:
|
|
52
|
+
- - '='
|
|
53
|
+
- !ruby/object:Gem::Version
|
|
54
|
+
version: 0.62.0
|
|
55
|
+
- !ruby/object:Gem::Dependency
|
|
56
|
+
name: bundler
|
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
|
58
|
+
requirements:
|
|
59
|
+
- - "~>"
|
|
60
|
+
- !ruby/object:Gem::Version
|
|
61
|
+
version: '1.17'
|
|
62
|
+
type: :development
|
|
63
|
+
prerelease: false
|
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
|
65
|
+
requirements:
|
|
66
|
+
- - "~>"
|
|
67
|
+
- !ruby/object:Gem::Version
|
|
68
|
+
version: '1.17'
|
|
69
|
+
- !ruby/object:Gem::Dependency
|
|
70
|
+
name: rake
|
|
71
|
+
requirement: !ruby/object:Gem::Requirement
|
|
72
|
+
requirements:
|
|
73
|
+
- - "~>"
|
|
74
|
+
- !ruby/object:Gem::Version
|
|
75
|
+
version: '10.0'
|
|
76
|
+
type: :development
|
|
77
|
+
prerelease: false
|
|
78
|
+
version_requirements: !ruby/object:Gem::Requirement
|
|
79
|
+
requirements:
|
|
80
|
+
- - "~>"
|
|
81
|
+
- !ruby/object:Gem::Version
|
|
82
|
+
version: '10.0'
|
|
83
|
+
- !ruby/object:Gem::Dependency
|
|
84
|
+
name: rspec
|
|
85
|
+
requirement: !ruby/object:Gem::Requirement
|
|
86
|
+
requirements:
|
|
87
|
+
- - "~>"
|
|
88
|
+
- !ruby/object:Gem::Version
|
|
89
|
+
version: '3.0'
|
|
90
|
+
type: :development
|
|
91
|
+
prerelease: false
|
|
92
|
+
version_requirements: !ruby/object:Gem::Requirement
|
|
93
|
+
requirements:
|
|
94
|
+
- - "~>"
|
|
95
|
+
- !ruby/object:Gem::Version
|
|
96
|
+
version: '3.0'
|
|
97
|
+
description:
|
|
98
|
+
email:
|
|
99
|
+
- julio@packagecloud.io
|
|
100
|
+
executables: []
|
|
101
|
+
extensions: []
|
|
102
|
+
extra_rdoc_files: []
|
|
103
|
+
files:
|
|
104
|
+
- ".gitignore"
|
|
105
|
+
- ".rspec"
|
|
106
|
+
- ".travis.yml"
|
|
107
|
+
- CODE_OF_CONDUCT.md
|
|
108
|
+
- Gemfile
|
|
109
|
+
- Gemfile.lock
|
|
110
|
+
- LICENSE.txt
|
|
111
|
+
- README.md
|
|
112
|
+
- Rakefile
|
|
113
|
+
- bin/console
|
|
114
|
+
- bin/packagecloud-maven-importer
|
|
115
|
+
- bin/setup
|
|
116
|
+
- lib/packagecloud/maven/importer.rb
|
|
117
|
+
- lib/packagecloud/maven/importer/database.rb
|
|
118
|
+
- lib/packagecloud/maven/importer/main.rb
|
|
119
|
+
- lib/packagecloud/maven/importer/patterns.rb
|
|
120
|
+
- lib/packagecloud/maven/importer/version.rb
|
|
121
|
+
- packagecloud-maven-importer.gemspec
|
|
122
|
+
homepage: https://github.com/computology/packagecloud-maven-importer
|
|
123
|
+
licenses:
|
|
124
|
+
- MIT
|
|
125
|
+
metadata: {}
|
|
126
|
+
post_install_message:
|
|
127
|
+
rdoc_options: []
|
|
128
|
+
require_paths:
|
|
129
|
+
- lib
|
|
130
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
|
131
|
+
requirements:
|
|
132
|
+
- - ">="
|
|
133
|
+
- !ruby/object:Gem::Version
|
|
134
|
+
version: '0'
|
|
135
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
|
136
|
+
requirements:
|
|
137
|
+
- - ">="
|
|
138
|
+
- !ruby/object:Gem::Version
|
|
139
|
+
version: '0'
|
|
140
|
+
requirements: []
|
|
141
|
+
rubyforge_project:
|
|
142
|
+
rubygems_version: 2.6.14.1
|
|
143
|
+
signing_key:
|
|
144
|
+
specification_version: 4
|
|
145
|
+
summary: Imports/Mirrors a local Maven repository to packagecloud.io
|
|
146
|
+
test_files: []
|