-
Notifications
You must be signed in to change notification settings - Fork 28
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'main' into #969-fix-sleep-command-build
- Loading branch information
Showing
9 changed files
with
236 additions
and
6 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1 @@ | ||
-Drevision=2025.01.001-beta-SNAPSHOT | ||
-Drevision=2025.01.002-beta-SNAPSHOT |
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
71 changes: 71 additions & 0 deletions
71
cli/src/main/java/com/devonfw/tools/ide/repo/CustomToolJsonDeserializer.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,71 @@ | ||
package com.devonfw.tools.ide.repo; | ||
|
||
import java.io.IOException; | ||
|
||
import com.fasterxml.jackson.core.JsonParser; | ||
import com.fasterxml.jackson.core.JsonToken; | ||
import com.fasterxml.jackson.databind.DeserializationContext; | ||
import com.fasterxml.jackson.databind.JsonDeserializer; | ||
|
||
/** | ||
* {@link JsonDeserializer} for {@link CustomToolJson}. | ||
*/ | ||
public class CustomToolJsonDeserializer extends JsonDeserializer<CustomToolJson> { | ||
|
||
private static final String INVALID_CUSTOM_TOOL = "Invalid JSON for custom tool!"; | ||
|
||
@Override | ||
public CustomToolJson deserialize(JsonParser p, DeserializationContext context) throws IOException { | ||
|
||
JsonToken token = p.getCurrentToken(); | ||
if (token == JsonToken.START_OBJECT) { | ||
token = p.nextToken(); | ||
String name = null; | ||
String version = null; | ||
boolean osAgnostic = true; | ||
boolean archAgnostic = true; | ||
String url = null; | ||
while (token == JsonToken.FIELD_NAME) { | ||
String property = p.currentName(); | ||
if (property.equals(CustomToolJson.PROPERTY_NAME)) { | ||
token = p.nextToken(); | ||
assert token == JsonToken.VALUE_STRING; | ||
name = p.getValueAsString(); | ||
} else if (property.equals(CustomToolJson.PROPERTY_VERSION)) { | ||
token = p.nextToken(); | ||
assert token == JsonToken.VALUE_STRING; | ||
version = p.getValueAsString(); | ||
} else if (property.equals(CustomToolJson.PROPERTY_OS_AGNOSTIC)) { | ||
token = p.nextToken(); | ||
osAgnostic = parseBoolean(token, CustomToolJson.PROPERTY_OS_AGNOSTIC); | ||
} else if (property.equals(CustomToolJson.PROPERTY_ARCH_AGNOSTIC)) { | ||
token = p.nextToken(); | ||
archAgnostic = parseBoolean(token, CustomToolJson.PROPERTY_ARCH_AGNOSTIC); | ||
} else if (property.equals(CustomToolJson.PROPERTY_URL)) { | ||
token = p.nextToken(); | ||
assert token == JsonToken.VALUE_STRING; | ||
url = p.getValueAsString(); | ||
} else { | ||
// ignore unknown property | ||
// currently cannot log here due to https://github.com/devonfw/IDEasy/issues/404 | ||
} | ||
token = p.nextToken(); | ||
} | ||
if ((name != null) && (version != null)) { | ||
return new CustomToolJson(name, version, osAgnostic, archAgnostic, url); | ||
} | ||
} | ||
throw new IllegalStateException(INVALID_CUSTOM_TOOL); | ||
} | ||
|
||
private boolean parseBoolean(JsonToken token, String name) { | ||
if (token == JsonToken.VALUE_TRUE) { | ||
return true; | ||
} else if (token == JsonToken.VALUE_FALSE) { | ||
return false; | ||
} else { | ||
throw new IllegalStateException(INVALID_CUSTOM_TOOL + " Property " + name + " must have boolean value (true or false)."); | ||
} | ||
} | ||
|
||
} |
37 changes: 37 additions & 0 deletions
37
cli/src/main/java/com/devonfw/tools/ide/repo/CustomToolJsonSerializer.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,37 @@ | ||
package com.devonfw.tools.ide.repo; | ||
|
||
import java.io.IOException; | ||
|
||
import com.fasterxml.jackson.core.JsonGenerator; | ||
import com.fasterxml.jackson.databind.JsonDeserializer; | ||
import com.fasterxml.jackson.databind.JsonSerializer; | ||
import com.fasterxml.jackson.databind.SerializerProvider; | ||
|
||
/** | ||
* {@link JsonDeserializer} for {@link CustomToolJson}. | ||
*/ | ||
public class CustomToolJsonSerializer extends JsonSerializer<CustomToolJson> { | ||
|
||
@Override | ||
public void serialize(CustomToolJson customToolJson, JsonGenerator jgen, SerializerProvider serializerProvider) throws IOException { | ||
if (customToolJson == null) { | ||
return; | ||
} | ||
jgen.writeStartObject(); | ||
jgen.writeFieldName(CustomToolJson.PROPERTY_NAME); | ||
jgen.writeString(customToolJson.name()); | ||
jgen.writeFieldName(CustomToolJson.PROPERTY_VERSION); | ||
jgen.writeString(customToolJson.version()); | ||
jgen.writeFieldName(CustomToolJson.PROPERTY_OS_AGNOSTIC); | ||
jgen.writeBoolean(customToolJson.osAgnostic()); | ||
jgen.writeFieldName(CustomToolJson.PROPERTY_ARCH_AGNOSTIC); | ||
jgen.writeBoolean(customToolJson.archAgnostic()); | ||
String url = customToolJson.url(); | ||
if ((url != null) && !url.isBlank()) { | ||
jgen.writeFieldName(CustomToolJson.PROPERTY_URL); | ||
jgen.writeString(url); | ||
} | ||
jgen.writeEndObject(); | ||
} | ||
|
||
} |
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
56 changes: 56 additions & 0 deletions
56
cli/src/main/java/com/devonfw/tools/ide/repo/CustomToolsJsonDeserializer.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,56 @@ | ||
package com.devonfw.tools.ide.repo; | ||
|
||
import java.io.IOException; | ||
import java.util.ArrayList; | ||
import java.util.List; | ||
|
||
import com.fasterxml.jackson.core.JsonParser; | ||
import com.fasterxml.jackson.core.JsonToken; | ||
import com.fasterxml.jackson.databind.DeserializationContext; | ||
import com.fasterxml.jackson.databind.JsonDeserializer; | ||
|
||
/** | ||
* {@link JsonDeserializer} for {@link CustomToolsJson}. | ||
*/ | ||
public class CustomToolsJsonDeserializer extends JsonDeserializer<CustomToolsJson> { | ||
|
||
private static final String INVALID_CUSTOM_TOOLS = "Invalid JSON for custom tools!"; | ||
|
||
@Override | ||
public CustomToolsJson deserialize(JsonParser p, DeserializationContext context) throws IOException { | ||
|
||
JsonToken token = p.getCurrentToken(); | ||
if (token == JsonToken.START_OBJECT) { | ||
token = p.nextToken(); | ||
String url = null; | ||
List<CustomToolJson> tools = new ArrayList<>(); | ||
while (token == JsonToken.FIELD_NAME) { | ||
String property = p.currentName(); | ||
if (property.equals(CustomToolsJson.PROPERTY_URL)) { | ||
token = p.nextToken(); | ||
assert token == JsonToken.VALUE_STRING; | ||
url = p.getValueAsString(); | ||
} else if (property.equals(CustomToolsJson.PROPERTY_TOOLS)) { | ||
token = p.nextToken(); | ||
if (token == JsonToken.START_ARRAY) { | ||
token = p.nextToken(); | ||
while (token != JsonToken.END_ARRAY) { | ||
CustomToolJson customToolJson = p.readValueAs(CustomToolJson.class); | ||
tools.add(customToolJson); | ||
token = p.nextToken(); | ||
} | ||
} | ||
} else { | ||
// ignore unknown property | ||
// currently cannot log here due to https://github.com/devonfw/IDEasy/issues/404 | ||
} | ||
token = p.nextToken(); | ||
} | ||
if ((url != null) && !tools.isEmpty()) { | ||
return new CustomToolsJson(url, tools); | ||
} | ||
} | ||
throw new IllegalStateException(INVALID_CUSTOM_TOOLS); | ||
} | ||
|
||
} |
34 changes: 34 additions & 0 deletions
34
cli/src/main/java/com/devonfw/tools/ide/repo/CustomToolsJsonSerializer.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,34 @@ | ||
package com.devonfw.tools.ide.repo; | ||
|
||
import java.io.IOException; | ||
import java.util.List; | ||
|
||
import com.fasterxml.jackson.core.JsonGenerator; | ||
import com.fasterxml.jackson.databind.JsonDeserializer; | ||
import com.fasterxml.jackson.databind.JsonSerializer; | ||
import com.fasterxml.jackson.databind.SerializerProvider; | ||
|
||
/** | ||
* {@link JsonDeserializer} for {@link CustomToolsJson}. | ||
*/ | ||
public class CustomToolsJsonSerializer extends JsonSerializer<CustomToolsJson> { | ||
|
||
@Override | ||
public void serialize(CustomToolsJson customToolsJson, JsonGenerator jgen, SerializerProvider serializerProvider) throws IOException { | ||
if (customToolsJson == null) { | ||
return; | ||
} | ||
jgen.writeStartObject(); | ||
jgen.writeFieldName(CustomToolsJson.PROPERTY_URL); | ||
jgen.writeString(customToolsJson.url()); | ||
jgen.writeFieldName(CustomToolsJson.PROPERTY_TOOLS); | ||
jgen.writeStartArray(); | ||
List<CustomToolJson> tools = customToolsJson.tools(); | ||
for (CustomToolJson tool : tools) { | ||
jgen.writeObject(tool); | ||
} | ||
jgen.writeEndArray(); | ||
jgen.writeEndObject(); | ||
} | ||
|
||
} |