Skip to content

Commit

Permalink
chore: rename stuff, add package structure, tweak some comments, more…
Browse files Browse the repository at this point in the history
… recurse logic
  • Loading branch information
Cervator committed Jul 11, 2020
1 parent 53662ac commit 85433d5
Show file tree
Hide file tree
Showing 15 changed files with 125 additions and 47 deletions.
4 changes: 4 additions & 0 deletions gradle/gooeycli/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,14 @@ repositories {
jcenter()
}

// Important note: These need to be in sync with the @Grab entries in the Groovy scripts if both have to work
dependencies {
// These are potentially available inside the Gradle/Groovy jar files already present
compile 'org.codehaus.groovy:groovy-all:2.5.10'
compile 'info.picocli:picocli-groovy:4.3.2'
compile 'org.fusesource.jansi:jansi:1.18'

// Have to rely on these via 3rd party jars
compile 'org.ajoberstar:grgit:1.9.3'
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,20 +15,22 @@ package org.terasology.cli
// Needed for colors to work on Windows, along with a mode toggle at the start and end of execution in main
@Grab('org.fusesource.jansi:jansi:1.18') // TODO: Exists at 1.17 inside the Gradle Wrapper lib - can use that one?
import org.fusesource.jansi.AnsiConsole

import org.terasology.cli.commands.BaseCommandType
import org.terasology.cli.commands.InitCommand
import org.terasology.cli.commands.ModuleCommand
import picocli.CommandLine
import picocli.CommandLine.Command
import picocli.CommandLine.HelpCommand

// If using local groovy files the subcommands section may highlight as bad syntax in IntelliJ - that's OK
// If using local groovy files without Gradle the subcommands section may highlight as bad syntax in IntelliJ - that's OK
@Command(name = "gw",
synopsisSubcommandLabel = "COMMAND", // Default is [COMMAND] indicating optional, but sub command here is required
subcommands = [
HelpCommand.class, // Adds standard help options (help as a subcommand, -h, and --help)
Module.class,
Init.class], // Note that these Groovy classes *must* start with a capital letter for some reason
ModuleCommand.class,
InitCommand.class], // Note that these Groovy classes *must* start with a capital letter for some reason
description = "Utility system for interacting with a Terasology developer workspace")
class GooeyCLI extends BaseCommand {
class GooeyCLI extends BaseCommandType {
static void main(String[] args) {
AnsiConsole.systemInstall() // enable colors on Windows - TODO: Test on not-so-Windows systems, should those not run this?
CommandLine cmd = new CommandLine(new GooeyCLI())
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
// Copyright 2020 The Terasology Foundation
// SPDX-License-Identifier: Apache-2.0
package org.terasology.cli
package org.terasology.cli.commands

import picocli.CommandLine.Command

Expand All @@ -13,6 +13,6 @@ import picocli.CommandLine.Command
parameterListHeading = "%n@|green Parameters:|@%n%n",
optionListHeading = "%n@|green Options:|@%n%n",
commandListHeading = "%n@|green Commands:|@%n%n")
class BaseCommand {
class BaseCommandType {

}
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
// Copyright 2020 The Terasology Foundation
// SPDX-License-Identifier: Apache-2.0
package org.terasology.cli
package org.terasology.cli.commands

import org.terasology.cli.options.GitOptions
import org.terasology.cli.managers.ManagedItem
import picocli.CommandLine.ParentCommand
import picocli.CommandLine.Command
// Actually in use, annotation below may show syntax error due to Groovy's annotation by the same name. Works fine
Expand All @@ -13,11 +16,11 @@ import picocli.CommandLine.Parameters
* Distinct from the sibling command add-remote which does *not* mix in GitOptions since the command itself involves git remote
*/
@Command(name = "get", description = "Gets one or more items directly")
class Get extends BaseCommand implements Runnable {
class GetCommand extends BaseCommandType implements Runnable {

/** Reference to the parent item command so we can figure out what type it is */
@ParentCommand
ItemCommand parent
ItemCommandType parent

/** Mix in a variety of supported Git extras */
@Mixin
Expand Down
Original file line number Diff line number Diff line change
@@ -1,14 +1,17 @@
// Copyright 2020 The Terasology Foundation
// SPDX-License-Identifier: Apache-2.0
package org.terasology.cli
package org.terasology.cli.commands

import org.terasology.cli.options.GitOptions
import org.terasology.cli.helpers.PropHelper
import picocli.CommandLine.Command
import picocli.CommandLine.Help.Ansi
// Is in use, IDE may think the Groovy-supplied is in use below and mark this unused
import picocli.CommandLine.Mixin
import picocli.CommandLine.Parameters

@Command(name = "init", description = "Initializes a workspace with some useful things")
class Init extends BaseCommand implements Runnable {
class InitCommand extends BaseCommandType implements Runnable {

/** The name of the distro, if given. Optional parameter (the arity = 0..1 bit) */
@Parameters(paramLabel = "distro", arity = "0..1", defaultValue = "sample", description = "Target module distro to prepare locally")
Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,13 @@
// Copyright 2020 The Terasology Foundation
// SPDX-License-Identifier: Apache-2.0
package org.terasology.cli
package org.terasology.cli.commands

import org.terasology.cli.managers.ManagedItem

/**
* Simple command type class that indicates the command deals with "items" - nested Git roots representing application elements
*/
abstract class ItemCommand extends BaseCommand {
abstract class ItemCommandType extends BaseCommandType {
/**
* Return a manager class for interacting with the specific type of item
* @param optionGitOrigin if the user indicated an alternative Git origin it will be used to vary some URLs
Expand Down
Original file line number Diff line number Diff line change
@@ -1,20 +1,22 @@
// Copyright 2020 The Terasology Foundation
// SPDX-License-Identifier: Apache-2.0
package org.terasology.cli
package org.terasology.cli.commands

import org.terasology.cli.managers.ManagedItem
import org.terasology.cli.managers.ManagedModule
import picocli.CommandLine.Command
import picocli.CommandLine.HelpCommand

// If using local groovy files the subcommands section may highlight as bad syntax in IntelliJ - that's OK
// If using local groovy files without Gradle the subcommands section may highlight as bad syntax in IntelliJ - that's OK
@Command(name = "module",
synopsisSubcommandLabel = "COMMAND", // Default is [COMMAND] indicating optional, but sub command here is required
subcommands = [
HelpCommand.class, // Adds standard help options (help as a subcommand, -h, and --help)
Recurse.class,
Update.class,
Get.class], // Note that these Groovy classes *must* start with a capital letter for some reason
RecurseCommand.class,
UpdateCommand.class,
GetCommand.class], // Note that these Groovy classes *must* start with a capital letter for some reason
description = "Sub command for interacting with modules")
class Module extends ItemCommand {
class ModuleCommand extends ItemCommandType {
@Override
ManagedItem getManager(String optionGitOrigin) {
return new ManagedModule(optionGitOrigin)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
// Copyright 2020 The Terasology Foundation
// SPDX-License-Identifier: Apache-2.0
package org.terasology.cli
package org.terasology.cli.commands

import org.terasology.cli.options.GitOptions
import picocli.CommandLine.ParentCommand
import picocli.CommandLine.Command
import picocli.CommandLine.Mixin
Expand All @@ -11,10 +13,10 @@ import picocli.CommandLine.Parameters
// Distinct from the sibling command add-remote which does *not* mix in GitOptions
@Command(name = "recurse",
description = "Gets one or more items and all their dependencies")
class Recurse extends BaseCommand implements Runnable {
class RecurseCommand extends BaseCommandType implements Runnable {

@ParentCommand
ItemCommand parent
ItemCommandType parent

/** Mix in a variety of supported Git extras */
@Mixin
Expand Down
Original file line number Diff line number Diff line change
@@ -1,17 +1,19 @@
// Copyright 2020 The Terasology Foundation
// SPDX-License-Identifier: Apache-2.0
package org.terasology.cli
package org.terasology.cli.commands

import org.terasology.cli.options.GitOptions
import picocli.CommandLine.ParentCommand
import picocli.CommandLine.Command
import picocli.CommandLine.Mixin
import picocli.CommandLine.Parameters

@Command(name = "update",
description = "Updates one or more items directly")
class Update extends BaseCommand implements Runnable {
class UpdateCommand extends BaseCommandType implements Runnable {

@ParentCommand
ItemCommand parent
ItemCommandType parent

/** Mix in a variety of supported Git extras */
@Mixin
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
// Copyright 2020 The Terasology Foundation
// SPDX-License-Identifier: Apache-2.0
package org.terasology.cli
package org.terasology.cli.helpers
/**
* Convenience class for pulling properties out of a 'gradle.properties' if present, for various overrides
* // TODO: YAML variant that can be added for more complex use cases?
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
// Copyright 2020 The Terasology Foundation
// SPDX-License-Identifier: Apache-2.0

package org.terasology.cli.managers

/**
* Marks a managed item as having the capacity to have dependencies, forcing implementation of a way to parse them.
*/
interface DependencyProvider {
def parseDependencies(String itemsToCheck)
}
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
// Copyright 2020 The Terasology Foundation
// SPDX-License-Identifier: Apache-2.0
package org.terasology.cli
package org.terasology.cli.managers
@GrabResolver(name = 'jcenter', root = 'http://jcenter.bintray.com/')
@Grab(group = 'org.ajoberstar', module = 'grgit', version = '1.9.3')
import org.ajoberstar.grgit.Grgit
import org.terasology.cli.helpers.PropHelper

/**
* Utility class for dealing with items managed in a developer workspace.
Expand Down Expand Up @@ -76,6 +77,44 @@ abstract class ManagedItem {
return code.toString() == "200"
}

List<String> recurse(List<String> items) {
def dependencies = []
println "Going to retrieve the following items (recursively): $items"
for (String item : items) {
// Check for circular dependencies - we should only ever act on a request to *retrieve* an item once
if (itemsRetrieved.contains(item)) {
println "Uh oh, we got told to re-retrieve the same thing for $item - somebody oopsed a circular dependency? Skipping"
} else {
// We didn't already try to retrieve this item: get it (if we already have it then getItem will just be a no-op)
getItem(item)
// Then goes and checks the item on disk and parses the thing to see if it has dependencies (even if we already had it)
dependencies << ((DependencyProvider) this).parseDependencies(item)
}
// Mark this item as retrieved just in case somebody made a whoops and introduced a circular dependency
itemsRetrieved << item
}

// If we parsed any dependencies, retrieve them recursively (and even if we already got them check them for dependencies as well)
if (!dependencies.isEmpty()) {
println "Got dependencies to fetch: " + dependencies
return recurse(dependencies)
}

println "Finally done recursing, both initial items and any parsed dependencies"
return null
}

def get(List<String> items) {
for (String itemName : items) {
getItem(itenName)
}
}

def getItem(String item) {
println "Going to get $item do we already have it? <logic to look for the dir existing>"
// Logic for a single retrieve, no dependency parsing involved
}

/**
* Primary entry point for retrieving items, kicks off recursively if needed.
* @param items the items we want to retrieve
Expand Down Expand Up @@ -121,23 +160,9 @@ abstract class ManagedItem {
Grgit.clone dir: itemDir, uri: targetUrl
}
/*
// This step allows the item type to check the newly cloned item and add in extra template stuff - TODO?
// This step allows the item type to check the newly cloned item and add in extra template stuff - TODO? Same as the recurse fix?
//itemTypeScript.copyInTemplateFiles(itemDir)
// Handle also retrieving dependencies if the item type cares about that
if (recurse) {
def foundDependencies = itemTypeScript.findDependencies(itemDir)
if (foundDependencies.length == 0) {
println "The $itemType $itemName did not appear to have any dependencies we need to worry about"
} else {
println "The $itemType $itemName has the following $itemType dependencies we care about: $foundDependencies"
String[] uniqueDependencies = foundDependencies - itemsRetrieved
println "After removing dupes already retrieved we have the remaining dependencies left: $uniqueDependencies"
if (uniqueDependencies.length > 0) {
retrieve(uniqueDependencies, true)
}
}
}*/
*/
}
}
}
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
// Copyright 2020 The Terasology Foundation
// SPDX-License-Identifier: Apache-2.0
package org.terasology.cli
class ManagedModule extends ManagedItem {
package org.terasology.cli.managers

class ManagedModule extends ManagedItem implements DependencyProvider {
ManagedModule() {
super()
}
Expand All @@ -25,6 +26,15 @@ class ManagedModule extends ManagedItem {
return "Terasology"
}

@Override
List<String> parseDependencies(String itemToCheck) {
List<String> foundDependencies = []

// logic to parse module.txt for dependencies

return foundDependencies
}

/**
* Copies in a fresh copy of build.gradle for all modules (in case changes are made and need to be propagated)
*/
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
// Copyright 2020 The Terasology Foundation
// SPDX-License-Identifier: Apache-2.0
package org.terasology.cli
package org.terasology.cli.options
import picocli.CommandLine.Option

/**
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
// Copyright 2020 The Terasology Foundation
// SPDX-License-Identifier: Apache-2.0

package org.terasology.cli.scm

/**
* Generic wrapper around SCM operations resulting in the retrieval of a resource
*/
class ScmGet {

}

0 comments on commit 85433d5

Please sign in to comment.