Skip to content
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

test: reduces I/O footprint (and found two IO bugs on the way) #969

Merged
merged 1 commit into from
Nov 14, 2016
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 src/main/java/spoon/Launcher.java
Original file line number Diff line number Diff line change
Expand Up @@ -710,15 +710,15 @@ public void process() {

@Override
public void prettyprint() {
OutputType outputType = OutputType.fromString(jsapActualArgs.getString("output-type"));
long tstart = System.currentTimeMillis();
try {
OutputType outputType = OutputType.fromString(jsapActualArgs.getString("output-type"));
modelBuilder.generateProcessedSourceFiles(outputType, typeFilter);
} catch (Exception e) {
throw new SpoonException(e);
}

if (getEnvironment().isCopyResources()) {
if (!outputType.equals(OutputType.NO_OUTPUT) && getEnvironment().isCopyResources()) {
for (File dirInputSource : modelBuilder.getInputSources()) {
if (dirInputSource.isDirectory()) {
final Collection<?> resources = FileUtils.listFiles(dirInputSource, RESOURCES_FILE_FILTER, ALL_DIR_FILTER);
Expand Down
8 changes: 1 addition & 7 deletions src/main/java/spoon/compiler/SpoonResourceHelper.java
Original file line number Diff line number Diff line change
Expand Up @@ -95,13 +95,7 @@ public static SpoonFolder createFolder(File f) throws FileNotFoundException {
return new FileSystemFolder(f);
}
if (isArchive(f)) {
ZipFolder zipFolder = new ZipFolder(f);
File tempFile = File.createTempFile("ZIP", "ZIP");
tempFile.delete();
tempFile.mkdirs();
zipFolder.extract(tempFile);
tempFile.deleteOnExit();
return new FileSystemFolder(tempFile);
return new ZipFolder(f);
}
} catch (IOException e) {
Launcher.LOGGER.error(e.getMessage(), e);
Expand Down
4 changes: 4 additions & 0 deletions src/main/java/spoon/support/compiler/FileSystemFile.java
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,10 @@ public class FileSystemFile implements SpoonFile {

File file;

public FileSystemFile(String path) {
this(new File(path));
}

public FileSystemFile(File file) {
super();
try {
Expand Down
11 changes: 1 addition & 10 deletions src/main/java/spoon/testing/utils/ModelUtils.java
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@ public static void canBeBuilt(String outputDirectory, int complianceLevel) {

public static void canBeBuilt(File outputDirectoryFile, int complianceLevel, boolean noClasspath) {
final Launcher launcher = new Launcher();
final Factory factory = launcher.createFactory();
final Factory factory = launcher.getFactory();
factory.getEnvironment().setComplianceLevel(complianceLevel);
factory.getEnvironment().setNoClasspath(noClasspath);
final SpoonCompiler compiler = launcher.createCompiler(factory);
Expand All @@ -124,13 +124,4 @@ public static void canBeBuilt(String outputDirectory, int complianceLevel, boole
canBeBuilt(new File(outputDirectory), complianceLevel, noClasspath);
}

public static File getSpoonedDirectory(Class testClass) {
String file = testClass.getName().replaceAll("\\.", "/");
return new File("./target/spooned/" + file);
}

public static File getBuildDirectory(Class testClass) {
String file = testClass.getName().replaceAll("\\.", "/");
return new File("./target/spooned-build/" + file);
}
}
2 changes: 1 addition & 1 deletion src/test/java/spoon/processing/ProcessingTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,8 @@ public class ProcessingTest {
public void testInterruptAProcessor() throws Exception {
final Launcher launcher = new Launcher();
launcher.getEnvironment().setNoClasspath(true);
launcher.setArgs(new String[] {"--output-type", "nooutput" });
launcher.addInputResource("./src/test/java/spoon/processing/");
launcher.setSourceOutputDirectory("./target/trash");
final MyProcessor processor = new MyProcessor();
launcher.addProcessor(processor);
try {
Expand Down
4 changes: 2 additions & 2 deletions src/test/java/spoon/reflect/ast/CloneTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,8 @@ public class CloneTest {
@Test
public void testCloneMethodsDeclaredInAST() throws Exception {
final Launcher launcher = new Launcher();
launcher.setArgs(new String[] {"--output-type", "nooutput" });
launcher.getEnvironment().setNoClasspath(true);
launcher.setSourceOutputDirectory("./target/trash");
// interfaces.
launcher.addInputResource("./src/main/java/spoon/reflect/code");
launcher.addInputResource("./src/main/java/spoon/reflect/declaration");
Expand Down Expand Up @@ -77,8 +77,8 @@ private <T> boolean isRootDeclaration(CtInterface<T> intrface) {
@Test
public void testCloneCastConditional() throws Exception {
final Launcher launcher = new Launcher();
launcher.setArgs(new String[] {"--output-type", "nooutput" });
launcher.getEnvironment().setNoClasspath(true);
launcher.setSourceOutputDirectory("./target/trash");

launcher.addInputResource("./src/test/resources/spoon/test/visitor/ConditionalRes.java");

Expand Down
2 changes: 1 addition & 1 deletion src/test/java/spoon/reflect/ast/ParentTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,8 @@ public void testParentSetInSetter() throws Exception {
// contract: Check that all setters protect their parameter.
final Launcher launcher = new Launcher();
final Factory factory = launcher.getFactory();
launcher.setArgs(new String[] {"--output-type", "nooutput" });
launcher.getEnvironment().setNoClasspath(true);
launcher.setSourceOutputDirectory("./target/trash");
// interfaces.
launcher.addInputResource("./src/main/java/spoon/reflect/code");
launcher.addInputResource("./src/main/java/spoon/reflect/declaration");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,9 +26,9 @@ public class CtInheritanceScannerMethodsTest {
public void testMethodsInInheritanceScanner() throws Exception {
// contract: CtInheritanceScanner must declare all scanner and visitor methods.
final Launcher launcher = new Launcher();
launcher.setArgs(new String[] {"--output-type", "nooutput" });
launcher.getEnvironment().setNoClasspath(true);
launcher.addProcessor(new CheckVisitorProcessor(CtInheritanceScanner.class).withScanners().withVisitors());
launcher.setSourceOutputDirectory("./target/trash");
// interfaces.
launcher.addInputResource("./src/main/java/spoon/reflect/code");
launcher.addInputResource("./src/main/java/spoon/reflect/declaration");
Expand Down
2 changes: 1 addition & 1 deletion src/test/java/spoon/reflect/visitor/CtScannerTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -26,9 +26,9 @@ public class CtScannerTest {
public void testScannerContract() throws Exception {
// contract: CtScanner must call enter and exit methods in each visit methods.
final Launcher launcher = new Launcher();
launcher.setArgs(new String[] {"--output-type", "nooutput" });
launcher.getEnvironment().setNoClasspath(true);
launcher.addProcessor(new CheckScannerProcessor());
launcher.setSourceOutputDirectory("./target/trash");
// interfaces.
launcher.addInputResource("./src/main/java/spoon/reflect/code");
launcher.addInputResource("./src/main/java/spoon/reflect/declaration");
Expand Down
2 changes: 1 addition & 1 deletion src/test/java/spoon/reflect/visitor/CtVisitorTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -26,9 +26,9 @@ public class CtVisitorTest {
public void testMethodsInVisitor() throws Exception {
// contract: CtVisitor must declare all visit methods.
final Launcher launcher = new Launcher();
launcher.setArgs(new String[] {"--output-type", "nooutput" });
launcher.getEnvironment().setNoClasspath(true);
launcher.addProcessor(new CheckVisitorProcessor(CtVisitor.class).withVisitors());
launcher.setSourceOutputDirectory("./target/trash");
// interfaces.
launcher.addInputResource("./src/main/java/spoon/reflect/code");
launcher.addInputResource("./src/main/java/spoon/reflect/declaration");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,8 @@ public class JDTBatchCompilerTest {
@Test
public void testCompileGeneratedJavaFile() throws Exception {
final Launcher launcher = new Launcher();
launcher.setArgs(new String[] {"--output-type", "nooutput" });
launcher.addInputResource("./src/test/java/spoon/support/compiler/jdt/testclasses/Foo.java");
launcher.setSourceOutputDirectory("./target/trash");
launcher.setBinaryOutputDirectory("./target/binaries");
launcher.getEnvironment().setShouldCompile(true);
launcher.buildModel();
Expand Down
10 changes: 7 additions & 3 deletions src/test/java/spoon/test/annotation/AnnotationTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import org.junit.Before;
import org.junit.Test;
import spoon.Launcher;
import spoon.OutputType;
import spoon.processing.AbstractAnnotationProcessor;
import spoon.processing.ProcessingManager;
import spoon.reflect.code.CtBlock;
Expand Down Expand Up @@ -73,14 +74,14 @@
import static spoon.testing.utils.ModelUtils.canBeBuilt;

public class AnnotationTest {
private Launcher launcher;
private Factory factory;

@Before
public void setUp() throws Exception {
final Launcher launcher = new Launcher();
launcher = new Launcher();
launcher.run(new String[] {
"-i", "./src/test/java/spoon/test/annotation/testclasses/",
"-o", "./target/spooned/"
"--output-type", "nooutput"
});
factory = launcher.getFactory();
}
Expand Down Expand Up @@ -633,6 +634,9 @@ public void testUsageOfParametersInTypeAnnotation() throws Exception {

@Test
public void testOutputGeneratedByTypeAnnotation() throws Exception {
// we only write to disk here
launcher.setSourceOutputDirectory(new File("./target/spooned/"));
launcher.getModelBuilder().generateProcessedSourceFiles(OutputType.CLASSES);
canBeBuilt(new File("./target/spooned/spoon/test/annotation/testclasses/"), 8);
}

Expand Down
8 changes: 4 additions & 4 deletions src/test/java/spoon/test/api/APITest.java
Original file line number Diff line number Diff line change
Expand Up @@ -51,9 +51,9 @@ public class APITest {
public void testBasicAPIUsage() throws Exception {
// this test shows a basic usage of the Launcher API without command line
// and asserts there is no exception
SpoonAPI spoon = new Launcher();
Launcher spoon = new Launcher();
spoon.setArgs(new String[] {"--output-type", "nooutput" });
spoon.addInputResource("src/test/resources/spoon/test/api");
spoon.setSourceOutputDirectory("target/spooned");
spoon.run();
Factory factory = spoon.getFactory();
for (CtPackage p : factory.Package().getAll()) {
Expand Down Expand Up @@ -87,7 +87,7 @@ public void init() {
};
spoon.run(new String[] {
"-i", "src/test/resources/spoon/test/api/",
"-o", "target/spooned/apitest"
"-o", "fancy/fake/apitest" // we shouldn't write anything anyway
});
Assert.assertEquals(2, l.size());
}
Expand Down Expand Up @@ -338,8 +338,8 @@ public void accept(CtVisitor visitor) {
}

final Launcher launcher = new Launcher();
launcher.setArgs(new String[] {"--output-type", "nooutput" });
launcher.getEnvironment().setNoClasspath(true);
launcher.setSourceOutputDirectory("./target/trash/");
// Implementations
launcher.addInputResource("./src/main/java/spoon/support/reflect/code");
launcher.addInputResource("./src/main/java/spoon/support/reflect/declaration");
Expand Down
2 changes: 1 addition & 1 deletion src/test/java/spoon/test/arrays/ArraysTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -40,8 +40,8 @@ public void testArrayReferences() throws Exception {
@Test
public void testInitializeWithNewArray() throws Exception {
Launcher launcher = new Launcher();
launcher.setArgs(new String[] {"--output-type", "nooutput" });
launcher.addInputResource("./src/test/resources/noclasspath/Foo.java");
launcher.setSourceOutputDirectory("./target/trash");
launcher.getEnvironment().setNoClasspath(true);
launcher.run();

Expand Down
2 changes: 1 addition & 1 deletion src/test/java/spoon/test/executable/ExecutableTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,8 @@ public class ExecutableTest {
@Test
public void testInfoInsideAnonymousExecutable() throws Exception {
final Launcher launcher = new Launcher();
launcher.setArgs(new String[] {"--output-type", "nooutput" });
launcher.addInputResource("./src/test/java/spoon/test/executable/testclasses/AnonymousExecutableSample.java");
launcher.setSourceOutputDirectory("./target/trash");
launcher.run();

final List<CtAnonymousExecutable> anonymousExecutables = Query.getElements(launcher.getFactory(), new TypeFilter<CtAnonymousExecutable>(CtAnonymousExecutable.class));
Expand Down
6 changes: 3 additions & 3 deletions src/test/java/spoon/test/fieldaccesses/FieldAccessTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -292,10 +292,10 @@ public void testTypeDeclaredInAnonymousClass() throws Exception {
@Test
public void testFieldAccessDeclaredInADefaultClass() throws Exception {
final Launcher launcher = new Launcher();
launcher.setArgs(new String[] {"--output-type", "nooutput" });
launcher.addInputResource("./src/test/java/spoon/test/fieldaccesses/testclasses/Tacos.java");
launcher.addInputResource("./src/test/java/spoon/test/fieldaccesses/testclasses/internal/Foo.java");
launcher.addInputResource("./src/test/java/spoon/test/fieldaccesses/testclasses/internal/Bar.java");
launcher.setSourceOutputDirectory("./target/trash");
launcher.run();

final CtType<Object> aTacos = launcher.getFactory().Type().get(Tacos.class);
Expand Down Expand Up @@ -344,9 +344,9 @@ public void testTypeOfFieldAccess() throws Exception {
@Test
public void testFieldAccessWithoutAnyImport() throws Exception {
final Launcher launcher = new Launcher();
launcher.setArgs(new String[] {"--output-type", "nooutput" });
launcher.addInputResource("./src/test/java/spoon/test/fieldaccesses/testclasses/Kuu.java");
launcher.addInputResource("./src/test/java/spoon/test/fieldaccesses/testclasses/Mole.java");
launcher.setSourceOutputDirectory("./target/trash");
launcher.run();

final CtType<Kuu> aType = launcher.getFactory().Type().get(Kuu.class);
Expand Down Expand Up @@ -385,8 +385,8 @@ public <T> void visitCtFieldWrite(CtFieldWrite<T> fieldWrite) {
public void testGetReference() throws Exception {
final Launcher launcher = new Launcher();
launcher.getEnvironment().setShouldCompile(true);
launcher.setArgs(new String[] {"--output-type", "nooutput" });
launcher.addInputResource("./src/test/java/spoon/test/fieldaccesses/testclasses/");
launcher.setSourceOutputDirectory("./target/trash");
launcher.run();

final CtClass<B> aClass = launcher.getFactory().Class().get(B.class);
Expand Down
18 changes: 9 additions & 9 deletions src/test/java/spoon/test/filters/FilterTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -233,8 +233,8 @@ public void testOverridingMethodFromAbstractClass() throws Exception {
// contract: When we declare an abstract method on an abstract class, we must return all overriding
// methods in sub classes and anonymous classes.
final Launcher launcher = new Launcher();
launcher.setArgs(new String[] {"--output-type", "nooutput" });
launcher.addInputResource("./src/test/java/spoon/test/filters/testclasses");
launcher.setSourceOutputDirectory("./target/trash");
launcher.run();

final CtClass<AbstractTostada> aClass = launcher.getFactory().Class().get(AbstractTostada.class);
Expand All @@ -255,8 +255,8 @@ public void testOverridingMethodFromSubClassOfAbstractClass() throws Exception {
// contract: When we ask all overriding methods from an overriding method, we must returns all methods
// below and not above (including the declaration).
final Launcher launcher = new Launcher();
launcher.setArgs(new String[] {"--output-type", "nooutput" });
launcher.addInputResource("./src/test/java/spoon/test/filters/testclasses");
launcher.setSourceOutputDirectory("./target/trash");
launcher.run();

final CtClass<Tostada> aTostada = launcher.getFactory().Class().get(Tostada.class);
Expand All @@ -280,8 +280,8 @@ public void testOverridingMethodFromInterface() throws Exception {
// contract: When we declare a method in an interface, we must return all overriding
// methods in sub classes and anonymous classes.
final Launcher launcher = new Launcher();
launcher.setArgs(new String[] {"--output-type", "nooutput" });
launcher.addInputResource("./src/test/java/spoon/test/filters/testclasses");
launcher.setSourceOutputDirectory("./target/trash");
launcher.run();

final CtInterface<ITostada> aITostada = launcher.getFactory().Interface().get(ITostada.class);
Expand All @@ -302,8 +302,8 @@ public void testOverridingMethodFromSubClassOfInterface() throws Exception {
// contract: When we ask all overriding methods from an overriding method, we must returns all methods
// below and not above (including the declaration).
final Launcher launcher = new Launcher();
launcher.setArgs(new String[] {"--output-type", "nooutput" });
launcher.addInputResource("./src/test/java/spoon/test/filters/testclasses");
launcher.setSourceOutputDirectory("./target/trash");
launcher.run();

final CtClass<AbstractTostada> anAbstractTostada = launcher.getFactory().Class().get(AbstractTostada.class);
Expand All @@ -322,8 +322,8 @@ public void testOverriddenMethodFromAbstractClass() throws Exception {
// contract: When we declare an abstract method on an abstract class, we must return an empty list
// when we ask all overriden methods from this declaration.
final Launcher launcher = new Launcher();
launcher.setArgs(new String[] {"--output-type", "nooutput" });
launcher.addInputResource("./src/test/java/spoon/test/filters/testclasses");
launcher.setSourceOutputDirectory("./target/trash");
launcher.run();

final CtClass<AbstractTostada> aClass = launcher.getFactory().Class().get(AbstractTostada.class);
Expand All @@ -336,8 +336,8 @@ public void testOverriddenMethodsFromSubClassOfAbstractClass() throws Exception
// contract: When we ask all overridden methods from an overriding method, we must returns all methods
// above and not below.
final Launcher launcher = new Launcher();
launcher.setArgs(new String[] {"--output-type", "nooutput" });
launcher.addInputResource("./src/test/java/spoon/test/filters/testclasses");
launcher.setSourceOutputDirectory("./target/trash");
launcher.run();

final CtClass<Tostada> aTostada = launcher.getFactory().Class().get(Tostada.class);
Expand All @@ -358,8 +358,8 @@ public void testOverriddenMethodFromInterface() throws Exception {
// contract: When we declare a method in an interface, we must return an empty list
// when we ask all overridden methods from this declaration.
final Launcher launcher = new Launcher();
launcher.setArgs(new String[] {"--output-type", "nooutput" });
launcher.addInputResource("./src/test/java/spoon/test/filters/testclasses");
launcher.setSourceOutputDirectory("./target/trash");
launcher.run();

final CtInterface<ITostada> aITostada = launcher.getFactory().Interface().get(ITostada.class);
Expand All @@ -373,8 +373,8 @@ public void testOverriddenMethodFromSubClassOfInterface() throws Exception {
// contract: When we ask all overridden methods from an overriding method, we must returns all methods
// above and not below.
final Launcher launcher = new Launcher();
launcher.setArgs(new String[] {"--output-type", "nooutput" });
launcher.addInputResource("./src/test/java/spoon/test/filters/testclasses");
launcher.setSourceOutputDirectory("./target/trash");
launcher.run();

final CtClass<AbstractTostada> anAbstractTostada = launcher.getFactory().Class().get(AbstractTostada.class);
Expand All @@ -395,8 +395,8 @@ public void testInvocationFilterWithExecutableInLibrary() throws Exception {
// contract: When we have an invocation of an executable declared in a library,
// we can filter it and get the executable of the invocation.
final Launcher launcher = new Launcher();
launcher.setArgs(new String[] {"--output-type", "nooutput" });
launcher.addInputResource("./src/test/java/spoon/test/filters/testclasses");
launcher.setSourceOutputDirectory("./target/trash");
launcher.run();

final CtClass<Tacos> aTacos = launcher.getFactory().Class().get(Tacos.class);
Expand Down
Loading