You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@sling.apache.org by ra...@apache.org on 2019/06/04 09:24:10 UTC

[sling-org-apache-sling-committer-cli] branch master updated (5aa8622 -> 2dddd99)

This is an automated email from the ASF dual-hosted git repository.

radu pushed a change to branch master
in repository https://gitbox.apache.org/repos/asf/sling-org-apache-sling-committer-cli.git.


    from 5aa8622  SLING-8391 - Add support for execution modes
     new e777f78  SLING-8391 - Add support for execution modes
     new 2dddd99  trivial: ignore the launcher folder

The 2 revisions listed above as "new" are entirely new to this
repository and will be described in separate emails.  The revisions
listed as "add" were already present in the repository and have only
been added to this reference.


Summary of changes:
 .gitignore                                            |  1 +
 pom.xml                                               |  5 +++++
 src/main/java/org/apache/sling/cli/impl/Command.java  |  5 ++++-
 .../org/apache/sling/cli/impl/CommandProcessor.java   |  6 +++---
 .../org/apache/sling/cli/impl/ExecutionContext.java   | 19 +++++++++++--------
 .../cli/impl/release/CreateJiraVersionCommand.java    |  3 ++-
 .../apache/sling/cli/impl/release/ListCommand.java    |  3 ++-
 .../cli/impl/release/PrepareVoteEmailCommand.java     |  3 ++-
 .../sling/cli/impl/release/TallyVotesCommand.java     |  3 ++-
 .../cli/impl/release/UpdateLocalSiteCommand.java      |  3 ++-
 .../sling/cli/impl/release/UpdateReporterCommand.java |  3 ++-
 .../cli/impl/release/PrepareVoteEmailCommandTest.java |  2 +-
 .../sling/cli/impl/release/TallyVotesCommandTest.java |  6 +++---
 .../cli/impl/release/UpdateReporterCommandTest.java   |  6 +++---
 14 files changed, 43 insertions(+), 25 deletions(-)


[sling-org-apache-sling-committer-cli] 01/02: SLING-8391 - Add support for execution modes

Posted by ra...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

radu pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/sling-org-apache-sling-committer-cli.git

commit e777f78a43cdd87028bdf158fb3aa983b82cf1ca
Author: Radu Cotescu <ra...@apache.org>
AuthorDate: Tue Jun 4 11:22:29 2019 +0200

    SLING-8391 - Add support for execution modes
    
    * made ExecutionContext and its handling more robust
---
 pom.xml                                               |  5 +++++
 src/main/java/org/apache/sling/cli/impl/Command.java  |  5 ++++-
 .../org/apache/sling/cli/impl/CommandProcessor.java   |  6 +++---
 .../org/apache/sling/cli/impl/ExecutionContext.java   | 19 +++++++++++--------
 .../cli/impl/release/CreateJiraVersionCommand.java    |  3 ++-
 .../apache/sling/cli/impl/release/ListCommand.java    |  3 ++-
 .../cli/impl/release/PrepareVoteEmailCommand.java     |  3 ++-
 .../sling/cli/impl/release/TallyVotesCommand.java     |  3 ++-
 .../cli/impl/release/UpdateLocalSiteCommand.java      |  3 ++-
 .../sling/cli/impl/release/UpdateReporterCommand.java |  3 ++-
 .../cli/impl/release/PrepareVoteEmailCommandTest.java |  2 +-
 .../sling/cli/impl/release/TallyVotesCommandTest.java |  6 +++---
 .../cli/impl/release/UpdateReporterCommandTest.java   |  6 +++---
 13 files changed, 42 insertions(+), 25 deletions(-)

diff --git a/pom.xml b/pom.xml
index 11c55ad..09766e2 100644
--- a/pom.xml
+++ b/pom.xml
@@ -172,6 +172,11 @@
 
     <dependencies>
         <dependency>
+            <groupId>org.jetbrains</groupId>
+            <artifactId>annotations</artifactId>
+            <scope>provided</scope>
+        </dependency>
+        <dependency>
             <groupId>org.osgi</groupId>
             <artifactId>org.osgi.service.component.annotations</artifactId>
             <scope>provided</scope>
diff --git a/src/main/java/org/apache/sling/cli/impl/Command.java b/src/main/java/org/apache/sling/cli/impl/Command.java
index 102b5e6..70a6c45 100644
--- a/src/main/java/org/apache/sling/cli/impl/Command.java
+++ b/src/main/java/org/apache/sling/cli/impl/Command.java
@@ -16,11 +16,14 @@
  */
 package org.apache.sling.cli.impl;
 
+
+import org.jetbrains.annotations.NotNull;
+
 public interface Command {
     
     String PROPERTY_NAME_COMMAND = "command";
     String PROPERTY_NAME_SUBCOMMAND = "subcommand";
     String PROPERTY_NAME_SUMMARY = "summary";
 
-    void execute(ExecutionContext context) throws Exception;
+    void execute(@NotNull ExecutionContext context) throws Exception;
 }
diff --git a/src/main/java/org/apache/sling/cli/impl/CommandProcessor.java b/src/main/java/org/apache/sling/cli/impl/CommandProcessor.java
index cb3de3a..9029d4b 100644
--- a/src/main/java/org/apache/sling/cli/impl/CommandProcessor.java
+++ b/src/main/java/org/apache/sling/cli/impl/CommandProcessor.java
@@ -88,12 +88,12 @@ public class CommandProcessor {
 
     private ExecutionContext defineContext(String[] arguments) {
         if (arguments.length < 3)
-            return null;
+            return ExecutionContext.DEFAULT;
         String target = arguments[2];
         if (arguments.length > 3) {
-            return new ExecutionContext(target, arguments[3]);
+            return new ExecutionContext(ExecutionContext.Mode.fromString(arguments[3]), target);
         } else {
-            return new ExecutionContext(target, null);
+            return new ExecutionContext(ExecutionContext.Mode.DRY_RUN, target);
         }
     }
     
diff --git a/src/main/java/org/apache/sling/cli/impl/ExecutionContext.java b/src/main/java/org/apache/sling/cli/impl/ExecutionContext.java
index 77eac71..6505508 100644
--- a/src/main/java/org/apache/sling/cli/impl/ExecutionContext.java
+++ b/src/main/java/org/apache/sling/cli/impl/ExecutionContext.java
@@ -18,6 +18,10 @@
  ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/
 package org.apache.sling.cli.impl;
 
+import java.util.Objects;
+
+import org.jetbrains.annotations.NotNull;
+import org.jetbrains.annotations.Nullable;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 
@@ -28,8 +32,9 @@ public class ExecutionContext {
 
     private static final Logger LOGGER = LoggerFactory.getLogger(ExecutionContext.class);
 
-    private final String target;
     private final Mode mode;
+    private final String target;
+    public static final ExecutionContext DEFAULT = new ExecutionContext(Mode.DRY_RUN, null);
 
     /**
      * Creates an {@code ExecutionContext}.
@@ -37,13 +42,9 @@ public class ExecutionContext {
      * @param target the command's target
      * @param mode   the execution mode
      */
-    public ExecutionContext(String target, String mode) {
-        this.target = target;
-        if (mode == null) {
-            this.mode = Mode.DRY_RUN;
-        } else {
-            this.mode = Mode.fromString(mode);
-        }
+    public ExecutionContext(@NotNull Mode mode, @Nullable String target) {
+        this.mode = mode;
+        this.target = Objects.requireNonNullElse(target, "");
     }
 
     /**
@@ -51,6 +52,7 @@ public class ExecutionContext {
      *
      * @return the execution target
      */
+    @NotNull
     public String getTarget() {
         return target;
     }
@@ -60,6 +62,7 @@ public class ExecutionContext {
      *
      * @return the execution mode
      */
+    @NotNull
     public Mode getMode() {
         return mode;
     }
diff --git a/src/main/java/org/apache/sling/cli/impl/release/CreateJiraVersionCommand.java b/src/main/java/org/apache/sling/cli/impl/release/CreateJiraVersionCommand.java
index a15c8a9..6605268 100644
--- a/src/main/java/org/apache/sling/cli/impl/release/CreateJiraVersionCommand.java
+++ b/src/main/java/org/apache/sling/cli/impl/release/CreateJiraVersionCommand.java
@@ -28,6 +28,7 @@ import org.apache.sling.cli.impl.jira.Version;
 import org.apache.sling.cli.impl.jira.VersionClient;
 import org.apache.sling.cli.impl.nexus.StagingRepository;
 import org.apache.sling.cli.impl.nexus.StagingRepositoryFinder;
+import org.jetbrains.annotations.NotNull;
 import org.osgi.service.component.annotations.Component;
 import org.osgi.service.component.annotations.Reference;
 import org.slf4j.Logger;
@@ -49,7 +50,7 @@ public class CreateJiraVersionCommand implements Command {
     private final Logger logger = LoggerFactory.getLogger(getClass());
 
     @Override
-    public void execute(ExecutionContext context) {
+    public void execute(@NotNull ExecutionContext context) {
         try {
             StagingRepository repo = repoFinder.find(Integer.parseInt(context.getTarget()));
             for (Release release : Release.fromString(repo.getDescription()) ) {
diff --git a/src/main/java/org/apache/sling/cli/impl/release/ListCommand.java b/src/main/java/org/apache/sling/cli/impl/release/ListCommand.java
index 39b9b8d..4a59b7f 100644
--- a/src/main/java/org/apache/sling/cli/impl/release/ListCommand.java
+++ b/src/main/java/org/apache/sling/cli/impl/release/ListCommand.java
@@ -21,6 +21,7 @@ import java.io.IOException;
 import org.apache.sling.cli.impl.Command;
 import org.apache.sling.cli.impl.ExecutionContext;
 import org.apache.sling.cli.impl.nexus.StagingRepositoryFinder;
+import org.jetbrains.annotations.NotNull;
 import org.osgi.service.component.annotations.Component;
 import org.osgi.service.component.annotations.Reference;
 import org.slf4j.Logger;
@@ -38,7 +39,7 @@ public class ListCommand implements Command {
     private StagingRepositoryFinder repoFinder;
 
     @Override
-    public void execute(ExecutionContext context) {
+    public void execute(@NotNull ExecutionContext context) {
         try {
             repoFinder.list().stream()
                 .forEach( r -> logger.info("{}\t{}", r.getRepositoryId(), r.getDescription()));
diff --git a/src/main/java/org/apache/sling/cli/impl/release/PrepareVoteEmailCommand.java b/src/main/java/org/apache/sling/cli/impl/release/PrepareVoteEmailCommand.java
index 748f68f..aff45f0 100644
--- a/src/main/java/org/apache/sling/cli/impl/release/PrepareVoteEmailCommand.java
+++ b/src/main/java/org/apache/sling/cli/impl/release/PrepareVoteEmailCommand.java
@@ -33,6 +33,7 @@ import org.apache.sling.cli.impl.nexus.StagingRepository;
 import org.apache.sling.cli.impl.nexus.StagingRepositoryFinder;
 import org.apache.sling.cli.impl.people.Member;
 import org.apache.sling.cli.impl.people.MembersFinder;
+import org.jetbrains.annotations.NotNull;
 import org.osgi.service.component.annotations.Component;
 import org.osgi.service.component.annotations.Reference;
 import org.slf4j.Logger;
@@ -94,7 +95,7 @@ public class PrepareVoteEmailCommand implements Command {
             "https://issues.apache.org/jira/browse/SLING/fixforversion/##VERSION_ID##";
 
     @Override
-    public void execute(ExecutionContext context) {
+    public void execute(@NotNull ExecutionContext context) {
         try {
             int repoId = Integer.parseInt(context.getTarget());
             StagingRepository repo = repoFinder.find(repoId);
diff --git a/src/main/java/org/apache/sling/cli/impl/release/TallyVotesCommand.java b/src/main/java/org/apache/sling/cli/impl/release/TallyVotesCommand.java
index 131a221..8cf26f2 100644
--- a/src/main/java/org/apache/sling/cli/impl/release/TallyVotesCommand.java
+++ b/src/main/java/org/apache/sling/cli/impl/release/TallyVotesCommand.java
@@ -38,6 +38,7 @@ import org.apache.sling.cli.impl.nexus.StagingRepository;
 import org.apache.sling.cli.impl.nexus.StagingRepositoryFinder;
 import org.apache.sling.cli.impl.people.Member;
 import org.apache.sling.cli.impl.people.MembersFinder;
+import org.jetbrains.annotations.NotNull;
 import org.osgi.service.component.annotations.Component;
 import org.osgi.service.component.annotations.Reference;
 import org.slf4j.Logger;
@@ -85,7 +86,7 @@ public class TallyVotesCommand implements Command {
             "\n";
 
     @Override
-    public void execute(ExecutionContext context) {
+    public void execute(@NotNull ExecutionContext context) {
         try {
             
             StagingRepository repository = repoFinder.find(Integer.parseInt(context.getTarget()));
diff --git a/src/main/java/org/apache/sling/cli/impl/release/UpdateLocalSiteCommand.java b/src/main/java/org/apache/sling/cli/impl/release/UpdateLocalSiteCommand.java
index 66aef04..d9ad68b 100644
--- a/src/main/java/org/apache/sling/cli/impl/release/UpdateLocalSiteCommand.java
+++ b/src/main/java/org/apache/sling/cli/impl/release/UpdateLocalSiteCommand.java
@@ -32,6 +32,7 @@ import org.eclipse.jgit.api.Git;
 import org.eclipse.jgit.api.ResetCommand.ResetType;
 import org.eclipse.jgit.api.errors.GitAPIException;
 import org.eclipse.jgit.lib.TextProgressMonitor;
+import org.jetbrains.annotations.NotNull;
 import org.osgi.service.component.annotations.Component;
 import org.osgi.service.component.annotations.Reference;
 import org.slf4j.Logger;
@@ -52,7 +53,7 @@ public class UpdateLocalSiteCommand implements Command {
     private final Logger logger = LoggerFactory.getLogger(getClass());
     
     @Override
-    public void execute(ExecutionContext context) {
+    public void execute(@NotNull ExecutionContext context) {
         try {
             ensureRepo();
             try ( Git git = Git.open(new File(GIT_CHECKOUT)) ) {
diff --git a/src/main/java/org/apache/sling/cli/impl/release/UpdateReporterCommand.java b/src/main/java/org/apache/sling/cli/impl/release/UpdateReporterCommand.java
index a53cfae..d613487 100644
--- a/src/main/java/org/apache/sling/cli/impl/release/UpdateReporterCommand.java
+++ b/src/main/java/org/apache/sling/cli/impl/release/UpdateReporterCommand.java
@@ -38,6 +38,7 @@ import org.apache.sling.cli.impl.UserInput;
 import org.apache.sling.cli.impl.http.HttpClientFactory;
 import org.apache.sling.cli.impl.nexus.StagingRepository;
 import org.apache.sling.cli.impl.nexus.StagingRepositoryFinder;
+import org.jetbrains.annotations.NotNull;
 import org.osgi.service.component.annotations.Component;
 import org.osgi.service.component.annotations.Reference;
 import org.slf4j.Logger;
@@ -61,7 +62,7 @@ public class UpdateReporterCommand implements Command {
     private HttpClientFactory httpClientFactory;
 
     @Override
-    public void execute(ExecutionContext context) {
+    public void execute(@NotNull ExecutionContext context) {
         try {
             StagingRepository repository = repoFinder.find(Integer.parseInt(context.getTarget()));
             List<Release> releases = Release.fromString(repository.getDescription());
diff --git a/src/test/java/org/apache/sling/cli/impl/release/PrepareVoteEmailCommandTest.java b/src/test/java/org/apache/sling/cli/impl/release/PrepareVoteEmailCommandTest.java
index 55ab275..d459306 100644
--- a/src/test/java/org/apache/sling/cli/impl/release/PrepareVoteEmailCommandTest.java
+++ b/src/test/java/org/apache/sling/cli/impl/release/PrepareVoteEmailCommandTest.java
@@ -52,7 +52,7 @@ public class PrepareVoteEmailCommandTest {
         ServiceReference<?> reference =
                 osgiContext.bundleContext().getServiceReference(Command.class.getName());
         Command command = (Command) osgiContext.bundleContext().getService(reference);
-        command.execute(new ExecutionContext("123", "--auto"));
+        command.execute(new ExecutionContext(ExecutionContext.Mode.AUTO, "123"));
         verify(mailer).send(
                 "From: John Doe <jo...@apache.org>\n" +
                         "To: \"Sling Developers List\" <de...@sling.apache.org>\n" +
diff --git a/src/test/java/org/apache/sling/cli/impl/release/TallyVotesCommandTest.java b/src/test/java/org/apache/sling/cli/impl/release/TallyVotesCommandTest.java
index bb25d9f..6b8bece 100644
--- a/src/test/java/org/apache/sling/cli/impl/release/TallyVotesCommandTest.java
+++ b/src/test/java/org/apache/sling/cli/impl/release/TallyVotesCommandTest.java
@@ -85,7 +85,7 @@ public class TallyVotesCommandTest {
         ServiceReference<?> reference =
                 osgiContext.bundleContext().getServiceReference(Command.class.getName());
         Command command = (Command) osgiContext.bundleContext().getService(reference);
-        command.execute(new ExecutionContext("123", null));
+        command.execute(new ExecutionContext(ExecutionContext.Mode.DRY_RUN, "123"));
         verify(logger).info(
                 "From: John Doe <jo...@apache.org> \n" +
                 "To: \"Sling Developers List\" <de...@sling.apache.org>\n" +
@@ -124,7 +124,7 @@ public class TallyVotesCommandTest {
         ServiceReference<?> reference =
                 osgiContext.bundleContext().getServiceReference(Command.class.getName());
         Command command = (Command) osgiContext.bundleContext().getService(reference);
-        command.execute(new ExecutionContext("123", null));
+        command.execute(new ExecutionContext(ExecutionContext.Mode.DRY_RUN, "123"));
         verify(logger).info(
                 "Release {} does not have at least 3 binding votes.",
                 "Apache Sling CLI Test 1.0.0"
@@ -148,7 +148,7 @@ public class TallyVotesCommandTest {
         ServiceReference<?> reference =
                 osgiContext.bundleContext().getServiceReference(Command.class.getName());
         Command command = (Command) osgiContext.bundleContext().getService(reference);
-        command.execute(new ExecutionContext("123", "--auto"));
+        command.execute(new ExecutionContext(ExecutionContext.Mode.AUTO, "123"));
         verify(mailer).send(
                 "From: John Doe <jo...@apache.org> \n" +
                         "To: \"Sling Developers List\" <de...@sling.apache.org>\n" +
diff --git a/src/test/java/org/apache/sling/cli/impl/release/UpdateReporterCommandTest.java b/src/test/java/org/apache/sling/cli/impl/release/UpdateReporterCommandTest.java
index 8af6c63..ac5f758 100644
--- a/src/test/java/org/apache/sling/cli/impl/release/UpdateReporterCommandTest.java
+++ b/src/test/java/org/apache/sling/cli/impl/release/UpdateReporterCommandTest.java
@@ -90,7 +90,7 @@ public class UpdateReporterCommandTest {
         Command updateReporter = osgiContext.getService(Command.class);
         assertTrue("Expected to retrieve the UpdateReporterCommand from the mocked OSGi environment.",
                 updateReporter instanceof UpdateReporterCommand);
-        updateReporter.execute(new ExecutionContext("42", "--dry-run"));
+        updateReporter.execute(new ExecutionContext(ExecutionContext.Mode.DRY_RUN, "42"));
         verify(logger).info("The following {} would be added to the Apache Reporter System:", "releases");
         verify(logger).info("  - {}", "Apache Sling CLI 1");
         verify(logger).info("  - {}", "Apache Sling CLI 2");
@@ -113,7 +113,7 @@ public class UpdateReporterCommandTest {
         when(response.getStatusLine()).thenReturn(statusLine);
         when(statusLine.getStatusCode()).thenReturn(200);
         when(client.execute(any())).thenReturn(response);
-        updateReporter.execute(new ExecutionContext("42", "--interactive"));
+        updateReporter.execute(new ExecutionContext(ExecutionContext.Mode.INTERACTIVE, "42"));
         verify(client, times(2)).execute(any());
     }
 
@@ -128,7 +128,7 @@ public class UpdateReporterCommandTest {
         when(response.getStatusLine()).thenReturn(statusLine);
         when(statusLine.getStatusCode()).thenReturn(200);
         when(client.execute(any())).thenReturn(response);
-        updateReporter.execute(new ExecutionContext("42", "--auto"));
+        updateReporter.execute(new ExecutionContext(ExecutionContext.Mode.AUTO, "42"));
         verify(client, times(2)).execute(any());
     }
 


[sling-org-apache-sling-committer-cli] 02/02: trivial: ignore the launcher folder

Posted by ra...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

radu pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/sling-org-apache-sling-committer-cli.git

commit 2dddd99b06252067c7ac3f24df51d637a284c8f3
Author: Radu Cotescu <ra...@apache.org>
AuthorDate: Tue Jun 4 11:23:56 2019 +0200

    trivial: ignore the launcher folder
---
 .gitignore | 1 +
 1 file changed, 1 insertion(+)

diff --git a/.gitignore b/.gitignore
index a864a38..72d1875 100644
--- a/.gitignore
+++ b/.gitignore
@@ -1,5 +1,6 @@
 docker-env
 /target/
+/launcher/
 .idea
 .classpath
 .metadata