-
Notifications
You must be signed in to change notification settings - Fork 25
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: Load service dynamically based on configuration property
Signed-off-by: Oleg Kopysov <[email protected]>
- Loading branch information
Showing
9 changed files
with
138 additions
and
75 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
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
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,35 @@ | ||
/** | ||
* Copyright (c) 2024, Samsung Electronics Co., Ltd. All rights reserved. | ||
* | ||
* Use of this source code is governed by a MIT license that can be | ||
* found in the LICENSE file. | ||
*/ | ||
package com.lpvs.service.scan; | ||
|
||
import com.lpvs.entity.LPVSFile; | ||
import com.lpvs.entity.LPVSQueue; | ||
|
||
import java.util.List; | ||
|
||
/** | ||
* Interface representing a service for scanning files and checking licenses. | ||
*/ | ||
public interface LPVSScanService { | ||
|
||
/** | ||
* Runs a scan on the specified path using the provided webhook configuration. | ||
* | ||
* @param webhookConfig The webhook configuration to use for the scan. | ||
* @param path The path to the file or directory to scan. | ||
* @throws Exception if an error occurs during the scan process. | ||
*/ | ||
void runScan(LPVSQueue webhookConfig, String path) throws Exception; | ||
|
||
/** | ||
* Checks licenses for files using the provided webhook configuration. | ||
* | ||
* @param webhookConfig The webhook configuration to use for checking licenses. | ||
* @return A list of LPVSFile objects representing files with detected licenses. | ||
*/ | ||
List<LPVSFile> checkLicenses(LPVSQueue webhookConfig); | ||
} |
50 changes: 50 additions & 0 deletions
50
src/main/java/com/lpvs/service/scan/LPVSScanServiceFactory.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,50 @@ | ||
/** | ||
* Copyright (c) 2024, Samsung Electronics Co., Ltd. All rights reserved. | ||
* | ||
* Use of this source code is governed by a MIT license that can be | ||
* found in the LICENSE file. | ||
*/ | ||
package com.lpvs.service.scan; | ||
|
||
import java.lang.reflect.Constructor; | ||
|
||
/** | ||
* Factory class for creating instances of {@link LPVSScanService}. | ||
*/ | ||
public class LPVSScanServiceFactory { | ||
|
||
/** | ||
* Creates a scan service based on the specified scanner type and configuration. | ||
* | ||
* @param scannerType The type of scanner to create. | ||
* @param isInternal Flag indicating whether the scanner is internal or not. | ||
* @return An instance of {@link LPVSScanService} corresponding to the specified scanner type. | ||
* @throws IllegalArgumentException if the specified scanner type is not supported or if an error occurs during | ||
* the creation process. | ||
*/ | ||
public LPVSScanService createScanService(String scannerType, boolean isInternal) { | ||
try { | ||
Class<?> serviceClass = Class.forName(getServiceClassName(scannerType, isInternal)); | ||
Constructor<?> constructor = serviceClass.getDeclaredConstructor(); | ||
return (LPVSScanService) constructor.newInstance(); | ||
} catch (Exception e) { | ||
throw new IllegalArgumentException("Error creating scan service for type: " + scannerType, e); | ||
} | ||
} | ||
|
||
/** | ||
* Gets the fully qualified class name of the scan service based on the specified scanner type and configuration. | ||
* | ||
* @param scannerType The type of scanner. | ||
* @param isInternal Flag indicating whether the scanner is internal or not. | ||
* @return The fully qualified class name of the scan service. | ||
* @throws IllegalArgumentException if the specified scanner type is null or empty string. | ||
*/ | ||
private String getServiceClassName(String scannerType, boolean isInternal) { | ||
if (scannerType != null && !scannerType.isEmpty()) { | ||
return "com.lpvs." + (isInternal ? "internal." : "") + "service.scan.scanner.LPVS" + scannerType.substring(0, 1).toUpperCase() + scannerType.substring(1) + "DetectService"; | ||
} else { | ||
throw new IllegalArgumentException("Scanner type cannot be null or empty."); | ||
} | ||
} | ||
} |
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
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.