Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 1 addition & 12 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -22,16 +22,5 @@ jobs:
key: ${{ runner.os }}-m2-${{ hashFiles('**/pom.xml') }}
restore-keys: ${{ runner.os }}-m2

- name: Set up Python
uses: actions/setup-python@v5
with:
python-version: "3.11.4"
- run: python --version
- run: pipx --version
- run: pipx ensurepath
- run: pipx install poetry==1.8.2
- run: pipx inject poetry poetry-plugin-export==1.7.1
- run: pipx install cyclonedx-bom==4.1.5

- name: Build with Maven and run the tests
run: mvn --batch-mode --update-snapshots verify -Dgpg.skip=true
run: mvn --batch-mode --update-snapshots verify -Dgpg.skip=true
17 changes: 17 additions & 0 deletions plugins/dependency-checker/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,12 @@
<version>4.13.1</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.mockito</groupId>
<artifactId>mockito-core</artifactId>
<version>5.23.0</version>
<scope>test</scope>
</dependency>

<dependency>
<groupId>org.apache.maven.shared</groupId>
Expand Down Expand Up @@ -329,6 +335,17 @@
</execution>
</executions>
</plugin>

<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<version>3.5.6</version>
<configuration>
<systemPropertyVariables>
<maven.home>${maven.home}</maven.home>
</systemPropertyVariables>
</configuration>
</plugin>
</plugins>
</build>
</project>
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
import com.freenow.sauron.model.DataSet;
import com.freenow.sauron.plugins.elasticsearch.DependenciesModel;
import com.freenow.sauron.plugins.elasticsearch.ElasticSearchClient;
import com.freenow.sauron.plugins.generator.DependencyGenerator;
import com.freenow.sauron.plugins.generator.DependencyGeneratorFactory;
import com.freenow.sauron.properties.PluginsConfigurationProperties;
import lombok.extern.slf4j.Slf4j;
Expand Down Expand Up @@ -38,21 +39,22 @@ public DataSet apply(PluginsConfigurationProperties properties, DataSet input)
log.info("Detected project type: {} for repository: {}", projectType, repository);
input.setAdditionalInformation("projectType", projectType.toString());

DependencyGeneratorFactory.newInstance(projectType, properties)
.map(dependencyGenerator ->
{
Path bom = dependencyGenerator.generateCycloneDxBom(repository);
log.info("Generated BOM path: {}", bom);
return bom;
})
.filter(Files::exists)
.ifPresent(bom ->
{
log.info("BOM exists, setting cycloneDxBomPath: {}", bom);
input.setAdditionalInformation("cycloneDxBomPath", bom.toString());
DependenciesModel dependenciesModel = DependenciesModel.from(input, parseCycloneDx(bom));
new ElasticSearchClient(properties).index(dependenciesModel);
});
Optional<DependencyGenerator> dependencyGenerator = DependencyGeneratorFactory.newInstance(projectType, properties);
Optional<Path> bomFile = dependencyGenerator.map(generator -> generator.generateCycloneDxBom(repository));
Path bom = bomFile.filter(Files::exists).orElse(null);

if (bom != null) {
log.info("Generated BOM using generator {}, setting cycloneDxBomPath: {}", dependencyGenerator.get().getClass().getSimpleName(), bom);
input.setAdditionalInformation("cycloneDxBomPath", bom.toString());
DependenciesModel dependenciesModel = DependenciesModel.from(input, parseCycloneDx(bom));
new ElasticSearchClient(properties).index(dependenciesModel);
} else if (bomFile.isPresent()) {
log.warn("DependencyGenerator {} returned BOM path, but didn't actually write the file: {}", dependencyGenerator.get().getClass().getSimpleName(), bomFile);
} else if (dependencyGenerator.isPresent()) {
log.warn("DependencyGenerator {} did not return a BOM path", dependencyGenerator.get().getClass().getSimpleName());
} else {
log.warn("Could not find DependencyGenerator for repository {} with detected type {}", repository, projectType);
}
});

return input;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,13 +50,17 @@ public void index(DependenciesModel dependenciesModel)
RestStatus status = response.status();
if (!status.equals(RestStatus.OK) && !status.equals(RestStatus.CREATED))
{
log.error(String.format("Error [%s] storing document: %s", status, dependenciesModel.toJson()));
log.error("Error [status: {}] storing document: {}", status, dependenciesModel.toJson());
} else {
log.info("Updated dependencies indexed successfully: {}", dependenciesModel.toJson());
}
}
catch (IOException e)
{
log.error(e.getMessage(), e);
log.error("Failure while updating dependencies index: {}", e.getMessage(), e);
}
} else {
log.warn("ElasticSearchClient wasn't configured. Dependencies index isn't getting updated!");
}
}

Expand All @@ -68,4 +72,4 @@ private IndexRequest getDocIndexRequest(DependenciesModel model) throws JsonProc
request.source(model.toJson(), XContentType.JSON);
return request;
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ public Path generateCycloneDxBom(Path repositoryPath)
InvocationRequest request = new DefaultInvocationRequest();
request.setTimeoutInSeconds(Math.toIntExact(Duration.ofMinutes(commandTimeoutMinutes).toSeconds()));
request.setPomFile(pom);
request.setBatchMode(true);
request.setQuiet(!log.isDebugEnabled());
request.setGoals(Collections.singletonList("cyclonedx:makeBom"));

Expand Down
Loading
Loading