Add detailed download reporting to AetherGrapeEngine

Groovy's Grape allows a user to enable download reports using the
system property groovy.grape.report.downloads. This commit updates
AetherGrapeEngine to honour this property and produce a detailed
download report when the system property is set to true. In the
absence of the system property, or when it's set to a value other than
true, the existing summary report is still produced.

[bs-344]
[60145094]
This commit is contained in:
Andy Wilkinson
2013-11-06 15:52:33 +00:00
parent dc4bf01e95
commit 6ab14a51eb
6 changed files with 262 additions and 69 deletions

View File

@@ -92,7 +92,11 @@ public class AetherGrapeEngineTests {
Map<String, Object> args = new HashMap<String, Object>();
System.setProperty("disableSpringSnapshotRepos", "true");
try {
new AetherGrapeEngine(this.groovyClassLoader).grab(args,
AetherGrapeEngine aetherGrapeEngine = new AetherGrapeEngine(
this.groovyClassLoader);
aetherGrapeEngine.addResolver(createResolver("restlet.org",
"http://maven.restlet.org"));
aetherGrapeEngine.grab(args,
createDependency("org.springframework", "spring-jdbc", "3.2.0.M1"));
}
finally {

View File

@@ -0,0 +1,75 @@
/*
* Copyright 2012-2013 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.springframework.boot.cli.compiler.grape;
import java.io.ByteArrayOutputStream;
import java.io.PrintStream;
import org.eclipse.aether.DefaultRepositorySystemSession;
import org.eclipse.aether.transfer.TransferCancelledException;
import org.eclipse.aether.transfer.TransferEvent;
import org.eclipse.aether.transfer.TransferResource;
import org.junit.Before;
import org.junit.Test;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertTrue;
public final class DetailedProgressReporterTests {
private static final String REPOSITORY = "http://my.repository.com/";
private static final String ARTIFACT = "org/alpha/bravo/charlie/1.2.3/charlie-1.2.3.jar";
private final TransferResource resource = new TransferResource(REPOSITORY, ARTIFACT,
null, null);
private final ByteArrayOutputStream baos = new ByteArrayOutputStream();
private final PrintStream out = new PrintStream(this.baos);
private final DefaultRepositorySystemSession session = new DefaultRepositorySystemSession();
@Before
public void initialize() {
new DetailedProgressReporter(this.session, this.out);
}
@Test
public void downloading() throws TransferCancelledException {
TransferEvent startedEvent = new TransferEvent.Builder(this.session,
this.resource).build();
this.session.getTransferListener().transferStarted(startedEvent);
assertEquals(String.format("Downloading: %s%s%n", REPOSITORY, ARTIFACT),
new String(this.baos.toByteArray()));
}
@Test
public void downloaded() throws InterruptedException {
// Ensure some transfer time
Thread.sleep(100);
TransferEvent completedEvent = new TransferEvent.Builder(this.session,
this.resource).addTransferredBytes(4096).build();
this.session.getTransferListener().transferSucceeded(completedEvent);
assertTrue(new String(this.baos.toByteArray()).matches(String.format(
"Downloaded: %s%s \\(4KB at [0-9]+\\.[0-9]KB/sec\\)\\n", REPOSITORY,
ARTIFACT)));
}
}