Skip to content

Commit

Permalink
Allow configuration of P2 mirror for spotless (#64)
Browse files Browse the repository at this point in the history
This fixes #58
  • Loading branch information
jskov authored May 24, 2024
1 parent fed0622 commit 54b86f1
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 7 deletions.
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,8 @@ By default uses [this configuration](./src/main/resources/config/spotless/eclips
* `dk.mada.style.formatter.eclipse-config-path = null`
Optional path to an alternative eclipse formatter configuration file
This can be a URL; the content will be downloaded and cached (so if you want to update the content, you must change the URL)
* `dk.mada.style.formatter.eclipse-429-p2-url = null`
Optional URL to a P2 update repository containing Eclipse 4.29 (aka 2023.09) plugins.

**Null-checker**

Expand Down
15 changes: 9 additions & 6 deletions src/main/java/dk/mada/style/config/PluginConfiguration.java
Original file line number Diff line number Diff line change
Expand Up @@ -64,12 +64,14 @@ public record ErrorProneConfiguration(boolean enabled, boolean ignoreTestSource,
/**
* Formatter configuration.
*
* @param enabled flag to activate formatter
* @param include Ant-style pattern for sources to format
* @param exclude Ant-style pattern for sources to ignore
* @param eclipseConfigPath an optional path to an eclipse configuration file
* @param enabled flag to activate formatter
* @param include Ant-style pattern for sources to format
* @param exclude Ant-style pattern for sources to ignore
* @param eclipseConfigPath an optional path to an eclipse configuration file
* @param eclipse429P2mirror an optional URL to a eclipse update P2 repository
*/
public record FormatterConfiguration(boolean enabled, String include, String exclude, @Nullable String eclipseConfigPath) {
public record FormatterConfiguration(boolean enabled, String include, String exclude, @Nullable String eclipseConfigPath,
@Nullable String eclipse429P2mirror) {
}

/**
Expand Down Expand Up @@ -124,7 +126,8 @@ public PluginConfiguration(Project project) {
getBoolProperty("formatter.enabled", true),
getProperty("formatter.include", "src/main/java/**/*.java"),
getProperty("formatter.exclude", ""),
getNullableProperty("formatter.eclipse-config-path", null));
getNullableProperty("formatter.eclipse-config-path", null),
getNullableProperty("formatter.eclipse-429-p2-url", null));

nullcheckerConf = new NullcheckerConfiguration(
getBoolProperty("null-checker.enabled", true),
Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
package dk.mada.style.configurators;

import java.nio.file.Path;
import java.util.Map;

import org.gradle.api.logging.Logger;

import com.diffplug.gradle.spotless.JavaExtension;
import com.diffplug.gradle.spotless.JavaExtension.EclipseConfig;
import com.diffplug.gradle.spotless.SpotlessExtension;

import dk.mada.style.config.ConfigFileExtractor;
Expand Down Expand Up @@ -61,7 +63,14 @@ private void configureJava(JavaExtension je) {
je.target(include);
je.targetExclude(exclude);

je.eclipse().configFile(configFile);
EclipseConfig eclipseConfig = je.eclipse();
eclipseConfig.configFile(configFile);

String p2Mirror = formatterConfig.eclipse429P2mirror();
if (p2Mirror != null) {
eclipseConfig.withP2Mirrors(Map.of("https://download.eclipse.org/eclipse/updates/4.29/", p2Mirror));
}

je.formatAnnotations(); // Note that this *must* come after the java formatter configuration
}

Expand Down

0 comments on commit 54b86f1

Please sign in to comment.