Skip to content

Commit

Permalink
Support suppressing to apply curations (#235)
Browse files Browse the repository at this point in the history
* Generate Curation Template without applied curations

* update test and master-solicitor.asciidoc

* adapt javadoc

* update after Review

* update javadoc

* update javadoc

* adapt javadoc in FilteredScancodeComponentInfoProvider.java

* Documentation improvements, added a unit test for SingleFileCurationProvider

* Fixed typo in Asciidoc

---------

Co-authored-by: ohecker <[email protected]>
  • Loading branch information
mahmoudAlkam and ohecker authored Mar 5, 2024
1 parent 1b2368d commit ccc6fc1
Show file tree
Hide file tree
Showing 10 changed files with 101 additions and 16 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,8 @@ public void add(Statistics statistics) {
* Set the curationDataSelector.
*
* @param curationDataSelector the curationDataSelector to chose when getting curation data. An empty string will be
* stored as <code>null</code> null which results in the default origin being taken.
* stored as <code>null</code> null which results in the default origin being taken. Use "none" to indicate no
* curation to be applied.
*/
@Value("${solicitor.curationDataSelector}")
public void setCurationDataSelector(String curationDataSelector) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,8 @@ public ComponentInfoCuratorImpl(CurationProvider curationProvider,
*
* @param componentInfo the componentInfo to curate
* @param curationDataSelector identifies which source should be used for the curation data. <code>null</code>
* indicates that the default should be used.
* indicates that the default should be used. The special value "none" indicates that no curations will be
* applied.
* @return the curated component info
* @throws ComponentInfoAdapterException if the curation could not be read
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,8 +50,8 @@ public CuratingComponentInfoAdapter(FilteredComponentInfoProvider filteredCompon
* data as a {@link ComponentInfo} object.
*
* @param packageUrl The identifier of the package for which information is requested
* @param curationDataSelector identifies which source should be used for the curation data. <code>null</code>
* indicates that the default should be used.
* @param curationDataSelector Identifies which source should be used for the curation data. <code>null</code>
* indicates that the default should be used. Use "none" to indicate that no curation should be applied.
* @return the data derived from the scancode results after applying any defined curation.
* @throws ComponentInfoAdapterException if there was an exception when reading the data. In case that there is no
* data available no exception will be thrown. Instead <code>null</code> will be return in such a case.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,13 @@ public interface CurationProvider {
*
* @param packageUrl identifies the package
* @param curationDataSelector identifies which source should be used for the curation data. <code>null</code>
* indicates that the default should be used.
* @return the curation data if it exists or <code>null</code> if no curation exist for the package.
* indicates that the default should be used. The special value "none" indicates that no curations should be
* returned.
* @return the curation data if it exists. <code>null</code> if no curation exist for the package or the
* curationDataSelector was given as "none".
* @throws ComponentInfoAdapterException if something unexpected happens
* @throws ComponentInfoAdapterNonExistingCurationDataSelectorException if the specified curationDataSelector could not be
* resolved
* @throws ComponentInfoAdapterNonExistingCurationDataSelectorException if the specified curationDataSelector could
* not be resolved
*/
ComponentInfoCuration findCurations(String packageUrl, String curationDataSelector)
throws ComponentInfoAdapterException, ComponentInfoAdapterNonExistingCurationDataSelectorException;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -56,14 +56,20 @@ public SingleFileCurationProvider(AllKindsPackageURLHandler packageURLHandler) {
* Return the curation data for a given package.
*
* @param packageUrl identifies the package
* @param curationDataSelector identifies which source should be used for the curation data. This parameter is ignored
* by this implementation.
* @param curationDataSelector identifies which source should be used for the curation data. The value "none"
* indicates that no curations should be returned.
* @return the curation data if it exists. <code>null</code> if no curation exist for the package or the
* curationDataSelector was given as "none".
* @throws ComponentInfoAdapterException if something unexpected happens
*/
@Override
public ComponentInfoCuration findCurations(String packageUrl, String curationDataSelector)
throws ComponentInfoAdapterException {

// Return null if curationDataSelector is "none"
if ("none".equalsIgnoreCase(curationDataSelector)) {
return null;
}
ComponentInfoCuration foundCuration = null;

String packagePathPart = this.packageURLHandler.pathFor(packageUrl);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -94,10 +94,10 @@ public void setMinLicensefileNumberOfLines(int minLicensefileNumberOfLines) {
*
* @param packageUrl The package url of the package
* @param curationDataSelector identifies which source should be used for the curation data. <code>null</code>
* indicates that the default should be used.
* indicates that the default should be used. "none" indicates that no curations should be applied.
* @return the read scancode information
* @throws ComponentInfoAdapterException if there was an exception when reading the data. In case that there is no
* data available no exception will be thrown. Instead <code>null</code> will be return in such a case.
* data available no exception will be thrown. Instead <code>null</code> will be returned in such a case.
*/
@Override
public ComponentInfo getComponentInfo(String packageUrl, String curationDataSelector)
Expand Down Expand Up @@ -136,10 +136,14 @@ private void addSupplementedData(ScancodeRawComponentInfo rawScancodeData,
}

/**
* @param packageUrl
* @param rawScancodeData
* @return
* @throws ComponentInfoAdapterException
* Parses and maps scancode JSON to create ScancodeComponentInfo.
*
* @param packageUrl package URL of the package
* @param rawScancodeData raw scancode data
* @param curationDataSelector identifies which source should be used for the curation data. If the value of
* curationdataselector equals "none," no curations will be applied.
* @return the ScancodeComponentInfo
* @throws ComponentInfoAdapterException if there was an issue during parsing
*/
private ScancodeComponentInfo parseAndMapScancodeJson(String packageUrl, ScancodeRawComponentInfo rawScancodeData,
String curationDataSelector) throws ComponentInfoAdapterException {
Expand Down
1 change: 1 addition & 0 deletions core/src/main/resources/application.properties
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,7 @@ solicitor.scancode.issuelistpatterns=.*unknown.*

# The curationDataSelector value to use when accessing curation data.
# You can change its value to select a specific curation data source (if the implementation supports this).
# Set it to "none" to skip applying curations (no curations will be applied).
# Leave it empty to use the default curation data source.
solicitor.curationDataSelector=

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
package com.devonfw.tools.solicitor.componentinfo.curating;

import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertNull;

import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import org.mockito.Mockito;

import com.devonfw.tools.solicitor.common.packageurl.AllKindsPackageURLHandler;
import com.devonfw.tools.solicitor.componentinfo.ComponentInfoAdapterException;
import com.devonfw.tools.solicitor.componentinfo.curation.SingleFileCurationProvider;
import com.devonfw.tools.solicitor.componentinfo.curation.model.ComponentInfoCuration;

/**
* Test for {@link SingleFileCurationProvider}.
*
*/
class SingleFileCurationProviderTest {

private SingleFileCurationProvider objectUnderTest;

@BeforeEach
public void setup() {

AllKindsPackageURLHandler packageUrlHandler = Mockito.mock(AllKindsPackageURLHandler.class);
Mockito.when(packageUrlHandler.pathFor("pkg:maven/somenamespace/[email protected]"))
.thenReturn("pkg/maven/somenamespace/somecomponent/2.3.4");
Mockito.when(packageUrlHandler.pathFor("pkg:maven/somenamespace/[email protected]"))
.thenReturn("pkg/maven/somenamespace/somecomponent/2.3.5");

this.objectUnderTest = new SingleFileCurationProvider(packageUrlHandler);
this.objectUnderTest.setCurationsFileName("src/test/resources/curations/array_of_curations.yaml");
}

/**
* Test method for
* {@link com.devonfw.tools.solicitor.componentinfo.curation.SingleFileCurationProvider#findCurations(java.lang.String, java.lang.String)}.
*
* @throws ComponentInfoAdapterException
*/
@Test
void testFindCurationsWithSelectorNull() throws ComponentInfoAdapterException {

ComponentInfoCuration result;

result = this.objectUnderTest.findCurations("pkg:maven/somenamespace/[email protected]", null);
assertEquals("https://scancode-licensedb.aboutcode.org/apache-2.0.LICENSE", result.getLicenses().get(0).getUrl());
result = this.objectUnderTest.findCurations("pkg:maven/somenamespace/[email protected]", null);
assertEquals("https://scancode-licensedb.aboutcode.org/bsd-simplified.LICENSE",
result.getLicenses().get(0).getUrl());
}

/**
* Test method for
* {@link com.devonfw.tools.solicitor.componentinfo.curation.SingleFileCurationProvider#findCurations(java.lang.String, java.lang.String)}.
*
* @throws ComponentInfoAdapterException
*/
@Test
void testFindCurationsWithSelectorNone() throws ComponentInfoAdapterException {

ComponentInfoCuration result;

result = this.objectUnderTest.findCurations("pkg:maven/somenamespace/[email protected]", "none");
assertNull(result);
}
}
1 change: 1 addition & 0 deletions documentation/files/application.properties
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,7 @@ solicitor.scancode.issuelistpatterns=.*unknown.*

# The curationDataSelector value to use when accessing curation data.
# You can change its value to select a specific curation data source (if the implementation supports this).
# Set it to "none" to skip applying curations (no curations will be applied).
# Leave it empty to use the default curation data source.
solicitor.curationDataSelector=

Expand Down
1 change: 1 addition & 0 deletions documentation/master-solicitor.asciidoc
Original file line number Diff line number Diff line change
Expand Up @@ -1670,6 +1670,7 @@ Spring beans implementing this interface will be called at certain points in the
Changes in 1.20.0::
* https://github.com/devonfw/solicitor/issues/232: Set a standard for ordering LicenseNameMapping rules. Rules with an 'or-later' suffix are put before '-only' rules.
* https://github.com/devonfw/solicitor/issues/234: Correct handling of new data model fields in ModelImporterExporter `dataStatus`,`traceabilityNotes` etc.
* https://github.com/devonfw/solicitor/pull/235: Improvements in Curation Data Handling. When the curationDataSelector parameter is set to "none," no curations will be applied.

Changes in 1.19.0::
* https://github.com/devonfw/solicitor/issues/227: Fixed a bug where the `dataStatus` field in the aggregated OSS-Inventory was not filled.
Expand Down

0 comments on commit ccc6fc1

Please sign in to comment.