Skip to content
This repository was archived by the owner on Oct 17, 2024. It is now read-only.
Open
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
18 changes: 16 additions & 2 deletions core/src/main/java/nl/eernie/as/ASConfigCreator.java
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,12 @@
import java.util.Map;
import java.util.Set;

import javax.xml.XMLConstants;
import javax.xml.bind.JAXBContext;
import javax.xml.bind.JAXBException;
import javax.xml.bind.Unmarshaller;
import javax.xml.validation.Schema;
import javax.xml.validation.SchemaFactory;

import nl.eernie.as.application_server.ApplicationServer;
import nl.eernie.as.aschangelog.ApplicationServerChangeLog;
Expand All @@ -23,9 +26,12 @@

import org.apache.commons.io.FilenameUtils;
import org.reflections.Reflections;
import org.xml.sax.SAXException;

public class ASConfigCreator
{
private static final String APPLICATION_SERVER_CONFIG_XSD = "ApplicationServerConfig-1.0.xsd";

private Configuration configuration;
private Map<ApplicationServer, Set<ConfigurationParser>> configurationParsers = new HashMap<>();
private boolean fromTagFound;
Expand Down Expand Up @@ -57,7 +63,7 @@ private void parseFile(String changeLogFilePath)
ApplicationServerChangeLog applicationServerChangeLog = createApplicationServerChangeLog(changeLogFilePath);
for (Include include : applicationServerChangeLog.getInclude())
{
if (include.getContext() == null || (include.getContext() != null && configurationHasContext(include.getContext())))
if (include.getContext() == null || include.getContext() != null && configurationHasContext(include.getContext()))
{
String path;
if (include.isRelativeToCurrentFile())
Expand Down Expand Up @@ -148,14 +154,22 @@ private ApplicationServerChangeLog createApplicationServerChangeLog(String chang

try
{
SchemaFactory sf = SchemaFactory.newInstance(XMLConstants.W3C_XML_SCHEMA_NS_URI);
Schema schema = sf.newSchema(ASConfigCreator.class.getResource("/" + APPLICATION_SERVER_CONFIG_XSD));

JAXBContext context = JAXBContext.newInstance(ApplicationServerChangeLog.class);
Unmarshaller unmarshaller = context.createUnmarshaller();
unmarshaller.setSchema(schema);
return (ApplicationServerChangeLog) unmarshaller.unmarshal(file);
}
catch (JAXBException e)
{
throw new RuntimeException("Something went wrong while unmarshalling the file " + changeLogFilePath, e);
}
catch (SAXException e)
{
throw new RuntimeException("Something went wrong while parsing file " + changeLogFilePath, e);
}
}

private boolean configurationHasContext(String contextList)
Expand All @@ -166,7 +180,7 @@ private boolean configurationHasContext(String contextList)
boolean negate = context.startsWith("!");
context = context.replace("!", "");
boolean contains = configuration.getContexts().contains(context);
if ((contains && !negate) || (!contains && negate))
if (contains && !negate || !contains && negate)
{
return true;
}
Expand Down