From 5cc4d92ba8352cf0dc062826662827caa3ba683d Mon Sep 17 00:00:00 2001 From: "elena.parovyshnaya" Date: Mon, 15 Jun 2020 11:30:00 +0300 Subject: [PATCH 01/10] basic demo feature structure --- .../lic/internal/api/FrameworkSupplier.java | 8 +++ .../internal/equinox/FrameworkSupplier.java | 45 ---------------- .../org.eclipse.passage.seal.demo/.classpath | 7 +++ .../org.eclipse.passage.seal.demo/.project | 39 ++++++++++++++ .../META-INF/MANIFEST.MF | 16 ++++++ .../OSGI-INF/l10n/bundle.properties | 23 ++++++++ .../org.eclipse.passage.seal.demo/about.html | 36 +++++++++++++ .../build.properties | 19 +++++++ .../seal/internal/demo/DemoFramework.java | 33 ++++++++++++ .../internal/demo/DemoFrameworkSupplier.java | 30 +++++++++++ .../org.eclipse.passage.demo.feature/.project | 17 ++++++ .../build.properties | 15 ++++++ .../feature.properties | 25 +++++++++ .../feature.xml | 39 ++++++++++++++ .../pom.xml | 35 ++++++++++++ .../category.xml | 26 +++++++++ .../pom.xml | 54 +++++++++++++++++++ .../.classpath | 11 ++++ .../.project | 34 ++++++++++++ .../META-INF/MANIFEST.MF | 12 +++++ .../OSGI-INF/l10n/bundle.properties | 23 ++++++++ .../build.properties | 18 +++++++ .../lic/api/tests/FrameworkContractTest.java | 50 +++++++++++++++++ .../ResolvedReqiorementsContractTest.java | 46 ++++++++++++++++ .../lic/api/tests/fakes/FakeFeature.java | 38 +++++++++++++ .../lic/api/tests/fakes/FakeRequirement.java | 46 ++++++++++++++++ .../tests/fakes/FakeResolvedRequirements.java | 33 ++++++++++++ .../.classpath | 11 ++++ .../.project | 34 ++++++++++++ .../META-INF/MANIFEST.MF | 15 ++++++ .../OSGI-INF/l10n/bundle.properties | 23 ++++++++ .../build.properties | 18 +++++++ .../seal/demo/tests/DemoFrameworkTest.java | 24 +++++++++ 33 files changed, 858 insertions(+), 45 deletions(-) create mode 100644 bundles/org.eclipse.passage.lic.api/src/org/eclipse/passage/lic/internal/api/FrameworkSupplier.java delete mode 100644 bundles/org.eclipse.passage.lic.equinox/src/org/eclipse/passage/lic/internal/equinox/FrameworkSupplier.java create mode 100644 bundles/org.eclipse.passage.seal.demo/.classpath create mode 100644 bundles/org.eclipse.passage.seal.demo/.project create mode 100644 bundles/org.eclipse.passage.seal.demo/META-INF/MANIFEST.MF create mode 100644 bundles/org.eclipse.passage.seal.demo/OSGI-INF/l10n/bundle.properties create mode 100644 bundles/org.eclipse.passage.seal.demo/about.html create mode 100644 bundles/org.eclipse.passage.seal.demo/build.properties create mode 100644 bundles/org.eclipse.passage.seal.demo/src/org/eclipse/passage/seal/internal/demo/DemoFramework.java create mode 100644 bundles/org.eclipse.passage.seal.demo/src/org/eclipse/passage/seal/internal/demo/DemoFrameworkSupplier.java create mode 100644 features/org.eclipse.passage.demo.feature/.project create mode 100644 features/org.eclipse.passage.demo.feature/build.properties create mode 100644 features/org.eclipse.passage.demo.feature/feature.properties create mode 100644 features/org.eclipse.passage.demo.feature/feature.xml create mode 100644 releng/org.eclipse.passage.demo.aggregator/pom.xml create mode 100644 releng/org.eclipse.passage.demo.repository/category.xml create mode 100644 releng/org.eclipse.passage.demo.repository/pom.xml create mode 100644 tests/org.eclipse.passage.lic.api.tests/.classpath create mode 100644 tests/org.eclipse.passage.lic.api.tests/.project create mode 100644 tests/org.eclipse.passage.lic.api.tests/META-INF/MANIFEST.MF create mode 100644 tests/org.eclipse.passage.lic.api.tests/OSGI-INF/l10n/bundle.properties create mode 100644 tests/org.eclipse.passage.lic.api.tests/build.properties create mode 100644 tests/org.eclipse.passage.lic.api.tests/src/org/eclipse/passage/lic/api/tests/FrameworkContractTest.java create mode 100644 tests/org.eclipse.passage.lic.api.tests/src/org/eclipse/passage/lic/api/tests/ResolvedReqiorementsContractTest.java create mode 100644 tests/org.eclipse.passage.lic.api.tests/src/org/eclipse/passage/lic/api/tests/fakes/FakeFeature.java create mode 100644 tests/org.eclipse.passage.lic.api.tests/src/org/eclipse/passage/lic/api/tests/fakes/FakeRequirement.java create mode 100644 tests/org.eclipse.passage.lic.api.tests/src/org/eclipse/passage/lic/api/tests/fakes/FakeResolvedRequirements.java create mode 100644 tests/org.eclipse.passage.seal.demo.tests/.classpath create mode 100644 tests/org.eclipse.passage.seal.demo.tests/.project create mode 100644 tests/org.eclipse.passage.seal.demo.tests/META-INF/MANIFEST.MF create mode 100644 tests/org.eclipse.passage.seal.demo.tests/OSGI-INF/l10n/bundle.properties create mode 100644 tests/org.eclipse.passage.seal.demo.tests/build.properties create mode 100644 tests/org.eclipse.passage.seal.demo.tests/src/org/eclipse/passage/seal/demo/tests/DemoFrameworkTest.java diff --git a/bundles/org.eclipse.passage.lic.api/src/org/eclipse/passage/lic/internal/api/FrameworkSupplier.java b/bundles/org.eclipse.passage.lic.api/src/org/eclipse/passage/lic/internal/api/FrameworkSupplier.java new file mode 100644 index 000000000..f74a0e08a --- /dev/null +++ b/bundles/org.eclipse.passage.lic.api/src/org/eclipse/passage/lic/internal/api/FrameworkSupplier.java @@ -0,0 +1,8 @@ +package org.eclipse.passage.lic.internal.api; + +import java.util.Optional; +import java.util.function.Supplier; + +public interface FrameworkSupplier extends Supplier> { + +} diff --git a/bundles/org.eclipse.passage.lic.equinox/src/org/eclipse/passage/lic/internal/equinox/FrameworkSupplier.java b/bundles/org.eclipse.passage.lic.equinox/src/org/eclipse/passage/lic/internal/equinox/FrameworkSupplier.java deleted file mode 100644 index c2c6cd8eb..000000000 --- a/bundles/org.eclipse.passage.lic.equinox/src/org/eclipse/passage/lic/internal/equinox/FrameworkSupplier.java +++ /dev/null @@ -1,45 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2020 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.Optional; -import java.util.function.Supplier; - -import org.eclipse.passage.lic.internal.api.Framework; -import org.eclipse.passage.lic.internal.equinox.i18n.EquinoxMessages; -import org.osgi.framework.BundleContext; -import org.osgi.framework.FrameworkUtil; -import org.osgi.framework.InvalidSyntaxException; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - -@SuppressWarnings("restriction") -final class FrameworkSupplier implements Supplier> { - - private final Logger log = LoggerFactory.getLogger(getClass()); - - @Override - public Optional get() { - BundleContext context = FrameworkUtil.getBundle(getClass()).getBundleContext(); - try { - return context.getServiceReferences(Framework.class, null).stream() // - .map(context::getService) // - .filter(s -> s.getClass() == EquinoxFramework.class) // - .findAny(); - } catch (InvalidSyntaxException e) { - log.error(EquinoxMessages.EquinoxPassage_no_framework, e); - return Optional.empty(); - } - } - -} diff --git a/bundles/org.eclipse.passage.seal.demo/.classpath b/bundles/org.eclipse.passage.seal.demo/.classpath new file mode 100644 index 000000000..eca7bdba8 --- /dev/null +++ b/bundles/org.eclipse.passage.seal.demo/.classpath @@ -0,0 +1,7 @@ + + + + + + + diff --git a/bundles/org.eclipse.passage.seal.demo/.project b/bundles/org.eclipse.passage.seal.demo/.project new file mode 100644 index 000000000..5c336bd19 --- /dev/null +++ b/bundles/org.eclipse.passage.seal.demo/.project @@ -0,0 +1,39 @@ + + + org.eclipse.passage.seal.demo + + + + + + org.eclipse.jdt.core.javabuilder + + + + + org.eclipse.pde.ManifestBuilder + + + + + org.eclipse.pde.SchemaBuilder + + + + + org.eclipse.pde.ds.core.builder + + + + + org.eclipse.pde.api.tools.apiAnalysisBuilder + + + + + + org.eclipse.pde.PluginNature + org.eclipse.jdt.core.javanature + org.eclipse.pde.api.tools.apiAnalysisNature + + diff --git a/bundles/org.eclipse.passage.seal.demo/META-INF/MANIFEST.MF b/bundles/org.eclipse.passage.seal.demo/META-INF/MANIFEST.MF new file mode 100644 index 000000000..2e3d26c79 --- /dev/null +++ b/bundles/org.eclipse.passage.seal.demo/META-INF/MANIFEST.MF @@ -0,0 +1,16 @@ +Manifest-Version: 1.0 +Automatic-Module-Name: org.eclipse.passage.seal.demo +Bundle-ManifestVersion: 2 +Bundle-SymbolicName: org.eclipse.passage.seal.demo +Bundle-Version: 0.1.0.qualifier +Bundle-Name: %Bundle-Name +Bundle-Vendor: %Bundle-Vendor +Bundle-Copyright: %Bundle-Copyright +Bundle-RequiredExecutionEnvironment: JavaSE-1.8 +Require-Bundle: org.eclipse.osgi.services;bundle-version="3.8.0", + org.eclipse.passage.lic.api, + org.eclipse.passage.lic.base, + org.eclipse.passage.lic.equinox +Service-Component: OSGI-INF/*.xml +Bundle-ActivationPolicy: lazy +Export-Package: org.eclipse.passage.seal.internal.demo diff --git a/bundles/org.eclipse.passage.seal.demo/OSGI-INF/l10n/bundle.properties b/bundles/org.eclipse.passage.seal.demo/OSGI-INF/l10n/bundle.properties new file mode 100644 index 000000000..bdcea19b1 --- /dev/null +++ b/bundles/org.eclipse.passage.seal.demo/OSGI-INF/l10n/bundle.properties @@ -0,0 +1,23 @@ +#Properties file for org.eclipse.passage.seal.demo +############################################################################### +# Copyright (c) 2019, 2020 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 +############################################################################### + +Bundle-Name = Passage Seal demo +Bundle-Vendor = Eclipse Passage +Bundle-Copyright = Copyright (c) 2020 ArSysOp and others.\n\ +\n\ +This program and the accompanying materials are made\n\ +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\ diff --git a/bundles/org.eclipse.passage.seal.demo/about.html b/bundles/org.eclipse.passage.seal.demo/about.html new file mode 100644 index 000000000..164f781a8 --- /dev/null +++ b/bundles/org.eclipse.passage.seal.demo/about.html @@ -0,0 +1,36 @@ + + + + +About + + +

About This Content

+ +

November 30, 2017

+

License

+ +

+ The Eclipse Foundation makes available all content in this plug-in + ("Content"). Unless otherwise indicated below, the Content + is provided to you under the terms and conditions of the Eclipse + Public License Version 2.0 ("EPL"). A copy of the EPL is + available at http://www.eclipse.org/legal/epl-2.0. + For purposes of the EPL, "Program" will mean the Content. +

+ +

+ If you did not receive this Content directly from the Eclipse + Foundation, the Content is being redistributed by another party + ("Redistributor") and different terms and conditions may + apply to your use of any object code in the Content. Check the + Redistributor's license that was provided with the Content. If no such + license exists, contact the Redistributor. Unless otherwise indicated + below, the terms and conditions of the EPL still apply to any source + code in the Content and such source code may be obtained at http://www.eclipse.org. +

+ + + \ No newline at end of file diff --git a/bundles/org.eclipse.passage.seal.demo/build.properties b/bundles/org.eclipse.passage.seal.demo/build.properties new file mode 100644 index 000000000..9eb249799 --- /dev/null +++ b/bundles/org.eclipse.passage.seal.demo/build.properties @@ -0,0 +1,19 @@ +############################################################################### +# Copyright (c) 2020 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 +############################################################################### + +source.. = src/ +output.. = bin/ +bin.includes = META-INF/,\ + .,\ + OSGI-INF/,\ + about.html diff --git a/bundles/org.eclipse.passage.seal.demo/src/org/eclipse/passage/seal/internal/demo/DemoFramework.java b/bundles/org.eclipse.passage.seal.demo/src/org/eclipse/passage/seal/internal/demo/DemoFramework.java new file mode 100644 index 000000000..8a816b127 --- /dev/null +++ b/bundles/org.eclipse.passage.seal.demo/src/org/eclipse/passage/seal/internal/demo/DemoFramework.java @@ -0,0 +1,33 @@ +package org.eclipse.passage.seal.internal.demo; + +import java.util.Arrays; + +import org.eclipse.passage.lic.internal.api.Framework; +import org.eclipse.passage.lic.internal.api.registry.Registry; +import org.eclipse.passage.lic.internal.api.registry.StringServiceId; +import org.eclipse.passage.lic.internal.api.requirements.ResolvedRequirements; +import org.eclipse.passage.lic.internal.api.requirements.ResolvedRequirementsRegistry; +import org.eclipse.passage.lic.internal.base.registry.ReadOnlyRegistry; +import org.eclipse.passage.lic.internal.equinox.requirements.BundleRequirements; +import org.eclipse.passage.lic.internal.equinox.requirements.ComponentRequirements; + +@SuppressWarnings("restriction") +final class DemoFramework implements Framework { + + private final Registry requirements; + static final Framework demo = new DemoFramework(); + + private DemoFramework() { + requirements = // + new ReadOnlyRegistry(Arrays.asList(// + new BundleRequirements(), // + new ComponentRequirements()) // + ); + } + + @Override + public ResolvedRequirementsRegistry requirementsRegistry() { + return () -> requirements; + } + +} diff --git a/bundles/org.eclipse.passage.seal.demo/src/org/eclipse/passage/seal/internal/demo/DemoFrameworkSupplier.java b/bundles/org.eclipse.passage.seal.demo/src/org/eclipse/passage/seal/internal/demo/DemoFrameworkSupplier.java new file mode 100644 index 000000000..c207653f5 --- /dev/null +++ b/bundles/org.eclipse.passage.seal.demo/src/org/eclipse/passage/seal/internal/demo/DemoFrameworkSupplier.java @@ -0,0 +1,30 @@ +/******************************************************************************* + * Copyright (c) 2020 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.seal.internal.demo; + +import java.util.Optional; +import java.util.function.Supplier; + +import org.eclipse.passage.lic.internal.api.Framework; +import org.osgi.service.component.annotations.Component; + +@SuppressWarnings("restriction") +@Component +public final class DemoFrameworkSupplier implements Supplier> { + + @Override + public Optional get() { + return Optional.of(DemoFramework.demo); + } + +} diff --git a/features/org.eclipse.passage.demo.feature/.project b/features/org.eclipse.passage.demo.feature/.project new file mode 100644 index 000000000..6bf36fa53 --- /dev/null +++ b/features/org.eclipse.passage.demo.feature/.project @@ -0,0 +1,17 @@ + + + org.eclipse.passage.loc.workbench.feature + + + + + + org.eclipse.pde.FeatureBuilder + + + + + + org.eclipse.pde.FeatureNature + + diff --git a/features/org.eclipse.passage.demo.feature/build.properties b/features/org.eclipse.passage.demo.feature/build.properties new file mode 100644 index 000000000..48a1fca79 --- /dev/null +++ b/features/org.eclipse.passage.demo.feature/build.properties @@ -0,0 +1,15 @@ +############################################################################### +# Copyright (c) 2020 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 +############################################################################### + +bin.includes = feature.xml,\ + feature.properties diff --git a/features/org.eclipse.passage.demo.feature/feature.properties b/features/org.eclipse.passage.demo.feature/feature.properties new file mode 100644 index 000000000..6c72ec8f1 --- /dev/null +++ b/features/org.eclipse.passage.demo.feature/feature.properties @@ -0,0 +1,25 @@ +#Properties file for org.eclipse.passage.demo.feature +############################################################################### +# Copyright (c) 2018, 2020 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 +############################################################################### + +featureName=Passage Demo +providerName=Eclipse Passage +description=Passage Licensing Operator Components: Workbench +copyright=Copyright (c) 2020 ArSysOp and others.\n\ +\n\ +This program and the accompanying materials are made\n\ +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\ + diff --git a/features/org.eclipse.passage.demo.feature/feature.xml b/features/org.eclipse.passage.demo.feature/feature.xml new file mode 100644 index 000000000..cb3f643e9 --- /dev/null +++ b/features/org.eclipse.passage.demo.feature/feature.xml @@ -0,0 +1,39 @@ + + + + + + %description + + + + %copyright + + + + %license + + + + + + diff --git a/releng/org.eclipse.passage.demo.aggregator/pom.xml b/releng/org.eclipse.passage.demo.aggregator/pom.xml new file mode 100644 index 000000000..3eeddec53 --- /dev/null +++ b/releng/org.eclipse.passage.demo.aggregator/pom.xml @@ -0,0 +1,35 @@ + + + + 4.0.0 + + org.eclipse.passage.demo.aggregator + pom + + + org.eclipse.passage + org.eclipse.passage.parent + 1.0.0-SNAPSHOT + ../../releng/org.eclipse.passage.parent + + + + ../../bundles/org.eclipse.passage.seal.demo + ../../features/org.eclipse.passage.demo.feature + ../../tests/org.eclipse.passage.seal.tests + + + \ No newline at end of file diff --git a/releng/org.eclipse.passage.demo.repository/category.xml b/releng/org.eclipse.passage.demo.repository/category.xml new file mode 100644 index 000000000..7d06f577f --- /dev/null +++ b/releng/org.eclipse.passage.demo.repository/category.xml @@ -0,0 +1,26 @@ + + + + + + Passage Demo contains final licensing runtime assembly + + + + + + diff --git a/releng/org.eclipse.passage.demo.repository/pom.xml b/releng/org.eclipse.passage.demo.repository/pom.xml new file mode 100644 index 000000000..844162ad5 --- /dev/null +++ b/releng/org.eclipse.passage.demo.repository/pom.xml @@ -0,0 +1,54 @@ + + + + 4.0.0 + + org.eclipse.passage.demo.repository + eclipse-repository + + + org.eclipse.passage + org.eclipse.passage.parent + 1.0.0-SNAPSHOT + ../../releng/org.eclipse.passage.parent + + + + + + org.eclipse.tycho + tycho-p2-repository-plugin + ${tycho.version} + true + + + package + archive-repository + + archive-repository + + + ${project.artifactId}-${build.label} + + + + + + + + \ No newline at end of file diff --git a/tests/org.eclipse.passage.lic.api.tests/.classpath b/tests/org.eclipse.passage.lic.api.tests/.classpath new file mode 100644 index 000000000..3e5654f17 --- /dev/null +++ b/tests/org.eclipse.passage.lic.api.tests/.classpath @@ -0,0 +1,11 @@ + + + + + + + + + + + diff --git a/tests/org.eclipse.passage.lic.api.tests/.project b/tests/org.eclipse.passage.lic.api.tests/.project new file mode 100644 index 000000000..58718ca06 --- /dev/null +++ b/tests/org.eclipse.passage.lic.api.tests/.project @@ -0,0 +1,34 @@ + + + org.eclipse.passage.lic.api.tests + + + + + + org.eclipse.jdt.core.javabuilder + + + + + org.eclipse.pde.ManifestBuilder + + + + + org.eclipse.pde.SchemaBuilder + + + + + org.eclipse.pde.api.tools.apiAnalysisBuilder + + + + + + org.eclipse.pde.PluginNature + org.eclipse.jdt.core.javanature + org.eclipse.pde.api.tools.apiAnalysisNature + + diff --git a/tests/org.eclipse.passage.lic.api.tests/META-INF/MANIFEST.MF b/tests/org.eclipse.passage.lic.api.tests/META-INF/MANIFEST.MF new file mode 100644 index 000000000..72f9ea2b4 --- /dev/null +++ b/tests/org.eclipse.passage.lic.api.tests/META-INF/MANIFEST.MF @@ -0,0 +1,12 @@ +Manifest-Version: 1.0 +Automatic-Module-Name: org.eclipse.passage.lic.api.tests +Bundle-ManifestVersion: 2 +Bundle-SymbolicName: org.eclipse.passage.lic.api.tests +Bundle-Version: 0.1.0.qualifier +Bundle-Name: %Bundle-Name +Bundle-Vendor: %Bundle-Vendor +Bundle-Copyright: %Bundle-Copyright +Bundle-RequiredExecutionEnvironment: JavaSE-1.8 +Require-Bundle: org.junit;bundle-version="4.12.0", + org.eclipse.passage.lic.api;bundle-version="0.7.0" +Export-Package: org.eclipse.passage.lic.api.tests diff --git a/tests/org.eclipse.passage.lic.api.tests/OSGI-INF/l10n/bundle.properties b/tests/org.eclipse.passage.lic.api.tests/OSGI-INF/l10n/bundle.properties new file mode 100644 index 000000000..a31605a91 --- /dev/null +++ b/tests/org.eclipse.passage.lic.api.tests/OSGI-INF/l10n/bundle.properties @@ -0,0 +1,23 @@ +#Properties file for org.eclipse.passage.lic.api.tests +############################################################################### +# Copyright (c) 2020 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 +############################################################################### + +Bundle-Name = Passage LIC API Tests +Bundle-Vendor = Eclipse Passage +Bundle-Copyright = Copyright (c) 2020 ArSysOp and others.\n\ +\n\ +This program and the accompanying materials are made\n\ +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\ diff --git a/tests/org.eclipse.passage.lic.api.tests/build.properties b/tests/org.eclipse.passage.lic.api.tests/build.properties new file mode 100644 index 000000000..fa01af22a --- /dev/null +++ b/tests/org.eclipse.passage.lic.api.tests/build.properties @@ -0,0 +1,18 @@ +############################################################################### +# Copyright (c) 2020 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 +############################################################################### + +source.. = src/ +output.. = bin/ +bin.includes = META-INF/,\ + .,\ + OSGI-INF/ diff --git a/tests/org.eclipse.passage.lic.api.tests/src/org/eclipse/passage/lic/api/tests/FrameworkContractTest.java b/tests/org.eclipse.passage.lic.api.tests/src/org/eclipse/passage/lic/api/tests/FrameworkContractTest.java new file mode 100644 index 000000000..9837589da --- /dev/null +++ b/tests/org.eclipse.passage.lic.api.tests/src/org/eclipse/passage/lic/api/tests/FrameworkContractTest.java @@ -0,0 +1,50 @@ +package org.eclipse.passage.lic.api.tests; + +import static org.junit.Assert.assertNotNull; +import static org.junit.Assert.assertTrue; + +import java.util.Optional; + +import org.eclipse.passage.lic.api.tests.fakes.FakeResolvedRequirements; +import org.eclipse.passage.lic.internal.api.Framework; +import org.eclipse.passage.lic.internal.api.registry.Registry; +import org.eclipse.passage.lic.internal.api.registry.StringServiceId; +import org.eclipse.passage.lic.internal.api.requirements.ResolvedRequirements; +import org.junit.Test; + +@SuppressWarnings("restriction") +public abstract class FrameworkContractTest { + + @Test + public void exists() { + assertNotNull(framework()); + assertTrue(framework().isPresent()); + } + + @Test + public void canResolveRequirements() { + Registry registry = framework().get().requirementsRegistry().get(); + assertNotNull(registry); + assertNotNull(registry.services()); + assertTrue(registry.services().size() > 0); + } + + @Test + public void prohibitsRequirementsResolutionExtension() { + assertTrue(readOnly(framework().get().requirementsRegistry().get())); + } + + @Test + public void prohibitsInjectionIntoRequirementResolutionServices() { + Registry registry = framework().get().requirementsRegistry().get(); + int before = registry.services().size(); + registry.services().add(new FakeResolvedRequirements()); + assertTrue(before == registry.services().size()); + + } + + protected abstract Optional framework(); + + protected abstract boolean readOnly(Registry registry); + +} diff --git a/tests/org.eclipse.passage.lic.api.tests/src/org/eclipse/passage/lic/api/tests/ResolvedReqiorementsContractTest.java b/tests/org.eclipse.passage.lic.api.tests/src/org/eclipse/passage/lic/api/tests/ResolvedReqiorementsContractTest.java new file mode 100644 index 000000000..4e1a2cc9c --- /dev/null +++ b/tests/org.eclipse.passage.lic.api.tests/src/org/eclipse/passage/lic/api/tests/ResolvedReqiorementsContractTest.java @@ -0,0 +1,46 @@ +package org.eclipse.passage.lic.api.tests; + +import static org.junit.Assert.assertTrue; +import static org.junit.Assume.assumeTrue; + +import java.util.Collection; +import java.util.Collections; +import java.util.function.Consumer; + +import org.eclipse.passage.lic.api.tests.fakes.FakeRequirement; +import org.eclipse.passage.lic.internal.api.requirements.Requirement; +import org.eclipse.passage.lic.internal.api.requirements.ResolvedRequirements; +import org.junit.Test; + +@SuppressWarnings("restriction") +public abstract class ResolvedReqiorementsContractTest { + + @Test + public void prohibitsInjectionIntoResolvedRequirements() { + testInterferenceResistence(shared -> shared.add(new FakeRequirement())); + testInterferenceResistence(shared -> shared.addAll(Collections.singleton(new FakeRequirement()))); + } + + @Test + public void prohibitsRemovalFromResolvedRequirements() { + assumeTrue(service().all().size() > 0); + testInterferenceResistence(Collection::clear); + testInterferenceResistence(shared -> shared.retainAll(Collections.emptyList())); + testInterferenceResistence(shared -> shared.removeAll(shared)); + testInterferenceResistence(shared -> shared.remove(shared.iterator().next())); + } + + private void testInterferenceResistence(Consumer> interference) { + // given + ResolvedRequirements service = service(); + Collection shared = service.all(); + int before = shared.size(); + // when + shared.clear(); + // then + assertTrue(before == service.all().size()); + } + + protected abstract ResolvedRequirements service(); + +} diff --git a/tests/org.eclipse.passage.lic.api.tests/src/org/eclipse/passage/lic/api/tests/fakes/FakeFeature.java b/tests/org.eclipse.passage.lic.api.tests/src/org/eclipse/passage/lic/api/tests/fakes/FakeFeature.java new file mode 100644 index 000000000..bbb665e9d --- /dev/null +++ b/tests/org.eclipse.passage.lic.api.tests/src/org/eclipse/passage/lic/api/tests/fakes/FakeFeature.java @@ -0,0 +1,38 @@ +package org.eclipse.passage.lic.api.tests.fakes; + +import org.eclipse.passage.lic.internal.api.requirements.Feature; + +@SuppressWarnings("restriction") +public final class FakeFeature implements Feature { + + private final String identity; + + public FakeFeature(String identity) { + this.identity = identity; + } + + public FakeFeature() { + this(Long.toHexString(System.currentTimeMillis())); + } + + @Override + public String name() { + return String.format("Fake feature %s ", identity); + } + + @Override + public String version() { + return "0.0.7"; + } + + @Override + public String identifier() { + return String.format("fake_%s ", identity); + } + + @Override + public String provider() { + return "API tests"; + } + +} diff --git a/tests/org.eclipse.passage.lic.api.tests/src/org/eclipse/passage/lic/api/tests/fakes/FakeRequirement.java b/tests/org.eclipse.passage.lic.api.tests/src/org/eclipse/passage/lic/api/tests/fakes/FakeRequirement.java new file mode 100644 index 000000000..515dfe263 --- /dev/null +++ b/tests/org.eclipse.passage.lic.api.tests/src/org/eclipse/passage/lic/api/tests/fakes/FakeRequirement.java @@ -0,0 +1,46 @@ +package org.eclipse.passage.lic.api.tests.fakes; + +import org.eclipse.passage.lic.internal.api.requirements.Feature; +import org.eclipse.passage.lic.internal.api.requirements.Requirement; +import org.eclipse.passage.lic.internal.api.restrictions.RestrictionLevel; + +@SuppressWarnings("restriction") +public final class FakeRequirement implements Requirement{ + + private final Feature feature; + private final RestrictionLevel level; + + + public FakeRequirement(Feature feature, RestrictionLevel level) { + this.feature = feature; + this.level = level; + } + + public FakeRequirement(String feature, String level) { + this(new FakeFeature(feature), new RestrictionLevel.Of(level)); + } + + public FakeRequirement(String feature) { + this(new FakeFeature(feature), new RestrictionLevel.Error()); + } + + public FakeRequirement() { + this(new FakeFeature(), new RestrictionLevel.Error()); + } + + @Override + public Feature feature() { + return feature; + } + + @Override + public RestrictionLevel restrictionLevel() { + return level; + } + + @Override + public Object source() { + return "API Tests"; + } + +} diff --git a/tests/org.eclipse.passage.lic.api.tests/src/org/eclipse/passage/lic/api/tests/fakes/FakeResolvedRequirements.java b/tests/org.eclipse.passage.lic.api.tests/src/org/eclipse/passage/lic/api/tests/fakes/FakeResolvedRequirements.java new file mode 100644 index 000000000..a361d5e4d --- /dev/null +++ b/tests/org.eclipse.passage.lic.api.tests/src/org/eclipse/passage/lic/api/tests/fakes/FakeResolvedRequirements.java @@ -0,0 +1,33 @@ +package org.eclipse.passage.lic.api.tests.fakes; + +import java.util.Collection; +import java.util.Collections; + +import org.eclipse.passage.lic.internal.api.registry.StringServiceId; +import org.eclipse.passage.lic.internal.api.requirements.Requirement; +import org.eclipse.passage.lic.internal.api.requirements.ResolvedRequirements; + +@SuppressWarnings("restriction") +public final class FakeResolvedRequirements implements ResolvedRequirements{ + + private final Collection requirements; + + public FakeResolvedRequirements(Collection requirements) { + this.requirements = requirements; + } + + public FakeResolvedRequirements() { + this.requirements = Collections.emptySet(); + } + + @Override + public StringServiceId id() { + return new StringServiceId("fake-req-res"); + } + + @Override + public Collection all() { + return requirements; + } + +} diff --git a/tests/org.eclipse.passage.seal.demo.tests/.classpath b/tests/org.eclipse.passage.seal.demo.tests/.classpath new file mode 100644 index 000000000..3e5654f17 --- /dev/null +++ b/tests/org.eclipse.passage.seal.demo.tests/.classpath @@ -0,0 +1,11 @@ + + + + + + + + + + + diff --git a/tests/org.eclipse.passage.seal.demo.tests/.project b/tests/org.eclipse.passage.seal.demo.tests/.project new file mode 100644 index 000000000..b8bff297c --- /dev/null +++ b/tests/org.eclipse.passage.seal.demo.tests/.project @@ -0,0 +1,34 @@ + + + org.eclipse.passage.seal.demo.tests + + + + + + org.eclipse.jdt.core.javabuilder + + + + + org.eclipse.pde.ManifestBuilder + + + + + org.eclipse.pde.SchemaBuilder + + + + + org.eclipse.pde.api.tools.apiAnalysisBuilder + + + + + + org.eclipse.pde.PluginNature + org.eclipse.jdt.core.javanature + org.eclipse.pde.api.tools.apiAnalysisNature + + diff --git a/tests/org.eclipse.passage.seal.demo.tests/META-INF/MANIFEST.MF b/tests/org.eclipse.passage.seal.demo.tests/META-INF/MANIFEST.MF new file mode 100644 index 000000000..75420edfb --- /dev/null +++ b/tests/org.eclipse.passage.seal.demo.tests/META-INF/MANIFEST.MF @@ -0,0 +1,15 @@ +Manifest-Version: 1.0 +Automatic-Module-Name: org.eclipse.passage.seal.demo.tests +Bundle-ManifestVersion: 2 +Bundle-SymbolicName: org.eclipse.passage.seal.demo.tests +Bundle-Version: 0.5.0.qualifier +Bundle-Name: %Bundle-Name +Bundle-Vendor: %Bundle-Vendor +Bundle-Copyright: %Bundle-Copyright +Bundle-RequiredExecutionEnvironment: JavaSE-1.8 +Require-Bundle: org.junit;bundle-version="4.12.0", + org.eclipse.osgi.services;bundle-version="0.0.0", + org.eclipse.passage.seal.demo;bundle-version="0.0.0", + org.eclipse.passage.lic.api.tests;bundle-version="0.0.0", + org.eclipse.passage.lic.api +Export-Package: org.eclipse.passage.seal.tests diff --git a/tests/org.eclipse.passage.seal.demo.tests/OSGI-INF/l10n/bundle.properties b/tests/org.eclipse.passage.seal.demo.tests/OSGI-INF/l10n/bundle.properties new file mode 100644 index 000000000..0e831a1e6 --- /dev/null +++ b/tests/org.eclipse.passage.seal.demo.tests/OSGI-INF/l10n/bundle.properties @@ -0,0 +1,23 @@ +#Properties file for org.eclipse.passage.seal.demo.tests +############################################################################### +# Copyright (c) 2020 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 +############################################################################### + +Bundle-Name = Passage Seal Demo Assembly Tests +Bundle-Vendor = Eclipse Passage +Bundle-Copyright = Copyright (c) 2020 ArSysOp and others.\n\ +\n\ +This program and the accompanying materials are made\n\ +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\ diff --git a/tests/org.eclipse.passage.seal.demo.tests/build.properties b/tests/org.eclipse.passage.seal.demo.tests/build.properties new file mode 100644 index 000000000..fa01af22a --- /dev/null +++ b/tests/org.eclipse.passage.seal.demo.tests/build.properties @@ -0,0 +1,18 @@ +############################################################################### +# Copyright (c) 2020 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 +############################################################################### + +source.. = src/ +output.. = bin/ +bin.includes = META-INF/,\ + .,\ + OSGI-INF/ diff --git a/tests/org.eclipse.passage.seal.demo.tests/src/org/eclipse/passage/seal/demo/tests/DemoFrameworkTest.java b/tests/org.eclipse.passage.seal.demo.tests/src/org/eclipse/passage/seal/demo/tests/DemoFrameworkTest.java new file mode 100644 index 000000000..505b7d7b7 --- /dev/null +++ b/tests/org.eclipse.passage.seal.demo.tests/src/org/eclipse/passage/seal/demo/tests/DemoFrameworkTest.java @@ -0,0 +1,24 @@ +package org.eclipse.passage.seal.demo.tests; + +import org.eclipse.passage.lic.internal.api.Framework; + +import java.util.Optional; + +import org.eclipse.passage.lic.api.tests.FrameworkContractTest; +import org.eclipse.passage.lic.internal.api.registry.Registry; +import org.eclipse.passage.seal.internal.demo.DemoFrameworkSupplier; + +@SuppressWarnings("restriction") +public final class DemoFrameworkTest extends FrameworkContractTest{ + + @Override + protected Optional framework() { + return new DemoFrameworkSupplier().get(); + } + + @Override + protected boolean readOnly(Registry registry) { + return false; + } + +} From 6faffae9b40e7593bf6d9b35be1fcf445b0335f7 Mon Sep 17 00:00:00 2001 From: "elena.parovyshnaya" Date: Mon, 15 Jun 2020 13:07:41 +0300 Subject: [PATCH 02/10] Bug 564282 - API revision | question extensibility The decision has been taken to close extensibility for critical access cycle parts and 'seal' final services assembly for security aims. Thus: - `registry` implementation altered to have final readonly registry class - extensibility of requirement resolution services registry is closed: readonly registry is used - both requirement resolution services we have now(BundleRequirements and ComponentRequirements) are detached from OSGi to be accessible for sealing. - contract tests are designed for `Framework` and resuirement resolution service (new `lic.api.tests` bundle) - 'seal.demo' bundle is added to supply final assembly of passage runtime (packed instance of `Framework` interface) for out-of-the-box facilities demontration purposes - `seal.demo.tests` bundle contains both contract and implementational tests for current `DemoFramework` - `demo` feature is appended Signed-off-by: elena.parovyshnaya --- .../internal/base/registry/BaseRegistry.java | 52 ++++++++------- .../base/registry/BaseRuntimeRegistry.java | 64 +++---------------- .../base/registry/ReadOnlyRegistry.java | 15 +++++ ....lic.internal.equinox.EquinoxFramework.xml | 8 --- ...ox.EquinoxResolvedRequirementsRegistry.xml | 8 --- ...quinox.requirements.BundleRequirements.xml | 7 -- ...nox.requirements.ComponentRequirements.xml | 8 --- .../internal/equinox/EquinoxFramework.java | 42 ------------ .../lic/internal/equinox/EquinoxPassage.java | 30 ++++++++- .../EquinoxResolvedRequirementsRegistry.java | 47 -------------- .../requirements/BundleRequirements.java | 7 +- .../requirements/ComponentRequirements.java | 18 ++++-- .../pom.xml | 2 +- .../pom.xml | 2 + .../lic/internal/base/SabotagedFramework.java | 6 +- .../META-INF/MANIFEST.MF | 5 +- .../demo/tests/DemoFrameworkContentTest.java} | 23 ++----- ...st.java => DemoFrameworkContractTest.java} | 2 +- 18 files changed, 116 insertions(+), 230 deletions(-) create mode 100644 bundles/org.eclipse.passage.lic.base/src/org/eclipse/passage/lic/internal/base/registry/ReadOnlyRegistry.java delete mode 100644 bundles/org.eclipse.passage.lic.equinox/OSGI-INF/org.eclipse.passage.lic.internal.equinox.EquinoxFramework.xml delete mode 100644 bundles/org.eclipse.passage.lic.equinox/OSGI-INF/org.eclipse.passage.lic.internal.equinox.EquinoxResolvedRequirementsRegistry.xml delete mode 100644 bundles/org.eclipse.passage.lic.equinox/OSGI-INF/org.eclipse.passage.lic.internal.equinox.requirements.BundleRequirements.xml delete mode 100644 bundles/org.eclipse.passage.lic.equinox/OSGI-INF/org.eclipse.passage.lic.internal.equinox.requirements.ComponentRequirements.xml delete mode 100644 bundles/org.eclipse.passage.lic.equinox/src/org/eclipse/passage/lic/internal/equinox/EquinoxFramework.java delete mode 100644 bundles/org.eclipse.passage.lic.equinox/src/org/eclipse/passage/lic/internal/equinox/EquinoxResolvedRequirementsRegistry.java rename tests/{org.eclipse.passage.lic.equinox.tests/src/org/eclipse/passage/lic/internal/equinox/EquinoxFrameworkSupplierTest.java => org.eclipse.passage.seal.demo.tests/src/org/eclipse/passage/seal/demo/tests/DemoFrameworkContentTest.java} (74%) rename tests/org.eclipse.passage.seal.demo.tests/src/org/eclipse/passage/seal/demo/tests/{DemoFrameworkTest.java => DemoFrameworkContractTest.java} (87%) diff --git a/bundles/org.eclipse.passage.lic.base/src/org/eclipse/passage/lic/internal/base/registry/BaseRegistry.java b/bundles/org.eclipse.passage.lic.base/src/org/eclipse/passage/lic/internal/base/registry/BaseRegistry.java index 300572bc7..4af74a196 100644 --- a/bundles/org.eclipse.passage.lic.base/src/org/eclipse/passage/lic/internal/base/registry/BaseRegistry.java +++ b/bundles/org.eclipse.passage.lic.base/src/org/eclipse/passage/lic/internal/base/registry/BaseRegistry.java @@ -14,7 +14,8 @@ import java.util.Collection; import java.util.Map; -import java.util.function.Supplier; +import java.util.function.Function; +import java.util.stream.Collectors; import org.eclipse.passage.lic.internal.api.registry.Registry; import org.eclipse.passage.lic.internal.api.registry.Service; @@ -23,31 +24,37 @@ /** *

- * {@linkplain Registry} implementation that delegates actual service owning to - * the incoming {@linkplain Supplier} + * {@linkplain Registry} implementation that is filled and managed at runtime + * programmatically. *

* - * @param type of {@linkplain Service} to spread + *

+ * Not thread safe (yet) + *

+ *

+ * Null free zone. + *

+ * + * @param type of {@linkplain Service} to keep */ @SuppressWarnings("restriction") -public final class BaseRegistry> implements Registry { +public abstract class BaseRegistry> implements Registry { - private final Supplier> services; + protected final Map services; /** - * Primary constructor + * Convenience constructor * - * @param init {@linkplain Map} implementation to be used as service storing - * facility - * @param handler error handler + * @param service {@linkplain Collection} list of actual services to be owned by + * the registry */ - public BaseRegistry(Supplier> services) { - this.services = services; + public BaseRegistry(Collection service) { + this.services = service.stream().collect(Collectors.toMap(Service::id, Function.identity())); } @Override - public boolean hasService(I id) { - return services.get().stream().anyMatch(s -> id.equals(s.id())); + public final boolean hasService(I id) { + return services.containsKey(id); } /** @@ -60,17 +67,18 @@ public boolean hasService(I id) { * @throws IllegalStateException if not yet registered service is requested */ @Override - public S service(I id) { - return services.get().stream()// - .filter(s -> id.equals(s.id()))// - .findFirst().orElseThrow(() -> new IllegalStateException(String.format(// - BaseMessages.getString("Registry.retrieve_absent_exception"), //$NON-NLS-1$ - id))); + public final S service(I id) { + if (!hasService(id)) { + throw new IllegalStateException(String.format(// + BaseMessages.getString("Registry.retrieve_absent_exception"), //$NON-NLS-1$ + id)); + } + return services.get(id); } @Override - public Collection services() { - return services.get(); + public final Collection services() { + return services.values(); } } diff --git a/bundles/org.eclipse.passage.lic.base/src/org/eclipse/passage/lic/internal/base/registry/BaseRuntimeRegistry.java b/bundles/org.eclipse.passage.lic.base/src/org/eclipse/passage/lic/internal/base/registry/BaseRuntimeRegistry.java index 6a7f0f834..e32b94a34 100644 --- a/bundles/org.eclipse.passage.lic.base/src/org/eclipse/passage/lic/internal/base/registry/BaseRuntimeRegistry.java +++ b/bundles/org.eclipse.passage.lic.base/src/org/eclipse/passage/lic/internal/base/registry/BaseRuntimeRegistry.java @@ -13,8 +13,7 @@ package org.eclipse.passage.lic.internal.base.registry; import java.util.Collection; -import java.util.HashMap; -import java.util.Map; +import java.util.Collections; import java.util.Objects; import java.util.function.Consumer; @@ -40,37 +39,23 @@ * @param type of {@linkplain Service} to keep */ @SuppressWarnings("restriction") -public final class BaseRuntimeRegistry> implements RuntimeRegistry { +public final class BaseRuntimeRegistry> // + extends BaseRegistry // + implements RuntimeRegistry { - private final Map services; private final Consumer handler; - /** - * Primary constructor - * - * @param init {@linkplain Map} implementation to be used as service storing - * facility - * @param handler error handler - */ - public BaseRuntimeRegistry(Map init, Consumer handler) { - this.services = init; + public BaseRuntimeRegistry(Collection services, Consumer handler) { + super(services); this.handler = handler; } - /** - * Convenience constructor, uses {@linkplain HashMap} as a storage and prints - * errors into {@linkplain Stsrem.err} stream - */ - public BaseRuntimeRegistry() { - this(new HashMap<>(), System.err::println); - } - - public BaseRuntimeRegistry(Map init) { - this(init, System.err::println); + public BaseRuntimeRegistry(Consumer handler) { + this(Collections.emptyList(), handler); } - public BaseRuntimeRegistry(Consumer handler) { - this(new HashMap<>(), handler); + public BaseRuntimeRegistry() { + this(System.err::println); } @Override @@ -86,35 +71,6 @@ public void unregister(S service) { services.remove(service.id()); } - @Override - public boolean hasService(I id) { - return services.containsKey(id); - } - - /** - *

- * Get the previously registered service by it's {@code id}. It's mandatory to - * either be sure the service has been registered or to check - * {@linkplain #hasService(ServiceId)} first. - *

- * - * @throws IllegalStateException if not yet registered service is requested - */ - @Override - public S service(I id) { - if (!hasService(id)) { - throw new IllegalStateException(String.format(// - BaseMessages.getString("Registry.retrieve_absent_exception"), //$NON-NLS-1$ - id)); - } - return services.get(id); - } - - @Override - public Collection services() { - return services.values(); - } - private void checkOverride(S service) { if (!hasService(service.id())) { return; diff --git a/bundles/org.eclipse.passage.lic.base/src/org/eclipse/passage/lic/internal/base/registry/ReadOnlyRegistry.java b/bundles/org.eclipse.passage.lic.base/src/org/eclipse/passage/lic/internal/base/registry/ReadOnlyRegistry.java new file mode 100644 index 000000000..0997c48ba --- /dev/null +++ b/bundles/org.eclipse.passage.lic.base/src/org/eclipse/passage/lic/internal/base/registry/ReadOnlyRegistry.java @@ -0,0 +1,15 @@ +package org.eclipse.passage.lic.internal.base.registry; + +import java.util.Collection; + +import org.eclipse.passage.lic.internal.api.registry.Service; +import org.eclipse.passage.lic.internal.api.registry.ServiceId; + +@SuppressWarnings("restriction") +public final class ReadOnlyRegistry> extends BaseRegistry { + + public ReadOnlyRegistry(Collection service) { + super(service); + } + +} diff --git a/bundles/org.eclipse.passage.lic.equinox/OSGI-INF/org.eclipse.passage.lic.internal.equinox.EquinoxFramework.xml b/bundles/org.eclipse.passage.lic.equinox/OSGI-INF/org.eclipse.passage.lic.internal.equinox.EquinoxFramework.xml deleted file mode 100644 index 8f128c3d7..000000000 --- a/bundles/org.eclipse.passage.lic.equinox/OSGI-INF/org.eclipse.passage.lic.internal.equinox.EquinoxFramework.xml +++ /dev/null @@ -1,8 +0,0 @@ - - - - - - - - \ No newline at end of file diff --git a/bundles/org.eclipse.passage.lic.equinox/OSGI-INF/org.eclipse.passage.lic.internal.equinox.EquinoxResolvedRequirementsRegistry.xml b/bundles/org.eclipse.passage.lic.equinox/OSGI-INF/org.eclipse.passage.lic.internal.equinox.EquinoxResolvedRequirementsRegistry.xml deleted file mode 100644 index 1bc64cd81..000000000 --- a/bundles/org.eclipse.passage.lic.equinox/OSGI-INF/org.eclipse.passage.lic.internal.equinox.EquinoxResolvedRequirementsRegistry.xml +++ /dev/null @@ -1,8 +0,0 @@ - - - - - - - - \ No newline at end of file diff --git a/bundles/org.eclipse.passage.lic.equinox/OSGI-INF/org.eclipse.passage.lic.internal.equinox.requirements.BundleRequirements.xml b/bundles/org.eclipse.passage.lic.equinox/OSGI-INF/org.eclipse.passage.lic.internal.equinox.requirements.BundleRequirements.xml deleted file mode 100644 index 1d565916d..000000000 --- a/bundles/org.eclipse.passage.lic.equinox/OSGI-INF/org.eclipse.passage.lic.internal.equinox.requirements.BundleRequirements.xml +++ /dev/null @@ -1,7 +0,0 @@ - - - - - - - \ No newline at end of file diff --git a/bundles/org.eclipse.passage.lic.equinox/OSGI-INF/org.eclipse.passage.lic.internal.equinox.requirements.ComponentRequirements.xml b/bundles/org.eclipse.passage.lic.equinox/OSGI-INF/org.eclipse.passage.lic.internal.equinox.requirements.ComponentRequirements.xml deleted file mode 100644 index 98f4f0b1f..000000000 --- a/bundles/org.eclipse.passage.lic.equinox/OSGI-INF/org.eclipse.passage.lic.internal.equinox.requirements.ComponentRequirements.xml +++ /dev/null @@ -1,8 +0,0 @@ - - - - - - - - \ No newline at end of file diff --git a/bundles/org.eclipse.passage.lic.equinox/src/org/eclipse/passage/lic/internal/equinox/EquinoxFramework.java b/bundles/org.eclipse.passage.lic.equinox/src/org/eclipse/passage/lic/internal/equinox/EquinoxFramework.java deleted file mode 100644 index cbeb792c4..000000000 --- a/bundles/org.eclipse.passage.lic.equinox/src/org/eclipse/passage/lic/internal/equinox/EquinoxFramework.java +++ /dev/null @@ -1,42 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2020 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 org.eclipse.passage.lic.internal.api.Framework; -import org.eclipse.passage.lic.internal.api.requirements.ResolvedRequirementsRegistry; -import org.osgi.service.component.annotations.Component; -import org.osgi.service.component.annotations.Reference; - -@SuppressWarnings("restriction") -@Component -public final class EquinoxFramework implements Framework { - - private ResolvedRequirementsRegistry requirements; - - @Override - public ResolvedRequirementsRegistry requirementsRegistry() { - return requirements; - } - - @Reference - public void bind(ResolvedRequirementsRegistry registry) { - this.requirements = registry; - } - - public void unbind(ResolvedRequirementsRegistry registry) { - if (this.requirements.equals(registry)) { - this.requirements = null; - } - } - -} diff --git a/bundles/org.eclipse.passage.lic.equinox/src/org/eclipse/passage/lic/internal/equinox/EquinoxPassage.java b/bundles/org.eclipse.passage.lic.equinox/src/org/eclipse/passage/lic/internal/equinox/EquinoxPassage.java index 0151d4c8f..77d1f2e81 100644 --- a/bundles/org.eclipse.passage.lic.equinox/src/org/eclipse/passage/lic/internal/equinox/EquinoxPassage.java +++ b/bundles/org.eclipse.passage.lic.equinox/src/org/eclipse/passage/lic/internal/equinox/EquinoxPassage.java @@ -15,15 +15,28 @@ import java.util.Optional; import org.eclipse.passage.lic.internal.api.Framework; +import org.eclipse.passage.lic.internal.api.FrameworkSupplier; import org.eclipse.passage.lic.internal.api.Passage; import org.eclipse.passage.lic.internal.base.Access; +import org.eclipse.passage.lic.internal.equinox.i18n.EquinoxMessages; +import org.osgi.framework.BundleContext; +import org.osgi.framework.FrameworkUtil; +import org.osgi.framework.InvalidSyntaxException; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; @SuppressWarnings("restriction") public final class EquinoxPassage implements Passage { + private final Logger log = LoggerFactory.getLogger(EquinoxPassage.class); + @Override public boolean canUse(String feature) { - Optional framework = new FrameworkSupplier().get(); + Optional supplier = frameworkSupplier(); + if (!supplier.isPresent()) { + return false; + } + Optional framework = supplier.get().get(); if (!framework.isPresent()) { return false; } @@ -36,4 +49,19 @@ public void checkLicense(String feature) { throw new UnsupportedOperationException(); } + Optional frameworkSupplier() { + BundleContext context = FrameworkUtil.getBundle(getClass()).getBundleContext(); + try { + return context.getServiceReferences(FrameworkSupplier.class, null).stream() // + .map(context::getService) // + // DI is used only to get rid of overwhelming dependencies here + .filter(supplier -> supplier.getClass().getName() + .equals("org.eclipse.passage.seal.internal.demo.DemoFrameworkSupplier")) //$NON-NLS-1$ FIXME + .findAny(); + } catch (InvalidSyntaxException e) { + log.error(EquinoxMessages.EquinoxPassage_no_framework, e); + return Optional.empty(); + } + } + } diff --git a/bundles/org.eclipse.passage.lic.equinox/src/org/eclipse/passage/lic/internal/equinox/EquinoxResolvedRequirementsRegistry.java b/bundles/org.eclipse.passage.lic.equinox/src/org/eclipse/passage/lic/internal/equinox/EquinoxResolvedRequirementsRegistry.java deleted file mode 100644 index e9972abb5..000000000 --- a/bundles/org.eclipse.passage.lic.equinox/src/org/eclipse/passage/lic/internal/equinox/EquinoxResolvedRequirementsRegistry.java +++ /dev/null @@ -1,47 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2020 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 org.eclipse.passage.lic.internal.api.registry.Registry; -import org.eclipse.passage.lic.internal.api.registry.RuntimeRegistry; -import org.eclipse.passage.lic.internal.api.registry.StringServiceId; -import org.eclipse.passage.lic.internal.api.requirements.ResolvedRequirements; -import org.eclipse.passage.lic.internal.api.requirements.ResolvedRequirementsRegistry; -import org.eclipse.passage.lic.internal.base.registry.BaseRuntimeRegistry; -import org.osgi.service.component.annotations.Component; -import org.osgi.service.component.annotations.Reference; -import org.osgi.service.component.annotations.ReferenceCardinality; - -@SuppressWarnings("restriction") - -@Component -public final class EquinoxResolvedRequirementsRegistry implements ResolvedRequirementsRegistry { - - private final RuntimeRegistry registry = // - new BaseRuntimeRegistry(); - - @Override - public Registry get() { - return registry; - } - - @Reference(cardinality = ReferenceCardinality.MULTIPLE) - public void add(ResolvedRequirements service) { - registry.register(service); - } - - public void remove(ResolvedRequirements service) { - registry.unregister(service); - } - -} diff --git a/bundles/org.eclipse.passage.lic.equinox/src/org/eclipse/passage/lic/internal/equinox/requirements/BundleRequirements.java b/bundles/org.eclipse.passage.lic.equinox/src/org/eclipse/passage/lic/internal/equinox/requirements/BundleRequirements.java index b166b8213..d54f51066 100644 --- a/bundles/org.eclipse.passage.lic.equinox/src/org/eclipse/passage/lic/internal/equinox/requirements/BundleRequirements.java +++ b/bundles/org.eclipse.passage.lic.equinox/src/org/eclipse/passage/lic/internal/equinox/requirements/BundleRequirements.java @@ -26,8 +26,8 @@ import org.eclipse.passage.lic.internal.base.requirements.UnsatisfiableRequirement; import org.eclipse.passage.lic.internal.equinox.i18n.EquinoxMessages; import org.osgi.framework.BundleContext; +import org.osgi.framework.FrameworkUtil; import org.osgi.service.component.annotations.Activate; -import org.osgi.service.component.annotations.Component; import org.osgi.service.component.annotations.Deactivate; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -43,15 +43,14 @@ * @see ResolvedRequirements */ @SuppressWarnings("restriction") -@Component public final class BundleRequirements implements ResolvedRequirements { private final Logger logger = LoggerFactory.getLogger(BundleRequirements.class); private Optional context; @Activate - public void activate(BundleContext bundle) { - this.context = Optional.ofNullable(bundle); + public void activate() { + this.context = Optional.ofNullable(FrameworkUtil.getBundle(getClass()).getBundleContext()); } @Deactivate diff --git a/bundles/org.eclipse.passage.lic.equinox/src/org/eclipse/passage/lic/internal/equinox/requirements/ComponentRequirements.java b/bundles/org.eclipse.passage.lic.equinox/src/org/eclipse/passage/lic/internal/equinox/requirements/ComponentRequirements.java index 63a99be3d..03a24f2b0 100644 --- a/bundles/org.eclipse.passage.lic.equinox/src/org/eclipse/passage/lic/internal/equinox/requirements/ComponentRequirements.java +++ b/bundles/org.eclipse.passage.lic.equinox/src/org/eclipse/passage/lic/internal/equinox/requirements/ComponentRequirements.java @@ -24,8 +24,8 @@ import org.eclipse.passage.lic.internal.base.requirements.UnsatisfiableRequirement; import org.eclipse.passage.lic.internal.equinox.i18n.EquinoxMessages; import org.osgi.framework.BundleContext; +import org.osgi.framework.FrameworkUtil; import org.osgi.service.component.annotations.Activate; -import org.osgi.service.component.annotations.Component; import org.osgi.service.component.annotations.Deactivate; import org.osgi.service.component.annotations.Reference; import org.osgi.service.component.runtime.ServiceComponentRuntime; @@ -40,13 +40,23 @@ * @see ResolvedRequirements */ @SuppressWarnings("restriction") -@Component public final class ComponentRequirements implements ResolvedRequirements { private final Logger logger = LoggerFactory.getLogger(BundleRequirements.class); - private Optional context = Optional.empty(); - private Optional runtime = Optional.empty(); + private Optional context; + private Optional runtime; + + public ComponentRequirements() { + context = Optional.of(FrameworkUtil.getBundle(getClass()).getBundleContext()); + runtime = retrieveRuntime(); + } + + private Optional retrieveRuntime() { + BundleContext bundle = context.get(); + return Optional.ofNullable(bundle.getServiceReference(ServiceComponentRuntime.class)) + .map(ref -> bundle.getService(ref)); + } @Override public StringServiceId id() { diff --git a/releng/org.eclipse.passage.demo.aggregator/pom.xml b/releng/org.eclipse.passage.demo.aggregator/pom.xml index 3eeddec53..48403ef76 100644 --- a/releng/org.eclipse.passage.demo.aggregator/pom.xml +++ b/releng/org.eclipse.passage.demo.aggregator/pom.xml @@ -29,7 +29,7 @@ ../../bundles/org.eclipse.passage.seal.demo ../../features/org.eclipse.passage.demo.feature - ../../tests/org.eclipse.passage.seal.tests + ../../tests/org.eclipse.passage.seal.demo.tests \ No newline at end of file diff --git a/releng/org.eclipse.passage.lic.aggregator/pom.xml b/releng/org.eclipse.passage.lic.aggregator/pom.xml index 2eea818d6..e753dbc3a 100644 --- a/releng/org.eclipse.passage.lic.aggregator/pom.xml +++ b/releng/org.eclipse.passage.lic.aggregator/pom.xml @@ -30,6 +30,8 @@ ../../bundles/org.eclipse.passage.lic.api + ../../tests/org.eclipse.passage.lic.api.tests + ../../bundles/org.eclipse.passage.lic.base ../../bundles/org.eclipse.passage.lic.equinox ../../features/org.eclipse.passage.lic.equinox.feature diff --git a/tests/org.eclipse.passage.lic.base.tests/src/org/eclipse/passage/lic/internal/base/SabotagedFramework.java b/tests/org.eclipse.passage.lic.base.tests/src/org/eclipse/passage/lic/internal/base/SabotagedFramework.java index 4ae578d42..49e541377 100644 --- a/tests/org.eclipse.passage.lic.base.tests/src/org/eclipse/passage/lic/internal/base/SabotagedFramework.java +++ b/tests/org.eclipse.passage.lic.base.tests/src/org/eclipse/passage/lic/internal/base/SabotagedFramework.java @@ -12,14 +12,14 @@ *******************************************************************************/ package org.eclipse.passage.lic.internal.base; -import java.util.Collections; +import java.util.ArrayList; import org.eclipse.passage.lic.internal.api.Framework; import org.eclipse.passage.lic.internal.api.registry.Registry; import org.eclipse.passage.lic.internal.api.registry.StringServiceId; import org.eclipse.passage.lic.internal.api.requirements.ResolvedRequirements; import org.eclipse.passage.lic.internal.api.requirements.ResolvedRequirementsRegistry; -import org.eclipse.passage.lic.internal.base.registry.BaseRegistry; +import org.eclipse.passage.lic.internal.base.registry.ReadOnlyRegistry; @SuppressWarnings("restriction") final class SabotagedFramework implements Framework { @@ -33,7 +33,7 @@ private static class NoResolvers implements ResolvedRequirementsRegistry { @Override public Registry get() { - return new BaseRegistry(Collections::emptyList); + return new ReadOnlyRegistry(new ArrayList<>()); } } diff --git a/tests/org.eclipse.passage.seal.demo.tests/META-INF/MANIFEST.MF b/tests/org.eclipse.passage.seal.demo.tests/META-INF/MANIFEST.MF index 75420edfb..369a1c7f1 100644 --- a/tests/org.eclipse.passage.seal.demo.tests/META-INF/MANIFEST.MF +++ b/tests/org.eclipse.passage.seal.demo.tests/META-INF/MANIFEST.MF @@ -11,5 +11,6 @@ Require-Bundle: org.junit;bundle-version="4.12.0", org.eclipse.osgi.services;bundle-version="0.0.0", org.eclipse.passage.seal.demo;bundle-version="0.0.0", org.eclipse.passage.lic.api.tests;bundle-version="0.0.0", - org.eclipse.passage.lic.api -Export-Package: org.eclipse.passage.seal.tests + org.eclipse.passage.lic.api, + org.eclipse.passage.lic.equinox +Export-Package: org.eclipse.passage.seal.demo.tests diff --git a/tests/org.eclipse.passage.lic.equinox.tests/src/org/eclipse/passage/lic/internal/equinox/EquinoxFrameworkSupplierTest.java b/tests/org.eclipse.passage.seal.demo.tests/src/org/eclipse/passage/seal/demo/tests/DemoFrameworkContentTest.java similarity index 74% rename from tests/org.eclipse.passage.lic.equinox.tests/src/org/eclipse/passage/lic/internal/equinox/EquinoxFrameworkSupplierTest.java rename to tests/org.eclipse.passage.seal.demo.tests/src/org/eclipse/passage/seal/demo/tests/DemoFrameworkContentTest.java index fc4dc9886..03b9ab8c0 100644 --- a/tests/org.eclipse.passage.lic.equinox.tests/src/org/eclipse/passage/lic/internal/equinox/EquinoxFrameworkSupplierTest.java +++ b/tests/org.eclipse.passage.seal.demo.tests/src/org/eclipse/passage/seal/demo/tests/DemoFrameworkContentTest.java @@ -1,16 +1,4 @@ -/******************************************************************************* - * Copyright (c) 2020 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; +package org.eclipse.passage.seal.demo.tests; import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertNotNull; @@ -28,14 +16,14 @@ import org.eclipse.passage.lic.internal.api.requirements.ResolvedRequirementsRegistry; import org.eclipse.passage.lic.internal.equinox.requirements.BundleRequirements; import org.eclipse.passage.lic.internal.equinox.requirements.ComponentRequirements; +import org.eclipse.passage.seal.internal.demo.DemoFrameworkSupplier; import org.junit.Test; @SuppressWarnings("restriction") -public final class EquinoxFrameworkSupplierTest { - +public final class DemoFrameworkContentTest { @Test public void accessible() { - assertTrue(new FrameworkSupplier().get().isPresent()); + assertTrue(new DemoFrameworkSupplier().get().isPresent()); } @Test @@ -60,7 +48,7 @@ private > void assertHasService(// } private Framework framework() { - Optional framework = new FrameworkSupplier().get(); + Optional framework = new DemoFrameworkSupplier().get(); assumeTrue(framework.isPresent()); return framework.get(); } @@ -71,5 +59,4 @@ private Registry registry() { assumeTrue(registry.isPresent()); return registry.get().get(); } - } diff --git a/tests/org.eclipse.passage.seal.demo.tests/src/org/eclipse/passage/seal/demo/tests/DemoFrameworkTest.java b/tests/org.eclipse.passage.seal.demo.tests/src/org/eclipse/passage/seal/demo/tests/DemoFrameworkContractTest.java similarity index 87% rename from tests/org.eclipse.passage.seal.demo.tests/src/org/eclipse/passage/seal/demo/tests/DemoFrameworkTest.java rename to tests/org.eclipse.passage.seal.demo.tests/src/org/eclipse/passage/seal/demo/tests/DemoFrameworkContractTest.java index 505b7d7b7..049078228 100644 --- a/tests/org.eclipse.passage.seal.demo.tests/src/org/eclipse/passage/seal/demo/tests/DemoFrameworkTest.java +++ b/tests/org.eclipse.passage.seal.demo.tests/src/org/eclipse/passage/seal/demo/tests/DemoFrameworkContractTest.java @@ -9,7 +9,7 @@ import org.eclipse.passage.seal.internal.demo.DemoFrameworkSupplier; @SuppressWarnings("restriction") -public final class DemoFrameworkTest extends FrameworkContractTest{ +public final class DemoFrameworkContractTest extends FrameworkContractTest{ @Override protected Optional framework() { From a520c7ee3410a494b0993e88c58344897bcc0865 Mon Sep 17 00:00:00 2001 From: "elena.parovyshnaya" Date: Mon, 15 Jun 2020 13:10:15 +0300 Subject: [PATCH 03/10] Bug 564282 - API revision | question extensibility - remove outdated OSGi-component life cycle methods Signed-off-by: elena.parovyshnaya --- .../requirements/BundleRequirements.java | 13 --------- .../requirements/ComponentRequirements.java | 27 ------------------- 2 files changed, 40 deletions(-) diff --git a/bundles/org.eclipse.passage.lic.equinox/src/org/eclipse/passage/lic/internal/equinox/requirements/BundleRequirements.java b/bundles/org.eclipse.passage.lic.equinox/src/org/eclipse/passage/lic/internal/equinox/requirements/BundleRequirements.java index d54f51066..73f04fabe 100644 --- a/bundles/org.eclipse.passage.lic.equinox/src/org/eclipse/passage/lic/internal/equinox/requirements/BundleRequirements.java +++ b/bundles/org.eclipse.passage.lic.equinox/src/org/eclipse/passage/lic/internal/equinox/requirements/BundleRequirements.java @@ -26,9 +26,6 @@ import org.eclipse.passage.lic.internal.base.requirements.UnsatisfiableRequirement; import org.eclipse.passage.lic.internal.equinox.i18n.EquinoxMessages; import org.osgi.framework.BundleContext; -import org.osgi.framework.FrameworkUtil; -import org.osgi.service.component.annotations.Activate; -import org.osgi.service.component.annotations.Deactivate; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -48,16 +45,6 @@ public final class BundleRequirements implements ResolvedRequirements { private final Logger logger = LoggerFactory.getLogger(BundleRequirements.class); private Optional context; - @Activate - public void activate() { - this.context = Optional.ofNullable(FrameworkUtil.getBundle(getClass()).getBundleContext()); - } - - @Deactivate - public void deactivate() { - this.context = Optional.empty(); - } - @Override public StringServiceId id() { return new StringServiceId("manifest"); //$NON-NLS-1$ diff --git a/bundles/org.eclipse.passage.lic.equinox/src/org/eclipse/passage/lic/internal/equinox/requirements/ComponentRequirements.java b/bundles/org.eclipse.passage.lic.equinox/src/org/eclipse/passage/lic/internal/equinox/requirements/ComponentRequirements.java index 03a24f2b0..b95feaad5 100644 --- a/bundles/org.eclipse.passage.lic.equinox/src/org/eclipse/passage/lic/internal/equinox/requirements/ComponentRequirements.java +++ b/bundles/org.eclipse.passage.lic.equinox/src/org/eclipse/passage/lic/internal/equinox/requirements/ComponentRequirements.java @@ -25,9 +25,6 @@ import org.eclipse.passage.lic.internal.equinox.i18n.EquinoxMessages; import org.osgi.framework.BundleContext; import org.osgi.framework.FrameworkUtil; -import org.osgi.service.component.annotations.Activate; -import org.osgi.service.component.annotations.Deactivate; -import org.osgi.service.component.annotations.Reference; import org.osgi.service.component.runtime.ServiceComponentRuntime; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -63,30 +60,6 @@ public StringServiceId id() { return new StringServiceId("OSGi component"); //$NON-NLS-1$ } - @Activate - public void activate(BundleContext bundle) { - this.context = Optional.ofNullable(bundle); - } - - @Deactivate - public void deactivate() { - this.context = Optional.empty(); - } - - @Reference - public void bindRuntime(ServiceComponentRuntime input) { - this.runtime = Optional.ofNullable(input); - } - - public void unbindRuntime(ServiceComponentRuntime input) { - if (!runtime.isPresent()) { - return; - } - if (runtime.get() == input) { - runtime = Optional.empty(); - } - } - @Override public Collection all() { if (!runtime.isPresent()) { From d7e8a1a082408eae02d90e7b4bdd11807cbe14ca Mon Sep 17 00:00:00 2001 From: "elena.parovyshnaya" Date: Mon, 15 Jun 2020 14:13:36 +0300 Subject: [PATCH 04/10] Bug 564282 - API revision | question extensibility - add single workable test among all the abstract ones to 'api.tests' bundle to make sure-fire go Signed-off-by: elena.parovyshnaya --- .../passage/lic/api/tests/TemporaryTest.java | 26 +++++++++++++++++++ 1 file changed, 26 insertions(+) create mode 100644 tests/org.eclipse.passage.lic.api.tests/src/org/eclipse/passage/lic/api/tests/TemporaryTest.java diff --git a/tests/org.eclipse.passage.lic.api.tests/src/org/eclipse/passage/lic/api/tests/TemporaryTest.java b/tests/org.eclipse.passage.lic.api.tests/src/org/eclipse/passage/lic/api/tests/TemporaryTest.java new file mode 100644 index 000000000..0e080b068 --- /dev/null +++ b/tests/org.eclipse.passage.lic.api.tests/src/org/eclipse/passage/lic/api/tests/TemporaryTest.java @@ -0,0 +1,26 @@ +package org.eclipse.passage.lic.api.tests; + +import static org.junit.Assert.assertTrue; + +import org.junit.Test; + +public final class TemporaryTest { + /** + *

+ * There only contract (meaning abstract) tests in this bundle. Nonetheless, + * it's still recognized as 'tests' bundle. All the special treatments are + * applied: sure-fire plug-in is applied. This one fails on a bundle where is + * nothing to run. + *

+ * + *

+ * Thus we add a single deadly stupid but workable test especially for sure-fire + * to make it go. + *

+ */ + @Test + public void singleWorkableTestInABundleFullOfAbstractTest() { + assertTrue(System.currentTimeMillis() > 0); + } + +} From e79fac45ed201c4dbd0a8c80562a15e8b24b1efa Mon Sep 17 00:00:00 2001 From: "elena.parovyshnaya" Date: Mon, 15 Jun 2020 14:28:09 +0300 Subject: [PATCH 05/10] Bug 564282 - API revision | question extensibility - document framework contract test idea Signed-off-by: elena.parovyshnaya --- .../passage/lic/api/tests/FrameworkContractTest.java | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/tests/org.eclipse.passage.lic.api.tests/src/org/eclipse/passage/lic/api/tests/FrameworkContractTest.java b/tests/org.eclipse.passage.lic.api.tests/src/org/eclipse/passage/lic/api/tests/FrameworkContractTest.java index 9837589da..66923aa8f 100644 --- a/tests/org.eclipse.passage.lic.api.tests/src/org/eclipse/passage/lic/api/tests/FrameworkContractTest.java +++ b/tests/org.eclipse.passage.lic.api.tests/src/org/eclipse/passage/lic/api/tests/FrameworkContractTest.java @@ -12,6 +12,16 @@ import org.eclipse.passage.lic.internal.api.requirements.ResolvedRequirements; import org.junit.Test; +/** + *

+ * Here we check severe assumptions Passage does about instance of + * {@linkplain Framework} interface it operates with. + *

+ *

+ * Each sealed {@linkplain Framework} implementation must follow the contract: + * extend the test, supply a framework instance and succeed at every test. + *

+ */ @SuppressWarnings("restriction") public abstract class FrameworkContractTest { @@ -46,5 +56,5 @@ public void prohibitsInjectionIntoRequirementResolutionServices() { protected abstract Optional framework(); protected abstract boolean readOnly(Registry registry); - + } From d1cabe2a9b5b88718834c013b4ed4894d5d37d84 Mon Sep 17 00:00:00 2001 From: "elena.parovyshnaya" Date: Mon, 15 Jun 2020 14:46:34 +0300 Subject: [PATCH 06/10] Bug 564282 - API revision: question extensibility - finalize fields ex- OSGi components Signed-off-by: elena.parovyshnaya --- .../internal/equinox/requirements/BundleRequirements.java | 7 ++++++- .../equinox/requirements/ComponentRequirements.java | 5 ++--- 2 files changed, 8 insertions(+), 4 deletions(-) diff --git a/bundles/org.eclipse.passage.lic.equinox/src/org/eclipse/passage/lic/internal/equinox/requirements/BundleRequirements.java b/bundles/org.eclipse.passage.lic.equinox/src/org/eclipse/passage/lic/internal/equinox/requirements/BundleRequirements.java index 73f04fabe..6286164df 100644 --- a/bundles/org.eclipse.passage.lic.equinox/src/org/eclipse/passage/lic/internal/equinox/requirements/BundleRequirements.java +++ b/bundles/org.eclipse.passage.lic.equinox/src/org/eclipse/passage/lic/internal/equinox/requirements/BundleRequirements.java @@ -26,6 +26,7 @@ import org.eclipse.passage.lic.internal.base.requirements.UnsatisfiableRequirement; import org.eclipse.passage.lic.internal.equinox.i18n.EquinoxMessages; import org.osgi.framework.BundleContext; +import org.osgi.framework.FrameworkUtil; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -43,7 +44,11 @@ public final class BundleRequirements implements ResolvedRequirements { private final Logger logger = LoggerFactory.getLogger(BundleRequirements.class); - private Optional context; + private final Optional context; + + public BundleRequirements() { + context = Optional.of(FrameworkUtil.getBundle(getClass()).getBundleContext()); + } @Override public StringServiceId id() { diff --git a/bundles/org.eclipse.passage.lic.equinox/src/org/eclipse/passage/lic/internal/equinox/requirements/ComponentRequirements.java b/bundles/org.eclipse.passage.lic.equinox/src/org/eclipse/passage/lic/internal/equinox/requirements/ComponentRequirements.java index b95feaad5..3804b2e3f 100644 --- a/bundles/org.eclipse.passage.lic.equinox/src/org/eclipse/passage/lic/internal/equinox/requirements/ComponentRequirements.java +++ b/bundles/org.eclipse.passage.lic.equinox/src/org/eclipse/passage/lic/internal/equinox/requirements/ComponentRequirements.java @@ -40,9 +40,8 @@ public final class ComponentRequirements implements ResolvedRequirements { private final Logger logger = LoggerFactory.getLogger(BundleRequirements.class); - - private Optional context; - private Optional runtime; + private final Optional context; + private final Optional runtime; public ComponentRequirements() { context = Optional.of(FrameworkUtil.getBundle(getClass()).getBundleContext()); From c88f2e10ffb461b3ec4ad0be9ca9fc15182d0fb2 Mon Sep 17 00:00:00 2001 From: "elena.parovyshnaya" Date: Mon, 15 Jun 2020 15:13:40 +0300 Subject: [PATCH 07/10] Bug 564282 - API revision: question extensibility - explain, generalize and extend api contract tests - reimplement existing requirement resolution services tests basing on contract assumptions checking - test requirement resolution services registry, supplied by demo framework (make sure it follows the contract) Signed-off-by: elena.parovyshnaya --- .../lic/api/tests/FrameworkContractTest.java | 12 +++ ...eworkRequirementResolutionServiceTest.java | 48 +++++++++++ .../lic/api/tests/ReadOnlyCollectionTest.java | 83 +++++++++++++++++++ .../ResolvedReqiorementsContractTest.java | 46 ---------- .../ResolvedRequirementsContractTest.java | 41 +++++++++ .../passage/lic/api/tests/TemporaryTest.java | 12 +++ .../META-INF/MANIFEST.MF | 3 +- .../ResolvedRequirementsServiceTest.java | 33 +++++--- .../demo/tests/DemoFrameworkContentTest.java | 12 +++ .../demo/tests/DemoFrameworkContractTest.java | 12 +++ ...eworkRequirementResolutionServiceTest.java | 29 +++++++ 11 files changed, 271 insertions(+), 60 deletions(-) create mode 100644 tests/org.eclipse.passage.lic.api.tests/src/org/eclipse/passage/lic/api/tests/FrameworkRequirementResolutionServiceTest.java create mode 100644 tests/org.eclipse.passage.lic.api.tests/src/org/eclipse/passage/lic/api/tests/ReadOnlyCollectionTest.java delete mode 100644 tests/org.eclipse.passage.lic.api.tests/src/org/eclipse/passage/lic/api/tests/ResolvedReqiorementsContractTest.java create mode 100644 tests/org.eclipse.passage.lic.api.tests/src/org/eclipse/passage/lic/api/tests/ResolvedRequirementsContractTest.java create mode 100644 tests/org.eclipse.passage.seal.demo.tests/src/org/eclipse/passage/seal/demo/tests/DemoFrameworkRequirementResolutionServiceTest.java diff --git a/tests/org.eclipse.passage.lic.api.tests/src/org/eclipse/passage/lic/api/tests/FrameworkContractTest.java b/tests/org.eclipse.passage.lic.api.tests/src/org/eclipse/passage/lic/api/tests/FrameworkContractTest.java index 66923aa8f..e9bc45040 100644 --- a/tests/org.eclipse.passage.lic.api.tests/src/org/eclipse/passage/lic/api/tests/FrameworkContractTest.java +++ b/tests/org.eclipse.passage.lic.api.tests/src/org/eclipse/passage/lic/api/tests/FrameworkContractTest.java @@ -1,3 +1,15 @@ +/******************************************************************************* + * Copyright (c) 2020 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.api.tests; import static org.junit.Assert.assertNotNull; diff --git a/tests/org.eclipse.passage.lic.api.tests/src/org/eclipse/passage/lic/api/tests/FrameworkRequirementResolutionServiceTest.java b/tests/org.eclipse.passage.lic.api.tests/src/org/eclipse/passage/lic/api/tests/FrameworkRequirementResolutionServiceTest.java new file mode 100644 index 000000000..553c4b03b --- /dev/null +++ b/tests/org.eclipse.passage.lic.api.tests/src/org/eclipse/passage/lic/api/tests/FrameworkRequirementResolutionServiceTest.java @@ -0,0 +1,48 @@ +/******************************************************************************* + * Copyright (c) 2020 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.api.tests; + +import java.util.Collection; +import java.util.Optional; +import java.util.function.Supplier; + +import org.eclipse.passage.lic.api.tests.fakes.FakeResolvedRequirements; +import org.eclipse.passage.lic.internal.api.Framework; +import org.eclipse.passage.lic.internal.api.requirements.ResolvedRequirements; + +/** + *

+ * Check that {@linkplain Framework} instance in use supplies read only + * collection of requirement resolution services. + *

+ *

+ * Each {@code Framework} implementation must extend this class and satisfy all + * the demands. + *

+ */ +@SuppressWarnings("restriction") +public abstract class FrameworkRequirementResolutionServiceTest extends ReadOnlyCollectionTest { + + @Override + protected Supplier> collection() { + return () -> framework().get().requirementsRegistry().get().services(); + } + + @Override + protected ResolvedRequirements single() { + return new FakeResolvedRequirements(); + } + + protected abstract Optional framework(); + +} diff --git a/tests/org.eclipse.passage.lic.api.tests/src/org/eclipse/passage/lic/api/tests/ReadOnlyCollectionTest.java b/tests/org.eclipse.passage.lic.api.tests/src/org/eclipse/passage/lic/api/tests/ReadOnlyCollectionTest.java new file mode 100644 index 000000000..02b7e578e --- /dev/null +++ b/tests/org.eclipse.passage.lic.api.tests/src/org/eclipse/passage/lic/api/tests/ReadOnlyCollectionTest.java @@ -0,0 +1,83 @@ +/******************************************************************************* + * Copyright (c) 2020 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.api.tests; + +import static org.junit.Assert.assertTrue; +import static org.junit.Assume.assumeTrue; + +import java.util.Collection; +import java.util.Collections; +import java.util.function.Consumer; +import java.util.function.Supplier; + +import org.junit.Test; + +/** + *

+ * Here we check an arbitrary service method, that returns multiple results as a + * collection for being read only. + *

+ *

+ * Each requirement resolution service must follow the contract. + *

+ */ +public abstract class ReadOnlyCollectionTest { + + @Test + public void prohibitsInjections() { + testInterferenceResistence(shared -> shared.add(single())); + testInterferenceResistence(shared -> shared.addAll(Collections.singleton(single()))); + } + + @Test + public void prohibitsRemovals() { + assumeTrue(collection().get().size() > 0); + testInterferenceResistence(Collection::clear); + testInterferenceResistence(shared -> shared.retainAll(Collections.emptyList())); + testInterferenceResistence(shared -> shared.removeAll(shared)); + testInterferenceResistence(shared -> shared.remove(shared.iterator().next())); + } + + /** + * + * @param interference alternation action over the collection supplying method + * result. Each {@code interference} operation must either + * be unsupported or cause no alternation to subsequent + * service method result. + */ + private void testInterferenceResistence(Consumer> interference) { + // given + Collection shared = collection().get(); + int before = shared.size(); + // when + try { + interference.accept(shared); + } catch (UnsupportedOperationException unsupported) { + // then (hooray! unsupported! no alternation either way!) + return; + } + // then + assertTrue(before == collection().get().size()); + } + + /** + * Define supplying service method under test + */ + protected abstract Supplier> collection(); + + /** + * Supply single instance of T here + */ + protected abstract T single(); + +} diff --git a/tests/org.eclipse.passage.lic.api.tests/src/org/eclipse/passage/lic/api/tests/ResolvedReqiorementsContractTest.java b/tests/org.eclipse.passage.lic.api.tests/src/org/eclipse/passage/lic/api/tests/ResolvedReqiorementsContractTest.java deleted file mode 100644 index 4e1a2cc9c..000000000 --- a/tests/org.eclipse.passage.lic.api.tests/src/org/eclipse/passage/lic/api/tests/ResolvedReqiorementsContractTest.java +++ /dev/null @@ -1,46 +0,0 @@ -package org.eclipse.passage.lic.api.tests; - -import static org.junit.Assert.assertTrue; -import static org.junit.Assume.assumeTrue; - -import java.util.Collection; -import java.util.Collections; -import java.util.function.Consumer; - -import org.eclipse.passage.lic.api.tests.fakes.FakeRequirement; -import org.eclipse.passage.lic.internal.api.requirements.Requirement; -import org.eclipse.passage.lic.internal.api.requirements.ResolvedRequirements; -import org.junit.Test; - -@SuppressWarnings("restriction") -public abstract class ResolvedReqiorementsContractTest { - - @Test - public void prohibitsInjectionIntoResolvedRequirements() { - testInterferenceResistence(shared -> shared.add(new FakeRequirement())); - testInterferenceResistence(shared -> shared.addAll(Collections.singleton(new FakeRequirement()))); - } - - @Test - public void prohibitsRemovalFromResolvedRequirements() { - assumeTrue(service().all().size() > 0); - testInterferenceResistence(Collection::clear); - testInterferenceResistence(shared -> shared.retainAll(Collections.emptyList())); - testInterferenceResistence(shared -> shared.removeAll(shared)); - testInterferenceResistence(shared -> shared.remove(shared.iterator().next())); - } - - private void testInterferenceResistence(Consumer> interference) { - // given - ResolvedRequirements service = service(); - Collection shared = service.all(); - int before = shared.size(); - // when - shared.clear(); - // then - assertTrue(before == service.all().size()); - } - - protected abstract ResolvedRequirements service(); - -} diff --git a/tests/org.eclipse.passage.lic.api.tests/src/org/eclipse/passage/lic/api/tests/ResolvedRequirementsContractTest.java b/tests/org.eclipse.passage.lic.api.tests/src/org/eclipse/passage/lic/api/tests/ResolvedRequirementsContractTest.java new file mode 100644 index 000000000..b71f543ed --- /dev/null +++ b/tests/org.eclipse.passage.lic.api.tests/src/org/eclipse/passage/lic/api/tests/ResolvedRequirementsContractTest.java @@ -0,0 +1,41 @@ +/******************************************************************************* + * Copyright (c) 2020 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.api.tests; + +import java.util.Collection; +import java.util.function.Supplier; + +import org.eclipse.passage.lic.api.tests.fakes.FakeRequirement; +import org.eclipse.passage.lic.internal.api.requirements.Requirement; +import org.eclipse.passage.lic.internal.api.requirements.ResolvedRequirements; + +/** + * Each requirement resolution service must follow the contract. + * + * @author user + * + */ +@SuppressWarnings("restriction") +public abstract class ResolvedRequirementsContractTest extends ReadOnlyCollectionTest { + + protected Supplier> collection() { + return service()::all; + } + + protected Requirement single() { + return new FakeRequirement(); + } + + protected abstract ResolvedRequirements service(); + +} diff --git a/tests/org.eclipse.passage.lic.api.tests/src/org/eclipse/passage/lic/api/tests/TemporaryTest.java b/tests/org.eclipse.passage.lic.api.tests/src/org/eclipse/passage/lic/api/tests/TemporaryTest.java index 0e080b068..f6f38a6a5 100644 --- a/tests/org.eclipse.passage.lic.api.tests/src/org/eclipse/passage/lic/api/tests/TemporaryTest.java +++ b/tests/org.eclipse.passage.lic.api.tests/src/org/eclipse/passage/lic/api/tests/TemporaryTest.java @@ -1,3 +1,15 @@ +/******************************************************************************* + * Copyright (c) 2020 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.api.tests; import static org.junit.Assert.assertTrue; diff --git a/tests/org.eclipse.passage.lic.equinox.tests/META-INF/MANIFEST.MF b/tests/org.eclipse.passage.lic.equinox.tests/META-INF/MANIFEST.MF index 3518c1774..02f89b44d 100644 --- a/tests/org.eclipse.passage.lic.equinox.tests/META-INF/MANIFEST.MF +++ b/tests/org.eclipse.passage.lic.equinox.tests/META-INF/MANIFEST.MF @@ -15,4 +15,5 @@ Require-Bundle: org.junit;bundle-version="0.0.0", org.eclipse.equinox.event;bundle-version="0.0.0", org.eclipse.passage.lic.base;bundle-version="0.0.0", org.eclipse.passage.lic.equinox.tests.data.requirements;bundle-version="0.1.0", - org.eclipse.passage.lic.base.tests + org.eclipse.passage.lic.base.tests, + org.eclipse.passage.lic.api.tests diff --git a/tests/org.eclipse.passage.lic.equinox.tests/src/org/eclipse/passage/lic/internal/equinox/requirements/ResolvedRequirementsServiceTest.java b/tests/org.eclipse.passage.lic.equinox.tests/src/org/eclipse/passage/lic/internal/equinox/requirements/ResolvedRequirementsServiceTest.java index dfb1379d4..87653a3a9 100644 --- a/tests/org.eclipse.passage.lic.equinox.tests/src/org/eclipse/passage/lic/internal/equinox/requirements/ResolvedRequirementsServiceTest.java +++ b/tests/org.eclipse.passage.lic.equinox.tests/src/org/eclipse/passage/lic/internal/equinox/requirements/ResolvedRequirementsServiceTest.java @@ -23,15 +23,17 @@ import java.util.Set; import java.util.stream.Collectors; +import org.eclipse.passage.lic.api.tests.ResolvedRequirementsContractTest; import org.eclipse.passage.lic.internal.api.requirements.Requirement; import org.eclipse.passage.lic.internal.api.requirements.ResolvedRequirements; import org.junit.Test; import org.osgi.framework.BundleContext; import org.osgi.framework.FrameworkUtil; import org.osgi.framework.InvalidSyntaxException; +import org.osgi.framework.ServiceReference; @SuppressWarnings("restriction") -abstract class ResolvedRequirementsServiceTest { +abstract class ResolvedRequirementsServiceTest extends ResolvedRequirementsContractTest { @Test public void providedAsResolvedRequirementsImpl() throws InvalidSyntaxException { @@ -56,24 +58,29 @@ public void requirementsForFeature() throws InvalidSyntaxException { new HashSet(forTheFeature)); } - protected abstract Class serviceClass(); - - protected abstract Set expectations(); - - protected abstract Requirement single(); + @Override + protected ResolvedRequirements service() { + Optional service = mayBeService(); + assumeTrue(service.isPresent()); + return service.get(); + } - private Optional mayBeService() throws InvalidSyntaxException { + private Optional mayBeService() { BundleContext context = FrameworkUtil.getBundle(getClass()).getBundleContext(); - return context.getServiceReferences(ResolvedRequirements.class, null).stream() // + Collection> refs; + try { + refs = context.getServiceReferences(ResolvedRequirements.class, null); // API-dictated null + } catch (InvalidSyntaxException e) { + return Optional.empty(); + } + return refs.stream() // .map(s -> context.getService(s)) // .filter(s -> s.getClass() == serviceClass()) // .findAny(); } - private ResolvedRequirements service() throws InvalidSyntaxException { - Optional service = mayBeService(); - assumeTrue(service.isPresent()); - return service.get(); - } + protected abstract Class serviceClass(); + + protected abstract Set expectations(); } diff --git a/tests/org.eclipse.passage.seal.demo.tests/src/org/eclipse/passage/seal/demo/tests/DemoFrameworkContentTest.java b/tests/org.eclipse.passage.seal.demo.tests/src/org/eclipse/passage/seal/demo/tests/DemoFrameworkContentTest.java index 03b9ab8c0..dcc480a76 100644 --- a/tests/org.eclipse.passage.seal.demo.tests/src/org/eclipse/passage/seal/demo/tests/DemoFrameworkContentTest.java +++ b/tests/org.eclipse.passage.seal.demo.tests/src/org/eclipse/passage/seal/demo/tests/DemoFrameworkContentTest.java @@ -1,3 +1,15 @@ +/******************************************************************************* + * Copyright (c) 2020 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.seal.demo.tests; import static org.junit.Assert.assertEquals; diff --git a/tests/org.eclipse.passage.seal.demo.tests/src/org/eclipse/passage/seal/demo/tests/DemoFrameworkContractTest.java b/tests/org.eclipse.passage.seal.demo.tests/src/org/eclipse/passage/seal/demo/tests/DemoFrameworkContractTest.java index 049078228..487097fef 100644 --- a/tests/org.eclipse.passage.seal.demo.tests/src/org/eclipse/passage/seal/demo/tests/DemoFrameworkContractTest.java +++ b/tests/org.eclipse.passage.seal.demo.tests/src/org/eclipse/passage/seal/demo/tests/DemoFrameworkContractTest.java @@ -1,3 +1,15 @@ +/******************************************************************************* + * Copyright (c) 2020 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.seal.demo.tests; import org.eclipse.passage.lic.internal.api.Framework; diff --git a/tests/org.eclipse.passage.seal.demo.tests/src/org/eclipse/passage/seal/demo/tests/DemoFrameworkRequirementResolutionServiceTest.java b/tests/org.eclipse.passage.seal.demo.tests/src/org/eclipse/passage/seal/demo/tests/DemoFrameworkRequirementResolutionServiceTest.java new file mode 100644 index 000000000..4c88cad3b --- /dev/null +++ b/tests/org.eclipse.passage.seal.demo.tests/src/org/eclipse/passage/seal/demo/tests/DemoFrameworkRequirementResolutionServiceTest.java @@ -0,0 +1,29 @@ +/******************************************************************************* + * Copyright (c) 2020 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.seal.demo.tests; + +import java.util.Optional; + +import org.eclipse.passage.lic.api.tests.FrameworkRequirementResolutionServiceTest; +import org.eclipse.passage.lic.internal.api.Framework; +import org.eclipse.passage.seal.internal.demo.DemoFrameworkSupplier; + +@SuppressWarnings("restriction") +public final class DemoFrameworkRequirementResolutionServiceTest extends FrameworkRequirementResolutionServiceTest { + + @Override + protected Optional framework() { + return new DemoFrameworkSupplier().get(); + } + +} From ad3c2e91478a00d1c4347d0858bb7e297d7da200 Mon Sep 17 00:00:00 2001 From: "elena.parovyshnaya" Date: Mon, 15 Jun 2020 15:31:40 +0300 Subject: [PATCH 08/10] Bug 564282 - API revision: question extensibility Fix code review findings: - add license headers - specify exact version of dependencies Signed-off-by: elena.parovyshnaya --- .../lic/internal/base/registry/ReadOnlyRegistry.java | 12 ++++++++++++ .../META-INF/MANIFEST.MF | 6 +++--- .../passage/seal/internal/demo/DemoFramework.java | 12 ++++++++++++ .../META-INF/MANIFEST.MF | 4 ++-- .../seal/demo/tests/DemoFrameworkContractTest.java | 2 +- 5 files changed, 30 insertions(+), 6 deletions(-) diff --git a/bundles/org.eclipse.passage.lic.base/src/org/eclipse/passage/lic/internal/base/registry/ReadOnlyRegistry.java b/bundles/org.eclipse.passage.lic.base/src/org/eclipse/passage/lic/internal/base/registry/ReadOnlyRegistry.java index 0997c48ba..ea31e6e52 100644 --- a/bundles/org.eclipse.passage.lic.base/src/org/eclipse/passage/lic/internal/base/registry/ReadOnlyRegistry.java +++ b/bundles/org.eclipse.passage.lic.base/src/org/eclipse/passage/lic/internal/base/registry/ReadOnlyRegistry.java @@ -1,3 +1,15 @@ +/******************************************************************************* + * Copyright (c) 2020 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.registry; import java.util.Collection; diff --git a/bundles/org.eclipse.passage.seal.demo/META-INF/MANIFEST.MF b/bundles/org.eclipse.passage.seal.demo/META-INF/MANIFEST.MF index 2e3d26c79..77f10e591 100644 --- a/bundles/org.eclipse.passage.seal.demo/META-INF/MANIFEST.MF +++ b/bundles/org.eclipse.passage.seal.demo/META-INF/MANIFEST.MF @@ -8,9 +8,9 @@ Bundle-Vendor: %Bundle-Vendor Bundle-Copyright: %Bundle-Copyright Bundle-RequiredExecutionEnvironment: JavaSE-1.8 Require-Bundle: org.eclipse.osgi.services;bundle-version="3.8.0", - org.eclipse.passage.lic.api, - org.eclipse.passage.lic.base, - org.eclipse.passage.lic.equinox + org.eclipse.passage.lic.api;bundle-version="0.7.0", + org.eclipse.passage.lic.base;bundle-version="0.6.100", + org.eclipse.passage.lic.equinox;bundle-version="0.6.0" Service-Component: OSGI-INF/*.xml Bundle-ActivationPolicy: lazy Export-Package: org.eclipse.passage.seal.internal.demo diff --git a/bundles/org.eclipse.passage.seal.demo/src/org/eclipse/passage/seal/internal/demo/DemoFramework.java b/bundles/org.eclipse.passage.seal.demo/src/org/eclipse/passage/seal/internal/demo/DemoFramework.java index 8a816b127..9e7da469b 100644 --- a/bundles/org.eclipse.passage.seal.demo/src/org/eclipse/passage/seal/internal/demo/DemoFramework.java +++ b/bundles/org.eclipse.passage.seal.demo/src/org/eclipse/passage/seal/internal/demo/DemoFramework.java @@ -1,3 +1,15 @@ +/******************************************************************************* + * Copyright (c) 2020 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.seal.internal.demo; import java.util.Arrays; diff --git a/tests/org.eclipse.passage.seal.demo.tests/META-INF/MANIFEST.MF b/tests/org.eclipse.passage.seal.demo.tests/META-INF/MANIFEST.MF index 369a1c7f1..97ff9a759 100644 --- a/tests/org.eclipse.passage.seal.demo.tests/META-INF/MANIFEST.MF +++ b/tests/org.eclipse.passage.seal.demo.tests/META-INF/MANIFEST.MF @@ -2,7 +2,7 @@ Manifest-Version: 1.0 Automatic-Module-Name: org.eclipse.passage.seal.demo.tests Bundle-ManifestVersion: 2 Bundle-SymbolicName: org.eclipse.passage.seal.demo.tests -Bundle-Version: 0.5.0.qualifier +Bundle-Version: 0.1.0.qualifier Bundle-Name: %Bundle-Name Bundle-Vendor: %Bundle-Vendor Bundle-Copyright: %Bundle-Copyright @@ -11,6 +11,6 @@ Require-Bundle: org.junit;bundle-version="4.12.0", org.eclipse.osgi.services;bundle-version="0.0.0", org.eclipse.passage.seal.demo;bundle-version="0.0.0", org.eclipse.passage.lic.api.tests;bundle-version="0.0.0", - org.eclipse.passage.lic.api, + org.eclipse.passage.lic.api;bundle-version="0.7.0", org.eclipse.passage.lic.equinox Export-Package: org.eclipse.passage.seal.demo.tests diff --git a/tests/org.eclipse.passage.seal.demo.tests/src/org/eclipse/passage/seal/demo/tests/DemoFrameworkContractTest.java b/tests/org.eclipse.passage.seal.demo.tests/src/org/eclipse/passage/seal/demo/tests/DemoFrameworkContractTest.java index 487097fef..5b819878d 100644 --- a/tests/org.eclipse.passage.seal.demo.tests/src/org/eclipse/passage/seal/demo/tests/DemoFrameworkContractTest.java +++ b/tests/org.eclipse.passage.seal.demo.tests/src/org/eclipse/passage/seal/demo/tests/DemoFrameworkContractTest.java @@ -21,7 +21,7 @@ import org.eclipse.passage.seal.internal.demo.DemoFrameworkSupplier; @SuppressWarnings("restriction") -public final class DemoFrameworkContractTest extends FrameworkContractTest{ +public final class DemoFrameworkContractTest extends FrameworkContractTest { @Override protected Optional framework() { From 9d0267e4a2ad8825f652adf8b346e15265e477d1 Mon Sep 17 00:00:00 2001 From: "elena.parovyshnaya" Date: Mon, 15 Jun 2020 15:37:54 +0300 Subject: [PATCH 09/10] Bug 564282 - API revision: question extensibility Fix existing requirement resolution services tests Signed-off-by: elena.parovyshnaya --- .../requirements/BundleRequirementsTest.java | 9 ++++++ .../ComponentRequirementsTest.java | 9 ++++++ .../ResolvedRequirementsServiceTest.java | 31 ------------------- 3 files changed, 18 insertions(+), 31 deletions(-) diff --git a/tests/org.eclipse.passage.lic.equinox.tests/src/org/eclipse/passage/lic/internal/equinox/requirements/BundleRequirementsTest.java b/tests/org.eclipse.passage.lic.equinox.tests/src/org/eclipse/passage/lic/internal/equinox/requirements/BundleRequirementsTest.java index d2ec9e7ce..badf5b6e2 100644 --- a/tests/org.eclipse.passage.lic.equinox.tests/src/org/eclipse/passage/lic/internal/equinox/requirements/BundleRequirementsTest.java +++ b/tests/org.eclipse.passage.lic.equinox.tests/src/org/eclipse/passage/lic/internal/equinox/requirements/BundleRequirementsTest.java @@ -15,7 +15,11 @@ import java.util.Set; import org.eclipse.passage.lic.internal.api.requirements.Requirement; +import org.eclipse.passage.lic.internal.api.requirements.ResolvedRequirements; +/** + * Integration test: requires OSGi running + */ @SuppressWarnings("restriction") public final class BundleRequirementsTest extends ResolvedRequirementsServiceTest { @@ -34,4 +38,9 @@ protected Requirement single() { return new DataBundle().pi(); } + @Override + protected ResolvedRequirements service() { + return new BundleRequirements(); + } + } diff --git a/tests/org.eclipse.passage.lic.equinox.tests/src/org/eclipse/passage/lic/internal/equinox/requirements/ComponentRequirementsTest.java b/tests/org.eclipse.passage.lic.equinox.tests/src/org/eclipse/passage/lic/internal/equinox/requirements/ComponentRequirementsTest.java index c2fde0355..a815529be 100644 --- a/tests/org.eclipse.passage.lic.equinox.tests/src/org/eclipse/passage/lic/internal/equinox/requirements/ComponentRequirementsTest.java +++ b/tests/org.eclipse.passage.lic.equinox.tests/src/org/eclipse/passage/lic/internal/equinox/requirements/ComponentRequirementsTest.java @@ -15,7 +15,11 @@ import java.util.Set; import org.eclipse.passage.lic.internal.api.requirements.Requirement; +import org.eclipse.passage.lic.internal.api.requirements.ResolvedRequirements; +/** + * Integration test: requires OSGi running + */ @SuppressWarnings("restriction") public final class ComponentRequirementsTest extends ResolvedRequirementsServiceTest { @@ -34,4 +38,9 @@ protected Requirement single() { return new DataBundle().goodWitch(); } + @Override + protected ResolvedRequirements service() { + return new ComponentRequirements(); + } + } diff --git a/tests/org.eclipse.passage.lic.equinox.tests/src/org/eclipse/passage/lic/internal/equinox/requirements/ResolvedRequirementsServiceTest.java b/tests/org.eclipse.passage.lic.equinox.tests/src/org/eclipse/passage/lic/internal/equinox/requirements/ResolvedRequirementsServiceTest.java index 87653a3a9..68b0aff09 100644 --- a/tests/org.eclipse.passage.lic.equinox.tests/src/org/eclipse/passage/lic/internal/equinox/requirements/ResolvedRequirementsServiceTest.java +++ b/tests/org.eclipse.passage.lic.equinox.tests/src/org/eclipse/passage/lic/internal/equinox/requirements/ResolvedRequirementsServiceTest.java @@ -14,12 +14,10 @@ import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertTrue; -import static org.junit.Assume.assumeTrue; import java.util.Collection; import java.util.Collections; import java.util.HashSet; -import java.util.Optional; import java.util.Set; import java.util.stream.Collectors; @@ -27,19 +25,11 @@ import org.eclipse.passage.lic.internal.api.requirements.Requirement; import org.eclipse.passage.lic.internal.api.requirements.ResolvedRequirements; import org.junit.Test; -import org.osgi.framework.BundleContext; -import org.osgi.framework.FrameworkUtil; import org.osgi.framework.InvalidSyntaxException; -import org.osgi.framework.ServiceReference; @SuppressWarnings("restriction") abstract class ResolvedRequirementsServiceTest extends ResolvedRequirementsContractTest { - @Test - public void providedAsResolvedRequirementsImpl() throws InvalidSyntaxException { - assertTrue(mayBeService().isPresent()); - } - @Test public void allRequirements() throws InvalidSyntaxException { Collection requirements = service().all(); @@ -58,27 +48,6 @@ public void requirementsForFeature() throws InvalidSyntaxException { new HashSet(forTheFeature)); } - @Override - protected ResolvedRequirements service() { - Optional service = mayBeService(); - assumeTrue(service.isPresent()); - return service.get(); - } - - private Optional mayBeService() { - BundleContext context = FrameworkUtil.getBundle(getClass()).getBundleContext(); - Collection> refs; - try { - refs = context.getServiceReferences(ResolvedRequirements.class, null); // API-dictated null - } catch (InvalidSyntaxException e) { - return Optional.empty(); - } - return refs.stream() // - .map(s -> context.getService(s)) // - .filter(s -> s.getClass() == serviceClass()) // - .findAny(); - } - protected abstract Class serviceClass(); protected abstract Set expectations(); From ff6e0df3a2c065aba9f4ee715048de217772cb73 Mon Sep 17 00:00:00 2001 From: "elena.parovyshnaya" Date: Tue, 16 Jun 2020 10:55:04 +0300 Subject: [PATCH 10/10] Bug 564282 - API revision: question extensibility Hide 'internal' package Signed-off-by: elena.parovyshnaya --- bundles/org.eclipse.passage.seal.demo/META-INF/MANIFEST.MF | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/bundles/org.eclipse.passage.seal.demo/META-INF/MANIFEST.MF b/bundles/org.eclipse.passage.seal.demo/META-INF/MANIFEST.MF index 77f10e591..32ab1db42 100644 --- a/bundles/org.eclipse.passage.seal.demo/META-INF/MANIFEST.MF +++ b/bundles/org.eclipse.passage.seal.demo/META-INF/MANIFEST.MF @@ -13,4 +13,4 @@ Require-Bundle: org.eclipse.osgi.services;bundle-version="3.8.0", org.eclipse.passage.lic.equinox;bundle-version="0.6.0" Service-Component: OSGI-INF/*.xml Bundle-ActivationPolicy: lazy -Export-Package: org.eclipse.passage.seal.internal.demo +Export-Package: org.eclipse.passage.seal.internal.demo;x-internal:=true