Skip to content
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
12 changes: 12 additions & 0 deletions buildSrc/src/main/kotlin/prepare-config-resources.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,17 @@ tasks.processResources {
val spineBaseVersion: String by extra
val spineTimeVersion: String by extra
val spineVersion: String by extra
val spineWebVersion: String by extra
val spineGCloudVersion: String by extra

/*
This task creates the `artifact-snapshot.properties` file which is later added to the classpath of
the Bootstrap plugin. The file contains versions, artifact notations, repositories, etc. used in
the Gradle scripts which should also be used in the runtime of the Bootstrap plugin.

The keys for the `artifact-snapshot.properties` file are duplicated in
the `io.spine.tools.gradle.config.ArtifactSnapshot` class, where the file is parsed.
*/
val writeDependencies by tasks.registering {
group = taskGroup

Expand All @@ -76,6 +86,8 @@ val writeDependencies by tasks.registering {
artifacts.setProperty("spine.version.base", spineBaseVersion)
artifacts.setProperty("spine.version.time", spineTimeVersion)
artifacts.setProperty("spine.version.core", spineVersion)
artifacts.setProperty("spine.version.web", spineWebVersion)
artifacts.setProperty("spine.version.gcloud", spineWebVersion)
artifacts.setProperty("protobuf.compiler", Deps.build.protoc)
artifacts.setProperty("protobuf.java", Deps.build.protobuf[0])
artifacts.setProperty("grpc.stub", Deps.grpc.stub)
Expand Down
4 changes: 2 additions & 2 deletions license-report.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@


# Dependencies of `io.spine.tools:spine-plugin:1.5.27`
# Dependencies of `io.spine.tools:spine-plugin:1.5.28`

## Runtime
1. **Group:** com.google.code.findbugs **Name:** jsr305 **Version:** 3.0.2
Expand Down Expand Up @@ -338,4 +338,4 @@
The dependencies distributed under several licenses, are used according their commercial-use-friendly license.


This report was generated on **Fri Aug 28 17:52:22 EEST 2020** using [Gradle-License-Report plugin](https://github.com/jk1/Gradle-License-Report) by Evgeny Naumenko, licensed under [Apache 2.0 License](https://github.com/jk1/Gradle-License-Report/blob/master/LICENSE).
This report was generated on **Thu Sep 03 12:51:44 EEST 2020** using [Gradle-License-Report plugin](https://github.com/jk1/Gradle-License-Report) by Evgeny Naumenko, licensed under [Apache 2.0 License](https://github.com/jk1/Gradle-License-Report/blob/master/LICENSE).
Original file line number Diff line number Diff line change
Expand Up @@ -26,11 +26,17 @@
import io.spine.tools.gradle.Artifact;
import io.spine.tools.gradle.ConfigurationName;
import io.spine.tools.gradle.GeneratedSourceRoot;
import io.spine.tools.gradle.compiler.Extension;
import io.spine.tools.gradle.config.ArtifactSnapshot;
import io.spine.tools.gradle.config.SpineDependency;
import io.spine.tools.gradle.project.SourceSuperset;
import org.gradle.api.Action;
import org.gradle.api.Project;
import org.gradle.plugins.ide.idea.model.IdeaModel;
import org.gradle.plugins.ide.idea.model.IdeaModule;

import java.io.File;
import java.util.Set;

import static com.google.common.base.Preconditions.checkNotNull;
import static io.spine.tools.gradle.ConfigurationName.implementation;
Expand Down Expand Up @@ -69,6 +75,32 @@ void enableGeneration() {
pluginTarget().apply(SpinePluginScripts.modelCompilerConfig());
addSourceSets();
excludeProtobufLite();
pluginTarget().withIdeaPlugin(this::configureIdea);
}

private void configureIdea(IdeaModel idea) {
IdeaModule module = idea.getModule();

Set<File> mainSrc = module.getSourceDirs();
Set<File> mainGenerated = module.getGeneratedSourceDirs();
add(mainSrc, Extension.getMainProtoSrcDir(project));
add(mainGenerated, Extension.getMainGenProtoDir(project));
add(mainGenerated, Extension.getMainGenGrpcDir(project));
add(mainGenerated, Extension.getTargetGenColumnsRootDir(project));
add(mainGenerated, Extension.getTargetGenRejectionsRootDir(project));

Set<File> testSrc = module.getTestSourceDirs();
add(testSrc, Extension.getTestProtoSrcDir(project));
add(testSrc, Extension.getTestGenProtoDir(project));
add(testSrc, Extension.getTestGenGrpcDir(project));

module.setDownloadJavadoc(true);
module.setDownloadSources(true);
}

private static void add(Set<File> files, String path) {
File file = new File(path);
files.add(file);
}

private void excludeProtobufLite() {
Expand All @@ -83,7 +115,7 @@ public void codegen(Action<JavaCodegenExtension> config) {
config.execute(codegen);
}

public void codegen(Closure config) {
public void codegen(@SuppressWarnings("rawtypes") /* For Gradle API. */ Closure config) {
configure(config, codegen);
}

Expand All @@ -109,6 +141,43 @@ public void server() {
dependOnCore(SpineDependency.testUtilServer(), testImplementation);
}

/**
* Marks this project as a part of a Java server and a Web server.
*
* <p>Additionally to the {@linkplain #server() server} dependencies, adds a dependency on
* {@code io.spine:spine-web}.
*/
public void webServer() {
dependOnWeb(SpineDependency.web());
}

/**
* Marks this project as a part of a Java server and a Web server based on the Firebase RDB.
*
* <p>Additionally to the {@linkplain #server() server} dependencies, adds a dependency on
* {@code io.spine.gcloud:spine-firebase-web}.
*/
public void firebaseWebServer() {
dependOnWeb(SpineDependency.firebaseWeb());
}

/**
* Marks this project as a part of a Java server and adds the Google Cloud Datastore storage
* dependency to the project.
*/
public void withDatastore() {
server();
Artifact dependency = SpineDependency.datastore()
.ofVersion(artifacts.spineGCloudVersion());
dependOn(dependency, implementation);
}

private void dependOnWeb(SpineDependency dependency) {
server();
String version = artifacts.spineWebVersion();
dependOn(dependency.ofVersion(version), implementation);
}

private void dependOn(Artifact module, ConfigurationName configurationName) {
dependant().depend(configurationName, module.notation());
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,13 @@
import io.spine.tools.gradle.PluginScript;
import io.spine.tools.gradle.compiler.ModelCompilerPlugin;
import io.spine.tools.gradle.project.PluginTarget;
import org.gradle.api.Plugin;
import org.gradle.api.Project;
import org.gradle.api.plugins.JavaPlugin;
import org.gradle.plugins.ide.idea.IdeaPlugin;
import org.gradle.plugins.ide.idea.model.IdeaModel;

import java.util.function.Consumer;

import static com.google.common.base.Preconditions.checkNotNull;

Expand All @@ -45,7 +51,12 @@ public SpinePluginTarget(PluginTarget delegate) {
}

@Override
public void apply(GradlePlugin plugin) {
public <P extends Plugin<Project>> void with(GradlePlugin<P> plugin, Consumer<P> action) {
delegate.with(plugin, action);
}

@Override
public void apply(GradlePlugin<?> plugin) {
delegate.apply(plugin);
}

Expand All @@ -55,15 +66,15 @@ public void apply(PluginScript pluginScript) {
}

@Override
public boolean isApplied(GradlePlugin plugin) {
public boolean isApplied(GradlePlugin<?> plugin) {
return delegate.isApplied(plugin);
}

/**
* Applies the standard {@link JavaPlugin}.
*/
public void applyJavaPlugin() {
GradlePlugin javaPlugin = GradlePlugin.implementedIn(JavaPlugin.class);
GradlePlugin<?> javaPlugin = GradlePlugin.implementedIn(JavaPlugin.class);
apply(javaPlugin);
}

Expand All @@ -74,23 +85,31 @@ public void applyJavaPlugin() {
*/
public void applyProtobufPlugin() {
applyJavaPlugin();
GradlePlugin protoPlugin = GradlePlugin.implementedIn(ProtobufPlugin.class);
GradlePlugin<?> protoPlugin = GradlePlugin.implementedIn(ProtobufPlugin.class);
apply(protoPlugin);
}

/**
* Applies the {@link ModelCompilerPlugin}.
*/
public void applyModelCompiler() {
GradlePlugin plugin = GradlePlugin.implementedIn(ModelCompilerPlugin.class);
GradlePlugin<?> plugin = GradlePlugin.implementedIn(ModelCompilerPlugin.class);
apply(plugin);
}

/**
* Applies the {@link ProtoJsPlugin}.
*/
public void applyProtoJsPlugin() {
GradlePlugin plugin = GradlePlugin.implementedIn(ProtoJsPlugin.class);
GradlePlugin<?> plugin = GradlePlugin.implementedIn(ProtoJsPlugin.class);
apply(plugin);
}

/**
* Checks if the {@code idea} plugin is applied to this project.
*/
public void withIdeaPlugin(Consumer<IdeaModel> action) {
GradlePlugin<IdeaPlugin> plugin = GradlePlugin.implementedIn(IdeaPlugin.class);
with(plugin, idea -> action.accept(idea.getModel()));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,8 @@ public final class ArtifactSnapshot {
private final String spineBaseVersion;
private final String spineTimeVersion;
private final String spineCoreVersion;
private final String spineWebVersion;
private final String spineGCloudVersion;

private final String protoc;
private final String protobufJava;
Expand All @@ -60,6 +62,8 @@ private ArtifactSnapshot(Builder builder) {
this.spineBaseVersion = checkNotNull(builder.spineBaseVersion);
this.spineTimeVersion = checkNotNull(builder.spineTimeVersion);
this.spineCoreVersion = checkNotNull(builder.spineCoreVersion);
this.spineWebVersion = checkNotNull(builder.spineWebVersion);
this.spineGCloudVersion = checkNotNull(builder.spineGCloudVersion);
this.protoc = checkNotNull(builder.protoc);
this.protobufJava = checkNotNull(builder.protobufJava);
this.grpcProtobuf = checkNotNull(builder.grpcProtobuf);
Expand All @@ -68,6 +72,14 @@ private ArtifactSnapshot(Builder builder) {
this.spineSnapshotRepository = checkNotNull(builder.spineSnapshotRepository);
}

/**
* Loads the values from the {@code artifact-snapshot.properties} file from classpath.
*
* <p>The keys for the {@code artifact-snapshot.properties} file are duplicated in
* the {@code prepare-config-resources.gradle.kts} Gradle script, where the file is generated.
*
* @return loaded {@code ArtifactSnapshot}
*/
private static ArtifactSnapshot load() {
Resource file = Resource.file("artifact-snapshot.properties");
Properties properties = new Properties();
Expand All @@ -80,6 +92,8 @@ private static ArtifactSnapshot load() {
.setSpineCoreVersion(properties.getProperty("spine.version.core"))
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please see if we can have a class which declares these constants and used at both ends.
If it's not easy, please document usage of this constants at both ends: when they generated, and here (consumed), referring to the other end of this trick.

.setSpineBaseVersion(properties.getProperty("spine.version.base"))
.setSpineTimeVersion(properties.getProperty("spine.version.time"))
.setSpineWebVersion(properties.getProperty("spine.version.web"))
.setSpineGCloudVersion(properties.getProperty("spine.version.gcloud"))
.setProtoc(properties.getProperty("protobuf.compiler"))
.setProtobufJava(properties.getProperty("protobuf.java"))
.setGrpcProtobuf(properties.getProperty("grpc.protobuf"))
Expand Down Expand Up @@ -120,6 +134,20 @@ public String spineTimeVersion() {
return spineTimeVersion;
}

/**
* Obtains the current version of Spine {@code web} API.
*/
public String spineWebVersion() {
return spineWebVersion;
}

/**
* Obtains the current version of Spine GCloud.
*/
public String spineGCloudVersion() {
return spineGCloudVersion;
}

/**
* Obtains the Maven repository which hosts Spine artifacts with release versions.
*/
Expand Down Expand Up @@ -173,6 +201,8 @@ public static final class Builder {
private String spineBaseVersion;
private String spineTimeVersion;
private String spineCoreVersion;
private String spineWebVersion;
private String spineGCloudVersion;
private String protoc;
private String protobufJava;
private String grpcProtobuf;
Expand Down Expand Up @@ -201,6 +231,16 @@ public Builder setSpineCoreVersion(String version) {
return this;
}

public Builder setSpineWebVersion(String spineWebVersion) {
this.spineWebVersion = checkNotNull(spineWebVersion);
return this;
}

public Builder setSpineGCloudVersion(String spineGCloudVersion) {
this.spineGCloudVersion = checkNotNull(spineGCloudVersion);
return this;
}

public Builder setProtoc(String artifact) {
this.protoc = checkNotNull(artifact);
return this;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,20 +27,43 @@
*/
public final class SpineDependency implements Dependency {

private static final String SPINE_PREFIX = "spine-";
private static final String DEFAULT_GROUP = "io.spine";
private static final String G_CLOUD_GROUP = DEFAULT_GROUP + ".gcloud";

private static final SpineDependency BASE = new SpineDependency("base");
private static final SpineDependency TIME = new SpineDependency("time");
private static final SpineDependency CLIENT = new SpineDependency("client");
private static final SpineDependency SERVER = new SpineDependency("server");
private static final SpineDependency TEST_UTIL_SERVER = new SpineDependency("testutil-server");
private static final SpineDependency TEST_UTIL_CLIENT = new SpineDependency("testutil-client");
private static final SpineDependency TESTLIB = new SpineDependency("testlib");
private static final SpineDependency TEST_UTIL_TIME = new SpineDependency("testutil-time");
private static final String SPINE_PREFIX = "spine-";

private static final SpineDependency BASE =
new SpineDependency("base");
private static final SpineDependency TIME =
new SpineDependency("time");
private static final SpineDependency CLIENT =
new SpineDependency("client");
private static final SpineDependency SERVER =
new SpineDependency("server");
private static final SpineDependency TEST_UTIL_SERVER =
new SpineDependency("testutil-server");
private static final SpineDependency TEST_UTIL_CLIENT =
new SpineDependency("testutil-client");
private static final SpineDependency TESTLIB =
new SpineDependency("testlib");
private static final SpineDependency TEST_UTIL_TIME =
new SpineDependency("testutil-time");
private static final SpineDependency WEB =
new SpineDependency("web");
private static final SpineDependency FIREBASE_WEB =
new SpineDependency(G_CLOUD_GROUP, "firebase-web");
private static final SpineDependency DATASTORE =
new SpineDependency(G_CLOUD_GROUP, "datastore");

private final String group;
private final String shortName;

private SpineDependency(String name) {
this(DEFAULT_GROUP, name);
}

private SpineDependency(String group, String name) {
this.group = group;
this.shortName = name;
}

Expand Down Expand Up @@ -100,14 +123,26 @@ public static SpineDependency testUtilTime() {
return TEST_UTIL_TIME;
}

public static SpineDependency web() {
return WEB;
}

public static SpineDependency firebaseWeb() {
return FIREBASE_WEB;
}

public static SpineDependency datastore() {
return DATASTORE;
}

@Override
public String name() {
return SPINE_PREFIX + shortName;
}

@Override
public String groupId() {
return "io.spine";
return group;
}

@Override
Expand Down
Loading