Handle removed dependency
This commit is contained in:
parent
068ff9d3d6
commit
5f5a8949f6
|
@ -150,7 +150,7 @@ class GrammarDependencies {
|
|||
Collection<String> usages = e.getValue().getValue();
|
||||
|
||||
if (usages.contains(grammarPath)) {
|
||||
if (!Arrays.equals(MojoUtils.checksum(depGrammarFile), checksum)) {
|
||||
if (!depGrammarFile.exists() || !Arrays.equals(MojoUtils.checksum(depGrammarFile), checksum)) {
|
||||
log.debug(" " + grammarPath + ": dependency " +
|
||||
depGrammarFile.getName() + " changed");
|
||||
|
||||
|
|
|
@ -5,6 +5,7 @@ import io.takari.maven.testing.TestResources;
|
|||
|
||||
import org.apache.maven.execution.MavenSession;
|
||||
import org.apache.maven.plugin.MojoExecution;
|
||||
import org.apache.maven.plugin.MojoExecutionException;
|
||||
import org.apache.maven.project.MavenProject;
|
||||
|
||||
import org.codehaus.plexus.util.xml.Xpp3Dom;
|
||||
|
@ -13,6 +14,7 @@ import static org.junit.Assert.*;
|
|||
|
||||
import org.junit.Rule;
|
||||
import org.junit.Test;
|
||||
import org.junit.rules.ExpectedException;
|
||||
|
||||
import java.io.ByteArrayOutputStream;
|
||||
import java.io.File;
|
||||
|
@ -31,6 +33,9 @@ import java.util.regex.Pattern;
|
|||
|
||||
|
||||
public class Antlr4MojoTest {
|
||||
@Rule
|
||||
public ExpectedException thrown = ExpectedException.none();
|
||||
|
||||
@Rule
|
||||
public final TestResources resources = new TestResources();
|
||||
|
||||
|
@ -275,6 +280,42 @@ public class Antlr4MojoTest {
|
|||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void processWhenDependencyRemoved() throws Exception {
|
||||
Map.Entry<ByteArrayOutputStream, PrintStream> stdout = redirect();
|
||||
ByteArrayOutputStream output = stdout.getKey();
|
||||
|
||||
try {
|
||||
File baseDir = resources.getBasedir("dependencyRemoved");
|
||||
File antlrDir = new File(baseDir, "src/main/antlr4");
|
||||
|
||||
File baseGrammar = new File(antlrDir, "imports/HelloBase.g4");
|
||||
|
||||
MavenProject project = maven.readMavenProject(baseDir);
|
||||
MavenSession session = maven.newMavenSession(project);
|
||||
MojoExecution exec = maven.newMojoExecution("antlr4");
|
||||
|
||||
maven.executeMojo(session, project, exec);
|
||||
|
||||
String t = text(baseGrammar);
|
||||
|
||||
try {
|
||||
// if the base grammar no longer exists, processing must be performed
|
||||
baseGrammar.delete();
|
||||
|
||||
thrown.expect(MojoExecutionException.class);
|
||||
thrown.expectMessage("ANTLR 4 caught 1 build errors.");
|
||||
|
||||
maven.executeMojo(session, project, exec);
|
||||
} finally {
|
||||
write(baseGrammar, t);
|
||||
}
|
||||
} finally {
|
||||
System.out.flush();
|
||||
System.setOut(stdout.getValue());
|
||||
}
|
||||
}
|
||||
|
||||
private List<String> processAndReset(ByteArrayOutputStream output) {
|
||||
Pattern pattern = Pattern.compile("Processing grammar: (.+)");
|
||||
Matcher matcher = pattern.matcher(output.toString());
|
||||
|
|
|
@ -0,0 +1,27 @@
|
|||
<project xmlns="http://maven.apache.org/POM/4.0.0"
|
||||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
<groupId>deps.removed</groupId>
|
||||
<artifactId>depRemoved</artifactId>
|
||||
<version>1.0-SNAPSHOT</version>
|
||||
<packaging>jar</packaging>
|
||||
<name>Test processing after dependency removed</name>
|
||||
<dependencies>
|
||||
<dependency>
|
||||
<groupId>junit</groupId>
|
||||
<artifactId>junit</artifactId>
|
||||
<version>4.11</version>
|
||||
<scope>test</scope>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
<build>
|
||||
<plugins>
|
||||
<plugin>
|
||||
<artifactId>antlr4-maven-plugin</artifactId>
|
||||
<configuration>
|
||||
</configuration>
|
||||
</plugin>
|
||||
</plugins>
|
||||
</build>
|
||||
</project>
|
|
@ -0,0 +1,16 @@
|
|||
lexer grammar TestBaseLexer;
|
||||
|
||||
tokens { Name }
|
||||
|
||||
// Default "mode": Everything OUTSIDE of a tag
|
||||
Comment : '<!--' .*? '-->' ;
|
||||
CDSect : '<![CDATA[' .*? ']]>' ;
|
||||
|
||||
fragment
|
||||
Whitespace : ' ' | '\n' | '\t' | '\r' ;
|
||||
|
||||
fragment
|
||||
Hexdigit : [a-fA-F0-9] ;
|
||||
|
||||
fragment
|
||||
Digit : [0-9] ;
|
|
@ -0,0 +1,7 @@
|
|||
grammar Hello;
|
||||
|
||||
import HelloBase;
|
||||
|
||||
r : 'hello' ID ;
|
||||
ID : [a-z]+ ;
|
||||
WS : [ \r\t\n]+ -> skip ;
|
Loading…
Reference in New Issue