Skip to content

Commit

Permalink
Bug 566287 API revision | remove deprecated code
Browse files Browse the repository at this point in the history
Rework StreamCodec usages and remove it

Signed-off-by: Alexander Fedorov <alexander.fedorov@arsysop.ru>
  • Loading branch information
ruspl-afed committed Sep 2, 2020
1 parent 34512cb commit f6d8948
Show file tree
Hide file tree
Showing 7 changed files with 22 additions and 108 deletions.
1 change: 0 additions & 1 deletion bundles/org.eclipse.passage.lic.api/META-INF/MANIFEST.MF
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ Bundle-Vendor: %Bundle-Vendor
Bundle-Copyright: %Bundle-Copyright
Bundle-RequiredExecutionEnvironment: JavaSE-1.8
Export-Package: org.eclipse.passage.lic.api,
org.eclipse.passage.lic.api.io,
org.eclipse.passage.lic.internal.api;
x-friends:="org.eclipse.passage.lbc.api,
org.eclipse.passage.lbc.base,
Expand Down

This file was deleted.

1 change: 1 addition & 0 deletions bundles/org.eclipse.passage.loc.api/META-INF/MANIFEST.MF
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ Require-Bundle: org.eclipse.e4.core.services;bundle-version="0.0.0",
org.eclipse.osgi;bundle-version="3.16.0",
org.eclipse.passage.lic.base;bundle-version="1.0.0",
org.eclipse.passage.lic.emf;bundle-version="1.0.0",
org.eclipse.passage.lic.equinox;bundle-version="1.0.0",
org.eclipse.passage.lic.licenses;bundle-version="1.0.0";visibility:=reexport,
org.eclipse.passage.lic.products;bundle-version="1.0.0";visibility:=reexport,
org.eclipse.passage.lic.users;bundle-version="1.0.0";visibility:=reexport,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
* Contributors:
* ArSysOp - initial API and implementation
*******************************************************************************/
package org.eclipse.passage.loc.internal.licenses.core;
package org.eclipse.passage.loc.internal.api;

import java.util.Optional;
import java.util.function.Supplier;
Expand All @@ -21,11 +21,11 @@
import org.eclipse.passage.lic.internal.equinox.FrameworkAware;

@SuppressWarnings("restriction")
final class CodecSupplier extends FrameworkAware implements Supplier<Optional<StreamCodec>> {
public final class CodecSupplier extends FrameworkAware implements Supplier<Optional<StreamCodec>> {

private final LicensedProduct product;

CodecSupplier(LicensedProduct product) {
public CodecSupplier(LicensedProduct product) {
this.product = product;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@
import org.eclipse.passage.lic.users.model.api.UserLicense;
import org.eclipse.passage.lic.users.model.meta.UsersFactory;
import org.eclipse.passage.lic.users.model.meta.UsersPackage;
import org.eclipse.passage.loc.internal.api.CodecSupplier;
import org.eclipse.passage.loc.internal.api.IssuedLicense;
import org.eclipse.passage.loc.internal.api.LicensingPaths;
import org.eclipse.passage.loc.internal.api.LicensingRequest;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,5 @@
</service>
<reference bind="bindEnvironmentInfo" interface="org.eclipse.osgi.service.environment.EnvironmentInfo" name="EnvironmentInfo" unbind="unbindEnvironmentInfo"/>
<reference bind="bindEventAdmin" interface="org.osgi.service.event.EventAdmin" name="EventAdmin" unbind="unbindEventAdmin"/>
<reference bind="bindStreamCodec" cardinality="0..1" interface="org.eclipse.passage.lic.api.io.StreamCodec" name="StreamCodec" unbind="unbindStreamCodec"/>
<implementation class="org.eclipse.passage.loc.internal.products.core.ProductOperatorServiceImpl"/>
</scr:component>
Original file line number Diff line number Diff line change
Expand Up @@ -17,16 +17,20 @@
import java.nio.file.Files;
import java.nio.file.Path;
import java.nio.file.Paths;
import java.util.Optional;

import org.eclipse.core.runtime.IStatus;
import org.eclipse.core.runtime.Status;
import org.eclipse.osgi.service.environment.EnvironmentInfo;
import org.eclipse.passage.lic.api.io.StreamCodec;
import org.eclipse.passage.lic.emf.ecore.LicensingEcore;
import org.eclipse.passage.lic.internal.api.LicensedProduct;
import org.eclipse.passage.lic.internal.api.io.StreamCodec;
import org.eclipse.passage.lic.internal.base.BaseLicensedProduct;
import org.eclipse.passage.lic.products.ProductDescriptor;
import org.eclipse.passage.lic.products.ProductVersionDescriptor;
import org.eclipse.passage.lic.products.model.api.Product;
import org.eclipse.passage.lic.products.model.api.ProductVersion;
import org.eclipse.passage.loc.internal.api.CodecSupplier;
import org.eclipse.passage.loc.internal.api.LicensingPaths;
import org.eclipse.passage.loc.internal.api.OperatorProductEvents;
import org.eclipse.passage.loc.internal.api.OperatorProductService;
Expand All @@ -35,7 +39,6 @@
import org.osgi.service.component.annotations.Activate;
import org.osgi.service.component.annotations.Component;
import org.osgi.service.component.annotations.Reference;
import org.osgi.service.component.annotations.ReferenceCardinality;
import org.osgi.service.event.EventAdmin;

@Component
Expand All @@ -45,7 +48,6 @@ public class ProductOperatorServiceImpl implements OperatorProductService {

private EnvironmentInfo environmentInfo;
private EventAdmin eventAdmin;
private StreamCodec streamCodec;

@Activate
public void activate(BundleContext context) {
Expand Down Expand Up @@ -74,17 +76,6 @@ public void unbindEventAdmin(EventAdmin admin) {
}
}

@Reference(cardinality = ReferenceCardinality.OPTIONAL)
public void bindStreamCodec(StreamCodec codec) {
this.streamCodec = codec;
}

public void unbindStreamCodec(StreamCodec codec) {
if (this.streamCodec == codec) {
this.streamCodec = null;
}
}

@Override
public String createPassword(ProductVersionDescriptor descriptor) {
String id = null;
Expand All @@ -108,7 +99,8 @@ public IStatus createProductKeys(ProductVersionDescriptor descriptor) {
productVersion = (ProductVersion) descriptor;
}
if (productVersion == null) {
return new Status(IStatus.ERROR, pluginId, ProductsCoreMessages.ProductOperatorServiceImpl_e_invalid_product_version);
return new Status(IStatus.ERROR, pluginId,
ProductsCoreMessages.ProductOperatorServiceImpl_e_invalid_product_version);
}
String installationToken = productVersion.getInstallationToken();
if (installationToken != null) {
Expand Down Expand Up @@ -136,7 +128,8 @@ public IStatus createProductKeys(ProductVersionDescriptor descriptor) {
}
String identifier = product.getIdentifier();
String version = productVersion.getVersion();
if (streamCodec == null) {
Optional<StreamCodec> codec = codec(new BaseLicensedProduct(identifier, version));
if (codec.isEmpty()) {
String pattern = ProductsCoreMessages.ProductOperatorServiceImpl_e_unable_to_create_keys;
String message = String.format(pattern, version, product.getName());
return new Status(IStatus.ERROR, pluginId, message);
Expand All @@ -150,7 +143,8 @@ public IStatus createProductKeys(ProductVersionDescriptor descriptor) {
String publicKeyPath = storageKeyFolder + File.separator + keyFileName
+ LicensingPaths.EXTENSION_PRODUCT_PUBLIC;
String privateKeyPath = storageKeyFolder + File.separator + keyFileName + EXTENSION_KEY_PRIVATE;
streamCodec.createKeyPair(publicKeyPath, privateKeyPath, identifier, createPassword(productVersion));
codec.get().createKeyPair(Paths.get(publicKeyPath), Paths.get(privateKeyPath), identifier,
createPassword(productVersion));
productVersion.setInstallationToken(publicKeyPath);
productVersion.setSecureToken(privateKeyPath);
eventAdmin.postEvent(OperatorProductEvents.publicCreated(publicKeyPath));
Expand All @@ -159,7 +153,8 @@ public IStatus createProductKeys(ProductVersionDescriptor descriptor) {
String message = String.format(format, publicKeyPath, privateKeyPath);
return new Status(IStatus.OK, pluginId, message);
} catch (Exception e) {
return new Status(IStatus.ERROR, pluginId, ProductsCoreMessages.ProductOperatorServiceImpl_e_export_error, e);
return new Status(IStatus.ERROR, pluginId, ProductsCoreMessages.ProductOperatorServiceImpl_e_export_error,
e);
}
}

Expand All @@ -175,4 +170,8 @@ public Path getBasePath() {
return passagePath;
}

private Optional<StreamCodec> codec(LicensedProduct product) {
return new CodecSupplier(product).get();
}

}

0 comments on commit f6d8948

Please sign in to comment.