etom 0.0.10

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.
data/.gitignore ADDED
@@ -0,0 +1,5 @@
1
+ *.gem
2
+ .bundle
3
+ Gemfile.lock
4
+ pkg/*
5
+ .idea/
data/.rspec ADDED
@@ -0,0 +1,2 @@
1
+ --format nested
2
+ --color
data/Gemfile ADDED
@@ -0,0 +1,6 @@
1
+ source "http://rubygems.org"
2
+
3
+ # Specify your gem's dependencies in etom.gemspec
4
+ gemspec
5
+
6
+ gem "rspec"
data/README.md ADDED
@@ -0,0 +1,26 @@
1
+ # Etom
2
+ Etom stands for Eclipe to maven. It is a simple command line tool to convert all eclipse plugins within the eclipse/plugin folder to maven artifacts within a local repository.
3
+
4
+ ## Usage
5
+
6
+ Install it using the normal gem installation mechanism.
7
+
8
+ gem install etom
9
+
10
+ Execute this command in the /path/to/eclipse/plugins/ directory you want to convert.
11
+
12
+ etom convert /path/to/local/mvn/repo
13
+
14
+ However, you can also specify the eclipse plugins directory using the --source flag.
15
+
16
+ etom convert /path/to/local/mvn/repo --source /path/to/eclipse/plugins/
17
+
18
+ Use the flag --short for using short versions (1.0.0) instead of the long versions with timestamps (1.0.0-v20113223232). Example:
19
+
20
+ etom convert /path/to/local/mvn/repo --short
21
+
22
+ ## Alternatives
23
+
24
+ There exists several projects that also target this problem.
25
+
26
+ * [[http://maven.apache.org/plugins/maven-eclipse-plugin/]] is a little too slow and does not detect the relation between binary and source packages.
data/Rakefile ADDED
@@ -0,0 +1 @@
1
+ require "bundler/gem_tasks"
data/bin/etom ADDED
@@ -0,0 +1,4 @@
1
+ #!/usr/bin/env ruby
2
+ require 'etom/cli'
3
+
4
+ Etom::CLI.start
data/etom.gemspec ADDED
@@ -0,0 +1,26 @@
1
+ # -*- encoding: utf-8 -*-
2
+ $:.push File.expand_path("../lib", __FILE__)
3
+ require "etom/version"
4
+
5
+ Gem::Specification.new do |s|
6
+ s.name = "etom"
7
+ s.version = Etom::VERSION
8
+ s.authors = ["Simon Harrer"]
9
+ s.email = ["simon.harrer@gmail.com"]
10
+ s.homepage = "https://github.com/simonharrer/etom"
11
+ s.summary = %q{Converts eclipse plugins to maven artifacts}
12
+ s.description = %q{Uses fast operations without relying onto maven to convert eclipse plugins to maven artifacts witin a local maven repository. }
13
+
14
+ s.rubyforge_project = "etom"
15
+
16
+ s.files = `git ls-files`.split("\n")
17
+ s.test_files = `git ls-files -- {spec,spec,features}/*`.split("\n")
18
+ s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
19
+ s.require_paths = ["lib"]
20
+
21
+ # specify any dependencies here; for example:
22
+ s.add_dependency "thor"
23
+ s.add_dependency "rubyzip"
24
+
25
+ s.add_development_dependency "rspec"
26
+ end
data/lib/etom/cli.rb ADDED
@@ -0,0 +1,35 @@
1
+ require 'thor'
2
+
3
+ require "etom/reference"
4
+ require "etom/version"
5
+
6
+ module Etom
7
+
8
+ class CLI < Thor
9
+ include Thor::Actions
10
+
11
+ desc "convert REPO_PATH","convert eclipse plugins to maven artifacts"
12
+ method_options :short => :boolean, :default => false
13
+ method_options :source => :string, :default => "#{File.dirname(".")}"
14
+ def convert(target)
15
+ source = options[:source]
16
+
17
+ jar_files_pattern = File.join("#{source}", "*.jar")
18
+ jar_files = Dir.glob(jar_files_pattern)
19
+ say "Converting #{jar_files.size} jar files within #{source} to #{target} as maven artifacts"
20
+
21
+ jar_files.each do |file|
22
+ say "Converting #{file}"
23
+ Reference.new(file).to_artifact(target,options.short?)
24
+ end
25
+
26
+ end
27
+
28
+ desc "version", "displays the current version of etom"
29
+ def version
30
+ say "Current version is #{Etom::VERSION}"
31
+ end
32
+
33
+ end
34
+
35
+ end
@@ -0,0 +1,42 @@
1
+ require 'digest/md5'
2
+ require 'digest/sha1'
3
+
4
+ module Etom
5
+
6
+ module Hash
7
+
8
+ def self.sha1(file)
9
+ Digest::SHA1.hexdigest(File.read(file))
10
+ end
11
+
12
+ def self.md5(file)
13
+ digest = Digest::SHA1.new
14
+ File.open(file, "r") do |f|
15
+ digest.update f.read(8192) until f.eof
16
+ end
17
+ digest.hexdigest
18
+
19
+ Digest::MD5.hexdigest(File.read(file))
20
+ end
21
+
22
+ def self.create_hashes_for_files(dir)
23
+ Dir.glob(File.join("dir","*.{jar,xml}")).each do |file|
24
+ create_hashes_for_file(file)
25
+ end
26
+ end
27
+
28
+ def self.create_hashes_for_file(file)
29
+ File.open("#{file}.sha1","w") do |f|
30
+ f << sha1(file)
31
+ end
32
+
33
+ File.open("#{file}.md5","w") do |f|
34
+ f << md5(file)
35
+ end
36
+ end
37
+
38
+ end
39
+
40
+
41
+ end
42
+
@@ -0,0 +1,37 @@
1
+ module PropertyReader
2
+
3
+ def self.load_from_string(properties_string)
4
+ properties = {}
5
+ properties_string.each_line do |line|
6
+ line.strip!
7
+ if (line[0] != ?# and line[0] != ?=)
8
+ i = line.index('=')
9
+ if (i)
10
+ properties[line[0..i - 1].strip] = line[i + 1..-1].strip
11
+ else
12
+ properties[line] = ''
13
+ end
14
+ end
15
+ end
16
+ properties
17
+ end
18
+
19
+ def self.load_from_file(properties_filename)
20
+ properties = {}
21
+ File.open(properties_filename, 'r') do |properties_file|
22
+ properties_file.read.each_line do |line|
23
+ line.strip!
24
+ if (line[0] != ?# and line[0] != ?=)
25
+ i = line.index('=')
26
+ if (i)
27
+ properties[line[0..i - 1].strip] = line[i + 1..-1].strip
28
+ else
29
+ properties[line] = ''
30
+ end
31
+ end
32
+ end
33
+ end
34
+ properties
35
+ end
36
+
37
+ end
@@ -0,0 +1,131 @@
1
+ require "zip/zip"
2
+ require "etom/property_reader"
3
+
4
+ module Etom
5
+
6
+ class Reference
7
+ attr_accessor :file
8
+
9
+ def initialize(url)
10
+ self.file = url
11
+ end
12
+
13
+ def valid?
14
+ File.exists?(file)
15
+ end
16
+
17
+ def file_name
18
+ File.basename(file)
19
+ end
20
+
21
+ def plugin_name
22
+ Zip::ZipFile.open(file, Zip::ZipFile::CREATE) do |zipfile|
23
+ begin
24
+ PropertyReader::load_from_string(zipfile.read("plugin.properties"))["bundleName"]
25
+ rescue
26
+ file_name
27
+ end
28
+ end
29
+ end
30
+
31
+ def full_name
32
+ file_name[0..-5]
33
+ end
34
+
35
+ def name
36
+ name = full_name.split("_")[0]
37
+ if(name.end_with?(".source"))
38
+ name[0..-8]
39
+ else
40
+ name
41
+ end
42
+ end
43
+
44
+ def version
45
+ version = full_name.split("_")[1]
46
+ short = version.split(".")[0..2].join(".")
47
+ timestamp = version.split(".").last
48
+ "#{short}-#{timestamp}"
49
+ end
50
+
51
+ def version_timestamp
52
+ version.split("-").last
53
+ end
54
+
55
+ def version_short
56
+ version.split("-").first
57
+ end
58
+
59
+ def group_id
60
+ ids = name.split(".")
61
+ ids.pop
62
+ ids.join(".")
63
+ end
64
+
65
+ def artifact_id
66
+ name.split("_")[0].split(".").last
67
+ end
68
+
69
+ def source?()
70
+ full_name.split("_")[0].end_with?(".source")
71
+ end
72
+
73
+ def binary?()
74
+ !source?
75
+ end
76
+
77
+ def to_pom
78
+ <<-eos
79
+ <?xml version="1.0" encoding="UTF-8"?>
80
+ <project xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd" xmlns="http://maven.apache.org/POM/4.0.0"
81
+ xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
82
+ <modelVersion>4.0.0</modelVersion>
83
+ <groupId>#{group_id}</groupId>
84
+ <artifactId>#{artifact_id}</artifactId>
85
+ <version>#{version}</version>
86
+ <name>#{plugin_name}</name>
87
+ </project>
88
+ eos
89
+ end
90
+
91
+ def md5()
92
+ Etom::Hasher::md5(file)
93
+ end
94
+
95
+ def sha1()
96
+ Etom::Hasher::sha1(file)
97
+ end
98
+
99
+ def to_artifact(local_repo, short = false)
100
+ require "ftools"
101
+
102
+ # select version
103
+ selected_version = version
104
+ if(short)
105
+ selected_version = version_short
106
+ end
107
+
108
+ # create path
109
+ maven_path = File.join("#{local_repo}",group_id.split("."),artifact_id,selected_version)
110
+ File.makedirs(maven_path)
111
+
112
+ # copy jar
113
+ if(source?)
114
+ maven_artifact_path = "#{maven_path}/#{artifact_id}-#{selected_version}-sources.jar"
115
+ else
116
+ maven_artifact_path = "#{maven_path}/#{artifact_id}-#{selected_version}.jar"
117
+ end
118
+ File.cp(file,maven_artifact_path)
119
+
120
+ # create pom
121
+ if(binary?)
122
+ maven_pom_path = "#{maven_path}/#{artifact_id}-#{selected_version}.pom"
123
+ File.open(maven_pom_path, "w") do |pom|
124
+ pom << to_pom
125
+ end
126
+ end
127
+
128
+ end
129
+
130
+ end
131
+ end
@@ -0,0 +1,3 @@
1
+ module Etom
2
+ VERSION = "0.0.10"
3
+ end
data/lib/etom.rb ADDED
@@ -0,0 +1,7 @@
1
+ require "etom/version"
2
+
3
+ module Etom
4
+
5
+
6
+
7
+ end
@@ -0,0 +1,12 @@
1
+ ###############################################################################
2
+ # Copyright (c) 2010 itemis AG (http://www.itemis.eu) and others.
3
+ # All rights reserved. This program and the accompanying materials
4
+ # are made available under the terms of the Eclipse Public License v1.0
5
+ # which accompanies this distribution, and is available at
6
+ # http://www.eclipse.org/legal/epl-v10.html
7
+ #
8
+ # Contributors:
9
+ # Sebastian Zarnekow - initial API and implementation
10
+ ###############################################################################
11
+ bundleName = Google Collections
12
+ bundleProvider = Eclipse Orbit
data/spec/etom_spec.rb ADDED
@@ -0,0 +1,89 @@
1
+ require "etom/reference"
2
+
3
+ describe Etom::Reference do
4
+
5
+ FILE_REF = "#{File.dirname(__FILE__)}/data/com.google.collect_1.0.0.v201105210816.jar"
6
+ SOURCE_FILE_REF = "#{File.dirname(__FILE__)}/data/com.google.collect.source_1.0.0.v201105210816.jar"
7
+
8
+ it "should detect files correctly" do
9
+ ref = Etom::Reference.new(FILE_REF)
10
+
11
+ ref.valid?.should eq(true)
12
+
13
+ ref.version.should eq("1.0.0-v201105210816")
14
+ ref.version_short.should eq("1.0.0")
15
+ ref.version_timestamp.should eq("v201105210816")
16
+
17
+ ref.group_id.should eq("com.google")
18
+ ref.artifact_id.should eq("collect")
19
+
20
+ ref.plugin_name.should eq("Google Collections")
21
+
22
+ ref.binary?.should eq(true)
23
+ ref.source?.should eq(false)
24
+ end
25
+
26
+ it "should detect source files correctly" do
27
+ ref = Etom::Reference.new(SOURCE_FILE_REF)
28
+
29
+ ref.valid?.should eq(true)
30
+
31
+ ref.version.should eq("1.0.0-v201105210816")
32
+ ref.version_short.should eq("1.0.0")
33
+ ref.version_timestamp.should eq("v201105210816")
34
+
35
+ ref.group_id.should eq("com.google")
36
+ ref.artifact_id.should eq("collect")
37
+
38
+ ref.plugin_name.should eq("Google Collections")
39
+
40
+ ref.binary?.should eq(false)
41
+ ref.source?.should eq(true)
42
+ end
43
+
44
+ it "should create maven artifact with full version" do
45
+ ref = Etom::Reference.new(FILE_REF)
46
+
47
+ require "tmpdir"
48
+
49
+ Dir.mktmpdir("repo") do |repo|
50
+ ref.to_artifact(repo)
51
+
52
+ artifact_path = File.join("#{repo}", "com", "google", "collect", "1.0.0-v201105210816")
53
+ File.exists?(artifact_path).should eq(true)
54
+ File.exists?("#{artifact_path}/collect-1.0.0-v201105210816.jar").should eq(true)
55
+ File.exists?("#{artifact_path}/collect-1.0.0-v201105210816.pom").should eq(true)
56
+ end
57
+ end
58
+
59
+ it "should create maven artifact with short version" do
60
+ ref = Etom::Reference.new(FILE_REF)
61
+
62
+ require "tmpdir"
63
+
64
+ Dir.mktmpdir("repo") do |repo|
65
+ ref.to_artifact(repo, true)
66
+
67
+ artifact_path = File.join("#{repo}", "com", "google", "collect", "1.0.0")
68
+ File.exists?(artifact_path).should eq(true)
69
+ File.exists?("#{artifact_path}/collect-1.0.0.jar").should eq(true)
70
+ File.exists?("#{artifact_path}/collect-1.0.0.pom").should eq(true)
71
+ end
72
+ end
73
+
74
+ it "should create maven artifact for source without pom file with short version" do
75
+ ref = Etom::Reference.new(SOURCE_FILE_REF)
76
+
77
+ require "tmpdir"
78
+
79
+ Dir.mktmpdir("repo") do |repo|
80
+ ref.to_artifact(repo, true)
81
+
82
+ artifact_path = File.join("#{repo}", "com", "google", "collect", "1.0.0")
83
+ File.exists?(artifact_path).should eq(true)
84
+ File.exists?("#{artifact_path}/collect-1.0.0-sources.jar").should eq(true)
85
+ File.exists?("#{artifact_path}/collect-1.0.0.pom").should eq(false)
86
+ end
87
+ end
88
+
89
+ end
@@ -0,0 +1,26 @@
1
+ require "rspec"
2
+ require "ftools"
3
+
4
+ require "etom/hasher"
5
+
6
+ describe "Etom::Hash" do
7
+
8
+ it "should create hashes for a file" do
9
+
10
+ require "tmpdir"
11
+
12
+ Dir.mktmpdir("test") do |dir|
13
+ #file = "#{dir}/com.google.collect_1.0.0.v201105210816.jar"
14
+
15
+ #File.cp("#{File.dirname(__FILE__)}/data/com.google.collect_1.0.0.v201105210816.jar",file)
16
+
17
+ #Etom::Hash::md5(file).should eq("8d439a65ae3b934063dc54d983e5c5b0")
18
+ #Etom::Hash::sha1(file).should eq("cce9683605b3d4cf6f98344d053a40cea9b3c87d")
19
+
20
+ #Etom::Hash::create_hashes_for_file(file)
21
+ #File.exists?("#{file}.md5").should eq(true)
22
+ #File.exists?("#{file}.sha1").should eq(true)
23
+ end
24
+
25
+ end
26
+ end
@@ -0,0 +1,21 @@
1
+ require "rspec"
2
+ require "etom/property_reader"
3
+
4
+ describe "PropertyReader" do
5
+
6
+ PROPERTY_FILE = "#{File.dirname(__FILE__)}/data/plugin.properties"
7
+ PROPERTY_HASH = Hash["bundleName" => "Google Collections","bundleProvider" => "Eclipse Orbit"]
8
+
9
+ it "should read properties file from file system" do
10
+ hash = PropertyReader::load_from_file(PROPERTY_FILE)
11
+ hash.should eq(PROPERTY_HASH)
12
+ end
13
+
14
+ it "should read properties from string" do
15
+ string = File.read(PROPERTY_FILE)
16
+
17
+ hash = PropertyReader::load_from_string(string)
18
+ hash.should eq(PROPERTY_HASH)
19
+ end
20
+
21
+ end
metadata ADDED
@@ -0,0 +1,100 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: etom
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.10
5
+ prerelease:
6
+ platform: ruby
7
+ authors:
8
+ - Simon Harrer
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+ date: 2011-09-09 00:00:00.000000000Z
13
+ dependencies:
14
+ - !ruby/object:Gem::Dependency
15
+ name: thor
16
+ requirement: &25870176 !ruby/object:Gem::Requirement
17
+ none: false
18
+ requirements:
19
+ - - ! '>='
20
+ - !ruby/object:Gem::Version
21
+ version: '0'
22
+ type: :runtime
23
+ prerelease: false
24
+ version_requirements: *25870176
25
+ - !ruby/object:Gem::Dependency
26
+ name: rubyzip
27
+ requirement: &25869564 !ruby/object:Gem::Requirement
28
+ none: false
29
+ requirements:
30
+ - - ! '>='
31
+ - !ruby/object:Gem::Version
32
+ version: '0'
33
+ type: :runtime
34
+ prerelease: false
35
+ version_requirements: *25869564
36
+ - !ruby/object:Gem::Dependency
37
+ name: rspec
38
+ requirement: &25868856 !ruby/object:Gem::Requirement
39
+ none: false
40
+ requirements:
41
+ - - ! '>='
42
+ - !ruby/object:Gem::Version
43
+ version: '0'
44
+ type: :development
45
+ prerelease: false
46
+ version_requirements: *25868856
47
+ description: ! 'Uses fast operations without relying onto maven to convert eclipse
48
+ plugins to maven artifacts witin a local maven repository. '
49
+ email:
50
+ - simon.harrer@gmail.com
51
+ executables:
52
+ - etom
53
+ extensions: []
54
+ extra_rdoc_files: []
55
+ files:
56
+ - .gitignore
57
+ - .rspec
58
+ - Gemfile
59
+ - README.md
60
+ - Rakefile
61
+ - bin/etom
62
+ - etom.gemspec
63
+ - lib/etom.rb
64
+ - lib/etom/cli.rb
65
+ - lib/etom/hasher.rb
66
+ - lib/etom/property_reader.rb
67
+ - lib/etom/reference.rb
68
+ - lib/etom/version.rb
69
+ - spec/data/com.google.appengine.eclipse.core_2.3.3.r37v201107211953.jar
70
+ - spec/data/com.google.collect.source_1.0.0.v201105210816.jar
71
+ - spec/data/com.google.collect_1.0.0.v201105210816.jar
72
+ - spec/data/plugin.properties
73
+ - spec/etom_spec.rb
74
+ - spec/hasher_spec.rb
75
+ - spec/property_reader_spec.rb
76
+ homepage: https://github.com/simonharrer/etom
77
+ licenses: []
78
+ post_install_message:
79
+ rdoc_options: []
80
+ require_paths:
81
+ - lib
82
+ required_ruby_version: !ruby/object:Gem::Requirement
83
+ none: false
84
+ requirements:
85
+ - - ! '>='
86
+ - !ruby/object:Gem::Version
87
+ version: '0'
88
+ required_rubygems_version: !ruby/object:Gem::Requirement
89
+ none: false
90
+ requirements:
91
+ - - ! '>='
92
+ - !ruby/object:Gem::Version
93
+ version: '0'
94
+ requirements: []
95
+ rubyforge_project: etom
96
+ rubygems_version: 1.8.10
97
+ signing_key:
98
+ specification_version: 3
99
+ summary: Converts eclipse plugins to maven artifacts
100
+ test_files: []