Skip to content
Open
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
17 changes: 17 additions & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
language: java

jdk: oraclejdk8

dist: trusty

branches: master

cache:
directories:
- $HOME/.m2

before_script:
- mvn -q clean install -DskipTests=true -Dmaven.javadoc.skip=true -B -V

script:
- mvn clean test
3 changes: 1 addition & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ This library helps in analyzing Nginx web server configuration files, looking up

#### Features
- Convert config file to AST tree using ANTLR4 parsing capabilities
- The same is available for JavaCC too (deprecated)
- Rebuild config files and dump them back to *.conf
- Nested blocks support
- If statements support
Expand All @@ -17,7 +16,7 @@ Add the following dependency to your POM:
<dependency>
<groupId>com.github.odiszapc</groupId>
<artifactId>nginxparser</artifactId>
<version>0.9.3</version>
<version>0.9.6</version>
</dependency>
```

Expand Down
2 changes: 0 additions & 2 deletions compile.javacc.cmd

This file was deleted.

6 changes: 3 additions & 3 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -71,13 +71,13 @@
<dependency>
<groupId>org.antlr</groupId>
<artifactId>antlr4-runtime</artifactId>
<version>4.5.3</version>
<version>4.7</version>
</dependency>

<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>4.11</version>
<version>4.12</version>
<scope>test</scope>
</dependency>
</dependencies>
Expand All @@ -87,7 +87,7 @@
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.5.1</version>
<version>3.6.1</version>
<configuration>
<source>1.6</source>
<target>1.6</target>
Expand Down
3 changes: 3 additions & 0 deletions src/main/java/com/github/odiszapc/nginxparser/NgxBlock.java
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ public Iterator<NgxEntry> iterator() {
return getEntries().iterator();
}

@SuppressWarnings("incomplete-switch")
public void remove(NgxEntry itemToRemove) {
if (null == itemToRemove)
throw new NullPointerException("Item can not be null");
Expand Down Expand Up @@ -78,6 +79,7 @@ public void removeAll(Iterable<NgxEntry> itemsToRemove) {
}
}

@SuppressWarnings("unchecked")
public <T extends NgxEntry> T find(Class<T> clazz, String... params) {
List<NgxEntry> all = findAll(clazz, new ArrayList<NgxEntry>(), params);
if (all.isEmpty())
Expand All @@ -104,6 +106,7 @@ public <T extends NgxEntry> List<NgxEntry> findAll(Class<T> clazz, String... par
return findAll(clazz, new ArrayList<NgxEntry>(), params);
}

@SuppressWarnings("incomplete-switch")
public <T extends NgxEntry> List<NgxEntry> findAll(Class<T> clazz, List<NgxEntry> result, String... params) {
List<NgxEntry> res = new ArrayList<NgxEntry>();

Expand Down
21 changes: 4 additions & 17 deletions src/main/java/com/github/odiszapc/nginxparser/NgxConfig.java
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,9 @@
import com.github.odiszapc.nginxparser.antlr.NginxLexer;
import com.github.odiszapc.nginxparser.antlr.NginxListenerImpl;
import com.github.odiszapc.nginxparser.antlr.NginxParser;
import com.github.odiszapc.nginxparser.javacc.NginxConfigParser;
import com.github.odiszapc.nginxparser.javacc.ParseException;
import org.antlr.v4.runtime.ANTLRInputStream;

import org.antlr.v4.runtime.CharStream;
import org.antlr.v4.runtime.CharStreams;
import org.antlr.v4.runtime.CommonTokenStream;
import org.antlr.v4.runtime.tree.ParseTree;
import org.antlr.v4.runtime.tree.ParseTreeWalker;
Expand Down Expand Up @@ -57,21 +57,8 @@ public static NgxConfig read(InputStream in) throws IOException {
return readAntlr(in);
}

/**
* Read config from existing stream
* @param input stream to read from
* @return Config object
* @throws IOException
* @throws ParseException
*/
public static NgxConfig readJavaCC(InputStream input) throws IOException, ParseException {
NginxConfigParser parser = new NginxConfigParser(input);
return parser.parse();
}


public static NgxConfig readAntlr(InputStream in) throws IOException {
ANTLRInputStream input = new ANTLRInputStream(in);
CharStream input = CharStreams.fromStream(in);
NginxLexer lexer = new NginxLexer(input);
CommonTokenStream tokens = new CommonTokenStream(lexer);
NginxParser parser = new NginxParser(tokens);
Expand Down
2 changes: 0 additions & 2 deletions src/main/java/com/github/odiszapc/nginxparser/NgxDumper.java
Original file line number Diff line number Diff line change
Expand Up @@ -26,12 +26,10 @@
public class NgxDumper {

private NgxConfig config;
private final static int PAD_SIZE = 2;
private final static String PAD_SYMBOL = " ";
private final static String LBRACE = "{";
private final static String RBRACE = "}";
private final static String LF = "\n";
private final static String CRLF = "\r\n";

public NgxDumper(NgxConfig config) {
this.config = config;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
// Generated from Nginx.g4 by ANTLR 4.5.3

package com.github.odiszapc.nginxparser.antlr;
import com.github.odiszapc.nginxparser.*;


import org.antlr.v4.runtime.ParserRuleContext;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
// Generated from Nginx.g4 by ANTLR 4.5.3

package com.github.odiszapc.nginxparser.antlr;
import com.github.odiszapc.nginxparser.*;

import org.antlr.v4.runtime.tree.AbstractParseTreeVisitor;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@

@SuppressWarnings({"all", "warnings", "unchecked", "unused", "cast"})
public class NginxLexer extends Lexer {
static { RuntimeMetaData.checkVersion("4.5.3", RuntimeMetaData.VERSION); }
static { RuntimeMetaData.checkVersion("4.7", RuntimeMetaData.VERSION); }

protected static final DFA[] _decisionToDFA;
protected static final PredictionContextCache _sharedContextCache =
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,7 @@
// Generated from Nginx.g4 by ANTLR 4.5.3

package com.github.odiszapc.nginxparser.antlr;
import com.github.odiszapc.nginxparser.*;

import org.antlr.v4.runtime.tree.ParseTreeListener;
import org.antlr.v4.runtime.tree.ParseTreeListener;

/**
* This interface defines a complete listener for a parse tree produced by
Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,7 @@
package com.github.odiszapc.nginxparser.antlr;

import com.github.odiszapc.nginxparser.NgxConfig;
import org.antlr.v4.runtime.misc.NotNull;
import org.antlr.v4.runtime.tree.ParseTree;
import org.antlr.v4.runtime.tree.TerminalNode;

import java.util.List;


public class NginxListenerImpl extends NginxBaseListener {
Expand All @@ -17,7 +13,7 @@ public NgxConfig getResult() {
}

@Override
public void enterConfig(@NotNull NginxParser.ConfigContext ctx) {
public void enterConfig(NginxParser.ConfigContext ctx) {
result = ctx.ret;
}
}
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
// Generated from Nginx.g4 by ANTLR 4.5.3

package com.github.odiszapc.nginxparser.antlr;
import com.github.odiszapc.nginxparser.*;

import org.antlr.v4.runtime.tree.ParseTreeVisitor;

Expand Down
Loading