Skip to content

Commit

Permalink
1039 make Operator more extensible
Browse files Browse the repository at this point in the history
add listener for license issuing, call when all license files are
successfully persisted
  • Loading branch information
eparovyshnaya committed Feb 22, 2022
1 parent d507766 commit 3909754
Show file tree
Hide file tree
Showing 11 changed files with 249 additions and 5 deletions.
12 changes: 12 additions & 0 deletions bundles/org.eclipse.passage.lic.jetty/plugin.xml
Original file line number Diff line number Diff line change
@@ -1,5 +1,17 @@
<?xml version="1.0" encoding="UTF-8"?>
<?eclipse version="3.4"?>
<!--
Copyright (c) 2022 ArSysOp and others
This program and the accompanying materials are made available under the
terms of the Eclipse Public License 2.0 which is available at
https://www.eclipse.org/legal/epl-2.0/.
SPDX-License-Identifier: EPL-2.0
Contributors:
ArSysOp - initial API and implementation
-->
<plugin>
<extension-point id="commands" name="%extension-point.name" schema="schema/commands.exsd"/>

Expand Down
12 changes: 12 additions & 0 deletions bundles/org.eclipse.passage.lic.jetty/schema/commands.exsd
Original file line number Diff line number Diff line change
@@ -1,4 +1,16 @@
<?xml version='1.0' encoding='UTF-8'?>
<!--
Copyright (c) 2022 ArSysOp and others
This program and the accompanying materials are made available under the
terms of the Eclipse Public License 2.0 which is available at
https://www.eclipse.org/legal/epl-2.0/.
SPDX-License-Identifier: EPL-2.0
Contributors:
ArSysOp - initial API and implementation
-->
<!-- Schema file written by PDE -->
<schema targetNamespace="org.eclipse.passage.lic.jetty" xmlns="http://www.w3.org/2001/XMLSchema">
<annotation>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
Manifest-Version: 1.0
Automatic-Module-Name: org.eclipse.passage.loc.licenses.core
Bundle-ManifestVersion: 2
Bundle-SymbolicName: org.eclipse.passage.loc.licenses.core
Bundle-SymbolicName: org.eclipse.passage.loc.licenses.core;singleton:=true
Bundle-Version: 2.0.102.qualifier
Bundle-Name: %Bundle-Name
Bundle-Vendor: %Bundle-Vendor
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,3 +21,5 @@ available under the terms of the Eclipse Public License 2.0\n\
which is available at https://www.eclipse.org/legal/epl-2.0/\n\
\n\
SPDX-License-Identifier: EPL-2.0\n\
extension-point.name = License Pack persistence lictener
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
###############################################################################
# Copyright (c) 2018, 2020 ArSysOp and others
# Copyright (c) 2018, 2022 ArSysOp and others
#
# This program and the accompanying materials are made available under the
# terms of the Eclipse Public License 2.0 which is available at
Expand All @@ -16,4 +16,5 @@ output.. = bin/
bin.includes = META-INF/,\
.,\
OSGI-INF/,\
about.html
about.html,\
plugin.xml
18 changes: 18 additions & 0 deletions bundles/org.eclipse.passage.loc.licenses.core/plugin.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
<?xml version="1.0" encoding="UTF-8"?>
<?eclipse version="3.4"?>
<!--
Copyright (c) 2022 ArSysOp and others
This program and the accompanying materials are made available under the
terms of the Eclipse Public License 2.0 which is available at
https://www.eclipse.org/legal/epl-2.0/.
SPDX-License-Identifier: EPL-2.0
Contributors:
ArSysOp - initial API and implementation
-->
<plugin>
<extension-point id="issue" name="%extension-point.name" schema="schema/issue.exsd"/>

</plugin>
114 changes: 114 additions & 0 deletions bundles/org.eclipse.passage.loc.licenses.core/schema/issue.exsd
Original file line number Diff line number Diff line change
@@ -0,0 +1,114 @@
<?xml version='1.0' encoding='UTF-8'?>
<!--
Copyright (c) 2022 ArSysOp and others
This program and the accompanying materials are made available under the
terms of the Eclipse Public License 2.0 which is available at
https://www.eclipse.org/legal/epl-2.0/.
SPDX-License-Identifier: EPL-2.0
Contributors:
ArSysOp - initial API and implementation
-->
<!-- Schema file written by PDE -->
<schema targetNamespace="org.eclipse.passage.loc.licenses.core" xmlns="http://www.w3.org/2001/XMLSchema">
<annotation>
<appinfo>
<meta.schema plugin="org.eclipse.passage.loc.licenses.core" id="issue" name="License Pack issue listener"/>
</appinfo>
<documentation>
instanciated and called on a license pack persistence phase
</documentation>
</annotation>

<element name="extension">
<annotation>
<appinfo>
<meta.element />
</appinfo>
</annotation>
<complexType>
<sequence minOccurs="1" maxOccurs="unbounded">
<element ref="listener" minOccurs="1" maxOccurs="unbounded"/>
</sequence>
<attribute name="point" type="string" use="required">
<annotation>
<documentation>

</documentation>
</annotation>
</attribute>
<attribute name="id" type="string">
<annotation>
<documentation>

</documentation>
</annotation>
</attribute>
<attribute name="name" type="string">
<annotation>
<documentation>

</documentation>
<appinfo>
<meta.attribute translatable="true"/>
</appinfo>
</annotation>
</attribute>
</complexType>
</element>

<element name="listener">
<complexType>
<attribute name="class" type="string" use="required">
<annotation>
<documentation>

</documentation>
<appinfo>
<meta.attribute kind="java" basedOn=":org.eclipse.passage.loc.internal.licenses.core.LicensePackPersistenceListener"/>
</appinfo>
</annotation>
</attribute>
</complexType>
</element>

<annotation>
<appinfo>
<meta.section type="since"/>
</appinfo>
<documentation>
[Enter the first release in which this extension point appears.]
</documentation>
</annotation>

<annotation>
<appinfo>
<meta.section type="examples"/>
</appinfo>
<documentation>
[Enter extension point usage example here.]
</documentation>
</annotation>

<annotation>
<appinfo>
<meta.section type="apiinfo"/>
</appinfo>
<documentation>
[Enter API information here.]
</documentation>
</annotation>

<annotation>
<appinfo>
<meta.section type="implementation"/>
</appinfo>
<documentation>
[Enter information about supplied implementation of this extension point.]
</documentation>
</annotation>


</schema>
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
package org.eclipse.passage.loc.internal.licenses.core;

import java.nio.file.Path;
import java.util.ArrayList;
import java.util.Collection;
import java.util.List;

import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import org.eclipse.core.runtime.CoreException;
import org.eclipse.core.runtime.IConfigurationElement;
import org.eclipse.core.runtime.IExtension;
import org.eclipse.core.runtime.Platform;
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.PersonalLicensePack;

final class ContributedLicensePackIssueListener implements LicensePackIssueListener {

private final Logger log = LogManager.getLogger(getClass());
private final List<LicensePackIssueListener> contributed;

ContributedLicensePackIssueListener() {
this.contributed = read();
}

@Override
public void floating(FloatingLicensePack pack, Collection<FloatingLicenseAccess> configs, Path residence) {
contributed.forEach(listener -> listener.floating(pack, configs, residence));

}

@Override
public void personal(PersonalLicensePack license, Path residence) {
contributed.forEach(listener -> listener.personal(license, residence));
}

private List<LicensePackIssueListener> read() {
IExtension[] extensions = Platform.getExtensionRegistry()
.getExtensionPoint("org.eclipse.passage.loc.licenses.core", "issue").getExtensions(); //$NON-NLS-1$//$NON-NLS-2$
List<LicensePackIssueListener> found = new ArrayList<>();
for (IExtension extension : extensions) {
for (IConfigurationElement config : extension.getConfigurationElements()) {
try {
found.add((LicensePackIssueListener) config.createExecutableExtension("class")); //$NON-NLS-1$
} catch (CoreException e) {
log.error("failed to instanciate licence pack issue listener", e); //$NON-NLS-1$
e.printStackTrace();
}
}
}
return found;
}

}
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*******************************************************************************
* Copyright (c) 2020, 2021 ArSysOp
* Copyright (c) 2020, 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
Expand Down Expand Up @@ -107,6 +107,7 @@ private ServiceInvocationResult<IssuedFloatingLicense> persistLicenseFiles(Float
if (!new NoSevereErrors().test(withKey.diagnostic())) {
return new BaseServiceInvocationResult<>(withKey.diagnostic());
}
new ContributedLicensePackIssueListener().floating(pack, configs, residence);
return new BaseServiceInvocationResult<>(new BaseIssuedFloatingLicense(residence, withKey.data().get()));
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*******************************************************************************
* Copyright (c) 2020, 2021 ArSysOp
* Copyright (c) 2020, 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
Expand Down Expand Up @@ -103,6 +103,7 @@ ServiceInvocationResult<IssuedLicense> issue(Supplier<PersonalLicensePack> templ
return new BaseServiceInvocationResult<>(new Trouble(new LicenseIssuingFailed(),
LicensesCoreMessages.LicenseOperatorServiceImpl_export_error, e));
}
new ContributedLicensePackIssueListener().personal(license, path);
return result(license, decrypted, encrypted);
}

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
/*******************************************************************************
* 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.Collection;

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.PersonalLicensePack;

public interface LicensePackIssueListener {

void floating(FloatingLicensePack pack, Collection<FloatingLicenseAccess> configs, Path residence);

void personal(PersonalLicensePack license, Path residence);

}

0 comments on commit 3909754

Please sign in to comment.