This is an automated email from the ASF dual-hosted git repository. joshtynjala pushed a commit to branch develop in repository https://gitbox.apache.org/repos/asf/royale-compiler.git
commit 4c0167e92bd7f2c13c8e732ba37b9035b379e2b0 Author: Josh Tynjala <[email protected]> AuthorDate: Tue Jan 21 13:46:38 2025 -0800 MXMLRoyalePublisher: when html-template file can't be found, report a problem instead of throwing an exception Exceptions should be for internal use, but html-template can be set to an invalid path by the user, so it should be reported differently --- .../codegen/mxml/royale/MXMLRoyalePublisher.java | 14 +++++---- .../problems/HTMLTemplateFileNotFoundProblem.java | 35 ++++++++++++++++++++++ 2 files changed, 44 insertions(+), 5 deletions(-) diff --git a/compiler-jx/src/main/java/org/apache/royale/compiler/internal/codegen/mxml/royale/MXMLRoyalePublisher.java b/compiler-jx/src/main/java/org/apache/royale/compiler/internal/codegen/mxml/royale/MXMLRoyalePublisher.java index 7b1abcc66..29f0f8028 100644 --- a/compiler-jx/src/main/java/org/apache/royale/compiler/internal/codegen/mxml/royale/MXMLRoyalePublisher.java +++ b/compiler-jx/src/main/java/org/apache/royale/compiler/internal/codegen/mxml/royale/MXMLRoyalePublisher.java @@ -47,6 +47,7 @@ import org.apache.royale.compiler.internal.graph.GoogDepsWriter; import org.apache.royale.compiler.internal.projects.RoyaleJSProject; import org.apache.royale.compiler.internal.scopes.ASProjectScope.DefinitionPromise; import org.apache.royale.compiler.internal.targets.ITargetAttributes; +import org.apache.royale.compiler.problems.HTMLTemplateFileNotFoundProblem; import org.apache.royale.compiler.utils.JSClosureCompilerWrapper; import org.apache.royale.swc.ISWC; import org.apache.royale.swc.ISWCFileEntry; @@ -561,7 +562,7 @@ public class MXMLRoyalePublisher extends JSPublisher implements IJSRoyalePublish // Create the index.html for the debug-js version. if (!((JSGoogConfiguration)configuration).getSkipTranspile()) { if (template != null) { - writeTemplate(template, "intermediate", projectName, mainClassQName, intermediateDir, depsFileData, wrappedScript); + writeTemplate(template, "intermediate", projectName, mainClassQName, intermediateDir, depsFileData, wrappedScript, problems); } else { writeHTML("intermediate", projectName, mainClassQName, intermediateDir, depsFileData, wrappedScript); } @@ -569,7 +570,7 @@ public class MXMLRoyalePublisher extends JSPublisher implements IJSRoyalePublish // Create the index.html for the release-js version. if (configuration.release()) { if (template != null) { - writeTemplate(template, "release", projectName, mainClassQName, releaseDir, depsFileData, wrappedScript); + writeTemplate(template, "release", projectName, mainClassQName, releaseDir, depsFileData, wrappedScript, problems); } else { writeHTML("release", projectName, mainClassQName, releaseDir, null, wrappedScript); } @@ -882,12 +883,15 @@ public class MXMLRoyalePublisher extends JSPublisher implements IJSRoyalePublish return source!=null ? Matcher.quoteReplacement(source) : ""; } - protected void writeTemplate(File template, String type, String projectName, String mainClassQName, File targetDir, String deps, List<String> additionalHTML) + protected void writeTemplate(File template, String type, String projectName, String mainClassQName, + File targetDir, String deps, List<String> additionalHTML, ProblemQuery problems) throws IOException { // Check if the template exists. - if(!template.exists()) { - throw new IOException("Template specified by 'html-template' does not exist: " + template.getPath()); + if(!template.exists() || template.isDirectory()) + { + problems.add(new HTMLTemplateFileNotFoundProblem(template.getPath())); + return; } String input = readCode(template); diff --git a/compiler-jx/src/main/java/org/apache/royale/compiler/problems/HTMLTemplateFileNotFoundProblem.java b/compiler-jx/src/main/java/org/apache/royale/compiler/problems/HTMLTemplateFileNotFoundProblem.java new file mode 100644 index 000000000..5848dbb2c --- /dev/null +++ b/compiler-jx/src/main/java/org/apache/royale/compiler/problems/HTMLTemplateFileNotFoundProblem.java @@ -0,0 +1,35 @@ +/* + * + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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 org.apache.royale.compiler.problems; + +public final class HTMLTemplateFileNotFoundProblem extends CompilerProblem +{ + public static final String DESCRIPTION = + "Can't find html-template file: ${file}"; + + public HTMLTemplateFileNotFoundProblem(String file) + { + super(); + this.file = file; + } + + public final String file; +} + \ No newline at end of file
