diff --git a/.build-jdk11 b/.build-jdk11
deleted file mode 100644
index e69de29..0000000
diff --git a/pom.xml b/pom.xml
index 6607784..4e9d853 100644
--- a/pom.xml
+++ b/pom.xml
@@ -5,7 +5,7 @@
com.hubspot
basepom
- 25.3
+ 59.3
com.hubspot.slimfast
@@ -13,99 +13,81 @@
0.23-SNAPSHOT
pom
-
- 3
-
-
slimfast-plugin
slimfast-hadoop
- 1.11.461
- 4.5.5
- 4.4.9
+ 3.6.3
+
+ com.amazonaws
+ aws-java-sdk-s3
+ ${aws.sdk.version}
+
+
+ com.googlecode.json-simple
+ json-simple
+ 1.1.1
+
+
+ com.hubspot
+ failsafe-s3-decorator
+ 0.7
+
+
+ org.apache.hadoop
+ hadoop-common
+ 2.7.2
+
+
+ commons-collections
+ commons-collections
+
+
+
org.apache.maven
maven-archiver
- 3.0.0
+ 3.5.0
org.apache.maven
maven-artifact
- 3.3.3
+ ${dep.maven.version}
org.apache.maven
maven-core
- 3.3.3
+ ${dep.maven.version}
org.apache.maven
maven-model
- 3.3.3
+ ${dep.maven.version}
org.apache.maven
maven-plugin-api
- 3.3.3
+ ${dep.maven.version}
org.apache.maven.plugin-tools
maven-plugin-annotations
- 3.4
+ 3.11.0
org.codehaus.plexus
plexus-interpolation
- 1.22
-
-
- com.amazonaws
- aws-java-sdk-s3
- ${aws.sdk.version}
-
-
- com.hubspot
- failsafe-s3-decorator
- 0.7
-
-
- com.googlecode.json-simple
- json-simple
- 1.1.1
-
-
- org.apache.hadoop
- hadoop-common
- 2.7.2
-
-
- commons-collections
- commons-collections
-
-
+ 1.25
-
-
-
-
- org.apache.maven.plugins
- maven-plugin-plugin
- 3.4
-
-
-
-
-
Jonathan Haber
diff --git a/slimfast-hadoop/src/main/java/com/hubspot/slimfast/hadoop/HadoopHelper.java b/slimfast-hadoop/src/main/java/com/hubspot/slimfast/hadoop/HadoopHelper.java
index f27043e..4097b77 100644
--- a/slimfast-hadoop/src/main/java/com/hubspot/slimfast/hadoop/HadoopHelper.java
+++ b/slimfast-hadoop/src/main/java/com/hubspot/slimfast/hadoop/HadoopHelper.java
@@ -1,12 +1,5 @@
package com.hubspot.slimfast.hadoop;
-import org.apache.hadoop.conf.Configuration;
-import org.apache.hadoop.fs.FileStatus;
-import org.apache.hadoop.fs.FileSystem;
-import org.apache.hadoop.fs.Path;
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
-
import java.io.FileNotFoundException;
import java.io.IOException;
import java.io.InputStream;
@@ -15,20 +8,33 @@
import java.util.LinkedHashSet;
import java.util.Set;
import java.util.jar.Manifest;
+import org.apache.hadoop.conf.Configuration;
+import org.apache.hadoop.fs.FileStatus;
+import org.apache.hadoop.fs.FileSystem;
+import org.apache.hadoop.fs.Path;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
public class HadoopHelper {
+
private static final Logger LOG = LoggerFactory.getLogger(HadoopHelper.class);
- public static void writeJarsToHdfsAndAddToClasspath(SlimfastHadoopConfiguration slimfastConfiguration) {
+ public static void writeJarsToHdfsAndAddToClasspath(
+ SlimfastHadoopConfiguration slimfastConfiguration
+ ) {
try {
FileSystem hdfs = FileSystem.get(slimfastConfiguration.getConfiguration());
for (String jar : findClasspathJars(slimfastConfiguration.getJarDirectory())) {
- Path destination = new Path(slimfastConfiguration.getHdfsArtifactRoot().resolve(jar).toString());
+ Path destination = new Path(
+ slimfastConfiguration.getHdfsArtifactRoot().resolve(jar).toString()
+ );
if (exists(hdfs, destination)) {
LOG.info("Path already exists {}", destination);
} else {
- Path source = new Path(slimfastConfiguration.getJarDirectory().resolve(jar).toString());
+ Path source = new Path(
+ slimfastConfiguration.getJarDirectory().resolve(jar).toString()
+ );
hdfs.copyFromLocalFile(source, destination);
LOG.info("Successfully uploaded path {}", destination);
}
@@ -40,15 +46,20 @@ public static void writeJarsToHdfsAndAddToClasspath(SlimfastHadoopConfiguration
}
}
- private static void addJarToJobConfiguration(Path jarPath, Configuration configuration) throws IOException {
+ private static void addJarToJobConfiguration(Path jarPath, Configuration configuration)
+ throws IOException {
String jar = jarPath.toString();
String existingClasspath = configuration.get("mapreduce.job.classpath.files");
- String updatedClasspath = existingClasspath == null ? jar : existingClasspath + "," + jar;
+ String updatedClasspath = existingClasspath == null
+ ? jar
+ : existingClasspath + "," + jar;
configuration.set("mapreduce.job.classpath.files", updatedClasspath);
jar = FileSystem.get(configuration).makeQualified(jarPath).toUri().toString();
String existingCacheFiles = configuration.get("mapreduce.job.cache.files");
- String updatedCacheFiles = existingCacheFiles == null ? jar : existingCacheFiles + "," + jar;
+ String updatedCacheFiles = existingCacheFiles == null
+ ? jar
+ : existingCacheFiles + "," + jar;
configuration.set("mapreduce.job.cache.files", updatedCacheFiles);
}
@@ -61,9 +72,12 @@ private static boolean exists(FileSystem fileSystem, Path path) throws IOExcepti
}
}
- private static Set findClasspathJars(java.nio.file.Path jarDirectory) throws IOException {
+ private static Set findClasspathJars(java.nio.file.Path jarDirectory)
+ throws IOException {
Set classpathJars = new LinkedHashSet<>();
- for (URL url : Collections.list(getClassLoader().getResources("META-INF/MANIFEST.MF"))) {
+ for (URL url : Collections.list(
+ getClassLoader().getResources("META-INF/MANIFEST.MF")
+ )) {
try (InputStream manifestStream = url.openStream()) {
Manifest manifest = new Manifest(manifestStream);
String classPath = manifest.getMainAttributes().getValue("Class-Path");
@@ -82,6 +96,8 @@ private static Set findClasspathJars(java.nio.file.Path jarDirectory) th
private static ClassLoader getClassLoader() {
ClassLoader contextClassLoader = Thread.currentThread().getContextClassLoader();
- return contextClassLoader == null ? HadoopHelper.class.getClassLoader() : contextClassLoader;
+ return contextClassLoader == null
+ ? HadoopHelper.class.getClassLoader()
+ : contextClassLoader;
}
}
diff --git a/slimfast-hadoop/src/main/java/com/hubspot/slimfast/hadoop/SlimfastHadoopConfiguration.java b/slimfast-hadoop/src/main/java/com/hubspot/slimfast/hadoop/SlimfastHadoopConfiguration.java
index eadaaff..93e2884 100644
--- a/slimfast-hadoop/src/main/java/com/hubspot/slimfast/hadoop/SlimfastHadoopConfiguration.java
+++ b/slimfast-hadoop/src/main/java/com/hubspot/slimfast/hadoop/SlimfastHadoopConfiguration.java
@@ -3,15 +3,19 @@
import java.net.URL;
import java.nio.file.Path;
import java.nio.file.Paths;
-
import org.apache.hadoop.conf.Configuration;
public class SlimfastHadoopConfiguration {
+
private final Path jarDirectory;
private final Path hdfsArtifactRoot;
private final Configuration configuration;
- private SlimfastHadoopConfiguration(Path jarDirectory, Path hdfsArtifactRoot, Configuration configuration) {
+ private SlimfastHadoopConfiguration(
+ Path jarDirectory,
+ Path hdfsArtifactRoot,
+ Configuration configuration
+ ) {
this.jarDirectory = jarDirectory;
this.hdfsArtifactRoot = hdfsArtifactRoot;
this.configuration = configuration;
@@ -34,22 +38,30 @@ public Configuration getConfiguration() {
}
public static class Builder {
+
private Path jarDirectory;
private Path hdfsArtifactRoot = Paths.get("jars");
private Configuration configuration;
public Builder setJarByClass(Class> jarClass) {
- URL url = jarClass.getResource("/" + jarClass.getName().replace('.', '/') + ".class");
+ URL url = jarClass.getResource(
+ "/" + jarClass.getName().replace('.', '/') + ".class"
+ );
if (url == null) {
throw new IllegalStateException("Could not find resource " + jarClass);
}
String qualifiedPath = url.toString();
if (!qualifiedPath.startsWith("jar:file:")) {
- throw new IllegalStateException("Class doesn't appear to be in a JAR, are you running from a JAR?");
+ throw new IllegalStateException(
+ "Class doesn't appear to be in a JAR, are you running from a JAR?"
+ );
}
- String jarPath = qualifiedPath.substring("jar:file:".length(), qualifiedPath.indexOf('!'));
+ String jarPath = qualifiedPath.substring(
+ "jar:file:".length(),
+ qualifiedPath.indexOf('!')
+ );
return setJarDirectory(Paths.get(jarPath).getParent());
}
@@ -77,7 +89,11 @@ public SlimfastHadoopConfiguration build() {
throw new IllegalStateException("configuration must be set");
}
- return new SlimfastHadoopConfiguration(jarDirectory, hdfsArtifactRoot, configuration);
+ return new SlimfastHadoopConfiguration(
+ jarDirectory,
+ hdfsArtifactRoot,
+ configuration
+ );
}
}
}
diff --git a/slimfast-plugin/pom.xml b/slimfast-plugin/pom.xml
index c19a6c1..67784a4 100644
--- a/slimfast-plugin/pom.xml
+++ b/slimfast-plugin/pom.xml
@@ -14,55 +14,67 @@
- org.apache.maven
- maven-archiver
+ com.amazonaws
+ aws-java-sdk-core
- org.apache.maven
- maven-artifact
+ com.amazonaws
+ aws-java-sdk-s3
- org.apache.maven
- maven-core
+ com.google.code.findbugs
+ annotations
- org.apache.maven
- maven-plugin-api
+ com.google.guava
+ guava
- org.apache.maven.plugin-tools
- maven-plugin-annotations
- provided
+ com.googlecode.json-simple
+ json-simple
+
+
+ org.apache.maven
+ maven-archiver
org.codehaus.plexus
plexus-interpolation
- com.google.guava
- guava
+ org.apache.maven
+ maven-artifact
+ provided
- com.amazonaws
- aws-java-sdk-core
+ org.apache.maven
+ maven-core
+ provided
- com.amazonaws
- aws-java-sdk-s3
+ org.apache.maven
+ maven-model
+ provided
- com.googlecode.json-simple
- json-simple
+ org.apache.maven
+ maven-plugin-api
+ provided
- org.slf4j
- jcl-over-slf4j
- runtime
+ org.apache.maven.plugin-tools
+ maven-plugin-annotations
+ provided
joda-time
joda-time
runtime
+
+ org.slf4j
+ jcl-over-slf4j
+ runtime
+
diff --git a/slimfast-plugin/src/main/java/com/hubspot/maven/plugins/slimfast/ArtifactHelper.java b/slimfast-plugin/src/main/java/com/hubspot/maven/plugins/slimfast/ArtifactHelper.java
index 655ab9c..be22245 100644
--- a/slimfast-plugin/src/main/java/com/hubspot/maven/plugins/slimfast/ArtifactHelper.java
+++ b/slimfast-plugin/src/main/java/com/hubspot/maven/plugins/slimfast/ArtifactHelper.java
@@ -14,7 +14,6 @@
import java.util.List;
import java.util.Properties;
import java.util.Set;
-
import org.apache.maven.archiver.ManifestConfiguration;
import org.apache.maven.archiver.MavenArchiveConfiguration;
import org.apache.maven.artifact.Artifact;
@@ -35,14 +34,23 @@
import org.codehaus.plexus.interpolation.ValueSource;
public class ArtifactHelper {
- private static final List ARTIFACT_EXPRESSION_PREFIXES = Collections.singletonList("artifact.");
- public static LocalArtifactWrapper getArtifactPaths(BeanConfigurator beanConfigurator,
- MavenProject project) throws MojoExecutionException {
- ManifestConfiguration manifestConfiguration = parseManifestConfiguration(beanConfigurator, project);
+ private static final List ARTIFACT_EXPRESSION_PREFIXES =
+ Collections.singletonList("artifact.");
+
+ public static LocalArtifactWrapper getArtifactPaths(
+ BeanConfigurator beanConfigurator,
+ MavenProject project
+ ) throws MojoExecutionException {
+ ManifestConfiguration manifestConfiguration = parseManifestConfiguration(
+ beanConfigurator,
+ project
+ );
if (!manifestConfiguration.isAddClasspath()) {
- throw new MojoExecutionException("maven-jar-plugin is not configured to add classpath");
+ throw new MojoExecutionException(
+ "maven-jar-plugin is not configured to add classpath"
+ );
}
Set artifacts = new HashSet<>();
@@ -67,13 +75,20 @@ public static LocalArtifactWrapper getArtifactPaths(BeanConfigurator beanConfigu
return new LocalArtifactWrapper(prefix, artifacts);
}
- private static ManifestConfiguration parseManifestConfiguration(BeanConfigurator beanConfigurator,
- MavenProject project) throws MojoExecutionException {
+ private static ManifestConfiguration parseManifestConfiguration(
+ BeanConfigurator beanConfigurator,
+ MavenProject project
+ ) throws MojoExecutionException {
MavenArchiveConfiguration archiveConfiguration = new MavenArchiveConfiguration();
BeanConfigurationRequest beanConfiguration = new DefaultBeanConfigurationRequest()
- .setBean(archiveConfiguration)
- .setConfiguration(project.getModel(), "org.apache.maven.plugins", "maven-jar-plugin", "default-jar");
+ .setBean(archiveConfiguration)
+ .setConfiguration(
+ project.getModel(),
+ "org.apache.maven.plugins",
+ "maven-jar-plugin",
+ "default-jar"
+ );
beanConfiguration.setConfiguration(beanConfiguration.getConfiguration(), "archive");
@@ -86,7 +101,8 @@ private static ManifestConfiguration parseManifestConfiguration(BeanConfigurator
return archiveConfiguration.getManifest();
}
- private static List classpathElements(MavenProject project) throws MojoExecutionException {
+ private static List classpathElements(MavenProject project)
+ throws MojoExecutionException {
try {
return project.getRuntimeClasspathElements();
} catch (DependencyResolutionRequiredException e) {
@@ -94,7 +110,8 @@ private static List classpathElements(MavenProject project) throws MojoE
}
}
- private static Path computePath(Artifact artifact, ManifestConfiguration config) throws MojoExecutionException {
+ private static Path computePath(Artifact artifact, ManifestConfiguration config)
+ throws MojoExecutionException {
String layoutType = config.getClasspathLayoutType();
String layout = config.getCustomClasspathLayout();
@@ -102,8 +119,16 @@ private static Path computePath(Artifact artifact, ManifestConfiguration config)
List valueSources = new ArrayList<>();
- valueSources.add(new PrefixedObjectValueSource(ARTIFACT_EXPRESSION_PREFIXES, artifact, true));
- valueSources.add(new PrefixedObjectValueSource(ARTIFACT_EXPRESSION_PREFIXES, artifact.getArtifactHandler(), true));
+ valueSources.add(
+ new PrefixedObjectValueSource(ARTIFACT_EXPRESSION_PREFIXES, artifact, true)
+ );
+ valueSources.add(
+ new PrefixedObjectValueSource(
+ ARTIFACT_EXPRESSION_PREFIXES,
+ artifact.getArtifactHandler(),
+ true
+ )
+ );
Properties extraExpressions = new Properties();
if (!artifact.isSnapshot()) {
@@ -118,13 +143,21 @@ private static Path computePath(Artifact artifact, ManifestConfiguration config)
extraExpressions.setProperty("dashClassifier", "");
extraExpressions.setProperty("dashClassifier?", "");
}
- valueSources.add(new PrefixedPropertiesValueSource(ARTIFACT_EXPRESSION_PREFIXES, extraExpressions, true));
+ valueSources.add(
+ new PrefixedPropertiesValueSource(
+ ARTIFACT_EXPRESSION_PREFIXES,
+ extraExpressions,
+ true
+ )
+ );
for (ValueSource vs : valueSources) {
interpolator.addValueSource(vs);
}
- RecursionInterceptor recursionInterceptor = new PrefixAwareRecursionInterceptor(ARTIFACT_EXPRESSION_PREFIXES);
+ RecursionInterceptor recursionInterceptor = new PrefixAwareRecursionInterceptor(
+ ARTIFACT_EXPRESSION_PREFIXES
+ );
try {
boolean useUniqueVersionsLayout = config.isUseUniqueVersions();
@@ -132,16 +165,20 @@ private static Path computePath(Artifact artifact, ManifestConfiguration config)
final String resolvedLayout;
switch (layoutType) {
case ManifestConfiguration.CLASSPATH_LAYOUT_TYPE_SIMPLE:
- resolvedLayout = useUniqueVersionsLayout ? SIMPLE_LAYOUT : SIMPLE_LAYOUT_NONUNIQUE;
+ resolvedLayout =
+ useUniqueVersionsLayout ? SIMPLE_LAYOUT : SIMPLE_LAYOUT_NONUNIQUE;
break;
case ManifestConfiguration.CLASSPATH_LAYOUT_TYPE_REPOSITORY:
- resolvedLayout = useUniqueVersionsLayout ? REPOSITORY_LAYOUT : REPOSITORY_LAYOUT_NONUNIQUE;
+ resolvedLayout =
+ useUniqueVersionsLayout ? REPOSITORY_LAYOUT : REPOSITORY_LAYOUT_NONUNIQUE;
break;
case ManifestConfiguration.CLASSPATH_LAYOUT_TYPE_CUSTOM:
resolvedLayout = layout;
break;
default:
- throw new MojoExecutionException("Unknown classpath layout type: " + layoutType);
+ throw new MojoExecutionException(
+ "Unknown classpath layout type: " + layoutType
+ );
}
return Paths.get(interpolator.interpolate(resolvedLayout, recursionInterceptor));
diff --git a/slimfast-plugin/src/main/java/com/hubspot/maven/plugins/slimfast/BaseFileUploader.java b/slimfast-plugin/src/main/java/com/hubspot/maven/plugins/slimfast/BaseFileUploader.java
index 4a334a8..5867da4 100644
--- a/slimfast-plugin/src/main/java/com/hubspot/maven/plugins/slimfast/BaseFileUploader.java
+++ b/slimfast-plugin/src/main/java/com/hubspot/maven/plugins/slimfast/BaseFileUploader.java
@@ -6,12 +6,12 @@
import java.util.Collections;
import java.util.LinkedHashSet;
import java.util.Set;
-
import org.apache.maven.plugin.MojoExecutionException;
import org.apache.maven.plugin.MojoFailureException;
import org.apache.maven.plugin.logging.Log;
public abstract class BaseFileUploader implements FileUploader, FromManifestUploader {
+
private Set s3Artifacts;
private Path prefix;
private Path outputFile;
@@ -24,7 +24,8 @@ public final void init(UploadConfiguration config, Log log) {
doInit(config, log);
}
- protected abstract void doUpload(String bucket, String key, Path path) throws MojoFailureException, MojoExecutionException;
+ protected abstract void doUpload(String bucket, String key, Path path)
+ throws MojoFailureException, MojoExecutionException;
protected void doInit(UploadConfiguration config, Log log) {
// empty by default
@@ -35,19 +36,22 @@ protected void doDestroy() throws MojoFailureException {
}
@Override
- public void upload(UploadConfiguration config, LocalArtifact artifact) throws MojoExecutionException, MojoFailureException {
+ public void upload(UploadConfiguration config, LocalArtifact artifact)
+ throws MojoExecutionException, MojoFailureException {
upload(config, artifact.getTargetPath(), artifact.getLocalPath());
}
@Override
- public void uploadFromManifest(UploadConfiguration config, PreparedArtifact artifact) throws MojoExecutionException, MojoFailureException {
+ public void uploadFromManifest(UploadConfiguration config, PreparedArtifact artifact)
+ throws MojoExecutionException, MojoFailureException {
Path targetPath = Paths.get(artifact.getTargetPath());
Path localPath = Paths.get(artifact.getLocalPath());
upload(config, targetPath, localPath);
}
- private void upload(UploadConfiguration config, Path targetPath, Path localPath) throws MojoExecutionException, MojoFailureException {
+ private void upload(UploadConfiguration config, Path targetPath, Path localPath)
+ throws MojoExecutionException, MojoFailureException {
String file = targetPath.toString();
boolean isUnresolvedSnapshot = file.toUpperCase().endsWith("-SNAPSHOT.JAR");
@@ -57,7 +61,11 @@ private void upload(UploadConfiguration config, Path targetPath, Path localPath)
String start = file.substring(0, file.length() - ".JAR".length());
String end = file.substring(file.length() - ".JAR".length());
String md5 = FileHelper.md5(localPath);
- s3Key = Paths.get(config.getS3ArtifactRoot()).resolve(start + "-" + md5 + end).toString();
+ s3Key =
+ Paths
+ .get(config.getS3ArtifactRoot())
+ .resolve(start + "-" + md5 + end)
+ .toString();
} else {
throw new MojoExecutionException("Encountered unresolved snapshot: " + file);
}
@@ -68,13 +76,24 @@ private void upload(UploadConfiguration config, Path targetPath, Path localPath)
doUpload(config.getS3Bucket(), s3Key, localPath);
String targetPathAsString = prefix.resolve(targetPath).toString();
- s3Artifacts.add(new S3Artifact(config.getS3Bucket(), s3Key, targetPathAsString, FileHelper.md5(localPath), FileHelper.size(localPath)));
+ s3Artifacts.add(
+ new S3Artifact(
+ config.getS3Bucket(),
+ s3Key,
+ targetPathAsString,
+ FileHelper.md5(localPath),
+ FileHelper.size(localPath)
+ )
+ );
}
@Override
public final void destroy() throws MojoFailureException {
try {
- JsonHelper.writeArtifactsToJson(outputFile.toFile(), new S3ArtifactWrapper(prefix.toString(), s3Artifacts));
+ JsonHelper.writeArtifactsToJson(
+ outputFile.toFile(),
+ new S3ArtifactWrapper(prefix.toString(), s3Artifacts)
+ );
} catch (IOException e) {
throw new MojoFailureException("Error writing dependencies json to file", e);
}
diff --git a/slimfast-plugin/src/main/java/com/hubspot/maven/plugins/slimfast/ClasspathConfiguration.java b/slimfast-plugin/src/main/java/com/hubspot/maven/plugins/slimfast/ClasspathConfiguration.java
index a43df09..5a72657 100644
--- a/slimfast-plugin/src/main/java/com/hubspot/maven/plugins/slimfast/ClasspathConfiguration.java
+++ b/slimfast-plugin/src/main/java/com/hubspot/maven/plugins/slimfast/ClasspathConfiguration.java
@@ -4,6 +4,7 @@
import java.util.Set;
public class ClasspathConfiguration {
+
private final Path prefix;
private final Set entries;
diff --git a/slimfast-plugin/src/main/java/com/hubspot/maven/plugins/slimfast/CopyJarsMojo.java b/slimfast-plugin/src/main/java/com/hubspot/maven/plugins/slimfast/CopyJarsMojo.java
index 54ef513..ec22ce3 100644
--- a/slimfast-plugin/src/main/java/com/hubspot/maven/plugins/slimfast/CopyJarsMojo.java
+++ b/slimfast-plugin/src/main/java/com/hubspot/maven/plugins/slimfast/CopyJarsMojo.java
@@ -5,7 +5,6 @@
import java.nio.file.Path;
import java.nio.file.Paths;
import java.nio.file.StandardCopyOption;
-
import org.apache.maven.configuration.BeanConfigurator;
import org.apache.maven.plugin.AbstractMojo;
import org.apache.maven.plugin.MojoExecutionException;
@@ -17,7 +16,12 @@
import org.apache.maven.plugins.annotations.ResolutionScope;
import org.apache.maven.project.MavenProject;
-@Mojo(name = "copy", defaultPhase = LifecyclePhase.PACKAGE, threadSafe = true, requiresDependencyResolution = ResolutionScope.RUNTIME)
+@Mojo(
+ name = "copy",
+ defaultPhase = LifecyclePhase.PACKAGE,
+ threadSafe = true,
+ requiresDependencyResolution = ResolutionScope.RUNTIME
+)
public class CopyJarsMojo extends AbstractMojo {
@Component
@@ -39,18 +43,27 @@ public void execute() throws MojoExecutionException, MojoFailureException {
return;
}
- LocalArtifactWrapper artifactWrapper = ArtifactHelper.getArtifactPaths(beanConfigurator, project);
+ LocalArtifactWrapper artifactWrapper = ArtifactHelper.getArtifactPaths(
+ beanConfigurator,
+ project
+ );
Path prefix = artifactWrapper.getPrefix();
for (LocalArtifact artifact : artifactWrapper.getArtifacts()) {
Path localPath = artifact.getLocalPath();
- Path targetPath = Paths.get(outputDirectory).resolve(prefix).resolve(artifact.getTargetPath());
+ Path targetPath = Paths
+ .get(outputDirectory)
+ .resolve(prefix)
+ .resolve(artifact.getTargetPath());
FileHelper.ensureDirectoryExists(targetPath.getParent());
try {
Files.copy(localPath, targetPath, StandardCopyOption.REPLACE_EXISTING);
} catch (IOException e) {
- throw new MojoFailureException(String.format("Error moving file from %s to %s", localPath, targetPath), e);
+ throw new MojoFailureException(
+ String.format("Error moving file from %s to %s", localPath, targetPath),
+ e
+ );
}
}
}
diff --git a/slimfast-plugin/src/main/java/com/hubspot/maven/plugins/slimfast/DefaultFileDownloader.java b/slimfast-plugin/src/main/java/com/hubspot/maven/plugins/slimfast/DefaultFileDownloader.java
index b989257..ebea796 100644
--- a/slimfast-plugin/src/main/java/com/hubspot/maven/plugins/slimfast/DefaultFileDownloader.java
+++ b/slimfast-plugin/src/main/java/com/hubspot/maven/plugins/slimfast/DefaultFileDownloader.java
@@ -1,21 +1,20 @@
package com.hubspot.maven.plugins.slimfast;
+import com.amazonaws.SdkBaseException;
+import com.amazonaws.services.s3.AmazonS3;
+import com.amazonaws.services.s3.model.S3Object;
import java.io.IOException;
import java.io.InputStream;
import java.nio.file.Files;
import java.nio.file.Path;
import java.nio.file.Paths;
import java.nio.file.StandardCopyOption;
-
import org.apache.maven.plugin.MojoExecutionException;
import org.apache.maven.plugin.MojoFailureException;
import org.apache.maven.plugin.logging.Log;
-import com.amazonaws.SdkBaseException;
-import com.amazonaws.services.s3.AmazonS3;
-import com.amazonaws.services.s3.model.S3Object;
-
public class DefaultFileDownloader implements FileDownloader {
+
private AmazonS3 s3Service;
private Path cacheDirectory;
private Log log;
@@ -28,14 +27,17 @@ public void init(DownloadConfiguration config, Log log) {
}
@Override
- public void download(DownloadConfiguration config, S3Artifact artifact) throws MojoExecutionException, MojoFailureException {
+ public void download(DownloadConfiguration config, S3Artifact artifact)
+ throws MojoExecutionException, MojoFailureException {
Path targetFile = config.getOutputDirectory().resolve(artifact.getTargetPath());
if (artifactIsCached(targetFile, artifact)) {
log.info("Target file exists " + targetFile);
return;
}
- Path cacheFile = cacheDirectory.resolve(config.getPrefix().relativize(Paths.get(artifact.getTargetPath())));
+ Path cacheFile = cacheDirectory.resolve(
+ config.getPrefix().relativize(Paths.get(artifact.getTargetPath()))
+ );
if (artifactIsCached(cacheFile, artifact)) {
log.info("Target file is cached " + cacheFile);
} else {
@@ -48,7 +50,10 @@ public void download(DownloadConfiguration config, S3Artifact artifact) throws M
try {
Files.copy(cacheFile, targetFile);
} catch (IOException e) {
- throw new MojoFailureException(String.format("Error copying file from %s to %s", cacheFile, targetFile), e);
+ throw new MojoFailureException(
+ String.format("Error copying file from %s to %s", cacheFile, targetFile),
+ e
+ );
}
verifyChecksums(targetFile, artifact);
@@ -57,11 +62,13 @@ public void download(DownloadConfiguration config, S3Artifact artifact) throws M
@Override
public void destroy() throws MojoExecutionException, MojoFailureException {}
- private boolean artifactIsCached(Path path, S3Artifact artifact) throws MojoExecutionException {
+ private boolean artifactIsCached(Path path, S3Artifact artifact)
+ throws MojoExecutionException {
return Files.exists(path) && checksumsMatch(path, artifact);
}
- private void doDownload(String bucket, String key, Path path) throws MojoFailureException, MojoExecutionException {
+ private void doDownload(String bucket, String key, Path path)
+ throws MojoFailureException, MojoExecutionException {
Path tempPath = createTempFile(path);
try {
@@ -79,33 +86,59 @@ private void doDownload(String bucket, String key, Path path) throws MojoFailure
FileHelper.ensureDirectoryExists(path.getParent());
Files.move(tempPath, path, StandardCopyOption.ATOMIC_MOVE);
} catch (IOException e) {
- throw new MojoFailureException(String.format("Error moving file from %s to %s", tempPath, path), e);
+ throw new MojoFailureException(
+ String.format("Error moving file from %s to %s", tempPath, path),
+ e
+ );
}
}
private Path createTempFile(Path path) throws MojoFailureException {
try {
- return Files.createTempFile(cacheDirectory, String.valueOf(path.getFileName()), null);
+ return Files.createTempFile(
+ cacheDirectory,
+ String.valueOf(path.getFileName()),
+ null
+ );
} catch (IOException e) {
throw new MojoFailureException("Error creating temp file in " + cacheDirectory, e);
}
}
- private static void verifyChecksums(Path path, S3Artifact artifact) throws MojoExecutionException {
+ private static void verifyChecksums(Path path, S3Artifact artifact)
+ throws MojoExecutionException {
long actualSize = FileHelper.size(path);
long expectedSize = artifact.getSize();
if (actualSize != expectedSize) {
- throw new MojoExecutionException(String.format("File %s has unexpected size, expected=%s, actual=%s", path, expectedSize, actualSize));
+ throw new MojoExecutionException(
+ String.format(
+ "File %s has unexpected size, expected=%s, actual=%s",
+ path,
+ expectedSize,
+ actualSize
+ )
+ );
}
String actualMd5 = FileHelper.md5(path);
String expectedMd5 = artifact.getMd5();
if (!actualMd5.equals(expectedMd5)) {
- throw new MojoExecutionException(String.format("File %s has unexpected checksum, expected=%s, actual=%s", path, expectedMd5, actualMd5));
+ throw new MojoExecutionException(
+ String.format(
+ "File %s has unexpected checksum, expected=%s, actual=%s",
+ path,
+ expectedMd5,
+ actualMd5
+ )
+ );
}
}
- private static boolean checksumsMatch(Path path, S3Artifact artifact) throws MojoExecutionException {
- return FileHelper.size(path) == artifact.getSize() && FileHelper.md5(path).equals(artifact.getMd5());
+ private static boolean checksumsMatch(Path path, S3Artifact artifact)
+ throws MojoExecutionException {
+ return (
+ FileHelper.size(path) == artifact.getSize() &&
+ FileHelper.md5(path).equals(artifact.getMd5())
+ );
}
}
diff --git a/slimfast-plugin/src/main/java/com/hubspot/maven/plugins/slimfast/DefaultFileUploader.java b/slimfast-plugin/src/main/java/com/hubspot/maven/plugins/slimfast/DefaultFileUploader.java
index 3dedace..13050c6 100644
--- a/slimfast-plugin/src/main/java/com/hubspot/maven/plugins/slimfast/DefaultFileUploader.java
+++ b/slimfast-plugin/src/main/java/com/hubspot/maven/plugins/slimfast/DefaultFileUploader.java
@@ -1,17 +1,16 @@
package com.hubspot.maven.plugins.slimfast;
-import java.nio.file.Path;
-
-import org.apache.maven.plugin.MojoExecutionException;
-import org.apache.maven.plugin.MojoFailureException;
-import org.apache.maven.plugin.logging.Log;
-
import com.amazonaws.AmazonServiceException;
import com.amazonaws.SdkBaseException;
import com.amazonaws.SdkClientException;
import com.amazonaws.services.s3.AmazonS3;
+import java.nio.file.Path;
+import org.apache.maven.plugin.MojoExecutionException;
+import org.apache.maven.plugin.MojoFailureException;
+import org.apache.maven.plugin.logging.Log;
public class DefaultFileUploader extends BaseFileUploader {
+
private AmazonS3 s3Service;
private Log log;
@@ -22,7 +21,8 @@ protected void doInit(UploadConfiguration config, Log log) {
}
@Override
- protected void doUpload(String bucket, String key, Path path) throws MojoFailureException, MojoExecutionException {
+ protected void doUpload(String bucket, String key, Path path)
+ throws MojoFailureException, MojoExecutionException {
if (keyExists(bucket, key)) {
log.info("Key already exists " + key);
return;
@@ -44,7 +44,10 @@ private boolean keyExists(String bucket, String key) throws MojoFailureException
s3Service.getObjectMetadata(bucket, key);
return true;
} catch (SdkBaseException e) {
- if (e instanceof AmazonServiceException && ((AmazonServiceException) e).getStatusCode() == 404) {
+ if (
+ e instanceof AmazonServiceException &&
+ ((AmazonServiceException) e).getStatusCode() == 404
+ ) {
return false;
} else {
throw new MojoFailureException("Error getting object metadata for key " + key, e);
diff --git a/slimfast-plugin/src/main/java/com/hubspot/maven/plugins/slimfast/DownloadConfiguration.java b/slimfast-plugin/src/main/java/com/hubspot/maven/plugins/slimfast/DownloadConfiguration.java
index 559d9a4..38a8ee7 100644
--- a/slimfast-plugin/src/main/java/com/hubspot/maven/plugins/slimfast/DownloadConfiguration.java
+++ b/slimfast-plugin/src/main/java/com/hubspot/maven/plugins/slimfast/DownloadConfiguration.java
@@ -1,21 +1,23 @@
package com.hubspot.maven.plugins.slimfast;
-import java.nio.file.Path;
-
import com.amazonaws.services.s3.AmazonS3;
+import java.nio.file.Path;
public class DownloadConfiguration {
+
private final Path prefix;
private final Path cacheDirectory;
private final Path outputDirectory;
private final String s3AccessKey;
private final String s3SecretKey;
- public DownloadConfiguration(Path prefix,
- Path cacheDirectory,
- Path outputDirectory,
- String s3AccessKey,
- String s3SecretKey) {
+ public DownloadConfiguration(
+ Path prefix,
+ Path cacheDirectory,
+ Path outputDirectory,
+ String s3AccessKey,
+ String s3SecretKey
+ ) {
this.prefix = prefix;
this.cacheDirectory = cacheDirectory;
this.outputDirectory = outputDirectory;
diff --git a/slimfast-plugin/src/main/java/com/hubspot/maven/plugins/slimfast/DownloadJarsMojo.java b/slimfast-plugin/src/main/java/com/hubspot/maven/plugins/slimfast/DownloadJarsMojo.java
index fbffe45..3c3aa6e 100644
--- a/slimfast-plugin/src/main/java/com/hubspot/maven/plugins/slimfast/DownloadJarsMojo.java
+++ b/slimfast-plugin/src/main/java/com/hubspot/maven/plugins/slimfast/DownloadJarsMojo.java
@@ -1,5 +1,7 @@
package com.hubspot.maven.plugins.slimfast;
+import com.google.common.base.Throwables;
+import com.google.common.util.concurrent.ThreadFactoryBuilder;
import java.io.File;
import java.io.IOException;
import java.nio.file.Paths;
@@ -12,32 +14,43 @@
import java.util.concurrent.Future;
import java.util.concurrent.ThreadFactory;
import java.util.concurrent.TimeUnit;
-
import org.apache.maven.plugin.AbstractMojo;
import org.apache.maven.plugin.MojoExecutionException;
import org.apache.maven.plugin.MojoFailureException;
import org.apache.maven.plugins.annotations.Mojo;
import org.apache.maven.plugins.annotations.Parameter;
-import com.google.common.base.Throwables;
-import com.google.common.util.concurrent.ThreadFactoryBuilder;
-
@Mojo(name = "download", requiresProject = false, threadSafe = true)
public class DownloadJarsMojo extends AbstractMojo {
- @Parameter(property = "slimfast.fileDownloader", alias = "fileDownloader", defaultValue = "com.hubspot.maven.plugins.slimfast.DefaultFileDownloader")
+ @Parameter(
+ property = "slimfast.fileDownloader",
+ alias = "fileDownloader",
+ defaultValue = "com.hubspot.maven.plugins.slimfast.DefaultFileDownloader"
+ )
private String fileDownloaderType;
- @Parameter(property = "slimfast.s3.accessKey", defaultValue = "${s3.access.key}", required = true)
+ @Parameter(
+ property = "slimfast.s3.accessKey",
+ defaultValue = "${s3.access.key}",
+ required = true
+ )
private String s3AccessKey;
- @Parameter(property = "slimfast.s3.secretKey", defaultValue = "${s3.secret.key}", required = true)
+ @Parameter(
+ property = "slimfast.s3.secretKey",
+ defaultValue = "${s3.secret.key}",
+ required = true
+ )
private String s3SecretKey;
@Parameter(property = "slimfast.s3.downloadThreads", defaultValue = "10")
private int s3DownloadThreads;
- @Parameter(property = "slimfast.cacheDirectory", defaultValue = "${settings.localRepository}")
+ @Parameter(
+ property = "slimfast.cacheDirectory",
+ defaultValue = "${settings.localRepository}"
+ )
private String cacheDirectory;
@Parameter(property = "slimfast.outputDirectory", defaultValue = "${basedir}")
@@ -53,21 +66,30 @@ public void execute() throws MojoExecutionException, MojoFailureException {
final DownloadConfiguration configuration = buildConfiguration(wrapper.getPrefix());
FileHelper.ensureDirectoryExists(configuration.getCacheDirectory());
- ThreadFactory threadFactory = new ThreadFactoryBuilder().setNameFormat("slimfast-download").setDaemon(true).build();
- ExecutorService executor = Executors.newFixedThreadPool(s3DownloadThreads, threadFactory);
+ ThreadFactory threadFactory = new ThreadFactoryBuilder()
+ .setNameFormat("slimfast-download")
+ .setDaemon(true)
+ .build();
+ ExecutorService executor = Executors.newFixedThreadPool(
+ s3DownloadThreads,
+ threadFactory
+ );
final FileDownloader downloader = instantiateFileDownloader();
downloader.init(configuration, getLog());
List> futures = new ArrayList<>();
for (final S3Artifact artifact : wrapper.getArtifacts()) {
- futures.add(executor.submit(new Callable