summaryrefslogtreecommitdiffstats
path: root/bundle-plugin/src/main/java/com/yahoo/container/plugin/util/ProvidedArtifact.java
blob: dbc006a4cb524d59ca03558007150ba325bf6f6e (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
package com.yahoo.container.plugin.util;

import org.apache.maven.artifact.Artifact;

/**
 * Helper class to work with artifacts provided by the container.
 *
 * @author gjoranv
 */
public record ProvidedArtifact(String groupId, String artifactId, String version) {


    public ProvidedArtifact(Artifact artifact) {
        this(artifact.getGroupId(), artifact.getArtifactId(), artifact.getVersion());
    }

    public static ProvidedArtifact fromStringValue(String stringValue) {
        var parts = stringValue.split(":");
        if (parts.length != 3) {
            throw new IllegalArgumentException("Invalid artifact string: " + stringValue);
        }
        return new ProvidedArtifact(parts[0], parts[1], parts[2]);
    }

    public String stringValue() {
        return groupId + ":" + artifactId + ":" + version;
    }

}