-
Notifications
You must be signed in to change notification settings - Fork 8
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #1061 from eclipse-passage/1059
1059
- Loading branch information
Showing
4 changed files
with
193 additions
and
33 deletions.
There are no files selected for viewing
72 changes: 72 additions & 0 deletions
72
...pse.passage.lic.base/src/org/eclipse/passage/lic/internal/base/conditions/CalmedDown.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,72 @@ | ||
/******************************************************************************* | ||
* Copyright (c) 2022 ArSysOp | ||
* | ||
* This program and the accompanying materials are made available under the | ||
* terms of the Eclipse Public License 2.0 which is available at | ||
* https://www.eclipse.org/legal/epl-2.0/. | ||
* | ||
* SPDX-License-Identifier: EPL-2.0 | ||
* | ||
* Contributors: | ||
* ArSysOp - initial API and implementation | ||
*******************************************************************************/ | ||
package org.eclipse.passage.lic.internal.base.conditions; | ||
|
||
import java.util.ArrayList; | ||
import java.util.Collection; | ||
import java.util.List; | ||
import java.util.function.Supplier; | ||
import java.util.stream.Collectors; | ||
|
||
import org.eclipse.passage.lic.api.ServiceInvocationResult; | ||
import org.eclipse.passage.lic.api.conditions.ConditionPack; | ||
import org.eclipse.passage.lic.api.diagnostic.Trouble; | ||
import org.eclipse.passage.lic.api.diagnostic.TroubleCode; | ||
import org.eclipse.passage.lic.base.BaseServiceInvocationResult; | ||
import org.eclipse.passage.lic.base.diagnostic.BaseDiagnostic; | ||
import org.eclipse.passage.lic.base.diagnostic.code.ServiceFailedOnMorsel; | ||
|
||
/** | ||
* <p> | ||
* Collecting conditions from set of licenses, dedicated for different parties | ||
* (product or its libraries), is accompanied by multiple <i>cannot read this | ||
* license</i> denials, as practically every license is tried against every | ||
* party. | ||
* </p> | ||
* <p> | ||
* These denials are to be treated as <i>bearable</i> as do not contain signs of | ||
* failure. | ||
* </p> | ||
*/ | ||
final class CalmedDown implements Supplier<ServiceInvocationResult<Collection<ConditionPack>>> { | ||
|
||
private final ServiceInvocationResult<Collection<ConditionPack>> original; | ||
|
||
CalmedDown(ServiceInvocationResult<Collection<ConditionPack>> original) { | ||
this.original = original; | ||
} | ||
|
||
@Override | ||
public ServiceInvocationResult<Collection<ConditionPack>> get() { | ||
TroubleCode morsel = new ServiceFailedOnMorsel(); | ||
List<Trouble> calmed = original.diagnostic().severe().stream()// | ||
.filter(trouble -> trouble.code().equals(morsel))// | ||
.collect(Collectors.toList()); | ||
return new BaseServiceInvocationResult<>(// | ||
new BaseDiagnostic(severe(calmed), bearable(calmed)), // | ||
original.data()); | ||
} | ||
|
||
private List<Trouble> severe(List<Trouble> calmed) { | ||
List<Trouble> severe = new ArrayList<>(original.diagnostic().severe()); | ||
severe.removeAll(calmed); | ||
return severe; | ||
} | ||
|
||
private List<Trouble> bearable(List<Trouble> calmed) { | ||
List<Trouble> bearable = new ArrayList<>(original.diagnostic().bearable()); | ||
bearable.addAll(calmed); | ||
return bearable; | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
103 changes: 103 additions & 0 deletions
103
...ge.lic.jface/src/org/eclipse/passage/lic/internal/jface/dialogs/licensing/LicenseSet.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,103 @@ | ||
/******************************************************************************* | ||
* Copyright (c) 2022 ArSysOp | ||
* | ||
* This program and the accompanying materials are made available under the | ||
* terms of the Eclipse Public License 2.0 which is available at | ||
* https://www.eclipse.org/legal/epl-2.0/. | ||
* | ||
* SPDX-License-Identifier: EPL-2.0 | ||
* | ||
* Contributors: | ||
* ArSysOp - initial API and implementation | ||
*******************************************************************************/ | ||
package org.eclipse.passage.lic.internal.jface.dialogs.licensing; | ||
|
||
import java.io.IOException; | ||
import java.nio.file.Path; | ||
import java.util.List; | ||
import java.util.Optional; | ||
import java.util.function.Consumer; | ||
|
||
import org.eclipse.passage.lic.api.LicensedProduct; | ||
import org.eclipse.passage.lic.api.LicensingException; | ||
import org.eclipse.passage.lic.api.ServiceInvocationResult; | ||
import org.eclipse.passage.lic.api.conditions.mining.LicenseReadingService; | ||
import org.eclipse.passage.lic.api.conditions.mining.MiningEquipment; | ||
import org.eclipse.passage.lic.api.diagnostic.Diagnostic; | ||
import org.eclipse.passage.lic.base.conditions.mining.BaseLicenseReadingService; | ||
import org.eclipse.passage.lic.base.diagnostic.DiagnosticExplained; | ||
import org.eclipse.passage.lic.base.diagnostic.NoSevereErrors; | ||
import org.eclipse.passage.lic.base.io.ExternalLicense; | ||
import org.eclipse.passage.lic.equinox.SuppliedFrameworkAware; | ||
import org.eclipse.passage.lic.internal.base.access.Libraries; | ||
import org.eclipse.passage.lic.internal.jface.i18n.ImportLicenseDialogMessages; | ||
|
||
@SuppressWarnings("restriction") | ||
final class LicenseSet { | ||
private final LicensedProduct product; | ||
private final List<Path> licenses; | ||
private final Libraries libraries; | ||
private final Consumer<String> error; | ||
private final Optional<LicenseReadingService> service; | ||
|
||
LicenseSet(List<Path> licenses, LicensedProduct product, Libraries libraries, Consumer<String> error) { | ||
this.licenses = licenses; | ||
this.product = product; | ||
this.libraries = libraries; | ||
this.error = error; | ||
this.service = productLicenseReadingService(); | ||
} | ||
|
||
private Optional<LicenseReadingService> productLicenseReadingService() { | ||
return miner().map(miner -> new BaseLicenseReadingService(product, miner)); | ||
} | ||
|
||
private Optional<MiningEquipment> miner() { | ||
return new SuppliedFrameworkAware() | ||
.withFramework(framework -> framework.accessCycleConfiguration().miningEquipment()); | ||
} | ||
|
||
void install() { | ||
licenses.forEach(file -> doLicenseImport(file)); | ||
} | ||
|
||
private void doLicenseImport(Path license) { | ||
try { | ||
installLibraryLicense(license); | ||
installProductLicense(license); | ||
} catch (Exception e) { | ||
error.accept( | ||
String.format(ImportLicenseDialogMessages.ImportLicenseDialog_io_error, e.getLocalizedMessage())); | ||
} | ||
} | ||
|
||
private void installProductLicense(Path license) throws IOException { | ||
if (!productRelevantLicense(license)) { | ||
return; | ||
} | ||
new ExternalLicense(product).install(license); | ||
} | ||
|
||
private void installLibraryLicense(Path license) throws Exception { | ||
Optional<ServiceInvocationResult<Boolean>> result = libraries.installLicense(license); | ||
if (!result.isPresent()) { | ||
return; // no libraries | ||
} | ||
ServiceInvocationResult<Boolean> status = result.get(); | ||
Diagnostic diagnostic = status.diagnostic(); | ||
System.out.println("Import license license: " + license); //$NON-NLS-1$ | ||
System.out.println(new DiagnosticExplained(diagnostic).get()); | ||
if (!new NoSevereErrors().test(diagnostic)) { | ||
throw new LicensingException(String.format("License file [%s] failed to be imported", license)); //$NON-NLS-1$ | ||
} | ||
} | ||
|
||
private boolean productRelevantLicense(Path license) { | ||
if (!service.isPresent()) { | ||
return false; | ||
} | ||
return service.get().read(license).data()// | ||
.map(conditions -> !conditions.isEmpty())// | ||
.orElse(Boolean.FALSE); | ||
} | ||
} |