Skip to content

Commit 6c1df6d

Browse files
authored
P2 mirror for maven plugin (#1821)
2 parents 03d3336 + 6271c51 commit 6c1df6d

File tree

7 files changed

+78
-3
lines changed

7 files changed

+78
-3
lines changed

CHANGES.md

+3-2
Original file line numberDiff line numberDiff line change
@@ -11,10 +11,11 @@ We adhere to the [keepachangelog](https://keepachangelog.com/en/1.0.0/) format (
1111

1212
## [Unreleased]
1313
### Added
14-
* Add support for biome. The Rome project [was renamed to Biome](https://biomejs.dev/blog/annoucing-biome/).
14+
* Support for biome. The Rome project [was renamed to Biome](https://biomejs.dev/blog/annoucing-biome/).
1515
The configuration is still the same, but you should switch to the new `biome` tag / function and adjust
1616
the version accordingly. ([#1804](https://github.com/diffplug/spotless/issues/1804)).
17-
* Add support for `google-java-format`'s `skip-javadoc-formatting` option. ([#1793](https://github.com/diffplug/spotless/pull/1793))
17+
* Support for `google-java-format`'s `skip-javadoc-formatting` option. ([#1793](https://github.com/diffplug/spotless/pull/1793))
18+
* Support configuration of mirrors for P2 repositories in maven DSL ([#1697](https://github.com/diffplug/spotless/issues/1697)).
1819
### Fixed
1920
* Fix support for plugins when using Prettier version `3.0.0` and newer. ([#1802](https://github.com/diffplug/spotless/pull/1802))
2021
### Changes

lib-extra/src/main/java/com/diffplug/spotless/extra/EquoBasedStepBuilder.java

+8-1
Original file line numberDiff line numberDiff line change
@@ -15,10 +15,13 @@
1515
*/
1616
package com.diffplug.spotless.extra;
1717

18+
import static java.util.stream.Collectors.toMap;
19+
1820
import java.io.File;
1921
import java.io.IOException;
2022
import java.io.Serializable;
2123
import java.util.ArrayList;
24+
import java.util.Collection;
2225
import java.util.List;
2326
import java.util.Map;
2427
import java.util.Properties;
@@ -76,6 +79,10 @@ public void setP2Mirrors(Map<String, String> p2Mirrors) {
7679
this.p2Mirrors = Map.copyOf(p2Mirrors);
7780
}
7881

82+
public void setP2Mirrors(Collection<P2Mirror> p2Mirrors) {
83+
this.p2Mirrors = p2Mirrors.stream().collect(toMap(P2Mirror::getPrefix, P2Mirror::getUrl));
84+
}
85+
7986
/** Returns the FormatterStep (whose state will be calculated lazily). */
8087
public FormatterStep build() {
8188
return FormatterStep.createLazy(formatterName, this::get, stateToFormatter);
@@ -110,7 +117,7 @@ EquoBasedStepBuilder.State get() throws Exception {
110117
}
111118
var classpath = new ArrayList<File>();
112119
var mavenDeps = new ArrayList<String>();
113-
mavenDeps.add("dev.equo.ide:solstice:1.3.1");
120+
mavenDeps.add("dev.equo.ide:solstice:1.7.3");
114121
mavenDeps.add("com.diffplug.durian:durian-swt.os:4.2.0");
115122
mavenDeps.addAll(query.getJarsOnMavenCentral());
116123
classpath.addAll(mavenProvisioner.provisionWithTransitives(false, mavenDeps));
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
/*
2+
* Copyright 2023 DiffPlug
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
package com.diffplug.spotless.extra;
17+
18+
import edu.umd.cs.findbugs.annotations.SuppressFBWarnings;
19+
20+
@SuppressFBWarnings("UWF_UNWRITTEN_FIELD")
21+
public class P2Mirror {
22+
23+
private String prefix;
24+
private String url;
25+
26+
public String getPrefix() {
27+
return prefix;
28+
}
29+
30+
public String getUrl() {
31+
return url;
32+
}
33+
}

plugin-maven/CHANGES.md

+13
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,19 @@ We adhere to the [keepachangelog](https://keepachangelog.com/en/1.0.0/) format (
88
* Added support for biome. The Rome project [was renamed to Biome](https://biomejs.dev/blog/annoucing-biome/).
99
The configuration is still the same, but you should switch to the new `<biome>` tag and adjust
1010
the version accordingly. ([#1804](https://github.com/diffplug/spotless/issues/1804)).
11+
* Support configuration of mirrors for P2 repositories ([#1697](https://github.com/diffplug/spotless/issues/1697)):
12+
```
13+
<eclipse>
14+
<p2Mirrors>
15+
<p2Mirror>
16+
<prefix>https://download.eclipse.org/</prefix>
17+
<url>https://some.internal.mirror/eclipse</url>
18+
</p2Mirror>
19+
</p2Mirrors>
20+
</eclipse>
21+
```
22+
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/`.
23+
The same configuration exists for `<greclipse>` and `<eclipseCdt>`.
1124
### Fixed
1225
* Fixed support for plugins when using Prettier version `3.0.0` and newer. ([#1802](https://github.com/diffplug/spotless/pull/1802))
1326
### Changes

plugin-maven/src/main/java/com/diffplug/spotless/maven/cpp/EclipseCdt.java

+7
Original file line numberDiff line numberDiff line change
@@ -16,12 +16,15 @@
1616
package com.diffplug.spotless.maven.cpp;
1717

1818
import java.io.File;
19+
import java.util.ArrayList;
1920
import java.util.Arrays;
21+
import java.util.List;
2022

2123
import org.apache.maven.plugins.annotations.Parameter;
2224

2325
import com.diffplug.spotless.FormatterStep;
2426
import com.diffplug.spotless.extra.EquoBasedStepBuilder;
27+
import com.diffplug.spotless.extra.P2Mirror;
2528
import com.diffplug.spotless.extra.cpp.EclipseCdtFormatterStep;
2629
import com.diffplug.spotless.maven.FormatterStepConfig;
2730
import com.diffplug.spotless.maven.FormatterStepFactory;
@@ -34,6 +37,9 @@ public class EclipseCdt implements FormatterStepFactory {
3437
@Parameter
3538
private String version;
3639

40+
@Parameter
41+
private List<P2Mirror> p2Mirrors = new ArrayList<>();
42+
3743
@Override
3844
public FormatterStep newFormatterStep(FormatterStepConfig stepConfig) {
3945
EquoBasedStepBuilder eclipseConfig = EclipseCdtFormatterStep.createBuilder(stepConfig.getProvisioner());
@@ -42,6 +48,7 @@ public FormatterStep newFormatterStep(FormatterStepConfig stepConfig) {
4248
File settingsFile = stepConfig.getFileLocator().locateFile(file);
4349
eclipseConfig.setPreferences(Arrays.asList(settingsFile));
4450
}
51+
eclipseConfig.setP2Mirrors(p2Mirrors);
4552
return eclipseConfig.build();
4653
}
4754
}

plugin-maven/src/main/java/com/diffplug/spotless/maven/groovy/GrEclipse.java

+7
Original file line numberDiff line numberDiff line change
@@ -16,12 +16,15 @@
1616
package com.diffplug.spotless.maven.groovy;
1717

1818
import java.io.File;
19+
import java.util.ArrayList;
1920
import java.util.Arrays;
21+
import java.util.List;
2022

2123
import org.apache.maven.plugins.annotations.Parameter;
2224

2325
import com.diffplug.spotless.FormatterStep;
2426
import com.diffplug.spotless.extra.EquoBasedStepBuilder;
27+
import com.diffplug.spotless.extra.P2Mirror;
2528
import com.diffplug.spotless.extra.groovy.GrEclipseFormatterStep;
2629
import com.diffplug.spotless.maven.FormatterStepConfig;
2730
import com.diffplug.spotless.maven.FormatterStepFactory;
@@ -34,6 +37,9 @@ public class GrEclipse implements FormatterStepFactory {
3437
@Parameter
3538
private String version;
3639

40+
@Parameter
41+
private List<P2Mirror> p2Mirrors = new ArrayList<>();
42+
3743
@Override
3844
public FormatterStep newFormatterStep(FormatterStepConfig stepConfig) {
3945
EquoBasedStepBuilder grEclipseConfig = GrEclipseFormatterStep.createBuilder(stepConfig.getProvisioner());
@@ -42,6 +48,7 @@ public FormatterStep newFormatterStep(FormatterStepConfig stepConfig) {
4248
File settingsFile = stepConfig.getFileLocator().locateFile(file);
4349
grEclipseConfig.setPreferences(Arrays.asList(settingsFile));
4450
}
51+
grEclipseConfig.setP2Mirrors(p2Mirrors);
4552
return grEclipseConfig.build();
4653
}
4754
}

plugin-maven/src/main/java/com/diffplug/spotless/maven/java/Eclipse.java

+7
Original file line numberDiff line numberDiff line change
@@ -16,12 +16,15 @@
1616
package com.diffplug.spotless.maven.java;
1717

1818
import java.io.File;
19+
import java.util.ArrayList;
1920
import java.util.Arrays;
21+
import java.util.List;
2022

2123
import org.apache.maven.plugins.annotations.Parameter;
2224

2325
import com.diffplug.spotless.FormatterStep;
2426
import com.diffplug.spotless.extra.EquoBasedStepBuilder;
27+
import com.diffplug.spotless.extra.P2Mirror;
2528
import com.diffplug.spotless.extra.java.EclipseJdtFormatterStep;
2629
import com.diffplug.spotless.maven.FormatterStepConfig;
2730
import com.diffplug.spotless.maven.FormatterStepFactory;
@@ -34,6 +37,9 @@ public class Eclipse implements FormatterStepFactory {
3437
@Parameter
3538
private String version;
3639

40+
@Parameter
41+
private List<P2Mirror> p2Mirrors = new ArrayList<>();
42+
3743
@Override
3844
public FormatterStep newFormatterStep(FormatterStepConfig stepConfig) {
3945
EquoBasedStepBuilder eclipseConfig = EclipseJdtFormatterStep.createBuilder(stepConfig.getProvisioner());
@@ -42,6 +48,7 @@ public FormatterStep newFormatterStep(FormatterStepConfig stepConfig) {
4248
File settingsFile = stepConfig.getFileLocator().locateFile(file);
4349
eclipseConfig.setPreferences(Arrays.asList(settingsFile));
4450
}
51+
eclipseConfig.setP2Mirrors(p2Mirrors);
4552
return eclipseConfig.build();
4653
}
4754
}

0 commit comments

Comments
 (0)