Skip to content

Commit

Permalink
fix: fixed build service naming strategy (#230)
Browse files Browse the repository at this point in the history
Fixes #217
  • Loading branch information
v1nc3n4 committed Jun 12, 2024
1 parent 112eb90 commit 13ec65a
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 7 deletions.
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));
}
}

0 comments on commit 13ec65a

Please sign in to comment.