-
Notifications
You must be signed in to change notification settings - Fork 35
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
478 jqa tries to load rules from jqa report file #482
Merged
DirkMahler
merged 9 commits into
master
from
478-jqa-tries-to-load-rules-from-jqa-report-file
Jul 17, 2024
Merged
Changes from all commits
Commits
Show all changes
9 commits
Select commit
Hold shift + click to select a range
f48144f
#478 Bug fix
yaseno2186 466c4df
#478 Bug fix
yaseno2186 31dd153
#478 Bug fix
yaseno2186 8cf518f
Merge branch 'refs/heads/master' into 478-jqa-tries-to-load-rules-fro…
yaseno2186 846818f
#478 Bug fix
yaseno2186 427fab4
#479 Cleaned XmlRuleParserPluginTest
yaseno2186 978042c
#482 Cleaned XmlRuleParserPluginTest
yaseno2186 433f354
#482 Cleaned XmlRuleParserPluginTest
yaseno2186 8bf26ec
#479 Updated XmlRuleParserPluginTest.java
yaseno2186 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
31 changes: 0 additions & 31 deletions
31
core/rule/src/main/java/com/buschmais/jqassistant/core/rule/impl/reader/XmlHelper.java
This file was deleted.
Oops, something went wrong.
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
75 changes: 75 additions & 0 deletions
75
core/shared/src/main/java/com/buschmais/jqassistant/core/shared/xml/XmlHelper.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,75 @@ | ||
package com.buschmais.jqassistant.core.shared.xml; | ||
|
||
import java.io.IOException; | ||
import java.io.InputStream; | ||
import java.util.function.Predicate; | ||
|
||
import javax.xml.XMLConstants; | ||
import javax.xml.namespace.QName; | ||
import javax.xml.stream.XMLInputFactory; | ||
import javax.xml.stream.XMLStreamConstants; | ||
import javax.xml.stream.XMLStreamException; | ||
import javax.xml.stream.XMLStreamReader; | ||
import javax.xml.validation.Schema; | ||
import javax.xml.validation.SchemaFactory; | ||
|
||
import lombok.extern.slf4j.Slf4j; | ||
import org.xml.sax.SAXException; | ||
|
||
/** | ||
* Provides utility functions for working with XML files. | ||
*/ | ||
@Slf4j | ||
public class XmlHelper { | ||
|
||
private final static XMLInputFactory xmlInputFactory; | ||
|
||
static { | ||
xmlInputFactory = XMLInputFactory.newInstance(); | ||
xmlInputFactory.setProperty(XMLInputFactory.SUPPORT_DTD, false); | ||
} | ||
|
||
public static XMLInputFactory getXMLInputFactory() { | ||
return xmlInputFactory; | ||
} | ||
|
||
public static boolean rootElementMatches(InputStreamSupplier inputStreamSupplier, Predicate<QName> rootElementPredicate) { | ||
try (InputStream stream = inputStreamSupplier.get()) { | ||
XMLStreamReader reader = xmlInputFactory.createXMLStreamReader(stream); | ||
while (reader.hasNext()) { | ||
if (reader.next() == XMLStreamConstants.START_ELEMENT) { | ||
return rootElementPredicate.test(reader.getName()); | ||
} | ||
} | ||
} catch (XMLStreamException e) { | ||
log.warn("Cannot parse XML file."); | ||
} catch (IOException e) { | ||
throw new IllegalStateException("Cannot close XML document.", e); | ||
} | ||
return false; | ||
} | ||
|
||
public interface InputStreamSupplier { | ||
|
||
InputStream get() throws IOException; | ||
|
||
} | ||
|
||
/** | ||
* Return a {@link Schema} instance for the given resource. | ||
* | ||
* @param resource | ||
* The resource. | ||
* @return The {@link Schema} instance. | ||
*/ | ||
public static Schema getSchema(String resource) { | ||
Schema schema; | ||
try { | ||
SchemaFactory schemaFactory = SchemaFactory.newInstance(XMLConstants.W3C_XML_SCHEMA_NS_URI); | ||
schema = schemaFactory.newSchema(XmlHelper.class.getResource(resource)); | ||
} catch (SAXException e) { | ||
throw new IllegalStateException("Cannot read rules schema.", e); | ||
} | ||
return schema; | ||
} | ||
} |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please reformat the class with the jQA settings