Skip to content

Commit b56a171

Browse files
committed
8344925: translet-name ignored when package-name is also set
1 parent bad39b6 commit b56a171

File tree

4 files changed

+166
-4
lines changed

4 files changed

+166
-4
lines changed

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

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -734,7 +734,6 @@ public boolean setDestDirectory(String dstDirName) {
734734
*/
735735
public void setPackageName(String packageName) {
736736
_packageName = Objects.requireNonNull(packageName);
737-
if (_className != null) setClassName(_className);
738737
}
739738

740739
/**

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

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -999,9 +999,6 @@ public Templates newTemplates(Source source)
999999
// Set the attributes for translet generation
10001000
int outputType = XSLTC.BYTEARRAY_OUTPUT;
10011001
if (_generateTranslet || _autoTranslet) {
1002-
// Set the translet name
1003-
xsltc.setClassName(getTransletBaseName(source));
1004-
10051002
if (_destinationDirectory != null)
10061003
xsltc.setDestDirectory(_destinationDirectory);
10071004
else {
@@ -1015,8 +1012,11 @@ public Templates newTemplates(Source source)
10151012
}
10161013
}
10171014

1015+
// set package name
10181016
if (_packageName != null)
10191017
xsltc.setPackageName(_packageName);
1018+
// Set the translet name
1019+
xsltc.setClassName(getTransletBaseName(source));
10201020

10211021
if (_jarFileName != null) {
10221022
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+
30+
public class JUnitTestUtil {
31+
public static final String CLS_DIR = System.getProperty("test.classes");
32+
public static final String SRC_DIR = System.getProperty("test.src");
33+
public static final boolean isWindows = System.getProperty("os.name").contains("Windows");
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 (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: 100 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,100 @@
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
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+
//Files.list(Path.of(path)).forEach(System.out::println);
95+
assertTrue(Files.exists(Path.of(path)), "Translet is expected at " + expected);
96+
} else {
97+
assertTrue(Files.notExists(Path.of(path)), "Translet is not to be generated.");
98+
}
99+
}
100+
}

0 commit comments

Comments
 (0)