diff --git a/src/tech/avroid/api/Artifactory.groovy b/src/tech/avroid/api/Artifactory.groovy
index ee2647f..d4459e0 100644
--- a/src/tech/avroid/api/Artifactory.groovy
+++ b/src/tech/avroid/api/Artifactory.groovy
@@ -11,6 +11,7 @@ import groovy.json.JsonSlurper
* Need plugin Jenkins:
* HTTP Request
*/
+@Deprecated
class Artifactory implements Serializable {
// See https://www.baeldung.com/java-serial-version-uid
diff --git a/src/tech/avroid/api/Eva.groovy b/src/tech/avroid/api/Eva.groovy
index 9fbaa23..3f9acb1 100644
--- a/src/tech/avroid/api/Eva.groovy
+++ b/src/tech/avroid/api/Eva.groovy
@@ -6,6 +6,7 @@ import groovy.json.JsonSlurper
/**
* Class for work with API Eva
*/
+@Deprecated
class Eva implements Serializable {
private Script script
private String host
diff --git a/src/tech/avroid/api/Gitea.groovy b/src/tech/avroid/api/Gitea.groovy
index 5dd9546..14b196d 100644
--- a/src/tech/avroid/api/Gitea.groovy
+++ b/src/tech/avroid/api/Gitea.groovy
@@ -5,6 +5,7 @@ import groovy.json.JsonOutput
/**
* Class for work with API gitea
*/
+@Deprecated
class Gitea implements Serializable {
private Script script
private String projectURL
diff --git a/src/tech/avroid/api/NextCloud.groovy b/src/tech/avroid/api/NextCloud.groovy
index 8bcc28a..0222818 100644
--- a/src/tech/avroid/api/NextCloud.groovy
+++ b/src/tech/avroid/api/NextCloud.groovy
@@ -1,5 +1,6 @@
package tech.avroid.api
+@Deprecated
class NextCloud implements Serializable {
private script
diff --git a/src/tech/avroid/api/Nexus.groovy b/src/tech/avroid/api/Nexus.groovy
index 77017d8..cddcf1c 100644
--- a/src/tech/avroid/api/Nexus.groovy
+++ b/src/tech/avroid/api/Nexus.groovy
@@ -1,5 +1,6 @@
package tech.avroid.api
+@Deprecated
class Nexus implements Serializable {
private script
diff --git a/src/tech/avroid/artifactory/Artifactory.groovy b/src/tech/avroid/artifactory/Artifactory.groovy
new file mode 100644
index 0000000..d0e680a
--- /dev/null
+++ b/src/tech/avroid/artifactory/Artifactory.groovy
@@ -0,0 +1,121 @@
+package tech.avroid.artifactory
+
+import groovy.json.JsonSlurper
+
+/**
+ * Work with REST API Artifactory
+ * Official example:
+ *
+ * aqlCleanup.groovy
+ *
+ * Need plugin Jenkins:
+ * HTTP Request
+ */
+class Artifactory implements Serializable {
+
+ // See https://www.baeldung.com/java-serial-version-uid
+ private static final long serialVersionUID = 1L
+
+ private Script script
+ private String urlArtifactory
+ private String credentials
+
+ /**
+ @param script Script - context pointer on step in Pipelines
+ @param host String - URL JFrog Artifactory server
+ @param credentials String - id Jenkins credentials with user's name and pass for Artifactory
+ */
+ Artifactory(Script script, String urlArtifactory, String credentials) {
+ this.script = script
+ this.urlArtifactory = urlArtifactory
+ this.credentials = credentials
+ }
+
+ /**
+ * Request type Artifactory Query Language (AQL) to REST API
+ * @param request String - AQL-request
+ * @return def - body response
+ * @see
+
+
+
+
+
+
+
+
+
+ /files/${dirPath}
+ infinity
+
+
+
+
+
+
+
+
+ ' > file.xml
+ cat file.xml
+ """).trim()
+ def path = /(.*?)<\/d:href>/
+ return (xml =~ path).collect { it[1] }
+ }
+ }
+
+ /**
+ * Info about artifact in NextCloud.
+ * @param artifactPath String - path of artifact in Nexus
+ * @return Map with information about package
+ */
+ public Map fileInfo(String filePath) {
+ String xml
+ Map fileInfo = [:]
+ def pattern
+ List values = []
+
+ this.script.withCredentials([this.script.usernamePassword(
+ credentialsId: this.credentials,
+ usernameVariable: 'username',
+ passwordVariable: 'password')]) {
+ List parts = filePath.tokenize('/')
+ String fileName = parts[-1]
+ String path = parts[0..-2].join('/')
+
+ xml = script.sh(returnStdout: true, script: """
+ curl "${this.host}/remote.php/dav/" \
+ --user "${script.username}":"${script.password}" \
+ -X SEARCH -H "content-Type: text/xml" \
+ --data '
+
+
+
+
+
+
+
+
+
+
+
+ /files/${path}
+ infinity
+
+
+
+
+
+
+
+ ${fileName}
+
+
+
+ ' > file.xml
+ cat file.xml
+ """).trim()
+
+ fileInfo.put("filePath", filePath)
+ fileInfo.put("displayName", fileName)
+ pattern = /(.*?)
+ values = (xml =~ pattern).collect { it[1] }
+ fileInfo.put("contentType", values[0])
+ pattern = /(.*?)
+ values = (xml =~ pattern).collect { it[1] }
+ fileInfo.put("lastModified", values[0])
+ }
+
+ return fileInfo
+ }
+
+ /**
+ * Download artifact from NextCloud
+ * @param filePath String - path of artifact in NextCloud
+ * @param path String - local path of artifact
+ * @return String - local path of file
+ */
+ public String download(String filePath, String path = "") {
+ if (path == "") {
+ path = filePath.split('/').last()
+ }
+ this.script.withCredentials([this.script.usernamePassword(
+ credentialsId: this.credentials,
+ usernameVariable: 'username',
+ passwordVariable: 'password')]) {
+ script.sh """
+ curl -u "${script.username}":"${script.password}" -o "$path" "$host/$filePath"
+ """
+ }
+
+ return path
+ }
+}
diff --git a/src/tech/avroid/nexus/Nexus.groovy b/src/tech/avroid/nexus/Nexus.groovy
new file mode 100644
index 0000000..0a8f5a8
--- /dev/null
+++ b/src/tech/avroid/nexus/Nexus.groovy
@@ -0,0 +1,186 @@
+package tech.avroid.nexus
+
+class Nexus implements Serializable {
+
+ private script
+ private host
+ private credentials
+
+ /**
+ *
+ @param script Script - context pointer on step in Pipelines
+ @param host String - Nexus host name
+ @param credentials String - User's name and pass in Nexus
+ */
+ Nexus(Script script, String host, String credentials) {
+ this.script = script
+ this.host = host
+ this.credentials = credentials
+ }
+
+ /**
+ * Upload artifact in Nexus.
+ * When call method need either artifactUrl or repository, and path
+ * either
+ *
+ @param artifactPath String - Local path to artifact
+ @param artifactUrl String - URL (optional)
+ @param repository String - Name of Nexus repository
+ @param path String - Path in Nexus repository
+ @param artifactName String - Name of artifact in Nexus (optional). Common calculate from artifactPath
+ @param type String - type of repository
+ @return String - artifact url in Nexus
+ */
+ @Deprecated
+ public String upload(Map args = [:], String type = "raw") {
+ String artifactName = args.artifactName ?: args.artifactPath.split('/').last()
+ String artifactUrl = args.artifactUrl ?: "${host}/repository/${args.repository}/${args.path}/${artifactName}"
+
+ script.httpRequest(
+ url: artifactUrl,
+ authentication: credentials,
+ httpMode: "PUT",
+ uploadFile: "${args.artifactPath}",
+ validResponseCodes: "201",
+ wrapAsMultipart: false
+ )
+ return artifactUrl
+ }
+
+ /**
+ * Method get artifacts' urls from nexus repository
+ @param repository String - Repository name in Nexus.
+ @param type String - type of repository
+ @return List - list of artifacts' urls
+ */
+ public List search(String repository, String type = "raw") {
+ String newUrl = ""
+
+ Object res = script.httpRequest(
+ url: "${host}/service/rest/v1/components?repository=${repository}",
+ httpMode: 'GET',
+ quiet: true,
+ authentication: credentials
+ )
+
+ Object dataJSON = script.readJSON text: res.content
+ String nextPage = dataJSON.continuationToken
+ List urls = []
+
+ dataJSON.items.each { index ->
+ if (!index.assets[0].downloadUrl.contains(".html")) {
+ urls.add(index.assets[0].downloadUrl)
+ }
+ }
+
+ int request = 0;
+ while (nextPage != 'null' && request < 2000) {
+ request++;
+ res = script.httpRequest(
+ url: "${host}/service/rest/v1/components?" +
+ "continuationToken=${nextPage}&repository=${repository}",
+ httpMode: 'GET',
+ quiet: true,
+ authentication: credentials
+ )
+
+ dataJSON = script.readJSON text: res.content
+ nextPage = dataJSON.continuationToken
+
+ dataJSON.items.each { index ->
+ if (!index.assets[0].downloadUrl.contains(".html")) {
+ newUrl = index.assets[0].downloadUrl
+ urls.add("$newUrl")
+ }
+ }
+ }
+ return urls
+ }
+
+
+ /**
+ * Download artifact from Nexus repo
+ *
+ @param url String - URL, откуда будет скачан файл
+ @param outputFile String - Путь с именем файла, по которому будет сохранен(optional).
+ * По умолчанию с именем сохраняется в текущей директории с именем файла
+ @return String - Возвращает имя загруженного файла
+ */
+ String download(String url, String outputFile = '') {
+ String artifactName = url.split('/').last()
+ String artifact = outputFile ?: "${this.script.pwd()}/${artifactName}"
+
+ this.script.httpRequest(
+ url: url,
+ authentication: this.credentials,
+ httpMode: "GET",
+ outputFile: artifact,
+ contentType: 'APPLICATION_JSON',
+ acceptType: 'APPLICATION_JSON',
+ responseHandle: 'NONE'
+ )
+
+ return artifact
+ }
+
+ /**
+ * Method get artifact's info from nexus
+ @param repository String - Repository name in Nexus.
+ @param name String - Artifact path in Nexus.
+ @return Object - artifacts's information
+ */
+ public Object fileInfo(String repository, String name) {
+ Object res = script.httpRequest(
+ url: "${host}/service/rest/v1/components?repository=${repository}&name=${name}",
+ httpMode: 'GET',
+ quiet: true,
+ authentication: credentials
+ )
+
+ Object dataJSON = script.readJSON text: res.content
+ return dataJSON.items[0].assets[0]
+ }
+
+ /**
+ * Функция загружает артефакт в Pypi-репозиторий Nexus
+ @param repository String - Имя репозитория в Nexus.
+ @param artifact String - Путь до артефакта.
+ @param artifactName String - Имя артефакта которое будет отображаться в Nexus. (optional)
+ */
+ public void uploadPypiArtifact(Map args = [:]) {
+ String artifactName = args.artifactName ?: args.artifact.split('/').last()
+
+ script.httpRequest(
+ url: "${host}/service/rest/v1/components?repository=${args.repository}",
+ httpMode: 'POST',
+ quiet: false,
+ formData: [[contentType: 'APPLICATION_FORM_DATA',
+ name: 'pypi.asset',
+ fileName: artifactName,
+ uploadFile: args.artifact]],
+ authentication: credentials
+ )
+ }
+
+ /**
+ * Функция загружает артефакт в Npm-репозиторий Nexus
+ @param repository String - Имя репозитория в Nexus.
+ @param artifact String - Путь до артефакта.
+ @param artifactName String - Имя артефакта которое будет отображаться в Nexus. (optional)
+ */
+ public void uploadNpmArtifact(Map args = [:]) {
+ String artifactName = args.artifactName ?: args.artifact.split('/').last()
+
+ script.httpRequest(
+ url: "${host}/service/rest/v1/components?repository=${args.repository}",
+ httpMode: 'POST',
+ quiet: false,
+ formData: [[contentType: 'APPLICATION_FORM_DATA',
+ name: 'npm.asset',
+ fileName: artifactName,
+ uploadFile: args.artifact]],
+ authentication: credentials
+ )
+ }
+
+}