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

P2 mirror for maven plugin #1821

Merged
merged 5 commits into from
Sep 28, 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
5 changes: 3 additions & 2 deletions CHANGES.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,11 @@ We adhere to the [keepachangelog](https://keepachangelog.com/en/1.0.0/) format (

## [Unreleased]
### Added
* Add support for biome. The Rome project [was renamed to Biome](https://biomejs.dev/blog/annoucing-biome/).
* 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)).
* Add support for `google-java-format`'s `skip-javadoc-formatting` option. ([#1793](https://github.com/diffplug/spotless/pull/1793))
* Support for `google-java-format`'s `skip-javadoc-formatting` option. ([#1793](https://github.com/diffplug/spotless/pull/1793))
* Support configuration of mirrors for P2 repositories in maven DSL ([#1697](https://github.com/diffplug/spotless/issues/1697)).
### Fixed
* Fix support for plugins when using Prettier version `3.0.0` and newer. ([#1802](https://github.com/diffplug/spotless/pull/1802))
### Changes
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -76,6 +79,10 @@ public void setP2Mirrors(Map<String, String> p2Mirrors) {
this.p2Mirrors = Map.copyOf(p2Mirrors);
}

public void setP2Mirrors(Collection<P2Mirror> 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);
Expand Down Expand Up @@ -110,7 +117,7 @@ EquoBasedStepBuilder.State get() throws Exception {
}
var classpath = new ArrayList<File>();
var mavenDeps = new ArrayList<String>();
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));
Expand Down
33 changes: 33 additions & 0 deletions lib-extra/src/main/java/com/diffplug/spotless/extra/P2Mirror.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
/*
* 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;

import edu.umd.cs.findbugs.annotations.SuppressFBWarnings;

@SuppressFBWarnings("UWF_UNWRITTEN_FIELD")
public class P2Mirror {

private String prefix;
private String url;

public String getPrefix() {
return prefix;
}

public String getUrl() {
return url;
}
}
13 changes: 13 additions & 0 deletions plugin-maven/CHANGES.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,19 @@ We adhere to the [keepachangelog](https://keepachangelog.com/en/1.0.0/) format (
* Added 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 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)):
```
<eclipse>
<p2Mirrors>
<p2Mirror>
<prefix>https://download.eclipse.org/</prefix>
<url>https://some.internal.mirror/eclipse</url>
</p2Mirror>
</p2Mirrors>
</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 `<greclipse>` and `<eclipseCdt>`.
### Fixed
* Fixed support for plugins when using Prettier version `3.0.0` and newer. ([#1802](https://github.com/diffplug/spotless/pull/1802))
### Changes
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -34,6 +37,9 @@ public class EclipseCdt implements FormatterStepFactory {
@Parameter
private String version;

@Parameter
private List<P2Mirror> p2Mirrors = new ArrayList<>();

@Override
public FormatterStep newFormatterStep(FormatterStepConfig stepConfig) {
EquoBasedStepBuilder eclipseConfig = EclipseCdtFormatterStep.createBuilder(stepConfig.getProvisioner());
Expand All @@ -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();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -34,6 +37,9 @@ public class GrEclipse implements FormatterStepFactory {
@Parameter
private String version;

@Parameter
private List<P2Mirror> p2Mirrors = new ArrayList<>();

@Override
public FormatterStep newFormatterStep(FormatterStepConfig stepConfig) {
EquoBasedStepBuilder grEclipseConfig = GrEclipseFormatterStep.createBuilder(stepConfig.getProvisioner());
Expand All @@ -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();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -34,6 +37,9 @@ public class Eclipse implements FormatterStepFactory {
@Parameter
private String version;

@Parameter
private List<P2Mirror> p2Mirrors = new ArrayList<>();

@Override
public FormatterStep newFormatterStep(FormatterStepConfig stepConfig) {
EquoBasedStepBuilder eclipseConfig = EclipseJdtFormatterStep.createBuilder(stepConfig.getProvisioner());
Expand All @@ -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();
}
}