Skip to content
Closed
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 .github/workflows/full-check.yml
Original file line number Diff line number Diff line change
Expand Up @@ -25,11 +25,11 @@ jobs:
java-version: [ '11', '17', '21', '22' ]
steps:
- name: Checkout GWT itself into one directory
uses: actions/checkout@v4
uses: actions/checkout@v5
with:
path: 'gwt'
- name: Checkout GWT tools into a sibling directory
uses: actions/checkout@v4
uses: actions/checkout@v5
with:
repository: 'gwtproject/tools'
path: 'tools'
Expand Down
4 changes: 2 additions & 2 deletions .github/workflows/quick-check.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,13 +12,13 @@ jobs:
java-version: ['11', '17', '21', '22']
steps:
- name: Checkout GWT itself into one directory
uses: actions/checkout@v4
uses: actions/checkout@v5
with:
path: 'gwt'
# we need depth=2 to see which style violations overlap with the current changes
fetch-depth: 2
- name: Checkout GWT tools into a sibling directory
uses: actions/checkout@v4
uses: actions/checkout@v5
with:
repository: 'gwtproject/tools'
path: 'tools'
Expand Down
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.TreeLogger.Type;
import com.google.gwt.core.ext.UnableToCompleteException;
import com.google.gwt.dev.util.Util;
import com.google.gwt.thirdparty.guava.common.io.MoreFiles;

import java.io.File;
import java.io.IOException;
Expand Down Expand Up @@ -87,7 +87,7 @@ static OutboxDir create(File dir, TreeLogger logger) throws IOException {
// (This is not guaranteed to delete all directories on Windows if a directory is locked.)
for (File candidate : children) {
if (candidate.getName().startsWith(COMPILE_DIR_PREFIX)) {
Util.recursiveDelete(candidate, false);
MoreFiles.deleteRecursively(candidate.toPath());
if (candidate.exists()) {
logger.log(Type.WARN, "unable to delete '" + candidate + "' (skipped)");
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,11 +17,13 @@
package com.google.gwt.dev.codeserver;

import com.google.gwt.core.ext.TreeLogger;
import com.google.gwt.dev.util.Util;
import com.google.gwt.thirdparty.debugging.sourcemap.SourceMapConsumerV3;
import com.google.gwt.thirdparty.debugging.sourcemap.SourceMapParseException;

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

/**
* A mapping from Java lines to JavaScript.
Expand All @@ -39,10 +41,13 @@ private ReverseSourceMap(SourceMapConsumerV3 consumer) {
*/
static ReverseSourceMap load(TreeLogger logger, File sourceMapFile) {
SourceMapConsumerV3 consumer = new SourceMapConsumerV3();
String unparsed = Util.readFileAsString(sourceMapFile);
try {
String unparsed = Files.readString(sourceMapFile.toPath(), StandardCharsets.UTF_8);
consumer.parse(unparsed);
return new ReverseSourceMap(consumer);
} catch (IOException ex) {
logger.log(TreeLogger.Type.WARN, "can't read source map", ex);
return new ReverseSourceMap(null);
} catch (SourceMapParseException e) {
logger.log(TreeLogger.WARN, "can't parse source map", e);
return new ReverseSourceMap(null);
Expand Down
11 changes: 5 additions & 6 deletions dev/codeserver/java/com/google/gwt/dev/codeserver/SourceMap.java
Original file line number Diff line number Diff line change
Expand Up @@ -19,11 +19,12 @@
import com.google.gwt.dev.json.JsonArray;
import com.google.gwt.dev.json.JsonException;
import com.google.gwt.dev.json.JsonObject;
import com.google.gwt.dev.util.Util;

import java.io.File;
import java.io.IOException;
import java.io.StringReader;
import java.nio.charset.StandardCharsets;
import java.nio.file.Files;
import java.util.ArrayList;
import java.util.Collections;
import java.util.HashSet;
Expand All @@ -37,21 +38,19 @@ class SourceMap {
private final JsonObject json;

/**
*@see #load
* @see #load
*/
private SourceMap(JsonObject json) {
this.json = json;
}

static SourceMap load(File file) {
String sourceMapJson = Util.readFileAsString(file);

JsonObject json;
try {
String sourceMapJson = Files.readString(file.toPath(), StandardCharsets.UTF_8);
json = JsonObject.parse(new StringReader(sourceMapJson));
} catch (JsonException e) {
throw new RuntimeException("can't parse sourcemap as json", e);
} catch (IOException e) {
} catch (JsonException | IOException e) {
throw new RuntimeException("can't parse sourcemap as json", e);
}

Expand Down
26 changes: 16 additions & 10 deletions dev/core/src/com/google/gwt/core/ext/linker/AbstractLinker.java
Original file line number Diff line number Diff line change
Expand Up @@ -18,11 +18,11 @@
import com.google.gwt.core.ext.Linker;
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.thirdparty.guava.common.hash.Hashing;

import java.io.ByteArrayOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.nio.charset.StandardCharsets;
import java.util.Locale;

/**
Expand Down Expand Up @@ -69,9 +69,12 @@ protected final SyntheticArtifact emitBytes(TreeLogger logger, byte[] what,
*/
protected final SyntheticArtifact emitInputStream(TreeLogger logger,
InputStream what, String partialPath) throws UnableToCompleteException {
ByteArrayOutputStream out = new ByteArrayOutputStream();
Util.copy(logger, what, out);
return emitBytes(logger, out.toByteArray(), partialPath);
try (what) {
return emitBytes(logger, what.readAllBytes(), partialPath);
} catch (IOException e) {
logger.log(TreeLogger.ERROR, "Error during copy", e);
throw new UnableToCompleteException();
}
}

/**
Expand All @@ -87,9 +90,12 @@ protected final SyntheticArtifact emitInputStream(TreeLogger logger,
protected final SyntheticArtifact emitInputStream(TreeLogger logger,
InputStream what, String partialPath, long lastModified)
throws UnableToCompleteException {
ByteArrayOutputStream out = new ByteArrayOutputStream();
Util.copy(logger, what, out);
return emitBytes(logger, out.toByteArray(), partialPath, lastModified);
try (what) {
return emitBytes(logger, what.readAllBytes(), partialPath, lastModified);
} catch (IOException e) {
logger.log(TreeLogger.ERROR, "Error during copy", e);
throw new UnableToCompleteException();
}
}

/**
Expand All @@ -102,7 +108,7 @@ protected final SyntheticArtifact emitInputStream(TreeLogger logger,
*/
protected final SyntheticArtifact emitString(TreeLogger logger, String what,
String partialPath) throws UnableToCompleteException {
return emitBytes(logger, Util.getBytes(what), partialPath);
return emitBytes(logger, what.getBytes(StandardCharsets.UTF_8), partialPath);
}

/**
Expand All @@ -116,7 +122,7 @@ protected final SyntheticArtifact emitString(TreeLogger logger, String what,
*/
protected final SyntheticArtifact emitString(TreeLogger logger, String what,
String partialPath, long lastModified) throws UnableToCompleteException {
return emitBytes(logger, Util.getBytes(what), partialPath, lastModified);
return emitBytes(logger, what.getBytes(StandardCharsets.UTF_8), partialPath, lastModified);
}

/**
Expand Down
10 changes: 2 additions & 8 deletions dev/core/src/com/google/gwt/core/ext/linker/EmittedArtifact.java
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,6 @@
import com.google.gwt.core.ext.Linker;
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.thirdparty.guava.common.io.Closeables;

import java.io.BufferedInputStream;
import java.io.IOException;
Expand Down Expand Up @@ -196,15 +194,11 @@ public String toString() {
*/
public void writeTo(TreeLogger logger, OutputStream out)
throws UnableToCompleteException {
InputStream in = null;
try {
in = new BufferedInputStream(getContents(logger));
Util.copyNoClose(in, out);
try (InputStream in = new BufferedInputStream(getContents(logger))) {
in.transferTo(out);
} catch (IOException e) {
logger.log(TreeLogger.ERROR, "Unable to copy artifact: " + getPartialPath(), e);
throw new UnableToCompleteException();
} finally {
Closeables.closeQuietly(in);
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,13 +30,13 @@
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 java.io.File;
import java.io.IOException;
import java.io.InputStream;
import java.net.URL;
import java.net.URLConnection;
import java.nio.charset.StandardCharsets;
import java.util.ArrayList;
import java.util.Collection;
import java.util.List;
Expand Down Expand Up @@ -257,8 +257,9 @@ protected Collection<Artifact<?>> doEmitCompilation(TreeLogger logger,
primary = null;

for (int i = 1; i < js.length; i++) {
byte[] bytes = Util.getBytes(generateDeferredFragment(logger, context, i, js[i], artifacts,
result));
String s = generateDeferredFragment(logger, context, i, js[i], artifacts,
result);
byte[] bytes = s.getBytes(StandardCharsets.UTF_8);
toReturn.add(emitBytes(logger, bytes, FRAGMENT_SUBDIR + File.separator
+ result.getStrongName() + File.separator + i + FRAGMENT_EXTENSION));
}
Expand Down Expand Up @@ -384,7 +385,7 @@ protected byte[] generatePrimaryFragment(TreeLogger logger,
charsPerChunk(context, logger), getScriptChunkSeparator(logger, context), context);
String primaryFragmentString =
generatePrimaryFragmentString(logger, context, result, temp, js.length, artifacts);
return Util.getBytes(primaryFragmentString);
return primaryFragmentString.getBytes(StandardCharsets.UTF_8);
}

protected String generatePrimaryFragmentString(TreeLogger logger,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,10 +22,10 @@
import com.google.gwt.core.ext.linker.SymbolData;
import com.google.gwt.dev.jjs.PermutationResult;
import com.google.gwt.dev.util.DiskCache;
import com.google.gwt.dev.util.Util;
import com.google.gwt.dev.util.collect.Lists;

import java.io.Serializable;
import java.nio.charset.StandardCharsets;
import java.util.Collections;
import java.util.Comparator;
import java.util.Iterator;
Expand Down Expand Up @@ -124,7 +124,7 @@ public String[] getJavaScript() {

String[] jsStrings = new String[applicationFragmentCount];
for (int fragmentIndex = 0; fragmentIndex < applicationFragmentCount; fragmentIndex++) {
jsStrings[fragmentIndex] = Util.toString(applicationJs[fragmentIndex]);
jsStrings[fragmentIndex] = new String(applicationJs[fragmentIndex], StandardCharsets.UTF_8);
}
return jsStrings;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,8 @@
import com.google.gwt.core.ext.UnableToCompleteException;
import com.google.gwt.core.ext.linker.PublicResource;
import com.google.gwt.dev.resource.Resource;
import com.google.gwt.dev.util.Util;

import java.io.ByteArrayInputStream;
import java.io.ByteArrayOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
Expand Down Expand Up @@ -99,10 +97,8 @@ private Object writeReplace() {
return this;
}
// Resource is not serializable, must replace myself.
try {
ByteArrayOutputStream baos = new ByteArrayOutputStream();
Util.copy(resource.openContents(), baos);
return new SerializedPublicResource(getPartialPath(), baos.toByteArray(),
try (InputStream is = resource.openContents()) {
return new SerializedPublicResource(getPartialPath(), is.readAllBytes(),
getLastModified());
} catch (IOException e) {
throw new RuntimeException(e);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@
import com.google.gwt.dev.jjs.ast.JDeclaredType;
import com.google.gwt.dev.jjs.ast.JField;
import com.google.gwt.dev.jjs.ast.JMethod;
import com.google.gwt.dev.util.Util;
import com.google.gwt.thirdparty.guava.common.collect.Maps;

import java.util.Collection;
Expand All @@ -35,9 +34,11 @@ public class ClassDescriptor extends EntityDescriptor {
* Creates a class descriptor from a JDeclaredType.
*/
public static ClassDescriptor from(JDeclaredType classType) {
return new ClassDescriptor(Util.getClassName(classType.getName()),
Util.getPackageName(classType.getName()),
classType);
String name = classType.getName();
int lastDot = name.lastIndexOf('.');
String className = name.substring(lastDot + 1);
final String packageName = lastDot > 0 ? name.substring(0, lastDot) : "";
return new ClassDescriptor(className, packageName, classType);
}

private final String packageName;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,12 +24,12 @@
import com.google.gwt.dev.js.ast.JsLiteral;
import com.google.gwt.dev.js.ast.JsName;
import com.google.gwt.dev.js.ast.JsStringLiteral;
import com.google.gwt.dev.util.Util;

import java.io.IOException;
import java.io.OutputStream;
import java.io.OutputStreamWriter;
import java.io.Writer;
import java.nio.charset.StandardCharsets;
import java.util.Comparator;
import java.util.Map;
import java.util.Map.Entry;
Expand Down Expand Up @@ -177,7 +177,7 @@ public static void escapeXml(String code, int start, int end, boolean quoteApost
public static void recordMap(TreeLogger logger, OutputStream out, SizeBreakdown[] sizeBreakdowns,
JavaToJavaScriptMap jjsmap, Map<JsName, JsLiteral> internedLiteralByVariableName) throws IOException {
out = new GZIPOutputStream(out);
Writer writer = new OutputStreamWriter(out, Util.DEFAULT_ENCODING);
Writer writer = new OutputStreamWriter(out, StandardCharsets.UTF_8);

writer.append("<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n");
writer.append("<sizemaps>\n");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,6 @@
*/
package com.google.gwt.core.ext.soyc.impl;

import static java.nio.charset.StandardCharsets.UTF_8;

import com.google.gwt.core.ext.TreeLogger;
import com.google.gwt.dev.jjs.ast.JProgram;
import com.google.gwt.dev.jjs.ast.JRunAsync;
Expand All @@ -26,6 +24,7 @@
import java.io.OutputStream;
import java.io.OutputStreamWriter;
import java.io.PrintWriter;
import java.nio.charset.StandardCharsets;
import java.util.List;
import java.util.zip.GZIPOutputStream;

Expand All @@ -42,7 +41,8 @@ public static void recordSplitPoints(JProgram jprogram, OutputStream out, TreeLo
logger.branch(TreeLogger.TRACE, "Creating split point map file for the compile report");

try {
try (OutputStreamWriter writer = new OutputStreamWriter(new GZIPOutputStream(out), UTF_8);
try (OutputStreamWriter writer = new OutputStreamWriter(
new GZIPOutputStream(out), StandardCharsets.UTF_8);
PrintWriter pw = new PrintWriter(writer)) {
HtmlTextOutput htmlOut = new HtmlTextOutput(pw, false);
String curLine = "<?xml version=\"1.0\" encoding=\"UTF-8\"?>";
Expand Down
Loading