yifan-c commented on code in PR #62:
URL: https://github.com/apache/cassandra-sidecar/pull/62#discussion_r1268656592


##########
common/src/testFixtures/java/org/apache/cassandra/sidecar/common/ResourceUtils.java:
##########
@@ -0,0 +1,74 @@
+/*
+ * 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.
+ */
+
+package org.apache.cassandra.sidecar.common;
+
+import java.io.IOException;
+import java.io.InputStream;
+import java.io.OutputStream;
+import java.nio.file.Files;
+import java.nio.file.Path;
+
+import static org.assertj.core.api.Assertions.assertThat;
+import static org.assertj.core.api.Assertions.fail;
+
+/**
+ * A utilities class to handle resources for tests
+ */
+public final class ResourceUtils
+{
+    /**
+     * Writes a resource with {@code resourceName} loaded from the {@link 
ClassLoader classLoader} into the
+     * {@code destinationPath}
+     *
+     * @param classLoader     the class loader for the resource
+     * @param destinationPath the destination path to write the file
+     * @param resourceName    the name of the resource to be loaded
+     * @return the {@link Path} to the created resource
+     */
+    public static Path writeResourceToTempDir(ClassLoader classLoader, Path 
destinationPath, String resourceName)
+    {
+        try
+        {
+            Path certFilePath = destinationPath.resolve(resourceName);

Review Comment:
   `cert`?



##########
scripts/build-shaded-dtest-jar-local.sh:
##########
@@ -25,33 +25,33 @@ SCRIPT_DIR=$( dirname -- "$( readlink -f -- "$0"; )"; )
 CASSANDRA_VERSION=$(cat build.xml | grep 'property name="base.version"' | awk 
-F "\"" '{print $4}')
 GIT_HASH=$(git rev-parse --short HEAD)
 DTEST_ARTIFACT_ID=${ARTIFACT_NAME}-local
-DTEST_JAR_DIR="$(dirname ${SCRIPT_DIR}/)/dtest-jars"
+DTEST_JAR_DIR="$(dirname "${SCRIPT_DIR}/")/dtest-jars"
 
-echo $CASSANDRA_VERSION
-echo $GIT_HASH
-echo $DTEST_ARTIFACT_ID
+echo "${CASSANDRA_VERSION}"
+echo "${GIT_HASH}"
+echo "${DTEST_ARTIFACT_ID}"
 
 ant clean
 ant dtest-jar -Dno-checkstyle=true
 
 # Install the version that will be shaded
-mvn install:install-file               \
-   -Dfile=./build/dtest-${CASSANDRA_VERSION}.jar \
-   -DgroupId=org.apache.cassandra      \
-   -DartifactId=${DTEST_ARTIFACT_ID} \
-   -Dversion=${CASSANDRA_VERSION}-${GIT_HASH}         \
-   -Dpackaging=jar                     \
-   -DgeneratePom=true                  \
-   -DlocalRepositoryPath=${REPO_DIR}
+"${SCRIPT_DIR}/mvnw" install:install-file                            \

Review Comment:
   should we consider windows development and run `mvnw.cmd`, or assume no such 
use case and discard the cmd file?



##########
common/src/testFixtures/java/org/apache/cassandra/sidecar/common/ResourceUtils.java:
##########
@@ -0,0 +1,74 @@
+/*
+ * 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.
+ */
+
+package org.apache.cassandra.sidecar.common;
+
+import java.io.IOException;
+import java.io.InputStream;
+import java.io.OutputStream;
+import java.nio.file.Files;
+import java.nio.file.Path;
+
+import static org.assertj.core.api.Assertions.assertThat;
+import static org.assertj.core.api.Assertions.fail;
+
+/**
+ * A utilities class to handle resources for tests
+ */
+public final class ResourceUtils
+{
+    /**
+     * Writes a resource with {@code resourceName} loaded from the {@link 
ClassLoader classLoader} into the
+     * {@code destinationPath}
+     *
+     * @param classLoader     the class loader for the resource
+     * @param destinationPath the destination path to write the file
+     * @param resourceName    the name of the resource to be loaded
+     * @return the {@link Path} to the created resource
+     */
+    public static Path writeResourceToTempDir(ClassLoader classLoader, Path 
destinationPath, String resourceName)
+    {
+        try
+        {
+            Path certFilePath = destinationPath.resolve(resourceName);
+
+            // ensure parent directory is created
+            Files.createDirectories(certFilePath.getParent());
+
+            try (InputStream inputStream = 
classLoader.getResourceAsStream(resourceName);
+                 OutputStream outputStream = 
Files.newOutputStream(certFilePath.toFile().toPath()))

Review Comment:
   `path.toFile().toPath()`..



##########
scripts/build-shaded-dtest-jar-local.sh:
##########
@@ -25,33 +25,33 @@ SCRIPT_DIR=$( dirname -- "$( readlink -f -- "$0"; )"; )
 CASSANDRA_VERSION=$(cat build.xml | grep 'property name="base.version"' | awk 
-F "\"" '{print $4}')
 GIT_HASH=$(git rev-parse --short HEAD)
 DTEST_ARTIFACT_ID=${ARTIFACT_NAME}-local
-DTEST_JAR_DIR="$(dirname ${SCRIPT_DIR}/)/dtest-jars"
+DTEST_JAR_DIR="$(dirname "${SCRIPT_DIR}/")/dtest-jars"
 
-echo $CASSANDRA_VERSION
-echo $GIT_HASH
-echo $DTEST_ARTIFACT_ID
+echo "${CASSANDRA_VERSION}"
+echo "${GIT_HASH}"
+echo "${DTEST_ARTIFACT_ID}"
 
 ant clean
 ant dtest-jar -Dno-checkstyle=true
 
 # Install the version that will be shaded
-mvn install:install-file               \
-   -Dfile=./build/dtest-${CASSANDRA_VERSION}.jar \
-   -DgroupId=org.apache.cassandra      \
-   -DartifactId=${DTEST_ARTIFACT_ID} \
-   -Dversion=${CASSANDRA_VERSION}-${GIT_HASH}         \
-   -Dpackaging=jar                     \
-   -DgeneratePom=true                  \
-   -DlocalRepositoryPath=${REPO_DIR}
+"${SCRIPT_DIR}/mvnw" install:install-file                            \
+                     -Dfile="./build/dtest-${CASSANDRA_VERSION}.jar" \
+                     -DgroupId=org.apache.cassandra                  \
+                     -DartifactId="${DTEST_ARTIFACT_ID}"             \
+                     -Dversion="${CASSANDRA_VERSION}-${GIT_HASH}"    \
+                     -Dpackaging=jar                                 \
+                     -DgeneratePom=true                              \
+                     -DlocalRepositoryPath="${REPO_DIR}"
 
 # Create shaded artifact
-mvn -f ${SCRIPT_DIR}/relocate-dtest-dependencies.pom package \
-    -Drevision=${CASSANDRA_VERSION} \
-    -DskipTests \
-    -Ddtest.version=${CASSANDRA_VERSION}-${GIT_HASH} \
-    -Dmaven.repo.local=${REPO_DIR} \
-    -DoutputFilePath=${DTEST_JAR_DIR}/dtest-${CASSANDRA_VERSION}.jar \
-    -Drelocation.prefix=shaded-${GIT_HASH} \
-    -nsu -U
+"${SCRIPT_DIR}/mvnw" --file "${SCRIPT_DIR}/relocate-dtest-dependencies.pom" 
package     \
+                     -Drevision="${CASSANDRA_VERSION}"                         
         \
+                     -DskipTests                                               
         \
+                     -Ddtest.version="${CASSANDRA_VERSION}-${GIT_HASH}"        
         \
+                     -Dmaven.repo.local="${REPO_DIR}"                          
         \
+                     
-DoutputFilePath="${DTEST_JAR_DIR}/dtest-${CASSANDRA_VERSION}.jar" \
+                     -Drelocation.prefix="shaded-${GIT_HASH}"                  
         \
+                     --no-snapshot-updates --update-snapshots

Review Comment:
   👍  on using the full option name



##########
scripts/build-shaded-dtest-jar-local.sh:
##########
@@ -25,33 +25,33 @@ SCRIPT_DIR=$( dirname -- "$( readlink -f -- "$0"; )"; )
 CASSANDRA_VERSION=$(cat build.xml | grep 'property name="base.version"' | awk 
-F "\"" '{print $4}')
 GIT_HASH=$(git rev-parse --short HEAD)
 DTEST_ARTIFACT_ID=${ARTIFACT_NAME}-local
-DTEST_JAR_DIR="$(dirname ${SCRIPT_DIR}/)/dtest-jars"
+DTEST_JAR_DIR="$(dirname "${SCRIPT_DIR}/")/dtest-jars"
 
-echo $CASSANDRA_VERSION
-echo $GIT_HASH
-echo $DTEST_ARTIFACT_ID
+echo "${CASSANDRA_VERSION}"
+echo "${GIT_HASH}"
+echo "${DTEST_ARTIFACT_ID}"
 
 ant clean
 ant dtest-jar -Dno-checkstyle=true
 
 # Install the version that will be shaded
-mvn install:install-file               \
-   -Dfile=./build/dtest-${CASSANDRA_VERSION}.jar \
-   -DgroupId=org.apache.cassandra      \
-   -DartifactId=${DTEST_ARTIFACT_ID} \
-   -Dversion=${CASSANDRA_VERSION}-${GIT_HASH}         \
-   -Dpackaging=jar                     \
-   -DgeneratePom=true                  \
-   -DlocalRepositoryPath=${REPO_DIR}
+"${SCRIPT_DIR}/mvnw" install:install-file                            \
+                     -Dfile="./build/dtest-${CASSANDRA_VERSION}.jar" \
+                     -DgroupId=org.apache.cassandra                  \
+                     -DartifactId="${DTEST_ARTIFACT_ID}"             \
+                     -Dversion="${CASSANDRA_VERSION}-${GIT_HASH}"    \
+                     -Dpackaging=jar                                 \
+                     -DgeneratePom=true                              \
+                     -DlocalRepositoryPath="${REPO_DIR}"
 
 # Create shaded artifact
-mvn -f ${SCRIPT_DIR}/relocate-dtest-dependencies.pom package \
-    -Drevision=${CASSANDRA_VERSION} \
-    -DskipTests \
-    -Ddtest.version=${CASSANDRA_VERSION}-${GIT_HASH} \
-    -Dmaven.repo.local=${REPO_DIR} \
-    -DoutputFilePath=${DTEST_JAR_DIR}/dtest-${CASSANDRA_VERSION}.jar \
-    -Drelocation.prefix=shaded-${GIT_HASH} \
-    -nsu -U
+"${SCRIPT_DIR}/mvnw" --file "${SCRIPT_DIR}/relocate-dtest-dependencies.pom" 
package     \
+                     -Drevision="${CASSANDRA_VERSION}"                         
         \
+                     -DskipTests                                               
         \
+                     -Ddtest.version="${CASSANDRA_VERSION}-${GIT_HASH}"        
         \
+                     -Dmaven.repo.local="${REPO_DIR}"                          
         \
+                     
-DoutputFilePath="${DTEST_JAR_DIR}/dtest-${CASSANDRA_VERSION}.jar" \
+                     -Drelocation.prefix="shaded-${GIT_HASH}"                  
         \
+                     --no-snapshot-updates --update-snapshots

Review Comment:
   👍  on using the full option name



##########
common/src/testFixtures/java/org/apache/cassandra/sidecar/common/ResourceUtils.java:
##########
@@ -0,0 +1,74 @@
+/*
+ * 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.
+ */
+
+package org.apache.cassandra.sidecar.common;
+
+import java.io.IOException;
+import java.io.InputStream;
+import java.io.OutputStream;
+import java.nio.file.Files;
+import java.nio.file.Path;
+
+import static org.assertj.core.api.Assertions.assertThat;
+import static org.assertj.core.api.Assertions.fail;
+
+/**
+ * A utilities class to handle resources for tests
+ */
+public final class ResourceUtils
+{
+    /**
+     * Writes a resource with {@code resourceName} loaded from the {@link 
ClassLoader classLoader} into the
+     * {@code destinationPath}
+     *
+     * @param classLoader     the class loader for the resource
+     * @param destinationPath the destination path to write the file
+     * @param resourceName    the name of the resource to be loaded
+     * @return the {@link Path} to the created resource
+     */
+    public static Path writeResourceToTempDir(ClassLoader classLoader, Path 
destinationPath, String resourceName)

Review Comment:
   The method name says "toTempDir", but it takes "destinationPath", which 
might not be located in a tempDir.



-- 
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: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to