diff --git a/bundles/org.eclipse.passage.loc.agreements.core/OSGI-INF/org.eclipse.passage.loc.internal.agreements.core.AgreementDomainRegistry.xml b/bundles/org.eclipse.passage.loc.agreements.core/OSGI-INF/org.eclipse.passage.loc.internal.agreements.core.AgreementDomainRegistry.xml index b6b201771..32024895d 100644 --- a/bundles/org.eclipse.passage.loc.agreements.core/OSGI-INF/org.eclipse.passage.loc.internal.agreements.core.AgreementDomainRegistry.xml +++ b/bundles/org.eclipse.passage.loc.agreements.core/OSGI-INF/org.eclipse.passage.loc.internal.agreements.core.AgreementDomainRegistry.xml @@ -7,5 +7,6 @@ + \ No newline at end of file diff --git a/bundles/org.eclipse.passage.loc.agreements.core/src/org/eclipse/passage/loc/internal/agreements/core/AgreementDomainRegistry.java b/bundles/org.eclipse.passage.loc.agreements.core/src/org/eclipse/passage/loc/internal/agreements/core/AgreementDomainRegistry.java index 96c64d843..4a6b2bc5a 100644 --- a/bundles/org.eclipse.passage.loc.agreements.core/src/org/eclipse/passage/loc/internal/agreements/core/AgreementDomainRegistry.java +++ b/bundles/org.eclipse.passage.loc.agreements.core/src/org/eclipse/passage/loc/internal/agreements/core/AgreementDomainRegistry.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2021 ArSysOp + * Copyright (c) 2021, 2022 ArSysOp * * This program and the accompanying materials are made available under the * terms of the Eclipse Public License 2.0 which is available at @@ -12,8 +12,6 @@ *******************************************************************************/ package org.eclipse.passage.loc.internal.agreements.core; -import java.nio.file.Files; -import java.nio.file.Path; import java.util.ArrayList; import java.util.Collection; import java.util.Collections; @@ -31,11 +29,15 @@ import org.eclipse.passage.lic.agreements.model.api.AgreementGroup; import org.eclipse.passage.lic.agreements.model.meta.AgreementsPackage; import org.eclipse.passage.lic.agreements.model.util.AgreementsResourceImpl; -import org.eclipse.passage.lic.equinox.io.InstallationPath; import org.eclipse.passage.lic.internal.equinox.events.EquinoxEvent; import org.eclipse.passage.loc.internal.agreements.AgreementRegistry; import org.eclipse.passage.loc.internal.agreements.AgreementRegistryEvents; import org.eclipse.passage.loc.internal.agreements.core.i18n.AgreementsCoreMessages; +import org.eclipse.passage.loc.internal.api.OperatorGearSupplier; +import org.eclipse.passage.loc.internal.api.workspace.Agreements; +import org.eclipse.passage.loc.internal.api.workspace.KnownResources; +import org.eclipse.passage.loc.internal.api.workspace.OperatorWorkspace; +import org.eclipse.passage.loc.internal.api.workspace.ResourceHandle; import org.eclipse.passage.loc.internal.emf.BaseDomainRegistry; import org.eclipse.passage.loc.internal.emf.DomainContentAdapter; import org.eclipse.passage.loc.internal.emf.EditingDomainRegistry; @@ -70,6 +72,17 @@ public void deactivate(Map properties) { super.deactivate(properties); } + @Override + @Reference + public void bindGear(OperatorGearSupplier supplier) { + super.bindGear(supplier); + } + + @Override + public void unbindGear(OperatorGearSupplier supplier) { + super.unbindGear(supplier); + } + @Reference public void bindEventAdmin(EventAdmin admin) { this.events = admin; @@ -197,15 +210,18 @@ public void unregisterContent(String identifier) { } @Override - protected Path getResourceSetPath() throws Exception { - Path passagePath = new InstallationPath().get(); - Files.createDirectories(passagePath); - return passagePath.resolve(domainName); + protected final Resource createResource(URI uri) { + return new AgreementsResourceImpl(uri); } @Override - protected final Resource createResource(URI uri) { - return new AgreementsResourceImpl(uri); + protected boolean emfResource(ResourceHandle handle) { + return Agreements.xmi.equals(handle.type()); + } + + @Override + protected KnownResources knownResources(OperatorWorkspace workspace) { + return workspace.agreements(); } } diff --git a/bundles/org.eclipse.passage.loc.api/src/org/eclipse/passage/loc/internal/api/workspace/Agreements.java b/bundles/org.eclipse.passage.loc.api/src/org/eclipse/passage/loc/internal/api/workspace/Agreements.java index 5069b3504..2fec4b617 100644 --- a/bundles/org.eclipse.passage.loc.api/src/org/eclipse/passage/loc/internal/api/workspace/Agreements.java +++ b/bundles/org.eclipse.passage.loc.api/src/org/eclipse/passage/loc/internal/api/workspace/Agreements.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2021 ArSysOp + * Copyright (c) 2021, 2022 ArSysOp * * This program and the accompanying materials are made available under the * terms of the Eclipse Public License 2.0 which is available at @@ -12,7 +12,7 @@ *******************************************************************************/ package org.eclipse.passage.loc.internal.api.workspace; -public interface Agreements { +public interface Agreements extends KnownResources { /** * Locate a handle for the given file under the common agreements residence @@ -24,4 +24,20 @@ public interface Agreements { boolean exists(String file); + ResourceType text = new ResourceType() { + + @Override + public String id() { + return "agreements_text"; //$NON-NLS-1$ + } + }; + + ResourceType xmi = new ResourceType() { + + @Override + public String id() { + return "agreements_xmi"; //$NON-NLS-1$ + } + }; + } diff --git a/bundles/org.eclipse.passage.loc.api/src/org/eclipse/passage/loc/internal/api/workspace/Features.java b/bundles/org.eclipse.passage.loc.api/src/org/eclipse/passage/loc/internal/api/workspace/Features.java new file mode 100644 index 000000000..f997dc6ee --- /dev/null +++ b/bundles/org.eclipse.passage.loc.api/src/org/eclipse/passage/loc/internal/api/workspace/Features.java @@ -0,0 +1,33 @@ +/******************************************************************************* + * 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.api.workspace; + +public interface Features extends KnownResources { + + ResourceType xmi = new ResourceType() { + + @Override + public String id() { + return "features_xmi"; //$NON-NLS-1$ + } + }; + + ResourceType xmi033 = new ResourceType() { + + @Override + public String id() { + return "lic_features"; //$NON-NLS-1$ + } + }; + +} diff --git a/bundles/org.eclipse.passage.loc.api/src/org/eclipse/passage/loc/internal/api/workspace/Keys.java b/bundles/org.eclipse.passage.loc.api/src/org/eclipse/passage/loc/internal/api/workspace/Keys.java index eb1057998..fc5f0ed88 100644 --- a/bundles/org.eclipse.passage.loc.api/src/org/eclipse/passage/loc/internal/api/workspace/Keys.java +++ b/bundles/org.eclipse.passage.loc.api/src/org/eclipse/passage/loc/internal/api/workspace/Keys.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2021 ArSysOp + * Copyright (c) 2021, 2022 ArSysOp * * This program and the accompanying materials are made available under the * terms of the Eclipse Public License 2.0 which is available at @@ -24,6 +24,22 @@ public interface Keys { ResourceHandle locatedPub(String product, String version); + ResourceType xmi = new ResourceType() { + + @Override + public String id() { + return "keys_xmi"; //$NON-NLS-1$ + } + }; + + ResourceType pub = new ResourceType() { + + @Override + public String id() { + return "pub"; //$NON-NLS-1$ + } + }; + public static final class Smart implements Keys { private final Keys delegate; diff --git a/bundles/org.eclipse.passage.loc.api/src/org/eclipse/passage/loc/internal/api/workspace/KnownResources.java b/bundles/org.eclipse.passage.loc.api/src/org/eclipse/passage/loc/internal/api/workspace/KnownResources.java new file mode 100644 index 000000000..5b7afeb69 --- /dev/null +++ b/bundles/org.eclipse.passage.loc.api/src/org/eclipse/passage/loc/internal/api/workspace/KnownResources.java @@ -0,0 +1,24 @@ +/******************************************************************************* + * 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.api.workspace; + +import java.util.List; + +public interface KnownResources { + + List all(); + + // FIXME: AF: temporary to not keep the functionality + void memento(List locations); + +} diff --git a/bundles/org.eclipse.passage.loc.api/src/org/eclipse/passage/loc/internal/api/workspace/Licenses.java b/bundles/org.eclipse.passage.loc.api/src/org/eclipse/passage/loc/internal/api/workspace/Licenses.java new file mode 100644 index 000000000..b6c4e5719 --- /dev/null +++ b/bundles/org.eclipse.passage.loc.api/src/org/eclipse/passage/loc/internal/api/workspace/Licenses.java @@ -0,0 +1,33 @@ +/******************************************************************************* + * 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.api.workspace; + +public interface Licenses extends KnownResources { + + ResourceType xmi = new ResourceType() { + + @Override + public String id() { + return "licenses_xmi"; //$NON-NLS-1$ + } + }; + + ResourceType xmi033 = new ResourceType() { + + @Override + public String id() { + return "lic_licenses"; //$NON-NLS-1$ + } + }; + +} diff --git a/bundles/org.eclipse.passage.loc.api/src/org/eclipse/passage/loc/internal/api/workspace/OperatorWorkspace.java b/bundles/org.eclipse.passage.loc.api/src/org/eclipse/passage/loc/internal/api/workspace/OperatorWorkspace.java index 5e92357a8..696d83f96 100644 --- a/bundles/org.eclipse.passage.loc.api/src/org/eclipse/passage/loc/internal/api/workspace/OperatorWorkspace.java +++ b/bundles/org.eclipse.passage.loc.api/src/org/eclipse/passage/loc/internal/api/workspace/OperatorWorkspace.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2021 ArSysOp + * Copyright (c) 2021, 2022 ArSysOp * * This program and the accompanying materials are made available under the * terms of the Eclipse Public License 2.0 which is available at @@ -14,8 +14,16 @@ public interface OperatorWorkspace { + Features features(); + + Products products(); + Keys keys(); Agreements agreements(); + Licenses licenses(); + + Users users(); + } diff --git a/bundles/org.eclipse.passage.loc.api/src/org/eclipse/passage/loc/internal/api/workspace/Products.java b/bundles/org.eclipse.passage.loc.api/src/org/eclipse/passage/loc/internal/api/workspace/Products.java new file mode 100644 index 000000000..2643dcfa0 --- /dev/null +++ b/bundles/org.eclipse.passage.loc.api/src/org/eclipse/passage/loc/internal/api/workspace/Products.java @@ -0,0 +1,33 @@ +/******************************************************************************* + * 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.api.workspace; + +public interface Products extends KnownResources { + + ResourceType xmi = new ResourceType() { + + @Override + public String id() { + return "products_xmi"; //$NON-NLS-1$ + } + }; + + ResourceType xmi033 = new ResourceType() { + + @Override + public String id() { + return "lic_products"; //$NON-NLS-1$ + } + }; + +} diff --git a/bundles/org.eclipse.passage.loc.api/src/org/eclipse/passage/loc/internal/api/workspace/ResourceHandle.java b/bundles/org.eclipse.passage.loc.api/src/org/eclipse/passage/loc/internal/api/workspace/ResourceHandle.java index c251cf4e2..9bd0b2296 100644 --- a/bundles/org.eclipse.passage.loc.api/src/org/eclipse/passage/loc/internal/api/workspace/ResourceHandle.java +++ b/bundles/org.eclipse.passage.loc.api/src/org/eclipse/passage/loc/internal/api/workspace/ResourceHandle.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2021 ArSysOp + * Copyright (c) 2021, 2022 ArSysOp * * This program and the accompanying materials are made available under the * terms of the Eclipse Public License 2.0 which is available at @@ -19,8 +19,13 @@ public interface ResourceHandle { */ String info(); + ResourceType type(); + void write(byte[] content) throws Exception; byte[] content() throws Exception; + // FIXME: AF: find better solution + String uri(); + } diff --git a/bundles/org.eclipse.passage.loc.api/src/org/eclipse/passage/loc/internal/api/workspace/ResourceType.java b/bundles/org.eclipse.passage.loc.api/src/org/eclipse/passage/loc/internal/api/workspace/ResourceType.java new file mode 100644 index 000000000..0e0ba3f3e --- /dev/null +++ b/bundles/org.eclipse.passage.loc.api/src/org/eclipse/passage/loc/internal/api/workspace/ResourceType.java @@ -0,0 +1,19 @@ +/******************************************************************************* + * 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.api.workspace; + +public interface ResourceType { + + String id(); + +} diff --git a/bundles/org.eclipse.passage.loc.api/src/org/eclipse/passage/loc/internal/api/workspace/Users.java b/bundles/org.eclipse.passage.loc.api/src/org/eclipse/passage/loc/internal/api/workspace/Users.java new file mode 100644 index 000000000..25a4a99a4 --- /dev/null +++ b/bundles/org.eclipse.passage.loc.api/src/org/eclipse/passage/loc/internal/api/workspace/Users.java @@ -0,0 +1,33 @@ +/******************************************************************************* + * 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.api.workspace; + +public interface Users extends KnownResources { + + ResourceType xmi = new ResourceType() { + + @Override + public String id() { + return "users_xmi"; //$NON-NLS-1$ + } + }; + + ResourceType xmi033 = new ResourceType() { + + @Override + public String id() { + return "lic_users"; //$NON-NLS-1$ + } + }; + +} diff --git a/bundles/org.eclipse.passage.loc.api/src/org/eclipse/passage/loc/internal/emf/BaseDomainRegistry.java b/bundles/org.eclipse.passage.loc.api/src/org/eclipse/passage/loc/internal/emf/BaseDomainRegistry.java index 734fbcf28..d84c3b5af 100644 --- a/bundles/org.eclipse.passage.loc.api/src/org/eclipse/passage/loc/internal/emf/BaseDomainRegistry.java +++ b/bundles/org.eclipse.passage.loc.api/src/org/eclipse/passage/loc/internal/emf/BaseDomainRegistry.java @@ -13,8 +13,6 @@ package org.eclipse.passage.loc.internal.emf; import java.io.IOException; -import java.nio.file.Files; -import java.nio.file.Path; import java.util.ArrayList; import java.util.Collections; import java.util.HashMap; @@ -38,79 +36,95 @@ import org.eclipse.passage.lic.api.diagnostic.Trouble; import org.eclipse.passage.lic.base.BaseServiceInvocationResult; import org.eclipse.passage.lic.base.diagnostic.DiagnosticExplained; -import org.eclipse.passage.lic.base.diagnostic.NoErrors; import org.eclipse.passage.lic.emf.resource.ResourceLoadFailed; import org.eclipse.passage.lic.internal.emf.i18n.EmfMessages; +import org.eclipse.passage.loc.internal.api.OperatorGear; +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; +import org.eclipse.passage.loc.internal.api.workspace.ResourceHandle; @SuppressWarnings("restriction") public abstract class BaseDomainRegistry implements EditingDomainRegistry, IEditingDomainProvider { protected String domainName; - private AdapterFactoryEditingDomain editingDomain; + private final AdapterFactoryEditingDomain editingDomain; - private final List sources = new ArrayList<>(); + private final List sources; - private EContentAdapter contentAdapter; + private final EContentAdapter contentAdapter; + + private final List gear; public BaseDomainRegistry() { + sources = new ArrayList<>(); + gear = new ArrayList<>(1); BasicCommandStack commandStack = new BasicCommandStack(); editingDomain = new AdapterFactoryEditingDomain( new ComposedAdapterFactory(ComposedAdapterFactory.Descriptor.Registry.INSTANCE), commandStack, new HashMap()); + contentAdapter = createContentAdapter(); } - protected void activate(Map properties) { - domainName = String.valueOf(properties.get(EditingDomainRegistryAccess.PROPERTY_DOMAIN_NAME)); - contentAdapter = createContentAdapter(); - ResourceSet resourceSet = editingDomain.getResourceSet(); - resourceSet.eAdapters().add(contentAdapter); - loadResourceSet(); + public void bindGear(OperatorGearSupplier supplier) { + gear.add(supplier); } - protected void loadResourceSet() { + public void unbindGear(OperatorGearSupplier supplier) { + gear.remove(supplier); + } + + protected void activate(Map properties) { + domainName = String.valueOf(properties.get(EditingDomainRegistryAccess.PROPERTY_DOMAIN_NAME)); + editingDomain.getResourceSet().eAdapters().add(contentAdapter); try { - Path domainPath = getResourceSetPath(); - if (!Files.exists(domainPath)) { - return; - } - Files.readAllLines(domainPath).stream()// - .map(URI::createURI)// - .map(this::registerSource)// - .map(ServiceInvocationResult::diagnostic)// - .filter(new NoErrors().negate())// - .forEach(this::logDiagnostic); + gear.stream()// + .findFirst()// + .map(OperatorGearSupplier::gear)// + .map(OperatorGear::workspace)// + .ifPresent(this::load); } catch (Exception e) { - Platform.getLog(getClass()).error(EmfMessages.BaseDomainRegistry_e_load_workspace, e); + Platform.getLog(getClass()).error(e.getMessage(), e); } } + private void load(OperatorWorkspace workspace) { + knownResources(workspace).all().stream()// + .filter(this::emfResource)// + .map(ResourceHandle::uri)// + .map(URI::createURI)// + .forEach(this::registerSource); + } + + protected abstract boolean emfResource(ResourceHandle handle); + + protected abstract KnownResources knownResources(OperatorWorkspace workspace); + protected void logDiagnostic(Diagnostic diagnostic) { Platform.getLog(getClass()).error(new DiagnosticExplained(diagnostic).get()); } - protected abstract Path getResourceSetPath() throws Exception; - protected abstract DomainContentAdapter> createContentAdapter(); protected void deactivate(Map properties) { - saveResourceSet(); - editingDomain.getResourceSet().eAdapters().remove(contentAdapter); - } - - protected void saveResourceSet() { try { - Path domainPath = getResourceSetPath(); - if (!Files.exists(domainPath)) { - Files.createFile(domainPath); - } - List strings = sources.stream()// - .map(URI::toString)// - .collect(Collectors.toList()); - Files.write(domainPath, strings); + gear.stream()// + .findFirst()// + .map(OperatorGearSupplier::gear)// + .map(OperatorGear::workspace)// + .ifPresent(this::store); } catch (Exception e) { Platform.getLog(getClass()).error(e.getMessage(), e); } + editingDomain.getResourceSet().eAdapters().remove(contentAdapter); + } + + private void store(OperatorWorkspace workspace) { + knownResources(workspace)// + .memento(getSources().stream()// + .map(URI::toString)// + .collect(Collectors.toList())); } @Override diff --git a/bundles/org.eclipse.passage.loc.features.core/OSGI-INF/org.eclipse.passage.loc.internal.features.core.FeatureDomainRegistry.xml b/bundles/org.eclipse.passage.loc.features.core/OSGI-INF/org.eclipse.passage.loc.internal.features.core.FeatureDomainRegistry.xml index 328e66aa4..593a0993e 100644 --- a/bundles/org.eclipse.passage.loc.features.core/OSGI-INF/org.eclipse.passage.loc.internal.features.core.FeatureDomainRegistry.xml +++ b/bundles/org.eclipse.passage.loc.features.core/OSGI-INF/org.eclipse.passage.loc.internal.features.core.FeatureDomainRegistry.xml @@ -7,5 +7,6 @@ + \ No newline at end of file diff --git a/bundles/org.eclipse.passage.loc.features.core/src/org/eclipse/passage/loc/internal/features/core/FeatureDomainRegistry.java b/bundles/org.eclipse.passage.loc.features.core/src/org/eclipse/passage/loc/internal/features/core/FeatureDomainRegistry.java index da158918c..7508d6411 100644 --- a/bundles/org.eclipse.passage.loc.features.core/src/org/eclipse/passage/loc/internal/features/core/FeatureDomainRegistry.java +++ b/bundles/org.eclipse.passage.loc.features.core/src/org/eclipse/passage/loc/internal/features/core/FeatureDomainRegistry.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2018, 2021 ArSysOp + * Copyright (c) 2018, 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 @@ -12,8 +12,6 @@ *******************************************************************************/ package org.eclipse.passage.loc.internal.features.core; -import java.nio.file.Files; -import java.nio.file.Path; import java.util.ArrayList; import java.util.Collection; import java.util.Collections; @@ -27,13 +25,17 @@ import org.eclipse.emf.ecore.EStructuralFeature; import org.eclipse.emf.ecore.resource.Resource; import org.eclipse.osgi.util.NLS; -import org.eclipse.passage.lic.equinox.io.InstallationPath; import org.eclipse.passage.lic.features.FeatureDescriptor; import org.eclipse.passage.lic.features.FeatureSetDescriptor; import org.eclipse.passage.lic.features.FeatureVersionDescriptor; import org.eclipse.passage.lic.features.model.meta.FeaturesPackage; import org.eclipse.passage.lic.features.model.util.FeaturesResourceImpl; import org.eclipse.passage.lic.internal.equinox.events.EquinoxEvent; +import org.eclipse.passage.loc.internal.api.OperatorGearSupplier; +import org.eclipse.passage.loc.internal.api.workspace.Features; +import org.eclipse.passage.loc.internal.api.workspace.KnownResources; +import org.eclipse.passage.loc.internal.api.workspace.OperatorWorkspace; +import org.eclipse.passage.loc.internal.api.workspace.ResourceHandle; import org.eclipse.passage.loc.internal.emf.BaseDomainRegistry; import org.eclipse.passage.loc.internal.emf.DomainContentAdapter; import org.eclipse.passage.loc.internal.emf.EditingDomainRegistry; @@ -67,6 +69,17 @@ public void unbindEventAdmin(@SuppressWarnings("unused") EventAdmin admin) { this.events = null; } + @Override + @Reference + public void bindGear(OperatorGearSupplier supplier) { + super.bindGear(supplier); + } + + @Override + public void unbindGear(OperatorGearSupplier supplier) { + super.unbindGear(supplier); + } + @Override @Activate public void activate(Map properties) { @@ -275,15 +288,18 @@ public void unregisterContent(String identifier) { } @Override - protected Path getResourceSetPath() throws Exception { - Path passagePath = new InstallationPath().get(); - Files.createDirectories(passagePath); - return passagePath.resolve(domainName); + protected final Resource createResource(URI uri) { + return new FeaturesResourceImpl(uri); } @Override - protected final Resource createResource(URI uri) { - return new FeaturesResourceImpl(uri); + protected boolean emfResource(ResourceHandle handle) { + return Features.xmi.equals(handle.type()) || Features.xmi033.equals(handle.type()); + } + + @Override + protected KnownResources knownResources(OperatorWorkspace workspace) { + return workspace.features(); } } diff --git a/bundles/org.eclipse.passage.loc.licenses.core/OSGI-INF/org.eclipse.passage.loc.internal.licenses.core.LicenseDomainRegistry.xml b/bundles/org.eclipse.passage.loc.licenses.core/OSGI-INF/org.eclipse.passage.loc.internal.licenses.core.LicenseDomainRegistry.xml index 6fe2aecac..71e90c075 100644 --- a/bundles/org.eclipse.passage.loc.licenses.core/OSGI-INF/org.eclipse.passage.loc.internal.licenses.core.LicenseDomainRegistry.xml +++ b/bundles/org.eclipse.passage.loc.licenses.core/OSGI-INF/org.eclipse.passage.loc.internal.licenses.core.LicenseDomainRegistry.xml @@ -7,5 +7,6 @@ + \ No newline at end of file diff --git a/bundles/org.eclipse.passage.loc.licenses.core/src/org/eclipse/passage/loc/internal/licenses/core/LicenseDomainRegistry.java b/bundles/org.eclipse.passage.loc.licenses.core/src/org/eclipse/passage/loc/internal/licenses/core/LicenseDomainRegistry.java index 8a8507d49..e794a4913 100644 --- a/bundles/org.eclipse.passage.loc.licenses.core/src/org/eclipse/passage/loc/internal/licenses/core/LicenseDomainRegistry.java +++ b/bundles/org.eclipse.passage.loc.licenses.core/src/org/eclipse/passage/loc/internal/licenses/core/LicenseDomainRegistry.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2018, 2021 ArSysOp + * Copyright (c) 2018, 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 @@ -12,8 +12,6 @@ *******************************************************************************/ package org.eclipse.passage.loc.internal.licenses.core; -import java.nio.file.Files; -import java.nio.file.Path; import java.util.ArrayList; import java.util.Collection; import java.util.HashMap; @@ -25,11 +23,15 @@ import org.eclipse.emf.ecore.EStructuralFeature; import org.eclipse.emf.ecore.resource.Resource; import org.eclipse.osgi.util.NLS; -import org.eclipse.passage.lic.equinox.io.InstallationPath; import org.eclipse.passage.lic.internal.equinox.events.EquinoxEvent; import org.eclipse.passage.lic.licenses.LicensePlanDescriptor; import org.eclipse.passage.lic.licenses.model.meta.LicensesPackage; import org.eclipse.passage.lic.licenses.model.util.LicensesResourceImpl; +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.Licenses; +import org.eclipse.passage.loc.internal.api.workspace.OperatorWorkspace; +import org.eclipse.passage.loc.internal.api.workspace.ResourceHandle; import org.eclipse.passage.loc.internal.emf.BaseDomainRegistry; import org.eclipse.passage.loc.internal.emf.DomainContentAdapter; import org.eclipse.passage.loc.internal.emf.EditingDomainRegistry; @@ -61,6 +63,17 @@ public void unbindEventAdmin(@SuppressWarnings("unused") EventAdmin admin) { this.events = null; } + @Override + @Reference + public void bindGear(OperatorGearSupplier supplier) { + super.bindGear(supplier); + } + + @Override + public void unbindGear(OperatorGearSupplier supplier) { + super.unbindGear(supplier); + } + @Override @Activate public void activate(Map properties) { @@ -149,15 +162,18 @@ public void unregisterContent(String identifier) { } @Override - protected Path getResourceSetPath() throws Exception { - Path passagePath = new InstallationPath().get(); - Files.createDirectories(passagePath); - return passagePath.resolve(domainName); + protected final Resource createResource(URI uri) { + return new LicensesResourceImpl(uri); } @Override - protected final Resource createResource(URI uri) { - return new LicensesResourceImpl(uri); + protected boolean emfResource(ResourceHandle handle) { + return Licenses.xmi.equals(handle.type()) || Licenses.xmi033.equals(handle.type()); + } + + @Override + protected KnownResources knownResources(OperatorWorkspace workspace) { + return workspace.licenses(); } } diff --git a/bundles/org.eclipse.passage.loc.products.core/OSGI-INF/org.eclipse.passage.loc.internal.products.core.ProductDomainRegistry.xml b/bundles/org.eclipse.passage.loc.products.core/OSGI-INF/org.eclipse.passage.loc.internal.products.core.ProductDomainRegistry.xml index 0600bffba..1aa05da54 100644 --- a/bundles/org.eclipse.passage.loc.products.core/OSGI-INF/org.eclipse.passage.loc.internal.products.core.ProductDomainRegistry.xml +++ b/bundles/org.eclipse.passage.loc.products.core/OSGI-INF/org.eclipse.passage.loc.internal.products.core.ProductDomainRegistry.xml @@ -7,5 +7,6 @@ + \ No newline at end of file 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 90ac944ea..a880b50cd 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 @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2018, 2021 ArSysOp + * Copyright (c) 2018, 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 @@ -12,8 +12,6 @@ *******************************************************************************/ package org.eclipse.passage.loc.internal.products.core; -import java.nio.file.Files; -import java.nio.file.Path; import java.util.ArrayList; import java.util.Collection; import java.util.Collections; @@ -27,7 +25,6 @@ import org.eclipse.emf.ecore.EStructuralFeature; import org.eclipse.emf.ecore.resource.Resource; import org.eclipse.osgi.util.NLS; -import org.eclipse.passage.lic.equinox.io.InstallationPath; import org.eclipse.passage.lic.internal.equinox.events.EquinoxEvent; import org.eclipse.passage.lic.products.ProductDescriptor; import org.eclipse.passage.lic.products.ProductLineDescriptor; @@ -35,6 +32,11 @@ import org.eclipse.passage.lic.products.ProductVersionFeatureDescriptor; 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; +import org.eclipse.passage.loc.internal.api.workspace.Products; +import org.eclipse.passage.loc.internal.api.workspace.ResourceHandle; import org.eclipse.passage.loc.internal.emf.BaseDomainRegistry; import org.eclipse.passage.loc.internal.emf.DomainContentAdapter; import org.eclipse.passage.loc.internal.emf.EditingDomainRegistry; @@ -69,6 +71,17 @@ public void unbindEventAdmin(@SuppressWarnings("unused") EventAdmin admin) { this.events = null; } + @Override + @Reference + public void bindGear(OperatorGearSupplier supplier) { + super.bindGear(supplier); + } + + @Override + public void unbindGear(OperatorGearSupplier supplier) { + super.unbindGear(supplier); + } + @Override @Activate public void activate(Map properties) { @@ -335,15 +348,18 @@ public void unregisterContent(String identifier) { } @Override - protected Path getResourceSetPath() throws Exception { - Path passagePath = new InstallationPath().get(); - Files.createDirectories(passagePath); - return passagePath.resolve(domainName); + protected final Resource createResource(URI uri) { + return new ProductsResourceImpl(uri); } @Override - protected final Resource createResource(URI uri) { - return new ProductsResourceImpl(uri); + protected boolean emfResource(ResourceHandle handle) { + return Products.xmi.equals(handle.type()) || Products.xmi033.equals(handle.type()); + } + + @Override + protected KnownResources knownResources(OperatorWorkspace workspace) { + return workspace.products(); } } diff --git a/bundles/org.eclipse.passage.loc.users.core/OSGI-INF/org.eclipse.passage.loc.internal.users.core.UserDomainRegistry.xml b/bundles/org.eclipse.passage.loc.users.core/OSGI-INF/org.eclipse.passage.loc.internal.users.core.UserDomainRegistry.xml index b24ee7f3c..d8d16c0ac 100644 --- a/bundles/org.eclipse.passage.loc.users.core/OSGI-INF/org.eclipse.passage.loc.internal.users.core.UserDomainRegistry.xml +++ b/bundles/org.eclipse.passage.loc.users.core/OSGI-INF/org.eclipse.passage.loc.internal.users.core.UserDomainRegistry.xml @@ -7,5 +7,6 @@ + \ No newline at end of file diff --git a/bundles/org.eclipse.passage.loc.users.core/src/org/eclipse/passage/loc/internal/users/core/UserDomainRegistry.java b/bundles/org.eclipse.passage.loc.users.core/src/org/eclipse/passage/loc/internal/users/core/UserDomainRegistry.java index 2216249a3..cec41794d 100644 --- a/bundles/org.eclipse.passage.loc.users.core/src/org/eclipse/passage/loc/internal/users/core/UserDomainRegistry.java +++ b/bundles/org.eclipse.passage.loc.users.core/src/org/eclipse/passage/loc/internal/users/core/UserDomainRegistry.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2018, 2021 ArSysOp + * Copyright (c) 2018, 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 @@ -12,8 +12,6 @@ *******************************************************************************/ package org.eclipse.passage.loc.internal.users.core; -import java.nio.file.Files; -import java.nio.file.Path; import java.util.ArrayList; import java.util.Collections; import java.util.HashMap; @@ -25,12 +23,16 @@ import org.eclipse.emf.ecore.EStructuralFeature; import org.eclipse.emf.ecore.resource.Resource; import org.eclipse.osgi.util.NLS; -import org.eclipse.passage.lic.equinox.io.InstallationPath; import org.eclipse.passage.lic.internal.equinox.events.EquinoxEvent; import org.eclipse.passage.lic.users.UserDescriptor; import org.eclipse.passage.lic.users.UserOriginDescriptor; import org.eclipse.passage.lic.users.model.meta.UsersPackage; import org.eclipse.passage.lic.users.model.util.UsersResourceImpl; +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; +import org.eclipse.passage.loc.internal.api.workspace.ResourceHandle; +import org.eclipse.passage.loc.internal.api.workspace.Users; import org.eclipse.passage.loc.internal.emf.BaseDomainRegistry; import org.eclipse.passage.loc.internal.emf.DomainContentAdapter; import org.eclipse.passage.loc.internal.emf.EditingDomainRegistry; @@ -63,6 +65,17 @@ public void unbindEventAdmin(@SuppressWarnings("unused") EventAdmin admin) { this.events = null; } + @Override + @Reference + public void bindGear(OperatorGearSupplier supplier) { + super.bindGear(supplier); + } + + @Override + public void unbindGear(OperatorGearSupplier supplier) { + super.unbindGear(supplier); + } + @Override @Activate public void activate(Map properties) { @@ -189,15 +202,18 @@ public void unregisterContent(String identifier) { } @Override - protected Path getResourceSetPath() throws Exception { - Path passagePath = new InstallationPath().get(); - Files.createDirectories(passagePath); - return passagePath.resolve(domainName); + protected final Resource createResource(URI uri) { + return new UsersResourceImpl(uri); } @Override - protected final Resource createResource(URI uri) { - return new UsersResourceImpl(uri); + protected boolean emfResource(ResourceHandle handle) { + return Users.xmi.equals(handle.type()) || Users.xmi033.equals(handle.type()); + } + + @Override + protected KnownResources knownResources(OperatorWorkspace workspace) { + return workspace.users(); } } diff --git a/bundles/org.eclipse.passage.loc.workbench/src/org/eclipse/passage/loc/internal/workbench/LocDomainRegistryAccess.java b/bundles/org.eclipse.passage.loc.workbench/src/org/eclipse/passage/loc/internal/workbench/LocDomainRegistryAccess.java index bb35ae7e9..6b76092ac 100644 --- a/bundles/org.eclipse.passage.loc.workbench/src/org/eclipse/passage/loc/internal/workbench/LocDomainRegistryAccess.java +++ b/bundles/org.eclipse.passage.loc.workbench/src/org/eclipse/passage/loc/internal/workbench/LocDomainRegistryAccess.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2018, 2021 ArSysOp + * Copyright (c) 2018, 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 @@ -39,6 +39,7 @@ public class LocDomainRegistryAccess implements EditingDomainRegistryAccess { @Reference(cardinality = ReferenceCardinality.MULTIPLE) public void registerEditingDomainRegistry(EditingDomainRegistry instance, Map properties) { + System.out.println("LocDomainRegistryAccess.registerEditingDomainRegistry()"); //$NON-NLS-1$ String domain = String.valueOf(properties.get(PROPERTY_DOMAIN_NAME)); registerEntry(domainRegistries, domain, instance); String extension = String.valueOf(properties.get(PROPERTY_FILE_EXTENSION)); diff --git a/bundles/org.eclipse.passage.loc.workspace/src/org/eclipse/passage/loc/workspace/CollectiveWorkspace.java b/bundles/org.eclipse.passage.loc.workspace/src/org/eclipse/passage/loc/workspace/CollectiveWorkspace.java index 0833771dc..c5bf928f1 100644 --- a/bundles/org.eclipse.passage.loc.workspace/src/org/eclipse/passage/loc/workspace/CollectiveWorkspace.java +++ b/bundles/org.eclipse.passage.loc.workspace/src/org/eclipse/passage/loc/workspace/CollectiveWorkspace.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2021 ArSysOp + * Copyright (c) 2021, 2022 ArSysOp * * This program and the accompanying materials are made available under the * terms of the Eclipse Public License 2.0 which is available at @@ -13,17 +13,39 @@ package org.eclipse.passage.loc.workspace; import org.eclipse.passage.loc.internal.api.workspace.Agreements; +import org.eclipse.passage.loc.internal.api.workspace.Features; import org.eclipse.passage.loc.internal.api.workspace.Keys; +import org.eclipse.passage.loc.internal.api.workspace.Licenses; import org.eclipse.passage.loc.internal.api.workspace.OperatorWorkspace; +import org.eclipse.passage.loc.internal.api.workspace.Products; +import org.eclipse.passage.loc.internal.api.workspace.Users; public final class CollectiveWorkspace implements OperatorWorkspace { + private final Features features; + private final Products products; private final Keys keys; private final Agreements agreements; + private final Licenses licenses; + private final Users users; public CollectiveWorkspace() { + this.features = new UncertainFeatures(); + this.products = new UncertainProducts(); this.keys = new HomeBasedKeys(); this.agreements = new HomeBasedAgreements(); + this.licenses = new UncertainLicenses(); + this.users = new UncertainUsers(); + } + + @Override + public Features features() { + return features; + } + + @Override + public Products products() { + return products; } @Override @@ -36,4 +58,14 @@ public Agreements agreements() { return agreements; } + @Override + public Licenses licenses() { + return licenses; + } + + @Override + public Users users() { + return users; + } + } diff --git a/bundles/org.eclipse.passage.loc.workspace/src/org/eclipse/passage/loc/workspace/HomeBasedAgreements.java b/bundles/org.eclipse.passage.loc.workspace/src/org/eclipse/passage/loc/workspace/HomeBasedAgreements.java index 50de4161c..0f9243ccb 100644 --- a/bundles/org.eclipse.passage.loc.workspace/src/org/eclipse/passage/loc/workspace/HomeBasedAgreements.java +++ b/bundles/org.eclipse.passage.loc.workspace/src/org/eclipse/passage/loc/workspace/HomeBasedAgreements.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2021 ArSysOp + * Copyright (c) 2021, 2022 ArSysOp * * This program and the accompanying materials are made available under the * terms of the Eclipse Public License 2.0 which is available at @@ -14,9 +14,11 @@ import java.nio.file.Files; import java.nio.file.Path; +import java.util.List; import org.eclipse.passage.lic.base.io.LicensingFolder; import org.eclipse.passage.lic.base.io.UserHomePath; +import org.eclipse.passage.lic.equinox.io.InstallationPath; import org.eclipse.passage.loc.internal.api.workspace.Agreements; import org.eclipse.passage.loc.internal.api.workspace.ResourceHandle; @@ -30,7 +32,7 @@ final class HomeBasedAgreements implements Agreements { @Override public ResourceHandle located(String file) { - return new LocalFileHandle(residence.resolve(file)); + return new LocalFileHandle(text, residence.resolve(file)); } @Override @@ -38,4 +40,21 @@ public boolean exists(String file) { return Files.exists(residence.resolve(file)); } + @Override + public List all() { + return new LoadResourceSet(// + xmi, // + new InstallationPath(), // + "agreements" //$NON-NLS-1$ + ).load(); + } + + @Override + public void memento(List locations) { + new StoreResourceSet(// + new InstallationPath(), // + "agreements" //$NON-NLS-1$ + ).store(locations); + } + } diff --git a/bundles/org.eclipse.passage.loc.workspace/src/org/eclipse/passage/loc/workspace/HomeBasedKeys.java b/bundles/org.eclipse.passage.loc.workspace/src/org/eclipse/passage/loc/workspace/HomeBasedKeys.java index 8f98969bf..793317697 100644 --- a/bundles/org.eclipse.passage.loc.workspace/src/org/eclipse/passage/loc/workspace/HomeBasedKeys.java +++ b/bundles/org.eclipse.passage.loc.workspace/src/org/eclipse/passage/loc/workspace/HomeBasedKeys.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2021 ArSysOp + * Copyright (c) 2021, 2022 ArSysOp * * This program and the accompanying materials are made available under the * terms of the Eclipse Public License 2.0 which is available at @@ -28,7 +28,6 @@ final class HomeBasedKeys implements Keys { private final Path residence; private final PassageFileExtension keys = new DomainFileExtension.Keys(); - private final PassageFileExtension pub = new PassageFileExtension.PublicKey(); HomeBasedKeys() { this.residence = new LicensingFolder(new UserHomePath()).get(); @@ -41,12 +40,12 @@ public Optional existing(String product, String version) { @Override public ResourceHandle located(String product, String version) { - return new LocalFileHandle(residentFile(product, version, keys)); + return new LocalFileHandle(xmi, residentFile(product, version, keys)); } @Override public ResourceHandle locatedPub(String product, String version) { - return new LocalFileHandle(residentFile(product, version, pub)); + return new LocalFileHandle(pub, residentFile(product, version, new PassageFileExtension.PublicKey())); } private Path residentFile(String product, String version, PassageFileExtension ext) { diff --git a/bundles/org.eclipse.passage.loc.workspace/src/org/eclipse/passage/loc/workspace/LoadResourceSet.java b/bundles/org.eclipse.passage.loc.workspace/src/org/eclipse/passage/loc/workspace/LoadResourceSet.java new file mode 100644 index 000000000..94af0086e --- /dev/null +++ b/bundles/org.eclipse.passage.loc.workspace/src/org/eclipse/passage/loc/workspace/LoadResourceSet.java @@ -0,0 +1,59 @@ +/******************************************************************************* + * 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.workspace; + +import java.nio.file.Files; +import java.nio.file.Path; +import java.nio.file.Paths; +import java.util.Collections; +import java.util.List; +import java.util.Objects; +import java.util.function.Supplier; +import java.util.stream.Collectors; + +import org.eclipse.core.runtime.Platform; +import org.eclipse.passage.loc.internal.api.workspace.ResourceHandle; +import org.eclipse.passage.loc.internal.api.workspace.ResourceType; + +public final class LoadResourceSet { + + private final Supplier base; + private final String domain; + private final ResourceType type; + + public LoadResourceSet(ResourceType type, Supplier path, String domain) { + this.base = Objects.requireNonNull(path); + this.domain = Objects.requireNonNull(domain); + this.type = Objects.requireNonNull(type); + } + + public List load() { + try { + Path parent = base.get(); + Files.createDirectories(parent); + Path path = parent.resolve(domain); + if (!Files.exists(path)) { + // FIXME: AF: log? + return Collections.emptyList(); + } + return Files.readAllLines(path).stream()// + .map(Paths::get)// + .map(p -> new LocalFileHandle(type, path))// + .collect(Collectors.toList()); + } catch (Exception e) { + Platform.getLog(getClass()).error(e.getMessage(), e); + } + return Collections.emptyList(); + } + +} diff --git a/bundles/org.eclipse.passage.loc.workspace/src/org/eclipse/passage/loc/workspace/LocalFileHandle.java b/bundles/org.eclipse.passage.loc.workspace/src/org/eclipse/passage/loc/workspace/LocalFileHandle.java index 13e518c7d..318503857 100644 --- a/bundles/org.eclipse.passage.loc.workspace/src/org/eclipse/passage/loc/workspace/LocalFileHandle.java +++ b/bundles/org.eclipse.passage.loc.workspace/src/org/eclipse/passage/loc/workspace/LocalFileHandle.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2021 ArSysOp + * Copyright (c) 2021, 2022 ArSysOp * * This program and the accompanying materials are made available under the * terms of the Eclipse Public License 2.0 which is available at @@ -17,18 +17,24 @@ import java.io.FileOutputStream; import java.io.OutputStream; import java.nio.file.Path; +import java.util.Objects; +import org.eclipse.emf.common.util.URI; import org.eclipse.passage.loc.internal.api.workspace.ResourceHandle; +import org.eclipse.passage.loc.internal.api.workspace.ResourceType; /** * temporary + * */ class LocalFileHandle implements ResourceHandle { + private final ResourceType type; private final Path path; - public LocalFileHandle(Path path) { - this.path = path; + public LocalFileHandle(ResourceType type, Path path) { + this.type = Objects.requireNonNull(type); + this.path = Objects.requireNonNull(path); } @Override @@ -53,4 +59,14 @@ public byte[] content() throws Exception { } } + @Override + public ResourceType type() { + return type; + } + + @Override + public String uri() { + return URI.createFileURI(path.toFile().toString()).toString(); + } + } diff --git a/bundles/org.eclipse.passage.loc.workspace/src/org/eclipse/passage/loc/workspace/StoreResourceSet.java b/bundles/org.eclipse.passage.loc.workspace/src/org/eclipse/passage/loc/workspace/StoreResourceSet.java new file mode 100644 index 000000000..4d422d123 --- /dev/null +++ b/bundles/org.eclipse.passage.loc.workspace/src/org/eclipse/passage/loc/workspace/StoreResourceSet.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.workspace; + +import java.nio.file.Files; +import java.nio.file.Path; +import java.util.List; +import java.util.Objects; +import java.util.function.Supplier; + +import org.eclipse.core.runtime.Platform; + +public final class StoreResourceSet { + + private final Supplier base; + private final String domain; + + public StoreResourceSet(Supplier path, String domain) { + this.base = Objects.requireNonNull(path); + this.domain = Objects.requireNonNull(domain); + } + + public void store(List locations) { + try { + Path parent = base.get(); + Files.createDirectories(parent); + Path path = parent.resolve(domain); + if (!Files.exists(path)) { + Files.createFile(path); + } + Files.write(path, locations); + } catch (Exception e) { + Platform.getLog(getClass()).error(e.getMessage(), e); + } + } + +} diff --git a/bundles/org.eclipse.passage.loc.workspace/src/org/eclipse/passage/loc/workspace/UncertainFeatures.java b/bundles/org.eclipse.passage.loc.workspace/src/org/eclipse/passage/loc/workspace/UncertainFeatures.java new file mode 100644 index 000000000..ce50dd386 --- /dev/null +++ b/bundles/org.eclipse.passage.loc.workspace/src/org/eclipse/passage/loc/workspace/UncertainFeatures.java @@ -0,0 +1,28 @@ +package org.eclipse.passage.loc.workspace; + +import java.util.List; + +import org.eclipse.passage.lic.equinox.io.InstallationPath; +import org.eclipse.passage.loc.internal.api.workspace.Features; +import org.eclipse.passage.loc.internal.api.workspace.ResourceHandle; + +final class UncertainFeatures implements Features { + + @Override + public List all() { + return new LoadResourceSet(// + xmi, // + new InstallationPath(), // + "features" //$NON-NLS-1$ + ).load(); + } + + @Override + public void memento(List locations) { + new StoreResourceSet(// + new InstallationPath(), // + "features" //$NON-NLS-1$ + ).store(locations); + } + +} diff --git a/bundles/org.eclipse.passage.loc.workspace/src/org/eclipse/passage/loc/workspace/UncertainLicenses.java b/bundles/org.eclipse.passage.loc.workspace/src/org/eclipse/passage/loc/workspace/UncertainLicenses.java new file mode 100644 index 000000000..cf9dc6480 --- /dev/null +++ b/bundles/org.eclipse.passage.loc.workspace/src/org/eclipse/passage/loc/workspace/UncertainLicenses.java @@ -0,0 +1,28 @@ +package org.eclipse.passage.loc.workspace; + +import java.util.List; + +import org.eclipse.passage.lic.equinox.io.InstallationPath; +import org.eclipse.passage.loc.internal.api.workspace.Licenses; +import org.eclipse.passage.loc.internal.api.workspace.ResourceHandle; + +final class UncertainLicenses implements Licenses { + + @Override + public List all() { + return new LoadResourceSet(// + xmi, // + new InstallationPath(), // + "licenses" //$NON-NLS-1$ + ).load(); + } + + @Override + public void memento(List locations) { + new StoreResourceSet(// + new InstallationPath(), // + "licenses" //$NON-NLS-1$ + ).store(locations); + } + +} diff --git a/bundles/org.eclipse.passage.loc.workspace/src/org/eclipse/passage/loc/workspace/UncertainProducts.java b/bundles/org.eclipse.passage.loc.workspace/src/org/eclipse/passage/loc/workspace/UncertainProducts.java new file mode 100644 index 000000000..3039c0d20 --- /dev/null +++ b/bundles/org.eclipse.passage.loc.workspace/src/org/eclipse/passage/loc/workspace/UncertainProducts.java @@ -0,0 +1,28 @@ +package org.eclipse.passage.loc.workspace; + +import java.util.List; + +import org.eclipse.passage.lic.equinox.io.InstallationPath; +import org.eclipse.passage.loc.internal.api.workspace.Products; +import org.eclipse.passage.loc.internal.api.workspace.ResourceHandle; + +final class UncertainProducts implements Products { + + @Override + public List all() { + return new LoadResourceSet(// + xmi, // + new InstallationPath(), // + "products" //$NON-NLS-1$ + ).load(); + } + + @Override + public void memento(List locations) { + new StoreResourceSet(// + new InstallationPath(), // + "products" //$NON-NLS-1$ + ).store(locations); + } + +} diff --git a/bundles/org.eclipse.passage.loc.workspace/src/org/eclipse/passage/loc/workspace/UncertainUsers.java b/bundles/org.eclipse.passage.loc.workspace/src/org/eclipse/passage/loc/workspace/UncertainUsers.java new file mode 100644 index 000000000..21d307ad0 --- /dev/null +++ b/bundles/org.eclipse.passage.loc.workspace/src/org/eclipse/passage/loc/workspace/UncertainUsers.java @@ -0,0 +1,28 @@ +package org.eclipse.passage.loc.workspace; + +import java.util.List; + +import org.eclipse.passage.lic.equinox.io.InstallationPath; +import org.eclipse.passage.loc.internal.api.workspace.ResourceHandle; +import org.eclipse.passage.loc.internal.api.workspace.Users; + +final class UncertainUsers implements Users { + + @Override + public List all() { + return new LoadResourceSet(// + xmi, // + new InstallationPath(), // + "users" //$NON-NLS-1$ + ).load(); + } + + @Override + public void memento(List locations) { + new StoreResourceSet(// + new InstallationPath(), // + "users" //$NON-NLS-1$ + ).store(locations); + } + +}