Skip to content

Commit 1a681ec

Browse files
authored
Add quotes in the command-line arguments formatted by JavaPathType (apache#2505)
This commit contains also opportunistic documentation fixes.
1 parent 0c5b2ad commit 1a681ec

File tree

7 files changed

+86
-19
lines changed

7 files changed

+86
-19
lines changed

api/maven-api-core/src/main/java/org/apache/maven/api/Artifact.java

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@
3939
@Immutable
4040
public interface Artifact {
4141
/**
42-
* {@return a unique identifier for this artifact}
42+
* {@return a unique identifier for this artifact}.
4343
* The identifier is composed of groupId, artifactId, extension, classifier, and version.
4444
*
4545
* @see ArtifactCoordinates#getId()
@@ -58,23 +58,23 @@ default String key() {
5858
}
5959

6060
/**
61-
* {@return the group identifier of the artifact}
61+
* {@return the group identifier of the artifact}.
6262
*
6363
* @see ArtifactCoordinates#getGroupId()
6464
*/
6565
@Nonnull
6666
String getGroupId();
6767

6868
/**
69-
* {@return the identifier of the artifact}
69+
* {@return the identifier of the artifact}.
7070
*
7171
* @see ArtifactCoordinates#getArtifactId()
7272
*/
7373
@Nonnull
7474
String getArtifactId();
7575

7676
/**
77-
* {@return the version of the artifact}
77+
* {@return the version of the artifact}.
7878
* Contrarily to {@link ArtifactCoordinates},
7979
* each {@code Artifact} is associated to a specific version instead of a range of versions.
8080
* If the {@linkplain #getBaseVersion() base version} contains a meta-version such as {@code SNAPSHOT},
@@ -86,7 +86,7 @@ default String key() {
8686
Version getVersion();
8787

8888
/**
89-
* {@return the version or meta-version of the artifact}
89+
* {@return the version or meta-version of the artifact}.
9090
* A meta-version is a version suffixed with the {@code SNAPSHOT} keyword.
9191
* Meta-versions are represented in a base version by their symbols (e.g., {@code SNAPSHOT}),
9292
* while they are replaced by, for example, the actual timestamp in the {@linkplain #getVersion() version}.
@@ -122,7 +122,7 @@ default String key() {
122122
boolean isSnapshot();
123123

124124
/**
125-
* {@return coordinates with the same identifiers as this artifact}
125+
* {@return coordinates with the same identifiers as this artifact}.
126126
* This is a shortcut for {@code session.createArtifactCoordinates(artifact)}.
127127
*
128128
* @see org.apache.maven.api.Session#createArtifactCoordinates(Artifact)

api/maven-api-core/src/main/java/org/apache/maven/api/ArtifactCoordinates.java

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -33,13 +33,13 @@
3333
@Immutable
3434
public interface ArtifactCoordinates {
3535
/**
36-
* {@return the group identifier of the artifact}
36+
* {@return the group identifier of the artifact}.
3737
*/
3838
@Nonnull
3939
String getGroupId();
4040

4141
/**
42-
* {@return the identifier of the artifact}
42+
* {@return the identifier of the artifact}.
4343
*/
4444
@Nonnull
4545
String getArtifactId();
@@ -53,7 +53,7 @@ public interface ArtifactCoordinates {
5353
String getClassifier();
5454

5555
/**
56-
* {@return the specific version, range of versions or meta-version of the artifact}
56+
* {@return the specific version, range of versions, or meta-version of the artifact}.
5757
* A meta-version is a version suffixed with the {@code SNAPSHOT} keyword.
5858
*/
5959
@Nonnull
@@ -69,7 +69,7 @@ public interface ArtifactCoordinates {
6969
String getExtension();
7070

7171
/**
72-
* {@return a unique string representation identifying this artifact}
72+
* {@return a unique string identifying this artifact}.
7373
*
7474
* The default implementation returns a colon-separated list of group
7575
* identifier, artifact identifier, extension, classifier and version.

api/maven-api-core/src/main/java/org/apache/maven/api/Dependency.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@
3636
@Immutable
3737
public interface Dependency extends Artifact {
3838
/**
39-
* {@return the type of the dependency}
39+
* {@return the type of the dependency}.
4040
* A dependency can be a <abbr>JAR</abbr> file,
4141
* a modular-<abbr>JAR</abbr> if it is intended to be placed on the module path,
4242
* a <abbr>JAR</abbr> containing test classes, <i>etc.</i>
@@ -47,7 +47,7 @@ public interface Dependency extends Artifact {
4747
Type getType();
4848

4949
/**
50-
* {@return the time at which the dependency will be used}
50+
* {@return the time at which the dependency will be used}.
5151
* It may be, for example, at compile time only, at run time or at test time.
5252
*
5353
* @see DependencyCoordinates#getScope()
@@ -66,7 +66,7 @@ public interface Dependency extends Artifact {
6666
boolean isOptional();
6767

6868
/**
69-
* {@return coordinates with the same identifiers as this dependency}
69+
* {@return coordinates with the same identifiers as this dependency}.
7070
*/
7171
@Nonnull
7272
@Override

api/maven-api-core/src/main/java/org/apache/maven/api/DownloadedArtifact.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@
3333
public interface DownloadedArtifact extends Artifact {
3434

3535
/**
36-
* {@return the actual file that has been downloaded in the file system}
36+
* {@return the a path to the file that has been downloaded to the file system}.
3737
*/
3838
Path getPath();
3939
}

api/maven-api-core/src/main/java/org/apache/maven/api/JavaPathType.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -263,8 +263,8 @@ final String[] format(String moduleName, Iterable<? extends Path> paths) {
263263
if (option == null) {
264264
throw new IllegalStateException("No option is associated to this path type.");
265265
}
266-
String prefix = (moduleName == null) ? "" : (moduleName + '=');
267-
StringJoiner joiner = new StringJoiner(File.pathSeparator, prefix, "");
266+
String prefix = (moduleName == null) ? "\"" : (moduleName + "=\"");
267+
StringJoiner joiner = new StringJoiner(File.pathSeparator, prefix, "\"");
268268
joiner.setEmptyValue("");
269269
for (Path p : paths) {
270270
joiner.add(p.toString());

api/maven-api-core/src/main/java/org/apache/maven/api/SourceRoot.java

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -68,9 +68,8 @@ default Path directory() {
6868
* If no syntax is specified, or if its length is 1 character (interpreted as a Windows drive),
6969
* the default is a Maven-specific variation of the {@code "glob"} pattern.
7070
*
71-
* <p>
72-
* The default implementation returns an empty list, which means to apply a language-dependent pattern.
73-
* For example, for the Java language, the pattern includes all files with the {@code .java} suffix.
71+
* <p>The default implementation returns an empty list, which means to apply a language-dependent pattern.
72+
* For example, for the Java language, the pattern includes all files with the {@code .java} suffix.</p>
7473
*
7574
* @see java.nio.file.FileSystem#getPathMatcher(String)
7675
*/
Lines changed: 68 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,68 @@
1+
/*
2+
* Licensed to the Apache Software Foundation (ASF) under one
3+
* or more contributor license agreements. See the NOTICE file
4+
* distributed with this work for additional information
5+
* regarding copyright ownership. The ASF licenses this file
6+
* to you under the Apache License, Version 2.0 (the
7+
* "License"); you may not use this file except in compliance
8+
* with the License. You may obtain a copy of the License at
9+
*
10+
* http://www.apache.org/licenses/LICENSE-2.0
11+
*
12+
* Unless required by applicable law or agreed to in writing,
13+
* software distributed under the License is distributed on an
14+
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15+
* KIND, either express or implied. See the License for the
16+
* specific language governing permissions and limitations
17+
* under the License.
18+
*/
19+
package org.apache.maven.api;
20+
21+
import java.io.File;
22+
import java.nio.file.Path;
23+
import java.util.List;
24+
25+
import org.junit.jupiter.api.Test;
26+
27+
import static org.junit.jupiter.api.Assertions.assertEquals;
28+
29+
public class JavaPathTypeTest {
30+
/**
31+
* {@return dummy paths to use in tests}.
32+
*/
33+
private static List<Path> paths() {
34+
return List.of(Path.of("src", "foo.java"), Path.of("src", "bar.java"));
35+
}
36+
37+
/**
38+
* Converts paths from Unix style to platform-dependent style.
39+
*
40+
* @param expected the option value expected by the test
41+
* @return the expected value with separators of the host
42+
*/
43+
private static String toPlatformSpecific(String expected) {
44+
return expected.replace("/", File.separator).replace(":", File.pathSeparator);
45+
}
46+
47+
/**
48+
* Tests the formatting of an option without module name.
49+
*/
50+
@Test
51+
public void testOption() {
52+
String[] formatted = JavaPathType.MODULES.option(paths());
53+
assertEquals(2, formatted.length);
54+
assertEquals("--module-path", formatted[0]);
55+
assertEquals(toPlatformSpecific("\"src/foo.java:src/bar.java\""), formatted[1]);
56+
}
57+
58+
/**
59+
* Tests the formatting of an option with a module name.
60+
*/
61+
@Test
62+
public void testModularOption() {
63+
String[] formatted = JavaPathType.patchModule("my.module").option(paths());
64+
assertEquals(2, formatted.length);
65+
assertEquals("--patch-module", formatted[0]);
66+
assertEquals(toPlatformSpecific("my.module=\"src/foo.java:src/bar.java\""), formatted[1]);
67+
}
68+
}

0 commit comments

Comments
 (0)