Skip to content

Commit eb8320c

Browse files
galderzjerboaa
authored andcommitted
8344925: translet-name ignored when package-name is also set
Reviewed-by: joehw Backport-of: 3989a199578fc1d91988cfdbb95f11dd6d4c7b81
1 parent 38a356d commit eb8320c

File tree

4 files changed

+169
-8
lines changed

4 files changed

+169
-8
lines changed

src/java.xml/share/classes/com/sun/org/apache/xalan/internal/xsltc/compiler/XSLTC.java

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 2012, 2022, Oracle and/or its affiliates. All rights reserved.
2+
* Copyright (c) 2012, 2025, Oracle and/or its affiliates. All rights reserved.
33
*/
44
/*
55
* Licensed to the Apache Software Foundation (ASF) under one or more
@@ -57,7 +57,7 @@
5757
* @author G. Todd Miller
5858
* @author Morten Jorgensen
5959
* @author John Howard (johnh@schemasoft.com)
60-
* @LastModified: Jan 2022
60+
* @LastModified: Feb 2025
6161
*/
6262
public final class XSLTC {
6363

@@ -730,7 +730,6 @@ public boolean setDestDirectory(String dstDirName) {
730730
*/
731731
public void setPackageName(String packageName) {
732732
_packageName = Objects.requireNonNull(packageName);
733-
if (_className != null) setClassName(_className);
734733
}
735734

736735
/**

src/java.xml/share/classes/com/sun/org/apache/xalan/internal/xsltc/trax/TransformerFactoryImpl.java

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 2007, 2022, Oracle and/or its affiliates. All rights reserved.
2+
* Copyright (c) 2007, 2025, Oracle and/or its affiliates. All rights reserved.
33
*/
44
/*
55
* Licensed to the Apache Software Foundation (ASF) under one or more
@@ -88,7 +88,7 @@
8888
* @author G. Todd Miller
8989
* @author Morten Jorgensen
9090
* @author Santiago Pericas-Geertsen
91-
* @LastModified: Jan 2022
91+
* @LastModified: Feb 2025
9292
*/
9393
public class TransformerFactoryImpl
9494
extends SAXTransformerFactory implements SourceLoader
@@ -1004,9 +1004,6 @@ public Templates newTemplates(Source source)
10041004
// Set the attributes for translet generation
10051005
int outputType = XSLTC.BYTEARRAY_OUTPUT;
10061006
if (_generateTranslet || _autoTranslet) {
1007-
// Set the translet name
1008-
xsltc.setClassName(getTransletBaseName(source));
1009-
10101007
if (_destinationDirectory != null)
10111008
xsltc.setDestDirectory(_destinationDirectory);
10121009
else {
@@ -1020,8 +1017,11 @@ public Templates newTemplates(Source source)
10201017
}
10211018
}
10221019

1020+
// set package name
10231021
if (_packageName != null)
10241022
xsltc.setPackageName(_packageName);
1023+
// Set the translet name
1024+
xsltc.setClassName(getTransletBaseName(source));
10251025

10261026
if (_jarFileName != null) {
10271027
xsltc.setJarFileName(_jarFileName);
Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
1+
/*
2+
* Copyright (c) 2025, Oracle and/or its affiliates. All rights reserved.
3+
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4+
*
5+
* This code is free software; you can redistribute it and/or modify it
6+
* under the terms of the GNU General Public License version 2 only, as
7+
* published by the Free Software Foundation.
8+
*
9+
* This code is distributed in the hope that it will be useful, but WITHOUT
10+
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
11+
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
12+
* version 2 for more details (a copy is included in the LICENSE file that
13+
* accompanied this code).
14+
*
15+
* You should have received a copy of the GNU General Public License version
16+
* 2 along with this work; if not, write to the Free Software Foundation,
17+
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
18+
*
19+
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
20+
* or visit www.oracle.com if you need additional information or have any
21+
* questions.
22+
*/
23+
package jaxp.library;
24+
25+
import java.io.IOException;
26+
import java.nio.file.Files;
27+
import java.nio.file.Path;
28+
import java.nio.file.StandardCopyOption;
29+
import jdk.test.lib.Platform;
30+
31+
public class JUnitTestUtil {
32+
public static final String CLS_DIR = System.getProperty("test.classes");
33+
public static final String SRC_DIR = System.getProperty("test.src");
34+
35+
/**
36+
* Returns the System identifier (URI) of the source.
37+
* @param path the path to the source
38+
* @return the System identifier
39+
*/
40+
public static String getSystemId(String path) {
41+
if (path == null) return null;
42+
String xmlSysId = "file://" + path;
43+
if (Platform.isWindows()) {
44+
path = path.replace('\\', '/');
45+
xmlSysId = "file:///" + path;
46+
}
47+
return xmlSysId;
48+
}
49+
50+
/**
51+
* Copies a file.
52+
* @param src the path of the source file
53+
* @param target the path of the target file
54+
* @throws Exception if the process fails
55+
*/
56+
public static void copyFile(String src, String target) throws Exception {
57+
try {
58+
Files.copy(Path.of(src), Path.of(target), StandardCopyOption.REPLACE_EXISTING);
59+
} catch (IOException x) {
60+
throw new Exception(x.getMessage());
61+
}
62+
}
63+
}
Lines changed: 99 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,99 @@
1+
/*
2+
* Copyright (c) 2025, Oracle and/or its affiliates. All rights reserved.
3+
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4+
*
5+
* This code is free software; you can redistribute it and/or modify it
6+
* under the terms of the GNU General Public License version 2 only, as
7+
* published by the Free Software Foundation.
8+
*
9+
* This code is distributed in the hope that it will be useful, but WITHOUT
10+
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
11+
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
12+
* version 2 for more details (a copy is included in the LICENSE file that
13+
* accompanied this code).
14+
*
15+
* You should have received a copy of the GNU General Public License version
16+
* 2 along with this work; if not, write to the Free Software Foundation,
17+
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
18+
*
19+
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
20+
* or visit www.oracle.com if you need additional information or have any
21+
* questions.
22+
*/
23+
24+
package transform;
25+
26+
import javax.xml.transform.TransformerFactory;
27+
import javax.xml.transform.stream.StreamSource;
28+
import java.io.*;
29+
import java.nio.file.Files;
30+
import java.nio.file.Path;
31+
import java.util.stream.Stream;
32+
import jaxp.library.JUnitTestUtil;
33+
import org.junit.jupiter.api.BeforeAll;
34+
import org.junit.jupiter.params.ParameterizedTest;
35+
import org.junit.jupiter.params.provider.Arguments;
36+
import org.junit.jupiter.params.provider.MethodSource;
37+
import static org.junit.jupiter.api.Assertions.assertTrue;
38+
39+
/*
40+
* @test
41+
* @bug 8344925
42+
* @summary Transformer properties tests
43+
* @library /javax/xml/jaxp/libs /javax/xml/jaxp/unittest /test/lib
44+
* @run junit/othervm transform.PropertiesTest
45+
*/
46+
public class PropertiesTest {
47+
private static final String USER_DIR = System.getProperty("user.dir");
48+
private static final String TEST_DIR = System.getProperty("test.src");
49+
// Test parameters:
50+
// generate-translet: indicates whether to generate translet
51+
// translet-name: the name of the translet
52+
// package-name: the package name
53+
// destination-directory: the destination
54+
// expected: the class path
55+
private static Stream<Arguments> testData() {
56+
String destination = JUnitTestUtil.CLS_DIR + "/testdir";
57+
return Stream.of(
58+
Arguments.of(true, "MyTranslet", "org.myorg", destination, "/org/myorg/MyTranslet.class"),
59+
Arguments.of(false, "Translet", "not.generate", destination, "/not/generate/Translet.class"),
60+
// translet named after the stylesheet
61+
Arguments.of(true, null, "org.myorg", destination, "/org/myorg/transform.class"),
62+
// default package name die.verwandlung since JDK 9
63+
Arguments.of(true, "MyTranslet", null, destination, "/die/verwandlung/MyTranslet.class"),
64+
Arguments.of(true, "MyTranslet", "org.myorg", null, "/org/myorg/MyTranslet.class")
65+
);
66+
}
67+
68+
@BeforeAll
69+
public static void setup() throws Exception {
70+
// so that the translet is generated under test.classes
71+
JUnitTestUtil.copyFile(JUnitTestUtil.SRC_DIR + "/transform.xsl", JUnitTestUtil.CLS_DIR + "/transform.xsl");
72+
}
73+
74+
@ParameterizedTest
75+
@MethodSource("testData")
76+
public void test(boolean generateTranslet, String name, String packageName,
77+
String destination, String expected)
78+
throws Exception {
79+
TransformerFactory tf = TransformerFactory.newInstance();
80+
81+
tf.setAttribute("generate-translet", generateTranslet);
82+
if (name != null) tf.setAttribute("translet-name", name);
83+
if (packageName != null) tf.setAttribute("package-name", packageName);
84+
if (destination != null) tf.setAttribute("destination-directory", destination);
85+
86+
String xslFile = JUnitTestUtil.CLS_DIR + "/transform.xsl";
87+
String xslSysId = JUnitTestUtil.getSystemId(xslFile);
88+
StreamSource xsl = new StreamSource(xslSysId);
89+
tf.newTemplates(xsl);
90+
91+
String path = (destination != null) ? destination + expected : new File(xslFile).getParent() + expected;
92+
93+
if (generateTranslet) {
94+
assertTrue(Files.exists(Path.of(path)), "Translet is expected at " + expected);
95+
} else {
96+
assertTrue(Files.notExists(Path.of(path)), "Translet is not to be generated.");
97+
}
98+
}
99+
}

0 commit comments

Comments
 (0)