-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
aee4ea3
commit e22fdca
Showing
6 changed files
with
22 additions
and
20 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters