Skip to content

Commit

Permalink
Update JavaCC to 7.0.13
Browse files Browse the repository at this point in the history
  • Loading branch information
zbynek committed Dec 4, 2023
1 parent c74a825 commit 45bfe9d
Show file tree
Hide file tree
Showing 7 changed files with 23 additions and 33 deletions.
6 changes: 4 additions & 2 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,15 +11,17 @@ permissions:

jobs:
build:

runs-on: ubuntu-latest
strategy:
matrix:
version: [ 8, 11, 17 ]

steps:
- uses: actions/checkout@v3
- name: Set up JDK 11
uses: actions/setup-java@v3
with:
java-version: '8'
java-version: ${{ matrix.version }}
distribution: 'temurin'
- name: Run build script
run: ./gradlew build
Expand Down
1 change: 1 addition & 0 deletions config/checkstyle/checks.xml
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@
</module>
<module name="AvoidStarImport">
<property name="severity" value="warning"/>
<property name="excludes" value="org.junit.Assert"/>
</module>
<module name="IllegalImport">
<property name="severity" value="error"/>
Expand Down
8 changes: 3 additions & 5 deletions subprojects/plugin/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -23,15 +23,13 @@ dependencies {
implementation('commons-io:commons-io') {
version { strictly '2.4' }
}
implementation 'org.apache.commons:commons-lang3:3.4'
implementation 'org.apache.commons:commons-lang3:3.12.0'

testImplementation 'org.hamcrest:hamcrest-all:1.3'
testImplementation 'org.mockito:mockito-all:1.10.19'
testImplementation 'org.powermock:powermock-module-junit4:1.6.4'
testImplementation 'org.powermock:powermock-api-mockito:1.6.4'

compileOnly 'net.java.dev.javacc:javacc:7.0.12'
testImplementation 'net.java.dev.javacc:javacc:7.0.12'
compileOnly 'net.java.dev.javacc:javacc:7.0.13'
testImplementation 'net.java.dev.javacc:javacc:7.0.13'
}

eclipse {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ public void givenVersion6WhenExecuteAllTasksFilesAreGenerated() throws URISyntax

@Test
public void givenVersion7WhenExecuteAllTasksFilesAreGenerated() throws URISyntaxException, IOException {
givenVersionWhenExecuteAllTasksFilesAreGenerated("net.java.dev.javacc:javacc:7.0.12", true);
givenVersionWhenExecuteAllTasksFilesAreGenerated("net.java.dev.javacc:javacc:7.0.13", true);
}

@Test
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ private Configuration createJavaccConfiguration(Project project) {

private void configureDefaultJavaccDependency(final Project project, Configuration configuration) {
configuration.defaultDependencies(dependencies ->
dependencies.add(project.getDependencies().create("net.java.dev.javacc:javacc:7.0.12")));
dependencies.add(project.getDependencies().create("net.java.dev.javacc:javacc:7.0.13")));
}

private void addCompileJavaccTaskToProject(Project project, Configuration configuration) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,12 +15,16 @@

public class CompiledJavaccFile {
private static final Pattern PACKAGE_DECLARATION_PATTERN = Pattern.compile("package\\s+([^\\s.;]+(\\.[^\\s.;]+)*)\\s*;");

protected FileCopyUtil fileCopyUtil = FileUtils::copyFile;
private File compiledJavaccFile;
private File outputDirectory;
private File targetDirectory;
private Logger logger;

protected interface FileCopyUtil {
void copyFile(File from, File to) throws IOException;
}

public CompiledJavaccFile(File file, File outputDirectory, File targetDirectory, Logger logger) {
this.compiledJavaccFile = file;
this.outputDirectory = outputDirectory;
Expand Down Expand Up @@ -87,7 +91,7 @@ public void copyCompiledFileToTargetDirectory() {
logger.info("Copying compiled file {} to {}", compiledJavaccFile, destination);

try {
FileUtils.copyFile(compiledJavaccFile, destination);
fileCopyUtil.copyFile(compiledJavaccFile, destination);
} catch (IOException e) {
String errorMessage = String.format("Could not copy %s from %s to %s", compiledJavaccFile, outputDirectory, targetDirectory);
throw new CompiledJavaccFileOperationException(errorMessage, e);
Expand All @@ -103,7 +107,7 @@ public void copyCustomAstClassToTargetDirectory(File customAstClassInputFile) {
logger.info("Copying custom AST class [{}] to [{}]", customAstClassInputFile, destination);

try {
FileUtils.copyFile(customAstClassInputFile, destination);
fileCopyUtil.copyFile(customAstClassInputFile, destination);
} catch (IOException e) {
String errorMessage = String.format("Could not copy %s to %s", customAstClassInputFile, targetDirectory);
throw new CompiledJavaccFileOperationException(errorMessage, e);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,16 +1,10 @@
package org.javacc.plugin.gradle.javacc.compilationresults;

import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertNull;
import static org.junit.Assert.assertTrue;
import static org.mockito.Matchers.any;
import static org.junit.Assert.*;
import static org.mockito.Matchers.anyString;
import static org.mockito.Matchers.eq;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.verify;
import static org.powermock.api.mockito.PowerMockito.doThrow;

import java.io.File;
import java.io.IOException;
Expand All @@ -23,14 +17,7 @@
import org.junit.After;
import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.mockito.Answers;
import org.powermock.api.mockito.PowerMockito;
import org.powermock.core.classloader.annotations.PrepareForTest;
import org.powermock.modules.junit4.PowerMockRunner;

@RunWith(PowerMockRunner.class)
@PrepareForTest(FileUtils.class)

public class CompiledJavaccFileTest {
private File outputDirectory;
private Collection<File> customAstClassesDirectory;
Expand Down Expand Up @@ -139,14 +126,12 @@ public void copyCustomAstClassToTargetDirectory() {
}

@Test(expected = CompiledJavaccFileOperationException.class)
public void copyCustomAstClassToTargetDirectoryFails() throws Exception {
PowerMockito.mockStatic(FileUtils.class, Answers.CALLS_REAL_METHODS.get());
doThrow(new IOException()).when(FileUtils.class);
FileUtils.copyFile(any(File.class), any(File.class));

public void copyCustomAstClassToTargetDirectoryFails() {
File file = new File(outputDirectory, "FileWithCorrespondingCustomAstClass.java");
CompiledJavaccFile compiledJavaccFile = new CompiledJavaccFile(file, outputDirectory, targetDirectory, logger);

compiledJavaccFile.fileCopyUtil = (from, to) -> {
throw new IOException();
};
compiledJavaccFile.handleCustomAstInJavacc(customAstClassesDirectory);
}

Expand Down

0 comments on commit 45bfe9d

Please sign in to comment.