diff --git a/dev/codeserver/javatests/com/google/gwt/dev/codeserver/RecompilerTest.java b/dev/codeserver/javatests/com/google/gwt/dev/codeserver/RecompilerTest.java index 03abc05fd71..33a8830c5d2 100644 --- a/dev/codeserver/javatests/com/google/gwt/dev/codeserver/RecompilerTest.java +++ b/dev/codeserver/javatests/com/google/gwt/dev/codeserver/RecompilerTest.java @@ -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; @@ -68,7 +68,7 @@ private static void writeResourcesTo(List 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); } } @@ -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[] { @@ -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.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(); @@ -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[] { @@ -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.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(); @@ -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(); + } } diff --git a/dev/core/test/com/google/gwt/dev/CompilerTest.java b/dev/core/test/com/google/gwt/dev/CompilerTest.java index 57e32447d9a..1161e3aac0a 100644 --- a/dev/core/test/com/google/gwt/dev/CompilerTest.java +++ b/dev/core/test/com/google/gwt/dev/CompilerTest.java @@ -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; @@ -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); } @@ -1032,7 +1032,7 @@ public void testReferenceThroughJsFunction() throws Exception { ""); 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); @@ -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); @@ -1368,7 +1368,7 @@ Lists. 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"); @@ -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(); @@ -1546,7 +1546,7 @@ public void testIncrementalRecompile_jsPropertyConsistencyCheck() ""); MinimalRebuildCache relinkMinimalRebuildCache = new MinimalRebuildCache(); - File relinkApplicationDir = Files.createTempDir(); + File relinkApplicationDir = createTempDir(); // Perform a first compile. compileToJs(relinkApplicationDir, "com.foo.TestModule", @@ -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", @@ -1593,7 +1593,7 @@ Lists. 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( @@ -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); @@ -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); @@ -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); @@ -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); @@ -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); @@ -2046,7 +2046,7 @@ 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); } @@ -2054,7 +2054,7 @@ public void testIncrementalRecompile_unifyASTAssertionRegression() 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, @@ -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, @@ -2490,7 +2490,7 @@ private void checkIncrementalRecompile_generatorInputResourceChange(JsOutputOpti private void assertCompileSucceeds(CompilerOptions options, String moduleName, List 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); @@ -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. @@ -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 { @@ -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, @@ -2639,7 +2639,7 @@ Lists. 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); @@ -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 getStaleTypeNames(MinimalRebuildCache relinkMinimalRebuildCache) { @@ -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); } } diff --git a/dev/core/test/com/google/gwt/dev/util/arg/SourceLevelTest.java b/dev/core/test/com/google/gwt/dev/util/arg/SourceLevelTest.java index d13c62ddd73..5c95e4eddc4 100644 --- a/dev/core/test/com/google/gwt/dev/util/arg/SourceLevelTest.java +++ b/dev/core/test/com/google/gwt/dev/util/arg/SourceLevelTest.java @@ -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 @@ -39,4 +39,4 @@ public void testVersionNumberComparisons() { } catch (IllegalArgumentException e) { } } -} \ No newline at end of file +}