Skip to content

Commit

Permalink
Merge pull request #478 from spyrkob/duplicated_licenses
Browse files Browse the repository at this point in the history
License agreement is shown duplicated if FPL is duplicated
  • Loading branch information
spyrkob authored Oct 12, 2023
2 parents 28f23c3 + 0be10e8 commit 76e7b0f
Show file tree
Hide file tree
Showing 4 changed files with 12 additions and 11 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -200,7 +200,7 @@ public List<License> getPendingLicenses(ProvisioningConfig provisioningConfig, L

private List<License> getPendingLicenses(ProvisioningConfig provisioningConfig, GalleonFeaturePackAnalyzer exporter) throws OperationException {
try {
final List<String> featurePacks = exporter.getFeaturePacks(provisioningConfig);
final Set<String> featurePacks = exporter.getFeaturePacks(provisioningConfig);
return licenseManager.getLicenses(featurePacks);
} catch (MavenUniverseException e) {
if (e.getCause() instanceof org.eclipse.aether.resolution.ArtifactResolutionException) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,6 @@
import java.io.IOException;
import java.nio.file.Files;
import java.nio.file.Path;
import java.util.ArrayList;
import java.util.HashSet;
import java.util.List;
import java.util.Set;
Expand Down Expand Up @@ -68,7 +67,7 @@ public GalleonFeaturePackAnalyzer(List<Channel> channels, MavenSessionManager ma
public void cacheGalleonArtifacts(Path installedDir, ProvisioningConfig provisioningConfig) throws Exception {
// no data will be actually written out, but we need a path to init the Galleon
final Path tempInstallationPath = Files.createTempDirectory("temp");
final List<String> fps = new ArrayList<>();
final Set<String> fps = new HashSet<>();

GalleonEnvironment galleonEnv = null;
ProvisioningLayoutFactory layoutFactory = null;
Expand Down Expand Up @@ -151,10 +150,10 @@ private void updateHashes(Path installedDir) throws IOException {
* @throws ProvisioningException
* @throws OperationException
*/
public List<String> getFeaturePacks(ProvisioningConfig provisioningConfig) throws IOException, ProvisioningException, OperationException {
public Set<String> getFeaturePacks(ProvisioningConfig provisioningConfig) throws IOException, ProvisioningException, OperationException {
// no data will be actually written out, but we need a path to init the Galleon
final Path tempInstallationPath = Files.createTempDirectory("temp");
final List<String> fps = new ArrayList<>();
final Set<String> fps = new HashSet<>();
try (GalleonEnvironment galleonEnv = galleonEnvWithFpMapper(tempInstallationPath, fps)) {
final ProvisioningManager pm = galleonEnv.getProvisioningManager();

Expand All @@ -166,7 +165,7 @@ public List<String> getFeaturePacks(ProvisioningConfig provisioningConfig) throw
}
}

private GalleonEnvironment galleonEnvWithFpMapper(Path tempInstallationPath, List<String> fps) throws ProvisioningException, OperationException {
private GalleonEnvironment galleonEnvWithFpMapper(Path tempInstallationPath, Set<String> fps) throws ProvisioningException, OperationException {
final GalleonEnvironment galleonEnv = GalleonEnvironment
.builder(tempInstallationPath, channels, mavenSessionManager)
.setConsole(null)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@
import java.util.Locale;
import java.util.Objects;
import java.util.Properties;
import java.util.Set;
import java.util.stream.Collectors;

/**
Expand Down Expand Up @@ -81,7 +82,7 @@ public LicenseManager() {
* @param fpls - list of Maven coordinates (groupId:artifactId) of installed Feature Packs
* @return list of required {@License}s. Empty list if no licenses are required.
*/
public List<License> getLicenses(List<String> fpls) {
public List<License> getLicenses(Set<String> fpls) {
Objects.requireNonNull(fpls);

return fpls.stream()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@
import java.util.Collections;
import java.util.List;
import java.util.Properties;
import java.util.Set;

import static org.assertj.core.api.Assertions.assertThat;
import static org.wildfly.prospero.licenses.LicenseManager.LICENSES_FOLDER;
Expand Down Expand Up @@ -58,28 +59,28 @@ public void setUp() throws Exception {

@Test
public void noLicenseFileDoesNothing() throws Exception {
assertThat(new LicenseManager(null).getLicenses(List.of(A_FEATURE_PACK)))
assertThat(new LicenseManager(null).getLicenses(Set.of(A_FEATURE_PACK)))
.isEmpty();
}

@Test
public void emptyListIfNoLicensesMatched() throws Exception {
License.writeLicenses(List.of(LICENSE_ONE), licenseFile);
assertThat(new LicenseManager(licenseFile.toURI().toURL()).getLicenses(List.of(UNKNOWN_FEATURE_PACK)))
assertThat(new LicenseManager(licenseFile.toURI().toURL()).getLicenses(Set.of(UNKNOWN_FEATURE_PACK)))
.isEmpty();
}

@Test
public void matchesLicenseByFpGav() throws Exception {
License.writeLicenses(List.of(LICENSE_ONE), licenseFile);
assertThat(new LicenseManager(licenseFile.toURI().toURL()).getLicenses(List.of(A_FEATURE_PACK)))
assertThat(new LicenseManager(licenseFile.toURI().toURL()).getLicenses(Set.of(A_FEATURE_PACK)))
.contains(LICENSE_ONE);
}

@Test
public void matchesMultipleLicenseByFpGav() throws Exception {
License.writeLicenses(List.of(LICENSE_ONE, LICENSE_TWO), licenseFile);
assertThat(new LicenseManager(licenseFile.toURI().toURL()).getLicenses(List.of(A_FEATURE_PACK)))
assertThat(new LicenseManager(licenseFile.toURI().toURL()).getLicenses(Set.of(A_FEATURE_PACK)))
.contains(LICENSE_ONE, LICENSE_TWO);
}

Expand Down

0 comments on commit 76e7b0f

Please sign in to comment.