Skip to content

Commit

Permalink
Merge pull request #1055 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 24, 2022
2 parents 83cbdcf + b9a37ef commit ce7edd7
Show file tree
Hide file tree
Showing 14 changed files with 338 additions and 68 deletions.
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*******************************************************************************
* Copyright (c) 2021 ArSysOp
* 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
Expand Down Expand Up @@ -35,16 +35,9 @@ public interface AgreementState {
byte[] content();

/**
* Path to the agreement content file deployed.
*
* @return
*/
// Path located();

/**
* Agreement acceptance check could possible fail due to a wide variety of
* reasons, not only because the agreement has not indeed be accepted. Is the
* case state is still 'not accepted' and diagnostic is supplied
* Agreement acceptance check could possibly fail due to a wide variety of
* reasons, not only because the agreement has not indeed be accepted. In the
* case state is still 'not accepted' and diagnostic is supplied by this method.
*/
Optional<Trouble> error();

Expand Down
8 changes: 0 additions & 8 deletions bundles/org.eclipse.passage.lic.base/.settings/.api_filters
Original file line number Diff line number Diff line change
@@ -1,13 +1,5 @@
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<component id="org.eclipse.passage.lic.base" version="2">
<resource path="META-INF/MANIFEST.MF">
<filter comment="intentional version change to 2.1.0" id="925892614">
<message_arguments>
<message_argument value="2.1.0"/>
<message_argument value="1.0.203"/>
</message_arguments>
</filter>
</resource>
<resource path="src/org/eclipse/passage/lic/base/access/Restrictions.java" type="org.eclipse.passage.lic.base.access.Restrictions">
<filter id="643850349">
<message_arguments>
Expand Down
2 changes: 1 addition & 1 deletion bundles/org.eclipse.passage.lic.base/META-INF/MANIFEST.MF
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
Manifest-Version: 1.0
Automatic-Module-Name: org.eclipse.passage.lic.base
Bundle-ManifestVersion: 2
Bundle-SymbolicName: org.eclipse.passage.lic.base
Bundle-SymbolicName: org.eclipse.passage.lic.base;singleton:=true
Bundle-Version: 2.3.0.qualifier
Bundle-Name: %Bundle-Name
Bundle-Vendor: %Bundle-Vendor
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,3 +21,5 @@ available under the terms of the Eclipse Public License 2.0\n\
which is available at https://www.eclipse.org/legal/epl-2.0/\n\
\n\
SPDX-License-Identifier: EPL-2.0\n\
extension-point.name = External Library licensing service
3 changes: 2 additions & 1 deletion bundles/org.eclipse.passage.lic.base/build.properties
Original file line number Diff line number Diff line change
Expand Up @@ -16,4 +16,5 @@ output.. = bin/
bin.includes = META-INF/,\
.,\
OSGI-INF/,\
about.html
about.html,\
plugin.xml
18 changes: 18 additions & 0 deletions bundles/org.eclipse.passage.lic.base/plugin.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
<?xml version="1.0" encoding="UTF-8"?>
<?eclipse version="3.4"?>
<!--
Copyright (c) 2022 ArSysOp and others
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
-->
<plugin>
<extension-point id="library" name="%extension-point.name" schema="schema/library.exsd"/>

</plugin>
114 changes: 114 additions & 0 deletions bundles/org.eclipse.passage.lic.base/schema/library.exsd
Original file line number Diff line number Diff line change
@@ -0,0 +1,114 @@
<?xml version='1.0' encoding='UTF-8'?>
<!--
Copyright (c) 2022 ArSysOp and others
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
-->
<!-- Schema file written by PDE -->
<schema targetNamespace="org.eclipse.passage.lic.base" xmlns="http://www.w3.org/2001/XMLSchema">
<annotation>
<appinfo>
<meta.schema plugin="org.eclipse.passage.lic.base" id="library" name="External Library licensing service"/>
</appinfo>
<documentation>
A library or component, developed separately, should use the extension to participate in licensing process of an outer project.
</documentation>
</annotation>

<element name="extension">
<annotation>
<appinfo>
<meta.element />
</appinfo>
</annotation>
<complexType>
<sequence minOccurs="1" maxOccurs="unbounded">
<element ref="licensingService" minOccurs="1" maxOccurs="unbounded"/>
</sequence>
<attribute name="point" type="string" use="required">
<annotation>
<documentation>

</documentation>
</annotation>
</attribute>
<attribute name="id" type="string">
<annotation>
<documentation>

</documentation>
</annotation>
</attribute>
<attribute name="name" type="string">
<annotation>
<documentation>

</documentation>
<appinfo>
<meta.attribute translatable="true"/>
</appinfo>
</annotation>
</attribute>
</complexType>
</element>

<element name="licensingService">
<complexType>
<attribute name="class" type="string" use="required">
<annotation>
<documentation>

</documentation>
<appinfo>
<meta.attribute kind="java" basedOn=":org.eclipse.passage.lic.internal.base.access.DelegatedLicensingService"/>
</appinfo>
</annotation>
</attribute>
</complexType>
</element>

<annotation>
<appinfo>
<meta.section type="since"/>
</appinfo>
<documentation>
[Enter the first release in which this extension point appears.]
</documentation>
</annotation>

<annotation>
<appinfo>
<meta.section type="examples"/>
</appinfo>
<documentation>
[Enter extension point usage example here.]
</documentation>
</annotation>

<annotation>
<appinfo>
<meta.section type="apiinfo"/>
</appinfo>
<documentation>
[Enter API information here.]
</documentation>
</annotation>

<annotation>
<appinfo>
<meta.section type="implementation"/>
</appinfo>
<documentation>
[Enter information about supplied implementation of this extension point.]
</documentation>
</annotation>


</schema>
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
/*******************************************************************************
* 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.Collection;
import java.util.Optional;

import org.eclipse.passage.lic.api.LicensedProduct;
import org.eclipse.passage.lic.api.PassageLicenseCoverage;
import org.eclipse.passage.lic.api.ServiceInvocationResult;
import org.eclipse.passage.lic.api.agreements.AgreementAcceptanceService;
import org.eclipse.passage.lic.api.conditions.Condition;
import org.eclipse.passage.lic.api.restrictions.ExaminationCertificate;

public interface DelegatedLicensingService extends PassageLicenseCoverage {

LicensedProduct product();

@Override
ServiceInvocationResult<ExaminationCertificate> assess();

Optional<AgreementAcceptanceService> agreementsService();

Collection<Condition> conditions(Path license);

void installLicense(Path license) throws IOException;

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

import java.util.Collection;
import java.util.Objects;
import java.util.Optional;
import java.util.function.Predicate;
import java.util.stream.Collectors;

import org.eclipse.passage.lic.api.ServiceInvocationResult;
import org.eclipse.passage.lic.api.registry.StringServiceId;
import org.eclipse.passage.lic.api.requirements.Requirement;
import org.eclipse.passage.lic.api.requirements.ResolvedRequirements;
import org.eclipse.passage.lic.base.BaseServiceInvocationResult;

public final class FilteredRequirements implements ResolvedRequirements {

private final ResolvedRequirements delegate;
private final Predicate<Requirement> condition;

public FilteredRequirements(ResolvedRequirements delegate, Predicate<Requirement> condition) {
Objects.requireNonNull(delegate, "FilteredRequirements::delegate"); //$NON-NLS-1$
Objects.requireNonNull(condition, "FilteredRequirements::condition"); //$NON-NLS-1$
this.delegate = delegate;
this.condition = condition;
}

@Override
public StringServiceId id() {
return new StringServiceId("filtered-" + delegate.id().toString()); //$NON-NLS-1$
}

@Override
public ServiceInvocationResult<Collection<Requirement>> all() {
ServiceInvocationResult<Collection<Requirement>> all = delegate.all();
Optional<Collection<Requirement>> some = all.data().map(this::filtered);
return new BaseServiceInvocationResult<>(all.diagnostic(), some);
}

private Collection<Requirement> filtered(Collection<Requirement> all) {
return all.stream()//
.filter(condition)//
.collect(Collectors.toList());
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ Export-Package: org.eclipse.passage.lic.equinox,
org.eclipse.passage.lic.equinox.conditions,
org.eclipse.passage.lic.equinox.io,
org.eclipse.passage.lic.equinox.requirements,
org.eclipse.passage.lic.internal.equinox;x-friends:="org.eclipse.passage.loc.licenses.core,org.eclipse.passage.lic.jetty",
org.eclipse.passage.lic.internal.equinox.events;
x-friends:="org.eclipse.passage.loc.features.core,
org.eclipse.passage.loc.products.core,
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,79 @@
/*******************************************************************************
* 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.equinox;

import java.util.Arrays;
import java.util.List;
import java.util.Objects;
import java.util.Optional;
import java.util.function.Supplier;
import java.util.stream.Collectors;

import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import org.eclipse.core.runtime.CoreException;
import org.eclipse.core.runtime.IConfigurationElement;
import org.eclipse.core.runtime.IExtension;
import org.eclipse.core.runtime.Platform;

/**
* <p>
* Reads and instantiates executables for the most common service-supplying
* extensions of sequence<service<class>> structure.
* </p>
* <p>
* In case there is a trouble with any single library, logs details and proceeds
* with the rest of them.
* </p>
*/
public final class ServiceExtensions<S> implements Supplier<List<S>> {

private final String namespace;
private final String point;
private final Class<S> service;
private final Logger log = LogManager.getLogger(getClass());

public ServiceExtensions(String namespace, String point, Class<S> service) {
Objects.requireNonNull(namespace, "ServiceExtensions::namespace"); //$NON-NLS-1$
Objects.requireNonNull(point, "ServiceExtensions::point"); //$NON-NLS-1$
Objects.requireNonNull(service, "ServiceExtensions::service"); //$NON-NLS-1$
this.namespace = namespace;
this.point = point;
this.service = service;
}

@Override
public List<S> get() {
return Arrays.stream(extensions())//
.map(IExtension::getConfigurationElements)//
.flatMap(Arrays::stream)//
.map(this::oneService)//
.filter(Optional::isPresent) //
.map(Optional::get) //
.collect(Collectors.toList());
}

private IExtension[] extensions() {
return Platform.getExtensionRegistry().getExtensionPoint(namespace, point).getExtensions();
}

private Optional<S> oneService(IConfigurationElement config) {
try {
Object executable = config.createExecutableExtension("class"); //$NON-NLS-1$
return Optional.of(service.cast(executable));
} catch (CoreException e) {
log.error("failed to instanciate a service ", e); //$NON-NLS-1$
return Optional.empty();
}
}
}
Loading

0 comments on commit ce7edd7

Please sign in to comment.