Skip to content

Commit

Permalink
fix: disabled Corepack strict checks during self-update
Browse files Browse the repository at this point in the history
Fixes #212
  • Loading branch information
v1nc3n4 committed Jun 12, 2024
1 parent 93c7eb9 commit 80d57c8
Show file tree
Hide file tree
Showing 14 changed files with 142 additions and 83 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -296,17 +296,17 @@ protected void configureTasks(final Project project,
task -> configureInstallFrontendTask(task, taskContainer, beanRegistryBuildServiceProvider,
frontendExtension, systemProviders));
taskContainer.register(CLEAN_TASK_NAME, CleanTask.class,
task -> configureCleanTask(task, taskContainer, beanRegistryBuildServiceProvider, frontendExtension,
task -> configureCleanFrontendTask(task, taskContainer, beanRegistryBuildServiceProvider, frontendExtension,
systemProviders));
taskContainer.register(CHECK_TASK_NAME, CheckTask.class,
task -> configureCheckTask(task, taskContainer, beanRegistryBuildServiceProvider, frontendExtension,
task -> configureCheckFrontendTask(task, taskContainer, beanRegistryBuildServiceProvider, frontendExtension,
systemProviders));
taskContainer.register(ASSEMBLE_TASK_NAME, AssembleTask.class,
task -> configureAssembleTask(task, taskContainer, beanRegistryBuildServiceProvider, frontendExtension,
systemProviders));
task -> configureAssembleFrontendTask(task, taskContainer, beanRegistryBuildServiceProvider,
frontendExtension, systemProviders));
taskContainer.register(PUBLISH_TASK_NAME, PublishTask.class,
task -> configurePublishTask(task, taskContainer, beanRegistryBuildServiceProvider, frontendExtension,
systemProviders));
task -> configurePublishFrontendTask(task, taskContainer, beanRegistryBuildServiceProvider,
frontendExtension, systemProviders));

// Configure dependencies with Gradle built-in tasks.
configureDependency(taskContainer, GRADLE_CLEAN_TASK_NAME, CLEAN_TASK_NAME, CleanTask.class);
Expand Down Expand Up @@ -559,7 +559,7 @@ protected void configureInstallFrontendTask(final InstallFrontendTask task, fina
* @param beanRegistryBuildServiceProvider Bean registry build service provider.
* @param frontendExtension Plugin extension.
*/
protected void configureCleanTask(final CleanTask task, final TaskContainer taskContainer,
protected void configureCleanFrontendTask(final CleanTask task, final TaskContainer taskContainer,
final Provider<BeanRegistryBuildService> beanRegistryBuildServiceProvider,
final FrontendExtension frontendExtension, final SystemProviders systemProviders) {
task.setGroup(TASK_GROUP);
Expand Down Expand Up @@ -587,7 +587,7 @@ protected void configureCleanTask(final CleanTask task, final TaskContainer task
* @param beanRegistryBuildServiceProvider Bean registry build service provider.
* @param frontendExtension Plugin extension.
*/
protected void configureCheckTask(final CheckTask task, final TaskContainer taskContainer,
protected void configureCheckFrontendTask(final CheckTask task, final TaskContainer taskContainer,
final Provider<BeanRegistryBuildService> beanRegistryBuildServiceProvider,
final FrontendExtension frontendExtension, final SystemProviders systemProviders) {
task.setGroup(TASK_GROUP);
Expand Down Expand Up @@ -615,7 +615,7 @@ protected void configureCheckTask(final CheckTask task, final TaskContainer task
* @param beanRegistryBuildServiceProvider Bean registry build service provider.
* @param frontendExtension Plugin extension.
*/
protected void configureAssembleTask(final AssembleTask task, final TaskContainer taskContainer,
protected void configureAssembleFrontendTask(final AssembleTask task, final TaskContainer taskContainer,
final Provider<BeanRegistryBuildService> beanRegistryBuildServiceProvider,
final FrontendExtension frontendExtension, final SystemProviders systemProviders) {
task.setGroup(TASK_GROUP);
Expand Down Expand Up @@ -644,7 +644,7 @@ protected void configureAssembleTask(final AssembleTask task, final TaskContaine
* @param beanRegistryBuildServiceProvider Bean registry build service provider.
* @param frontendExtension Plugin extension.
*/
protected void configurePublishTask(final PublishTask task, final TaskContainer taskContainer,
protected void configurePublishFrontendTask(final PublishTask task, final TaskContainer taskContainer,
final Provider<BeanRegistryBuildService> beanRegistryBuildServiceProvider,
final FrontendExtension frontendExtension, final SystemProviders systemProviders) {
task.setGroup(TASK_GROUP);
Expand Down Expand Up @@ -680,7 +680,7 @@ private Provider<ExecutableType> getExecutableType(final TaskContainer taskConta
.type()
.getExecutableType();
} catch (final IOException | MalformedPackageManagerSpecification |
UnsupportedPackageManagerException e) {
UnsupportedPackageManagerException e) {
throw new GradleException(
"Cannot read package manager specification from file: " + packageManagerSpecificationFilePath,
e);
Expand Down Expand Up @@ -730,7 +730,7 @@ private <T> T getBeanOrFail(final BeanRegistry beanRegistry, final Class<T> bean
try {
return beanRegistry.getBean(beanClass);
} catch (final BeanInstanciationException | TooManyCandidateBeansException |
ZeroOrMultiplePublicConstructorsException e) {
ZeroOrMultiplePublicConstructorsException e) {
throw new GradleException(e.getClass().getName() + ": " + e.getMessage(), e);
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -63,8 +63,9 @@ public abstract class AbstractArchiver<C extends ArchiverContext, E extends Arch
protected final FileManager fileManager;

/**
* Initializes a context to explode an archive. If initialization fails, the archiver is responsible to leave this
* method with no resources opened, because the context {@link ArchiverContext#close()} method won't be called.
* Initializes a context to explode an archive. If initialization fails, the archiver is responsible to close any
* resources that may have been created, because the context {@link ArchiverContext#close()} method won't be
* called.
*
* @param explodeCommand Parameters to explode archive content.
* @return Context.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,6 @@

/**
* This task assembles project artifacts.
* <p>
* NOTE: this task will be renamed {@code AssembleFrontendTask} to conform with naming convention of other tasks.
*/
public class AssembleTask extends AbstractRunCommandTask {

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,6 @@

/**
* This task checks the project.
* <p>
* NOTE: this task will be renamed {@code CheckFrontendTask} to conform with naming convention of other tasks.
*/
public class CheckTask extends AbstractRunCommandTask {

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,6 @@

/**
* This task cleans project artifacts.
* <p>
* NOTE: this task will be renamed {@code CleanFrontendTask} to conform with naming convention of other tasks.
*/
public class CleanTask extends AbstractRunCommandTask {

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ public void execute(final ScriptProperties scriptProperties) {
.script(scriptProperties.getScript())
.environmentVariables(scriptProperties.getEnvironmentVariables())
.build());
logger.info("Execution settings: {}", executionSettings);
logger.debug("Execution settings: {}", executionSettings);

scriptProperties
.getExecOperations()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,12 @@ public class InstallCorepackTask extends AbstractRunCommandTask {
*/
public static final String COREPACK_MODULE_PATH = "node_modules/corepack";

/**
* Name of the environment variable that prevents Corepack to fail during update with NPM, if the project uses
* another package manager.
*/
public static final String COREPACK_ENABLE_STRICT_VARIABLE = "COREPACK_ENABLE_STRICT";

/**
* Version of Corepack that should be installed: may be a specific version number such as {@code X.Y.Z} or the
* {@link #LATEST_VERSION_ARGUMENT} keyword to install the latest version available.
Expand Down Expand Up @@ -76,6 +82,7 @@ public void execute() throws NonRunnableTaskException, BeanRegistryException {
scriptBuilder.append(version);
}
this.script.set(scriptBuilder.toString());
this.environmentVariables.put(COREPACK_ENABLE_STRICT_VARIABLE, "0");

super.execute();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,6 @@

/**
* This task publishes project artifacts.
* <p>
* NOTE: this task will be renamed {@code PublishFrontendTask} to conform with naming convention of other tasks.
*
* @since 1.4.0
*/
public class PublishTask extends AbstractRunCommandTask {

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -307,70 +307,79 @@ private void assertThatTasksAreConfigured(final Project project, final FrontendE
assertThat(installFrontendTask.getSystemOsName().get()).isEqualTo(expectedSystemProperties.get(OS_NAME));
assertThat(installFrontendTask.getDependsOn()).containsExactlyInAnyOrder(installPackageManagerTask.getName());

final CleanTask frontendCleanTask = project.getTasks().named(CLEAN_TASK_NAME, CleanTask.class).get();
assertThat(frontendCleanTask.getBeanRegistryBuildService().get().getBeanRegistry()).isNotNull();
assertThat(frontendCleanTask.getPackageJsonDirectory().get()).isEqualTo(
final CleanTask cleanFrontendTask = project
.getTasks()
.named(CLEAN_TASK_NAME, CleanTask.class)
.get();
assertThat(cleanFrontendTask.getBeanRegistryBuildService().get().getBeanRegistry()).isNotNull();
assertThat(cleanFrontendTask.getPackageJsonDirectory().get()).isEqualTo(
extension.getPackageJsonDirectory().getAsFile().get());
assertThat(frontendCleanTask.getNodeInstallDirectory().get()).isEqualTo(
assertThat(cleanFrontendTask.getNodeInstallDirectory().get()).isEqualTo(
extension.getNodeInstallDirectory().getAsFile().get());
//frontendCleanTask.getPackageManagerExecutableFile()
assertThat(frontendCleanTask.getCleanScript().getOrNull()).isEqualTo(extension.getCleanScript().getOrNull());
assertThat(frontendCleanTask.getVerboseModeEnabled().get()).isEqualTo(extension.getVerboseModeEnabled().get());
assertThat(frontendCleanTask.getSystemJvmArch().get()).isEqualTo(expectedSystemProperties.get(JVM_ARCH));
assertThat(frontendCleanTask.getSystemOsName().get()).isEqualTo(expectedSystemProperties.get(OS_NAME));
assertThat(frontendCleanTask.getDependsOn()).containsExactlyInAnyOrder(installFrontendTask.getName());
assertThat(cleanFrontendTask.getCleanScript().getOrNull()).isEqualTo(extension.getCleanScript().getOrNull());
assertThat(cleanFrontendTask.getVerboseModeEnabled().get()).isEqualTo(extension.getVerboseModeEnabled().get());
assertThat(cleanFrontendTask.getSystemJvmArch().get()).isEqualTo(expectedSystemProperties.get(JVM_ARCH));
assertThat(cleanFrontendTask.getSystemOsName().get()).isEqualTo(expectedSystemProperties.get(OS_NAME));
assertThat(cleanFrontendTask.getDependsOn()).containsExactlyInAnyOrder(installFrontendTask.getName());
assertThat(project.getTasks().named(BasePlugin.CLEAN_TASK_NAME).get().getDependsOn()).contains(
frontendCleanTask.getName());
cleanFrontendTask.getName());

final AssembleTask frontendAssembleTask = project
final AssembleTask assembleFrontendTask = project
.getTasks()
.named(ASSEMBLE_TASK_NAME, AssembleTask.class)
.get();
assertThat(frontendAssembleTask.getBeanRegistryBuildService().get().getBeanRegistry()).isNotNull();
assertThat(frontendAssembleTask.getPackageJsonDirectory().get()).isEqualTo(
assertThat(assembleFrontendTask.getBeanRegistryBuildService().get().getBeanRegistry()).isNotNull();
assertThat(assembleFrontendTask.getPackageJsonDirectory().get()).isEqualTo(
extension.getPackageJsonDirectory().getAsFile().get());
//frontendAssembleTask.getPackageManagerExecutableFile()
assertThat(frontendAssembleTask.getAssembleScript().getOrNull()).isEqualTo(
assertThat(assembleFrontendTask.getAssembleScript().getOrNull()).isEqualTo(
extension.getAssembleScript().getOrNull());
assertThat(frontendAssembleTask.getVerboseModeEnabled().get()).isEqualTo(
assertThat(assembleFrontendTask.getVerboseModeEnabled().get()).isEqualTo(
extension.getVerboseModeEnabled().get());
assertThat(frontendAssembleTask.getSystemJvmArch().get()).isEqualTo(expectedSystemProperties.get(JVM_ARCH));
assertThat(frontendAssembleTask.getSystemOsName().get()).isEqualTo(expectedSystemProperties.get(OS_NAME));
assertThat(frontendAssembleTask.getDependsOn()).containsExactlyInAnyOrder(installFrontendTask.getName());
assertThat(assembleFrontendTask.getSystemJvmArch().get()).isEqualTo(expectedSystemProperties.get(JVM_ARCH));
assertThat(assembleFrontendTask.getSystemOsName().get()).isEqualTo(expectedSystemProperties.get(OS_NAME));
assertThat(assembleFrontendTask.getDependsOn()).containsExactlyInAnyOrder(installFrontendTask.getName());
assertThat(project.getTasks().named(BasePlugin.ASSEMBLE_TASK_NAME).get().getDependsOn()).contains(
frontendAssembleTask.getName());
assembleFrontendTask.getName());

final CheckTask frontendCheckTask = project.getTasks().named(CHECK_TASK_NAME, CheckTask.class).get();
assertThat(frontendCheckTask.getBeanRegistryBuildService().get().getBeanRegistry()).isNotNull();
assertThat(frontendCheckTask.getPackageJsonDirectory().get()).isEqualTo(
final CheckTask checkFrontendTask = project
.getTasks()
.named(CHECK_TASK_NAME, CheckTask.class)
.get();
assertThat(checkFrontendTask.getBeanRegistryBuildService().get().getBeanRegistry()).isNotNull();
assertThat(checkFrontendTask.getPackageJsonDirectory().get()).isEqualTo(
extension.getPackageJsonDirectory().getAsFile().get());
assertThat(frontendCheckTask.getNodeInstallDirectory().get()).isEqualTo(
assertThat(checkFrontendTask.getNodeInstallDirectory().get()).isEqualTo(
extension.getNodeInstallDirectory().getAsFile().get());
//frontendCheckTask.getPackageManagerExecutableFile()
assertThat(frontendCheckTask.getCheckScript().getOrNull()).isEqualTo(extension.getCheckScript().getOrNull());
assertThat(frontendCheckTask.getVerboseModeEnabled().get()).isEqualTo(extension.getVerboseModeEnabled().get());
assertThat(frontendCheckTask.getSystemJvmArch().get()).isEqualTo(expectedSystemProperties.get(JVM_ARCH));
assertThat(frontendCheckTask.getSystemOsName().get()).isEqualTo(expectedSystemProperties.get(OS_NAME));
assertThat(frontendCheckTask.getDependsOn()).containsExactlyInAnyOrder(installFrontendTask.getName());
assertThat(checkFrontendTask.getCheckScript().getOrNull()).isEqualTo(extension.getCheckScript().getOrNull());
assertThat(checkFrontendTask.getVerboseModeEnabled().get()).isEqualTo(extension.getVerboseModeEnabled().get());
assertThat(checkFrontendTask.getSystemJvmArch().get()).isEqualTo(expectedSystemProperties.get(JVM_ARCH));
assertThat(checkFrontendTask.getSystemOsName().get()).isEqualTo(expectedSystemProperties.get(OS_NAME));
assertThat(checkFrontendTask.getDependsOn()).containsExactlyInAnyOrder(installFrontendTask.getName());
assertThat(project.getTasks().named(LifecycleBasePlugin.CHECK_TASK_NAME).get().getDependsOn()).contains(
frontendCheckTask.getName());
checkFrontendTask.getName());

final PublishTask frontendPublishTask = project.getTasks().named(PUBLISH_TASK_NAME, PublishTask.class).get();
assertThat(frontendPublishTask.getBeanRegistryBuildService().get().getBeanRegistry()).isNotNull();
assertThat(frontendPublishTask.getPackageJsonDirectory().get()).isEqualTo(
final PublishTask publishFrontendTask = project
.getTasks()
.named(PUBLISH_TASK_NAME, PublishTask.class)
.get();
assertThat(publishFrontendTask.getBeanRegistryBuildService().get().getBeanRegistry()).isNotNull();
assertThat(publishFrontendTask.getPackageJsonDirectory().get()).isEqualTo(
extension.getPackageJsonDirectory().getAsFile().get());
assertThat(frontendPublishTask.getNodeInstallDirectory().get()).isEqualTo(
assertThat(publishFrontendTask.getNodeInstallDirectory().get()).isEqualTo(
extension.getNodeInstallDirectory().getAsFile().get());
//frontendPublishTask.getPackageManagerExecutableFile()
assertThat(frontendPublishTask.getPublishScript().getOrNull()).isEqualTo(
assertThat(publishFrontendTask.getPublishScript().getOrNull()).isEqualTo(
extension.getPublishScript().getOrNull());
assertThat(frontendPublishTask.getVerboseModeEnabled().get()).isEqualTo(
assertThat(publishFrontendTask.getVerboseModeEnabled().get()).isEqualTo(
extension.getVerboseModeEnabled().get());
assertThat(frontendPublishTask.getSystemJvmArch().get()).isEqualTo(expectedSystemProperties.get(JVM_ARCH));
assertThat(frontendPublishTask.getSystemOsName().get()).isEqualTo(expectedSystemProperties.get(OS_NAME));
assertThat(frontendPublishTask.getDependsOn()).containsExactlyInAnyOrder(frontendAssembleTask.getName());
assertThat(publishFrontendTask.getSystemJvmArch().get()).isEqualTo(expectedSystemProperties.get(JVM_ARCH));
assertThat(publishFrontendTask.getSystemOsName().get()).isEqualTo(expectedSystemProperties.get(OS_NAME));
assertThat(publishFrontendTask.getDependsOn()).containsExactlyInAnyOrder(assembleFrontendTask.getName());
assertThat(
project.getTasks().named(PublishingPlugin.PUBLISH_LIFECYCLE_TASK_NAME).get().getDependsOn()).contains(
frontendPublishTask.getName());
publishFrontendTask.getName());
}
}
Loading

0 comments on commit 80d57c8

Please sign in to comment.