-
Notifications
You must be signed in to change notification settings - Fork 155
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
print help on error task usage (#76)
* print help on error task usage * add unit test * retrigger checks
- Loading branch information
1 parent
b19b205
commit b3b263c
Showing
12 changed files
with
125 additions
and
49 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
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 |
---|---|---|
@@ -1,2 +1,2 @@ | ||
package=co.com.bancolombia | ||
systemProp.version=1.6.4 | ||
systemProp.version=1.6.5 |
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
38 changes: 38 additions & 0 deletions
38
src/main/java/co/com/bancolombia/task/CleanArchitectureDefaultTask.java
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,38 @@ | ||
package co.com.bancolombia.task; | ||
|
||
import co.com.bancolombia.factory.ModuleBuilder; | ||
import org.gradle.api.DefaultTask; | ||
import org.gradle.api.Task; | ||
import org.gradle.api.internal.tasks.options.OptionReader; | ||
import org.gradle.api.logging.Logger; | ||
import org.gradle.configuration.TaskDetailPrinter; | ||
import org.gradle.execution.TaskSelector; | ||
import org.gradle.internal.logging.text.StyledTextOutput; | ||
import org.gradle.internal.logging.text.StyledTextOutputFactory; | ||
|
||
import javax.inject.Inject; | ||
|
||
public class CleanArchitectureDefaultTask extends DefaultTask { | ||
protected final ModuleBuilder builder = new ModuleBuilder(getProject()); | ||
protected final Logger logger = getProject().getLogger(); | ||
|
||
protected void printHelp() { | ||
StyledTextOutput output = this.getTextOutputFactory().create(CleanArchitectureDefaultTask.class); | ||
final Task task = this; | ||
TaskSelector.TaskSelection selection = new TaskSelector.TaskSelection(getPath(), getName(), | ||
collection -> collection.add(task)); | ||
OptionReader optionReader = this.getOptionReader(); | ||
TaskDetailPrinter taskDetailPrinter = new TaskDetailPrinter(getName(), selection, optionReader); | ||
taskDetailPrinter.print(output); | ||
} | ||
|
||
@Inject | ||
protected StyledTextOutputFactory getTextOutputFactory() { | ||
throw new UnsupportedOperationException(); | ||
} | ||
|
||
@Inject | ||
protected OptionReader getOptionReader() { | ||
throw new UnsupportedOperationException(); | ||
} | ||
} |
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
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
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
71 changes: 71 additions & 0 deletions
71
src/test/java/co/com/bancolombia/task/CleanArchitectureDefaultTaskTest.java
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,71 @@ | ||
package co.com.bancolombia.task; | ||
|
||
import org.gradle.api.Project; | ||
import org.gradle.api.internal.tasks.options.OptionDescriptor; | ||
import org.gradle.api.internal.tasks.options.OptionReader; | ||
import org.gradle.internal.logging.text.StyledTextOutputFactory; | ||
import org.gradle.testfixtures.ProjectBuilder; | ||
import org.junit.Before; | ||
import org.junit.Test; | ||
|
||
import java.io.File; | ||
import java.util.List; | ||
|
||
import static org.junit.Assert.*; | ||
|
||
public class CleanArchitectureDefaultTaskTest { | ||
private Project project; | ||
|
||
@Before | ||
public void setup() { | ||
project = ProjectBuilder.builder() | ||
.withName("cleanArchitecture") | ||
.withProjectDir(new File("build/unitTest")) | ||
.build(); | ||
|
||
project.getTasks().create("dm", DeleteModuleTask.class); | ||
project.getTasks().create("cadt", CleanArchitectureDefaultTask.class); | ||
} | ||
|
||
@Test | ||
public void shouldGetTaskDescriptor() { | ||
// Arrange | ||
CleanArchitectureDefaultTask task = (CleanArchitectureDefaultTask) project.getTasks().getByName("cadt"); | ||
// Act | ||
OptionReader reader = task.getOptionReader(); | ||
// Assert | ||
assertTrue(reader.getOptions(task).isEmpty()); | ||
} | ||
|
||
@Test | ||
public void shouldGetTaskDescriptorWithOptions() { | ||
// Arrange | ||
CleanArchitectureDefaultTask task = (CleanArchitectureDefaultTask) project.getTasks().getByName("dm"); | ||
// Act | ||
OptionReader reader = task.getOptionReader(); | ||
// Assert | ||
List<OptionDescriptor> list = reader.getOptions(task); | ||
assertEquals(1, list.size()); | ||
assertEquals("module", list.get(0).getName()); | ||
} | ||
|
||
@Test | ||
public void shouldGetTextOutputFactory() { | ||
// Arrange | ||
CleanArchitectureDefaultTask task = (CleanArchitectureDefaultTask) project.getTasks().getByName("dm"); | ||
// Act | ||
StyledTextOutputFactory factory = task.getTextOutputFactory(); | ||
// Assert | ||
assertNotNull(factory); | ||
} | ||
|
||
@Test | ||
public void shouldPrintHelp() { | ||
// Arrange | ||
CleanArchitectureDefaultTask task = (CleanArchitectureDefaultTask) project.getTasks().getByName("dm"); | ||
// Act | ||
task.printHelp(); | ||
// Assert | ||
assertNotNull(task.getTextOutputFactory()); | ||
} | ||
} |