diff --git a/bundles/org.eclipse.passage.lic.products.model/META-INF/MANIFEST.MF b/bundles/org.eclipse.passage.lic.products.model/META-INF/MANIFEST.MF index 0c9b6b069..ddaad1e4a 100644 --- a/bundles/org.eclipse.passage.lic.products.model/META-INF/MANIFEST.MF +++ b/bundles/org.eclipse.passage.lic.products.model/META-INF/MANIFEST.MF @@ -14,6 +14,7 @@ Require-Bundle: org.eclipse.core.runtime;bundle-version="0.0.0";x-installation:= org.eclipse.passage.lic.emf;bundle-version="0.0.0", org.eclipse.passage.lic.products;bundle-version="0.0.0";visibility:=reexport Export-Package: org.eclipse.passage.lic.internal.products.model;x-friends:="org.eclipse.passage.loc.dashboard.ui", + org.eclipse.passage.lic.internal.products.model.util;x-internal:=true, org.eclipse.passage.lic.products.model.api, org.eclipse.passage.lic.products.model.impl;x-internal:=true, org.eclipse.passage.lic.products.model.meta, diff --git a/bundles/org.eclipse.passage.lic.products.model/plugin.xml b/bundles/org.eclipse.passage.lic.products.model/plugin.xml index 621f54a42..945a8f3bf 100644 --- a/bundles/org.eclipse.passage.lic.products.model/plugin.xml +++ b/bundles/org.eclipse.passage.lic.products.model/plugin.xml @@ -1,36 +1,36 @@ - - - - - - - - - - - - - - - - - + + + + + + + + + + + + + + + + + diff --git a/bundles/org.eclipse.passage.lic.products.model/src-gen/org/eclipse/passage/lic/products/model/util/ProductsResourceFactoryImpl.java b/bundles/org.eclipse.passage.lic.products.model/src/org/eclipse/passage/lic/internal/products/model/util/ProductsResourceFactoryImpl.java similarity index 58% rename from bundles/org.eclipse.passage.lic.products.model/src-gen/org/eclipse/passage/lic/products/model/util/ProductsResourceFactoryImpl.java rename to bundles/org.eclipse.passage.lic.products.model/src/org/eclipse/passage/lic/internal/products/model/util/ProductsResourceFactoryImpl.java index 0a72b6f2b..693ddad81 100644 --- a/bundles/org.eclipse.passage.lic.products.model/src-gen/org/eclipse/passage/lic/products/model/util/ProductsResourceFactoryImpl.java +++ b/bundles/org.eclipse.passage.lic.products.model/src/org/eclipse/passage/lic/internal/products/model/util/ProductsResourceFactoryImpl.java @@ -1,48 +1,27 @@ -/******************************************************************************* - * Copyright (c) 2018, 2024 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.products.model.util; - -import org.eclipse.emf.common.util.URI; -import org.eclipse.emf.ecore.resource.Resource; -import org.eclipse.emf.ecore.resource.impl.ResourceFactoryImpl; - -/** - * The Resource Factory associated with the - * package. - * @see org.eclipse.passage.lic.products.model.util.ProductsResourceImpl - * @generated - */ -public class ProductsResourceFactoryImpl extends ResourceFactoryImpl { - /** - * Creates an instance of the resource factory. - * - * - * @generated - */ - public ProductsResourceFactoryImpl() { - super(); - } - - /** - * Creates an instance of the resource. - * - * - * @generated - */ - @Override - public Resource createResource(URI uri) { - Resource result = new ProductsResourceImpl(uri); - return result; - } - -} // ProductsResourceFactoryImpl +/******************************************************************************* + * Copyright (c) 2018, 2024 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.products.model.util; + +import org.eclipse.emf.common.util.URI; +import org.eclipse.emf.ecore.resource.Resource; +import org.eclipse.emf.ecore.resource.impl.ResourceFactoryImpl; + +public class ProductsResourceFactoryImpl extends ResourceFactoryImpl { + + @Override + public Resource createResource(URI uri) { + Resource result = new ProductsResourceImpl(uri); + return result; + } + +} diff --git a/bundles/org.eclipse.passage.lic.products.model/src-gen/org/eclipse/passage/lic/products/model/util/ProductsResourceImpl.java b/bundles/org.eclipse.passage.lic.products.model/src/org/eclipse/passage/lic/internal/products/model/util/ProductsResourceImpl.java similarity index 70% rename from bundles/org.eclipse.passage.lic.products.model/src-gen/org/eclipse/passage/lic/products/model/util/ProductsResourceImpl.java rename to bundles/org.eclipse.passage.lic.products.model/src/org/eclipse/passage/lic/internal/products/model/util/ProductsResourceImpl.java index ecea71cbb..b2531b895 100644 --- a/bundles/org.eclipse.passage.lic.products.model/src-gen/org/eclipse/passage/lic/products/model/util/ProductsResourceImpl.java +++ b/bundles/org.eclipse.passage.lic.products.model/src/org/eclipse/passage/lic/internal/products/model/util/ProductsResourceImpl.java @@ -1,47 +1,35 @@ -/******************************************************************************* - * Copyright (c) 2018, 2024 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.products.model.util; - -import java.util.Map; - -import org.eclipse.emf.common.util.URI; -import org.eclipse.emf.ecore.xmi.impl.XMIResourceImpl; -import org.eclipse.passage.lic.internal.products.model.migration.ProductsResourceHandler; - -/** - * The Resource associated with the package. - * - * @see org.eclipse.passage.lic.products.model.util.ProductsResourceFactoryImpl - * @generated - */ -public class ProductsResourceImpl extends XMIResourceImpl { - /** - * Creates an instance of the resource. - * - * - * @param uri the URI of the new resource. - * @generated - */ - public ProductsResourceImpl(URI uri) { - super(uri); - } - - @Override - protected void init() { - super.init(); - Map options = getDefaultLoadOptions(); - options.put(OPTION_RECORD_UNKNOWN_FEATURE, Boolean.TRUE); - options.put(OPTION_RESOURCE_HANDLER, new ProductsResourceHandler()); - } - -} // ProductsResourceImpl +/******************************************************************************* + * Copyright (c) 2018, 2024 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.products.model.util; + +import java.util.Map; + +import org.eclipse.emf.common.util.URI; +import org.eclipse.emf.ecore.xmi.impl.XMIResourceImpl; +import org.eclipse.passage.lic.internal.products.model.migration.ProductsResourceHandler; + +public class ProductsResourceImpl extends XMIResourceImpl { + + public ProductsResourceImpl(URI uri) { + super(uri); + } + + @Override + protected void init() { + super.init(); + Map options = getDefaultLoadOptions(); + options.put(OPTION_RECORD_UNKNOWN_FEATURE, Boolean.TRUE); + options.put(OPTION_RESOURCE_HANDLER, new ProductsResourceHandler()); + } + +} diff --git a/bundles/org.eclipse.passage.loc.products.core/src/org/eclipse/passage/loc/internal/products/core/ProductDomainRegistry.java b/bundles/org.eclipse.passage.loc.products.core/src/org/eclipse/passage/loc/internal/products/core/ProductDomainRegistry.java index ef8d2fa72..3b7f75aa1 100644 --- a/bundles/org.eclipse.passage.loc.products.core/src/org/eclipse/passage/loc/internal/products/core/ProductDomainRegistry.java +++ b/bundles/org.eclipse.passage.loc.products.core/src/org/eclipse/passage/loc/internal/products/core/ProductDomainRegistry.java @@ -26,12 +26,12 @@ import org.eclipse.emf.ecore.resource.Resource; import org.eclipse.osgi.util.NLS; import org.eclipse.passage.lic.internal.equinox.events.EquinoxEvent; +import org.eclipse.passage.lic.internal.products.model.util.ProductsResourceImpl; import org.eclipse.passage.lic.products.model.api.Product; import org.eclipse.passage.lic.products.model.api.ProductLine; import org.eclipse.passage.lic.products.model.api.ProductVersion; import org.eclipse.passage.lic.products.model.api.ProductVersionFeature; import org.eclipse.passage.lic.products.model.meta.ProductsPackage; -import org.eclipse.passage.lic.products.model.util.ProductsResourceImpl; import org.eclipse.passage.loc.internal.api.OperatorGearSupplier; import org.eclipse.passage.loc.internal.api.workspace.KnownResources; import org.eclipse.passage.loc.internal.api.workspace.OperatorWorkspace; @@ -51,6 +51,7 @@ import org.osgi.service.component.annotations.ReferenceCardinality; import org.osgi.service.event.EventAdmin; +@SuppressWarnings("restriction") @Component(property = { EditingDomainRegistryAccess.PROPERTY_DOMAIN_NAME + '=' + ProductsPackage.eNAME, EditingDomainRegistryAccess.PROPERTY_FILE_EXTENSION + '=' + "products_xmi" }) public final class ProductDomainRegistry extends BaseDomainRegistry diff --git a/bundles/org.eclipse.passage.loc.products.core/src/org/eclipse/passage/loc/internal/products/core/ProductVersionKeys.java b/bundles/org.eclipse.passage.loc.products.core/src/org/eclipse/passage/loc/internal/products/core/ProductVersionKeys.java index d53b9f30e..70290c892 100644 --- a/bundles/org.eclipse.passage.loc.products.core/src/org/eclipse/passage/loc/internal/products/core/ProductVersionKeys.java +++ b/bundles/org.eclipse.passage.loc.products.core/src/org/eclipse/passage/loc/internal/products/core/ProductVersionKeys.java @@ -1,139 +1,140 @@ -/******************************************************************************* - * Copyright (c) 2021, 2024 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.loc.internal.products.core; - -import java.io.ByteArrayOutputStream; -import java.util.Objects; -import java.util.Optional; -import java.util.function.Consumer; - -import org.eclipse.core.runtime.IStatus; -import org.eclipse.core.runtime.Status; -import org.eclipse.passage.lic.api.LicensedProduct; -import org.eclipse.passage.lic.api.LicensingException; -import org.eclipse.passage.lic.api.io.StreamCodec; -import org.eclipse.passage.lic.base.BaseLicensedProduct; -import org.eclipse.passage.lic.keys.model.api.KeyPair; -import org.eclipse.passage.lic.products.model.api.ProductVersion; -import org.eclipse.passage.loc.internal.api.workspace.Keys; -import org.eclipse.passage.loc.internal.equinox.OperatorGearAware; -import org.eclipse.passage.loc.internal.products.core.i18n.ProductsCoreMessages; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - -final class ProductVersionKeys { - - private final String plugin; - private final Consumer notify; - private final Logger log = LoggerFactory.getLogger(getClass()); - - ProductVersionKeys(String plugin, Consumer notify) { - Objects.requireNonNull(plugin, "ProductVersionPassword::plugin"); //$NON-NLS-1$ - Objects.requireNonNull(notify, "ProductVersionPassword::notify"); //$NON-NLS-1$ - this.plugin = plugin; - this.notify = notify; - } - - ProductVersionKeys(String plugin) { - this(plugin, p -> { - }); - } - - public IStatus createKeys(ProductVersion target) { - LicensedProduct product = product(target); - Optional existing; - try { - existing = keyIsPresent(product); - } catch (LicensingException e) { - return failed(e); - } - if (existing.isPresent()) { - return error(existing.get()); - } - Optional codec; - try { - codec = codec(product); - } catch (LicensingException e) { - return failed(e); - } - if (codec.isEmpty()) { - return noCodec(target, product); - } - try { - return createKeyPair(target, product, codec.get()); - } catch (Exception e) { - return failed(e); - } - } - - private BaseLicensedProduct product(ProductVersion target) { - return new BaseLicensedProduct(// - target.getProduct().getIdentifier(), // - target.getVersion()); - } - - private Optional codec(LicensedProduct product) throws LicensingException { - return new OperatorGearAware().withGear(gear -> gear.codec(product)); - } - - private Optional keyIsPresent(LicensedProduct target) throws LicensingException { - Keys service = new OperatorGearAware().withGear(gear -> Optional.of(gear.workspace().keys())).get(); - Optional exists = service.existing(target.identifier(), target.version()); - return exists.map( - path -> String.format(ProductsCoreMessages.ProductOperatorServiceImpl_e_key_already_defined, path)); - } - - private IStatus createKeyPair(ProductVersion target, LicensedProduct product, StreamCodec codec) - throws LicensingException { - Optional stored = store(generate(target, product, codec)); - if (!stored.isPresent()) { - notify.accept(stored.get()); - } - return created(stored); - } - - private Optional store(KeyPair pair) throws LicensingException { - return new KeyPairStored(pair).store(); - } - - private KeyPair generate(ProductVersion target, LicensedProduct product, StreamCodec codec) - throws LicensingException { - try (ByteArrayOutputStream open = new ByteArrayOutputStream(); - ByteArrayOutputStream secret = new ByteArrayOutputStream()) { - codec.createKeyPair(open, secret, product.identifier(), new ProductVersionPassword(target).get()); - return new KeyPairGeneraged(codec, open.toByteArray(), secret.toByteArray()).get(); - } catch (Exception e) { - throw new LicensingException("failed to generate keys", e); //$NON-NLS-1$ // TODO: l10n - } - } - - private Status error(String errors) { - return new Status(IStatus.ERROR, plugin, errors); - } - - private Status noCodec(ProductVersion target, LicensedProduct product) { - return error(String.format(ProductsCoreMessages.ProductOperatorServiceImpl_e_unable_to_create_keys, - product.version(), target.getProduct().getName())); - } - - private Status failed(Exception e) { - log.error("", e); //$NON-NLS-1$ - return new Status(IStatus.ERROR, plugin, ProductsCoreMessages.ProductOperatorServiceImpl_e_export_error, e); - } - - private Status created(Optional persisted) { - return new Status(IStatus.OK, plugin, String - .format(ProductsCoreMessages.ProductOperatorServiceImpl_ok_keys_exported, persisted.orElse("unknown"))); //$NON-NLS-1$ - } - +/******************************************************************************* + * Copyright (c) 2021, 2024 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.loc.internal.products.core; + +import java.io.ByteArrayOutputStream; +import java.util.Objects; +import java.util.Optional; +import java.util.function.Consumer; + +import org.eclipse.core.runtime.IStatus; +import org.eclipse.core.runtime.Status; +import org.eclipse.passage.lic.api.LicensedProduct; +import org.eclipse.passage.lic.api.LicensingException; +import org.eclipse.passage.lic.api.io.StreamCodec; +import org.eclipse.passage.lic.base.BaseLicensedProduct; +import org.eclipse.passage.lic.keys.model.api.KeyPair; +import org.eclipse.passage.lic.products.model.api.ProductVersion; +import org.eclipse.passage.loc.internal.api.workspace.Keys; +import org.eclipse.passage.loc.internal.equinox.OperatorGearAware; +import org.eclipse.passage.loc.internal.products.core.i18n.ProductsCoreMessages; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +@SuppressWarnings("restriction") +final class ProductVersionKeys { + + private final String plugin; + private final Consumer notify; + private final Logger log = LoggerFactory.getLogger(getClass()); + + ProductVersionKeys(String plugin, Consumer notify) { + Objects.requireNonNull(plugin, "ProductVersionPassword::plugin"); //$NON-NLS-1$ + Objects.requireNonNull(notify, "ProductVersionPassword::notify"); //$NON-NLS-1$ + this.plugin = plugin; + this.notify = notify; + } + + ProductVersionKeys(String plugin) { + this(plugin, p -> { + }); + } + + public IStatus createKeys(ProductVersion target) { + LicensedProduct product = product(target); + Optional existing; + try { + existing = keyIsPresent(product); + } catch (LicensingException e) { + return failed(e); + } + if (existing.isPresent()) { + return error(existing.get()); + } + Optional codec; + try { + codec = codec(product); + } catch (LicensingException e) { + return failed(e); + } + if (codec.isEmpty()) { + return noCodec(target, product); + } + try { + return createKeyPair(target, product, codec.get()); + } catch (Exception e) { + return failed(e); + } + } + + private BaseLicensedProduct product(ProductVersion target) { + return new BaseLicensedProduct(// + target.getProduct().getIdentifier(), // + target.getVersion()); + } + + private Optional codec(LicensedProduct product) throws LicensingException { + return new OperatorGearAware().withGear(gear -> gear.codec(product)); + } + + private Optional keyIsPresent(LicensedProduct target) throws LicensingException { + Keys service = new OperatorGearAware().withGear(gear -> Optional.of(gear.workspace().keys())).get(); + Optional exists = service.existing(target.identifier(), target.version()); + return exists.map( + path -> String.format(ProductsCoreMessages.ProductOperatorServiceImpl_e_key_already_defined, path)); + } + + private IStatus createKeyPair(ProductVersion target, LicensedProduct product, StreamCodec codec) + throws LicensingException { + Optional stored = store(generate(target, product, codec)); + if (!stored.isPresent()) { + notify.accept(stored.get()); + } + return created(stored); + } + + private Optional store(KeyPair pair) throws LicensingException { + return new KeyPairStored(pair).store(); + } + + private KeyPair generate(ProductVersion target, LicensedProduct product, StreamCodec codec) + throws LicensingException { + try (ByteArrayOutputStream open = new ByteArrayOutputStream(); + ByteArrayOutputStream secret = new ByteArrayOutputStream()) { + codec.createKeyPair(open, secret, product.identifier(), new ProductVersionPassword(target).get()); + return new KeyPairGeneraged(codec, open.toByteArray(), secret.toByteArray()).get(); + } catch (Exception e) { + throw new LicensingException("failed to generate keys", e); //$NON-NLS-1$ // TODO: l10n + } + } + + private Status error(String errors) { + return new Status(IStatus.ERROR, plugin, errors); + } + + private Status noCodec(ProductVersion target, LicensedProduct product) { + return error(String.format(ProductsCoreMessages.ProductOperatorServiceImpl_e_unable_to_create_keys, + product.version(), target.getProduct().getName())); + } + + private Status failed(Exception e) { + log.error("", e); //$NON-NLS-1$ + return new Status(IStatus.ERROR, plugin, ProductsCoreMessages.ProductOperatorServiceImpl_e_export_error, e); + } + + private Status created(Optional persisted) { + return new Status(IStatus.OK, plugin, String + .format(ProductsCoreMessages.ProductOperatorServiceImpl_ok_keys_exported, persisted.orElse("unknown"))); //$NON-NLS-1$ + } + } \ No newline at end of file diff --git a/tests/org.eclipse.passage.lic.products.model.tests/src/org/eclipse/passage/lic/products/model/migration/tests/ProductsMigratorTest.java b/tests/org.eclipse.passage.lic.products.model.tests/src/org/eclipse/passage/lic/products/model/migration/tests/ProductsMigratorTest.java index 256d28d09..640be9bf5 100644 --- a/tests/org.eclipse.passage.lic.products.model.tests/src/org/eclipse/passage/lic/products/model/migration/tests/ProductsMigratorTest.java +++ b/tests/org.eclipse.passage.lic.products.model.tests/src/org/eclipse/passage/lic/products/model/migration/tests/ProductsMigratorTest.java @@ -1,83 +1,84 @@ -/******************************************************************************* - * Copyright (c) 2018, 2021 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.products.model.migration.tests; - -import static org.junit.Assert.assertEquals; - -import java.io.File; - -import org.eclipse.emf.common.util.EList; -import org.eclipse.emf.common.util.URI; -import org.eclipse.emf.ecore.EObject; -import org.eclipse.emf.ecore.resource.Resource; -import org.eclipse.passage.lic.products.model.api.Product; -import org.eclipse.passage.lic.products.model.api.ProductLine; -import org.eclipse.passage.lic.products.model.api.ProductVersion; -import org.eclipse.passage.lic.products.model.api.ProductVersionFeature; -import org.eclipse.passage.lic.products.model.util.ProductsResourceImpl; -import org.junit.Test; - -public final class ProductsMigratorTest { - - @Test - public void testMigratorPositive() throws Exception { - File legacy = new File( - System.getProperty("user.dir") + File.separator + "model/org.eclipse.passage.lic.lic_products"); //$NON-NLS-1$//$NON-NLS-2$ - URI uri = URI.createFileURI(legacy.getPath()); - Resource resource = new ProductsResourceImpl(uri); - resource.load(null); - EList contents = resource.getContents(); - EObject eObject = contents.get(0); - - ProductLine productLine = ProductLine.class.cast(eObject); - assertEquals("org.eclipse.passage.lic", productLine.getIdentifier()); //$NON-NLS-1$ - assertEquals("Eclipse Passage LIC", productLine.getName()); //$NON-NLS-1$ - assertEquals("Eclipse Passage Licensing Integration Components", productLine.getDescription()); //$NON-NLS-1$ - - EList products = productLine.getProducts(); - assertEquals(1, products.size()); - - Product p0 = products.get(0); - assertEquals("org.eclipse.passage.lic.product", p0.getIdentifier()); //$NON-NLS-1$ - assertEquals("Eclipse Passage LIC", p0.getName()); //$NON-NLS-1$ - assertEquals("Eclipse Passage Licensing Integration Components product", p0.getDescription()); //$NON-NLS-1$ - - EList p0vs = p0.getProductVersions(); - assertEquals(2, p0vs.size()); - ProductVersion p0v0 = p0vs.get(0); - assertEquals("0.3.3", p0v0.getVersion()); //$NON-NLS-1$ - assertEquals("./.passage/org.eclipse.passage.lic.product/0.3.3/org.eclipse.passage.lic.product_0.3.3.pub", //$NON-NLS-1$ - p0v0.getInstallationToken()); - assertEquals("./.passage/org.eclipse.passage.lic.product/0.3.3/org.eclipse.passage.lic.product_0.3.3.scr", //$NON-NLS-1$ - p0v0.getSecureToken()); - EList p0v0pvfs = p0v0.getProductVersionFeatures(); - assertEquals(1, p0v0pvfs.size()); - ProductVersionFeature p0v0pvf0 = p0v0pvfs.get(0); - assertEquals("org.eclipse.passage.lic.launch", p0v0pvf0.getFeatureIdentifier()); //$NON-NLS-1$ - assertEquals("0.3.3", p0v0pvf0.getFeatureVersion()); //$NON-NLS-1$ - assertEquals("error", p0v0pvf0.getRestrictionLevel()); //$NON-NLS-1$ - - ProductVersion p0v1 = p0vs.get(1); - assertEquals("0.4.0", p0v1.getVersion()); //$NON-NLS-1$ - assertEquals("./.passage/org.eclipse.passage.lic.product/0.4.0/org.eclipse.passage.lic.product_0.4.0.pub", //$NON-NLS-1$ - p0v1.getInstallationToken()); - assertEquals("./.passage/org.eclipse.passage.lic.product/0.4.0/org.eclipse.passage.lic.product_0.4.0.scr", //$NON-NLS-1$ - p0v1.getSecureToken()); - EList p1v0pvfs = p0v1.getProductVersionFeatures(); - assertEquals(1, p1v0pvfs.size()); - ProductVersionFeature p1v0pvf0 = p1v0pvfs.get(0); - assertEquals("org.eclipse.passage.lic.product", p1v0pvf0.getFeatureIdentifier()); //$NON-NLS-1$ - assertEquals("0.4.0", p1v0pvf0.getFeatureVersion()); //$NON-NLS-1$ - assertEquals("error", p1v0pvf0.getRestrictionLevel()); //$NON-NLS-1$ - } -} +/******************************************************************************* + * Copyright (c) 2018, 2024 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 + * ArSysOp - further support + *******************************************************************************/ +package org.eclipse.passage.lic.products.model.migration.tests; + +import static org.junit.Assert.assertEquals; + +import java.io.File; + +import org.eclipse.emf.common.util.EList; +import org.eclipse.emf.common.util.URI; +import org.eclipse.emf.ecore.EObject; +import org.eclipse.emf.ecore.resource.Resource; +import org.eclipse.passage.lic.internal.products.model.util.ProductsResourceImpl; +import org.eclipse.passage.lic.products.model.api.Product; +import org.eclipse.passage.lic.products.model.api.ProductLine; +import org.eclipse.passage.lic.products.model.api.ProductVersion; +import org.eclipse.passage.lic.products.model.api.ProductVersionFeature; +import org.junit.Test; + +public final class ProductsMigratorTest { + + @Test + public void testMigratorPositive() throws Exception { + File legacy = new File( + System.getProperty("user.dir") + File.separator + "model/org.eclipse.passage.lic.lic_products"); //$NON-NLS-1$//$NON-NLS-2$ + URI uri = URI.createFileURI(legacy.getPath()); + Resource resource = new ProductsResourceImpl(uri); + resource.load(null); + EList contents = resource.getContents(); + EObject eObject = contents.get(0); + + ProductLine productLine = ProductLine.class.cast(eObject); + assertEquals("org.eclipse.passage.lic", productLine.getIdentifier()); //$NON-NLS-1$ + assertEquals("Eclipse Passage LIC", productLine.getName()); //$NON-NLS-1$ + assertEquals("Eclipse Passage Licensing Integration Components", productLine.getDescription()); //$NON-NLS-1$ + + EList products = productLine.getProducts(); + assertEquals(1, products.size()); + + Product p0 = products.get(0); + assertEquals("org.eclipse.passage.lic.product", p0.getIdentifier()); //$NON-NLS-1$ + assertEquals("Eclipse Passage LIC", p0.getName()); //$NON-NLS-1$ + assertEquals("Eclipse Passage Licensing Integration Components product", p0.getDescription()); //$NON-NLS-1$ + + EList p0vs = p0.getProductVersions(); + assertEquals(2, p0vs.size()); + ProductVersion p0v0 = p0vs.get(0); + assertEquals("0.3.3", p0v0.getVersion()); //$NON-NLS-1$ + assertEquals("./.passage/org.eclipse.passage.lic.product/0.3.3/org.eclipse.passage.lic.product_0.3.3.pub", //$NON-NLS-1$ + p0v0.getInstallationToken()); + assertEquals("./.passage/org.eclipse.passage.lic.product/0.3.3/org.eclipse.passage.lic.product_0.3.3.scr", //$NON-NLS-1$ + p0v0.getSecureToken()); + EList p0v0pvfs = p0v0.getProductVersionFeatures(); + assertEquals(1, p0v0pvfs.size()); + ProductVersionFeature p0v0pvf0 = p0v0pvfs.get(0); + assertEquals("org.eclipse.passage.lic.launch", p0v0pvf0.getFeatureIdentifier()); //$NON-NLS-1$ + assertEquals("0.3.3", p0v0pvf0.getFeatureVersion()); //$NON-NLS-1$ + assertEquals("error", p0v0pvf0.getRestrictionLevel()); //$NON-NLS-1$ + + ProductVersion p0v1 = p0vs.get(1); + assertEquals("0.4.0", p0v1.getVersion()); //$NON-NLS-1$ + assertEquals("./.passage/org.eclipse.passage.lic.product/0.4.0/org.eclipse.passage.lic.product_0.4.0.pub", //$NON-NLS-1$ + p0v1.getInstallationToken()); + assertEquals("./.passage/org.eclipse.passage.lic.product/0.4.0/org.eclipse.passage.lic.product_0.4.0.scr", //$NON-NLS-1$ + p0v1.getSecureToken()); + EList p1v0pvfs = p0v1.getProductVersionFeatures(); + assertEquals(1, p1v0pvfs.size()); + ProductVersionFeature p1v0pvf0 = p1v0pvfs.get(0); + assertEquals("org.eclipse.passage.lic.product", p1v0pvf0.getFeatureIdentifier()); //$NON-NLS-1$ + assertEquals("0.4.0", p1v0pvf0.getFeatureVersion()); //$NON-NLS-1$ + assertEquals("error", p1v0pvf0.getRestrictionLevel()); //$NON-NLS-1$ + } +}