Class ArtifactoryService
- All Implemented Interfaces:
org.gradle.api.services.BuildService<com.konfigyr.gradle.ArtifactoryService.Parameters>
BuildService for interacting with the Konfigyr Artifactory REST API.
Registered once, exactly, for the whole build via registerIfAbsent and shared
across every project and task that needs it, rather than one instance per project.
Builds one ArtifactoryClient per configured Registry, all sharing a single
ArtifactoryClientFactory, and therefore a single connection pool and a single
token/discovery cache. Every method that talks to a registry takes its name as the first
argument to select which of those clients to use, this service itself is keyed by the
registry name rather than bound to a single one.
- Since:
- 1.0.0
- See Also:
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptioncom.konfigyr.artifactory.ServiceReleaseCompletes the givenServiceRelease, promoting it to the service's currentManifeston the named registry.com.konfigyr.artifactory.ArtifactMetadatacreateArtifactMetadata(com.konfigyr.artifactory.Artifact artifact, File metadata) Creates anArtifactMetadatainstances for the givenArtifactby loading the serialized configuration metadata from the givenFile.List<com.konfigyr.artifactory.PropertyDescriptor> parsePropertyDescriptors(Iterable<? extends com.konfigyr.ArtifactMetadataResource> metadata, Iterable<? extends File> classpath) Attempts to parse the given collection ofArtifactMetadataResources into a list ofPropertyDescriptors.voidpublish(String registryName, com.konfigyr.artifactory.ArtifactMetadata metadata, Duration timeout, Duration interval) Starts the publication process for the givenArtifactMetadataagainst the named registry.com.konfigyr.artifactory.ArtifactMetadatareadArtifactMetadata(File metadata) Reads a singleArtifactMetadatapreviously written bywriteServiceArtifactMetadata(ArtifactMetadata, File).List<com.konfigyr.artifactory.ArtifactMetadata> readArtifactMetadata(File manifest, File directory) ReadsArtifactMetadatafrom the given directory that are present in the artifact manifest list.com.konfigyr.artifactory.ServiceReleaserelease(String registryName, String service, Collection<? extends com.konfigyr.artifactory.ServiceReleaseCandidate> candidates) Attempts to publish a newServiceReleasefor the given service, against the named registry.voidupload(String registryName, String service, com.konfigyr.artifactory.ServiceRelease release, com.konfigyr.artifactory.ArtifactMetadata metadata) Uploads the givenArtifactMetadatafor the givenServiceRelease, against the named registry.writeArtifactMetadata(com.konfigyr.artifactory.ArtifactMetadata metadata, File targetDirectory) Writes the givenArtifactMetadatato the given directory.voidwritePropertyDescriptorMetadata(Iterable<? extends com.konfigyr.ArtifactMetadataResource> metadata, Iterable<? extends File> classpath, File target) Generates and writesPropertyDescriptormetadata extracted from the given collection ofArtifactMetadataResources to the given targetFile.voidwriteServiceArtifactMetadata(com.konfigyr.artifactory.ArtifactMetadata metadata, File target) Writes the givenArtifactMetadatato the exact given target file, unlikewriteArtifactMetadata(ArtifactMetadata, File)which derives a filename from the artifact's coordinates inside a target directory.Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitMethods inherited from interface org.gradle.api.services.BuildService
getParameters
-
Constructor Details
-
ArtifactoryService
public ArtifactoryService()Creates a newArtifactoryServiceinstance.
-
-
Method Details
-
parsePropertyDescriptors
public List<com.konfigyr.artifactory.PropertyDescriptor> parsePropertyDescriptors(Iterable<? extends com.konfigyr.ArtifactMetadataResource> metadata, Iterable<? extends File> classpath) Attempts to parse the given collection ofArtifactMetadataResources into a list ofPropertyDescriptors.This method would create a
ClassLoaderthat can resolve the Java types to construct theJsonSchemafor each property using the specified collection of classpath files, usually jars.- Parameters:
metadata- the collection of Spring Boot configuration metadata resources, cannot be null.classpath- the collection of files used to create aClassLoader, cannot be null.- Returns:
- list of parsed
PropertyDescriptor, never null.
-
writePropertyDescriptorMetadata
public void writePropertyDescriptorMetadata(Iterable<? extends com.konfigyr.ArtifactMetadataResource> metadata, Iterable<? extends File> classpath, File target) Generates and writesPropertyDescriptormetadata extracted from the given collection ofArtifactMetadataResources to the given targetFile.This method would create a
ClassLoaderthat can resolve the Java types to construct theJsonSchemafor each property using the specified collection of classpath files, usually jars.- Parameters:
metadata- the collection of Spring Boot configuration metadata resources, cannot be null.classpath- the collection of files used to create aClassLoader, cannot be null.target- the target file where the metadata should be written, cannot be null.
-
createArtifactMetadata
public com.konfigyr.artifactory.ArtifactMetadata createArtifactMetadata(com.konfigyr.artifactory.Artifact artifact, File metadata) Creates anArtifactMetadatainstances for the givenArtifactby loading the serialized configuration metadata from the givenFile.- Parameters:
artifact- the artifact for which the metadata is created, cannot be null.metadata- the file containing the serialized configuration metadata, cannot be null.- Returns:
- the artifact metadata that should be published, never null.
-
writeArtifactMetadata
public String writeArtifactMetadata(com.konfigyr.artifactory.ArtifactMetadata metadata, File targetDirectory) Writes the givenArtifactMetadatato the given directory. The file that would be created, or updated, would be using the following file name format:${groupId}-${artifactId}-${version}.json- Parameters:
metadata- artifact metadata to be writtentargetDirectory- the target directory where the metadata should be written- Returns:
- the name of the file that was written, never null.
-
writeServiceArtifactMetadata
public void writeServiceArtifactMetadata(com.konfigyr.artifactory.ArtifactMetadata metadata, File target) Writes the givenArtifactMetadatato the exact given target file, unlikewriteArtifactMetadata(ArtifactMetadata, File)which derives a filename from the artifact's coordinates inside a target directory. Used for the metadata of the artifact that represents the service (project) itself, where there is always at most one file and no need to derive its name.- Parameters:
metadata- artifact metadata to be writtentarget- the exact file to write the metadata to
-
readArtifactMetadata
Reads a singleArtifactMetadatapreviously written bywriteServiceArtifactMetadata(ArtifactMetadata, File).- Parameters:
metadata- the exact file to read the metadata from, cannot be null.- Returns:
- the artifact metadata, never null.
-
readArtifactMetadata
public List<com.konfigyr.artifactory.ArtifactMetadata> readArtifactMetadata(File manifest, File directory) throws IOException ReadsArtifactMetadatafrom the given directory that are present in the artifact manifest list.This method should collect all the filenames in the artifact manifest file and then attempt to deserialize the metadata files from the given output directory.
- Parameters:
manifest- the manifest file that contains the list of metadata files to be uploadeddirectory- the directory where the metadata files are located- Returns:
- list of artifact metadata, never null.
- Throws:
IOException- if an I/O error occurs while reading the metadata files.
-
release
public com.konfigyr.artifactory.ServiceRelease release(String registryName, String service, Collection<? extends com.konfigyr.artifactory.ServiceReleaseCandidate> candidates) Attempts to publish a newServiceReleasefor the given service, against the named registry. The namespace owning the service is resolved server-side from the registry's authenticated access token, not asserted by the caller.- Parameters:
registryName- the registry to publish the release to, cannot be null.service- the service this release is opened for, cannot be null.candidates- the release candidate artifacts to be added to the new release, cannot be null.- Returns:
- the service release, never null
-
upload
public void upload(String registryName, String service, com.konfigyr.artifactory.ServiceRelease release, com.konfigyr.artifactory.ArtifactMetadata metadata) Uploads the givenArtifactMetadatafor the givenServiceRelease, against the named registry. Intended to be called from aServiceReleaseArtifactUploadAction, one artifact per work item.- Parameters:
registryName- the registry the release was opened against, cannot be null.service- the service this release belongs to, cannot be null.release- the service release this upload contributes to, cannot be null.metadata- the artifact metadata payload to upload, cannot be null.- Throws:
org.gradle.api.artifacts.PublishException- if the upload fails.
-
complete
public com.konfigyr.artifactory.ServiceRelease complete(String registryName, String service, com.konfigyr.artifactory.ServiceRelease release) Completes the givenServiceRelease, promoting it to the service's currentManifeston the named registry. EveryServiceReleaseEntryrequiring an upload must already have been uploaded viaupload(String, String, ServiceRelease, ArtifactMetadata)before this is called.- Parameters:
registryName- the registry the release was opened against, cannot be null.service- the service this release belongs to, cannot be null.release- the release to complete, cannot be null.- Returns:
- the completed release, never null.
- Throws:
org.gradle.api.artifacts.PublishException- if the release could not be completed.
-
publish
public void publish(String registryName, com.konfigyr.artifactory.ArtifactMetadata metadata, Duration timeout, Duration interval) Starts the publication process for the givenArtifactMetadataagainst the named registry. This method would post the metadata to the Konfigyr Artifactory and then poll the service until the publication state is either successfully published or failed.- Parameters:
registryName- the registry to publish the artifact metadata to, cannot be null.metadata- the artifact metadata to publish, cannot be null.timeout- the maximum time to wait for a successful poll of the release, cannot be null.interval- the time interval between consecutive polling attempts, cannot be null.- Throws:
org.gradle.api.artifacts.PublishException- if the poll process timed out or the artifact metadata upload fails.
-