maven-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From hbout...@apache.org
Subject [23/48] maven-resolver git commit: Polished example code
Date Fri, 26 May 2017 21:15:59 GMT
Polished example code


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

Branch: refs/heads/demos
Commit: bfcb0fd12d2425f5c423e88ad013a7f7b84078bb
Parents: 4af4916
Author: Benjamin Bentmann <bentmann@sonatype.com>
Authored: Sat Aug 17 16:21:14 2013 +0200
Committer: Benjamin Bentmann <bentmann@sonatype.com>
Committed: Sat Aug 17 16:21:14 2013 +0200

----------------------------------------------------------------------
 aether-demo-maven-plugin/pom.xml                |  3 +-
 .../examples/maven/ResolveArtifactMojo.java     |  4 +-
 .../aether/examples/FindAvailableVersions.java  |  4 +-
 .../aether/examples/FindNewestVersion.java      |  4 +-
 .../aether/examples/GetDependencyTree.java      |  4 +-
 .../aether/examples/GetDirectDependencies.java  |  4 +-
 .../aether/examples/ResolveArtifact.java        |  4 +-
 .../examples/ResolveTransitiveDependencies.java |  4 +-
 .../util/ConsoleDependencyGraphDumper.java      | 62 ++++++++++++++++----
 .../examples/util/ConsoleTransferListener.java  | 11 +++-
 10 files changed, 77 insertions(+), 27 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/maven-resolver/blob/bfcb0fd1/aether-demo-maven-plugin/pom.xml
----------------------------------------------------------------------
diff --git a/aether-demo-maven-plugin/pom.xml b/aether-demo-maven-plugin/pom.xml
index 85a6209..46b4cdf 100644
--- a/aether-demo-maven-plugin/pom.xml
+++ b/aether-demo-maven-plugin/pom.xml
@@ -30,7 +30,7 @@
   <inceptionYear>2010</inceptionYear>
 
   <prerequisites>
-    <maven>3.1.0</maven>
+    <maven>3.1.0-alpha-1</maven>
   </prerequisites>
 
   <properties>
@@ -43,6 +43,7 @@
       <groupId>org.apache.maven</groupId>
       <artifactId>maven-plugin-api</artifactId>
       <version>${mavenVersion}</version>
+      <scope>provided</scope>
       <exclusions>
         <exclusion>
           <groupId>org.apache.maven</groupId>

http://git-wip-us.apache.org/repos/asf/maven-resolver/blob/bfcb0fd1/aether-demo-maven-plugin/src/main/java/org/eclipse/aether/examples/maven/ResolveArtifactMojo.java
----------------------------------------------------------------------
diff --git a/aether-demo-maven-plugin/src/main/java/org/eclipse/aether/examples/maven/ResolveArtifactMojo.java
b/aether-demo-maven-plugin/src/main/java/org/eclipse/aether/examples/maven/ResolveArtifactMojo.java
index bd6d2c8..1039bc1 100644
--- a/aether-demo-maven-plugin/src/main/java/org/eclipse/aether/examples/maven/ResolveArtifactMojo.java
+++ b/aether-demo-maven-plugin/src/main/java/org/eclipse/aether/examples/maven/ResolveArtifactMojo.java
@@ -1,5 +1,5 @@
 /*******************************************************************************
- * Copyright (c) 2010, 2012 Sonatype, Inc.
+ * Copyright (c) 2010, 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
@@ -25,6 +25,8 @@ import org.eclipse.aether.resolution.ArtifactResolutionException;
 import org.eclipse.aether.resolution.ArtifactResult;
 
 /**
+ * Resolves a single artifact (not including its transitive dependencies).
+ * 
  * @goal resolve-artifact
  */
 public class ResolveArtifactMojo

http://git-wip-us.apache.org/repos/asf/maven-resolver/blob/bfcb0fd1/aether-demo-snippets/src/main/java/org/eclipse/aether/examples/FindAvailableVersions.java
----------------------------------------------------------------------
diff --git a/aether-demo-snippets/src/main/java/org/eclipse/aether/examples/FindAvailableVersions.java
b/aether-demo-snippets/src/main/java/org/eclipse/aether/examples/FindAvailableVersions.java
index 772445a..be309b0 100644
--- a/aether-demo-snippets/src/main/java/org/eclipse/aether/examples/FindAvailableVersions.java
+++ b/aether-demo-snippets/src/main/java/org/eclipse/aether/examples/FindAvailableVersions.java
@@ -1,5 +1,5 @@
 /*******************************************************************************
- * Copyright (c) 2010, 2012 Sonatype, Inc.
+ * Copyright (c) 2010, 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
@@ -38,7 +38,7 @@ public class FindAvailableVersions
 
         RepositorySystemSession session = Booter.newRepositorySystemSession( system );
 
-        Artifact artifact = new DefaultArtifact( "org.sonatype.aether:aether-util:[0,)" );
+        Artifact artifact = new DefaultArtifact( "org.eclipse.aether:aether-util:[0,)" );
 
         RemoteRepository repo = Booter.newCentralRepository();
 

http://git-wip-us.apache.org/repos/asf/maven-resolver/blob/bfcb0fd1/aether-demo-snippets/src/main/java/org/eclipse/aether/examples/FindNewestVersion.java
----------------------------------------------------------------------
diff --git a/aether-demo-snippets/src/main/java/org/eclipse/aether/examples/FindNewestVersion.java
b/aether-demo-snippets/src/main/java/org/eclipse/aether/examples/FindNewestVersion.java
index fa7b38f..e039232 100644
--- a/aether-demo-snippets/src/main/java/org/eclipse/aether/examples/FindNewestVersion.java
+++ b/aether-demo-snippets/src/main/java/org/eclipse/aether/examples/FindNewestVersion.java
@@ -1,5 +1,5 @@
 /*******************************************************************************
- * Copyright (c) 2010, 2012 Sonatype, Inc.
+ * Copyright (c) 2010, 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
@@ -36,7 +36,7 @@ public class FindNewestVersion
 
         RepositorySystemSession session = Booter.newRepositorySystemSession( system );
 
-        Artifact artifact = new DefaultArtifact( "org.sonatype.aether:aether-util:[0,)" );
+        Artifact artifact = new DefaultArtifact( "org.eclipse.aether:aether-util:[0,)" );
 
         RemoteRepository repo = Booter.newCentralRepository();
 

http://git-wip-us.apache.org/repos/asf/maven-resolver/blob/bfcb0fd1/aether-demo-snippets/src/main/java/org/eclipse/aether/examples/GetDependencyTree.java
----------------------------------------------------------------------
diff --git a/aether-demo-snippets/src/main/java/org/eclipse/aether/examples/GetDependencyTree.java
b/aether-demo-snippets/src/main/java/org/eclipse/aether/examples/GetDependencyTree.java
index 8c88348..0265895 100644
--- a/aether-demo-snippets/src/main/java/org/eclipse/aether/examples/GetDependencyTree.java
+++ b/aether-demo-snippets/src/main/java/org/eclipse/aether/examples/GetDependencyTree.java
@@ -1,5 +1,5 @@
 /*******************************************************************************
- * Copyright (c) 2010, 2012 Sonatype, Inc.
+ * Copyright (c) 2010, 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
@@ -37,7 +37,7 @@ public class GetDependencyTree
 
         RepositorySystemSession session = Booter.newRepositorySystemSession( system );
 
-        Artifact artifact = new DefaultArtifact( "org.apache.maven:maven-aether-provider:3.0.2"
);
+        Artifact artifact = new DefaultArtifact( "org.apache.maven:maven-aether-provider:3.1.0"
);
 
         RemoteRepository repo = Booter.newCentralRepository();
 

http://git-wip-us.apache.org/repos/asf/maven-resolver/blob/bfcb0fd1/aether-demo-snippets/src/main/java/org/eclipse/aether/examples/GetDirectDependencies.java
----------------------------------------------------------------------
diff --git a/aether-demo-snippets/src/main/java/org/eclipse/aether/examples/GetDirectDependencies.java
b/aether-demo-snippets/src/main/java/org/eclipse/aether/examples/GetDirectDependencies.java
index 3fafb7e..bb70025 100644
--- a/aether-demo-snippets/src/main/java/org/eclipse/aether/examples/GetDirectDependencies.java
+++ b/aether-demo-snippets/src/main/java/org/eclipse/aether/examples/GetDirectDependencies.java
@@ -1,5 +1,5 @@
 /*******************************************************************************
- * Copyright (c) 2010, 2012 Sonatype, Inc.
+ * Copyright (c) 2010, 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
@@ -36,7 +36,7 @@ public class GetDirectDependencies
 
         RepositorySystemSession session = Booter.newRepositorySystemSession( system );
 
-        Artifact artifact = new DefaultArtifact( "org.sonatype.aether:aether-impl:1.13" );
+        Artifact artifact = new DefaultArtifact( "org.eclipse.aether:aether-impl:0.9.0.M3"
);
 
         RemoteRepository repo = Booter.newCentralRepository();
 

http://git-wip-us.apache.org/repos/asf/maven-resolver/blob/bfcb0fd1/aether-demo-snippets/src/main/java/org/eclipse/aether/examples/ResolveArtifact.java
----------------------------------------------------------------------
diff --git a/aether-demo-snippets/src/main/java/org/eclipse/aether/examples/ResolveArtifact.java
b/aether-demo-snippets/src/main/java/org/eclipse/aether/examples/ResolveArtifact.java
index bcc8aa1..655678d 100644
--- a/aether-demo-snippets/src/main/java/org/eclipse/aether/examples/ResolveArtifact.java
+++ b/aether-demo-snippets/src/main/java/org/eclipse/aether/examples/ResolveArtifact.java
@@ -1,5 +1,5 @@
 /*******************************************************************************
- * Copyright (c) 2010, 2012 Sonatype, Inc.
+ * Copyright (c) 2010, 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
@@ -35,7 +35,7 @@ public class ResolveArtifact
 
         RepositorySystemSession session = Booter.newRepositorySystemSession( system );
 
-        Artifact artifact = new DefaultArtifact( "org.sonatype.aether:aether-util:1.13" );
+        Artifact artifact = new DefaultArtifact( "org.eclipse.aether:aether-util:0.9.0.M3"
);
 
         RemoteRepository repo = Booter.newCentralRepository();
 

http://git-wip-us.apache.org/repos/asf/maven-resolver/blob/bfcb0fd1/aether-demo-snippets/src/main/java/org/eclipse/aether/examples/ResolveTransitiveDependencies.java
----------------------------------------------------------------------
diff --git a/aether-demo-snippets/src/main/java/org/eclipse/aether/examples/ResolveTransitiveDependencies.java
b/aether-demo-snippets/src/main/java/org/eclipse/aether/examples/ResolveTransitiveDependencies.java
index 9cf7cc8..fbf9489 100644
--- a/aether-demo-snippets/src/main/java/org/eclipse/aether/examples/ResolveTransitiveDependencies.java
+++ b/aether-demo-snippets/src/main/java/org/eclipse/aether/examples/ResolveTransitiveDependencies.java
@@ -1,5 +1,5 @@
 /*******************************************************************************
- * Copyright (c) 2010, 2012 Sonatype, Inc.
+ * Copyright (c) 2010, 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
@@ -42,7 +42,7 @@ public class ResolveTransitiveDependencies
 
         RepositorySystemSession session = Booter.newRepositorySystemSession( system );
 
-        Artifact artifact = new DefaultArtifact( "org.sonatype.aether:aether-impl:1.13" );
+        Artifact artifact = new DefaultArtifact( "org.eclipse.aether:aether-impl:0.9.0.M3"
);
 
         RemoteRepository repo = Booter.newCentralRepository();
 

http://git-wip-us.apache.org/repos/asf/maven-resolver/blob/bfcb0fd1/aether-demo-snippets/src/main/java/org/eclipse/aether/examples/util/ConsoleDependencyGraphDumper.java
----------------------------------------------------------------------
diff --git a/aether-demo-snippets/src/main/java/org/eclipse/aether/examples/util/ConsoleDependencyGraphDumper.java
b/aether-demo-snippets/src/main/java/org/eclipse/aether/examples/util/ConsoleDependencyGraphDumper.java
index 59867a3..254b200 100644
--- a/aether-demo-snippets/src/main/java/org/eclipse/aether/examples/util/ConsoleDependencyGraphDumper.java
+++ b/aether-demo-snippets/src/main/java/org/eclipse/aether/examples/util/ConsoleDependencyGraphDumper.java
@@ -1,5 +1,5 @@
 /*******************************************************************************
- * Copyright (c) 2010, 2011 Sonatype, Inc.
+ * Copyright (c) 2010, 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
@@ -11,6 +11,9 @@
 package org.eclipse.aether.examples.util;
 
 import java.io.PrintStream;
+import java.util.ArrayList;
+import java.util.Iterator;
+import java.util.List;
 
 import org.eclipse.aether.graph.DependencyNode;
 import org.eclipse.aether.graph.DependencyVisitor;
@@ -24,7 +27,7 @@ public class ConsoleDependencyGraphDumper
 
     private PrintStream out;
 
-    private String currentIndent = "";
+    private List<ChildInfo> childInfos = new ArrayList<ChildInfo>();
 
     public ConsoleDependencyGraphDumper()
     {
@@ -38,22 +41,61 @@ public class ConsoleDependencyGraphDumper
 
     public boolean visitEnter( DependencyNode node )
     {
-        out.println( currentIndent + node );
-        if ( currentIndent.length() <= 0 )
+        out.println( formatIndentation() + formatNode( node ) );
+        childInfos.add( new ChildInfo( node.getChildren().size() ) );
+        return true;
+    }
+
+    private String formatIndentation()
+    {
+        StringBuilder buffer = new StringBuilder( 128 );
+        for ( Iterator<ChildInfo> it = childInfos.iterator(); it.hasNext(); )
+        {
+            buffer.append( it.next().formatIndentation( !it.hasNext() ) );
+        }
+        return buffer.toString();
+    }
+
+    private String formatNode( DependencyNode node )
+    {
+        return String.valueOf( node );
+    }
+
+    public boolean visitLeave( DependencyNode node )
+    {
+        if ( !childInfos.isEmpty() )
         {
-            currentIndent = "+- ";
+            childInfos.remove( childInfos.size() - 1 );
         }
-        else
+        if ( !childInfos.isEmpty() )
         {
-            currentIndent = "|  " + currentIndent;
+            childInfos.get( childInfos.size() - 1 ).index++;
         }
         return true;
     }
 
-    public boolean visitLeave( DependencyNode node )
+    private static class ChildInfo
     {
-        currentIndent = currentIndent.substring( 3, currentIndent.length() );
-        return true;
+
+        final int count;
+
+        int index;
+
+        public ChildInfo( int count )
+        {
+            this.count = count;
+        }
+
+        public String formatIndentation( boolean end )
+        {
+            boolean last = index + 1 >= count;
+            if ( end )
+            {
+                return last ? "\\- " : "+- ";
+            }
+            return last ? "   " : "|  ";
+        }
+
     }
 
 }

http://git-wip-us.apache.org/repos/asf/maven-resolver/blob/bfcb0fd1/aether-demo-snippets/src/main/java/org/eclipse/aether/examples/util/ConsoleTransferListener.java
----------------------------------------------------------------------
diff --git a/aether-demo-snippets/src/main/java/org/eclipse/aether/examples/util/ConsoleTransferListener.java
b/aether-demo-snippets/src/main/java/org/eclipse/aether/examples/util/ConsoleTransferListener.java
index f162975..b89329c 100644
--- a/aether-demo-snippets/src/main/java/org/eclipse/aether/examples/util/ConsoleTransferListener.java
+++ b/aether-demo-snippets/src/main/java/org/eclipse/aether/examples/util/ConsoleTransferListener.java
@@ -1,5 +1,5 @@
 /*******************************************************************************
- * Copyright (c) 2010, 2011 Sonatype, Inc.
+ * Copyright (c) 2010, 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
@@ -18,6 +18,7 @@ import java.util.Map;
 import java.util.concurrent.ConcurrentHashMap;
 
 import org.eclipse.aether.transfer.AbstractTransferListener;
+import org.eclipse.aether.transfer.MetadataNotFoundException;
 import org.eclipse.aether.transfer.TransferEvent;
 import org.eclipse.aether.transfer.TransferResource;
 
@@ -123,8 +124,9 @@ public class ConsoleTransferListener
             long duration = System.currentTimeMillis() - resource.getTransferStartTime();
             if ( duration > 0 )
             {
+                long bytes = contentLength - resource.getResumeOffset();
                 DecimalFormat format = new DecimalFormat( "0.0", new DecimalFormatSymbols(
Locale.ENGLISH ) );
-                double kbPerSec = ( contentLength / 1024.0 ) / ( duration / 1000.0 );
+                double kbPerSec = ( bytes / 1024.0 ) / ( duration / 1000.0 );
                 throughput = " at " + format.format( kbPerSec ) + " KB/sec";
             }
 
@@ -138,7 +140,10 @@ public class ConsoleTransferListener
     {
         transferCompleted( event );
 
-        event.getException().printStackTrace( out );
+        if ( !( event.getException() instanceof MetadataNotFoundException ) )
+        {
+            event.getException().printStackTrace( out );
+        }
     }
 
     private void transferCompleted( TransferEvent event )


Mime
View raw message