8000 Replace commons-io by Guava by regisd · Pull Request #319 · jflex-de/jflex · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content

Replace commons-io by Guava #319

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

Merged
merged 5 commits into from
Sep 21, 2018
Merged
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
4 changes: 2 additions & 2 deletions jflex-maven-plugin/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -78,8 +78,8 @@
</build>
<dependencies>
<dependency>
<groupId>commons-io</groupId>
<artifactId>commons-io</artifactId>
<groupId>com.google.guava</groupId>
<artifactId>guava</artifactId>
</dependency>
<dependency>
<groupId>de.jflex</groupId>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,16 +8,18 @@
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
package de.jflex.plugin.maven;

import com.google.common.base.Predicate;
import com.google.common.collect.FluentIterable;
import com.google.common.collect.ImmutableSet;
import com.google.common.io.Files;
import java.io.File;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Iterator;
import java.util.List;
import jflex.Main;
import jflex.Options;
import org.apache.commons.io.FileUtils;
import org.apache.maven.plugin.AbstractMojo;
import org.apache.maven.plugin.MojoExecutionException;
import org.apache.maven.plugin.MojoFailureException;
Expand Down Expand Up @@ -170,11 +172,12 @@ private void parseLexDefinition(File lexDefinition)

if (lexDefinition.isDirectory()) {
// recursively process files contained within
String[] extensions = {"jflex", "jlex", "lex", "flex"};
getLog().debug("Processing lexer files found in " + lexDefinition);
Iterator<File> fileIterator = FileUtils.iterateFiles(lexDefinition, extensions, true);
while (fileIterator.hasNext()) {
File lexFile = fileIterator.next();
FluentIterable<File> files =
Files.fileTreeTraverser()
.preOrderTraversal(lexDefinition)
.filter(new ExtensionPredicate("jflex", "jlex", "lex", "flex"));
for (File lexFile : files) {
parseLexFile(lexFile);
}
} else {
Expand Down Expand Up @@ -277,4 +280,21 @@ private File getAbsolutePath(File path) {
}
return new File(this.project.getBasedir().getAbsolutePath(), path.getPath());
}

static class ExtensionPredicate implements Predicate<File> {
final ImmutableSet<String> extensions;

ExtensionPredicate(ImmutableSet<String> extensions) {
this.extensions = extensions;
}

ExtensionPredicate(String... extensions) {
this(ImmutableSet.copyOf(extensions));
}

@Override
public boolean apply(File file) {
return extensions.contains(Files.getFileExtension(file.getName()));
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,10 @@
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
package de.jflex.plugin.maven;

import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertTrue;

import com.google.common.base.Predicate;
import java.io.File;
import java.io.IOException;
import org.apache.maven.plugin.testing.MojoRule;
Expand Down Expand Up @@ -89,6 +91,15 @@ public void testRecursion() throws Exception {
assertTrue("produced file is a file: " + produced, produced.isFile());
}

@Test
public void extensionPredicate() {
Predicate<File> predicate = new JFlexMojo.ExtensionPredicate("bar", "baz");
assertTrue(predicate.apply(new File("/tmp/foo.bar")));
assertTrue(predicate.apply(new File("/tmp/foo.baz")));
assertFalse(predicate.apply(new File("/tmp/foo.bar.too")));
assertFalse(predicate.apply(new File("/tmp/foo.blahblahbar")));
}

/**
* Gets the expected path to the output file from jflex.
*
Expand Down
0