Skip to content

Commit

Permalink
#121: Worked in review findings.
Browse files Browse the repository at this point in the history
  • Loading branch information
redcatbear committed Aug 23, 2022
1 parent aee4ea3 commit e22fdca
Show file tree
Hide file tree
Showing 6 changed files with 22 additions and 20 deletions.
2 changes: 1 addition & 1 deletion doc/changes/changes_1.3.0.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,6 @@ Code name:

## Features

* #121: Verify references
* #121: Added tests to verify version references

## Dependency Updates
2 changes: 1 addition & 1 deletion doc/developer_guide/developer_guide.md
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ sudo luarocks install remotelog
sudo luarocks install luacov
sudo luarocks install luacov-coveralls
sudo luarocks install luacheck
sudo luarocks install ExaError
sudo luarocks install exaerror
sudo luarocks install amalg
```

Expand Down
16 changes: 9 additions & 7 deletions spec/pom/Reader.lua → spec/PomReader.lua
Original file line number Diff line number Diff line change
@@ -1,42 +1,44 @@
--- This class implements a basic reader for information in a Maven projects POM file.
-- @classmod Reader
local Reader = {
local PomReader = {
_artifact_version = nil,
_artifact_id = nil
}

Reader.__index = Reader
PomReader.__index = PomReader

--- Create a new instance of a `PomReader`.
-- @string path path to the POM file
-- @return new instance
function Reader:new(path)
function PomReader:new(path)
assert(path ~= nil, "Path to POM file must be given.")
local instance = setmetatable({}, self)
instance:_init(path)
return instance
end

function Reader:_init(path)
function PomReader:_init(path)
local pom = assert(io.open(path, "r"), "Failed to open POM: " .. path)
repeat
local line = pom:read("*l")
self._artifact_version = string.match(line,"<version>%s*([0-9.]+)") or self._artifact_version
self._artifact_id = string.match(line,"<artifactId>%s*([-.%w]+)") or self._artifact_id
until (self._artifact_id and self._artifact_version) or (line == nil)
pom:close()
assert(self._artifact_id, "No artifact ID found in project's POM file")
assert(self._artifact_version, "No artifact version found in project's POM file")
end

--- Get the artifact version.
-- @return version of the Maven artifact
function Reader:get_artifact_version()
function PomReader:get_artifact_version()
return self._artifact_version
end

--- Get the artifact ID.
-- ID of the Maven artifact
function Reader:get_artifact_id()
function PomReader:get_artifact_id()
return self._artifact_id
end

return Reader
return PomReader
8 changes: 4 additions & 4 deletions spec/build_preconditions_spec.lua
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
package.path = "spec/?.lua;" .. package.path
require("busted.runner")()
local Reader = require("pom.Reader")
local Reader = require("PomReader")

local function get_project_base_path()
return debug.getinfo(1,"S").source:sub(2):gsub("[^/]*$", "") .. ".."
end

local reader = Reader:new(get_project_base_path() .. "/pom.xml")
local pom = Reader:new(get_project_base_path() .. "/pom.xml")

local function load_rockspec(path)
local env = {}
Expand All @@ -17,7 +17,7 @@ end

local function get_rockspec_path() --
return get_project_base_path() .. "/"
.. (string.format("%s-%s-1.rockspec", reader:get_artifact_id(), reader:get_artifact_version()))
.. (string.format("%s-%s-1.rockspec", pom:get_artifact_id(), pom:get_artifact_version()))
end

local rockspec = load_rockspec(get_rockspec_path())
Expand All @@ -39,7 +39,7 @@ describe("Build precondition", function()
end)

it("starts with the same version number as the main artifact in the Maven POM file", function()
assert.matches(reader:get_artifact_version() .. "%-%d+", rockspec.version)
assert.matches(pom:get_artifact_version() .. "%-%d+", rockspec.version)
end)
end)
end)
Expand Down
6 changes: 3 additions & 3 deletions spec/exasolrls/RlsAdapter_spec.lua
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,13 @@ local mockagne = require("mockagne")
local adapter_capabilities = require("exasolrls.adapter_capabilities")
local RlsAdapter = require("exasolrls.RlsAdapter")
require("exasolrls.RlsAdapterProperties")
local Reader = require("spec.pom.Reader")
local Reader = require("PomReader")

local function get_project_base_path()
return debug.getinfo(1,"S").source:sub(2):gsub("[^/]*$", "") .. "../.."
end

local reader = Reader:new(get_project_base_path() .. "/pom.xml")
local pom = Reader:new(get_project_base_path() .. "/pom.xml")

describe("RlsAdapter", function()
local adapter
Expand All @@ -28,7 +28,7 @@ describe("RlsAdapter", function()
end)

it("has the same version number as the project in the Maven POM file", function()
assert.are.equal(reader:get_artifact_version(), adapter:get_version())
assert.are.equal(pom:get_artifact_version(), adapter:get_version())
end)

it("reports the name of the adapter", function()
Expand Down
8 changes: 4 additions & 4 deletions spec/smoke_test_spec.lua
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
package.path = "target/?.lua;" .. package.path
require("busted.runner")()
local Reader = require("spec.pom.Reader")
local Reader = require("PomReader")

local function get_project_base_path()
return debug.getinfo(1,"S").source:sub(2):gsub("[^/]*$", "") .. ".."
end

local reader = Reader:new(get_project_base_path() .. "/pom.xml")
local pom = Reader:new(get_project_base_path() .. "/pom.xml")

local VERSION <const> = reader:get_artifact_version()
local PROJECT <const> = reader:get_artifact_id()
local VERSION <const> = pom:get_artifact_version()
local PROJECT <const> = pom:get_artifact_id()
local DISTRIBUTION_MODULE <const> = PROJECT .. "-dist"
local DISTRIBUTION_PATH = "target"

Expand Down

0 comments on commit e22fdca

Please sign in to comment.