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

fix: fixed build service naming strategy #230

Merged
merged 1 commit into from
Jun 12, 2024
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
Original file line number Diff line number Diff line change
Expand Up @@ -201,8 +201,6 @@ public class FrontendGradlePlugin implements Plugin<Project> {
*/
private static final String TASK_GROUP = "Frontend";

public static final String BEAN_REGISTRY_BUILD_SERVICE_NAME_PREFIX = "beanRegistryBuildService";

@Override
public void apply(final Project project) {
project.getPluginManager().apply(BasePlugin.class);
Expand Down Expand Up @@ -263,8 +261,7 @@ protected Provider<BeanRegistryBuildService> configureBeanRegistry(final Project
return project
.getGradle()
.getSharedServices()
.registerIfAbsent(BEAN_REGISTRY_BUILD_SERVICE_NAME_PREFIX + project.getLayout().getProjectDirectory(),
BeanRegistryBuildService.class,
.registerIfAbsent(BeanRegistryBuildService.buildName(project), BeanRegistryBuildService.class,
buildServiceSpec -> buildServiceSpec.getParameters().getBeanRegistry().set(beanRegistry));
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
package org.siouan.frontendgradleplugin.infrastructure.gradle;

import static org.siouan.frontendgradleplugin.FrontendGradlePlugin.BEAN_REGISTRY_BUILD_SERVICE_NAME_PREFIX;

import org.gradle.api.Project;
import org.gradle.api.model.ObjectFactory;
import org.gradle.api.provider.Provider;
Expand All @@ -22,7 +20,7 @@ public abstract class AbstractRunCommandTaskType extends AbstractRunCommandTask
.getGradle()
.getSharedServices()
.getRegistrations()
.named(BEAN_REGISTRY_BUILD_SERVICE_NAME_PREFIX + project.getLayout().getProjectDirectory())
.named(BeanRegistryBuildService.buildName(project))
.flatMap(BuildServiceRegistration::getService);
beanRegistryBuildService.set(beanRegistryBuildServiceProvider);
packageJsonDirectory.set(frontendExtension.getPackageJsonDirectory().getAsFile());
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
package org.siouan.frontendgradleplugin.infrastructure.gradle;

import java.nio.charset.StandardCharsets;
import java.util.Base64;

import lombok.Getter;
import org.gradle.api.Project;
import org.gradle.api.provider.Property;
import org.gradle.api.services.BuildService;
import org.gradle.api.services.BuildServiceParameters;
Expand All @@ -14,6 +18,8 @@
@Getter
public abstract class BeanRegistryBuildService implements BuildService<BeanRegistryBuildService.Params> {

public static final String BEAN_REGISTRY_BUILD_SERVICE_NAME_PREFIX = "fgpBeanRegistryBuildService";

/**
* The project bean registry.
*/
Expand All @@ -27,4 +33,21 @@ public interface Params extends BuildServiceParameters {

Property<BeanRegistry> getBeanRegistry();
}

/**
* Gets the name of the build service instance registered in the given project.
*
* @param project Project.
* @return Name.
*/
public static String buildName(final Project project) {
return BEAN_REGISTRY_BUILD_SERVICE_NAME_PREFIX + Base64
.getEncoder()
.encodeToString(project
.getLayout()
.getProjectDirectory()
.getAsFile()
.getAbsolutePath()
.getBytes(StandardCharsets.UTF_8));
}
}
Loading