Curl语法用于将伪像从Snapshot升级到Release Repository

时间:2015-09-22 10:44:59

标签: maven curl nexus

有没有人知道用于从Nexus Snapshot Repo到Release Repository推广伪像的curl语法?

4 个答案:

答案 0 :(得分:2)

您可以绝对为所有内容使用curl。我个人使用NING HttpClient(v1.8.16)。

无论出于何种原因,Sonatype都难以确定难以置信难以确定正确的URL,标头和有效负载应该是什么;我不得不嗅到流量并猜测......那里有一些勉强有用的博客/文档,但它与oss.sonatype.org无关,或者它基于XML(我发现它甚至不起作用。他们自己的垃圾文件,恕我直言,希望未来的寻求者可以找到这个答案有用。

我不认为你可以从SNAPSHOT转到RELEASE而不生成另一个版本,但是如果你创建另一个版本并直接部署到staging repo并从staging升级 - >释放,这将完成我认为你想要的。

如果你发布到oss.sonatype.org以外的Nexus,只需用正确的主机替换它。

您感兴趣的网址 "https://oss.sonatype.org/service/local/staging/profiles/" + profile + "/finish"

从您上传初始POM / Jar时,profile是您的sonatype / nexus profileID(例如4364f3bbaf163)。

以下是我为完成此操作而编写的(CC0许可的)代码。当您上传初始POM / Jar时,也会从响应中解析repo(例如comdorkbox-1003)。

关闭回购:

/**
 * Closes the repo and (the server) will verify everything is correct.
 * @throws IOException
 */
private static
String closeRepo(final String authInfo, final String profile, final String repo, final String nameAndVersion) throws IOException {

    String repoInfo = "{'data':{'stagedRepositoryId':'" + repo + "','description':'Closing " + nameAndVersion + "'}}";
    RequestBuilder builder = new RequestBuilder("POST");
    Request request = builder.setUrl("https://oss.sonatype.org/service/local/staging/profiles/" + profile + "/finish")
                             .addHeader("Content-Type", "application/json")
                             .addHeader("Authorization", "Basic " + authInfo)

                             .setBody(repoInfo.getBytes(OS.UTF_8))

                             .build();

    return sendHttpRequest(request);
}

推广回购:

/**
 * Promotes (ie: release) the repo. Make sure to drop when done
 * @throws IOException
 */
private static
String promoteRepo(final String authInfo, final String profile, final String repo, final String nameAndVersion) throws IOException {

    String repoInfo = "{'data':{'stagedRepositoryId':'" + repo + "','description':'Promoting " + nameAndVersion + "'}}";
    RequestBuilder builder = new RequestBuilder("POST");
    Request request = builder.setUrl("https://oss.sonatype.org/service/local/staging/profiles/" + profile + "/promote")
                     .addHeader("Content-Type", "application/json")
                     .addHeader("Authorization", "Basic " + authInfo)

                     .setBody(repoInfo.getBytes(OS.UTF_8))

                     .build();
    return sendHttpRequest(request);
}

删除回购:

/**
 * Drops the repo
 * @throws IOException
 */
private static
String dropRepo(final String authInfo, final String profile, final String repo, final String nameAndVersion) throws IOException {

    String repoInfo = "{'data':{'stagedRepositoryId':'" + repo + "','description':'Dropping " + nameAndVersion + "'}}";
    RequestBuilder builder = new RequestBuilder("POST");
    Request request = builder.setUrl("https://oss.sonatype.org/service/local/staging/profiles/" + profile + "/drop")
                     .addHeader("Content-Type", "application/json")
                     .addHeader("Authorization", "Basic " + authInfo)

                     .setBody(repoInfo.getBytes(OS.UTF_8))

                     .build();

    return sendHttpRequest(request);
}

删除签名粪便:

/**
 * Deletes the extra .asc.md5 and .asc.sh1 'turds' that show-up when you upload the signature file. And yes, 'turds' is from sonatype
 * themselves. See: https://issues.sonatype.org/browse/NEXUS-4906
 * @throws IOException
 */
private static
void deleteSignatureTurds(final String authInfo, final String repo, final String groupId_asPath, final String name,
                          final String version, final File signatureFile)
                throws IOException {

    String delURL = "https://oss.sonatype.org/service/local/repositories/" + repo + "/content/" +
                    groupId_asPath + "/" + name + "/" + version + "/" + signatureFile.getName();

    RequestBuilder builder;
    Request request;

    builder = new RequestBuilder("DELETE");
    request = builder.setUrl(delURL + ".sha1")
                     .addHeader("Authorization", "Basic " + authInfo)
                     .build();
    sendHttpRequest(request);

    builder = new RequestBuilder("DELETE");
    request = builder.setUrl(delURL + ".md5")
                     .addHeader("Authorization", "Basic " + authInfo)
                     .build();
    sendHttpRequest(request);
}

文件上传:

    public
    String upload(final File file, final String extension, String classification) throws IOException {

        final RequestBuilder builder = new RequestBuilder("POST");
        final RequestBuilder requestBuilder = builder.setUrl(uploadURL);
        requestBuilder.addHeader("Authorization", "Basic " + authInfo)

                      .addBodyPart(new StringPart("r", repo))
                      .addBodyPart(new StringPart("g", groupId))
                      .addBodyPart(new StringPart("a", name))
                      .addBodyPart(new StringPart("v", version))
                      .addBodyPart(new StringPart("p", "jar"))
                      .addBodyPart(new StringPart("e", extension))
                      .addBodyPart(new StringPart("desc", description));


        if (classification != null) {
            requestBuilder.addBodyPart(new StringPart("c", classification));
        }

        requestBuilder.addBodyPart(new FilePart("file", file));
        final Request request = requestBuilder.build();

        return sendHttpRequest(request);
    }

<强> EDIT1:

如何获取回购的活动/状态

/**
 * Gets the activity information for a repo. If there is a failure during verification/finish -- this will provide what it was.
 * @throws IOException
 */
private static
String activityForRepo(final String authInfo, final String repo) throws IOException {

    RequestBuilder builder = new RequestBuilder("GET");
    Request request = builder.setUrl("https://oss.sonatype.org/service/local/staging/repository/" + repo + "/activity")
                             .addHeader("Content-Type", "application/json")
                             .addHeader("Authorization", "Basic " + authInfo)

                             .build();

    return sendHttpRequest(request);
}

答案 1 :(得分:1)

Nexus Pro的登台套件允许您通过多个步骤将部署到临时登台存储库的发布工件升级到最终版本存储库。有一个用于自动执行此操作的REST API,但您也可以使用Nexus Staging Maven插件或Ant任务。 Staging chapter in the Nexus documentation有更多针对所有这些以及更多的指针。

然而,它与将SNAPSHOT工件升级到版本无关。这通常被视为一种不好的做法,因为它需要重写POM文件。

答案 2 :(得分:0)

据我所知,没有这样的事情。您需要更改您的pom文件并进行部署。

答案 3 :(得分:0)

不,你不能。您必须执行完整版本:mvn release:prepare release:perform