Skip to content

Commit

Permalink
Merge pull request #1057 from eclipse-passage/1054
Browse files Browse the repository at this point in the history
1054  LIC: library-licensed-separately: support license import
  • Loading branch information
eparovyshnaya authored Feb 28, 2022
2 parents ce7edd7 + a37fc2b commit a13acc8
Show file tree
Hide file tree
Showing 28 changed files with 749 additions and 112 deletions.
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*******************************************************************************
* Copyright (c) 2021 ArSysOp
* Copyright (c) 2021, 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
Expand All @@ -16,6 +16,19 @@

public interface AgreementToAccept {

/**
* <p>
* Agreement can be demanded for acceptance right where a licensing Requirement
* for a feature is declared Thus agreement is bound to a physical Requirement.
* </p>
* <p>
* It if also possible to demand an agreement acceptance in the body of a
* license. In this case an instance of {@linkplain AgreementAcceptanceDemand}
* is instantiated to represent a requirement under this demand. It references a
* product-representing-feature (it's id and name correspond to the ones of the
* product).
* </p>
*/
Requirement origin();

ResolvedAgreement definition();
Expand Down
2 changes: 1 addition & 1 deletion bundles/org.eclipse.passage.lic.base/schema/library.exsd
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@

</documentation>
<appinfo>
<meta.attribute kind="java" basedOn=":org.eclipse.passage.lic.internal.base.access.DelegatedLicensingService"/>
<meta.attribute kind="java" basedOn=":org.eclipse.passage.lic.internal.base.access.Library"/>
</appinfo>
</annotation>
</attribute>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*******************************************************************************
* Copyright (c) 2020, 2021 ArSysOp
* Copyright (c) 2020, 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
Expand Down Expand Up @@ -94,7 +94,7 @@ private ExaminationCertificate agreementsBasedCertificate() {
private AgreementToAccept agreementToAccept(GlobalAgreement agreement) {
ResolvedAgreement definition = new MinedAgreement(agreement);
return new BaseAgreementToAccept(//
new AgreementAcceptanceDemand(definition), //
new AgreementAcceptanceDemand(definition, product), //
definition, //
acceptanceState(agreement));
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*******************************************************************************
* Copyright (c) 2021 ArSysOp
* Copyright (c) 2021, 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
Expand All @@ -15,6 +15,7 @@
import java.util.Collections;
import java.util.List;

import org.eclipse.passage.lic.api.LicensedProduct;
import org.eclipse.passage.lic.api.agreements.ResolvedAgreement;
import org.eclipse.passage.lic.api.requirements.Feature;
import org.eclipse.passage.lic.api.requirements.Requirement;
Expand All @@ -25,8 +26,8 @@ public final class AgreementAcceptanceDemand implements Requirement {
private final Feature feature;
private final List<ResolvedAgreement> agreement;

public AgreementAcceptanceDemand(ResolvedAgreement agreement) {
this.feature = new GlobalAgreementSupportFeature().get();
public AgreementAcceptanceDemand(ResolvedAgreement agreement, LicensedProduct product) {
this.feature = new GlobalAgreementSupportFeature(product).get();
this.agreement = Collections.singletonList(agreement);
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*******************************************************************************
* Copyright (c) 2021 ArSysOp
* Copyright (c) 2021, 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
Expand All @@ -14,16 +14,23 @@

import java.util.function.Supplier;

import org.eclipse.passage.lic.api.LicensedProduct;
import org.eclipse.passage.lic.api.requirements.Feature;
import org.eclipse.passage.lic.base.requirements.BaseFeature;

public final class GlobalAgreementSupportFeature implements Supplier<Feature> {

private final LicensedProduct product;

public GlobalAgreementSupportFeature(LicensedProduct product) {
this.product = product;
}

@Override
public Feature get() {
return new BaseFeature(//
"passage.global-agreement-support.feature", //$NON-NLS-1$
"1.0.0", //$NON-NLS-1$
product.identifier(), //
product.version(), //
"Global Agreements Support by Passage", //$NON-NLS-1$
"Eclipse Passage Runtime" //$NON-NLS-1$
);
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
/*******************************************************************************
* 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.base.diagnostic.code;

import org.eclipse.passage.lic.api.diagnostic.TroubleCode;
import org.eclipse.passage.lic.internal.base.i18n.DiagnosticCodeMessages;

/**
*
* @since 2.3
*/
public final class ForeignLicense extends TroubleCode {

public ForeignLicense() {
super(413, DiagnosticCodeMessages.getString("ForeignLicense.explanation")); //$NON-NLS-1$
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,8 @@
* <li>411 - no data of a particular type found (info)</li>
* <li>412 - a licensing agreement has not been actively accepted by the product
* user</li>
* <li>413 - foreign license: suggested license file cannot be read with the
* product/library key (bearable)
* </ul>
* </li>
* <li>5xx - reserved</li>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*******************************************************************************
* Copyright (c) 2020, 2021 ArSysOp
* Copyright (c) 2020, 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
Expand All @@ -12,6 +12,7 @@
*******************************************************************************/
package org.eclipse.passage.lic.base.io;

import java.io.File;
import java.nio.file.Path;
import java.util.function.Supplier;

Expand All @@ -24,6 +25,13 @@ public final boolean ends(Path path) {
return path.getFileName().toString().endsWith(get());
}

/**
* @since 2.3
*/
public final boolean ends(File file) {
return file.getName().endsWith(get());
}

public static final class LicenseEncrypted extends PassageFileExtension {

@Override
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,101 @@
/*******************************************************************************
* 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.access;

import java.io.IOException;
import java.nio.file.Path;
import java.util.Arrays;
import java.util.Collections;
import java.util.List;
import java.util.Optional;
import java.util.function.BinaryOperator;
import java.util.function.Supplier;

import org.eclipse.passage.lic.api.LicensedProduct;
import org.eclipse.passage.lic.api.ServiceInvocationResult;
import org.eclipse.passage.lic.api.agreements.AgreementAcceptanceService;
import org.eclipse.passage.lic.api.agreements.AgreementToAccept;
import org.eclipse.passage.lic.api.conditions.mining.LicenseReadingService;
import org.eclipse.passage.lic.api.restrictions.ExaminationCertificate;
import org.eclipse.passage.lic.base.BaseServiceInvocationResult;
import org.eclipse.passage.lic.base.BaseServiceInvocationResult.Sum;
import org.eclipse.passage.lic.base.access.SumOfCertificates;
import org.eclipse.passage.lic.base.diagnostic.SumOfLists;

/**
* Set of libraries registered for the the product
*
* @see Library
*/
public final class Libraries {

private final List<Library> libraries;
private final Supplier<LicensedProduct> owner;

public Libraries(Supplier<List<Library>> libraries, Supplier<LicensedProduct> owner) {
this(libraries.get(), owner);
}

public Libraries(List<Library> libraries, Supplier<LicensedProduct> owner) {
this.libraries = libraries;
this.owner = owner;
}

public boolean empty() {
return libraries.isEmpty();
}

public LicensedProduct product() {
return owner.get();
}

public Optional<ServiceInvocationResult<ExaminationCertificate>> assess() {
return libraries.stream()//
.map(Library::assess).reduce(new BaseServiceInvocationResult.Sum<>(new SumOfCertificates()));
}

public Optional<ServiceInvocationResult<List<AgreementAcceptanceService>>> agreementsServices(
AgreementToAccept agreement) {
return libraries.stream()//
.map(library -> library.agreementsService(agreement))//
.map(this::enlisted)//
.reduce(sum());
}

public Optional<ServiceInvocationResult<List<LicenseReadingService>>> licenseReadingServices() {
return libraries.stream()//
.map(Library::licenseReadingService)//
.map(this::enlisted)//
.reduce(sum());
}

public Optional<ServiceInvocationResult<Boolean>> installLicense(Path license) throws IOException {
return libraries.stream()//
.map(library -> library.installLicense(license))//
.reduce(new Sum<Boolean>(or()));
}

private <T> ServiceInvocationResult<List<T>> enlisted(ServiceInvocationResult<T> origin) {
List<T> data = origin.data().isPresent() ? Arrays.asList(origin.data().get()) : Collections.emptyList();
return new BaseServiceInvocationResult<List<T>>(origin.diagnostic(), data);
}

private <T> Sum<List<T>> sum() {
return new Sum<List<T>>(new SumOfLists<T>());
}

private BinaryOperator<Boolean> or() {
return (first, second) -> first || second;
}

}
Loading

0 comments on commit a13acc8

Please sign in to comment.