You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@maven.apache.org by hb...@apache.org on 2017/05/26 21:15:52 UTC

[16/48] maven-resolver git commit: Added GuiceRepositorySystemFactory to demonstrate usage of JSR-330/Guice to wire components

Added GuiceRepositorySystemFactory to demonstrate usage of JSR-330/Guice to wire components


Project: http://git-wip-us.apache.org/repos/asf/maven-resolver/repo
Commit: http://git-wip-us.apache.org/repos/asf/maven-resolver/commit/0a9b2a53
Tree: http://git-wip-us.apache.org/repos/asf/maven-resolver/tree/0a9b2a53
Diff: http://git-wip-us.apache.org/repos/asf/maven-resolver/diff/0a9b2a53

Branch: refs/heads/demos
Commit: 0a9b2a53bffbbaef70992dcdb243631f1bc8e48b
Parents: 276cf13
Author: Benjamin Bentmann <be...@sonatype.com>
Authored: Tue Apr 23 00:38:57 2013 +0200
Committer: Benjamin Bentmann <be...@sonatype.com>
Committed: Tue Apr 23 00:38:57 2013 +0200

----------------------------------------------------------------------
 .../aether/examples/guice/DemoAetherModule.java | 59 ++++++++++++++++++++
 .../guice/GuiceRepositorySystemFactory.java     | 28 ++++++++++
 .../manual/ManualWagonConfigurator.java         | 26 +++++++++
 .../eclipse/aether/examples/util/Booter.java    |  1 +
 4 files changed, 114 insertions(+)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/maven-resolver/blob/0a9b2a53/aether-demo-snippets/src/main/java/org/eclipse/aether/examples/guice/DemoAetherModule.java
----------------------------------------------------------------------
diff --git a/aether-demo-snippets/src/main/java/org/eclipse/aether/examples/guice/DemoAetherModule.java b/aether-demo-snippets/src/main/java/org/eclipse/aether/examples/guice/DemoAetherModule.java
new file mode 100644
index 0000000..be2b5d7
--- /dev/null
+++ b/aether-demo-snippets/src/main/java/org/eclipse/aether/examples/guice/DemoAetherModule.java
@@ -0,0 +1,59 @@
+/*******************************************************************************
+ * Copyright (c) 2013 Sonatype, Inc.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ *    Sonatype, Inc. - initial API and implementation
+ *******************************************************************************/
+package org.eclipse.aether.examples.guice;
+
+import java.util.Collections;
+import java.util.HashSet;
+import java.util.Set;
+
+import javax.inject.Named;
+import javax.inject.Singleton;
+
+import org.apache.maven.repository.internal.MavenAetherModule;
+import org.eclipse.aether.connector.file.FileRepositoryConnectorFactory;
+import org.eclipse.aether.connector.wagon.WagonConfigurator;
+import org.eclipse.aether.connector.wagon.WagonProvider;
+import org.eclipse.aether.connector.wagon.WagonRepositoryConnectorFactory;
+import org.eclipse.aether.examples.manual.ManualWagonConfigurator;
+import org.eclipse.aether.examples.manual.ManualWagonProvider;
+import org.eclipse.aether.spi.connector.RepositoryConnectorFactory;
+
+import com.google.inject.AbstractModule;
+import com.google.inject.Provides;
+import com.google.inject.name.Names;
+
+class DemoAetherModule
+    extends AbstractModule
+{
+
+    @Override
+    protected void configure()
+    {
+        install( new MavenAetherModule() );
+        // alternatively, use the Guice Multibindings extensions
+        bind( RepositoryConnectorFactory.class ).annotatedWith( Names.named( "file" ) ).to( FileRepositoryConnectorFactory.class );
+        bind( RepositoryConnectorFactory.class ).annotatedWith( Names.named( "wagon" ) ).to( WagonRepositoryConnectorFactory.class );
+        bind( WagonProvider.class ).to( ManualWagonProvider.class );
+        bind( WagonConfigurator.class ).to( ManualWagonConfigurator.class );
+    }
+
+    @Provides
+    @Singleton
+    Set<RepositoryConnectorFactory> provideRepositoryConnectorFactories( @Named( "file" ) RepositoryConnectorFactory file,
+                                                                         @Named( "wagon" ) RepositoryConnectorFactory wagon )
+    {
+        Set<RepositoryConnectorFactory> factories = new HashSet<RepositoryConnectorFactory>();
+        factories.add( file );
+        factories.add( wagon );
+        return Collections.unmodifiableSet( factories );
+    }
+
+}

http://git-wip-us.apache.org/repos/asf/maven-resolver/blob/0a9b2a53/aether-demo-snippets/src/main/java/org/eclipse/aether/examples/guice/GuiceRepositorySystemFactory.java
----------------------------------------------------------------------
diff --git a/aether-demo-snippets/src/main/java/org/eclipse/aether/examples/guice/GuiceRepositorySystemFactory.java b/aether-demo-snippets/src/main/java/org/eclipse/aether/examples/guice/GuiceRepositorySystemFactory.java
new file mode 100644
index 0000000..37c8b95
--- /dev/null
+++ b/aether-demo-snippets/src/main/java/org/eclipse/aether/examples/guice/GuiceRepositorySystemFactory.java
@@ -0,0 +1,28 @@
+/*******************************************************************************
+ * Copyright (c) 2013 Sonatype, Inc.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ *    Sonatype, Inc. - initial API and implementation
+ *******************************************************************************/
+package org.eclipse.aether.examples.guice;
+
+import org.eclipse.aether.RepositorySystem;
+
+import com.google.inject.Guice;
+
+/**
+ * A factory for repository system instances that employs JSR-330 via Guice to wire up the system's components.
+ */
+public class GuiceRepositorySystemFactory
+{
+
+    public static RepositorySystem newRepositorySystem()
+    {
+        return Guice.createInjector( new DemoAetherModule() ).getInstance( RepositorySystem.class );
+    }
+
+}

http://git-wip-us.apache.org/repos/asf/maven-resolver/blob/0a9b2a53/aether-demo-snippets/src/main/java/org/eclipse/aether/examples/manual/ManualWagonConfigurator.java
----------------------------------------------------------------------
diff --git a/aether-demo-snippets/src/main/java/org/eclipse/aether/examples/manual/ManualWagonConfigurator.java b/aether-demo-snippets/src/main/java/org/eclipse/aether/examples/manual/ManualWagonConfigurator.java
new file mode 100644
index 0000000..c2f531a
--- /dev/null
+++ b/aether-demo-snippets/src/main/java/org/eclipse/aether/examples/manual/ManualWagonConfigurator.java
@@ -0,0 +1,26 @@
+/*******************************************************************************
+ * Copyright (c) 2013 Sonatype, Inc.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ *    Sonatype, Inc. - initial API and implementation
+ *******************************************************************************/
+package org.eclipse.aether.examples.manual;
+
+import org.apache.maven.wagon.Wagon;
+import org.eclipse.aether.connector.wagon.WagonConfigurator;
+
+public class ManualWagonConfigurator
+    implements WagonConfigurator
+{
+
+    public void configure( Wagon wagon, Object configuration )
+        throws Exception
+    {
+        // no-op
+    }
+
+}

http://git-wip-us.apache.org/repos/asf/maven-resolver/blob/0a9b2a53/aether-demo-snippets/src/main/java/org/eclipse/aether/examples/util/Booter.java
----------------------------------------------------------------------
diff --git a/aether-demo-snippets/src/main/java/org/eclipse/aether/examples/util/Booter.java b/aether-demo-snippets/src/main/java/org/eclipse/aether/examples/util/Booter.java
index 2ec33f5..5911ed6 100644
--- a/aether-demo-snippets/src/main/java/org/eclipse/aether/examples/util/Booter.java
+++ b/aether-demo-snippets/src/main/java/org/eclipse/aether/examples/util/Booter.java
@@ -25,6 +25,7 @@ public class Booter
     public static RepositorySystem newRepositorySystem()
     {
         return org.eclipse.aether.examples.manual.ManualRepositorySystemFactory.newRepositorySystem();
+        // return org.eclipse.aether.examples.guice.GuiceRepositorySystemFactory.newRepositorySystem();
         // return org.eclipse.aether.examples.plexus.PlexusRepositorySystemFactory.newRepositorySystem();
     }