Skip to content

Commit

Permalink
Merge pull request #23 from evant/master
Browse files Browse the repository at this point in the history
Added argument to tell only which files have changed
  • Loading branch information
luontola committed Jul 4, 2014
2 parents c81f777 + 70cdac4 commit 2a54ad3
Show file tree
Hide file tree
Showing 3 changed files with 52 additions and 7 deletions.
5 changes: 5 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,11 @@ Optional system properties:
retrolambda.outputDir
Output directory into where the generated class files are written.
Defaults to same as retrolambda.inputDir
retrolambda.changed
A list of all the files that have changed since last run.
This is useful for a build tool to support incremental compilation.
```


Expand Down
20 changes: 19 additions & 1 deletion retrolambda/src/main/java/net/orfjackal/retrolambda/Config.java
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,11 @@

import org.objectweb.asm.Opcodes;

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

public class Config {

Expand All @@ -16,6 +19,7 @@ public class Config {
private static final String INPUT_DIR = PREFIX + "inputDir";
private static final String OUTPUT_DIR = PREFIX + "outputDir";
private static final String CLASSPATH = PREFIX + "classpath";
private static final String CHANGED = PREFIX + "changed";

private static final List<String> requiredProperties = new ArrayList<>();
private static final List<String> requiredProperitesHelp = new ArrayList<>();
Expand Down Expand Up @@ -119,6 +123,20 @@ private String getRequiredProperty(String key) {
return value;
}

// incremental files

static {
optionalParameterHelp(CHANGED,
"A list of all the files that have changed since last run.",
"This is useful for a build tool to support incremental compilation.");
}

public List<Path> getChangedFiles() {
String files = p.getProperty(CHANGED);
if (files == null) return null;
return Arrays.asList(files.split(File.pathSeparator)).stream()
.map(Paths::get).collect(Collectors.toList());
}

// help

Expand Down
34 changes: 28 additions & 6 deletions retrolambda/src/main/java/net/orfjackal/retrolambda/Main.java
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,19 @@

package net.orfjackal.retrolambda;

import java.io.*;
import java.net.*;
import java.nio.file.*;
import java.util.*;
import java.io.IOException;
import java.io.InputStream;
import java.net.MalformedURLException;
import java.net.URI;
import java.net.URL;
import java.net.URLClassLoader;
import java.nio.file.Files;
import java.nio.file.Path;
import java.nio.file.Paths;
import java.nio.file.attribute.BasicFileAttributes;
import java.util.Arrays;
import java.util.List;
import java.util.Properties;

public class Main {

Expand All @@ -23,10 +32,14 @@ public static void main(String[] args) {
Path inputDir = config.getInputDir();
Path outputDir = config.getOutputDir();
String classpath = config.getClasspath();
List<Path> changedFiles = config.getChangedFiles();
System.out.println("Bytecode version: " + bytecodeVersion + " (" + config.getJavaVersion() + ")");
System.out.println("Input directory: " + inputDir);
System.out.println("Output directory: " + outputDir);
System.out.println("Classpath: " + classpath);
if (changedFiles != null) {
System.out.println("Changed: " + changedFiles.size() + " files");
}

if (!Files.isDirectory(inputDir)) {
System.out.println("Nothing to do; not a directory: " + inputDir);
Expand All @@ -35,12 +48,21 @@ public static void main(String[] args) {

try {
Thread.currentThread().setContextClassLoader(new URLClassLoader(asUrls(classpath)));
Files.walkFileTree(inputDir, new BytecodeTransformingFileVisitor(inputDir, outputDir) {

BytecodeTransformingFileVisitor visitor = new BytecodeTransformingFileVisitor(inputDir, outputDir) {
@Override
protected byte[] transform(byte[] bytecode) {
return LambdaUsageBackporter.transform(bytecode, bytecodeVersion);
}
});
};

if (changedFiles == null) {
Files.walkFileTree(inputDir, visitor);
} else {
for (Path inputFile : changedFiles) {
visitor.visitFile(inputFile, Files.readAttributes(inputFile, BasicFileAttributes.class));
}
}
} catch (Throwable t) {
System.out.println("Error! Failed to transform some classes");
t.printStackTrace(System.out);
Expand Down

0 comments on commit 2a54ad3

Please sign in to comment.