[GitHub] [maven] gnodet commented on a diff in pull request #884: Add M4 Transport API

2022-11-28 Thread GitBox


gnodet commented on code in PR #884:
URL: https://github.com/apache/maven/pull/884#discussion_r1033666376


##
api/maven-api-core/src/main/java/org/apache/maven/api/services/Transport.java:
##
@@ -0,0 +1,114 @@
+/*
+ * 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.maven.api.services;
+
+import java.io.Closeable;
+import java.net.URI;
+import java.nio.charset.Charset;
+import java.nio.charset.StandardCharsets;
+import java.nio.file.Path;
+import org.apache.maven.api.RemoteRepository;
+import org.apache.maven.api.annotations.Consumer;
+import org.apache.maven.api.annotations.Experimental;
+import org.apache.maven.api.annotations.Nonnull;
+import org.apache.maven.api.annotations.Nullable;
+
+/**
+ * Transport for specified remote repository (using provided remote repository 
base URI as root). Must be treated as a
+ * resource, best in try-with-resource block.
+ *
+ * @since 4.0
+ */
+@Experimental
+@Consumer
+public interface Transport extends Closeable {
+/**
+ * GETs the source URI content into target (does not have to exist, or 
will be overwritten if exist). The
+ * source MUST BE relative from the {@link RemoteRepository#getUrl()} root.
+ *
+ * @return {@code true} if operation succeeded, {@code false} if source 
does not exist.
+ * @throws RuntimeException If failed (and not due source not exists).
+ */
+boolean get(@Nonnull URI relativeSource, @Nonnull Path target);
+
+/**
+ * GETs the source URI content as byte array. The source MUST BE relative 
from the {@link RemoteRepository#getUrl()}
+ * root.
+ *
+ * @return the byte array if operation succeeded, {@code null} if source 
does not exist.
+ * @throws RuntimeException If failed (and not due source not exists).
+ */
+@Nullable
+byte[] getBytes(@Nonnull URI relativeSource);
+
+/**
+ * GETs the source URI content as string. The source MUST BE relative from 
the {@link RemoteRepository#getUrl()}
+ * root.
+ *
+ * @return the string if operation succeeded, {@code null} if source does 
not exist.
+ * @throws RuntimeException If failed (and not due source not exists).
+ */
+@Nullable
+String getString(@Nonnull URI relativeSource, @Nonnull Charset charset);
+
+/**
+ * GETs the source URI content as string using UTF8 charset. The source 
MUST BE relative from the 
+ * {@link RemoteRepository#getUrl()} root.
+ *
+ * @return the string if operation succeeded, {@code null} if source does 
not exist.
+ * @throws RuntimeException If failed (and not due source not exists).
+ */
+default String getString(@Nonnull URI relativeSource) {

Review Comment:
   `@Nullable` ?



-- 
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-unsubscr...@maven.apache.org

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



[GitHub] [maven] gnodet commented on a diff in pull request #884: Add M4 Transport API

2022-11-28 Thread GitBox


gnodet commented on code in PR #884:
URL: https://github.com/apache/maven/pull/884#discussion_r1033659141


##
api/maven-api-core/src/main/java/org/apache/maven/api/services/Transport.java:
##
@@ -0,0 +1,91 @@
+/*
+ * 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.maven.api.services;
+
+import java.io.Closeable;
+import java.net.URI;
+import java.nio.charset.Charset;
+import java.nio.file.Path;
+import org.apache.maven.api.RemoteRepository;
+import org.apache.maven.api.annotations.Consumer;
+import org.apache.maven.api.annotations.Experimental;
+import org.apache.maven.api.annotations.Nullable;
+
+/**
+ * Transport for specified remote repository (using provided remote repository 
base URI as root). Must be treated as a
+ * resource, best in try-with-resource block.
+ *
+ * @since 4.0
+ */
+@Experimental
+@Consumer
+public interface Transport extends Closeable {
+/**
+ * GETs the source URI content into target (does not have to exist, or 
will be overwritten if exist). The
+ * source MUST BE relative from the {@link RemoteRepository#getUrl()} root.
+ *
+ * @return {@code true} if operation succeeded, {@code false} if source 
does not exist.
+ * @throws RuntimeException If failed (and not due source not exists).
+ */
+boolean get(URI relativeSource, Path target);
+
+/**
+ * GETs the source URI content into target consumer. The
+ * source MUST BE relative from the {@link RemoteRepository#getUrl()} root.
+ *
+ * @return the byte array if operation succeeded, {@code null} if source 
does not exist.
+ * @throws RuntimeException If failed (and not due source not exists).
+ */
+@Nullable
+byte[] getBytes(URI relativeSource);
+
+/**
+ * GETs the source URI content as string. The
+ * source MUST BE relative from the {@link RemoteRepository#getUrl()} root.
+ *
+ * @return the string if operation succeeded, {@code null} if source does 
not exist.
+ * @throws RuntimeException If failed (and not due source not exists).
+ */
+@Nullable
+String getString(URI relativeSource, Charset charset);
+
+/**
+ * PUTs the source file (must exist as file) to target URI. The target 
MUST BE relative from the
+ * {@link RemoteRepository#getUrl()} root.
+ *
+ * @throws RuntimeException If PUT fails for any reason.
+ */
+void put(Path source, URI relativeTarget);
+
+/**
+ * PUTs the source byte array to target URI. The target MUST BE relative 
from the
+ * {@link RemoteRepository#getUrl()} root.
+ *
+ * @throws RuntimeException If PUT fails for any reason.
+ */
+void putBytes(byte[] source, URI relativeTarget);
+
+/**
+ * PUTs the source string to target URI. The target MUST BE relative from 
the
+ * {@link RemoteRepository#getUrl()} root.
+ *
+ * @throws RuntimeException If PUT fails for any reason.
+ */
+void putString(String source, Charset charset, URI relativeTarget);

Review Comment:
   May I ask for a default:
   ```
   default void putString(String source, URI relativeTarget) {
   putString(source, StandardCharsets.UTF_8, relativeTarget);
   }
   ```



##
api/maven-api-core/src/main/java/org/apache/maven/api/services/Transport.java:
##
@@ -0,0 +1,91 @@
+/*
+ * 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.maven.api.services;
+
+import java.io.Closeable;

[GitHub] [maven] gnodet commented on a diff in pull request #884: Add M4 Transport API

2022-11-28 Thread GitBox


gnodet commented on code in PR #884:
URL: https://github.com/apache/maven/pull/884#discussion_r1033568463


##
api/maven-api-core/src/main/java/org/apache/maven/api/services/Transport.java:
##
@@ -0,0 +1,50 @@
+/*
+ * 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.maven.api.services;
+
+import java.net.URI;
+import java.nio.file.Path;
+
+import org.apache.maven.api.RemoteRepository;
+import org.apache.maven.api.annotations.Consumer;
+import org.apache.maven.api.annotations.Experimental;
+
+/**
+ * @since 4.0
+ */
+@Experimental
+@Consumer
+public interface Transport
+{

Review Comment:
   I would still add helpers for transferring the data as `byte[]` and 
`String`.  Even the `java.nio.Files` api now as those !



-- 
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-unsubscr...@maven.apache.org

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