Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Detailed logging and generated plexus component metadata #14

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
33 changes: 33 additions & 0 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -84,9 +84,42 @@
</excludes>
</configuration>
</plugin>
<!-- generate plexus DI metadata from annotations -->
<plugin>
<groupId>org.codehaus.plexus</groupId>
<artifactId>plexus-component-metadata</artifactId>
<version>1.5.5</version>
<executions>
<execution>
<goals>
<goal>generate-metadata</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</build>
<dependencies>
<dependency>
<groupId>javax.inject</groupId>
<artifactId>javax.inject</artifactId>
<version>1</version>
</dependency>
<dependency>
<groupId>org.codehaus.plexus</groupId>
<artifactId>plexus-component-annotations</artifactId>
<version>1.5.5</version>
</dependency>
<dependency>
<groupId>org.apache.maven.plugin-tools</groupId>
<artifactId>maven-plugin-annotations</artifactId>
<version>3.2</version>
</dependency>
<dependency>
<groupId>org.apache.maven</groupId>
<artifactId>maven-project</artifactId>
<version>2.2.1</version>
</dependency>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
Expand Down
4 changes: 2 additions & 2 deletions src/main/java/org/kuali/maven/wagon/AbstractWagon.java
Original file line number Diff line number Diff line change
Expand Up @@ -163,7 +163,7 @@ public final void disconnect() throws ConnectionException {
}

public final void get(final String resourceName, final File destination) throws TransferFailedException, ResourceDoesNotExistException, AuthorizationException {
Resource resource = new Resource(resourceName);
S3Resource resource = new S3Resource(resourceName);
transferListeners.fireTransferInitiated(resource, TransferEvent.REQUEST_GET);
transferListeners.fireTransferStarted(resource, TransferEvent.REQUEST_GET);

Expand Down Expand Up @@ -225,7 +225,7 @@ public final void openConnection() throws ConnectionException, AuthenticationExc
}

protected PutFileContext getPutFileContext(File source, String destination) {
Resource resource = new Resource(destination);
S3Resource resource = new S3Resource(destination);
PutFileContext context = new PutFileContext();
context.setResource(resource);
context.setProgress(new TransferProgress(resource, TransferEvent.REQUEST_PUT, transferListeners));
Expand Down
13 changes: 11 additions & 2 deletions src/main/java/org/kuali/maven/wagon/S3Listener.java
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
import org.apache.maven.wagon.events.SessionListener;
import org.apache.maven.wagon.events.TransferEvent;
import org.apache.maven.wagon.events.TransferListener;
import org.apache.maven.wagon.resource.Resource;
import org.kuali.common.aws.s3.SimpleFormatter;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
Expand All @@ -40,7 +41,15 @@ public class S3Listener implements TransferListener, SessionListener {
public void transferCompleted(final TransferEvent transferEvent) {
TransferTracker tt = sessionTracker.getCurrentTransfer();
tt.setCompleted(System.currentTimeMillis());
// System.out.println();
Resource resource = transferEvent.getResource();
if (resource instanceof S3Resource) {
final S3Resource s3resource = (S3Resource) resource;
if (transferEvent.getRequestType() == TransferEvent.REQUEST_PUT) {
log.info("Uploaded: " + s3resource.getUrl());
} else {
log.info("Downloaded: " + s3resource.getUrl());
}
}
// log(tt.toString());
}

Expand Down Expand Up @@ -74,7 +83,7 @@ public void transferStarted(final TransferEvent transferEvent) {
}
// System.out.print("[INFO] ");
}

protected String getURI(final TransferEvent event) {
return getNormalizedURI(event.getWagon().getRepository().getUrl() + "/" + event.getResource().getName());
}
Expand Down
38 changes: 38 additions & 0 deletions src/main/java/org/kuali/maven/wagon/S3Resource.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
/**
* Copyright 2014 Adobe Systems Incorporated
*
* Licensed under the Educational Community 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.opensource.org/licenses/ecl2.php
*
* 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.kuali.maven.wagon;

import org.apache.maven.wagon.resource.Resource;

/**
* @author <a href="mailto:[email protected]>Markus A. Kuppe</a>
*/
public class S3Resource extends Resource {

private String url;

public S3Resource(String resourceName) {
super(resourceName);
}

public String getUrl() {
return url;
}

public void setURL(String anUrl) {
this.url = anUrl;
}
}
20 changes: 15 additions & 5 deletions src/main/java/org/kuali/maven/wagon/S3Wagon.java
Original file line number Diff line number Diff line change
Expand Up @@ -28,10 +28,12 @@
import org.apache.commons.lang.StringUtils;
import org.apache.maven.wagon.ResourceDoesNotExistException;
import org.apache.maven.wagon.TransferFailedException;
import org.apache.maven.wagon.Wagon;
import org.apache.maven.wagon.authentication.AuthenticationInfo;
import org.apache.maven.wagon.proxy.ProxyInfo;
import org.apache.maven.wagon.repository.Repository;
import org.apache.maven.wagon.repository.RepositoryPermissions;
import org.codehaus.plexus.component.annotations.Component;
import org.kuali.common.aws.s3.S3Utils;
import org.kuali.common.aws.s3.SimpleFormatter;
import org.kuali.common.threads.ExecutionStatistics;
Expand Down Expand Up @@ -78,11 +80,10 @@
* This implementation uses the <code>username</code> and <code>password</code> portions of the server authentication metadata for credentials.
* </p>
*
* @plexus.component role="org.apache.maven.wagon.Wagon" role-hint="http" instantiation-strategy="per-lookup"
*
* @author Ben Hale
* @author Jeff Caddel
*/
@Component( role = Wagon.class, hint = "s3", instantiationStrategy= "per-lookup")
public class S3Wagon extends AbstractWagon implements RequestFactory {

/**
Expand Down Expand Up @@ -230,6 +231,7 @@ protected void getResource(final String resourceName, final File destination, fi
try {
String key = basedir + resourceName;
object = client.getObject(bucketName, key);
progress.getResource().setURL(client.getResourceUrl(bucketName, key));
} catch (Exception e) {
throw new ResourceDoesNotExistException("Resource " + resourceName + " does not exist in the repository", e);
}
Expand Down Expand Up @@ -379,12 +381,17 @@ protected InputStream getInputStream(File source, TransferProgress progress) thr
}
}

protected PutObjectRequest getPutObjectRequest(File source,
String destination, TransferProgress progress) {
return getPutObjectRequest(source, destination,
getCanonicalKey(destination), progress);
}

/**
* Create a PutObjectRequest based on the source file and destination passed in
*/
protected PutObjectRequest getPutObjectRequest(File source, String destination, TransferProgress progress) {
private PutObjectRequest getPutObjectRequest(File source, String destination, String key, TransferProgress progress) {
try {
String key = getCanonicalKey(destination);
InputStream input = getInputStream(source, progress);
ObjectMetadata metadata = getObjectMetadata(source, destination);
PutObjectRequest request = new PutObjectRequest(bucketName, key, input, metadata);
Expand Down Expand Up @@ -474,10 +481,13 @@ protected long sum(List<PutFileContext> contexts) {
protected void putResource(final File source, final String destination, final TransferProgress progress) throws IOException {

// Create a new PutObjectRequest
PutObjectRequest request = getPutObjectRequest(source, destination, progress);
String key = getCanonicalKey(destination);
PutObjectRequest request = getPutObjectRequest(source, destination, key, progress);

// Upload the file to S3, using multi-part upload for large files
S3Utils.getInstance().upload(source, request, client, transferManager);

progress.getResource().setURL(client.getResourceUrl(bucketName, key));
}

protected String getDestinationPath(final String destination) {
Expand Down
8 changes: 5 additions & 3 deletions src/main/java/org/kuali/maven/wagon/TransferProgress.java
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@
*/
package org.kuali.maven.wagon;

import org.apache.maven.wagon.resource.Resource;

/**
* A class that encapsulates the notification of the transfer listeners for
Expand All @@ -26,13 +25,13 @@
*/
class TransferProgress {

private Resource resource;
private S3Resource resource;

private int requestType;

private TransferListenerSupport transferListeners;

public TransferProgress(Resource resource, int requestType, TransferListenerSupport listeners) {
public TransferProgress(S3Resource resource, int requestType, TransferListenerSupport listeners) {
this.resource = resource;
this.requestType = requestType;
this.transferListeners = listeners;
Expand All @@ -42,4 +41,7 @@ protected void notify(byte[] buffer, int length) {
transferListeners.fireTransferProgress(resource, requestType, buffer, length);
}

public S3Resource getResource() {
return resource;
}
}
27 changes: 0 additions & 27 deletions src/main/resources/META-INF/plexus/components.xml

This file was deleted.