Skip to content

Commit

Permalink
Merge pull request #74 from tkhduracell/master
Browse files Browse the repository at this point in the history
Added a file parameter for file inclusion
  • Loading branch information
luontola committed Dec 15, 2015
2 parents e02a05b + 2ee88fb commit 4cb15a6
Show file tree
Hide file tree
Showing 4 changed files with 90 additions and 5 deletions.
4 changes: 4 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -126,6 +126,10 @@ Optional system properties:
List of files to process, instead of processing all files.
This is useful for a build tool to support incremental compilation.
retrolambda.includedFile
A file listing the files to process (one file per line), instead of processing all files.
This is useful for a build tool to support incremental compilation.
If the Java agent is used, then Retrolambda will use it to capture the
lambda classes generated by Java. Otherwise Retrolambda will hook into
Java's internal lambda dumping API, which is more susceptible to suddenly
Expand Down
30 changes: 29 additions & 1 deletion retrolambda/src/main/java/net/orfjackal/retrolambda/Config.java
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,13 @@

package net.orfjackal.retrolambda;

import com.google.common.base.Charsets;
import com.google.common.io.*;
import com.google.common.io.Files;
import org.objectweb.asm.Opcodes;

import java.io.File;
import java.io.*;
import java.nio.charset.Charset;
import java.nio.file.*;
import java.util.*;
import java.util.stream.Collectors;
Expand All @@ -20,6 +24,7 @@ public class Config {
public static final String OUTPUT_DIR = PREFIX + "outputDir";
public static final String CLASSPATH = PREFIX + "classpath";
public static final String INCLUDED_FILES = PREFIX + "includedFiles";
public static final String INCLUDED_FILE = PREFIX + "includedFile";

private static final List<String> requiredProperties = new ArrayList<>();
private static final List<String> requiredPropertiesHelp = new ArrayList<>();
Expand Down Expand Up @@ -159,6 +164,29 @@ public List<Path> getIncludedFiles() {
.collect(Collectors.toList());
}

static {
optionalParameterHelp(INCLUDED_FILE,
"A file listing the files to process (one file per line), instead of processing all files.",
"This is useful for a build tool to support incremental compilation.");
}

public List<Path> getIncludedFileList() {
String filePath = p.getProperty(INCLUDED_FILE);
if (filePath == null) {
return null;
}
File file = Paths.get(filePath).toFile();

try {
return Files.readLines(file, Charsets.UTF_8).stream()
.filter(s -> !s.isEmpty())
.map(Paths::get)
.collect(Collectors.toList());
} catch (IOException e) {
return Collections.emptyList();
}
}

// help

public String getHelp() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

package net.orfjackal.retrolambda;

import com.google.common.collect.Lists;
import net.orfjackal.retrolambda.files.*;
import net.orfjackal.retrolambda.interfaces.*;
import net.orfjackal.retrolambda.lambdas.*;
Expand All @@ -21,13 +22,23 @@ public static void run(Config config) throws Throwable {
Path inputDir = config.getInputDir();
Path outputDir = config.getOutputDir();
String classpath = config.getClasspath();
List<Path> includedFiles = config.getIncludedFiles();
List<Path> includedFilesByArgument = config.getIncludedFileList();
List<Path> includedFilesByFileList = config.getIncludedFiles();

System.out.println("Bytecode version: " + bytecodeVersion + " (" + config.getJavaVersion() + ")");
System.out.println("Default methods: " + defaultMethodsEnabled);
System.out.println("Input directory: " + inputDir);
System.out.println("Output directory: " + outputDir);
System.out.println("Classpath: " + classpath);
if (includedFiles != null) {

List<Path> includedFiles = Lists.newArrayList();
if (includedFilesByArgument != null) {
includedFiles.addAll(includedFilesByArgument);
}
if (includedFilesByFileList != null) {
includedFiles.addAll(includedFilesByFileList);
}
if (!includedFiles.isEmpty()) {
System.out.println("Included files: " + includedFiles.size());
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,17 @@

package net.orfjackal.retrolambda;

import com.google.common.base.*;
import com.google.common.collect.Lists;
import com.google.common.io.Files;
import org.junit.*;
import org.junit.rules.ExpectedException;

import java.io.File;
import java.io.*;
import java.nio.file.Paths;
import java.util.*;
import java.util.Optional;
import java.util.stream.Collectors;

import static org.hamcrest.MatcherAssert.assertThat;
import static org.hamcrest.Matchers.*;
Expand Down Expand Up @@ -72,4 +77,41 @@ public void included_files() {
systemProperties.setProperty(Config.INCLUDED_FILES, "/foo/one.class" + File.pathSeparator + "/foo/two.class");
assertThat("multiple values", config().getIncludedFiles(), is(Arrays.asList(Paths.get("/foo/one.class"), Paths.get("/foo/two.class"))));
}
}

@Test
public void included_file() throws IOException {
assertThat("not set", config().getIncludedFileList(), is(nullValue()));

systemProperties.setProperty(Config.INCLUDED_FILE, "");
assertThat("zero values", config().getIncludedFileList(), is(empty()));

// Single file
File singleTmp = File.createTempFile("test",".list");
singleTmp.deleteOnExit();

List<String> file = Lists.newArrayList("foo.java");
String delimiter = System.getProperty("line.separator");
Files.write(file.stream()
.collect(Collectors.joining(delimiter)), singleTmp, Charsets.UTF_8);

systemProperties.setProperty(Config.INCLUDED_FILE, singleTmp.getAbsolutePath());
assertThat("one value", config().getIncludedFileList(), is(
file.stream()
.map(f -> Paths.get(f))
.collect(Collectors.toList())));

// Multiple files
File multiTmp = File.createTempFile("test",".list");
multiTmp.deleteOnExit();

List<String> files = Lists.newArrayList("foo.java", "bar.java");
Files.write(files.stream()
.collect(Collectors.joining(delimiter)), multiTmp, Charsets.UTF_8);

systemProperties.setProperty(Config.INCLUDED_FILE, multiTmp.getAbsolutePath());
assertThat("two values", config().getIncludedFileList(), is(
files.stream()
.map(f -> Paths.get(f))
.collect(Collectors.toList())));
}
}

0 comments on commit 4cb15a6

Please sign in to comment.