-
Notifications
You must be signed in to change notification settings - Fork 99
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fixing issues 215 / 244 due to xjc-ri changes from 2.3.4
- Loading branch information
Laurent SCHOELENS
committed
Aug 9, 2023
1 parent
93f623a
commit 824c7d6
Showing
13 changed files
with
200 additions
and
59 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
39 changes: 28 additions & 11 deletions
39
...ugin-core/src/main/java/org/jvnet/jaxb/maven/resolver/tools/ClasspathCatalogResolver.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,50 +1,67 @@ | ||
package org.jvnet.jaxb.maven.resolver.tools; | ||
|
||
import com.sun.org.apache.xml.internal.resolver.CatalogManager; | ||
|
||
import org.apache.maven.plugin.logging.Log; | ||
import org.jvnet.jaxb.maven.plugin.logging.NullLog; | ||
|
||
import java.net.URI; | ||
import java.net.URISyntaxException; | ||
import java.net.URL; | ||
import java.text.MessageFormat; | ||
|
||
public class ClasspathCatalogResolver extends | ||
com.sun.org.apache.xml.internal.resolver.tools.CatalogResolver { | ||
com.sun.org.apache.xml.internal.resolver.tools.CatalogResolver implements LoggingCatalogResolver { | ||
|
||
public static final String URI_SCHEME_CLASSPATH = "classpath"; | ||
private Log log; | ||
|
||
public ClasspathCatalogResolver() { | ||
super(); | ||
this.log = NullLog.INSTANCE; | ||
} | ||
|
||
@Override | ||
public String getResolvedEntity(String publicId, String systemId) { | ||
// System.out.println("Resolving [" + publicId + "], [" + systemId + "]."); | ||
|
||
log.debug( "ClasspathCatalogResolver : Resolving [" + publicId + "], [" + systemId + "]."); | ||
final String result = super.getResolvedEntity(publicId, systemId); | ||
// System.out.println("Resolved to [" + result+ "]."); | ||
log.debug("ClasspathCatalogResolver : Resolved to [" + result+ "]."); | ||
|
||
if (result == null) { | ||
// System.err.println(MessageFormat.format( | ||
// "Could not resolve publicId [{0}], systemId [{1}]", | ||
// publicId, systemId)); | ||
log.info(MessageFormat.format( | ||
"ClasspathCatalogResolver : Could not resolve publicId [{0}], systemId [{1}]", | ||
publicId, systemId)); | ||
return null; | ||
} | ||
|
||
try { | ||
final URI uri = new URI(result); | ||
if (URI_SCHEME_CLASSPATH.equals(uri.getScheme())) { | ||
final String schemeSpecificPart = uri.getSchemeSpecificPart(); | ||
// System.out.println("Resolve [" + schemeSpecificPart + "]."); | ||
log.debug("ClasspathCatalogResolver : Resolve [" + schemeSpecificPart + "]."); | ||
|
||
final URL resource = Thread.currentThread() | ||
.getContextClassLoader() | ||
.getResource(schemeSpecificPart); | ||
if (resource == null) { | ||
// System.out.println("Returning [" + null + "]."); | ||
log.debug("ClasspathCatalogResolver : Returning [" + null + "]."); | ||
return null; | ||
} else { | ||
// System.out.println("Returning to [" + resource.toString()+ "]."); | ||
log.debug("ClasspathCatalogResolver : Returning to [" + resource.toString() + "]."); | ||
return resource.toString(); | ||
} | ||
} else { | ||
// System.out.println("Returning to [" + result+ "]."); | ||
log.debug("ClasspathCatalogResolver : Returning to [" + result+ "]."); | ||
return result; | ||
} | ||
} catch (URISyntaxException urisex) { | ||
// System.out.println("Returning to [" + result+ "]."); | ||
log.debug("ClasspathCatalogResolver : Returning to [" + result+ "]."); | ||
return result; | ||
} | ||
} | ||
|
||
public void setLog(Log log) { | ||
this.log = log; | ||
} | ||
} |
11 changes: 11 additions & 0 deletions
11
...plugin-core/src/main/java/org/jvnet/jaxb/maven/resolver/tools/LoggingCatalogResolver.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
package org.jvnet.jaxb.maven.resolver.tools; | ||
|
||
import org.apache.maven.plugin.logging.Log; | ||
|
||
/** | ||
* This interface allow Maven XJC Mojo to pass it's logger to the CatalogResolver | ||
* in order to allow debugging with appropriate maven flags. | ||
*/ | ||
public interface LoggingCatalogResolver { | ||
void setLog(Log log); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
66 changes: 48 additions & 18 deletions
66
...e/src/main/java/org/jvnet/jaxb/maven/resolver/tools/ReResolvingEntityResolverWrapper.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,44 +1,74 @@ | ||
package org.jvnet.jaxb.maven.resolver.tools; | ||
|
||
import java.io.IOException; | ||
import java.net.URI; | ||
import java.net.URISyntaxException; | ||
import java.nio.file.Files; | ||
import java.nio.file.Paths; | ||
import java.text.MessageFormat; | ||
import java.util.Optional; | ||
|
||
import org.apache.maven.plugin.logging.Log; | ||
import org.jvnet.jaxb.maven.plugin.logging.NullLog; | ||
import org.jvnet.jaxb.maven.util.StringUtils; | ||
import org.xml.sax.EntityResolver; | ||
import org.xml.sax.InputSource; | ||
import org.xml.sax.SAXException; | ||
|
||
public class ReResolvingEntityResolverWrapper implements EntityResolver { | ||
|
||
private final EntityResolver entityResolver; | ||
private final Log log; | ||
|
||
public ReResolvingEntityResolverWrapper(EntityResolver entityResolver) { | ||
public ReResolvingEntityResolverWrapper(EntityResolver entityResolver, Log log) { | ||
if (entityResolver == null) { | ||
throw new IllegalArgumentException( | ||
"Provided entity resolver must not be null."); | ||
throw new IllegalArgumentException("Provided entity resolver must not be null."); | ||
} | ||
this.entityResolver = entityResolver; | ||
this.log = Optional.ofNullable(log).orElse(NullLog.INSTANCE); | ||
} | ||
|
||
@Override | ||
public InputSource resolveEntity(String publicId, String systemId) | ||
throws SAXException, IOException { | ||
// System.out.println(MessageFormat.format("Resolving publicId [{0}], systemId [{1}].", | ||
// publicId, systemId)); | ||
final InputSource resolvedInputSource = this.entityResolver | ||
.resolveEntity(publicId, systemId); | ||
log.debug(MessageFormat.format("ReResolvingEntityResolverWrapper : Resolving publicId [{0}], systemId [{1}].", publicId, systemId)); | ||
final InputSource resolvedInputSource = this.entityResolver.resolveEntity(publicId, systemId); | ||
if (resolvedInputSource == null) { | ||
// System.out.println("Resolution result is null."); | ||
log.debug("ReResolvingEntityResolverWrapper : Resolution result is null."); | ||
return null; | ||
} else { | ||
// System.out.println(MessageFormat.format( | ||
// "Resolved to publicId [{0}], systemId [{1}].", | ||
// resolvedInputSource.getPublicId(), | ||
// resolvedInputSource.getSystemId())); | ||
final String pId = publicId != null ? publicId | ||
: resolvedInputSource.getPublicId(); | ||
final String sId = systemId != null ? systemId | ||
: resolvedInputSource.getSystemId(); | ||
return new ReResolvingInputSourceWrapper(this.entityResolver, | ||
resolvedInputSource, pId, sId); | ||
log.debug(MessageFormat.format("ReResolvingEntityResolverWrapper : Resolved to publicId [{0}], systemId [{1}].", resolvedInputSource.getPublicId(), resolvedInputSource.getSystemId())); | ||
final String pId = !StringUtils.isEmpty(publicId) ? publicId : resolvedInputSource.getPublicId(); | ||
final String sId = computeSystemId(systemId, resolvedInputSource.getSystemId(), log); | ||
return new ReResolvingInputSourceWrapper(this.entityResolver, resolvedInputSource, pId, sId, resolvedInputSource.getPublicId(), resolvedInputSource.getSystemId()); | ||
} | ||
} | ||
|
||
private static String computeSystemId(String systemId, String resolvedSystemId, Log log) { | ||
if (systemId == null) { | ||
return resolvedSystemId; | ||
} | ||
if (resolvedSystemId == null) { | ||
return systemId; | ||
} | ||
boolean fileExistsSystemId = checkFileExists(systemId, log); | ||
boolean fileExistsResolvedSystemId = checkFileExists(resolvedSystemId, log); | ||
return !StringUtils.isEmpty(systemId) && fileExistsSystemId ? systemId : fileExistsResolvedSystemId ? resolvedSystemId : systemId; | ||
} | ||
|
||
private static boolean checkFileExists(String sId, Log log) { | ||
try { | ||
URI uriSystemId = new URI(sId); | ||
if ("file".equals(uriSystemId.getScheme())) { | ||
if (!Files.exists(Paths.get(uriSystemId))) { | ||
// resolved file does not exist, warn and let's continue with original systemId | ||
log.warn(MessageFormat.format("ReResolvingEntityResolverWrapper : File {0} does not exists.", sId)); | ||
return false; | ||
} | ||
} | ||
} catch (URISyntaxException ex) { | ||
// ignore, let it be handled by parser as is | ||
} | ||
return true; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd"> | ||
<modelVersion>4.0.0</modelVersion> | ||
<artifactId>jaxb-maven-plugin-tests-244</artifactId> | ||
<parent> | ||
<groupId>org.jvnet.jaxb</groupId> | ||
<artifactId>jaxb-maven-plugin-tests</artifactId> | ||
<version>2.0.4-SNAPSHOT</version> | ||
</parent> | ||
<packaging>jar</packaging> | ||
<name>JAXB Tools :: Maven Plugin :: Test [JAXB-TOOLS 244]</name> | ||
<dependencies> | ||
<dependency> | ||
<groupId>org.glassfish.jaxb</groupId> | ||
<artifactId>jaxb-runtime</artifactId> | ||
</dependency> | ||
<dependency> | ||
<groupId>org.jvnet.jaxb</groupId> | ||
<artifactId>jaxb-maven-plugin-testing</artifactId> | ||
<scope>test</scope> | ||
</dependency> | ||
</dependencies> | ||
<build> | ||
<plugins> | ||
<plugin> | ||
<groupId>org.jvnet.jaxb</groupId> | ||
<artifactId>jaxb-maven-plugin</artifactId> | ||
<executions> | ||
<execution> | ||
<id>generate</id> | ||
<goals> | ||
<goal>generate</goal> | ||
</goals> | ||
<configuration> | ||
<strict>false</strict> | ||
<catalog>src/main/resources/catalog.xml</catalog> | ||
<schemaDirectory>src/main/resources/schemas</schemaDirectory> | ||
<schemaIncludes> | ||
<include>a.xsd</include> | ||
</schemaIncludes> | ||
<bindingDirectory>src/main/resources</bindingDirectory> | ||
</configuration> | ||
</execution> | ||
</executions> | ||
</plugin> | ||
</plugins> | ||
</build> | ||
</project> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
<bindings xmlns="http://java.sun.com/xml/ns/jaxb" version="2.1" | ||
xmlns:xs="http://www.w3.org/2001/XMLSchema" | ||
xmlns:xjc="http://java.sun.com/xml/ns/jaxb/xjc" | ||
extensionBindingPrefixes="xjc"> | ||
</bindings> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
<catalog xmlns="urn:oasis:names:tc:entity:xmlns:xml:catalog" | ||
prefer="public"> | ||
<systemSuffix systemIdSuffix="b.xsd" uri="schemas/common/b.xsd"/> | ||
</catalog> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
<xs:schema xmlns:b="B" xmlns:xs="http://www.w3.org/2001/XMLSchema"> | ||
<xs:import namespace="B" schemaLocation="b.xsd"/> | ||
<xs:element name="a" type="b:foo"/> | ||
</xs:schema> |
Oops, something went wrong.