Skip to content

Commit

Permalink
Implemented license support for Nuget Test Artifact generation
Browse files Browse the repository at this point in the history
  • Loading branch information
anki2189 committed Dec 9, 2020
1 parent e77653d commit 954897c
Show file tree
Hide file tree
Showing 3 changed files with 40 additions and 12 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
import java.util.zip.ZipOutputStream;

import org.apache.commons.codec.digest.MessageDigestAlgorithms;
import org.apache.commons.lang3.ArrayUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

Expand Down Expand Up @@ -60,6 +61,8 @@ public class NugetArtifactGenerator

private Path basePath;

private LicenseConfiguration[] licenses;

public NugetArtifactGenerator(String baseDir)
{
this(Paths.get(baseDir));
Expand All @@ -70,6 +73,17 @@ public NugetArtifactGenerator(Path basePath)
this.basePath = basePath.normalize().toAbsolutePath();
}

public String getBasedir()
{
return basePath.normalize().toAbsolutePath().toString();
}

@Override
public void setLicenses(LicenseConfiguration[] licenses)
{
this.licenses = licenses;
}

@Override
public Path generateArtifact(String id,
String version,
Expand Down Expand Up @@ -198,12 +212,26 @@ public void createArchive(Nuspec nuspec,

createContentType(zos);
createRels(id, zos);
copyLicenseFiles(zos);
}
generateChecksum(packagePath, layoutOutputStream);
}
}
}

private void copyLicenseFiles(ZipOutputStream zos)
throws IOException
{
if (!ArrayUtils.isEmpty(licenses))
{
LicenseConfiguration license = licenses[0];
ZipEntry zipEntry = new ZipEntry(license.destinationPath());
zos.putNextEntry(zipEntry);

copyLicenseFile(license.license().getLicenseFileSourcePath(), zos);
}
}

private void createRels(String id,
ZipOutputStream zos)
throws IOException
Expand Down Expand Up @@ -295,8 +323,13 @@ private Nuspec generateNuspec(String id,
metadata.version = version;
metadata.authors = "carlspring";
metadata.owners = "Carlspring Consulting & Development Ltd.";
metadata.licenseUrl = "https://www.apache.org/licenses/LICENSE-2.0";
metadata.description = "Strongbox Nuget package for tests";
String licenseUrl = "https://www.apache.org/licenses/LICENSE-2.0";
if (!ArrayUtils.isEmpty(licenses))
{
licenseUrl = licenses[0].license().getUrl();
}
metadata.licenseUrl = licenseUrl;

if (dependencyList != null)
{
Expand Down Expand Up @@ -357,15 +390,4 @@ private void generateChecksum(Path artifactPath,
MessageDigestUtils.writeChecksum(artifactPath, ".sha512", sha512);
}

public String getBasedir()
{
return basePath.normalize().toAbsolutePath().toString();
}

@Override
public void setLicenses(LicenseConfiguration[] licenses)
{
// set Nuget licenses
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ public Path generateArtifact(NugetArtifactGenerator artifactGenerator,
throws IOException
{
NugetArtifactCoordinates coordinates = new NugetArtifactCoordinates(id, version);
setLicenses(artifactGenerator, attributesMap);

return artifactGenerator.generateArtifact(coordinates, bytesSize);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -56,4 +56,9 @@
*/
@AliasFor(annotation = TestArtifact.class)
long bytesSize() default 1000000;

/**
* License Configuration for test artifact
*/
LicenseConfiguration[] licenses() default {};
}

0 comments on commit 954897c

Please sign in to comment.