Skip to content

Commit

Permalink
remove UseShortJavaName code - should be in its own PR
Browse files Browse the repository at this point in the history
  • Loading branch information
pjfanning committed Jun 24, 2024
1 parent bc4c826 commit 323be55
Show file tree
Hide file tree
Showing 8 changed files with 5 additions and 119 deletions.
15 changes: 0 additions & 15 deletions src/main/java/org/apache/xmlbeans/XmlOptions.java
Original file line number Diff line number Diff line change
Expand Up @@ -1069,21 +1069,6 @@ public boolean isCompileDownloadUrls() {
return hasOption(XmlOptionsKeys.COMPILE_DOWNLOAD_URLS);
}

/**
* If this option is set, then the schema compiler will use the java_short_name to generate file name
*
*/
public XmlOptions setCompileUseShortJavaName() {
return setCompileUseShortJavaName(true);
}

public XmlOptions setCompileUseShortJavaName(boolean b) {
return set(XmlOptionsKeys.USE_JAVA_SHORT_NAME, b);
}

public boolean isCompileUseShortJavaName() {
return hasOption(XmlOptionsKeys.USE_JAVA_SHORT_NAME);
}
/**
* If this option is set, then the schema compiler will permit and
* ignore multiple definitions of the same component (element, attribute,
Expand Down
22 changes: 2 additions & 20 deletions src/main/java/org/apache/xmlbeans/impl/schema/SchemaTypePool.java
Original file line number Diff line number Diff line change
Expand Up @@ -89,17 +89,7 @@ String handleForElement(SchemaGlobalElement element) {
}
String handle = _componentsToHandles.get(element);
if (handle == null) {
if(typeSystem.isUseShortJavaName()) {
SchemaType type = element.getType();
String javaName = type.getShortJavaName();
if (javaName != null && !javaName.isEmpty()) {
handle = addUniqueHandle(element, NameUtil.upperCamelCase(javaName) + "Element");
} else {
handle = addUniqueHandle(element, NameUtil.upperCamelCase(element.getName().getLocalPart()) + "Element");
}
} else {
handle = addUniqueHandle(element, NameUtil.upperCamelCase(element.getName().getLocalPart()) + "Element");
}
handle = addUniqueHandle(element, NameUtil.upperCamelCase(element.getName().getLocalPart()) + "Element");
}
return handle;
}
Expand Down Expand Up @@ -189,15 +179,7 @@ String handleForType(SchemaType type) {
if (name == null) {
baseName = "Anon" + uniq + "Type";
} else {
if(typeSystem.isUseShortJavaName()) {
String javaName = type.getShortJavaName();
if (javaName == null || javaName.isEmpty())
javaName = name.getLocalPart();
baseName = NameUtil.upperCamelCase(javaName) + uniq + suffix + "Type";
}
else {
baseName = NameUtil.upperCamelCase(name.getLocalPart()) + uniq + suffix + "Type";
}
baseName = NameUtil.upperCamelCase(name.getLocalPart()) + uniq + suffix + "Type";
}

handle = addUniqueHandle(type, baseName);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -166,7 +166,6 @@ public class SchemaTypeSystemImpl extends SchemaTypeLoaderBase implements Schema

// the additional config option
private String _sourceCodeEncoding ;
private boolean _useShortJavaName;

static String nameToPathString(String nameForSystem) {
nameForSystem = nameForSystem.replace('.', '/');
Expand Down Expand Up @@ -319,25 +318,7 @@ void savePointers() {

void savePointersForComponents(SchemaComponent[] components, String dir) {
for (SchemaComponent component : components) {
if(_useShortJavaName) {
String javaName = _localHandles.handleForComponent(component);
if (javaName != null && !javaName.isEmpty())
{
QName nameTemp = component.getName();
String resultName;
if (nameTemp.getNamespaceURI() == null || nameTemp.getNamespaceURI().length() == 0) {
resultName = "_nons/" + QNameHelper.hexsafe(javaName);
} else {
resultName = QNameHelper.hexsafe(nameTemp.getNamespaceURI()) + "/"
+ QNameHelper.hexsafe(javaName);
}
savePointerFile(dir + resultName, _name);
} else {
savePointerFile(dir + QNameHelper.hexsafedir(component.getName()), _name);
}
} else {
savePointerFile(dir + QNameHelper.hexsafedir(component.getName()), _name);
}
savePointerFile(dir + QNameHelper.hexsafedir(component.getName()), _name);
}
}

Expand Down Expand Up @@ -440,10 +421,6 @@ String getSourceCodeEncoding() {
return _sourceCodeEncoding ;
}

boolean isUseShortJavaName(){
return _useShortJavaName;
}

@SuppressWarnings("unchecked")
private <T extends SchemaComponent.Ref> void buildContainersHelper(Map<QName, SchemaComponent.Ref> elements, BiConsumer<SchemaContainer, T> adder) {
elements.forEach((k, v) -> adder.accept(getContainerNonNull(k.getNamespaceURI()), (T) v));
Expand Down Expand Up @@ -648,7 +625,6 @@ public void loadFromStscState(StscState state) {
_annotations = state.annotations();
_namespaces = new HashSet<>(Arrays.asList(state.getNamespaces()));
_containers = state.getContainerMap();
_useShortJavaName = state.useShortName();
_sourceCodeEncoding = state.sourceCodeEncoding();
fixupContainers();
// Checks that data in the containers matches the lookup maps
Expand Down
11 changes: 0 additions & 11 deletions src/main/java/org/apache/xmlbeans/impl/schema/StscState.java
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,6 @@ public class StscState {
private boolean _noPvr;
private boolean _noAnn;
private boolean _mdefAll;
private boolean _useShortJavaName;
private String _sourceCodeEncoding ;
private final Set<String> _mdefNamespaces = buildDefaultMdefNamespaces();
private EntityResolver _entityResolver;
Expand Down Expand Up @@ -465,8 +464,6 @@ public void setOptions(XmlOptions options) {
if (_sourceCodeEncoding == null || _sourceCodeEncoding.isEmpty()) {
_sourceCodeEncoding = SystemProperties.getProperty("xmlbean.sourcecodeencoding");
}
_useShortJavaName = options.isCompileUseShortJavaName() ||
"true".equals(SystemProperties.getProperty("xmlbean.useshortjavaname", "false"));
_entityResolver = options.getEntityResolver();

if (_entityResolver == null) {
Expand Down Expand Up @@ -539,14 +536,6 @@ public String sourceCodeEncoding() {
return _sourceCodeEncoding ;
}

/**
* True if use the java_short_name to generate file name
*/
// EXPERIMENTAL
public boolean useShortName() {
return _useShortJavaName;
}

/**
* Get count of recovered errors. Not for public.
*/
Expand Down
9 changes: 0 additions & 9 deletions src/main/java/org/apache/xmlbeans/impl/tool/MavenPlugin.java
Original file line number Diff line number Diff line change
Expand Up @@ -192,14 +192,6 @@ public class MavenPlugin extends AbstractMojo {
@Parameter
private String sourceCodeEncoding;

/**
* Used for File Names.
*
* @since 5.2.2
*/
@Parameter( defaultValue = "false" )
private boolean useShortJavaName;

@Parameter
private List<Extension> extensions;

Expand Down Expand Up @@ -320,7 +312,6 @@ public void execute() throws MojoExecutionException, MojoFailureException {
if (sourceCodeEncoding != null && !sourceCodeEncoding.isEmpty()) {
params.setSourceCodeEncoding(sourceCodeEncoding);
}
params.setUseShortJavaName(useShortJavaName);

boolean result = SchemaCompiler.compile(params);

Expand Down
9 changes: 0 additions & 9 deletions src/main/java/org/apache/xmlbeans/impl/tool/Parameters.java
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,6 @@ public class Parameters {
private boolean noExt;
private boolean debug;
private boolean copyAnn;
private boolean useShortJavaName;
private String sourceCodeEncoding;
private boolean incrementalSrcGen;
private String repackage;
Expand Down Expand Up @@ -205,10 +204,6 @@ public boolean isNoAnn() {
return noAnn;
}

public boolean isUseShortJavaName() {
return useShortJavaName;
}

public String getSourceCodeEncoding() {
return sourceCodeEncoding;
}
Expand Down Expand Up @@ -249,10 +244,6 @@ public void setDebug(boolean debug) {
this.debug = debug;
}

public void setUseShortJavaName(boolean useShortJavaName) {
this.useShortJavaName = useShortJavaName;
}

public void setSourceCodeEncoding(String sourceCodeEncoding) {
this.sourceCodeEncoding = sourceCodeEncoding;
}
Expand Down
13 changes: 2 additions & 11 deletions src/main/java/org/apache/xmlbeans/impl/tool/SchemaCompiler.java
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,6 @@ public static void printUsage() {
System.out.println(" -repackage - repackage specification, e.g. \"org.apache.xmlbeans.metadata:mypackage.metadata\" to change the metadata directory");
System.out.println(" -copyann - copy schema annotations to javadoc (default false) - don't activate on untrusted schema sources!");
System.out.println(" -sourcecodeencoding [encodingName] - Generate Java source code with the specified encoding (ISO-8859-1 is the legacy default)");
System.out.println(" -useshortjavaname - Generate file name using Short Java Name");
/* Undocumented feature - pass in one schema compiler extension and related parameters
System.out.println(" -extension - registers a schema compiler extension");
System.out.println(" -extensionParms - specify parameters for the compiler extension");
Expand Down Expand Up @@ -100,7 +99,6 @@ public static void main(String[] args) {
flags.add("noext");
flags.add("srconly");
flags.add("debug");
flags.add("useshortjavaname");

Set<String> opts = new HashSet<>();
opts.add("out");
Expand Down Expand Up @@ -191,7 +189,6 @@ public static void main(String[] args) {
boolean debug = (cl.getOpt("debug") != null);
boolean copyAnn = (cl.getOpt("copyann") != null);
String sourceCodeEncoding = cl.getOpt("sourcecodeencoding");
boolean useShortJavaName = (cl.getOpt("useshortjavaname") != null);

String allowmdef = cl.getOpt("allowmdef");
Set<String> mdefNamespaces = (allowmdef == null ? Collections.emptySet() :
Expand Down Expand Up @@ -340,7 +337,6 @@ public static void main(String[] args) {
params.setNoExt(noExt);
params.setDebug(debug);
params.setSourceCodeEncoding(sourceCodeEncoding);
params.setUseShortJavaName(useShortJavaName);
params.setErrorListener(err);
params.setRepackage(repackage);
params.setExtensions(extensions);
Expand All @@ -364,7 +360,7 @@ public static void main(String[] args) {

private static SchemaTypeSystem loadTypeSystem(String name, File[] xsdFiles, File[] wsdlFiles, URL[] urlFiles, File[] configFiles,
File[] javaFiles, ResourceLoader cpResourceLoader,
boolean download, boolean noUpa, boolean noPvr, boolean noAnn, boolean noVDoc, boolean noExt, String sourceCodeEncoding, boolean useShortName,
boolean download, boolean noUpa, boolean noPvr, boolean noAnn, boolean noVDoc, boolean noExt, String sourceCodeEncoding,
Set<String> mdefNamespaces, File baseDir, Map<String, String> sourcesToCopyMap,
Collection<XmlError> outerErrorListener, File schemasDir, EntityResolver entResolver, File[] classpath) {
XmlErrorWatcher errorListener = new XmlErrorWatcher(outerErrorListener);
Expand Down Expand Up @@ -532,9 +528,6 @@ private static SchemaTypeSystem loadTypeSystem(String name, File[] xsdFiles, Fil
if (sourceCodeEncoding != null ) {
opts.setCharacterEncoding(sourceCodeEncoding);
}
if (useShortName) {
opts.setCompileUseShortJavaName();
}
if (mdefNamespaces != null) {
opts.setCompileMdefNamespaces(mdefNamespaces);
}
Expand Down Expand Up @@ -629,7 +622,6 @@ public static boolean compile(Parameters params) {
boolean incrSrcGen = params.isIncrementalSrcGen();
boolean copyAnn = params.isCopyAnn();
String sourceCodeEncoding = params.getSourceCodeEncoding();
boolean useShortName = params.isUseShortJavaName();
Collection<XmlError> outerErrorListener = params.getErrorListener();
Set<BeanMethod> partialMethods = params.getPartialMethods();

Expand Down Expand Up @@ -682,7 +674,7 @@ public static boolean compile(Parameters params) {
// build the in-memory type system
XmlErrorWatcher errorListener = new XmlErrorWatcher(outerErrorListener);
SchemaTypeSystem system = loadTypeSystem(name, xsdFiles, wsdlFiles, urlFiles, configFiles,
javaFiles, cpResourceLoader, download, noUpa, noPvr, noAnn, noVDoc, noExt, sourceCodeEncoding, useShortName, mdefNamespaces,
javaFiles, cpResourceLoader, download, noUpa, noPvr, noAnn, noVDoc, noExt, sourceCodeEncoding, mdefNamespaces,
baseDir, sourcesToCopyMap, errorListener, schemasDir, cmdLineEntRes, classpath);
if (errorListener.hasError()) {
result = false;
Expand Down Expand Up @@ -710,7 +702,6 @@ public static boolean compile(Parameters params) {
options.setCompileNoAnnotations(noAnn);
options.setCompileAnnotationAsJavadoc(copyAnn);
options.setCharacterEncoding(sourceCodeEncoding);
options.setCompileUseShortJavaName(useShortName);

// save .xsb files
system.save(filer);
Expand Down
19 changes: 0 additions & 19 deletions src/test/java/compile/scomp/checkin/XmlBeansCompCheckinTests.java
Original file line number Diff line number Diff line change
Expand Up @@ -99,25 +99,6 @@ void test_Filer_compilation() throws Exception {
MatcherAssert.assertThat(f.getSrcFileVec(), is(expSrcType));
}

@Test
void test_Filer_shortname_compilation() throws Exception {
XmlObject obj1 = XmlObject.Factory.parse(FOR_XSD);
XmlObject[] schemas = new XmlObject[]{obj1};

TestFiler f = new TestFiler();
xm_opts.setCompileUseShortJavaName();
XmlBeans.compileXmlBeans("apiCompile", null, schemas, null, XmlBeans.getBuiltinTypeSystem(), f, xm_opts);

assertTrue(f.isCreateBinaryFile(), "Binary File method not invoked");
assertTrue(f.isCreateSourceFile(), "Source File method not invoked");

assertNotNull(f.getBinFileVec());
MatcherAssert.assertThat(f.getBinFileVec(), is(expBinShortnameType));

assertNotNull(f.getSrcFileVec());
MatcherAssert.assertThat(f.getSrcFileVec(), is(expSrcType));
}

/**
* Verify Partial SOM cannot be saved to file system
*/
Expand Down

0 comments on commit 323be55

Please sign in to comment.