Skip to content

Commit

Permalink
Also remove deprecated guava Files calls, other self review
Browse files Browse the repository at this point in the history
  • Loading branch information
niloc132 committed Jan 9, 2025
1 parent e0ef7b1 commit 3e49843
Show file tree
Hide file tree
Showing 3 changed files with 43 additions and 35 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -28,13 +28,13 @@
import com.google.gwt.thirdparty.guava.common.base.Charsets;
import com.google.gwt.thirdparty.guava.common.collect.ImmutableMap;
import com.google.gwt.thirdparty.guava.common.collect.Lists;
import com.google.gwt.thirdparty.guava.common.io.Files;

import junit.framework.TestCase;

import java.io.File;
import java.io.FilenameFilter;
import java.io.IOException;
import java.nio.file.Files;
import java.util.Arrays;
import java.util.Comparator;
import java.util.HashMap;
Expand Down Expand Up @@ -68,7 +68,7 @@ private static void writeResourcesTo(List<MockResource> resources, File dir) thr
File resourceFile =
new File(dir.getAbsolutePath() + File.separator + applicationResource.getPath());
resourceFile.getParentFile().mkdirs();
Files.write(applicationResource.getContent(), resourceFile, Charsets.UTF_8);
Files.write(resourceFile.toPath(), List.of(applicationResource.getContent()), Charsets.UTF_8);
}
}

Expand Down Expand Up @@ -163,7 +163,7 @@ public void testIncrementalRecompile_compileErrorDoesntCorruptMinimalRebuildCach
PrintWriterTreeLogger logger = new PrintWriterTreeLogger();
logger.setMaxDetail(TreeLogger.ERROR);

File sourcePath = Files.createTempDir();
File sourcePath = createTempDir();
// Setup options to perform a per-file compile and compile the given module.
Options options = new Options();
options.parseArgs(new String[] {
Expand All @@ -175,12 +175,12 @@ public void testIncrementalRecompile_compileErrorDoesntCorruptMinimalRebuildCach
fooResource);
writeResourcesTo(originalResources, sourcePath);

File baseCacheDir = Files.createTempDir();
File baseCacheDir = createTempDir();
UnitCache unitCache = UnitCacheSingleton.get(
logger, null, baseCacheDir, new CompilerOptionsImpl(options));
MinimalRebuildCacheManager minimalRebuildCacheManager =
new MinimalRebuildCacheManager(logger, baseCacheDir, ImmutableMap.<String, String>of());
Recompiler recompiler = new Recompiler(OutboxDir.create(Files.createTempDir(), logger), null,
Recompiler recompiler = new Recompiler(OutboxDir.create(createTempDir(), logger), null,
moduleName, options, unitCache, minimalRebuildCacheManager);
Outbox outbox = new Outbox("Transactional Cache", recompiler, options, logger);
OutboxTable outboxTable = new OutboxTable();
Expand Down Expand Up @@ -211,7 +211,7 @@ public void testIncrementalRecompile_modulePropertyEditsWork() throws UnableToCo
PrintWriterTreeLogger logger = new PrintWriterTreeLogger();
logger.setMaxDetail(TreeLogger.ERROR);

File sourcePath = Files.createTempDir();
File sourcePath = createTempDir();
// Setup options to perform a per-file compile and compile the given module.
Options options = new Options();
options.parseArgs(new String[] {
Expand All @@ -223,12 +223,12 @@ public void testIncrementalRecompile_modulePropertyEditsWork() throws UnableToCo
fooResource);
writeResourcesTo(originalResources, sourcePath);

File baseCacheDir = Files.createTempDir();
File baseCacheDir = createTempDir();
UnitCache unitCache = UnitCacheSingleton.get(
logger, null, baseCacheDir, new CompilerOptionsImpl(options));
MinimalRebuildCacheManager minimalRebuildCacheManager =
new MinimalRebuildCacheManager(logger, baseCacheDir, ImmutableMap.<String, String>of());
Recompiler recompiler = new Recompiler(OutboxDir.create(Files.createTempDir(), logger), null,
Recompiler recompiler = new Recompiler(OutboxDir.create(createTempDir(), logger), null,
moduleName, options, unitCache, minimalRebuildCacheManager);
Outbox outbox = new Outbox("Transactional Cache", recompiler, options, logger);
OutboxTable outboxTable = new OutboxTable();
Expand Down Expand Up @@ -276,4 +276,8 @@ private Result compileWithChanges(TreeLogger logger, JobRunner runner, Outbox ou
runner.submit(job);
return job.waitForResult();
}

private static File createTempDir() throws IOException {
return Files.createTempDirectory("RecompilerTest").toFile();
}
}
54 changes: 29 additions & 25 deletions dev/core/test/com/google/gwt/dev/CompilerTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -37,10 +37,10 @@
import com.google.gwt.thirdparty.guava.common.collect.ImmutableList;
import com.google.gwt.thirdparty.guava.common.collect.Lists;
import com.google.gwt.thirdparty.guava.common.collect.Sets;
import com.google.gwt.thirdparty.guava.common.io.Files;

import java.io.File;
import java.io.IOException;
import java.nio.file.Files;
import java.util.Arrays;
import java.util.HashSet;
import java.util.List;
Expand Down Expand Up @@ -976,7 +976,7 @@ public void testSourceLevelHighestVersion() {
*/
public void testGwtCreateJsTypeRebindResult() throws Exception {
CompilerOptions compilerOptions = new CompilerOptionsImpl();
compileToJs(compilerOptions, Files.createTempDir(), "com.foo.SimpleModule",
compileToJs(compilerOptions, createTempDir(), "com.foo.SimpleModule",
Lists.newArrayList(simpleModuleResource, gwtCreateEntryPointResource),
new MinimalRebuildCache(), emptySet, JsOutputOption.OBFUSCATED);
}
Expand Down Expand Up @@ -1032,7 +1032,7 @@ public void testReferenceThroughJsFunction() throws Exception {
"</module>");

CompilerOptions compilerOptions = new CompilerOptionsImpl();
String js = compileToJs(compilerOptions, Files.createTempDir(), testEntryPoint.getTypeName(),
String js = compileToJs(compilerOptions, createTempDir(), testEntryPoint.getTypeName(),
Lists.newArrayList(moduleResource, testEntryPoint, someJsFunction,
jsFunctionInterfaceImplementation, someInterface),
new MinimalRebuildCache(), emptySet, JsOutputOption.DETAILED);
Expand Down Expand Up @@ -1340,7 +1340,7 @@ public void testChangeJsIgnore() throws Exception {

public void testJsInteropNameCollision() throws Exception {
MinimalRebuildCache minimalRebuildCache = new MinimalRebuildCache();
File applicationDir = Files.createTempDir();
File applicationDir = Files.createTempDirectory("JsInteropNameCollision").toFile();
CompilerOptions compilerOptions = new CompilerOptionsImpl();
compilerOptions.setGenerateJsInteropExports(true);

Expand Down Expand Up @@ -1368,7 +1368,7 @@ Lists.<MockResource> newArrayList(complexDialogResourceWithExport), minimalRebui

public void testGwtCreateJsoRebindResult() throws Exception {
try {
compileToJs(Files.createTempDir(), "com.foo.SimpleModule",
compileToJs(createTempDir(), "com.foo.SimpleModule",
Lists.newArrayList(simpleModuleResource, brokenGwtCreateEntryPointResource),
new MinimalRebuildCache(), emptySet, JsOutputOption.OBFUSCATED);
fail("Compile should have failed");
Expand Down Expand Up @@ -1399,7 +1399,7 @@ public void testNonZeroArgConstructorEntryPoint() throws Exception {
"}");

MinimalRebuildCache minimalRebuildCache = new MinimalRebuildCache();
File applicationDir = Files.createTempDir();
File applicationDir = createTempDir();
CompilerOptions compilerOptions = new CompilerOptionsImpl();

UnitTestTreeLogger.Builder builder = new UnitTestTreeLogger.Builder();
Expand Down Expand Up @@ -1546,7 +1546,7 @@ public void testIncrementalRecompile_jsPropertyConsistencyCheck()
"</module>");

MinimalRebuildCache relinkMinimalRebuildCache = new MinimalRebuildCache();
File relinkApplicationDir = Files.createTempDir();
File relinkApplicationDir = createTempDir();

// Perform a first compile.
compileToJs(relinkApplicationDir, "com.foo.TestModule",
Expand All @@ -1565,7 +1565,7 @@ public void testIncrementalRecompile_jsPropertyConsistencyCheck()
public void testIncrementalRecompile_invalidatePreamble() throws UnableToCompleteException,
IOException, InterruptedException {
MinimalRebuildCache relinkMinimalRebuildCache = new MinimalRebuildCache();
File relinkApplicationDir = Files.createTempDir();
File relinkApplicationDir = createTempDir();

// Perform a first compile.
compileToJs(relinkApplicationDir, "com.foo.SimpleModule",
Expand Down Expand Up @@ -1593,7 +1593,7 @@ Lists.<MockResource> newArrayList(emptyEntryPointResource), relinkMinimalRebuild
public void testIncrementalRecompile_bridgeMethodOverrideChain()
throws UnableToCompleteException, IOException, InterruptedException {
MinimalRebuildCache relinkMinimalRebuildCache = new MinimalRebuildCache();
File relinkApplicationDir = Files.createTempDir();
File relinkApplicationDir = createTempDir();

// Perform a first compile.
compileToJs(relinkApplicationDir, "com.foo.SimpleModule", Lists.newArrayList(
Expand Down Expand Up @@ -1699,7 +1699,7 @@ public void testIncrementalRecompile_withErrors()
"}");

MinimalRebuildCache minimalRebuildCache = new MinimalRebuildCache();
File applicationDir = Files.createTempDir();
File applicationDir = createTempDir();
CompilerOptions compilerOptions = new CompilerOptionsImpl();
compilerOptions.setUseDetailedTypeIds(true);
compilerOptions.setSourceLevel(SourceLevel.JAVA11);
Expand Down Expand Up @@ -1762,7 +1762,7 @@ public void testIncrementalRecompile_representedAsNative()
logger.setMaxDetail(TreeLogger.ERROR);

MinimalRebuildCache minimalRebuildCache = new MinimalRebuildCache();
File applicationDir = Files.createTempDir();
File applicationDir = createTempDir();
CompilerOptions compilerOptions = new CompilerOptionsImpl();
compilerOptions.setUseDetailedTypeIds(true);
compilerOptions.setSourceLevel(SourceLevel.JAVA11);
Expand Down Expand Up @@ -1920,7 +1920,7 @@ public void testIncrementalRecompile_invalidatedGeneratorOutputRerunsGenerator()

// Compile the app with original files, modify a file and do a per-file recompile.
MinimalRebuildCache relinkMinimalRebuildCache = new MinimalRebuildCache();
File relinkApplicationDir = Files.createTempDir();
File relinkApplicationDir = createTempDir();
compileToJs(compilerOptions, relinkApplicationDir, "com.foo.SimpleModule", originalResources,
relinkMinimalRebuildCache, emptySet, output);

Expand Down Expand Up @@ -1960,7 +1960,7 @@ public void testIncrementalRecompile_invalidatedGeneratorOutputRerunsCascadedGen

// Compile the app with original files.
MinimalRebuildCache relinkMinimalRebuildCache = new MinimalRebuildCache();
File relinkApplicationDir = Files.createTempDir();
File relinkApplicationDir = createTempDir();
compileToJs(compilerOptions, relinkApplicationDir, "com.foo.SimpleModule", originalResources,
relinkMinimalRebuildCache, emptySet, output);

Expand Down Expand Up @@ -2009,7 +2009,7 @@ public void testIncrementalRecompile_carriesOverGeneratorArtifacts()

// Compile the app with original files.
MinimalRebuildCache relinkMinimalRebuildCache = new MinimalRebuildCache();
File relinkApplicationDir = Files.createTempDir();
File relinkApplicationDir = createTempDir();
compileToJs(compilerOptions, relinkApplicationDir, "com.foo.SimpleModule", originalResources,
relinkMinimalRebuildCache, emptySet, output);

Expand Down Expand Up @@ -2046,15 +2046,15 @@ public void testIncrementalRecompile_unifyASTAssertionRegression()

// Compile the app with original files.
MinimalRebuildCache relinkMinimalRebuildCache = new MinimalRebuildCache();
File relinkApplicationDir = Files.createTempDir();
File relinkApplicationDir = createTempDir();
compileToJs(compilerOptions, relinkApplicationDir, "com.foo.Hello",
originalResources, relinkMinimalRebuildCache, emptySet, output);
}

private void checkIncrementalRecompile_noop(JsOutputOption output) throws UnableToCompleteException,
IOException, InterruptedException {
MinimalRebuildCache relinkMinimalRebuildCache = new MinimalRebuildCache();
File relinkApplicationDir = Files.createTempDir();
File relinkApplicationDir = createTempDir();

String originalJs = compileToJs(relinkApplicationDir, "com.foo.SimpleModule", Lists
.newArrayList(simpleModuleResource, simpleModelEntryPointResource, simpleModelResource,
Expand Down Expand Up @@ -2233,7 +2233,7 @@ public void checkIncrementalRecompile_primitiveClassLiteralReference(JsOutputOpt
private void checkIncrementalRecompile_dateStampChange(JsOutputOption output)
throws UnableToCompleteException, IOException, InterruptedException {
MinimalRebuildCache relinkMinimalRebuildCache = new MinimalRebuildCache();
File relinkApplicationDir = Files.createTempDir();
File relinkApplicationDir = createTempDir();

String originalJs = compileToJs(relinkApplicationDir, "com.foo.SimpleModule",
Lists.newArrayList(simpleModuleResource, simpleModelEntryPointResource, simpleModelResource,
Expand Down Expand Up @@ -2490,7 +2490,7 @@ private void checkIncrementalRecompile_generatorInputResourceChange(JsOutputOpti

private void assertCompileSucceeds(CompilerOptions options, String moduleName,
List<MockResource> applicationResources) throws Exception {
File compileWorkDir = java.nio.file.Files.createTempDirectory(moduleName).toFile();
File compileWorkDir = Files.createTempDirectory(moduleName).toFile();
final CompilerOptionsImpl compilerOptions = new CompilerOptionsImpl(options);
PrintWriterTreeLogger logger = new PrintWriterTreeLogger();
logger.setMaxDetail(TreeLogger.ERROR);
Expand All @@ -2499,7 +2499,7 @@ private void assertCompileSucceeds(CompilerOptions options, String moduleName,
System.setProperty(UnitCacheSingleton.GWT_PERSISTENTUNITCACHE, "false");
try {

File applicationDir = Files.createTempDir();
File applicationDir = createTempDir();
Thread.sleep(1001);
// We might be reusing the same application dir but we want to make sure that the output dir
// is clean to avoid confusion when returning the output JS.
Expand Down Expand Up @@ -2552,8 +2552,8 @@ private void assertDeterministicBuild(String topLevelModule, int optimizationLev
final CompilerOptionsImpl options = new CompilerOptionsImpl();
options.setOptimizationLevel(optimizationLevel);

File firstCompileWorkDir = java.nio.file.Files.createTempDirectory("hellowork").toFile();
File secondCompileWorkDir = java.nio.file.Files.createTempDirectory("hellowork").toFile();
File firstCompileWorkDir = Files.createTempDirectory("hellowork").toFile();
File secondCompileWorkDir = Files.createTempDirectory("hellowork").toFile();
String oldPersistentUnitCacheValue =
System.setProperty(UnitCacheSingleton.GWT_PERSISTENTUNITCACHE, "false");
try {
Expand Down Expand Up @@ -2630,7 +2630,7 @@ private void checkRecompiledModifiedApp(

// Compile the app with original files, modify a file and do a per-file recompile.
MinimalRebuildCache relinkMinimalRebuildCache = new MinimalRebuildCache();
File relinkApplicationDir = Files.createTempDir();
File relinkApplicationDir = createTempDir();
String originalAppFromScratchJs = compileToJs(compilerOptions, relinkApplicationDir, moduleName,
originalResources, relinkMinimalRebuildCache, emptySet, output);
String modifiedAppRelinkedJs = compileToJs(compilerOptions, relinkApplicationDir, moduleName,
Expand All @@ -2639,7 +2639,7 @@ Lists.<MockResource> newArrayList(modifiedResource), relinkMinimalRebuildCache,

// Compile the app from scratch with the modified file.
MinimalRebuildCache fromScratchMinimalRebuildCache = new MinimalRebuildCache();
File fromScratchApplicationDir = Files.createTempDir();
File fromScratchApplicationDir = createTempDir();
String modifiedAppFromScratchJs = compileToJs(compilerOptions, fromScratchApplicationDir,
moduleName, modifiedResources, fromScratchMinimalRebuildCache, emptySet, output);

Expand Down Expand Up @@ -2737,7 +2737,11 @@ private String compileToJs(TreeLogger logger, CompilerOptions compilerOptions, F
if (expectedProcessedStaleTypeNames != null) {
assertEquals(expectedProcessedStaleTypeNames, getStaleTypeNames(minimalRebuildCache));
}
return Files.toString(outputJsFile, Charsets.UTF_8);
return Files.readString(outputJsFile.toPath(), Charsets.UTF_8);
}

private static File createTempDir() throws IOException {
return Files.createTempDirectory("CompilerTest").toFile();
}

private Set<String> getStaleTypeNames(MinimalRebuildCache relinkMinimalRebuildCache) {
Expand Down Expand Up @@ -2793,6 +2797,6 @@ private void writeResourceTo(MockResource mockResource, File applicationDir) thr
File resourceFile =
new File(applicationDir.getAbsolutePath() + File.separator + mockResource.getPath());
resourceFile.getParentFile().mkdirs();
Files.write(mockResource.getContent(), resourceFile, Charsets.UTF_8);
Files.write(resourceFile.toPath(), List.of(mockResource.getContent()), Charsets.UTF_8);
}
}
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright 2024 GWT Project Authors
* Copyright 2025 GWT Project Authors
*
* Licensed under the Apache License, Version 2.0 (the "License"); you may not
* use this file except in compliance with the License. You may obtain a copy of
Expand Down Expand Up @@ -39,4 +39,4 @@ public void testVersionNumberComparisons() {
} catch (IllegalArgumentException e) {
}
}
}
}

0 comments on commit 3e49843

Please sign in to comment.