-
Notifications
You must be signed in to change notification settings - Fork 43
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
SaveLockTask: avoid using project object when using doFirst
- Loading branch information
Showing
16 changed files
with
427 additions
and
275 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
61 changes: 61 additions & 0 deletions
61
src/main/groovy/nebula/plugin/dependencylock/tasks/AbstractSaveLockTask.groovy
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,61 @@ | ||
/* | ||
* Copyright 2014-2019 Netflix, Inc. | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
package nebula.plugin.dependencylock.tasks | ||
|
||
import org.gradle.api.provider.Property | ||
import org.gradle.api.specs.Spec | ||
import org.gradle.api.tasks.InputFile | ||
import org.gradle.api.tasks.Internal | ||
import org.gradle.api.tasks.OutputFile | ||
import org.gradle.api.tasks.PathSensitive | ||
import org.gradle.api.tasks.PathSensitivity | ||
import org.gradle.api.tasks.TaskAction | ||
import org.gradle.work.DisableCachingByDefault | ||
|
||
@DisableCachingByDefault | ||
abstract class AbstractSaveLockTask extends AbstractLockTask { | ||
@Internal | ||
String description = 'Move the generated lock file into the project directory' | ||
|
||
@InputFile | ||
@PathSensitive(PathSensitivity.NONE) | ||
abstract Property<File> getGeneratedLock() | ||
|
||
@OutputFile | ||
abstract Property<File> getOutputLock() | ||
|
||
AbstractSaveLockTask() { | ||
outputs.upToDateWhen(new Spec<AbstractSaveLockTask>() { | ||
@Override | ||
boolean isSatisfiedBy(AbstractSaveLockTask task) { | ||
if (task.generatedLock.isPresent() && task.generatedLock.get().exists() && task.outputLock.isPresent() && task.outputLock.get().exists()) { | ||
task.generatedLock.get().text == task.outputLock.get().text | ||
} else { | ||
false | ||
} | ||
} | ||
}) | ||
} | ||
|
||
abstract void verifyIfCanSaveLock() | ||
|
||
@TaskAction | ||
void saveLock() { | ||
verifyIfCanSaveLock() | ||
getOutputLock().get().text = generatedLock.get().text | ||
} | ||
|
||
} |
35 changes: 35 additions & 0 deletions
35
src/main/groovy/nebula/plugin/dependencylock/tasks/SaveGlobalLockTask.groovy
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
/* | ||
* Copyright 2014-2019 Netflix, Inc. | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
package nebula.plugin.dependencylock.tasks | ||
|
||
import org.gradle.api.provider.Property | ||
import org.gradle.api.tasks.Input | ||
import org.gradle.work.DisableCachingByDefault | ||
|
||
@DisableCachingByDefault | ||
abstract class SaveGlobalLockTask extends AbstractSaveLockTask { | ||
|
||
@Input | ||
abstract Property<Boolean> getAnySubprojectHasLockFile() | ||
|
||
@Override | ||
void verifyIfCanSaveLock() { | ||
if (anySubprojectHasLockFile.isPresent() && anySubprojectHasLockFile.get()) { | ||
throw new IllegalStateException("Cannot save global lock, one or more individual locks are in place, run deleteLock task") | ||
} | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
9 changes: 9 additions & 0 deletions
9
src/test/groovy/nebula/plugin/BaseIntegrationTestKitSpec.groovy
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
package nebula.plugin | ||
|
||
import nebula.test.IntegrationTestKitSpec | ||
|
||
abstract class BaseIntegrationTestKitSpec extends IntegrationTestKitSpec { | ||
def setup() { | ||
|
||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.