From d92bf7bbca594528c22af129b66b7c675383db94 Mon Sep 17 00:00:00 2001 From: Andrew Glick Date: Wed, 24 Aug 2016 20:04:04 -0400 Subject: [PATCH 01/11] added the atlassian plugin's xml file to .gitignore --- .gitignore | 1 + 1 file changed, 1 insertion(+) diff --git a/.gitignore b/.gitignore index 118ca45..cd2856d 100644 --- a/.gitignore +++ b/.gitignore @@ -21,3 +21,4 @@ versioneye-maven-plugin.iws .classpath .project .settings +atlassian-ide-plugin.xml From d6bdeec54c179979315badfd63dab8d37e8591b3 Mon Sep 17 00:00:00 2001 From: Andrew Glick Date: Wed, 24 Aug 2016 20:24:10 -0400 Subject: [PATCH 02/11] assigned the maven-javadoc-plugin's version. retrograded testng version from 6.9.12 which I couldn't find to 6.9.10 which I could --- pom.xml | 41 ++++++++++++++++++++++++++--------------- 1 file changed, 26 insertions(+), 15 deletions(-) diff --git a/pom.xml b/pom.xml index 4c1a189..ad39f35 100644 --- a/pom.xml +++ b/pom.xml @@ -57,6 +57,29 @@ 4.5.2 + + + gpg + + + + org.apache.maven.plugins + maven-gpg-plugin + + + sign-artifacts + verify + + sign + + + + + + + + + org.apache.maven @@ -97,10 +120,10 @@ org.testng testng - 6.9.12 + 6.9.10 test - + @@ -152,19 +175,6 @@ - - org.apache.maven.plugins - maven-gpg-plugin - - - sign-artifacts - verify - - sign - - - - org.apache.maven.plugins @@ -207,6 +217,7 @@ org.apache.maven.plugins maven-javadoc-plugin + 2.10.4 attach-javadocs From e1565823ad2c9dbcc3f32b54baa9ef19dd3c5447 Mon Sep 17 00:00:00 2001 From: Andrew Glick Date: Sat, 1 Oct 2016 04:00:22 -0400 Subject: [PATCH 03/11] added SSLPoke.java as an https connection diagnostic aid and made other changes --- .gitignore | 7 ++-- src/main/java/SSLPoke.java | 36 ++++++++++++++++++ src/main/java/com/versioneye/CreateMojo.java | 19 +++++---- src/main/java/com/versioneye/DeleteMojo.java | 1 - src/main/java/com/versioneye/JsonMojo.java | 1 - .../java/com/versioneye/LicenseCheckMojo.java | 9 +++-- src/main/java/com/versioneye/ListMojo.java | 4 +- src/main/java/com/versioneye/PingMojo.java | 3 +- src/main/java/com/versioneye/ProjectMojo.java | 8 ++-- src/main/java/com/versioneye/UpdateMojo.java | 2 +- src/site/.DS_Store | Bin 6148 -> 0 bytes .../com/versioneye/utils/HttpUtilsTest.java | 6 +++ 12 files changed, 70 insertions(+), 26 deletions(-) create mode 100644 src/main/java/SSLPoke.java delete mode 100644 src/site/.DS_Store diff --git a/.gitignore b/.gitignore index cd2856d..3afdcc9 100644 --- a/.gitignore +++ b/.gitignore @@ -15,9 +15,10 @@ capybara-*.html /coverage/ .idea/ .env -versioneye-maven-plugin.iml -versioneye-maven-plugin.ipr -versioneye-maven-plugin.iws +*.iml +*.ipr +*.iws +*.log .classpath .project .settings diff --git a/src/main/java/SSLPoke.java b/src/main/java/SSLPoke.java new file mode 100644 index 0000000..4da3e83 --- /dev/null +++ b/src/main/java/SSLPoke.java @@ -0,0 +1,36 @@ +import java.io.InputStream; +import java.io.OutputStream; + +import javax.net.ssl.SSLSocket; +import javax.net.ssl.SSLSocketFactory; + +/** Establish a SSL connection to a host and port, writes a byte and + * prints the response. See + * http://confluence.atlassian.com/display/JIRA/Connecting+to+SSL+services + */ +public class SSLPoke { + public static void main(String[] args) { + if (args.length != 2) { + System.out.println("Usage: " + SSLPoke.class.getName() + " "); + System.exit(1); + } + try { + SSLSocketFactory sslsocketfactory = (SSLSocketFactory) SSLSocketFactory.getDefault(); + SSLSocket sslsocket = (SSLSocket) sslsocketfactory.createSocket(args[0], Integer.parseInt(args[1])); + + InputStream in = sslsocket.getInputStream(); + OutputStream out = sslsocket.getOutputStream(); + + // Write a test byte to get a reaction :) + out.write(1); + + while (in.available() > 0) { + System.out.print(in.read()); + } + System.out.println("Successfully connected"); + + } catch (Exception exception) { + exception.printStackTrace(); + } + } +} diff --git a/src/main/java/com/versioneye/CreateMojo.java b/src/main/java/com/versioneye/CreateMojo.java index c77122e..f8181c7 100644 --- a/src/main/java/com/versioneye/CreateMojo.java +++ b/src/main/java/com/versioneye/CreateMojo.java @@ -3,6 +3,8 @@ import com.versioneye.dto.ProjectJsonResponse; import com.versioneye.utils.HttpUtils; import com.versioneye.utils.PropertiesUtils; + +import org.apache.commons.lang3.StringUtils; import org.apache.maven.plugin.MojoExecutionException; import org.apache.maven.plugin.MojoFailureException; import org.apache.maven.plugins.annotations.LifecyclePhase; @@ -29,8 +31,8 @@ public void execute() throws MojoExecutionException, MojoFailureException { setProxy(); prettyPrintStart(); - ByteArrayOutputStream jsonDependenciesStream = null; - if (transitiveDependencies == true){ + ByteArrayOutputStream jsonDependenciesStream; + if (transitiveDependencies){ jsonDependenciesStream = getTransitiveDependenciesJsonStream(nameStrategy); } else { jsonDependenciesStream = getDirectDependenciesJsonStream(nameStrategy); @@ -49,8 +51,8 @@ public void execute() throws MojoExecutionException, MojoFailureException { prettyPrint(response); } catch( Exception exception ){ throw new MojoExecutionException("Oh no! Something went wrong :-( " + - "Get in touch with the VersionEye guys and give them feedback." + - "You find them on Twitter at https//twitter.com/VersionEye. ", exception); + "Get in touch with the VersionEye guys and give them feedback." + + "You find them on Twitter at https//twitter.com/VersionEye. ", exception); } } @@ -78,16 +80,14 @@ protected void writeProperties(ProjectJsonResponse response) throws Exception { } protected void merge(String childId) { - if (mergeAfterCreate == false) { + if (!mergeAfterCreate) { return ; } try { - if (parentGroupId == null || parentGroupId.isEmpty() || - parentArtifactId == null || parentArtifactId.isEmpty()){ + if (StringUtils.isBlank(parentGroupId) || StringUtils.isBlank(parentArtifactId)) { MavenProject mp = project.getParent(); - if (mp == null || mp.getGroupId() == null || mp.getGroupId().isEmpty() || - mp.getArtifactId() == null || mp.getArtifactId().isEmpty()){ + if (mp == null || StringUtils.isBlank(mp.getGroupId()) || StringUtils.isBlank(mp.getArtifactId()) ){ return ; } parentGroupId = mp.getGroupId(); @@ -110,5 +110,4 @@ protected void merge(String childId) { getLog().error(ex); } } - } diff --git a/src/main/java/com/versioneye/DeleteMojo.java b/src/main/java/com/versioneye/DeleteMojo.java index 327c378..501964a 100644 --- a/src/main/java/com/versioneye/DeleteMojo.java +++ b/src/main/java/com/versioneye/DeleteMojo.java @@ -1,6 +1,5 @@ package com.versioneye; - import com.versioneye.utils.HttpUtils; import org.apache.maven.plugin.MojoExecutionException; import org.apache.maven.plugin.MojoFailureException; diff --git a/src/main/java/com/versioneye/JsonMojo.java b/src/main/java/com/versioneye/JsonMojo.java index 49e9484..17df797 100644 --- a/src/main/java/com/versioneye/JsonMojo.java +++ b/src/main/java/com/versioneye/JsonMojo.java @@ -33,5 +33,4 @@ private void prettyPrintEnd(String pathToJson){ getLog().info("You find your json file here: " + pathToJson); getLog().info(""); } - } diff --git a/src/main/java/com/versioneye/LicenseCheckMojo.java b/src/main/java/com/versioneye/LicenseCheckMojo.java index 6394cc1..47b1e92 100644 --- a/src/main/java/com/versioneye/LicenseCheckMojo.java +++ b/src/main/java/com/versioneye/LicenseCheckMojo.java @@ -16,12 +16,14 @@ public class LicenseCheckMojo extends UpdateMojo { public void execute() throws MojoExecutionException, MojoFailureException { + try{ setProxy(); prettyPrintStart(); - ByteArrayOutputStream jsonDependenciesStream = null; - if (transitiveDependencies == true){ + ByteArrayOutputStream jsonDependenciesStream; + + if (transitiveDependencies){ jsonDependenciesStream = getTransitiveDependenciesJsonStream(nameStrategy); } else { jsonDependenciesStream = getDirectDependenciesJsonStream(nameStrategy); @@ -39,7 +41,7 @@ public void execute() throws MojoExecutionException, MojoFailureException { "More details here: " + baseUrl + "/user/projects/" + response.getId() ); } - if (response.getLicenses_unknown() > 0 && licenseCheckBreakByUnknown == true ){ + if (response.getLicenses_unknown() > 0 && licenseCheckBreakByUnknown) { throw new MojoExecutionException("Some components are without any license! " + "More details here: " + baseUrl + "/user/projects/" + response.getId() ); } @@ -52,5 +54,4 @@ public void execute() throws MojoExecutionException, MojoFailureException { "You find them on Twitter at https//twitter.com/VersionEye. ", exception); } } - } diff --git a/src/main/java/com/versioneye/ListMojo.java b/src/main/java/com/versioneye/ListMojo.java index 0d571ce..0c083cf 100644 --- a/src/main/java/com/versioneye/ListMojo.java +++ b/src/main/java/com/versioneye/ListMojo.java @@ -20,6 +20,7 @@ public class ListMojo extends ProjectMojo { public void execute() throws MojoExecutionException { versionEyeOutput(); + try{ PreorderNodeListGenerator nlg = new PreorderNodeListGenerator(); DependencyNode root = getDependencyNode(nlg); @@ -52,9 +53,11 @@ private void productNiceOutputForDirectDependencies(List directDepen getLog().info(""); getLog().info(directDependencies.size() + " Direct Dependencies: "); getLog().info("--------------------"); + for (Dependency dependency : directDependencies){ getLog().info( dependency.getGroupId() + ":" + dependency.getArtifactId() + ":" + dependency.getVersion()); } + getLog().info(""); } @@ -77,5 +80,4 @@ private void produceNiceOutputSummary(int directCount, int recursiveCount) { getLog().info(""); getLog().info(""); } - } diff --git a/src/main/java/com/versioneye/PingMojo.java b/src/main/java/com/versioneye/PingMojo.java index 6548758..237253e 100644 --- a/src/main/java/com/versioneye/PingMojo.java +++ b/src/main/java/com/versioneye/PingMojo.java @@ -24,7 +24,7 @@ public void execute() throws MojoExecutionException, MojoFailureException { initTls(); InputStream inputStream = getInputStream(baseUrl + apiPath + "/services/ping"); BufferedReader input = new BufferedReader( new InputStreamReader( inputStream ) ); - String line = ""; + String line; getLog().info(""); while((line = input.readLine())!=null){ getLog().info(line); @@ -50,5 +50,4 @@ private InputStream getInputStream( String urlPath ) throws Exception { return urlConnection.getInputStream(); } } - } diff --git a/src/main/java/com/versioneye/ProjectMojo.java b/src/main/java/com/versioneye/ProjectMojo.java index 32b98b0..5e2a15c 100644 --- a/src/main/java/com/versioneye/ProjectMojo.java +++ b/src/main/java/com/versioneye/ProjectMojo.java @@ -61,13 +61,15 @@ protected ByteArrayOutputStream getDirectDependenciesJsonStream(String nameStrat } List dependencies = project.getDependencies(); - if (ignoreDependencyManagement == false && - project.getDependencyManagement() != null && + if (!ignoreDependencyManagement && project.getDependencyManagement() != null && project.getDependencyManagement().getDependencies() != null && project.getDependencyManagement().getDependencies().size() > 0){ - dependencies.addAll(project.getDependencyManagement().getDependencies()); + + dependencies.addAll(project.getDependencyManagement().getDependencies()); } + List filteredDependencies = filterForScopes(dependencies); + JsonUtils jsonUtils = new JsonUtils(); return jsonUtils.dependenciesToJson(project, filteredDependencies, plugins, nameStrategy); } diff --git a/src/main/java/com/versioneye/UpdateMojo.java b/src/main/java/com/versioneye/UpdateMojo.java index 321a419..916328f 100644 --- a/src/main/java/com/versioneye/UpdateMojo.java +++ b/src/main/java/com/versioneye/UpdateMojo.java @@ -27,7 +27,7 @@ public void execute() throws MojoExecutionException, MojoFailureException { prettyPrintStart(); ByteArrayOutputStream jsonDependenciesStream = null; - if (transitiveDependencies == true){ + if (transitiveDependencies){ jsonDependenciesStream = getTransitiveDependenciesJsonStream(nameStrategy); } else { jsonDependenciesStream = getDirectDependenciesJsonStream(nameStrategy); diff --git a/src/site/.DS_Store b/src/site/.DS_Store deleted file mode 100644 index cd3a2cf86a516c8064df523e3cb54a7528c4c45a..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 6148 zcmeHKOKQU~5S>X)F?8c)mbyZ2AcAuOU!aACP{;>bnzdIsSC7^=pN;Ew=WfCq7(Hn; zPeO0u@ra0SKVLT@ortt>L%G>7H`_O#*(xIngyW38d|Ze3^YL;%%(8zE823@$ Date: Sat, 5 Nov 2016 11:10:45 -0400 Subject: [PATCH 04/11] applying Glick's changes to plugin --- pom.xml | 5 +++ src/main/java/com/versioneye/SuperMojo.java | 36 ++++++++++--------- src/main/java/com/versioneye/UpdateMojo.java | 3 +- .../com/versioneye/dto/ErrorJsonResponse.java | 2 +- .../com/versioneye/dto/ProjectDependency.java | 1 + .../versioneye/dto/ProjectJsonResponse.java | 1 + .../java/com/versioneye/utils/HttpUtils.java | 18 +++++----- .../java/com/versioneye/utils/JsonUtils.java | 20 ++++++++--- 8 files changed, 55 insertions(+), 31 deletions(-) diff --git a/pom.xml b/pom.xml index b0a51a7..93a6923 100644 --- a/pom.xml +++ b/pom.xml @@ -107,6 +107,11 @@ jackson-mapper-lgpl ${jackson.version} + + org.apache.commons + commons-lang3 + 3.4 + org.apache.httpcomponents httpclient diff --git a/src/main/java/com/versioneye/SuperMojo.java b/src/main/java/com/versioneye/SuperMojo.java index 92aba00..6bf856b 100644 --- a/src/main/java/com/versioneye/SuperMojo.java +++ b/src/main/java/com/versioneye/SuperMojo.java @@ -1,30 +1,34 @@ package com.versioneye; -import com.versioneye.utils.PropertiesUtils; +import java.io.File; +import java.io.IOException; +import java.security.SecureRandom; +import java.security.cert.X509Certificate; +import java.util.List; +import java.util.Properties; + +import javax.net.ssl.HttpsURLConnection; +import javax.net.ssl.SSLContext; +import javax.net.ssl.TrustManager; +import javax.net.ssl.X509TrustManager; + import org.apache.maven.plugin.AbstractMojo; import org.apache.maven.plugin.MojoExecutionException; import org.apache.maven.plugin.MojoFailureException; import org.apache.maven.plugins.annotations.Component; import org.apache.maven.plugins.annotations.Parameter; import org.apache.maven.project.MavenProject; +import org.codehaus.plexus.util.StringUtils; import org.eclipse.aether.RepositorySystem; import org.eclipse.aether.RepositorySystemSession; import org.eclipse.aether.repository.RemoteRepository; -import javax.net.ssl.HttpsURLConnection; -import javax.net.ssl.SSLContext; -import javax.net.ssl.TrustManager; -import javax.net.ssl.X509TrustManager; -import java.io.File; -import java.io.IOException; -import java.security.SecureRandom; -import java.security.cert.X509Certificate; -import java.util.List; -import java.util.Properties; +import com.versioneye.utils.PropertiesUtils; /** * The Mother of all Mojos! */ +@SuppressWarnings("WeakerAccess") public class SuperMojo extends AbstractMojo { protected static final String propertiesFile = "versioneye.properties"; @@ -125,26 +129,26 @@ public class SuperMojo extends AbstractMojo { public void execute() throws MojoExecutionException, MojoFailureException { } protected String fetchApiKey() throws Exception { - if (apiKey != null && !apiKey.isEmpty() ) + if (StringUtils.isNotBlank(apiKey) ) return apiKey; apiKey = System.getenv().get("VERSIONEYE_API_KEY"); String propertiesPath = homeDirectory + "/.m2/" + propertiesFile; String key = getPropertyFromPath(propertiesPath, "api_key"); - if (key != null && !key.isEmpty()){ + if (StringUtils.isNotBlank(key)){ apiKey = key; } propertiesPath = projectDirectory + "/src/qa/resources/" + propertiesFile; key = getPropertyFromPath(propertiesPath, "api_key"); - if (key != null && !key.isEmpty()){ + if (StringUtils.isNotBlank(key)){ apiKey = key; } propertiesPath = projectDirectory + "/src/main/resources/" + propertiesFile; key = getPropertyFromPath(propertiesPath, "api_key"); - if (key != null && !key.isEmpty()){ + if (StringUtils.isNotBlank(key)) { apiKey = key; } @@ -152,7 +156,7 @@ protected String fetchApiKey() throws Exception { } protected String fetchBaseUrl() throws Exception { - if (baseUrl != null && !baseUrl.isEmpty() ) + if (StringUtils.isNotBlank(baseUrl)) return baseUrl; baseUrl = System.getenv().get("VERSIONEYE_BASE_URL"); diff --git a/src/main/java/com/versioneye/UpdateMojo.java b/src/main/java/com/versioneye/UpdateMojo.java index 79b1622..3610727 100644 --- a/src/main/java/com/versioneye/UpdateMojo.java +++ b/src/main/java/com/versioneye/UpdateMojo.java @@ -15,6 +15,7 @@ /** * Updates an existing project at VersionEye with the dependencies from the current project. */ +@SuppressWarnings("WeakerAccess") @Mojo( name = "update", defaultPhase = LifecyclePhase.PACKAGE ) public class UpdateMojo extends ProjectMojo { @@ -26,7 +27,7 @@ public void execute() throws MojoExecutionException, MojoFailureException { setProxy(); prettyPrintStart(); - ByteArrayOutputStream jsonDependenciesStream = null; + ByteArrayOutputStream jsonDependenciesStream; if (transitiveDependencies){ jsonDependenciesStream = getTransitiveDependenciesJsonStream(nameStrategy); } else { diff --git a/src/main/java/com/versioneye/dto/ErrorJsonResponse.java b/src/main/java/com/versioneye/dto/ErrorJsonResponse.java index 41783c0..75c6572 100644 --- a/src/main/java/com/versioneye/dto/ErrorJsonResponse.java +++ b/src/main/java/com/versioneye/dto/ErrorJsonResponse.java @@ -12,8 +12,8 @@ public String getError() { return error; } + @SuppressWarnings("unused") public void setError(String error) { this.error = error; } - } diff --git a/src/main/java/com/versioneye/dto/ProjectDependency.java b/src/main/java/com/versioneye/dto/ProjectDependency.java index d553ae4..95b14c9 100644 --- a/src/main/java/com/versioneye/dto/ProjectDependency.java +++ b/src/main/java/com/versioneye/dto/ProjectDependency.java @@ -3,6 +3,7 @@ import org.codehaus.jackson.annotate.JsonIgnoreProperties; +@SuppressWarnings("unused") @JsonIgnoreProperties(ignoreUnknown = true) public class ProjectDependency { diff --git a/src/main/java/com/versioneye/dto/ProjectJsonResponse.java b/src/main/java/com/versioneye/dto/ProjectJsonResponse.java index 4a62c44..d0eddc5 100644 --- a/src/main/java/com/versioneye/dto/ProjectJsonResponse.java +++ b/src/main/java/com/versioneye/dto/ProjectJsonResponse.java @@ -5,6 +5,7 @@ /** * Java representation of the project JSON response from VersionEye API. */ +@SuppressWarnings("unused") @JsonIgnoreProperties(ignoreUnknown = true) public class ProjectJsonResponse { diff --git a/src/main/java/com/versioneye/utils/HttpUtils.java b/src/main/java/com/versioneye/utils/HttpUtils.java index 0f82488..d05912b 100644 --- a/src/main/java/com/versioneye/utils/HttpUtils.java +++ b/src/main/java/com/versioneye/utils/HttpUtils.java @@ -9,6 +9,7 @@ import org.apache.http.entity.mime.content.StringBody; import org.apache.http.impl.client.SystemDefaultHttpClient; import org.codehaus.jackson.map.ObjectMapper; +import org.codehaus.plexus.util.StringUtils; import java.io.BufferedReader; import java.io.InputStream; @@ -20,6 +21,7 @@ /** * Methods to deal with the HTTP protocol. */ +@SuppressWarnings("WeakerAccess") public class HttpUtils { public static Integer ONE_SECOND = 1000; @@ -40,7 +42,7 @@ public static String get(String url) throws Exception { BufferedReader in = new BufferedReader(new InputStreamReader(con.getInputStream())); String inputLine; - StringBuffer response = new StringBuffer(); + StringBuilder response = new StringBuilder(); while ((inputLine = in.readLine()) != null) { response.append(inputLine); } @@ -56,16 +58,16 @@ public static Reader post(String url, byte[] data, String dataName, String visib MultipartEntity multipartEntity = new MultipartEntity(); multipartEntity.addPart(dataName, byteArrayBody); - if (visibility != null && !visibility.isEmpty()) + if (StringUtils.isNotBlank(visibility)) multipartEntity.addPart("visibility", new StringBody(visibility)); - if (name != null && !name.isEmpty()) + if (StringUtils.isNotBlank(name)) multipartEntity.addPart("name", new StringBody(name)); - if (orga_name != null && !orga_name.isEmpty()) + if (StringUtils.isNotBlank(orga_name)) multipartEntity.addPart("orga_name", new StringBody(orga_name)); - if (team != null && !team.isEmpty()) + if (StringUtils.isNotBlank(team)) multipartEntity.addPart("team_name", new StringBody(team)); httpPost.setEntity(multipartEntity); @@ -96,7 +98,7 @@ public static String delete(String url) throws Exception { BufferedReader in = new BufferedReader(new InputStreamReader(con.getInputStream())); String inputLine; - StringBuffer response = new StringBuffer(); + StringBuilder response = new StringBuilder(); while ((inputLine = in.readLine()) != null) { response.append(inputLine); } @@ -128,7 +130,7 @@ private static String getPureBodyString(HttpResponse response){ InputStream content = response.getEntity().getContent(); BufferedReader in = new BufferedReader(new InputStreamReader( content ) ); String inputLine; - StringBuffer body = new StringBuffer(); + StringBuilder body = new StringBuilder(); while ((inputLine = in.readLine()) != null) { body.append(inputLine); } @@ -138,7 +140,5 @@ private static String getPureBodyString(HttpResponse response){ exception.printStackTrace(); return ""; } - } - } diff --git a/src/main/java/com/versioneye/utils/JsonUtils.java b/src/main/java/com/versioneye/utils/JsonUtils.java index 502cf67..19c1eb9 100644 --- a/src/main/java/com/versioneye/utils/JsonUtils.java +++ b/src/main/java/com/versioneye/utils/JsonUtils.java @@ -1,5 +1,6 @@ package com.versioneye.utils; +import org.apache.commons.lang3.StringUtils; import org.apache.maven.model.Dependency; import org.apache.maven.model.Plugin; import org.apache.maven.project.MavenProject; @@ -16,6 +17,7 @@ /** * Methods to deal with JSON. */ +@SuppressWarnings("WeakerAccess") public class JsonUtils { public ByteArrayOutputStream dependenciesToJson(MavenProject project, List dependencies, List plugins, String nameStrategy) throws Exception { @@ -36,11 +38,13 @@ public ByteArrayOutputStream artifactsToJson(List directDependencies) return outstream; } + @SuppressWarnings("UnusedParameters") public void dependenciesToJsonFile(String name, Map directDependencies, String file) throws Exception { File targetFile = getTargetFile(file); toJson(new FileOutputStream(targetFile), directDependencies); } + @SuppressWarnings("unused") public void dependenciesToJsonFile(MavenProject project, List directDependencies, String file, String nameStrategy) throws Exception { List> dependencyHashes = getHashes(directDependencies); File targetFile = getTargetFile(file); @@ -54,16 +58,24 @@ public static void toJson(OutputStream output, Object input) throws Exception { } public List> getHashes(List directDependencies){ - List> hashes = (List>) new Vector>(directDependencies.size()); + List> hashes = new Vector>(directDependencies.size()); hashes.addAll( generateHashForJsonOutput( directDependencies)); return hashes; } public List> getDependencyHashes(List directDependencies, List plugins){ +<<<<<<< Updated upstream List> hashes = (List>) new Vector>(); if (directDependencies != null && directDependencies.size() > 0){ hashes.addAll( generateHashFromDependencyList( directDependencies)); } +||||||| merged common ancestors + List> hashes = (List>) new Vector>(); + hashes.addAll( generateHashFromDependencyList( directDependencies)); +======= + List> hashes = new Vector>(); + hashes.addAll( generateHashFromDependencyList( directDependencies)); +>>>>>>> Stashed changes if (plugins != null && plugins.size() > 0){ hashes.addAll( generateHashFromPluginList(plugins)); } @@ -125,12 +137,12 @@ public Map getJsonPom(MavenProject project, List Date: Mon, 23 Jan 2017 22:53:36 -0500 Subject: [PATCH 05/11] more cleanup --- src/main/java/com/versioneye/CreateMojo.java | 7 +++---- src/main/java/com/versioneye/DeleteMojo.java | 2 ++ src/main/java/com/versioneye/JsonMojo.java | 2 ++ .../java/com/versioneye/LicenseCheckMojo.java | 1 + src/main/java/com/versioneye/ListMojo.java | 4 +++- src/main/java/com/versioneye/PingMojo.java | 2 ++ src/main/java/com/versioneye/ProjectMojo.java | 4 ++-- .../SecurityAndLicenseCheckMojo.java | 20 ++++++++++--------- .../com/versioneye/SecurityCheckMojo.java | 6 ++++-- src/main/java/com/versioneye/SuperMojo.java | 18 ++++++++--------- src/main/java/com/versioneye/UpdateMojo.java | 10 +++++----- 11 files changed, 43 insertions(+), 33 deletions(-) diff --git a/src/main/java/com/versioneye/CreateMojo.java b/src/main/java/com/versioneye/CreateMojo.java index cbedc2e..aee14d2 100644 --- a/src/main/java/com/versioneye/CreateMojo.java +++ b/src/main/java/com/versioneye/CreateMojo.java @@ -55,9 +55,9 @@ public void execute() throws MojoExecutionException, MojoFailureException { } prettyPrint(response); } catch( Exception exception ){ - throw new MojoExecutionException("Oh no! Something went wrong :-( " + - "Get in touch with the VersionEye guys and give them feedback." + - "You find them on Twitter at https//twitter.com/VersionEye. ", exception); + throw new MojoExecutionException("Oh no! Something went wrong :-( " + + "Get in touch with the VersionEye guys and give them feedback." + + "You find them on Twitter at https//twitter.com/VersionEye. ", exception); } } @@ -89,7 +89,6 @@ protected void merge(String childId) { return ; } try { - if (StringUtils.isBlank(parentGroupId) || StringUtils.isBlank(parentArtifactId)) { MavenProject mp = project.getParent(); if (mp == null || StringUtils.isBlank(mp.getGroupId()) || StringUtils.isBlank(mp.getArtifactId()) ){ diff --git a/src/main/java/com/versioneye/DeleteMojo.java b/src/main/java/com/versioneye/DeleteMojo.java index 488daf6..14cb6ae 100644 --- a/src/main/java/com/versioneye/DeleteMojo.java +++ b/src/main/java/com/versioneye/DeleteMojo.java @@ -9,12 +9,14 @@ import java.io.File; +@SuppressWarnings({"WeakerAccess", "unused"}) @Mojo( name = "delete", defaultPhase = LifecyclePhase.PROCESS_SOURCES ) public class DeleteMojo extends ProjectMojo { @Parameter( property = "resource", defaultValue = "/projects") private String resource; + @Override public void execute() throws MojoExecutionException, MojoFailureException { try{ setProxy(); diff --git a/src/main/java/com/versioneye/JsonMojo.java b/src/main/java/com/versioneye/JsonMojo.java index 17df797..010a33b 100644 --- a/src/main/java/com/versioneye/JsonMojo.java +++ b/src/main/java/com/versioneye/JsonMojo.java @@ -11,9 +11,11 @@ /** * Writes all direct dependencies into a JSON file. */ +@SuppressWarnings("unused") @Mojo( name = "json", defaultPhase = LifecyclePhase.PROCESS_SOURCES ) public class JsonMojo extends ProjectMojo { + @Override public void execute() throws MojoExecutionException, MojoFailureException { try{ Map jsonMap = getDirectDependenciesJsonMap(nameStrategy); diff --git a/src/main/java/com/versioneye/LicenseCheckMojo.java b/src/main/java/com/versioneye/LicenseCheckMojo.java index c4160e8..03c143c 100644 --- a/src/main/java/com/versioneye/LicenseCheckMojo.java +++ b/src/main/java/com/versioneye/LicenseCheckMojo.java @@ -15,6 +15,7 @@ @Mojo( name = "licenseCheck", defaultPhase = LifecyclePhase.VERIFY ) public class LicenseCheckMojo extends UpdateMojo { + @Override public void execute() throws MojoExecutionException, MojoFailureException { try{ diff --git a/src/main/java/com/versioneye/ListMojo.java b/src/main/java/com/versioneye/ListMojo.java index f94c567..3d98a5f 100644 --- a/src/main/java/com/versioneye/ListMojo.java +++ b/src/main/java/com/versioneye/ListMojo.java @@ -16,9 +16,11 @@ /** * Lists all direct and recursive dependencies. */ +@SuppressWarnings("unused") @Mojo( name = "list", defaultPhase = LifecyclePhase.PROCESS_SOURCES ) public class ListMojo extends ProjectMojo { + @Override public void execute() throws MojoExecutionException, MojoFailureException { versionEyeOutput(); @@ -28,7 +30,7 @@ public void execute() throws MojoExecutionException, MojoFailureException DependencyNode root = getDependencyNode(nlg); List dependencies = DependencyUtils.collectAllDependencies(nlg.getDependencies(true)); List directDependencies = DependencyUtils.collectDirectDependencies(root.getChildren()); - List recursiveDependencies = new ArrayList(dependencies); + List recursiveDependencies = new ArrayList<>(dependencies); recursiveDependencies.removeAll(directDependencies); List deps = project.getDependencies(); produceNiceOutput(deps, recursiveDependencies); diff --git a/src/main/java/com/versioneye/PingMojo.java b/src/main/java/com/versioneye/PingMojo.java index c5cd737..7f07c7b 100644 --- a/src/main/java/com/versioneye/PingMojo.java +++ b/src/main/java/com/versioneye/PingMojo.java @@ -15,9 +15,11 @@ /** * Ping the VersionEye API. Expects a pong in response. */ +@SuppressWarnings("unused") @Mojo( name = "ping", defaultPhase = LifecyclePhase.PROCESS_SOURCES ) public class PingMojo extends SuperMojo { + @Override public void execute() throws MojoExecutionException, MojoFailureException { try{ setProxy(); diff --git a/src/main/java/com/versioneye/ProjectMojo.java b/src/main/java/com/versioneye/ProjectMojo.java index 1635026..b749bad 100644 --- a/src/main/java/com/versioneye/ProjectMojo.java +++ b/src/main/java/com/versioneye/ProjectMojo.java @@ -40,7 +40,7 @@ /** * Methods required to deal with projects resource */ -@SuppressWarnings("WeakerAccess") +@SuppressWarnings({"WeakerAccess", "unused"}) public class ProjectMojo extends SuperMojo { protected ByteArrayOutputStream getTransitiveDependenciesJsonStream(String nameStrategy) throws Exception { @@ -190,7 +190,7 @@ private void iterateThrough(List dependencies){ } private List getPluginsFromXml(){ - List plugins = new ArrayList(); + List plugins = new ArrayList<>(); try { File pom = project.getModel().getPomFile(); diff --git a/src/main/java/com/versioneye/SecurityAndLicenseCheckMojo.java b/src/main/java/com/versioneye/SecurityAndLicenseCheckMojo.java index 054691e..61a2145 100644 --- a/src/main/java/com/versioneye/SecurityAndLicenseCheckMojo.java +++ b/src/main/java/com/versioneye/SecurityAndLicenseCheckMojo.java @@ -8,16 +8,19 @@ import java.io.ByteArrayOutputStream; +@SuppressWarnings("unused") @Mojo( name = "securityAndLicenseCheck", defaultPhase = LifecyclePhase.VERIFY ) public class SecurityAndLicenseCheckMojo extends UpdateMojo { + @Override public void execute() throws MojoExecutionException, MojoFailureException { try{ setProxy(); prettyPrintStart(); - ByteArrayOutputStream jsonDependenciesStream = null; - if (transitiveDependencies == true){ + ByteArrayOutputStream jsonDependenciesStream; + + if (transitiveDependencies){ jsonDependenciesStream = getTransitiveDependenciesJsonStream(nameStrategy); } else { jsonDependenciesStream = getDirectDependenciesJsonStream(nameStrategy); @@ -32,28 +35,27 @@ public void execute() throws MojoExecutionException, MojoFailureException { System.out.println("sv_count: " + response.getSv_count()); if (response.getSv_count() > 0){ throw new MojoExecutionException("Some components have security vulnerabilities! " + - "More details here: " + fetchBaseUrl() + "/user/projects/" + response.getId() ); + "More details here: " + fetchBaseUrl() + "/user/projects/" + response.getId() ); } System.out.println("licenses_red: " + response.getLicenses_red()); if (response.getLicenses_red() > 0){ throw new MojoExecutionException("Some components violate the license whitelist! " + - "More details here: " + fetchBaseUrl() + "/user/projects/" + response.getId() ); + "More details here: " + fetchBaseUrl() + "/user/projects/" + response.getId() ); } - if (response.getLicenses_unknown() > 0 && licenseCheckBreakByUnknown == true ){ + if (response.getLicenses_unknown() > 0 && licenseCheckBreakByUnknown){ throw new MojoExecutionException("Some components are without any license! " + - "More details here: " + fetchBaseUrl() + "/user/projects/" + response.getId() ); + "More details here: " + fetchBaseUrl() + "/user/projects/" + response.getId() ); } prettyPrint( response ); } catch( Exception exception ){ exception.printStackTrace(); throw new MojoExecutionException("Oh no! Something went wrong. " + - "Get in touch with the VersionEye guys and give them feedback. " + - "You find them on Twitter at https//twitter.com/VersionEye. ", exception); + "Get in touch with the VersionEye guys and give them feedback. " + + "You find them on Twitter at https//twitter.com/VersionEye. ", exception); } } - } diff --git a/src/main/java/com/versioneye/SecurityCheckMojo.java b/src/main/java/com/versioneye/SecurityCheckMojo.java index 711f1c4..4e6b8d4 100644 --- a/src/main/java/com/versioneye/SecurityCheckMojo.java +++ b/src/main/java/com/versioneye/SecurityCheckMojo.java @@ -8,16 +8,18 @@ import java.io.ByteArrayOutputStream; +@SuppressWarnings("unused") @Mojo( name = "securityCheck", defaultPhase = LifecyclePhase.VERIFY ) public class SecurityCheckMojo extends UpdateMojo { + @Override public void execute() throws MojoExecutionException, MojoFailureException { try{ setProxy(); prettyPrintStart(); - ByteArrayOutputStream jsonDependenciesStream = null; - if (transitiveDependencies == true){ + ByteArrayOutputStream jsonDependenciesStream; + if (transitiveDependencies){ jsonDependenciesStream = getTransitiveDependenciesJsonStream(nameStrategy); } else { jsonDependenciesStream = getDirectDependenciesJsonStream(nameStrategy); diff --git a/src/main/java/com/versioneye/SuperMojo.java b/src/main/java/com/versioneye/SuperMojo.java index 8550ddc..cb93ccb 100644 --- a/src/main/java/com/versioneye/SuperMojo.java +++ b/src/main/java/com/versioneye/SuperMojo.java @@ -4,7 +4,6 @@ import org.apache.maven.execution.MavenSession; import org.apache.maven.plugin.AbstractMojo; import org.apache.maven.plugin.MojoExecutionException; -import org.apache.maven.plugin.MojoFailureException; import org.apache.maven.plugins.annotations.Component; import org.apache.maven.plugins.annotations.Parameter; import org.apache.maven.project.MavenProject; @@ -143,10 +142,6 @@ public abstract class SuperMojo extends AbstractMojo protected Properties properties = null; // Properties in src/main/resources protected Properties homeProperties = null; // Properties in ~/.m2/ - - public abstract void execute() throws MojoExecutionException, MojoFailureException; - - protected String fetchApiKey() throws Exception { if (StringUtils.isNotBlank(apiKey) ) return apiKey; @@ -292,11 +287,14 @@ private void createPropertiesFile(File file) throws IOException protected void initTls(){ TrustManager[] trustAllCerts = new TrustManager[]{new X509TrustManager(){ - public X509Certificate[] getAcceptedIssuers(){return null;} - @Override - public void checkClientTrusted(X509Certificate[] certs, String authType){} - @Override - public void checkServerTrusted(X509Certificate[] certs, String authType){} + @Override + public X509Certificate[] getAcceptedIssuers(){return null;} + + @Override + public void checkClientTrusted(X509Certificate[] certs, String authType){} + + @Override + public void checkServerTrusted(X509Certificate[] certs, String authType){} }}; try { SSLContext sc = SSLContext.getInstance("TLS"); diff --git a/src/main/java/com/versioneye/UpdateMojo.java b/src/main/java/com/versioneye/UpdateMojo.java index d47dd86..6f474d4 100644 --- a/src/main/java/com/versioneye/UpdateMojo.java +++ b/src/main/java/com/versioneye/UpdateMojo.java @@ -19,7 +19,7 @@ public class UpdateMojo extends ProjectMojo { @Parameter( property = "resource", defaultValue = "/projects") private String resource; - + @Override public void execute() throws MojoExecutionException, MojoFailureException { try{ setProxy(); @@ -42,8 +42,8 @@ public void execute() throws MojoExecutionException, MojoFailureException { } catch( Exception exception ){ exception.printStackTrace(); throw new MojoExecutionException("Oh no! Something went wrong. " + - "Get in touch with the VersionEye guys and give them feedback. " + - "You find them on Twitter at https//twitter.com/VersionEye. ", exception); + "Get in touch with the VersionEye guys and give them feedback. " + + "You find them on Twitter at https//twitter.com/VersionEye. ", exception); } } @@ -51,7 +51,7 @@ public void execute() throws MojoExecutionException, MojoFailureException { protected ProjectJsonResponse uploadDependencies(ByteArrayOutputStream outStream) throws Exception { try { String projectId = fetchProjectId(); - if (mavenSession.getTopLevelProject().getId().equals(mavenSession.getCurrentProject().getId())){ + if (mavenSession.getTopLevelProject().getId().equals(mavenSession.getCurrentProject().getId())) { mavenSession.getTopLevelProject().setContextValue("veye_project_id", projectId); } return updateExistingProject(resource, projectId, outStream); @@ -66,7 +66,7 @@ protected ProjectJsonResponse uploadDependencies(ByteArrayOutputStream outStream } } - protected void prettyPrintStart(){ + protected void prettyPrintStart() { getLog().info("."); getLog().info("Starting to update dependencies to server. This can take a couple seconds ... "); getLog().info("."); From 404a63edfb3990509f22a71bc1c1d0c5971b5e88 Mon Sep 17 00:00:00 2001 From: andyglick Date: Thu, 26 Jan 2017 01:07:03 -0500 Subject: [PATCH 06/11] made many changes -- modified the exception strategy, removed many "throws Exception" and replaced the "generic" exception with the actual exception(s) being thrown by the code -- refactored a number of classes --- pom.xml | 150 ++++++++++++++++++ src/main/java/com/versioneye/CreateMojo.java | 12 +- src/main/java/com/versioneye/DeleteMojo.java | 11 +- src/main/java/com/versioneye/JsonMojo.java | 7 +- .../java/com/versioneye/LicenseCheckMojo.java | 12 +- src/main/java/com/versioneye/ListMojo.java | 18 +-- src/main/java/com/versioneye/PingMojo.java | 10 +- src/main/java/com/versioneye/ProjectMojo.java | 58 +++---- .../SecurityAndLicenseCheckMojo.java | 3 +- .../com/versioneye/SecurityCheckMojo.java | 9 +- src/main/java/com/versioneye/SuperMojo.java | 64 ++++---- src/main/java/com/versioneye/UpdateMojo.java | 3 +- .../versioneye/dto/ProjectJsonResponse.java | 4 +- .../com/versioneye/utils/CollectionUtils.java | 5 +- .../com/versioneye/utils/DependencyUtils.java | 42 ++--- .../java/com/versioneye/utils/HttpUtils.java | 20 +-- .../java/com/versioneye/utils/JsonUtils.java | 17 +- .../com/versioneye/utils/PropertiesUtils.java | 13 +- 18 files changed, 319 insertions(+), 139 deletions(-) diff --git a/pom.xml b/pom.xml index e606d99..ff5ed23 100644 --- a/pom.xml +++ b/pom.xml @@ -51,6 +51,7 @@ + 2.0.15 4.5.2 1.9.13 1.8 @@ -58,10 +59,106 @@ ${java.version} 3.3.9 + 2.8.1 + 3.0.24 + UTF-8 + UTF-8 + 1.7.22 2.19.1 + + enforcer + + + + org.apache.maven.plugins + maven-enforcer-plugin + 1.4.1 + + + enforce-dependency-convergence + validate + + enforce + + + + + + + + true + + + commons-logging + log4j + log4j:log4j + slf4j-to-log4j + + jdom:jdom + + org.apache.commons:commons-io + + + + + + + + + + errorprone-compiler + + + + + maven-compiler-plugin + 3.6.1 + + javac-with-errorprone + true + + + + com.google.errorprone + error_prone_annotations + ${errorprone.compiler.version} + + + com.google.errorprone + error_prone_core + ${errorprone.compiler.version} + + + + org.codehaus.plexus + plexus-compiler-javac-errorprone + ${plexus.compiler.version} + + + org.codehaus.plexus + plexus-compiler-api + ${plexus.compiler.version} + + + org.codehaus.plexus + plexus-compiler-manager + ${plexus.compiler.version} + + + org.codehaus.plexus + plexus-utils + ${plexus.utils.version} + + + + + + + + gpg @@ -85,7 +182,52 @@ + + + + org.apache.commons + commons-lang3 + 3.5 + + + org.apache.maven + maven-artifact + 3.3.9 + + + com.google.guava + guava + 21.0 + + + org.codehaus.plexus + plexus-utils + 3.0.24 + + + org.codehaus.plexus + plexus-component-annotations + 1.6 + + + + + + org.slf4j + jcl-over-slf4j + ${slf4j.version} + + + org.slf4j + slf4j-simple + ${slf4j.version} + + + org.slf4j + slf4j-api + ${slf4j.version} + org.apache.maven maven-plugin-api @@ -121,6 +263,12 @@ org.apache.httpcomponents httpclient ${httpcomponents.version} + + + commons-logging + commons-logging + + org.apache.httpcomponents @@ -241,6 +389,7 @@ attach-sources + verify jar-no-fork @@ -255,6 +404,7 @@ attach-javadocs + verify jar diff --git a/src/main/java/com/versioneye/CreateMojo.java b/src/main/java/com/versioneye/CreateMojo.java index aee14d2..d4fb3b9 100644 --- a/src/main/java/com/versioneye/CreateMojo.java +++ b/src/main/java/com/versioneye/CreateMojo.java @@ -13,6 +13,7 @@ import com.versioneye.utils.PropertiesUtils; import java.io.ByteArrayOutputStream; +import java.io.IOException; import java.util.Properties; /** @@ -55,14 +56,15 @@ public void execute() throws MojoExecutionException, MojoFailureException { } prettyPrint(response); } catch( Exception exception ){ - throw new MojoExecutionException("Oh no! Something went wrong :-( " + - "Get in touch with the VersionEye guys and give them feedback." + - "You find them on Twitter at https//twitter.com/VersionEye. ", exception); + throw new MojoExecutionException("Oh no! Something went wrong :-( " + + "Get in touch with the VersionEye guys and give them feedback." + + "You find them on Twitter at https//twitter.com/VersionEye. ", exception); } } - private ProjectJsonResponse uploadDependencies(ByteArrayOutputStream outStream) throws Exception { + private ProjectJsonResponse uploadDependencies(ByteArrayOutputStream outStream) throws Exception + { return createNewProject(resource, outStream); } @@ -74,7 +76,7 @@ private void prettyPrintStart(){ } @Override - protected void writeProperties(ProjectJsonResponse response) throws Exception { + protected void writeProperties(ProjectJsonResponse response) throws IOException { Properties properties = fetchProjectProperties(); if (response.getId() != null) { properties.setProperty("project_id", response.getId()); diff --git a/src/main/java/com/versioneye/DeleteMojo.java b/src/main/java/com/versioneye/DeleteMojo.java index 14cb6ae..ddf9edc 100644 --- a/src/main/java/com/versioneye/DeleteMojo.java +++ b/src/main/java/com/versioneye/DeleteMojo.java @@ -1,12 +1,13 @@ package com.versioneye; -import com.versioneye.utils.HttpUtils; import org.apache.maven.plugin.MojoExecutionException; import org.apache.maven.plugin.MojoFailureException; import org.apache.maven.plugins.annotations.LifecyclePhase; import org.apache.maven.plugins.annotations.Mojo; import org.apache.maven.plugins.annotations.Parameter; +import com.versioneye.utils.HttpUtils; + import java.io.File; @SuppressWarnings({"WeakerAccess", "unused"}) @@ -26,8 +27,8 @@ public void execute() throws MojoExecutionException, MojoFailureException { } catch( Exception exception ){ exception.printStackTrace(); throw new MojoExecutionException("Oh no! Something went wrong. " + - "Get in touch with the VersionEye guys and give them feedback. " + - "You find them on Twitter at https//twitter.com/VersionEye. ", exception); + "Get in touch with the VersionEye guys and give them feedback. " + + "You find them on Twitter at https//twitter.com/VersionEye. ", exception); } } @@ -39,13 +40,13 @@ protected void deleteProject() throws Exception { HttpUtils.delete(url); } - protected void deletePropertiesFile() throws Exception{ + protected void deletePropertiesFile() throws Exception { String propertiesPath = getPropertiesPath(); File file = new File(propertiesPath); file.delete(); } - protected void prettyPrintStart(){ + protected void prettyPrintStart() { getLog().info("."); getLog().info("Starting to delete this project from the VersionEye server. This can take a couple seconds ... "); getLog().info("."); diff --git a/src/main/java/com/versioneye/JsonMojo.java b/src/main/java/com/versioneye/JsonMojo.java index 010a33b..df7df81 100644 --- a/src/main/java/com/versioneye/JsonMojo.java +++ b/src/main/java/com/versioneye/JsonMojo.java @@ -1,11 +1,12 @@ package com.versioneye; -import com.versioneye.utils.JsonUtils; import org.apache.maven.plugin.MojoExecutionException; import org.apache.maven.plugin.MojoFailureException; import org.apache.maven.plugins.annotations.LifecyclePhase; import org.apache.maven.plugins.annotations.Mojo; +import com.versioneye.utils.JsonUtils; + import java.util.Map; /** @@ -25,8 +26,8 @@ public void execute() throws MojoExecutionException, MojoFailureException { prettyPrintEnd(filePath); } catch( Exception exception ){ throw new MojoExecutionException( "Oh no! Something went wrong. " + - "Get in touch with the VersionEye guys and give them feedback. " + - "You find them on Twitter at https//twitter.com/VersionEye. ", exception ); + "Get in touch with the VersionEye guys and give them feedback. " + + "You find them on Twitter at https//twitter.com/VersionEye. ", exception ); } } diff --git a/src/main/java/com/versioneye/LicenseCheckMojo.java b/src/main/java/com/versioneye/LicenseCheckMojo.java index 03c143c..443cd6a 100644 --- a/src/main/java/com/versioneye/LicenseCheckMojo.java +++ b/src/main/java/com/versioneye/LicenseCheckMojo.java @@ -1,17 +1,19 @@ package com.versioneye; -import com.versioneye.dto.ProjectJsonResponse; import org.apache.maven.plugin.MojoExecutionException; import org.apache.maven.plugin.MojoFailureException; import org.apache.maven.plugins.annotations.LifecyclePhase; import org.apache.maven.plugins.annotations.Mojo; +import com.versioneye.dto.ProjectJsonResponse; + import java.io.ByteArrayOutputStream; /** * Updates an existing project at VersionEye with the dependencies from the current project AND * ensures that all used licenses are on a whitelist. If that is not the case it breaks the build. */ +@SuppressWarnings("unused") @Mojo( name = "licenseCheck", defaultPhase = LifecyclePhase.VERIFY ) public class LicenseCheckMojo extends UpdateMojo { @@ -39,20 +41,20 @@ public void execute() throws MojoExecutionException, MojoFailureException { System.out.println(response.getLicenses_red()); if (response.getLicenses_red() > 0){ throw new MojoExecutionException("Some components violate the license whitelist! " + - "More details here: " + fetchBaseUrl() + "/user/projects/" + response.getId() ); + "More details here: " + fetchBaseUrl() + "/user/projects/" + response.getId() ); } if (response.getLicenses_unknown() > 0 && licenseCheckBreakByUnknown) { throw new MojoExecutionException("Some components are without any license! " + - "More details here: " + fetchBaseUrl() + "/user/projects/" + response.getId() ); + "More details here: " + fetchBaseUrl() + "/user/projects/" + response.getId() ); } prettyPrint( response ); } catch( Exception exception ){ exception.printStackTrace(); throw new MojoExecutionException("Oh no! Something went wrong. " + - "Get in touch with the VersionEye guys and give them feedback. " + - "You find them on Twitter at https//twitter.com/VersionEye. ", exception); + "Get in touch with the VersionEye guys and give them feedback. " + + "You find them on Twitter at https//twitter.com/VersionEye. ", exception); } } } diff --git a/src/main/java/com/versioneye/ListMojo.java b/src/main/java/com/versioneye/ListMojo.java index 3d98a5f..516bc66 100644 --- a/src/main/java/com/versioneye/ListMojo.java +++ b/src/main/java/com/versioneye/ListMojo.java @@ -1,6 +1,5 @@ package com.versioneye; -import com.versioneye.utils.DependencyUtils; import org.apache.maven.model.Dependency; import org.apache.maven.plugin.MojoExecutionException; import org.apache.maven.plugin.MojoFailureException; @@ -10,6 +9,8 @@ import org.eclipse.aether.graph.DependencyNode; import org.eclipse.aether.util.graph.visitor.PreorderNodeListGenerator; +import com.versioneye.utils.DependencyUtils; + import java.util.ArrayList; import java.util.List; @@ -21,8 +22,7 @@ public class ListMojo extends ProjectMojo { @Override - public void execute() throws MojoExecutionException, MojoFailureException - { + public void execute() throws MojoExecutionException, MojoFailureException { versionEyeOutput(); try{ @@ -41,19 +41,19 @@ public void execute() throws MojoExecutionException, MojoFailureException } } - private void produceNiceOutput(List directDependencies, List recursiveDependencies){ + private void produceNiceOutput(List directDependencies, List recursiveDependencies) { productNiceOutputForDirectDependencies(directDependencies); productNiceOutputForRecursiveDependencies(recursiveDependencies); produceNiceOutputSummary(directDependencies.size(), recursiveDependencies.size()); } - private void versionEyeOutput(){ + private void versionEyeOutput() { getLog().info(""); getLog().info("************* \\_/ VersionEye \\_/ *************"); getLog().info(""); } - private void productNiceOutputForDirectDependencies(List directDependencies){ + private void productNiceOutputForDirectDependencies(List directDependencies) { getLog().info(""); getLog().info(directDependencies.size() + " Direct Dependencies: "); getLog().info("--------------------"); @@ -65,7 +65,7 @@ private void productNiceOutputForDirectDependencies(List directDepen getLog().info(""); } - private void productNiceOutputForRecursiveDependencies(List recursiveDependencies){ + private void productNiceOutputForRecursiveDependencies(List recursiveDependencies) { getLog().info(""); getLog().info(recursiveDependencies.size() + " Transitive Dependencies: "); getLog().info("--------------------"); @@ -79,8 +79,8 @@ private void produceNiceOutputSummary(int directCount, int recursiveCount) { int allCount = directCount + recursiveCount; getLog().info(""); getLog().info(directCount + " Direct dependencies and " + - recursiveCount + " transitive dependencies. This project has " + - allCount + " dependencies."); + recursiveCount + " transitive dependencies. This project has " + + allCount + " dependencies."); getLog().info(""); getLog().info(""); } diff --git a/src/main/java/com/versioneye/PingMojo.java b/src/main/java/com/versioneye/PingMojo.java index 7f07c7b..4c9e238 100644 --- a/src/main/java/com/versioneye/PingMojo.java +++ b/src/main/java/com/versioneye/PingMojo.java @@ -5,13 +5,15 @@ import org.apache.maven.plugins.annotations.LifecyclePhase; import org.apache.maven.plugins.annotations.Mojo; -import javax.net.ssl.HttpsURLConnection; import java.io.BufferedReader; +import java.io.IOException; import java.io.InputStream; import java.io.InputStreamReader; import java.net.URL; import java.net.URLConnection; +import javax.net.ssl.HttpsURLConnection; + /** * Ping the VersionEye API. Expects a pong in response. */ @@ -35,12 +37,12 @@ public void execute() throws MojoExecutionException, MojoFailureException { input.close(); } catch (Exception ex){ throw new MojoExecutionException( "Oh no! The API or your internet connection seems to be down. " + - "Get in touch with the VersionEye guys and give them feedback. " + - "You find them on Twitter at https//twitter.com/VersionEye. ", ex ); + "Get in touch with the VersionEye guys and give them feedback. " + + "You find them on Twitter at https//twitter.com/VersionEye. ", ex ); } } - private InputStream getInputStream( String urlPath ) throws Exception { + private InputStream getInputStream( String urlPath ) throws IOException { URL url = new URL( urlPath ); if (urlPath.startsWith("https")){ System.out.println("https"); diff --git a/src/main/java/com/versioneye/ProjectMojo.java b/src/main/java/com/versioneye/ProjectMojo.java index b749bad..4083e41 100644 --- a/src/main/java/com/versioneye/ProjectMojo.java +++ b/src/main/java/com/versioneye/ProjectMojo.java @@ -1,13 +1,5 @@ package com.versioneye; -import com.versioneye.dto.ProjectDependency; -import com.versioneye.dto.ProjectJsonResponse; -import com.versioneye.utils.CollectionUtils; -import com.versioneye.utils.DependencyUtils; -import com.versioneye.utils.HttpUtils; -import com.versioneye.utils.JsonUtils; -import com.versioneye.utils.PropertiesUtils; - import org.apache.commons.lang3.StringUtils; import org.apache.maven.model.Dependency; import org.apache.maven.model.Plugin; @@ -23,27 +15,38 @@ import org.w3c.dom.Node; import org.w3c.dom.NodeList; -import javax.xml.parsers.DocumentBuilder; -import javax.xml.parsers.DocumentBuilderFactory; -import javax.xml.xpath.XPath; -import javax.xml.xpath.XPathConstants; -import javax.xml.xpath.XPathExpression; -import javax.xml.xpath.XPathFactory; +import com.versioneye.dto.ProjectDependency; +import com.versioneye.dto.ProjectJsonResponse; +import com.versioneye.utils.CollectionUtils; +import com.versioneye.utils.DependencyUtils; +import com.versioneye.utils.HttpUtils; +import com.versioneye.utils.JsonUtils; +import com.versioneye.utils.PropertiesUtils; + import java.io.ByteArrayOutputStream; import java.io.File; +import java.io.IOException; import java.io.Reader; import java.util.ArrayList; import java.util.List; import java.util.Map; import java.util.Properties; +import javax.xml.parsers.DocumentBuilder; +import javax.xml.parsers.DocumentBuilderFactory; +import javax.xml.xpath.XPath; +import javax.xml.xpath.XPathConstants; +import javax.xml.xpath.XPathExpression; +import javax.xml.xpath.XPathFactory; + /** * Methods required to deal with projects resource */ @SuppressWarnings({"WeakerAccess", "unused"}) public class ProjectMojo extends SuperMojo { - protected ByteArrayOutputStream getTransitiveDependenciesJsonStream(String nameStrategy) throws Exception { + protected ByteArrayOutputStream getTransitiveDependenciesJsonStream(String nameStrategy) throws Exception + { PreorderNodeListGenerator nlg = new PreorderNodeListGenerator(); DependencyNode root = getDependencyNode(nlg); List transDependencies = DependencyUtils.collectAllDependencies(nlg.getDependencies(true)); @@ -65,7 +68,8 @@ protected ByteArrayOutputStream getTransitiveDependenciesJsonStream(String nameS return jsonUtils.dependenciesToJson(project, dependencies, null, nameStrategy); } - protected ByteArrayOutputStream getDirectDependenciesJsonStream(String nameStrategy) throws Exception { + protected ByteArrayOutputStream getDirectDependenciesJsonStream(String nameStrategy) throws IOException + { List plugins = new ArrayList<>(); if (trackPlugins){ plugins = getPluginsFromXml(); @@ -84,7 +88,7 @@ protected ByteArrayOutputStream getDirectDependenciesJsonStream(String nameStrat return jsonUtils.dependenciesToJson(project, filteredDependencies, plugins, nameStrategy); } - protected Map getDirectDependenciesJsonMap(String nameStrategy) throws Exception { + protected Map getDirectDependenciesJsonMap(String nameStrategy) { List dependencies = project.getDependencies(); if (dependencies == null || dependencies.isEmpty()){ return null; @@ -96,7 +100,8 @@ protected Map getDirectDependenciesJsonMap(String nameStrategy) return jsonUtils.getJsonPom(project, dependencyHashes, nameStrategy); } - protected ByteArrayOutputStream getDirectArtifactsJsonStream() throws Exception { + protected ByteArrayOutputStream getDirectArtifactsJsonStream() throws Exception + { DependencyNode root = getDependencyNode(new PreorderNodeListGenerator()); List directDependencies = DependencyUtils.collectDirectDependencies(root.getChildren()); JsonUtils jsonUtils = new JsonUtils(); @@ -112,13 +117,13 @@ protected DependencyNode getDependencyNode(PreorderNodeListGenerator nlg) throws return root; } - protected void prettyPrint0End() throws Exception { + protected void prettyPrint0End() { getLog().info("."); getLog().info("There are no dependencies in this project! - " + project.getId() ); getLog().info("."); } - protected void prettyPrint(ProjectJsonResponse response) throws Exception { + protected void prettyPrint(ProjectJsonResponse response) throws IOException { getLog().info("."); getLog().info("Project name: " + response.getName()); getLog().info("Project id: " + response.getId()); @@ -174,7 +179,7 @@ protected void merge(String childId) { } } - protected void writeProperties(ProjectJsonResponse response) throws Exception { + protected void writeProperties(ProjectJsonResponse response) throws IOException { Properties properties = fetchProjectProperties(); if (response.getId() != null) { properties.setProperty("project_id", response.getId()); @@ -183,13 +188,13 @@ protected void writeProperties(ProjectJsonResponse response) throws Exception { utils.writeProperties(properties, getPropertiesPath()); } - private void iterateThrough(List dependencies){ + private void iterateThrough(List dependencies) { for(Dependency dep: dependencies){ getLog().info(" - dependency: " + dep.getGroupId() + "/" + dep.getArtifactId() + " " + dep.getVersion()); } } - private List getPluginsFromXml(){ + private List getPluginsFromXml() { List plugins = new ArrayList<>(); try { File pom = project.getModel().getPomFile(); @@ -236,7 +241,7 @@ private void fillPlugin(Node node, Plugin plugin){ } } - private String parseVersionString(String version){ + private String parseVersionString(String version) { String localVersion = version; @@ -247,7 +252,7 @@ private String parseVersionString(String version){ return localVersion; } - private List filterForScopes(List dependencies){ + private List filterForScopes(List dependencies) { if (StringUtils.isBlank(skipScopes) || CollectionUtils.collectionIsEmpty(dependencies)) return dependencies; @@ -272,8 +277,7 @@ private List filterForScopes(List dependencies){ } @Override - public void execute() throws MojoExecutionException, MojoFailureException - { + public void execute() throws MojoExecutionException, MojoFailureException { } } diff --git a/src/main/java/com/versioneye/SecurityAndLicenseCheckMojo.java b/src/main/java/com/versioneye/SecurityAndLicenseCheckMojo.java index 61a2145..7d21fa1 100644 --- a/src/main/java/com/versioneye/SecurityAndLicenseCheckMojo.java +++ b/src/main/java/com/versioneye/SecurityAndLicenseCheckMojo.java @@ -1,11 +1,12 @@ package com.versioneye; -import com.versioneye.dto.ProjectJsonResponse; import org.apache.maven.plugin.MojoExecutionException; import org.apache.maven.plugin.MojoFailureException; import org.apache.maven.plugins.annotations.LifecyclePhase; import org.apache.maven.plugins.annotations.Mojo; +import com.versioneye.dto.ProjectJsonResponse; + import java.io.ByteArrayOutputStream; @SuppressWarnings("unused") diff --git a/src/main/java/com/versioneye/SecurityCheckMojo.java b/src/main/java/com/versioneye/SecurityCheckMojo.java index 4e6b8d4..e971297 100644 --- a/src/main/java/com/versioneye/SecurityCheckMojo.java +++ b/src/main/java/com/versioneye/SecurityCheckMojo.java @@ -1,11 +1,12 @@ package com.versioneye; -import com.versioneye.dto.ProjectJsonResponse; import org.apache.maven.plugin.MojoExecutionException; import org.apache.maven.plugin.MojoFailureException; import org.apache.maven.plugins.annotations.LifecyclePhase; import org.apache.maven.plugins.annotations.Mojo; +import com.versioneye.dto.ProjectJsonResponse; + import java.io.ByteArrayOutputStream; @SuppressWarnings("unused") @@ -34,15 +35,15 @@ public void execute() throws MojoExecutionException, MojoFailureException { System.out.println("sv_count: " + response.getSv_count()); if (response.getSv_count() > 0){ throw new MojoExecutionException("Some components have security vulnerabilities! " + - "More details here: " + fetchBaseUrl() + "/user/projects/" + response.getId() ); + "More details here: " + fetchBaseUrl() + "/user/projects/" + response.getId() ); } prettyPrint( response ); } catch( Exception exception ){ exception.printStackTrace(); throw new MojoExecutionException("Oh no! Something went wrong. " + - "Get in touch with the VersionEye guys and give them feedback. " + - "You find them on Twitter at https//twitter.com/VersionEye. ", exception); + "Get in touch with the VersionEye guys and give them feedback. " + + "You find them on Twitter at https//twitter.com/VersionEye. ", exception); } } diff --git a/src/main/java/com/versioneye/SuperMojo.java b/src/main/java/com/versioneye/SuperMojo.java index cb93ccb..a636aa2 100644 --- a/src/main/java/com/versioneye/SuperMojo.java +++ b/src/main/java/com/versioneye/SuperMojo.java @@ -142,7 +142,7 @@ public abstract class SuperMojo extends AbstractMojo protected Properties properties = null; // Properties in src/main/resources protected Properties homeProperties = null; // Properties in ~/.m2/ - protected String fetchApiKey() throws Exception { + protected String fetchApiKey() throws IOException { if (StringUtils.isNotBlank(apiKey) ) return apiKey; @@ -168,14 +168,14 @@ protected String fetchApiKey() throws Exception { if (apiKey == null){ getLog().error("API Key can not be found!"); - throw new Exception("API Key can not be found!"); + throw new IllegalArgumentException("API Key can not be found!"); } return apiKey; } - protected String fetchBaseUrl() throws Exception { + protected String fetchBaseUrl() throws IOException { if (StringUtils.isNotBlank(baseUrl)) return baseUrl; @@ -203,7 +203,8 @@ protected String fetchBaseUrl() throws Exception { } - protected String fetchProjectId() throws Exception { + protected String fetchProjectId() throws IOException, MojoExecutionException + { if (StringUtils.isNotBlank(projectId) ) return projectId; @@ -240,7 +241,7 @@ protected String fetchProjectId() throws Exception { } - protected Properties fetchProjectProperties() throws Exception { + protected Properties fetchProjectProperties() throws IOException { if (properties != null) return properties; String localPropertiesPath = getPropertiesPath(); @@ -253,7 +254,7 @@ protected Properties fetchProjectProperties() throws Exception { return properties; } - protected String getPropertiesPath() throws Exception { + protected String getPropertiesPath() { if (this.propertiesPath != null && !this.propertiesPath.isEmpty()) return this.propertiesPath; @@ -270,8 +271,7 @@ protected String getPropertiesPath() throws Exception { } @SuppressWarnings("ResultOfMethodCallIgnored") - private void createPropertiesFile(File file) throws IOException - { + private void createPropertiesFile(File file) throws IOException { File parent = file.getParentFile(); if (!parent.exists()){ File grandpa = parent.getParentFile(); @@ -284,7 +284,7 @@ private void createPropertiesFile(File file) throws IOException file.createNewFile(); } - protected void initTls(){ + protected void initTls() { TrustManager[] trustAllCerts = new TrustManager[]{new X509TrustManager(){ @Override @@ -318,21 +318,21 @@ protected void setProxy() { } } - if (StringUtils.isNotBlank(proxyPort)) { + if (StringUtils.isBlank(proxyPort)) { String port = getPropertyFromPath(localPropertiesPath, "proxyPort"); if (StringUtils.isNotBlank(port)){ proxyPort = port; } } - if (StringUtils.isNotBlank(proxyUser)) { + if (StringUtils.isBlank(proxyUser)) { String user = getPropertyFromPath(localPropertiesPath, "proxyUser"); if (StringUtils.isNotBlank(user)){ proxyUser = user; } } - if (StringUtils.isNotBlank(proxyPassword)) { + if (StringUtils.isBlank(proxyPassword)) { String password = getPropertyFromPath(localPropertiesPath, "proxyPassword"); if (StringUtils.isNotBlank(password)) { proxyPassword = password; @@ -342,30 +342,31 @@ protected void setProxy() { ex.printStackTrace(); } - boolean emptyProxyHost = StringUtils.isBlank(proxyHost); - boolean emptyProxyPort = StringUtils.isBlank(proxyPort); + assignProxySystemProperties(); + } - if (emptyProxyHost && emptyProxyPort){ - return; - } + public void assignProxySystemProperties() { + boolean emptyProxyHost = StringUtils.isBlank(proxyHost); + boolean emptyProxyPort = StringUtils.isBlank(proxyPort); - System.setProperty("proxySet", "true"); - System.setProperty("http.proxyHost", proxyHost); - System.setProperty("http.proxyPort", proxyPort); - System.setProperty("https.proxyHost", proxyHost); - System.setProperty("https.proxyPort", proxyPort); + if (emptyProxyHost && emptyProxyPort){ + return; + } - boolean emptyProxyUser = StringUtils.isBlank(proxyUser); - boolean emptyProxyPass = StringUtils.isBlank(proxyPassword); + System.setProperty("proxySet", "true"); + System.setProperty("http.proxyHost", proxyHost); + System.setProperty("http.proxyPort", proxyPort); + System.setProperty("https.proxyHost", proxyHost); + System.setProperty("https.proxyPort", proxyPort); - if (emptyProxyUser && emptyProxyPass){ - return ; - } - System.getProperties().put("http.proxyUser", proxyUser); - System.getProperties().put("http.proxyPassword", proxyPassword); - } + if (StringUtils.isBlank(proxyUser)) + System.setProperty("http.proxyUser", proxyUser); - private String getPropertyFromPath(String propertiesPath, String propertiesKey ) throws Exception { + if (StringUtils.isBlank(proxyPassword)) + System.setProperty("http.proxyPassword", proxyPassword); + } + + private String getPropertyFromPath(String propertiesPath, String propertiesKey ) throws IOException { File file = new File(propertiesPath); if (file.exists()){ PropertiesUtils propertiesUtils = new PropertiesUtils(); @@ -374,6 +375,7 @@ private String getPropertyFromPath(String propertiesPath, String propertiesKey ) } else { getLog().debug("File " + propertiesPath + " does not exist"); } + return null; } } diff --git a/src/main/java/com/versioneye/UpdateMojo.java b/src/main/java/com/versioneye/UpdateMojo.java index 6f474d4..f70ca63 100644 --- a/src/main/java/com/versioneye/UpdateMojo.java +++ b/src/main/java/com/versioneye/UpdateMojo.java @@ -1,12 +1,13 @@ package com.versioneye; -import com.versioneye.dto.ProjectJsonResponse; import org.apache.maven.plugin.MojoExecutionException; import org.apache.maven.plugin.MojoFailureException; import org.apache.maven.plugins.annotations.LifecyclePhase; import org.apache.maven.plugins.annotations.Mojo; import org.apache.maven.plugins.annotations.Parameter; +import com.versioneye.dto.ProjectJsonResponse; + import java.io.ByteArrayOutputStream; /** diff --git a/src/main/java/com/versioneye/dto/ProjectJsonResponse.java b/src/main/java/com/versioneye/dto/ProjectJsonResponse.java index d0eddc5..a477b02 100644 --- a/src/main/java/com/versioneye/dto/ProjectJsonResponse.java +++ b/src/main/java/com/versioneye/dto/ProjectJsonResponse.java @@ -17,6 +17,8 @@ public class ProjectJsonResponse { private Integer licenses_unknown = 0; private Integer sv_count = 0; + private ProjectDependency[] dependencies; + public Integer getSv_count() { return sv_count; } @@ -25,8 +27,6 @@ public void setSv_count(Integer sv_count) { this.sv_count = sv_count; } - private ProjectDependency[] dependencies; - public Integer getLicenses_red() { return licenses_red; } diff --git a/src/main/java/com/versioneye/utils/CollectionUtils.java b/src/main/java/com/versioneye/utils/CollectionUtils.java index 81398a2..03293f0 100644 --- a/src/main/java/com/versioneye/utils/CollectionUtils.java +++ b/src/main/java/com/versioneye/utils/CollectionUtils.java @@ -8,13 +8,12 @@ @SuppressWarnings("WeakerAccess") public class CollectionUtils { - private CollectionUtils() { - - } + private CollectionUtils() {} public static boolean collectionIsEmpty(Collection collection) { return collection == null || collection.isEmpty(); } + public static boolean collectionNotEmpty(Collection collection) { return !collectionIsEmpty(collection); } diff --git a/src/main/java/com/versioneye/utils/DependencyUtils.java b/src/main/java/com/versioneye/utils/DependencyUtils.java index 105d209..440afef 100644 --- a/src/main/java/com/versioneye/utils/DependencyUtils.java +++ b/src/main/java/com/versioneye/utils/DependencyUtils.java @@ -8,37 +8,41 @@ import org.eclipse.aether.graph.DependencyNode; import org.eclipse.aether.repository.RemoteRepository; -import java.util.ArrayList; import java.util.List; +import java.util.stream.Collectors; /** * Utility methods for Maven Dependencies. */ public class DependencyUtils { + private DependencyUtils() {} + public static List collectAllDependencies(List dependencies) { - List result = new ArrayList(dependencies.size()); - for (Dependency dependency : dependencies) { - result.add(dependency.getArtifact()); - } - return result; + + List artifacts = dependencies.stream() + .map(Dependency::getArtifact) + .collect(Collectors.toList()); + + return artifacts; } public static List collectDirectDependencies(List dependencies) { - List result = new ArrayList(dependencies.size()); - for (DependencyNode dependencyNode : dependencies) { - result.add(dependencyNode.getDependency().getArtifact()); - } - return result; - } - public static CollectRequest getCollectRequest(MavenProject project, List repos){ - Artifact a = new DefaultArtifact( project.getArtifact().toString() ); - DefaultArtifact pom = new DefaultArtifact( a.getGroupId(), a.getArtifactId(), "pom", a.getVersion() ); - CollectRequest collectRequest = new CollectRequest(); - collectRequest.setRoot(new Dependency(pom, "compile")); - collectRequest.setRepositories(repos); - return collectRequest; + List artifacts = dependencies.stream() + .map(DependencyNode::getDependency) + .map(Dependency::getArtifact) + .collect(Collectors.toList()); + + return artifacts; } + public static CollectRequest getCollectRequest(MavenProject project, List repos) { + Artifact a = new DefaultArtifact( project.getArtifact().toString() ); + DefaultArtifact pom = new DefaultArtifact( a.getGroupId(), a.getArtifactId(), "pom", a.getVersion() ); + CollectRequest collectRequest = new CollectRequest(); + collectRequest.setRoot(new Dependency(pom, "compile")); + collectRequest.setRepositories(repos); + return collectRequest; + } } diff --git a/src/main/java/com/versioneye/utils/HttpUtils.java b/src/main/java/com/versioneye/utils/HttpUtils.java index 02a4e3f..b3b40d8 100644 --- a/src/main/java/com/versioneye/utils/HttpUtils.java +++ b/src/main/java/com/versioneye/utils/HttpUtils.java @@ -1,6 +1,5 @@ package com.versioneye.utils; -import com.versioneye.dto.ErrorJsonResponse; import org.apache.http.HttpResponse; import org.apache.http.client.HttpClient; import org.apache.http.client.methods.HttpPost; @@ -11,7 +10,10 @@ import org.codehaus.jackson.map.ObjectMapper; import org.codehaus.plexus.util.StringUtils; +import com.versioneye.dto.ErrorJsonResponse; + import java.io.BufferedReader; +import java.io.IOException; import java.io.InputStream; import java.io.InputStreamReader; import java.io.Reader; @@ -24,11 +26,11 @@ @SuppressWarnings("WeakerAccess") public class HttpUtils { - public static Integer ONE_SECOND = 1000; - public static Integer ONE_MINUTE = ONE_SECOND * 60; - public static Integer TEN_MINUTE = ONE_MINUTE * 10; + public static final Integer ONE_SECOND = 1000; + public static final Integer ONE_MINUTE = ONE_SECOND * 60; + public static final Integer TEN_MINUTE = ONE_MINUTE * 10; - public static String get(String url) throws Exception { + public static String get(String url) throws IOException { URL obj = new URL(url); HttpURLConnection con = (HttpURLConnection) obj.openConnection(); con.setRequestMethod("GET"); @@ -83,7 +85,7 @@ public static Reader post(String url, byte[] data, String dataName, String visib return new InputStreamReader(response.getEntity().getContent()); } - public static String delete(String url) throws Exception { + public static String delete(String url) throws IOException { URL obj = new URL(url); HttpURLConnection con = (HttpURLConnection) obj.openConnection(); con.setRequestMethod("GET"); @@ -106,7 +108,7 @@ public static String delete(String url) throws Exception { return response.toString(); } - private static String getErrorMessage(HttpResponse response) throws Exception { + private static String getErrorMessage(HttpResponse response) { String errorMsg = getErrorFromJson(response); if (errorMsg != null){ return errorMsg; @@ -114,7 +116,7 @@ private static String getErrorMessage(HttpResponse response) throws Exception { return getPureBodyString(response); } - private static String getErrorFromJson(HttpResponse response){ + private static String getErrorFromJson(HttpResponse response) { try { ObjectMapper mapper = new ObjectMapper(); ErrorJsonResponse error = mapper.readValue(response.getEntity().getContent(), ErrorJsonResponse.class); @@ -125,7 +127,7 @@ private static String getErrorFromJson(HttpResponse response){ } } - private static String getPureBodyString(HttpResponse response){ + private static String getPureBodyString(HttpResponse response) { try { InputStream content = response.getEntity().getContent(); BufferedReader in = new BufferedReader(new InputStreamReader( content ) ); diff --git a/src/main/java/com/versioneye/utils/JsonUtils.java b/src/main/java/com/versioneye/utils/JsonUtils.java index 0d82b25..b3dbcef 100644 --- a/src/main/java/com/versioneye/utils/JsonUtils.java +++ b/src/main/java/com/versioneye/utils/JsonUtils.java @@ -11,6 +11,7 @@ import java.io.ByteArrayOutputStream; import java.io.File; import java.io.FileOutputStream; +import java.io.IOException; import java.io.OutputStream; import java.util.ArrayList; import java.util.Collections; @@ -28,7 +29,8 @@ public class JsonUtils { private static final String NAME = "name"; private static final String SCOPE = "scope"; - public ByteArrayOutputStream dependenciesToJson(MavenProject project, List dependencies, List plugins, String nameStrategy) throws Exception { + public ByteArrayOutputStream dependenciesToJson(MavenProject project, List dependencies, List plugins, String nameStrategy) throws + IOException { List> dependencyHashes = new ArrayList<>(); if ((CollectionUtils.collectionNotEmpty(dependencies)) || (CollectionUtils.collectionNotEmpty(plugins))) { dependencyHashes = getDependencyHashes(dependencies, plugins); @@ -38,7 +40,7 @@ public ByteArrayOutputStream dependenciesToJson(MavenProject project, List directDependencies) throws Exception { + public ByteArrayOutputStream artifactsToJson(List directDependencies) throws IOException { List> hashes = getHashes(directDependencies); ByteArrayOutputStream outstream = new ByteArrayOutputStream(); toJson(outstream, hashes); @@ -46,31 +48,31 @@ public ByteArrayOutputStream artifactsToJson(List directDependencies) } @SuppressWarnings("UnusedParameters") - public void dependenciesToJsonFile(String name, Map directDependencies, String file) throws Exception { + public void dependenciesToJsonFile(String name, Map directDependencies, String file) throws IOException { File targetFile = getTargetFile(file); toJson(new FileOutputStream(targetFile), directDependencies); } @SuppressWarnings("unused") - public void dependenciesToJsonFile(MavenProject project, List directDependencies, String file, String nameStrategy) throws Exception { + public void dependenciesToJsonFile(MavenProject project, List directDependencies, String file, String nameStrategy) throws IOException { List> dependencyHashes = getHashes(directDependencies); File targetFile = getTargetFile(file); toJson(new FileOutputStream(targetFile), getJsonPom(project, dependencyHashes, nameStrategy)); } - public static void toJson(OutputStream output, Object input) throws Exception { + public static void toJson(OutputStream output, Object input) throws IOException { ObjectMapper mapper = new ObjectMapper(); mapper.configure(JsonParser.Feature.ALLOW_UNQUOTED_FIELD_NAMES, true); mapper.writeValue(output, input); } - public List> getHashes(List directDependencies){ + public List> getHashes(List directDependencies) { List> hashes = new ArrayList<>(directDependencies.size()); hashes.addAll( generateHashForJsonOutput( directDependencies)); return hashes; } - public List> getDependencyHashes(List directDependencies, List plugins){ + public List> getDependencyHashes(List directDependencies, List plugins) { List> hashes = new ArrayList<>(); @@ -102,6 +104,7 @@ public static List> generateHashFromDependencyList(List> output = new ArrayList<>(input.size()); + for (Dependency dependency : input) { Map map = new HashMap<>(2); map.put(VERSION, dependency.getVersion()); diff --git a/src/main/java/com/versioneye/utils/PropertiesUtils.java b/src/main/java/com/versioneye/utils/PropertiesUtils.java index b658e5a..6f4e5e1 100644 --- a/src/main/java/com/versioneye/utils/PropertiesUtils.java +++ b/src/main/java/com/versioneye/utils/PropertiesUtils.java @@ -1,6 +1,11 @@ package com.versioneye.utils; -import java.io.*; +import java.io.File; +import java.io.FileInputStream; +import java.io.FileOutputStream; +import java.io.IOException; +import java.io.InputStream; +import java.io.OutputStream; import java.util.Properties; /** @@ -8,15 +13,15 @@ */ public class PropertiesUtils { - public void writeProperties(Properties properties, String filePath) throws Exception{ + public void writeProperties(Properties properties, String filePath) throws IOException { File file = new File(filePath); OutputStream out = new FileOutputStream( file ); properties.store(out, " Properties for https://www.VersionEye.com"); } - public Properties readProperties(String filePath) throws Exception{ + public Properties readProperties(String filePath) throws IOException { Properties properties = new Properties(); - InputStream inputStream = null; + InputStream inputStream; File file = new File(filePath); inputStream = new FileInputStream( file ); properties.load(inputStream); From 9a156f51f9abed7ae6b9722f086849a2abeb8f44 Mon Sep 17 00:00:00 2001 From: andyglick Date: Fri, 10 Feb 2017 08:23:38 -0500 Subject: [PATCH 07/11] bumped httpcomponents and maven-dependency-plugin's versions --- pom.xml | 9 +++------ 1 file changed, 3 insertions(+), 6 deletions(-) diff --git a/pom.xml b/pom.xml index ff5ed23..cd1dab6 100644 --- a/pom.xml +++ b/pom.xml @@ -52,7 +52,7 @@ 2.0.15 - 4.5.2 + 4.5.3 1.9.13 1.8 ${java.version} @@ -207,7 +207,7 @@ org.codehaus.plexus plexus-component-annotations - 1.6 + 1.7.1 @@ -337,9 +337,6 @@ - - - org.sonatype.plugins nexus-staging-maven-plugin @@ -414,7 +411,7 @@ maven-dependency-plugin - 2.10 + 3.0.0 maven-help-plugin From 2a4c477fc272354c0ab4937addfd9ab5eb39b28f Mon Sep 17 00:00:00 2001 From: andyglick Date: Tue, 21 Feb 2017 22:11:41 -0500 Subject: [PATCH 08/11] bumped the version of slf4j artifacts from 1.7.22 to 1.7.23 by changing the value of the slf4j.version property --- pom.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pom.xml b/pom.xml index cd1dab6..99b74be 100644 --- a/pom.xml +++ b/pom.xml @@ -63,7 +63,7 @@ 3.0.24 UTF-8 UTF-8 - 1.7.22 + 1.7.23 2.19.1 From 98125b5bddc7fc9601f5ee6777c47de96b9ddc17 Mon Sep 17 00:00:00 2001 From: andyglick Date: Mon, 6 Mar 2017 11:25:12 -0500 Subject: [PATCH 09/11] used versions-mavwn-plugin to identify out of date property versions as well as direct dependency versions --- pom.xml | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/pom.xml b/pom.xml index 99b74be..57b7767 100644 --- a/pom.xml +++ b/pom.xml @@ -51,7 +51,7 @@ - 2.0.15 + 2.0.18 4.5.3 1.9.13 1.8 @@ -63,7 +63,7 @@ 3.0.24 UTF-8 UTF-8 - 1.7.23 + 1.7.24 2.19.1 @@ -278,7 +278,7 @@ org.testng testng - 6.10 + 6.11 test From afd910fd74fcff11c741e4608ba6427a3f617acb Mon Sep 17 00:00:00 2001 From: andyglick Date: Fri, 31 Mar 2017 02:05:30 -0400 Subject: [PATCH 10/11] bumped slf4j's version property --- pom.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pom.xml b/pom.xml index 15916b1..783f1e6 100644 --- a/pom.xml +++ b/pom.xml @@ -63,7 +63,7 @@ 3.0.24 UTF-8 UTF-8 - 1.7.24 + 1.7.25 2.19.1 From 6838bfa5c95d5a30b03827687782a4efde15a74e Mon Sep 17 00:00:00 2001 From: Andy Glick Date: Wed, 3 May 2017 07:50:25 -0400 Subject: [PATCH 11/11] bumped versions where they were out of date --- pom.xml | 13 ++++++------- 1 file changed, 6 insertions(+), 7 deletions(-) diff --git a/pom.xml b/pom.xml index b310e24..50961ec 100644 --- a/pom.xml +++ b/pom.xml @@ -2,11 +2,6 @@ xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> 4.0.0 - - - ${maven.version} - - com.versioneye versioneye-maven-plugin 3.11.2 @@ -50,6 +45,10 @@ + + ${maven.version} + + 2.0.18 4.5.3 @@ -64,7 +63,7 @@ UTF-8 UTF-8 1.7.25 - 2.19.1 + 2.20 @@ -198,7 +197,7 @@ org.apache.maven maven-artifact - 3.3.9 + ${maven.version} com.google.guava