-
Notifications
You must be signed in to change notification settings - Fork 8
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[#1482] From-The-Box Support for optional license storage
Signed-off-by: eparovyshnaia <[email protected]>
- Loading branch information
eparovyshnaia
committed
Jan 28, 2025
1 parent
7d40238
commit baea7a1
Showing
14 changed files
with
475 additions
and
186 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
114 changes: 114 additions & 0 deletions
114
...sage.lic.base/src/org/eclipse/passage/lic/base/conditions/mining/BaseLocalConditions.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,114 @@ | ||
/******************************************************************************* | ||
* Copyright (c) 2025 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.base.conditions.mining; | ||
|
||
import java.nio.file.Path; | ||
import java.util.Collection; | ||
import java.util.Collections; | ||
import java.util.Objects; | ||
import java.util.function.Supplier; | ||
|
||
import org.eclipse.passage.lic.api.LicensedProduct; | ||
import org.eclipse.passage.lic.api.LicensingException; | ||
import org.eclipse.passage.lic.api.ServiceInvocationResult; | ||
import org.eclipse.passage.lic.api.conditions.Condition; | ||
import org.eclipse.passage.lic.api.conditions.ConditionMiningTarget; | ||
import org.eclipse.passage.lic.api.conditions.ConditionPack; | ||
import org.eclipse.passage.lic.api.conditions.mining.MinedConditions; | ||
import org.eclipse.passage.lic.api.conditions.mining.MiningEquipment; | ||
import org.eclipse.passage.lic.api.diagnostic.Trouble; | ||
import org.eclipse.passage.lic.base.BaseServiceInvocationResult; | ||
import org.eclipse.passage.lic.base.diagnostic.BaseDiagnostic; | ||
import org.eclipse.passage.lic.base.diagnostic.code.NoLicenses; | ||
import org.eclipse.passage.lic.base.diagnostic.code.ServiceFailedOnInfrastructureDenial; | ||
import org.eclipse.passage.lic.base.io.PassageFileExtension; | ||
import org.eclipse.passage.lic.internal.base.i18n.ConditionMiningMessages; | ||
|
||
/** | ||
* <p> | ||
* Scans the configured part of the local file system for encrypted license | ||
* files, reads them and retrieves all the licensing {@linkplain Condition}s | ||
* they declare. | ||
* </p> | ||
* <p> | ||
* Bearable warning leased in case of no license file is found. | ||
* </p> | ||
* <p> | ||
* Severe (infrastructure denial) error leased in case of any mining error. | ||
* </p> | ||
* | ||
* @since 4.1 | ||
*/ | ||
abstract class BaseLocalConditions implements MinedConditions { | ||
|
||
private final ConditionMiningTarget id; | ||
private final MiningEquipment equipment; | ||
protected final PassageFileExtension scope; | ||
|
||
protected BaseLocalConditions(ConditionMiningTarget id, MiningEquipment equipment, PassageFileExtension scope) { | ||
String cls = getClass().getSimpleName(); | ||
this.id = Objects.requireNonNull(id, cls + "::id"); //$NON-NLS-1$ | ||
this.equipment = Objects.requireNonNull(equipment, cls + "::equipment"); //$NON-NLS-1$ | ||
this.scope = Objects.requireNonNull(scope, cls + "::scope"); //$NON-NLS-1$ | ||
} | ||
|
||
protected BaseLocalConditions(ConditionMiningTarget id, MiningEquipment equipment) { | ||
this(id, equipment, new PassageFileExtension.LicenseEncrypted()); | ||
} | ||
|
||
@Override | ||
public final ConditionMiningTarget id() { | ||
return id; | ||
} | ||
|
||
@Override | ||
public final ServiceInvocationResult<Collection<ConditionPack>> all(LicensedProduct product) { | ||
try { | ||
Collection<Path> licenses = licenses(product); | ||
if (licenses.isEmpty()) { | ||
return noLicenses(product); | ||
} | ||
return equipment.tool(product, id).mine(licenses); | ||
} catch (LicensingException e) { | ||
return scanFailed(e); | ||
} | ||
} | ||
|
||
protected abstract Collection<Path> licenses(LicensedProduct product) throws LicensingException; | ||
|
||
protected abstract Supplier<Path> base(LicensedProduct product); | ||
|
||
private ServiceInvocationResult<Collection<ConditionPack>> noLicenses(LicensedProduct product) { | ||
return new BaseServiceInvocationResult<Collection<ConditionPack>>(// | ||
new BaseDiagnostic(// | ||
Collections.emptyList(), // | ||
Collections.singletonList(// | ||
new Trouble(// | ||
new NoLicenses(), // | ||
String.format(// | ||
ConditionMiningMessages.getString("BaseLocalConditions.no_licenses"), //$NON-NLS-1$ | ||
base(product).get().toAbsolutePath())))// | ||
), // | ||
Collections.emptyList()// | ||
); | ||
} | ||
|
||
private BaseServiceInvocationResult<Collection<ConditionPack>> scanFailed(LicensingException e) { | ||
return new BaseServiceInvocationResult<Collection<ConditionPack>>( // | ||
new Trouble(// | ||
new ServiceFailedOnInfrastructureDenial(), // | ||
ConditionMiningMessages.getString("BaseLocalConditions.failed"), //$NON-NLS-1$ | ||
e)); | ||
} | ||
|
||
} |
43 changes: 43 additions & 0 deletions
43
...e.lic.base/src/org/eclipse/passage/lic/base/conditions/mining/LenientLocalConditions.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
/******************************************************************************* | ||
* Copyright (c) 2025 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.base.conditions.mining; | ||
|
||
import java.nio.file.Path; | ||
import java.util.Collection; | ||
|
||
import org.eclipse.passage.lic.api.LicensedProduct; | ||
import org.eclipse.passage.lic.api.LicensingException; | ||
import org.eclipse.passage.lic.api.conditions.ConditionMiningTarget; | ||
import org.eclipse.passage.lic.api.conditions.mining.MiningEquipment; | ||
import org.eclipse.passage.lic.base.io.LenientFileCollection; | ||
import org.eclipse.passage.lic.base.io.PassageFileExtension; | ||
|
||
/** | ||
* @since 4.1 | ||
*/ | ||
public abstract class LenientLocalConditions extends BaseLocalConditions { | ||
|
||
protected LenientLocalConditions(ConditionMiningTarget id, MiningEquipment equipment, PassageFileExtension scope) { | ||
super(id, equipment, scope); | ||
} | ||
|
||
protected LenientLocalConditions(ConditionMiningTarget id, MiningEquipment equipment) { | ||
this(id, equipment, new PassageFileExtension.LicenseEncrypted()); | ||
} | ||
|
||
@Override | ||
protected Collection<Path> licenses(LicensedProduct product) throws LicensingException { | ||
return new LenientFileCollection(base(product), scope).get(); | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
30 changes: 30 additions & 0 deletions
30
bundles/org.eclipse.passage.lic.base/src/org/eclipse/passage/lic/base/io/CollectedFiles.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
/******************************************************************************* | ||
* Copyright (c) 2025 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.base.io; | ||
|
||
import java.nio.file.Path; | ||
import java.util.Collection; | ||
|
||
import org.eclipse.passage.lic.api.LicensingException; | ||
|
||
/** | ||
* Collects regular files of the given {@code extension} starting from the given | ||
* {@code base} path recursively. No particular order is guaranteed. | ||
* | ||
* @since 4.1 | ||
*/ | ||
public interface CollectedFiles { | ||
|
||
Collection<Path> get() throws LicensingException; | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.