Java Code Examples for org.gradle.api.artifacts.ResolvedArtifact#getClassifier()

The following examples show how to use org.gradle.api.artifacts.ResolvedArtifact#getClassifier() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: CycloneDxTask.java    From cyclonedx-gradle-plugin with Apache License 2.0 6 votes vote down vote up
private String generatePackageUrl(final ResolvedArtifact artifact) {
    try {
        TreeMap<String, String> qualifiers = null;
        if (artifact.getType() != null || artifact.getClassifier() != null) {
            qualifiers = new TreeMap<>();
            if (artifact.getType() != null) {
                qualifiers.put("type", artifact.getType());
            }
            if (artifact.getClassifier() != null) {
                qualifiers.put("classifier", artifact.getClassifier());
            }
        }
        return new PackageURL(PackageURL.StandardTypes.MAVEN,
                artifact.getModuleVersion().getId().getGroup(),
                artifact.getModuleVersion().getId().getName(),
                artifact.getModuleVersion().getId().getVersion(),
                qualifiers, null).canonicalize();
    } catch (MalformedPackageURLException e) {
        getLogger().warn("An unexpected issue occurred attempting to create a PackageURL for "
                + artifact.getModuleVersion().getId().getGroup() + ":"
                + artifact.getModuleVersion().getId().getName()
                + ":" + artifact.getModuleVersion().getId().getVersion(), e);
    }
    return null;
}
 
Example 2
Source File: AtlasDepHelper.java    From atlas with Apache License 2.0 6 votes vote down vote up
@NonNull
public static String computeArtifactPath(@NonNull ModuleVersionIdentifier moduleVersion,
                                         @NonNull ResolvedArtifact artifact) {
    StringBuilder pathBuilder = new StringBuilder();

    pathBuilder.append(normalize(moduleVersion, moduleVersion.getGroup()))
        .append("/")
        .append(normalize(moduleVersion, moduleVersion.getName()))
        .append("/")
        .append(normalize(moduleVersion, moduleVersion.getVersion()));

    if (artifact.getClassifier() != null && !artifact.getClassifier().isEmpty()) {
        pathBuilder.append("/")
            .append(normalize(moduleVersion, artifact.getClassifier()));
    }

    return pathBuilder.toString();
}
 
Example 3
Source File: AtlasDepHelper.java    From atlas with Apache License 2.0 6 votes vote down vote up
@NonNull
public static String computeArtifactName(@NonNull ModuleVersionIdentifier moduleVersion,
                                          @NonNull ResolvedArtifact artifact) {
    StringBuilder nameBuilder = new StringBuilder();

    nameBuilder.append(moduleVersion.getGroup())
        .append(":")
        .append(moduleVersion.getName())
        .append(":")
        .append(moduleVersion.getVersion());

    if (artifact.getClassifier() != null && !artifact.getClassifier().isEmpty()) {
        nameBuilder.append(":").append(artifact.getClassifier());
    }

    return nameBuilder.toString();
}
 
Example 4
Source File: DependencyManager.java    From javaide with GNU General Public License v3.0 6 votes vote down vote up
@NonNull
private static String computeArtifactName(
        @NonNull ModuleVersionIdentifier moduleVersion,
        @NonNull ResolvedArtifact artifact) {
    StringBuilder nameBuilder = new StringBuilder();

    nameBuilder.append(moduleVersion.getGroup())
            .append(':')
            .append(moduleVersion.getName())
            .append(':')
            .append(moduleVersion.getVersion());

    if (artifact.getClassifier() != null && !artifact.getClassifier().isEmpty()) {
        nameBuilder.append(':').append(artifact.getClassifier());
    }

    return nameBuilder.toString();
}
 
Example 5
Source File: DependencyManager.java    From javaide with GNU General Public License v3.0 6 votes vote down vote up
@NonNull
private String computeArtifactPath(
        @NonNull ModuleVersionIdentifier moduleVersion,
        @NonNull ResolvedArtifact artifact) {
    StringBuilder pathBuilder = new StringBuilder();

    pathBuilder.append(normalize(logger, moduleVersion, moduleVersion.getGroup()))
            .append('/')
            .append(normalize(logger, moduleVersion, moduleVersion.getName()))
            .append('/')
            .append(normalize(logger, moduleVersion,
                    moduleVersion.getVersion()));

    if (artifact.getClassifier() != null && !artifact.getClassifier().isEmpty()) {
        pathBuilder.append('/').append(normalize(logger, moduleVersion,
                artifact.getClassifier()));
    }

    return pathBuilder.toString();
}
 
Example 6
Source File: GradleDependencyResolutionHelper.java    From thorntail with Apache License 2.0 6 votes vote down vote up
/**
 * Translate the given {@link ResolvedDependency resolved dependency} in to a {@link DependencyDescriptor} reference.
 *
 * @param scope      the scope to assign to the descriptor.
 * @param dependency the resolved dependency reference.
 * @return an instance of {@link DependencyDescriptor}.
 */
private static DependencyDescriptor asDescriptor(String scope, ResolvedDependency dependency) {

    Set<ResolvedArtifact> artifacts = dependency.getModuleArtifacts();

    // Let us use the first artifact's type for determining the type.
    // I am not sure under what circumstances, would we need to check for multiple artifacts.
    String type = "jar";
    String classifier = null;
    File file = null;

    if (!artifacts.isEmpty()) {
        ResolvedArtifact ra = artifacts.iterator().next();
        type = ra.getType();
        classifier = ra.getClassifier();
        file = ra.getFile();
    }
    return new DefaultDependencyDescriptor(scope, dependency.getModuleGroup(), dependency.getModuleName(),
                                           dependency.getModuleVersion(), type, classifier, file);
}
 
Example 7
Source File: AppModelGradleResolver.java    From quarkus with Apache License 2.0 5 votes vote down vote up
public static AppArtifact toAppArtifact(ResolvedArtifact a) {
    final String[] split = a.getModuleVersion().toString().split(":");
    final AppArtifact appArtifact = new AppArtifact(split[0], split[1], a.getClassifier(), a.getType(),
            split.length > 2 ? split[2] : null);
    if (a.getFile().exists()) {
        appArtifact.setPath(a.getFile().toPath());
    }
    return appArtifact;
}
 
Example 8
Source File: MavenCoordinatesImpl.java    From javaide with GNU General Public License v3.0 5 votes vote down vote up
public MavenCoordinatesImpl(@NonNull ResolvedArtifact resolvedArtifact) {
    this(
            resolvedArtifact.getModuleVersion().getId().getGroup(),
            resolvedArtifact.getModuleVersion().getId().getName(),
            resolvedArtifact.getModuleVersion().getId().getVersion(),
            resolvedArtifact.getExtension(),
            resolvedArtifact.getClassifier());
}
 
Example 9
Source File: DependencyConvertUtils.java    From atlas with Apache License 2.0 4 votes vote down vote up
public static MavenCoordinatesImpl convert(ResolvedArtifact artifact,Type type) {
    return new MavenCoordinatesImpl(artifact.getModuleVersion().getId().getGroup(),
                                    artifact.getModuleVersion().getId().getName(),
                                    artifact.getModuleVersion().getId().getVersion(),type.getType(),
                                    artifact.getClassifier());
}
 
Example 10
Source File: GradleDependencyResolutionHelper.java    From thorntail with Apache License 2.0 2 votes vote down vote up
/**
 * Translate the given {@link ResolvedArtifact resolved artifact} in to a {@link DependencyDescriptor} reference.
 *
 * @param scope    the scope to assign to the descriptor.
 * @param artifact the resolved artifact reference.
 * @return an instance of {@link DependencyDescriptor}.
 */
private static DependencyDescriptor asDescriptor(String scope, ResolvedArtifact artifact) {
    ModuleVersionIdentifier id = artifact.getModuleVersion().getId();
    return new DefaultDependencyDescriptor(scope, id.getGroup(), id.getName(), id.getVersion(),
                                           artifact.getType(), artifact.getClassifier(), artifact.getFile());
}