Skip to content

Commit

Permalink
Merge branch 'main' into 10090-hash-test
Browse files Browse the repository at this point in the history
  • Loading branch information
niloc132 committed Feb 26, 2025
2 parents ce8db41 + 32a0771 commit 30abfda
Show file tree
Hide file tree
Showing 75 changed files with 1,424 additions and 2,099 deletions.
40 changes: 3 additions & 37 deletions build_tools/doctool/src/com/google/doctool/ResourceIncluder.java
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@
*/
package com.google.doctool;

import java.io.ByteArrayOutputStream;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.io.InputStream;
Expand All @@ -26,18 +25,6 @@
*/
public class ResourceIncluder {

/**
* Copied from {@link com.google.gwt.util.tools.Utility#close(AutoCloseable)}.
*/
public static void close(AutoCloseable is) {
try {
if (is != null) {
is.close();
}
} catch (Exception e) {
}
}

public static String getResourceFromClasspathScrubbedForHTML(String partialPath)
throws IOException {
String contents;
Expand All @@ -46,35 +33,14 @@ public static String getResourceFromClasspathScrubbedForHTML(String partialPath)
return contents;
}

/**
* Copied from
* {@link com.google.gwt.util.tools.Utility#getFileFromClassPath(String)}.
*/
private static String getFileFromClassPath(String partialPath)
throws IOException {
InputStream in = ResourceIncluder.class.getClassLoader().getResourceAsStream(
partialPath);
try {
try (InputStream in = ResourceIncluder.class.getClassLoader().getResourceAsStream(
partialPath)) {
if (in == null) {
throw new FileNotFoundException(partialPath);
}
ByteArrayOutputStream os = new ByteArrayOutputStream();
byte[] buffer = new byte[1024];
int bytesRead;
while (true) {
bytesRead = in.read(buffer);
if (bytesRead >= 0) {
// Copy the bytes out.
os.write(buffer, 0, bytesRead);
} else {
// End of input stream.
break;
}
}

return os.toString(StandardCharsets.UTF_8);
} finally {
close(in);
return new String(in.readAllBytes(), StandardCharsets.UTF_8);
}
}

Expand Down
23 changes: 10 additions & 13 deletions dev/build.xml
Original file line number Diff line number Diff line change
Expand Up @@ -63,16 +63,15 @@
<include name="apache/tapestry-util-text-4.0.2.jar"/>
<include name="apache/ant-zipscanner/ant-zipscanner-1.6.5-1-rebased.jar"/>
<include name="colt/colt-1.2.jar"/>
<include name="eclipse/org.eclipse.jdt.core_3.32.0.v20221108-1853.jar"/>
<include name="eclipse/jdtCompilerAdapter_3.32.0.v20221108-1853.jar"/>
<include name="eclipse/3.33.0/*.jar"/>
<include name="objectweb/asm-9.6/asm-9.6.jar"/>
<include name="objectweb/asm-9.6/asm-commons-9.6.jar"/>
<include name="objectweb/asm-9.6/asm-util-9.6.jar"/>
<include name="guava/guava-33.0/guava-33.0.0-jre-rebased.jar"/>
<include name="guava/guava-33.0/failureaccess-1.0.2-rebased.jar"/>
<include name="icu4j/63.1/icu4j.jar"/>
<include name="jetty/jetty-9.4.44.v20210927/jetty-all-9.4.44.v20210927.jar"/>
<include name="gson/gson-2.6.2.jar"/>
<include name="gson/gson-2.11.0.jar"/>
<include name="jscomp/20231112/sourcemap-rebased.jar"/>
<include name="jsr305/jsr305.jar"/>
<include name="protobuf/protobuf-2.5.0/protobuf-java-rebased-2.5.0.jar"/>
Expand Down Expand Up @@ -126,10 +125,9 @@
<zipfileset src="${gwt.tools.lib}/apache/tapestry-util-text-4.0.2.jar"/>
<zipfileset src="${gwt.tools.lib}/apache/ant-zipscanner/ant-zipscanner-1.6.5-1-rebased.jar"/>
<zipfileset src="${gwt.tools.lib}/colt/colt-1.2.jar"/>
<zipfileset
src="${gwt.tools.lib}/eclipse/org.eclipse.jdt.core_3.32.0.v20221108-1853.jar"/>
<zipfileset
src="${gwt.tools.lib}/eclipse/jdtCompilerAdapter_3.32.0.v20221108-1853.jar"/>
<zipgroupfileset dir="${gwt.tools.lib}/eclipse/3.33.0">
<include name="**/*.jar"/>
</zipgroupfileset>
<zipfileset src="${gwt.tools.lib}/guava/guava-33.0/guava-33.0.0-jre-rebased.jar"/>
<zipfileset src="${gwt.tools.lib}/guava/guava-33.0/failureaccess-1.0.2-rebased.jar" />
<zipfileset src="${gwt.tools.lib}/icu4j/63.1/icu4j.jar"/>
Expand All @@ -141,7 +139,7 @@
-->
<exclude name="META-INF/services/org.eclipse.jetty.security.Authenticator$Factory"/>
</zipfileset>
<zipfileset src="${gwt.tools.lib}/gson/gson-2.6.2.jar"/>
<zipfileset src="${gwt.tools.lib}/gson/gson-2.11.0.jar"/>
<zipfileset src="${gwt.tools.lib}/jscomp/20231112/sourcemap-rebased.jar"/>
<zipfileset src="${gwt.tools.lib}/jsr305/jsr305.jar"/>
<zipfileset
Expand Down Expand Up @@ -224,15 +222,14 @@
<pathelement location="${gwt.tools.lib}/objectweb/asm-9.6/asm-util-9.6.jar"/>
<pathelement
location="${gwt.tools.lib}/apache/commons/commons-collections-3.2.2.jar"/>
<pathelement
location="${gwt.tools.lib}/eclipse/org.eclipse.jdt.core_3.32.0.v20221108-1853.jar"/>
<pathelement
location="${gwt.tools.lib}/eclipse/jdtCompilerAdapter_3.32.0.v20221108-1853.jar"/>
<fileset dir="${gwt.tools.lib}/eclipse/3.33.0">
<include name="**/*.jar"/>
</fileset>
<pathelement
location="${gwt.tools.lib}/guava/guava-33.0/guava-33.0.0-jre-rebased.jar"/>
<pathelement
location="${gwt.tools.lib}/guava/guava-33.0/failureaccess-1.0.2-rebased.jar"/>
<pathelement location="${gwt.tools.lib}/gson/gson-2.6.2.jar"/>
<pathelement location="${gwt.tools.lib}/gson/gson-2.11.0.jar"/>
<pathelement location="${gwt.tools.lib}/jscomp/20231112/sourcemap-rebased.jar"/>
<pathelement location="${gwt.tools.lib}/json/android-sdk-19.1/json-android-rebased.jar"/>
<pathelement location="${gwt.tools.lib}/jsr305/jsr305.jar"/>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,10 +25,10 @@
import com.google.gwt.dev.util.DiskCachingUtil;
import com.google.gwt.dev.util.log.PrintWriterTreeLogger;
import com.google.gwt.thirdparty.guava.common.collect.ImmutableMap;
import com.google.gwt.util.tools.Utility;

import java.io.File;
import java.io.IOException;
import java.nio.file.Files;

/**
* <p>This class contains the {@link #main main method} that starts the code server for
Expand Down Expand Up @@ -201,7 +201,7 @@ private static OutboxTable makeOutboxTable(Options options, TreeLogger logger,
private static File ensureWorkDir(Options options) throws IOException {
File workDir = options.getWorkDir();
if (workDir == null) {
workDir = Utility.makeTemporaryDirectory(null, "gwt-codeserver-");
workDir = Files.createTempDirectory("gwt-codeserver-").toFile();
} else {
if (!workDir.isDirectory()) {
throw new IOException("workspace directory doesn't exist: " + workDir);
Expand Down
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();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
import com.google.gwt.core.ext.TreeLogger;
import com.google.gwt.core.ext.UnableToCompleteException;
import com.google.gwt.dev.util.Util;
import com.google.gwt.util.tools.Utility;
import com.google.gwt.thirdparty.guava.common.io.Closeables;

import java.io.BufferedInputStream;
import java.io.IOException;
Expand Down Expand Up @@ -204,7 +204,7 @@ public void writeTo(TreeLogger logger, OutputStream out)
logger.log(TreeLogger.ERROR, "Unable to copy artifact: " + getPartialPath(), e);
throw new UnableToCompleteException();
} finally {
Utility.close(in);
Closeables.closeQuietly(in);
}
}

Expand Down
48 changes: 48 additions & 0 deletions dev/core/src/com/google/gwt/core/ext/linker/LinkerUtils.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
/*
* 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
* the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
* License for the specific language governing permissions and limitations under
* the License.
*/
package com.google.gwt.core.ext.linker;

import java.io.FileNotFoundException;
import java.io.IOException;
import java.io.InputStream;
import java.nio.charset.StandardCharsets;

/**
* Utility methods for Linkers.
*/
public class LinkerUtils {
/**
* Gets the contents of a file from the class path as a String. Note: this
* method is only guaranteed to work for resources in the same class loader
* that contains this {@link LinkerUtils} class.
*
* @param path the partial path to the resource on the class path
* @return the contents of the file
* @throws IOException if the file could not be found or an error occurred
* while reading it
*/
public static String readClasspathFileAsString(String path) throws IOException {
try (InputStream in = LinkerUtils.class.getClassLoader().getResourceAsStream(path)) {
if (in == null) {
throw new FileNotFoundException(path);
}
return new String(in.readAllBytes(), StandardCharsets.UTF_8);
}
}

private LinkerUtils() {
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,8 @@
import com.google.gwt.core.ext.TreeLogger;
import com.google.gwt.core.ext.UnableToCompleteException;
import com.google.gwt.core.ext.linker.ArtifactSet;
import com.google.gwt.core.ext.linker.LinkerUtils;
import com.google.gwt.core.ext.linker.Shardable;
import com.google.gwt.util.tools.Utility;

import java.io.IOException;

Expand All @@ -32,7 +32,7 @@
public final class HostedModeLinker extends SelectionScriptLinker {

public static String getHostedHtml() throws IOException {
return Utility.getFileFromClassPath("com/google/gwt/core/ext/linker/impl/hosted.html");
return LinkerUtils.readClasspathFileAsString("com/google/gwt/core/ext/linker/impl/hosted.html");
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,12 +25,12 @@
import com.google.gwt.core.ext.linker.CompilationResult;
import com.google.gwt.core.ext.linker.ConfigurationProperty;
import com.google.gwt.core.ext.linker.EmittedArtifact;
import com.google.gwt.core.ext.linker.LinkerUtils;
import com.google.gwt.core.ext.linker.SelectionProperty;
import com.google.gwt.core.ext.linker.SoftPermutation;
import com.google.gwt.core.ext.linker.StatementRanges;
import com.google.gwt.core.linker.SymbolMapsLinker;
import com.google.gwt.dev.util.Util;
import com.google.gwt.util.tools.Utility;

import java.io.File;
import java.io.IOException;
Expand Down Expand Up @@ -323,8 +323,8 @@ protected String fillSelectionScriptTemplate(StringBuffer selectionScript,
String computeScriptBase;
String processMetas;
try {
computeScriptBase = Utility.getFileFromClassPath(COMPUTE_SCRIPT_BASE_JS);
processMetas = Utility.getFileFromClassPath(PROCESS_METAS_JS);
computeScriptBase = LinkerUtils.readClasspathFileAsString(COMPUTE_SCRIPT_BASE_JS);
processMetas = LinkerUtils.readClasspathFileAsString(PROCESS_METAS_JS);
} catch (IOException e) {
logger.log(TreeLogger.ERROR, "Unable to read selection script template",
e);
Expand Down Expand Up @@ -566,7 +566,7 @@ protected StringBuffer readFileToStringBuffer(String filename,
TreeLogger logger) throws UnableToCompleteException {
StringBuffer buffer;
try {
buffer = new StringBuffer(Utility.getFileFromClassPath(filename));
buffer = new StringBuffer(LinkerUtils.readClasspathFileAsString(filename));
} catch (IOException e) {
logger.log(TreeLogger.ERROR, "Unable to read file: " + filename, e);
throw new UnableToCompleteException();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,6 @@
import com.google.gwt.dev.resource.ResourceOracle;
import com.google.gwt.dev.util.DefaultTextOutput;
import com.google.gwt.dev.util.OutputFileSet;
import com.google.gwt.util.tools.Utility;

import java.io.BufferedOutputStream;
import java.io.File;
Expand Down Expand Up @@ -521,10 +520,8 @@ public void produceOutput(TreeLogger logger, ArtifactSet artifacts,
partialPath = partialPath.substring(1);
}
}
OutputStream artifactStream = null;
try {
artifactStream = new BufferedOutputStream(out.openForWrite(partialPath,
artifact.getLastModified()));
try (OutputStream artifactStream = new BufferedOutputStream(
out.openForWrite(partialPath, artifact.getLastModified()))) {
artifact.writeTo(artifactLogger, artifactStream);
} catch (IOException e) {
artifactLogger.log(TreeLogger.ERROR,
Expand All @@ -533,8 +530,6 @@ public void produceOutput(TreeLogger logger, ArtifactSet artifacts,
if (visibility != Visibility.Private) {
throw new UnableToCompleteException();
}
} finally {
Utility.close(artifactStream);
}
}
}
Expand Down
Loading

0 comments on commit 30abfda

Please sign in to comment.