Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[#19] Fix relative Catalog Resolution #361

Merged
merged 1 commit into from
Sep 8, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -446,6 +446,19 @@ public boolean getDisableSystemIdResolution() {
public void setDisableSystemIdResolution(boolean disableSystemIdResolution) {
this.disableSystemIdResolution = disableSystemIdResolution;
}
/**
* If 'true', the fix for issue #19 will be applied.
*/
@Parameter(defaultValue = "false", property = "maven.xjc2.relativeCatalogResolution")
private boolean relativeCatalogResolution;

public boolean getRelativeCatalogResolution() {
return relativeCatalogResolution;
laurentschoelens marked this conversation as resolved.
Show resolved Hide resolved
}

public void getRelativeCatalogResolution(boolean relativeCatalogResolution) {
laurentschoelens marked this conversation as resolved.
Show resolved Hide resolved
this.relativeCatalogResolution = relativeCatalogResolution;
}

/**
* <p>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,7 @@
import org.jvnet.jaxb.maven.resolver.tools.LoggingCatalogResolver;
import org.jvnet.jaxb.maven.resolver.tools.MavenCatalogResolver;
import org.jvnet.jaxb.maven.resolver.tools.ReResolvingEntityResolverWrapper;
import org.jvnet.jaxb.maven.resolver.tools.RelativeCatalog;
import org.jvnet.jaxb.maven.util.ArtifactUtils;
import org.jvnet.jaxb.maven.util.CollectionUtils;
import org.jvnet.jaxb.maven.util.IOUtils;
Expand Down Expand Up @@ -895,6 +896,9 @@ protected CatalogResolver createCatalogResolver() throws MojoExecutionException
final CatalogManager catalogManager = new CatalogManager();
catalogManager.setIgnoreMissingProperties(true);
catalogManager.setUseStaticCatalog(false);
if (getRelativeCatalogResolution()) {
catalogManager.setCatalogClassName(RelativeCatalog.class.getName());
}
// TODO Logging
if (getLog().isDebugEnabled()) {
catalogManager.setVerbosity(Integer.MAX_VALUE);
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
package org.jvnet.jaxb.maven.resolver.tools;

import com.sun.org.apache.xml.internal.resolver.Catalog;
import com.sun.org.apache.xml.internal.resolver.CatalogEntry;
import com.sun.org.apache.xml.internal.resolver.CatalogException;

import java.util.Vector;

public class RelativeCatalog extends Catalog {
@Override
public void addEntry(CatalogEntry entry) {
super.addEntry(entry);
if (entry.getEntryType() == REWRITE_SYSTEM) {
try {
if (entry.getEntryArg(0) != null && entry.getEntryArg(0).startsWith("..")) {
// generate new entry for catalog
Vector<String> args = new Vector<>(2);
args.addElement(makeAbsolute(normalizeURI(entry.getEntryArg(0))));
args.addElement(makeAbsolute(normalizeURI(entry.getEntryArg(1))));

CatalogEntry duplicatedEntry = new CatalogEntry(entry.getEntryType(), args);

catalogManager.debug.message(4, "REWRITE_SYSTEM",
duplicatedEntry.getEntryArg(0), duplicatedEntry.getEntryArg(1));

catalogEntries.addElement(duplicatedEntry);
}
} catch (CatalogException e) {
catalogManager.debug.message(1, "REWRITE_SYSTEM relative fix failed");
}
}
}
}
13 changes: 12 additions & 1 deletion maven-plugin/tests/gh-issue-19/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
<artifactId>jaxb-maven-plugin-tests-gh-issue-19</artifactId>
<packaging>pom</packaging>
<name>JAXB Tools :: Maven Plugin :: Test [GitHub Issue #19]</name>
<description>Test project for catalog relative uri resolution.</description>
<modules>
<module>a</module>
<module>b</module>
Expand All @@ -18,10 +19,20 @@
<dependency>
<groupId>org.glassfish.jaxb</groupId>
<artifactId>jaxb-runtime</artifactId>
<version>${jaxb.version}</version>
</dependency>
</dependencies>
<build>
<defaultGoal>test</defaultGoal>
<pluginManagement>
<plugins>
<plugin>
<groupId>org.jvnet.jaxb</groupId>
<artifactId>jaxb-maven-plugin</artifactId>
<configuration>
<relativeCatalogResolution>true</relativeCatalogResolution>
</configuration>
</plugin>
</plugins>
</pluginManagement>
</build>
</project>
1 change: 1 addition & 0 deletions maven-plugin/tests/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@
<module>MAVEN_JAXB2_PLUGIN-86</module>
<module>MAVEN_JAXB2_PLUGIN-87</module>
<module>gh-issue-16</module>
<module>gh-issue-19</module>
<module>gh-issue-22</module>
<module>gh-issue-23</module>
<module>gh-issue-58</module>
Expand Down