Skip to content

Commit

Permalink
[#336] adding new parameter to disable fix introduced in 2.0.5
Browse files Browse the repository at this point in the history
  • Loading branch information
laurentschoelens authored and mattrpav committed Aug 29, 2023
1 parent ae505d8 commit b148894
Show file tree
Hide file tree
Showing 5 changed files with 58 additions and 30 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -432,6 +432,21 @@ public void setCatalogResolver(String catalogResolver) {
this.catalogResolver = catalogResolver;
}


/**
* If 'true', the fix for issue #306 will no more be applied.
*/
@Parameter(defaultValue = "false", property = "maven.xjc2.disableSystemIdResolution")
private boolean disableSystemIdResolution;

public boolean getDisableSystemIdResolution() {
return disableSystemIdResolution;
}

public void setDisableSystemIdResolution(boolean disableSystemIdResolution) {
this.disableSystemIdResolution = disableSystemIdResolution;
}

/**
* <p>
* The generated classes will all be placed under this Java package (xjc's
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -880,7 +880,7 @@ private void setupEntityResolver() {
}

protected EntityResolver createEntityResolver(CatalogResolver catalogResolver) {
final EntityResolver entityResolver = new ReResolvingEntityResolverWrapper(catalogResolver, getLog());
final EntityResolver entityResolver = new ReResolvingEntityResolverWrapper(catalogResolver, getLog(), getDisableSystemIdResolution());
return entityResolver;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,14 +14,21 @@
public class ReResolvingEntityResolverWrapper implements EntityResolver {

private final EntityResolver entityResolver;
private final Log log;
private final Log log;
private final boolean disableSystemIdResolution;

public ReResolvingEntityResolverWrapper(EntityResolver entityResolver, Log log) {
public ReResolvingEntityResolverWrapper(EntityResolver entityResolver, Log log, boolean disableSystemIdResolution) {
if (entityResolver == null) {
throw new IllegalArgumentException("Provided entity resolver must not be null.");
}
this.entityResolver = entityResolver;
this.log = Optional.ofNullable(log).orElse(NullLog.INSTANCE);
this.disableSystemIdResolution = disableSystemIdResolution;
if (disableSystemIdResolution) {
log.warn("ReResolvingEntityResolverWrapper : systemIdResolution fix is disable, you may have problems with schema resolution.");
} else {
log.debug("ReResolvingEntityResolverWrapper : systemIdResolution fix is enabled");
}
}

@Override
Expand All @@ -37,7 +44,7 @@ public InputSource resolveEntity(String publicId, String systemId)
final String pId = !StringUtils.isEmpty(publicId) ? publicId : resolvedInputSource.getPublicId();
final String sId = !StringUtils.isEmpty(systemId) ? systemId : resolvedInputSource.getSystemId();
log.debug(MessageFormat.format("ReResolvingEntityResolverWrapper : Final Resolved to publicId [{0}], systemId [{1}].", pId, sId));
return new ReResolvingInputSourceWrapper(this.entityResolver, this.log, resolvedInputSource, pId, sId);
return new ReResolvingInputSourceWrapper(this.entityResolver, this.disableSystemIdResolution, this.log, resolvedInputSource, pId, sId);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -16,43 +16,48 @@

public class ReResolvingInputSourceWrapper extends InputSource {

private final EntityResolver entityResolver;
private final EntityResolver entityResolver;

private final boolean disableSystemIdResolution;

private final Log log;

private final InputSource inputSource;
private final InputSource inputSource;

public ReResolvingInputSourceWrapper(EntityResolver entityResolver, Log log,
InputSource inputSource, String publicId, String systemId) {
this.entityResolver = entityResolver;
public ReResolvingInputSourceWrapper(EntityResolver entityResolver, boolean disableSystemIdResolution,
Log log, InputSource inputSource, String publicId, String systemId) {
this.entityResolver = entityResolver;
this.disableSystemIdResolution = disableSystemIdResolution;
this.log = log;
this.inputSource = inputSource;
this.setPublicId(publicId);
this.setSystemId(systemId);
}
this.inputSource = inputSource;
this.setPublicId(publicId);
this.setSystemId(systemId);
}

@Override
public String getSystemId() {
String systemId = super.getSystemId();
String callerClassName = getCallerClassName();
if (callerClassName.endsWith("domforest")) {
log.debug("ReResolvingInputSourceWrapper : Handling DOMForest xjc 2.3.4+ change");
// DomForest checks now if file in initial systemId exists and override it if it doesnt
// --> This breaks CatalogResolution (JT-306)
// Do the check here, and if file doesn't exist, return the inputSource.systemId instead,
// which is the resolved systemId of the resource
try {
URI uri = new URI(systemId);
if ("file".equals(uri.getScheme())) {
if (!Files.exists(Paths.get(uri))) {
log.debug("ReResolvingInputSourceWrapper : Initial systemId "
+ systemId + " is file, and does not exist"
+ ", returning inputSource.getSystemId() as systemId (" + inputSource.getSystemId() + ")");
systemId = inputSource.getSystemId();
if (!disableSystemIdResolution) {
String callerClassName = getCallerClassName();
if (callerClassName.endsWith("domforest")) {
log.debug("ReResolvingInputSourceWrapper : Handling DOMForest xjc 2.3.4+ change");
// DomForest checks now if file in initial systemId exists and override it if it doesnt
// --> This breaks CatalogResolution (JT-306)
// Do the check here, and if file doesn't exist, return the inputSource.systemId instead,
// which is the resolved systemId of the resource
try {
URI uri = new URI(systemId);
if ("file".equals(uri.getScheme())) {
if (!Files.exists(Paths.get(uri))) {
log.debug("ReResolvingInputSourceWrapper : Initial systemId "
+ systemId + " is file, and does not exist"
+ ", returning inputSource.getSystemId() as systemId (" + inputSource.getSystemId() + ")");
systemId = inputSource.getSystemId();
}
}
} catch (URISyntaxException ex) {
//ignore, let it be handled by parser as is
}
} catch (URISyntaxException ex) {
//ignore, let it be handled by parser as is
}
}
return systemId;
Expand Down
1 change: 1 addition & 0 deletions maven-plugin/tests/issues/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@
<markGenerated>true</markGenerated>
<!-- Issue #81 -->
<accessExternalSchema>file</accessExternalSchema>
<disableSystemIdResolution>true</disableSystemIdResolution>
<!-- Issue #99 -->
<otherDepends>
<file>src/main/resources/depends.txt</file>
Expand Down

0 comments on commit b148894

Please sign in to comment.