Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[MRESOLVER-470] Prepare for new changes regarding Artifact properties/scopes #411

Merged
merged 2 commits into from
Jan 24, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,10 @@ public final class ArtifactProperties {
/**
* A boolean flag indicating whether the artifact is meant to be used for the compile/runtime/test build path of a
* consumer project.
* <p>
* Note: This property is about "build path", whatever it means in the scope of the consumer project. It is NOT
* about Java classpath or anything alike. How artifact is being consumed depends heavily on the consumer project.
* Resolver is and will remain agnostic of consumer project use cases.
*/
public static final String CONSTITUTES_BUILD_PATH = "constitutesBuildPath";

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ public final class DefaultArtifact extends AbstractArtifact {
* format.
*/
public DefaultArtifact(String coords) {
this(coords, Collections.<String, String>emptyMap());
this(coords, null, null);
}

/**
Expand All @@ -73,18 +73,51 @@ public DefaultArtifact(String coords) {
* format.
*/
public DefaultArtifact(String coords, Map<String, String> properties) {
this(coords, properties, null);
}

/**
* Creates a new artifact with the specified coordinates and type. If not specified in the artifact coordinates,
* the artifact's extension defaults to type extension (or "jar" if type is {@code null}) and
* classifier to type extension (or "" if type is {@code null}).
*
* @param coords The artifact coordinates in the format
* {@code <groupId>:<artifactId>[:<extension>[:<classifier>]]:<version>}, must not be {@code null}.
* @param type The artifact type, may be {@code null}.
*
* @throws IllegalArgumentException If the artifact coordinates found in {@code coords} do not match the expected
* format.
*/
public DefaultArtifact(String coords, ArtifactType type) {
this(coords, null, type);
}

/**
* Creates a new artifact with the specified coordinates, properties and type. If not specified in the artifact
* coordinates, the artifact's extension defaults to type extension (or "jar" if type is {@code null}) and
* classifier to type extension (or "" if type is {@code null}).
*
* @param coords The artifact coordinates in the format
* {@code <groupId>:<artifactId>[:<extension>[:<classifier>]]:<version>}, must not be {@code null}.
* @param properties The artifact properties, may be {@code null}.
* @param type The artifact type, may be {@code null}.
*
* @throws IllegalArgumentException If the artifact coordinates found in {@code coords} do not match the expected
* format.
*/
public DefaultArtifact(String coords, Map<String, String> properties, ArtifactType type) {
Matcher m = COORDINATE_PATTERN.matcher(coords);
if (!m.matches()) {
throw new IllegalArgumentException("Bad artifact coordinates " + coords
+ ", expected format is <groupId>:<artifactId>[:<extension>[:<classifier>]]:<version>");
}
groupId = m.group(1);
artifactId = m.group(2);
extension = get(m.group(4), "jar");
classifier = get(m.group(6), "");
version = m.group(7);
file = null;
this.properties = copyProperties(properties);
extension = get(m.group(4), type == null ? "jar" : type.getExtension());
classifier = get(m.group(6), type == null ? "" : type.getClassifier());
this.version = emptify(m.group(7));
this.file = null;
this.properties = merge(properties, (type != null) ? type.getProperties() : null);
}

private static String get(String value, String defaultValue) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@ public interface DependencyNode {

/**
* Gets the artifact associated with this node. If this node is associated with a dependency, this is equivalent to
* {@code getDependency().getArtifact()}. Otherwise the artifact merely provides a label for this node in which case
* {@code getDependency().getArtifact()}. Otherwise, the artifact merely provides a label for this node in which case
* the artifact must not be subjected to dependency collection/resolution.
*
* @return The associated artifact or {@code null} if none.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,10 @@
* is not used in Resolver and is kept only for backward compatibility reasons.
*
* @see AbstractDependencyNodeConsumerVisitor
*
* @deprecated See {@link AbstractDependencyNodeConsumerVisitor} that is more versatile.
*/
@Deprecated
abstract class AbstractDepthFirstNodeListGenerator implements DependencyVisitor {

private final Map<DependencyNode, Object> visitedNodes;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,8 @@
* free of duplicates.
*
* @since 2.0.0
*
* @see NodeListGenerator
*/
public final class LevelOrderDependencyNodeConsumerVisitor extends AbstractDependencyNodeConsumerVisitor {

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,10 @@
* offers several transformations, that are handy.
*
* @since 2.0.0
*
* @see PreorderDependencyNodeConsumerVisitor
* @see PostorderDependencyNodeConsumerVisitor
* @see LevelOrderDependencyNodeConsumerVisitor
*/
public final class NodeListGenerator implements Consumer<DependencyNode> {

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,8 @@
* free of duplicates.
*
* @since 2.0.0
*
* @see NodeListGenerator
*/
public final class PostorderDependencyNodeConsumerVisitor extends AbstractDependencyNodeConsumerVisitor {

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,10 @@
*
* @see PostorderDependencyNodeConsumerVisitor
* @see NodeListGenerator
*
* @deprecated See {@link PostorderDependencyNodeConsumerVisitor} that is more versatile.
*/
@Deprecated
public final class PostorderNodeListGenerator extends AbstractDepthFirstNodeListGenerator {

private final Stack<Boolean> visits;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,8 @@
* free of duplicates.
*
* @since 2.0.0
*
* @see NodeListGenerator
*/
public final class PreorderDependencyNodeConsumerVisitor extends AbstractDependencyNodeConsumerVisitor {

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,10 @@
*
* @see PreorderDependencyNodeConsumerVisitor
* @see NodeListGenerator
*
* @deprecated See {@link PreorderDependencyNodeConsumerVisitor} that is more versatile.
*/
@Deprecated
public final class PreorderNodeListGenerator extends AbstractDepthFirstNodeListGenerator {

/**
Expand Down