You are viewing a plain text version of this content. The canonical link for it is here.
Posted to issues@lucene.apache.org by GitBox <gi...@apache.org> on 2022/11/18 15:27:58 UTC

[GitHub] [lucene] dweiss commented on a diff in pull request #11947: Add self-contained artifact upload script for apache nexus (#11329)

dweiss commented on code in PR #11947:
URL: https://github.com/apache/lucene/pull/11947#discussion_r1026571426


##########
dev-tools/scripts/StageArtifacts.java:
##########
@@ -0,0 +1,395 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+import org.w3c.dom.Document;
+import org.w3c.dom.Node;
+import org.w3c.dom.NodeList;
+import org.xml.sax.InputSource;
+import org.xml.sax.SAXException;
+
+import javax.xml.parsers.DocumentBuilderFactory;
+import javax.xml.parsers.ParserConfigurationException;
+import java.io.Console;
+import java.io.IOException;
+import java.io.StringReader;
+import java.net.Authenticator;
+import java.net.HttpURLConnection;
+import java.net.PasswordAuthentication;
+import java.net.URI;
+import java.net.URISyntaxException;
+import java.net.URLEncoder;
+import java.net.http.HttpClient;
+import java.net.http.HttpRequest;
+import java.net.http.HttpResponse;
+import java.nio.charset.StandardCharsets;
+import java.nio.file.Files;
+import java.nio.file.Path;
+import java.nio.file.Paths;
+import java.util.ArrayList;
+import java.util.Comparator;
+import java.util.List;
+import java.util.Map;
+import java.util.Objects;
+import java.util.stream.Collectors;
+import java.util.stream.Stream;
+
+/**
+ * Sonatype nexus artifact staging/deployment script. This could be made
+ * nicer, but this keeps it to JDK classes only.
+ *
+ * <p>The implementation is based on the REST API documentation of
+ * <a href="https://oss.sonatype.org/nexus-staging-plugin/default/docs/index.html">nexus-staging-plugin</a>
+ * and on anecdotal evidence and reverse-engineered information from around
+ * the web... Weird that such a crucial piece of infrastructure has such obscure
+ * documentation.
+ */
+public class StageArtifacts {
+  private static final String DEFAULT_NEXUS_URI = "https://repository.apache.org";
+
+  private static class Params {
+    URI nexusUri = URI.create(DEFAULT_NEXUS_URI);
+    String userName;
+    char[] userPass;
+    Path mavenDir;
+    String description;
+
+    private static char[] envVar(String envVar) {
+      var value = System.getenv(envVar);
+      return value == null ? null : value.toCharArray();
+    }
+
+    static Params parse(String[] args) {
+      try {
+        var params = new Params();
+        for (int i = 0; i < args.length; i++) {
+          switch (args[i]) {
+            case "-n":
+            case "--nexus":
+              params.nexusUri = URI.create(args[++i]);
+              break;
+            case "-u":
+            case "--user":
+              params.userName = args[++i];

Review Comment:
   there's a catch block that does it, below. it's a waste of time to elaborate much on arg validation if it's used from the wizard anyway?



##########
dev-tools/scripts/StageArtifacts.java:
##########
@@ -0,0 +1,395 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+import org.w3c.dom.Document;
+import org.w3c.dom.Node;
+import org.w3c.dom.NodeList;
+import org.xml.sax.InputSource;
+import org.xml.sax.SAXException;
+
+import javax.xml.parsers.DocumentBuilderFactory;
+import javax.xml.parsers.ParserConfigurationException;
+import java.io.Console;
+import java.io.IOException;
+import java.io.StringReader;
+import java.net.Authenticator;
+import java.net.HttpURLConnection;
+import java.net.PasswordAuthentication;
+import java.net.URI;
+import java.net.URISyntaxException;
+import java.net.URLEncoder;
+import java.net.http.HttpClient;
+import java.net.http.HttpRequest;
+import java.net.http.HttpResponse;
+import java.nio.charset.StandardCharsets;
+import java.nio.file.Files;
+import java.nio.file.Path;
+import java.nio.file.Paths;
+import java.util.ArrayList;
+import java.util.Comparator;
+import java.util.List;
+import java.util.Map;
+import java.util.Objects;
+import java.util.stream.Collectors;
+import java.util.stream.Stream;
+
+/**
+ * Sonatype nexus artifact staging/deployment script. This could be made
+ * nicer, but this keeps it to JDK classes only.
+ *
+ * <p>The implementation is based on the REST API documentation of
+ * <a href="https://oss.sonatype.org/nexus-staging-plugin/default/docs/index.html">nexus-staging-plugin</a>
+ * and on anecdotal evidence and reverse-engineered information from around
+ * the web... Weird that such a crucial piece of infrastructure has such obscure
+ * documentation.
+ */
+public class StageArtifacts {
+  private static final String DEFAULT_NEXUS_URI = "https://repository.apache.org";
+
+  private static class Params {
+    URI nexusUri = URI.create(DEFAULT_NEXUS_URI);
+    String userName;
+    char[] userPass;
+    Path mavenDir;
+    String description;
+
+    private static char[] envVar(String envVar) {
+      var value = System.getenv(envVar);
+      return value == null ? null : value.toCharArray();
+    }
+
+    static Params parse(String[] args) {
+      try {
+        var params = new Params();
+        for (int i = 0; i < args.length; i++) {
+          switch (args[i]) {
+            case "-n":
+            case "--nexus":
+              params.nexusUri = URI.create(args[++i]);
+              break;
+            case "-u":
+            case "--user":
+              params.userName = args[++i];
+              break;
+            case "-p":
+            case "--password":
+              params.userPass = args[++i].toCharArray();
+              break;
+            case "--description":
+              params.description = args[++i];
+              break;
+
+            case "-h":
+            case "--help":
+              System.out.println("java " + StageArtifacts.class.getName() + " [options] path");
+              System.out.println("  -u, --user  User name for authentication.");
+              System.out.println("              better: ASF_USERNAME env. var.");
+              System.out.println("  -p, --password  Password for authentication.");
+              System.out.println("              better: ASF_PASSWORD env. var.");
+              System.out.println("  -n, --nexus URL to Apache Nexus (optional).");
+              System.out.println("  --description  Staging repo description (optional).");
+              System.out.println("");
+              System.out.println("  path        Path to maven artifact directory.");
+              System.out.println("");
+              System.out.println(" Password can be omitted for console prompt-input.");

Review Comment:
   jdk11.



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: issues-unsubscribe@lucene.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscribe@lucene.apache.org
For additional commands, e-mail: issues-help@lucene.apache.org