From a35af334cec87aa26c7f4b9b8cfa91b0e5dd9fa1 Mon Sep 17 00:00:00 2001 From: Jean-Baptiste Mille Date: Thu, 21 Sep 2023 13:44:26 +0200 Subject: [PATCH 1/4] Support configuration of P2 mirrors in maven plugin (fixes #1697) --- .../spotless/extra/EquoBasedStepBuilder.java | 7 +++++ .../com/diffplug/spotless/extra/P2Mirror.java | 30 +++++++++++++++++++ .../spotless/maven/cpp/EclipseCdt.java | 7 +++++ .../spotless/maven/groovy/GrEclipse.java | 7 +++++ .../diffplug/spotless/maven/java/Eclipse.java | 7 +++++ 5 files changed, 58 insertions(+) create mode 100644 lib-extra/src/main/java/com/diffplug/spotless/extra/P2Mirror.java diff --git a/lib-extra/src/main/java/com/diffplug/spotless/extra/EquoBasedStepBuilder.java b/lib-extra/src/main/java/com/diffplug/spotless/extra/EquoBasedStepBuilder.java index 586deeb5bf..22ba268426 100644 --- a/lib-extra/src/main/java/com/diffplug/spotless/extra/EquoBasedStepBuilder.java +++ b/lib-extra/src/main/java/com/diffplug/spotless/extra/EquoBasedStepBuilder.java @@ -15,10 +15,13 @@ */ package com.diffplug.spotless.extra; +import static java.util.stream.Collectors.toMap; + import java.io.File; import java.io.IOException; import java.io.Serializable; import java.util.ArrayList; +import java.util.Collection; import java.util.List; import java.util.Map; import java.util.Properties; @@ -76,6 +79,10 @@ public void setP2Mirrors(Map p2Mirrors) { this.p2Mirrors = Map.copyOf(p2Mirrors); } + public void setP2Mirrors(Collection p2Mirrors) { + this.p2Mirrors = p2Mirrors.stream().collect(toMap(P2Mirror::getPrefix, P2Mirror::getUrl)); + } + /** Returns the FormatterStep (whose state will be calculated lazily). */ public FormatterStep build() { return FormatterStep.createLazy(formatterName, this::get, stateToFormatter); diff --git a/lib-extra/src/main/java/com/diffplug/spotless/extra/P2Mirror.java b/lib-extra/src/main/java/com/diffplug/spotless/extra/P2Mirror.java new file mode 100644 index 0000000000..f6ce6727b2 --- /dev/null +++ b/lib-extra/src/main/java/com/diffplug/spotless/extra/P2Mirror.java @@ -0,0 +1,30 @@ +/* + * Copyright 2023 DiffPlug + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package com.diffplug.spotless.extra; + +public class P2Mirror { + + private String prefix; + private String url; + + public String getPrefix() { + return prefix; + } + + public String getUrl() { + return url; + } +} diff --git a/plugin-maven/src/main/java/com/diffplug/spotless/maven/cpp/EclipseCdt.java b/plugin-maven/src/main/java/com/diffplug/spotless/maven/cpp/EclipseCdt.java index a92e7b2423..92f4229ed3 100644 --- a/plugin-maven/src/main/java/com/diffplug/spotless/maven/cpp/EclipseCdt.java +++ b/plugin-maven/src/main/java/com/diffplug/spotless/maven/cpp/EclipseCdt.java @@ -16,12 +16,15 @@ package com.diffplug.spotless.maven.cpp; import java.io.File; +import java.util.ArrayList; import java.util.Arrays; +import java.util.List; import org.apache.maven.plugins.annotations.Parameter; import com.diffplug.spotless.FormatterStep; import com.diffplug.spotless.extra.EquoBasedStepBuilder; +import com.diffplug.spotless.extra.P2Mirror; import com.diffplug.spotless.extra.cpp.EclipseCdtFormatterStep; import com.diffplug.spotless.maven.FormatterStepConfig; import com.diffplug.spotless.maven.FormatterStepFactory; @@ -34,6 +37,9 @@ public class EclipseCdt implements FormatterStepFactory { @Parameter private String version; + @Parameter + private List p2Mirrors = new ArrayList<>(); + @Override public FormatterStep newFormatterStep(FormatterStepConfig stepConfig) { EquoBasedStepBuilder eclipseConfig = EclipseCdtFormatterStep.createBuilder(stepConfig.getProvisioner()); @@ -42,6 +48,7 @@ public FormatterStep newFormatterStep(FormatterStepConfig stepConfig) { File settingsFile = stepConfig.getFileLocator().locateFile(file); eclipseConfig.setPreferences(Arrays.asList(settingsFile)); } + eclipseConfig.setP2Mirrors(p2Mirrors); return eclipseConfig.build(); } } diff --git a/plugin-maven/src/main/java/com/diffplug/spotless/maven/groovy/GrEclipse.java b/plugin-maven/src/main/java/com/diffplug/spotless/maven/groovy/GrEclipse.java index 8836993cce..67ab40fbf2 100644 --- a/plugin-maven/src/main/java/com/diffplug/spotless/maven/groovy/GrEclipse.java +++ b/plugin-maven/src/main/java/com/diffplug/spotless/maven/groovy/GrEclipse.java @@ -16,12 +16,15 @@ package com.diffplug.spotless.maven.groovy; import java.io.File; +import java.util.ArrayList; import java.util.Arrays; +import java.util.List; import org.apache.maven.plugins.annotations.Parameter; import com.diffplug.spotless.FormatterStep; import com.diffplug.spotless.extra.EquoBasedStepBuilder; +import com.diffplug.spotless.extra.P2Mirror; import com.diffplug.spotless.extra.groovy.GrEclipseFormatterStep; import com.diffplug.spotless.maven.FormatterStepConfig; import com.diffplug.spotless.maven.FormatterStepFactory; @@ -34,6 +37,9 @@ public class GrEclipse implements FormatterStepFactory { @Parameter private String version; + @Parameter + private List p2Mirrors = new ArrayList<>(); + @Override public FormatterStep newFormatterStep(FormatterStepConfig stepConfig) { EquoBasedStepBuilder grEclipseConfig = GrEclipseFormatterStep.createBuilder(stepConfig.getProvisioner()); @@ -42,6 +48,7 @@ public FormatterStep newFormatterStep(FormatterStepConfig stepConfig) { File settingsFile = stepConfig.getFileLocator().locateFile(file); grEclipseConfig.setPreferences(Arrays.asList(settingsFile)); } + grEclipseConfig.setP2Mirrors(p2Mirrors); return grEclipseConfig.build(); } } diff --git a/plugin-maven/src/main/java/com/diffplug/spotless/maven/java/Eclipse.java b/plugin-maven/src/main/java/com/diffplug/spotless/maven/java/Eclipse.java index e30a4faad9..8d5869cc8e 100644 --- a/plugin-maven/src/main/java/com/diffplug/spotless/maven/java/Eclipse.java +++ b/plugin-maven/src/main/java/com/diffplug/spotless/maven/java/Eclipse.java @@ -16,12 +16,15 @@ package com.diffplug.spotless.maven.java; import java.io.File; +import java.util.ArrayList; import java.util.Arrays; +import java.util.List; import org.apache.maven.plugins.annotations.Parameter; import com.diffplug.spotless.FormatterStep; import com.diffplug.spotless.extra.EquoBasedStepBuilder; +import com.diffplug.spotless.extra.P2Mirror; import com.diffplug.spotless.extra.java.EclipseJdtFormatterStep; import com.diffplug.spotless.maven.FormatterStepConfig; import com.diffplug.spotless.maven.FormatterStepFactory; @@ -34,6 +37,9 @@ public class Eclipse implements FormatterStepFactory { @Parameter private String version; + @Parameter + private List p2Mirrors = new ArrayList<>(); + @Override public FormatterStep newFormatterStep(FormatterStepConfig stepConfig) { EquoBasedStepBuilder eclipseConfig = EclipseJdtFormatterStep.createBuilder(stepConfig.getProvisioner()); @@ -42,6 +48,7 @@ public FormatterStep newFormatterStep(FormatterStepConfig stepConfig) { File settingsFile = stepConfig.getFileLocator().locateFile(file); eclipseConfig.setPreferences(Arrays.asList(settingsFile)); } + eclipseConfig.setP2Mirrors(p2Mirrors); return eclipseConfig.build(); } } From d0fca7a14d8513883c53f2f1a845fb6becc29267 Mon Sep 17 00:00:00 2001 From: Jean-Baptiste Mille Date: Thu, 21 Sep 2023 13:54:23 +0200 Subject: [PATCH 2/4] Update changelog --- CHANGES.md | 1 + plugin-maven/CHANGES.md | 13 +++++++++++++ 2 files changed, 14 insertions(+) diff --git a/CHANGES.md b/CHANGES.md index 71cde3f643..24dfc66c39 100644 --- a/CHANGES.md +++ b/CHANGES.md @@ -14,6 +14,7 @@ We adhere to the [keepachangelog](https://keepachangelog.com/en/1.0.0/) format ( * Add support for biome. The Rome project [was renamed to Biome](https://biomejs.dev/blog/annoucing-biome/). The configuration is still the same, but you should switch to the new `biome` tag / function and adjust the version accordingly. ([#1804](https://github.com/diffplug/spotless/issues/1804)). +* Support configuration of mirrors for P2 repositories in maven DSL ([#1697](https://github.com/diffplug/spotless/issues/1697)). ### Fixed * Added support for plugins when using Prettier version `3.0.0` and newer. ([#1802](https://github.com/diffplug/spotless/pull/1802)) ### Changes diff --git a/plugin-maven/CHANGES.md b/plugin-maven/CHANGES.md index 72d1e502a1..5a75a717a0 100644 --- a/plugin-maven/CHANGES.md +++ b/plugin-maven/CHANGES.md @@ -7,6 +7,19 @@ We adhere to the [keepachangelog](https://keepachangelog.com/en/1.0.0/) format ( * Add support for biome. The Rome project [was renamed to Biome](https://biomejs.dev/blog/annoucing-biome/). The configuration is still the same, but you should switch to the new `` tag and adjust the version accordingly. ([#1804](https://github.com/diffplug/spotless/issues/1804)). +* Support configuration of mirrors for P2 repositories ([#1697](https://github.com/diffplug/spotless/issues/1697)): + ``` + + + + https://download.eclipse.org/ + https://some.internal.mirror/eclipse + + + + ``` + Mirrors are selected by prefix match, for example `https://download.eclipse.org/eclipse/updates/4.26/` will be redirected to `https://some.internal.mirror/eclipse/eclipse/updates/4.26/`. + The same configuration exists for `` and ``. ### Fixed * Added support for plugins when using Prettier version `3.0.0` and newer. ([#1802](https://github.com/diffplug/spotless/pull/1802)) ### Changes From 3562e49ef862e53678fdc02fd3280d5a4f249fb9 Mon Sep 17 00:00:00 2001 From: Ned Twigg Date: Thu, 28 Sep 2023 09:19:51 -0700 Subject: [PATCH 3/4] Bump solstice to latest. --- .../java/com/diffplug/spotless/extra/EquoBasedStepBuilder.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib-extra/src/main/java/com/diffplug/spotless/extra/EquoBasedStepBuilder.java b/lib-extra/src/main/java/com/diffplug/spotless/extra/EquoBasedStepBuilder.java index 22ba268426..2d62e25355 100644 --- a/lib-extra/src/main/java/com/diffplug/spotless/extra/EquoBasedStepBuilder.java +++ b/lib-extra/src/main/java/com/diffplug/spotless/extra/EquoBasedStepBuilder.java @@ -117,7 +117,7 @@ EquoBasedStepBuilder.State get() throws Exception { } var classpath = new ArrayList(); var mavenDeps = new ArrayList(); - mavenDeps.add("dev.equo.ide:solstice:1.3.1"); + mavenDeps.add("dev.equo.ide:solstice:1.7.3"); mavenDeps.add("com.diffplug.durian:durian-swt.os:4.2.0"); mavenDeps.addAll(query.getJarsOnMavenCentral()); classpath.addAll(mavenProvisioner.provisionWithTransitives(false, mavenDeps)); From 6271c51fd85f4450e0cc0a0c7faa2a0f4e976ca6 Mon Sep 17 00:00:00 2001 From: Ned Twigg Date: Thu, 28 Sep 2023 10:22:05 -0700 Subject: [PATCH 4/4] Fix findbugs warnings. --- .../src/main/java/com/diffplug/spotless/extra/P2Mirror.java | 3 +++ 1 file changed, 3 insertions(+) diff --git a/lib-extra/src/main/java/com/diffplug/spotless/extra/P2Mirror.java b/lib-extra/src/main/java/com/diffplug/spotless/extra/P2Mirror.java index f6ce6727b2..172857422b 100644 --- a/lib-extra/src/main/java/com/diffplug/spotless/extra/P2Mirror.java +++ b/lib-extra/src/main/java/com/diffplug/spotless/extra/P2Mirror.java @@ -15,6 +15,9 @@ */ package com.diffplug.spotless.extra; +import edu.umd.cs.findbugs.annotations.SuppressFBWarnings; + +@SuppressFBWarnings("UWF_UNWRITTEN_FIELD") public class P2Mirror { private String prefix;