Skip to content

Commit

Permalink
devonfw#103: fixed write json bug, and more
Browse files Browse the repository at this point in the history
 - changed pom.xml
 - getCpeEdition now has argument, since there is only a single UrlUpdater for multiple editions of a tool
 - some cleanup
  • Loading branch information
MattesMrzik committed Dec 22, 2023
1 parent fe9109f commit b19b877
Show file tree
Hide file tree
Showing 6 changed files with 13 additions and 31 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -10,13 +10,13 @@
import java.util.Objects;
import java.util.Set;

import com.devonfw.tools.ide.context.IdeContext;
import com.devonfw.tools.ide.url.model.file.json.UrlSecurityWarning;
import com.devonfw.tools.ide.url.model.file.json.UrlSecurityWarningsJson;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import com.devonfw.tools.ide.context.IdeContext;
import com.devonfw.tools.ide.json.mapping.JsonMapping;
import com.devonfw.tools.ide.url.model.file.json.UrlSecurityWarning;
import com.devonfw.tools.ide.url.model.file.json.UrlSecurityWarningsJson;
import com.devonfw.tools.ide.url.model.folder.UrlEdition;
import com.devonfw.tools.ide.version.VersionIdentifier;
import com.devonfw.tools.ide.version.VersionRange;
Expand Down Expand Up @@ -177,7 +177,7 @@ protected void doSave() {

String jsonString;
try {
jsonString = mapper.writeValueAsString(this.urlSecurityWarningsJson.getWarnings());
jsonString = mapper.writeValueAsString(this.urlSecurityWarningsJson);
} catch (JsonProcessingException e) {
throw new RuntimeException(e);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -114,9 +114,10 @@ public String getCpeProduct() {
}

/**
* @return the edition of the tool as specified in the CPE (Common Platform Enumeration)
* @param urlEdition the {@link UrlEdition} to get the CPE (Common Platform Enumeration) edition for.
* @return the edition as specified in the CPE.
*/
public String getCpeEdition() {
public String getCpeEdition(String urlEdition) {

return null;
}
Expand Down
2 changes: 1 addition & 1 deletion cli/src/main/java/com/devonfw/tools/ide/util/MapUtil.java
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
import java.util.Map;

/**
* Utility class for operations on maps.
* Utility class for operations with maps.
*/
public class MapUtil {

Expand Down
16 changes: 1 addition & 15 deletions security/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,7 @@
<artifactId>security</artifactId>

<properties>
<maven.compiler.source>17</maven.compiler.source>
<maven.compiler.target>17</maven.compiler.target>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<java.version>17</java.version>
</properties>
<dependencies>
<!-- Other configurations and properties -->
Expand All @@ -31,17 +29,5 @@
<scope>compile</scope>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<configuration>
<source>9</source>
<target>9</target>
</configuration>
</plugin>
</plugins>
</build>

</project>
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,6 @@
import java.util.Set;
import java.util.stream.Collectors;

import com.devonfw.tools.ide.url.model.folder.UrlVersion;
import com.devonfw.tools.ide.util.MapUtil;
import com.devonfw.tools.ide.version.VersionIdentifier;
import org.owasp.dependencycheck.Engine;
import org.owasp.dependencycheck.analyzer.AbstractAnalyzer;
import org.owasp.dependencycheck.analyzer.AnalysisPhase;
Expand Down Expand Up @@ -54,8 +51,11 @@
import com.devonfw.tools.ide.context.IdeContextConsole;
import com.devonfw.tools.ide.log.IdeLogLevel;
import com.devonfw.tools.ide.url.model.file.UrlSecurityJsonFile;
import com.devonfw.tools.ide.url.model.folder.UrlVersion;
import com.devonfw.tools.ide.url.updater.AbstractUrlUpdater;
import com.devonfw.tools.ide.url.updater.UpdateManager;
import com.devonfw.tools.ide.util.MapUtil;
import com.devonfw.tools.ide.version.VersionIdentifier;
import com.devonfw.tools.ide.version.VersionRange;

// TODO Doesn't yet work with versions defined like this /<tool>/<edition>/latest
Expand Down Expand Up @@ -123,9 +123,6 @@ private static void run() {
String tool = parent.getParent().getParent().getFileName().toString();
String edition = parent.getParent().getFileName().toString();
AbstractUrlUpdater urlUpdater = updateManager.getUrlUpdater(tool);

System.out.println(tool + ", " + edition);

UrlSecurityJsonFile securityFile = context.getUrls().getEdition(tool, edition).getSecurityJsonFile();
boolean newlyAdded = foundToolsAndEditions.add(new Pair<>(tool, edition));
if (newlyAdded) { // to assure that the file is cleared only once per tool and edition
Expand Down Expand Up @@ -272,10 +269,8 @@ private static String getUrlVersion(String cpeVersion, AbstractUrlUpdater urlUpd
if (cpeVersion != null) {
if (cpeToUrlVersion.containsKey(cpeVersion)) {
urlVersion = cpeToUrlVersion.get(cpeVersion);
System.out.println("tool mapped using map cpe " + cpeVersion + " -> url " + urlVersion);
} else {
urlVersion = urlUpdater.mapCpeVersionToUrlVersion(cpeVersion);
System.out.println("tool mapped using mapCpeVersionToUrlVersion cpe " + cpeVersion + " -> url " + urlVersion);

}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ protected void analyzeDependency(Dependency dependency, Engine engine) {
// adding vendor evidence
String cpeVendor = urlUpdater.getCpeVendor();
String cpeProduct = urlUpdater.getCpeProduct();
String cpeEdition = urlUpdater.getCpeEdition();
String cpeEdition = urlUpdater.getCpeEdition(edition);
String cpeVersion = urlUpdater.mapUrlVersionToCpeVersion(parent.getFileName().toString());

if (cpeVendor == null || cpeProduct == null) {
Expand Down

0 comments on commit b19b877

Please sign in to comment.