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

Revert "Gradle wrapper scripts packed as resources" #4978

Closed
wants to merge 2 commits into from
Closed
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
31 changes: 19 additions & 12 deletions rewrite-core/src/main/java/org/openrewrite/remote/Remote.java
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,10 @@
* If a Checksum is provided it will be used to validate the integrity of the downloaded file.
*/
public interface Remote extends SourceFile {
URI getUri();

<R extends Remote> R withUri(URI uri);

/**
* Any text describing what this remote URI represents. Used to present human-readable results to an end user.
*/
Expand All @@ -62,6 +66,7 @@ default <T extends SourceFile> T withChecksum(@Nullable Checksum checksum) {
return (T) this;
}


/**
* Download the remote file
*
Expand Down Expand Up @@ -92,12 +97,16 @@ default <P> boolean isAcceptable(TreeVisitor<?, P> v, P p) {
return v.isAdaptableTo(RemoteVisitor.class);
}

static Builder builder(SourceFile before) {
return new Builder(before.getId(), before.getSourcePath(), before.getMarkers());
static Builder builder(SourceFile before, URI uri) {
return new Builder(before.getId(), before.getSourcePath(), before.getMarkers(), uri);
}

static Builder builder(Path sourcePath) {
return new Builder(Tree.randomId(), sourcePath, Markers.EMPTY);
static Builder builder(Path sourcePath, URI uri) {
return new Builder(Tree.randomId(), sourcePath, Markers.EMPTY, uri);
}

static Builder builder(UUID id, Path sourcePath, Markers markers, URI uri) {
return new Builder(id, sourcePath, markers, uri);
}

@Override
Expand All @@ -118,6 +127,7 @@ class Builder {
protected final UUID id;
protected final Path sourcePath;
protected final Markers markers;
protected final URI uri;

@Nullable
@Language("markdown")
Expand All @@ -134,10 +144,11 @@ class Builder {
@Nullable
FileAttributes fileAttributes;

Builder(UUID id, Path sourcePath, Markers markers) {
Builder(UUID id, Path sourcePath, Markers markers, URI uri) {
this.id = id;
this.sourcePath = sourcePath;
this.markers = markers;
this.uri = uri;
}

public Builder description(@Language("markdown") String description) {
Expand Down Expand Up @@ -165,21 +176,17 @@ public Builder checksum(Checksum checksum) {
return this;
}

public RemoteResource build(InputStream inputStream) {
return new RemoteResource(id, sourcePath, markers, inputStream, charset, charsetBomMarked, fileAttributes, description, checksum);
}

public RemoteFile build(URI uri) {
public RemoteFile build() {
return new RemoteFile(id, sourcePath, markers, uri, charset, charsetBomMarked, fileAttributes, description, checksum);
}

public RemoteArchive build(URI uri, Path path) {
public RemoteArchive build(Path path) {
return new RemoteArchive(id, sourcePath, markers, uri, charset, charsetBomMarked, fileAttributes, description,
Arrays.asList(path.toString().replace("/", "\\/").replace(".", "\\.")
.split("!")), checksum);
}

public RemoteArchive build(URI uri, String... paths) {
public RemoteArchive build(String... paths) {
return new RemoteArchive(id, sourcePath, markers, uri, charset, charsetBomMarked, fileAttributes, description,
Arrays.asList(paths), checksum);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,8 +47,8 @@
* Useful when a Recipe wishes to create a SourceFile based on something specific from within a remote archive, but not
* the entire archive.
* <p>
* Downloading and extracting the correct file from within the archive are not handled during recipe execution.
* Post-processing of recipe results by a build plugin or other caller of OpenRewrite is responsible for this.
* Downloading and extracting the correct file from within the archive are not handled during Recipe execution.
* Post-processing of Recipe results by a build plugin or other caller of OpenRewrite is responsible for this.
*/
@Value
@EqualsAndHashCode(callSuper = false, onlyExplicitlyIncluded = true)
Expand All @@ -70,7 +70,6 @@ public class RemoteArchive implements Remote {
FileAttributes fileAttributes;

@Language("markdown")
@Nullable
String description;

/**
Expand All @@ -93,10 +92,10 @@ public InputStream getInputStream(ExecutionContext ctx) {
RemoteArtifactCache cache = RemoteExecutionContextView.view(ctx).getArtifactCache();
try {
Path localArchive = cache.compute(uri, () -> {
//noinspection resource
if ("file".equals(uri.getScheme())) {
return Files.newInputStream(Paths.get(uri));
}
//noinspection resource
HttpSender.Response response = httpSender.send(httpSender.get(uri.toString()).build());
if (response.isSuccessful()) {
return response.getBody();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,6 @@ public class RemoteFile implements Remote {
FileAttributes fileAttributes;

@Language("markdown")
@Nullable
String description;

@Nullable
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -44,8 +44,11 @@ void gradleWrapper(String version) throws Exception {
ExecutionContext ctx = new InMemoryExecutionContext();

RemoteArchive remoteArchive = Remote
.builder(Paths.get("gradle/wrapper/gradle-wrapper.jar"))
.build(distributionUrl.toURI(), "gradle-[^\\/]+\\/(?:.*\\/)+gradle-wrapper-(?!shared).*\\.jar");
.builder(
Paths.get("gradle/wrapper/gradle-wrapper.jar"),
distributionUrl.toURI()
)
.build("gradle-[^\\/]+\\/(?:.*\\/)+gradle-wrapper-(?!shared).*\\.jar");

long actual = getInputStreamSize(remoteArchive.getInputStream(ctx));
assertThat(actual).isGreaterThan(50_000);
Expand All @@ -60,8 +63,11 @@ void gradleWrapperDownloadFails() throws Exception {
.setLargeFileHttpSender(new MockHttpSender(408));

RemoteArchive remoteArchive = Remote
.builder(Paths.get("gradle/wrapper/gradle-wrapper.jar"))
.build(distributionUrl.toURI(), "gradle-[^\\/]+\\/(?:.*\\/)+gradle-wrapper-(?!shared).*\\.jar");
.builder(
Paths.get("gradle/wrapper/gradle-wrapper.jar"),
distributionUrl.toURI()
)
.build("gradle-[^\\/]+\\/(?:.*\\/)+gradle-wrapper-(?!shared).*\\.jar");

assertThatThrownBy(() -> getInputStreamSize(remoteArchive.getInputStream(ctx)))
.isInstanceOf(IllegalStateException.class)
Expand All @@ -88,8 +94,11 @@ void gradleWrapperConcurrent(String version) throws Exception {
.setLargeFileHttpSender(new MockHttpSender(distributionUrl::openStream));

RemoteArchive remoteArchive = Remote
.builder(Paths.get("gradle/wrapper/gradle-wrapper.jar"))
.build(distributionUrl.toURI(), "gradle-[^\\/]+\\/(?:.*\\/)+gradle-wrapper-(?!shared).*\\.jar");
.builder(
Paths.get("gradle/wrapper/gradle-wrapper.jar"),
distributionUrl.toURI()
)
.build("gradle-[^\\/]+\\/(?:.*\\/)+gradle-wrapper-(?!shared).*\\.jar");

return getInputStreamSize(remoteArchive.getInputStream(ctx));
});
Expand All @@ -109,8 +118,11 @@ void printingRemoteArchive() throws URISyntaxException {
URL zipUrl = requireNonNull(RemoteArchiveTest.class.getClassLoader().getResource("zipfile.zip"));

RemoteArchive remoteArchive = Remote
.builder(Paths.get("content.txt"))
.build(zipUrl.toURI(), "content.txt");
.builder(
Paths.get("content.txt"),
zipUrl.toURI()
)
.build("content.txt");

String printed = remoteArchive.printAll(new PrintOutputCapture<>(0, PrintOutputCapture.MarkerPrinter.DEFAULT));
assertThat(printed).isEqualTo("this is a zipped file");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,8 +43,11 @@ void gradleWrapperProperties() throws Exception {
.setLargeFileHttpSender(new MockHttpSender(distributionUrl::openStream));

RemoteFile remoteFile = Remote
.builder(Paths.get("gradle/wrapper/gradle-wrapper.properties"))
.build(distributionUrl.toURI());
.builder(
Paths.get("gradle/wrapper/gradle-wrapper.properties"),
distributionUrl.toURI()
)
.build();

long actual = getInputStreamSize(remoteFile.getInputStream(ctx));
assertThat(actual).isGreaterThan(800);
Expand All @@ -58,8 +61,11 @@ void gradleWrapperDownloadFails() throws Exception {
.setLargeFileHttpSender(new MockHttpSender(408));

RemoteArchive remoteFile = Remote
.builder(Paths.get("gradle/wrapper/gradle-wrapper.properties"))
.build(distributionUrl.toURI(), "gradle-[^\\/]+\\/(?:.*\\/)+gradle-wrapper-(?!shared).*\\.jar");
.builder(
Paths.get("gradle/wrapper/gradle-wrapper.properties"),
distributionUrl.toURI()
)
.build("gradle-[^\\/]+\\/(?:.*\\/)+gradle-wrapper-(?!shared).*\\.jar");


assertThatThrownBy(() -> getInputStreamSize(remoteFile.getInputStream(ctx)))
Expand All @@ -84,8 +90,11 @@ void gradleWrapperPropertiesConcurrent() throws Exception {
.setLargeFileHttpSender(new MockHttpSender(distributionUrl::openStream));

RemoteFile remoteFile = Remote
.builder(Paths.get("gradle/wrapper/gradle-wrapper.properties"))
.build(distributionUrl.toURI());
.builder(
Paths.get("gradle/wrapper/gradle-wrapper.properties"),
distributionUrl.toURI()
)
.build();

return getInputStreamSize(remoteFile.getInputStream(ctx));
});
Expand Down
6 changes: 0 additions & 6 deletions rewrite-gradle/build.gradle.kts
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
import nl.javadude.gradle.plugins.license.LicenseExtension

plugins {
id("org.openrewrite.build.language-library")
id("groovy")
Expand Down Expand Up @@ -96,7 +94,3 @@ tasks.withType<Javadoc> {
"**/GradleSettings**"
)
}

configure<LicenseExtension> {
excludePatterns.add("**/gradle-wrapper/*")
}
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,9 @@
import org.openrewrite.gradle.marker.GradleProject;
import org.openrewrite.gradle.search.FindGradleProject;
import org.openrewrite.gradle.trait.GradleDependency;
import org.openrewrite.gradle.internal.ChangeStringLiteral;
import org.openrewrite.gradle.internal.Dependency;
import org.openrewrite.gradle.internal.DependencyStringNotationConverter;
import org.openrewrite.gradle.util.ChangeStringLiteral;
import org.openrewrite.gradle.util.Dependency;
import org.openrewrite.gradle.util.DependencyStringNotationConverter;
import org.openrewrite.groovy.GroovyIsoVisitor;
import org.openrewrite.groovy.tree.G;
import org.openrewrite.internal.ListUtils;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,9 @@
import org.openrewrite.gradle.marker.GradleDependencyConfiguration;
import org.openrewrite.gradle.marker.GradleProject;
import org.openrewrite.gradle.trait.GradleDependency;
import org.openrewrite.gradle.internal.ChangeStringLiteral;
import org.openrewrite.gradle.internal.Dependency;
import org.openrewrite.gradle.internal.DependencyStringNotationConverter;
import org.openrewrite.gradle.util.ChangeStringLiteral;
import org.openrewrite.gradle.util.Dependency;
import org.openrewrite.gradle.util.DependencyStringNotationConverter;
import org.openrewrite.groovy.GroovyIsoVisitor;
import org.openrewrite.groovy.tree.G;
import org.openrewrite.internal.ListUtils;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,9 @@
import org.openrewrite.gradle.marker.GradleDependencyConfiguration;
import org.openrewrite.gradle.marker.GradleProject;
import org.openrewrite.gradle.trait.GradleDependency;
import org.openrewrite.gradle.internal.ChangeStringLiteral;
import org.openrewrite.gradle.internal.Dependency;
import org.openrewrite.gradle.internal.DependencyStringNotationConverter;
import org.openrewrite.gradle.util.ChangeStringLiteral;
import org.openrewrite.gradle.util.Dependency;
import org.openrewrite.gradle.util.DependencyStringNotationConverter;
import org.openrewrite.groovy.GroovyIsoVisitor;
import org.openrewrite.groovy.tree.G;
import org.openrewrite.internal.ListUtils;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,8 @@
import org.jspecify.annotations.Nullable;
import org.openrewrite.*;
import org.openrewrite.gradle.trait.GradleDependency;
import org.openrewrite.gradle.internal.Dependency;
import org.openrewrite.gradle.internal.DependencyStringNotationConverter;
import org.openrewrite.gradle.util.Dependency;
import org.openrewrite.gradle.util.DependencyStringNotationConverter;
import org.openrewrite.groovy.GroovyIsoVisitor;
import org.openrewrite.groovy.tree.G;
import org.openrewrite.internal.StringUtils;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,9 @@
import org.jspecify.annotations.Nullable;
import org.openrewrite.*;
import org.openrewrite.gradle.trait.GradleDependency;
import org.openrewrite.gradle.internal.ChangeStringLiteral;
import org.openrewrite.gradle.internal.Dependency;
import org.openrewrite.gradle.internal.DependencyStringNotationConverter;
import org.openrewrite.gradle.util.ChangeStringLiteral;
import org.openrewrite.gradle.util.Dependency;
import org.openrewrite.gradle.util.DependencyStringNotationConverter;
import org.openrewrite.groovy.GroovyIsoVisitor;
import org.openrewrite.groovy.tree.G;
import org.openrewrite.internal.ListUtils;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,9 @@
import org.openrewrite.gradle.marker.GradleDependencyConfiguration;
import org.openrewrite.gradle.marker.GradleProject;
import org.openrewrite.gradle.trait.GradleDependency;
import org.openrewrite.gradle.internal.ChangeStringLiteral;
import org.openrewrite.gradle.internal.Dependency;
import org.openrewrite.gradle.internal.DependencyStringNotationConverter;
import org.openrewrite.gradle.util.ChangeStringLiteral;
import org.openrewrite.gradle.util.Dependency;
import org.openrewrite.gradle.util.DependencyStringNotationConverter;
import org.openrewrite.groovy.GroovyIsoVisitor;
import org.openrewrite.groovy.tree.G;
import org.openrewrite.internal.ListUtils;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,8 @@
import org.openrewrite.Recipe;
import org.openrewrite.TreeVisitor;
import org.openrewrite.gradle.trait.GradleDependency;
import org.openrewrite.gradle.internal.Dependency;
import org.openrewrite.gradle.internal.DependencyStringNotationConverter;
import org.openrewrite.gradle.util.Dependency;
import org.openrewrite.gradle.util.DependencyStringNotationConverter;
import org.openrewrite.groovy.GroovyVisitor;
import org.openrewrite.groovy.tree.G;
import org.openrewrite.internal.ListUtils;
Expand Down
Loading