diff --git a/bundles/org.eclipse.passage.loc.licenses.core/src/org/eclipse/passage/loc/internal/licenses/core/IssueFloatingLicense.java b/bundles/org.eclipse.passage.loc.licenses.core/src/org/eclipse/passage/loc/internal/licenses/core/IssueFloatingLicense.java index 732a9e4d7..9fe929e7b 100644 --- a/bundles/org.eclipse.passage.loc.licenses.core/src/org/eclipse/passage/loc/internal/licenses/core/IssueFloatingLicense.java +++ b/bundles/org.eclipse.passage.loc.licenses.core/src/org/eclipse/passage/loc/internal/licenses/core/IssueFloatingLicense.java @@ -34,12 +34,10 @@ import org.eclipse.passage.lic.base.diagnostic.NoSevereErrors; import org.eclipse.passage.lic.base.diagnostic.SumOfLists; import org.eclipse.passage.lic.base.io.FloatingFileExtension; -import org.eclipse.passage.lic.base.io.UserHomeProductResidence; import org.eclipse.passage.lic.emf.validation.ErrorMessages; import org.eclipse.passage.lic.licenses.LicensePlanDescriptor; import org.eclipse.passage.lic.licenses.model.api.FloatingLicenseAccess; import org.eclipse.passage.lic.licenses.model.api.FloatingLicensePack; -import org.eclipse.passage.lic.licenses.model.api.LicenseRequisites; import org.eclipse.passage.lic.licenses.model.api.ProductRef; import org.eclipse.passage.lic.licenses.model.api.UserGrant; import org.eclipse.passage.loc.internal.agreements.AgreementRegistry; @@ -95,7 +93,7 @@ ServiceInvocationResult issue(FloatingLicensePack pack, private ServiceInvocationResult persistLicenseFiles(FloatingLicensePack pack, Collection configs) { LicensedProduct product = product(pack.getLicense().getProduct()); - Path residence = residence(pack.getLicense()); + Path residence = new LicensePackResidence(pack.getLicense()).get(); ServiceInvocationResult> license = // persist(pack, product, residence, decryptedFile(pack), encryptedFile(pack)); BinaryOperator>> sum = new BaseServiceInvocationResult.Sum<>( @@ -149,14 +147,6 @@ private ServiceInvocationResult> replicateKey(LicensedProduct product return new BaseServiceInvocationResult<>(Collections.singletonList(key)); } - private Path residence(LicenseRequisites license) { - return new UserHomeProductResidence(// - license.getProduct().getIdentifier(), // - license.getProduct().getVersion())// - .get()// - .resolve(license.getIdentifier()); - } - private LicensedProduct product(ProductRef ref) { return new BaseLicensedProduct(ref.getIdentifier(), ref.getVersion()); } diff --git a/bundles/org.eclipse.passage.loc.licenses.core/src/org/eclipse/passage/loc/internal/licenses/core/IssuePersonalLicense.java b/bundles/org.eclipse.passage.loc.licenses.core/src/org/eclipse/passage/loc/internal/licenses/core/IssuePersonalLicense.java index 397af8699..461fda364 100644 --- a/bundles/org.eclipse.passage.loc.licenses.core/src/org/eclipse/passage/loc/internal/licenses/core/IssuePersonalLicense.java +++ b/bundles/org.eclipse.passage.loc.licenses.core/src/org/eclipse/passage/loc/internal/licenses/core/IssuePersonalLicense.java @@ -27,7 +27,6 @@ import org.eclipse.passage.lic.base.BaseLicensedProduct; import org.eclipse.passage.lic.base.BaseServiceInvocationResult; import org.eclipse.passage.lic.base.io.PassageFileExtension; -import org.eclipse.passage.lic.base.io.UserHomeProductResidence; import org.eclipse.passage.lic.emf.validation.ErrorMessages; import org.eclipse.passage.lic.internal.licenses.model.AssignGrantIdentifiers; import org.eclipse.passage.lic.licenses.LicensePlanDescriptor; @@ -85,8 +84,7 @@ ServiceInvocationResult issue(Supplier templ return new BaseServiceInvocationResult<>(new Trouble(new LicenseIssuingFailed(), LicensesCoreMessages.LicenseOperatorServiceImpl_error_io, e)); } - LicensedProduct product = product(license); - Path path = new UserHomeProductResidence(product).get(); + Path path = new LicensePackResidence(license.getLicense()).get(); Path decrypted; try { @@ -98,7 +96,7 @@ ServiceInvocationResult issue(Supplier templ Path encrypted; try { - encrypted = encrypted(license, product, decrypted); + encrypted = encrypted(license, product(license), decrypted); } catch (LicensingException e) { return new BaseServiceInvocationResult<>(new Trouble(new LicenseIssuingFailed(), LicensesCoreMessages.LicenseOperatorServiceImpl_export_error, e)); diff --git a/bundles/org.eclipse.passage.loc.licenses.core/src/org/eclipse/passage/loc/internal/licenses/core/LicensePackResidence.java b/bundles/org.eclipse.passage.loc.licenses.core/src/org/eclipse/passage/loc/internal/licenses/core/LicensePackResidence.java new file mode 100644 index 000000000..375e990fc --- /dev/null +++ b/bundles/org.eclipse.passage.loc.licenses.core/src/org/eclipse/passage/loc/internal/licenses/core/LicensePackResidence.java @@ -0,0 +1,47 @@ +/******************************************************************************* + * Copyright (c) 2022 ArSysOp + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License 2.0 which is available at + * https://www.eclipse.org/legal/epl-2.0/. + * + * SPDX-License-Identifier: EPL-2.0 + * + * Contributors: + * ArSysOp - initial API and implementation + *******************************************************************************/ +package org.eclipse.passage.loc.internal.licenses.core; + +import java.nio.file.Path; +import java.util.function.Supplier; + +import org.eclipse.passage.lic.base.io.UserHomeProductResidence; +import org.eclipse.passage.lic.licenses.model.api.LicenseRequisites; + +final class LicensePackResidence implements Supplier { + + private final LicenseRequisites license; + + LicensePackResidence(LicenseRequisites license) { + this.license = license; + } + + @Override + public Path get() { + return existing(residence()); + } + + private Path residence() { + return new UserHomeProductResidence(// + license.getProduct().getIdentifier(), // + license.getProduct().getVersion())// + .get()// + .resolve(license.getIdentifier()); + } + + private Path existing(Path folder) { + folder.toFile().mkdirs(); + return folder; + } + +}