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
22 changes: 22 additions & 0 deletions .github/workflows/ci.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
name: CI
on:
workflow_dispatch:
pull_request:

jobs:
build-and-test:
runs-on: ubuntu-latest

steps:
- name: Checkout
uses: actions/checkout@v4

- name: "Set up JDK 17"
uses: actions/setup-java@v4
with:
java-version: '17'
distribution: 'temurin'
cache: maven

- name: "Build with Maven"
run: "mvn -B compile test --file api/pom.xml"
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ public record Translations(String path) {
public record Routers(String path) {
}

public record Parsers(String path, List<String> list) {
public record Parsers(String path) {
}

public record Assets(String path) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ public class ConfigEntry {
// Own identifier config path
private final Path path;

// If the config is a derived config, this path points to derivative (parent) config
// If the config is a derived config, this path points to the derived from (parent) config
private final Path derivedPath;

// Source config name
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ class IndexRepository {
private final RouterService routerService;
private final TranslationsService translationsService;
// The actual index
private final Index index = new Index();
private Index index;

public IndexRepository(ParserService parserService, RouterService routerService,
TranslationsService translationsService) {
Expand All @@ -34,7 +34,7 @@ public IndexRepository(ParserService parserService, RouterService routerService,
@PostConstruct
public void populateIndex() {
logger.info("Parsing the configs, populating ConfigIndex...");
index.update(parserService.populateConfigIndex());
index = parserService.populateConfigIndex();
logger.info("Finished parsing");

logger.info("Resolving derivations...");
Expand Down Expand Up @@ -68,14 +68,13 @@ private void resolveDerivation(ConfigEntry configEntry) {
ParameterArray derivedParameters = new ParameterArray();
ConfigEntry derivedConfig = readConfigIndex(configEntry.getSourceConfig(), configEntry.getDerivedPath());
while (derivedConfig != null) {
derivedParameters.update(derivedConfig.getParameters());
derivedParameters.update(derivedConfig.getParameters()); // would this not mean the parent potentially overwriting the child parameters?
if (!derivedConfig.isDerived()) {
configEntry.setDerivedImplementationType(derivedConfig.getImplementationType());
}
derivedConfig = readConfigIndex(configEntry.getSourceConfig(), derivedConfig.getDerivedPath());
}
configEntry.updateDerivedParameters(derivedParameters);
index.addConfigIndexEntry(configEntry.getSourceConfig(), configEntry.getPath(), configEntry);
}

// Resolve and cache ALL derivations from ConfigIndex
Expand Down
42 changes: 14 additions & 28 deletions api/src/main/java/com/crowfunder/cogmaster/Parsers/Parser.java
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import com.crowfunder.cogmaster.Index.Index;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.core.io.Resource;
import org.w3c.dom.Document;
import org.w3c.dom.Element;
import org.w3c.dom.Node;
Expand All @@ -22,12 +23,11 @@

public class Parser {

// Path to parsed xml config file
private final String xmlFilePath;

Logger logger = LoggerFactory.getLogger(Parser.class);
// Parsed xml config file resource
private final Resource xmlFileResource;
// Config name, should also correspond to root node of parameters in derived entries
private final String configName;

// List of paths leading to parameters to index into ParameterIndex
private final List<Path> indexableParameterPaths;

Expand All @@ -37,25 +37,27 @@ public class Parser {
// Do I care? No idea.
Index index = new Index();

Logger logger = LoggerFactory.getLogger(Parser.class);

public String getXmlFilePath() {
return xmlFilePath;
public Parser(String configName, Resource xmlFileResource, List<Path> indexableParameterPaths) {
this.xmlFileResource = xmlFileResource;
this.indexableParameterPaths = indexableParameterPaths;
this.configName = configName;
}

public List<Path> getIndexableParameterPaths() {
return indexableParameterPaths;
// Temporary constructor until reverse indexing works
public Parser(String configName, Resource xmlFileResource) {
this.xmlFileResource = xmlFileResource;
this.indexableParameterPaths = new ArrayList<>();
this.configName = configName;
}


public Index populateConfigIndex() {

// Restart the index for parsing
index = new Index();

try {
DocumentBuilder builder = DocumentBuilderFactory.newInstance().newDocumentBuilder();
Document doc = builder.parse(Parser.class.getResourceAsStream(xmlFilePath));
Document doc = builder.parse(xmlFileResource.getInputStream());
doc.getDocumentElement().normalize();

// Start reading
Expand Down Expand Up @@ -85,7 +87,6 @@ public Index populateConfigIndex() {
logger.error(e.toString());
throw new RuntimeException(e);
}

return index;
}

Expand Down Expand Up @@ -251,19 +252,4 @@ private ParameterValue parseParameterValue(Node parameterNode) {
}
return parameterValue;
}


public Parser(String configName, String xmlFilePath, List<Path> indexableParameterPaths) {
this.xmlFilePath = xmlFilePath;
this.indexableParameterPaths = indexableParameterPaths;
this.configName = configName;
}

// Temporary constructor until reverse indexing works
public Parser(String configName, String xmlFilePath) {
this.xmlFilePath = xmlFilePath;
this.indexableParameterPaths = new ArrayList<>();
this.configName = configName;
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -2,29 +2,42 @@

import com.crowfunder.cogmaster.CogmasterConfig;
import com.crowfunder.cogmaster.Index.Index;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.core.io.Resource;
import org.springframework.core.io.support.PathMatchingResourcePatternResolver;
import org.springframework.stereotype.Service;

import java.io.IOException;
import java.util.ArrayList;
import java.util.List;

@Service
public class ParserService {

Logger logger = LoggerFactory.getLogger(ParserService.class);
private final List<Parser> parsers;
private final List<String> parserNames;
private final String parseablePath;

public ParserService(CogmasterConfig cogmasterConfig) {

// Initialize existing parsers, probably not the best idea to do it like that but oh well
// Initialize existing parsers, probably not the best idea to do it like that
// but oh well
this.parsers = new ArrayList<>();
this.parserNames = cogmasterConfig.parsers().list();
this.parseablePath = cogmasterConfig.parsers().path();
var parseablePath = cogmasterConfig.parsers().path();

for (String parserName : this.parserNames) {
this.parsers.add(new Parser(parserName, "/" + parseablePath + "/" + parserName + ".xml"));
}
try {
PathMatchingResourcePatternResolver r = new PathMatchingResourcePatternResolver();
var parserResources = r.getResources("classpath*:/" + parseablePath + "/*.xml");

for (Resource resource : parserResources) {
var parserName = resource.getFilename().split("\\.")[0];
this.parsers.add(new Parser(parserName, resource));
}

} catch (IOException e) {
logger.error("Failed to load properties from specified path: /{}/*", parseablePath);
throw new RuntimeException("Failed to load properties", e);
}
}

public Index populateConfigIndex() {
Expand Down
8 changes: 0 additions & 8 deletions api/src/main/resources/application.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,14 +14,6 @@ cogmaster:

parsers:
path: "parseable"
list:
- "item"
- "harness"
- "effect"
- "conversation"
- "attack"
- "actor"
- "accessory"

assets:
path: "assets"
19 changes: 19 additions & 0 deletions api/src/test/resources/application.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
spring:
application:
name: "Cogmaster"

server:
port: 2137

cogmaster:
translations:
path: "properties"

routers:
path: "routers"

parsers:
path: "parseable"

assets:
path: "assets"
16 changes: 16 additions & 0 deletions api/src/test/resources/parseable/actor.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
<?xml version="1.0" encoding="UTF-8"?><java class="com.threerings.export.XMLImporter" version="1.0">
<object class="[Lcom.threerings.tudey.config.ActorConfig;">
<entry>
<name>Block/Barbed Hedgehog</name>
<implementation class="com.threerings.tudey.config.ActorConfig$Derived">
<actor>
<name>Block/Parts/Barbed Hedgehog Base</name>
<arguments>
<key class="java.lang.String">Variant</key>
<value class="java.lang.String">Normal</value>
</arguments>
</actor>
</implementation>
</entry>
</object>
</java>
17 changes: 17 additions & 0 deletions api/src/test/resources/parseable/effect.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
<?xml version="1.0" encoding="UTF-8"?><java class="com.threerings.export.XMLImporter" version="1.0">
<object class="[Lcom.threerings.tudey.config.EffectConfig;">
<entry>
<name>Action</name>
<parameters>
<entry class="com.threerings.config.Parameter$Direct">
<name>Action</name>
<paths>implementation.action.fire_action</paths>
</entry>
</parameters>
<implementation class="com.threerings.tudey.config.EffectConfig$Original">
<action class="com.threerings.projectx.dungeon.config.DungeonActionConfig$FireAction">
</action>
</implementation>
</entry>
</object>
</java>
Loading