Skip to content

Commit

Permalink
[MRESOLVER-602][MRESOLVER-603] Expose redirect config for apache tran…
Browse files Browse the repository at this point in the history
…sport (#581)

The Apache transport `maxRedirects` and `followRedirects` exposed. Also return some missing config doco. But all this exposed another issue with doco generator, so fixed that as well, that in turn, required more (mostly Javadoc) fixes.

And sorry for "overloading" this PR with unrelated (mostly side or Javadoc) related fixes, as doco generator fixes made me run site, that on other hand revealed that master site is not buildable 😢 

---

https://issues.apache.org/jira/browse/MRESOLVER-602
https://issues.apache.org/jira/browse/MRESOLVER-603
  • Loading branch information
cstamas authored Oct 12, 2024
1 parent 2089216 commit f65d0ac
Show file tree
Hide file tree
Showing 8 changed files with 178 additions and 75 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -142,6 +142,28 @@ public final class ConfigurationProperties {
*/
public static final String CACHED_PRIORITIES = PREFIX_PRIORITY + "cached";

/**
* The priority to use for a certain extension class. {@code <class>} can either be the fully qualified
* name or the simple name of a class. If the class name ends with Factory that suffix could optionally be left out.
* This configuration is used by {@code org.eclipse.aether.internal.impl.PrioritizedComponents} internal utility
* to sort classes by priority. This is reusable utility (so an extension can make use of it), but by default
* in "vanilla" Resolver following classes are sorted:
* <ul>
* <li>{@code org.eclipse.aether.spi.localrepo.LocalRepositoryManagerFactory}</li>
* <li>{@code org.eclipse.aether.spi.connector.RepositoryConnectorFactory}</li>
* <li>{@code org.eclipse.aether.spi.connector.layout.RepositoryLayoutFactory}</li>
* <li>{@code org.eclipse.aether.spi.connector.transport.TransporterFactory}</li>
* <li>{@code org.eclipse.aether.spi.artifact.decorator.ArtifactDecoratorFactory}</li>
* <li>{@code org.eclipse.aether.spi.artifact.generator.ArtifactGeneratorFactory}</li>
* <li>{@code org.eclipse.aether.impl.MetadataGeneratorFactory}</li>
* </ul>
*
* @configurationSource {@link RepositorySystemSession#getConfigProperties()}
* @configurationType {@link java.lang.Float}
* @configurationRepoIdSuffix No
*/
public static final String CLASS_PRIORITIES = PREFIX_PRIORITY + "<class>";

/**
* The default caching of priority components if {@link #CACHED_PRIORITIES} isn't set. Default value is {@code true}.
*
Expand Down Expand Up @@ -215,7 +237,7 @@ public final class ConfigurationProperties {
/**
* The request headers to use for HTTP-based repository connectors. The headers are specified using a
* {@code Map<String, String>}, mapping a header name to its value. Besides this general key, clients may also
* specify headers for a specific remote repository by appending the suffix {@code .<repoId>} to this key when
* specify headers for a specific remote repository by appending the suffix {@code .&lt;repoId&gt;} to this key when
* storing the headers map. The repository-specific headers map is supposed to be complete, i.e. is not merged with
* the general headers map.
*
Expand All @@ -227,7 +249,7 @@ public final class ConfigurationProperties {

/**
* The encoding/charset to use when exchanging credentials with HTTP servers. Besides this general key, clients may
* also specify the encoding for a specific remote repository by appending the suffix {@code .<repoId>} to this key
* also specify the encoding for a specific remote repository by appending the suffix {@code .&lt;repoId&gt;} to this key
* when storing the charset name.
*
* @configurationSource {@link RepositorySystemSession#getConfigProperties()}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ public interface Artifact {
* "1.0-SNAPSHOT", the artifact's version depends on the state of the artifact. Artifacts that have been resolved or
* deployed will usually have the meta version expanded.
* This may also return version ranges like "[1.0,2.0)". The exact syntax for (meta) versions and version ranges
* depends on the underlying provider (encapsulated in {@link RepositorySystem}).
* depends on the underlying provider (encapsulated in {@link org.eclipse.aether.RepositorySystem}).
*
* @return The version, never {@code null}.
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@
import org.apache.velocity.app.VelocityEngine;
import org.apache.velocity.runtime.resource.loader.ClasspathResourceLoader;
import org.jboss.forge.roaster.Roaster;
import org.jboss.forge.roaster.model.JavaDoc;
import org.jboss.forge.roaster.model.JavaDocCapable;
import org.jboss.forge.roaster.model.JavaDocTag;
import org.jboss.forge.roaster.model.JavaType;
Expand Down Expand Up @@ -96,7 +97,7 @@ public static void main(String[] args) throws Exception {
key,
defValue,
fqName,
f.getJavaDoc().getText(),
cleanseJavadoc(f),
nvl(getSince(f), ""),
getConfigurationSource(f),
configurationType,
Expand Down Expand Up @@ -125,6 +126,39 @@ public static void main(String[] args) throws Exception {
}
}

private static String cleanseJavadoc(FieldSource<JavaClassSource> javaClassSource) {
JavaDoc<FieldSource<JavaClassSource>> javaDoc = javaClassSource.getJavaDoc();
String[] text = javaDoc.getFullText().split("\n");
StringBuilder result = new StringBuilder();
for (String line : text) {
if (!line.startsWith("@") && !line.trim().isEmpty()) {
result.append(line);
}
}
return cleanseTags(result.toString());
}

private static String cleanseTags(String text) {
// {@code XXX} -> <pre>XXX</pre>
// {@link XXX} -> ??? pre for now
Pattern pattern = Pattern.compile("(\\{@\\w\\w\\w\\w (.+?)})");
Matcher matcher = pattern.matcher(text);
if (!matcher.find()) {
return text;
}
int prevEnd = 0;
StringBuilder result = new StringBuilder();
do {
result.append(text, prevEnd, matcher.start(1));
result.append("<code>");
result.append(matcher.group(2));
result.append("</code>");
prevEnd = matcher.end(1);
} while (matcher.find());
result.append(text, prevEnd, text.length());
return result.toString();
}

private static JavaType<?> parse(Path path) {
try {
return Roaster.parse(path.toFile());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,7 @@
import org.apache.http.impl.client.CloseableHttpClient;
import org.apache.http.impl.client.DefaultHttpRequestRetryHandler;
import org.apache.http.impl.client.HttpClientBuilder;
import org.apache.http.impl.client.LaxRedirectStrategy;
import org.apache.http.impl.client.StandardHttpRequestRetryHandler;
import org.apache.http.protocol.HttpContext;
import org.apache.http.util.EntityUtils;
Expand All @@ -105,10 +106,14 @@

import static java.util.Objects.requireNonNull;
import static org.eclipse.aether.spi.connector.transport.http.HttpConstants.CONTENT_RANGE_PATTERN;
import static org.eclipse.aether.transport.apache.ApacheTransporterConfigurationKeys.CONFIG_PROP_FOLLOW_REDIRECTS;
import static org.eclipse.aether.transport.apache.ApacheTransporterConfigurationKeys.CONFIG_PROP_HTTP_RETRY_HANDLER_NAME;
import static org.eclipse.aether.transport.apache.ApacheTransporterConfigurationKeys.CONFIG_PROP_HTTP_RETRY_HANDLER_REQUEST_SENT_ENABLED;
import static org.eclipse.aether.transport.apache.ApacheTransporterConfigurationKeys.CONFIG_PROP_MAX_REDIRECTS;
import static org.eclipse.aether.transport.apache.ApacheTransporterConfigurationKeys.CONFIG_PROP_USE_SYSTEM_PROPERTIES;
import static org.eclipse.aether.transport.apache.ApacheTransporterConfigurationKeys.DEFAULT_FOLLOW_REDIRECTS;
import static org.eclipse.aether.transport.apache.ApacheTransporterConfigurationKeys.DEFAULT_HTTP_RETRY_HANDLER_REQUEST_SENT_ENABLED;
import static org.eclipse.aether.transport.apache.ApacheTransporterConfigurationKeys.DEFAULT_MAX_REDIRECTS;
import static org.eclipse.aether.transport.apache.ApacheTransporterConfigurationKeys.DEFAULT_USE_SYSTEM_PROPERTIES;
import static org.eclipse.aether.transport.apache.ApacheTransporterConfigurationKeys.HTTP_RETRY_HANDLER_NAME_DEFAULT;
import static org.eclipse.aether.transport.apache.ApacheTransporterConfigurationKeys.HTTP_RETRY_HANDLER_NAME_STANDARD;
Expand Down Expand Up @@ -261,6 +266,16 @@ final class ApacheTransporter extends AbstractTransporter implements HttpTranspo
DEFAULT_HTTP_RETRY_HANDLER_REQUEST_SENT_ENABLED,
CONFIG_PROP_HTTP_RETRY_HANDLER_REQUEST_SENT_ENABLED + "." + repository.getId(),
CONFIG_PROP_HTTP_RETRY_HANDLER_REQUEST_SENT_ENABLED);
int maxRedirects = ConfigUtils.getInteger(
session,
DEFAULT_MAX_REDIRECTS,
CONFIG_PROP_MAX_REDIRECTS + "." + repository.getId(),
CONFIG_PROP_MAX_REDIRECTS);
boolean followRedirects = ConfigUtils.getBoolean(
session,
DEFAULT_FOLLOW_REDIRECTS,
CONFIG_PROP_FOLLOW_REDIRECTS + "." + repository.getId(),
CONFIG_PROP_FOLLOW_REDIRECTS);
String userAgent = ConfigUtils.getString(
session, ConfigurationProperties.DEFAULT_USER_AGENT, ConfigurationProperties.USER_AGENT);

Expand All @@ -275,6 +290,9 @@ final class ApacheTransporter extends AbstractTransporter implements HttpTranspo
SocketConfig socketConfig =
SocketConfig.custom().setSoTimeout(requestTimeout).build();
RequestConfig requestConfig = RequestConfig.custom()
.setMaxRedirects(maxRedirects)
.setRedirectsEnabled(followRedirects)
.setRelativeRedirectsAllowed(followRedirects)
.setConnectTimeout(connectTimeout)
.setConnectionRequestTimeout(connectTimeout)
.setLocalAddress(getHttpLocalAddress(session, repository))
Expand Down Expand Up @@ -306,6 +324,7 @@ final class ApacheTransporter extends AbstractTransporter implements HttpTranspo

HttpClientBuilder builder = HttpClientBuilder.create()
.setUserAgent(userAgent)
.setRedirectStrategy(LaxRedirectStrategy.INSTANCE)
.setDefaultSocketConfig(socketConfig)
.setDefaultRequestConfig(requestConfig)
.setServiceUnavailableRetryStrategy(serviceUnavailableRetryStrategy)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -95,4 +95,30 @@ private ApacheTransporterConfigurationKeys() {}
* @configurationType {@link java.lang.String}
*/
public static final String CONFIG_PROP_PROTOCOLS = CONFIG_PROPS_PREFIX + "https.protocols";

/**
* If enabled, Apache HttpClient will follow HTTP redirects.
*
* @configurationSource {@link RepositorySystemSession#getConfigProperties()}
* @configurationType {@link Boolean}
* @configurationDefaultValue {@link #DEFAULT_FOLLOW_REDIRECTS}
* @configurationRepoIdSuffix Yes
* @since 2.0.2
*/
public static final String CONFIG_PROP_FOLLOW_REDIRECTS = CONFIG_PROPS_PREFIX + "followRedirects";

public static final boolean DEFAULT_FOLLOW_REDIRECTS = true;

/**
* The max redirect count to follow.
*
* @configurationSource {@link RepositorySystemSession#getConfigProperties()}
* @configurationType {@link java.lang.Integer}
* @configurationDefaultValue {@link #DEFAULT_MAX_REDIRECTS}
* @configurationRepoIdSuffix Yes
* @since 2.0.2
*/
public static final String CONFIG_PROP_MAX_REDIRECTS = CONFIG_PROPS_PREFIX + "maxRedirects";

public static final int DEFAULT_MAX_REDIRECTS = 5;
}
Original file line number Diff line number Diff line change
Expand Up @@ -47,8 +47,7 @@ public final class JdkTransporterFactory implements HttpTransporterFactory {
private float priority = 10.0f;

@Inject
public JdkTransporterFactory(
ChecksumExtractor checksumExtractor, PathProcessor pathProcessor, JdkRFC9457Reporter rfc9457Reporter) {
public JdkTransporterFactory(ChecksumExtractor checksumExtractor, PathProcessor pathProcessor) {
// this is to equalize all Java version constructors to be same, so Supplier could work across all versions
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ public final class DependencyManagerUtils {
* The key in the repository session's {@link org.eclipse.aether.RepositorySystemSession#getConfigProperties()
* configuration properties} used to store a {@link Boolean} flag controlling the verbose mode for dependency
* management. If enabled, the original attributes of a dependency before its update due to dependency management
* will be recorded * in the node's {@link DependencyNode#getData() custom data} when building a dependency graph.
* will be recorded in the node's {@link DependencyNode#getData() custom data} when building a dependency graph.
*
* @configurationSource {@link RepositorySystemSession#getConfigProperties()}
* @configurationType {@link java.lang.Boolean}
Expand Down
Loading

0 comments on commit f65d0ac

Please sign in to comment.