You are viewing a plain text version of this content. The canonical link for it is here.
Posted to issues@maven.apache.org by GitBox <gi...@apache.org> on 2021/04/27 10:19:05 UTC

[GitHub] [maven-resolver] michael-o commented on a change in pull request #99: Fix bindings and do test them

michael-o commented on a change in pull request #99:
URL: https://github.com/apache/maven-resolver/pull/99#discussion_r621071001



##########
File path: maven-resolver-demos/maven-resolver-demo-snippets/src/main/java/org/apache/maven/resolver/examples/util/Booter.java
##########
@@ -35,12 +35,42 @@
  */
 public class Booter
 {
+    public static final String SERVICE_LOCATOR = "serviceLocator";
 
-    public static RepositorySystem newRepositorySystem()
+    public static final String GUICE = "guice";
+
+    public static final String SISU = "sisu";
+
+    public static String selectFactory( String[] args )
+    {
+        if ( args == null || args.length == 0 )
+        {
+            return SERVICE_LOCATOR;
+        }
+        else
+        {
+            return args[0];
+        }
+    }
+
+    public static RepositorySystem newRepositorySystem( final String factory )
     {
-        return org.apache.maven.resolver.examples.manual.ManualRepositorySystemFactory.newRepositorySystem();
-        // return org.apache.maven.resolver.examples.guice.GuiceRepositorySystemFactory.newRepositorySystem();
-        // return org.apache.maven.resolver.examples.sisu.SisuRepositorySystemFactory.newRepositorySystem();
+        if ( SERVICE_LOCATOR.equals( factory ) )
+        {
+            return org.apache.maven.resolver.examples.manual.ManualRepositorySystemFactory.newRepositorySystem();
+        }
+        else if ( GUICE.equals( factory ) )
+        {
+            return org.apache.maven.resolver.examples.guice.GuiceRepositorySystemFactory.newRepositorySystem();
+        }
+        else if ( SISU.equals( factory ) )
+        {
+            return org.apache.maven.resolver.examples.sisu.SisuRepositorySystemFactory.newRepositorySystem();
+        }
+        else
+        {
+            throw new IllegalArgumentException( "Unknown factory: " + factory );
+        }

Review comment:
       You can use a switch case on strings here to make it more compact.




-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
users@infra.apache.org