├── src ├── site │ ├── .DS_Store │ └── images │ │ ├── VersionEyeLogo.png │ │ ├── VersionEyeApiKey.png │ │ ├── VersionEyeMavenPlugin.png │ │ └── VersionEyeDependencies.png ├── main │ ├── resources │ │ └── versioneye.properties │ └── java │ │ └── com │ │ └── versioneye │ │ ├── dto │ │ ├── ErrorJsonResponse.java │ │ ├── ProjectDependency.java │ │ └── ProjectJsonResponse.java │ │ ├── utils │ │ ├── ProxyAuthenticator.java │ │ ├── PropertiesUtils.java │ │ ├── DependencyUtils.java │ │ ├── JsonUtils.java │ │ └── HttpUtils.java │ │ ├── JsonMojo.java │ │ ├── DeleteMojo.java │ │ ├── SecurityCheckMojo.java │ │ ├── PingMojo.java │ │ ├── LicenseCheckMojo.java │ │ ├── SecurityAndLicenseCheckMojo.java │ │ ├── CreateMojo.java │ │ ├── UpdateMojo.java │ │ ├── ListMojo.java │ │ ├── ProjectMojo.java │ │ └── SuperMojo.java └── test │ └── java │ └── com │ └── versioneye │ └── utils │ └── HttpUtilsTest.java ├── .gitignore ├── pom.xml └── README.md /src/site/.DS_Store: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/versioneye/versioneye_maven_plugin/HEAD/src/site/.DS_Store -------------------------------------------------------------------------------- /src/site/images/VersionEyeLogo.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/versioneye/versioneye_maven_plugin/HEAD/src/site/images/VersionEyeLogo.png -------------------------------------------------------------------------------- /src/site/images/VersionEyeApiKey.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/versioneye/versioneye_maven_plugin/HEAD/src/site/images/VersionEyeApiKey.png -------------------------------------------------------------------------------- /src/site/images/VersionEyeMavenPlugin.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/versioneye/versioneye_maven_plugin/HEAD/src/site/images/VersionEyeMavenPlugin.png -------------------------------------------------------------------------------- /src/site/images/VersionEyeDependencies.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/versioneye/versioneye_maven_plugin/HEAD/src/site/images/VersionEyeDependencies.png -------------------------------------------------------------------------------- /src/main/resources/versioneye.properties: -------------------------------------------------------------------------------- 1 | # Properties for https://www.VersionEye.com 2 | #Thu May 25 15:14:18 CEST 2017 3 | project_id=5926d8a9368b08001261e989 4 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | *.rbc 2 | *.sassc 3 | .sass-cache 4 | .sass-cache/ 5 | capybara-*.html 6 | .rspec 7 | /.bundle 8 | /vendor/bundle 9 | /log/* 10 | /tmp/* 11 | /target 12 | /target/* 13 | /db/*.sqlite3 14 | /public/system/* 15 | /coverage/ 16 | .idea/ 17 | .env 18 | versioneye-maven-plugin.iml 19 | versioneye-maven-plugin.ipr 20 | versioneye-maven-plugin.iws 21 | .classpath 22 | .project 23 | .settings 24 | -------------------------------------------------------------------------------- /src/main/java/com/versioneye/dto/ErrorJsonResponse.java: -------------------------------------------------------------------------------- 1 | package com.versioneye.dto; 2 | 3 | 4 | import org.codehaus.jackson.annotate.JsonIgnoreProperties; 5 | 6 | @JsonIgnoreProperties(ignoreUnknown = true) 7 | public class ErrorJsonResponse { 8 | 9 | private String error; 10 | 11 | public String getError() { 12 | return error; 13 | } 14 | 15 | public void setError(String error) { 16 | this.error = error; 17 | } 18 | 19 | } 20 | -------------------------------------------------------------------------------- /src/main/java/com/versioneye/utils/ProxyAuthenticator.java: -------------------------------------------------------------------------------- 1 | package com.versioneye.utils; 2 | 3 | import java.net.Authenticator; 4 | import java.net.PasswordAuthentication; 5 | 6 | 7 | public class ProxyAuthenticator extends Authenticator { 8 | 9 | private String user, pass; 10 | 11 | public ProxyAuthenticator(String user, String pass){ 12 | this.user = user; 13 | this.pass = pass; 14 | } 15 | 16 | public PasswordAuthentication getPasswordAuthentication() { 17 | return (new PasswordAuthentication(user, pass.toCharArray())); 18 | } 19 | 20 | } 21 | -------------------------------------------------------------------------------- /src/main/java/com/versioneye/utils/PropertiesUtils.java: -------------------------------------------------------------------------------- 1 | package com.versioneye.utils; 2 | 3 | import java.io.*; 4 | import java.util.Properties; 5 | 6 | /** 7 | * Methods to deal with properties files. 8 | */ 9 | public class PropertiesUtils { 10 | 11 | public void writeProperties(Properties properties, String filePath) throws Exception{ 12 | File file = new File(filePath); 13 | OutputStream out = new FileOutputStream( file ); 14 | properties.store(out, " Properties for https://www.VersionEye.com"); 15 | } 16 | 17 | public Properties readProperties(String filePath) throws Exception{ 18 | Properties properties = new Properties(); 19 | InputStream inputStream = null; 20 | File file = new File(filePath); 21 | inputStream = new FileInputStream( file ); 22 | properties.load(inputStream); 23 | return properties; 24 | } 25 | 26 | } 27 | -------------------------------------------------------------------------------- /src/test/java/com/versioneye/utils/HttpUtilsTest.java: -------------------------------------------------------------------------------- 1 | package com.versioneye.utils; 2 | 3 | 4 | import org.codehaus.jackson.JsonParser; 5 | import org.codehaus.jackson.map.ObjectMapper; 6 | import org.testng.annotations.Test; 7 | 8 | import java.io.ByteArrayOutputStream; 9 | import java.util.HashMap; 10 | import java.util.List; 11 | import java.util.Map; 12 | import java.util.Vector; 13 | 14 | public class HttpUtilsTest { 15 | 16 | @Test(expectedExceptions = Exception.class) 17 | public void postTestData() throws Exception{ 18 | List> input = new Vector>(2); 19 | HashMap hash = new HashMap(2); 20 | hash.put("name", "junit"); 21 | hash.put("version", "4.0"); 22 | input.add(hash); 23 | 24 | ByteArrayOutputStream outstream = new ByteArrayOutputStream(); 25 | ObjectMapper mapper = new ObjectMapper(); 26 | mapper.configure(JsonParser.Feature.ALLOW_UNQUOTED_FIELD_NAMES, true); 27 | mapper.writeValue(outstream, input); 28 | 29 | String url = "http://localhost:3000/api/v2/projects/1_54d11ffa6c13297974000002?api_key=f511fb2"; 30 | HttpUtils.post(url, outstream.toByteArray(), "project_file", null, null, null, null); 31 | } 32 | 33 | } 34 | -------------------------------------------------------------------------------- /src/main/java/com/versioneye/JsonMojo.java: -------------------------------------------------------------------------------- 1 | package com.versioneye; 2 | 3 | import com.versioneye.utils.JsonUtils; 4 | import org.apache.maven.plugin.MojoExecutionException; 5 | import org.apache.maven.plugin.MojoFailureException; 6 | import org.apache.maven.plugins.annotations.LifecyclePhase; 7 | import org.apache.maven.plugins.annotations.Mojo; 8 | 9 | import java.util.Map; 10 | 11 | /** 12 | * Writes all direct dependencies into a JSON file. 13 | */ 14 | @Mojo( name = "json", defaultPhase = LifecyclePhase.PROCESS_SOURCES ) 15 | public class JsonMojo extends ProjectMojo { 16 | 17 | public void execute() throws MojoExecutionException, MojoFailureException { 18 | try{ 19 | Map jsonMap = getDirectDependenciesJsonMap(nameStrategy); 20 | JsonUtils jsonUtils = new JsonUtils(); 21 | String filePath = outputDirectory + "/pom.json"; 22 | jsonUtils.dependenciesToJsonFile(project.getName(), jsonMap, filePath); 23 | prettyPrintEnd(filePath); 24 | } catch( Exception exception ){ 25 | throw new MojoExecutionException( "Oh no! Something went wrong. " + 26 | "Get in touch with the VersionEye guys and give them feedback. " + 27 | "You find them on Twitter at https//twitter.com/VersionEye. ", exception ); 28 | } 29 | } 30 | 31 | private void prettyPrintEnd(String pathToJson){ 32 | getLog().info(""); 33 | getLog().info("You find your json file here: " + pathToJson); 34 | getLog().info(""); 35 | } 36 | 37 | } 38 | -------------------------------------------------------------------------------- /src/main/java/com/versioneye/utils/DependencyUtils.java: -------------------------------------------------------------------------------- 1 | package com.versioneye.utils; 2 | 3 | import org.apache.maven.project.MavenProject; 4 | import org.eclipse.aether.artifact.Artifact; 5 | import org.eclipse.aether.artifact.DefaultArtifact; 6 | import org.eclipse.aether.collection.CollectRequest; 7 | import org.eclipse.aether.graph.Dependency; 8 | import org.eclipse.aether.graph.DependencyNode; 9 | import org.eclipse.aether.repository.RemoteRepository; 10 | 11 | import java.util.ArrayList; 12 | import java.util.List; 13 | 14 | /** 15 | * Utility methods for Maven Dependencies. 16 | */ 17 | public class DependencyUtils { 18 | 19 | public static List collectAllDependencies(List dependencies) { 20 | List result = new ArrayList(dependencies.size()); 21 | for (Dependency dependency : dependencies) { 22 | result.add(dependency.getArtifact()); 23 | } 24 | return result; 25 | } 26 | 27 | public static List collectDirectDependencies(List dependencies) { 28 | List result = new ArrayList(dependencies.size()); 29 | for (DependencyNode dependencyNode : dependencies) { 30 | result.add(dependencyNode.getDependency().getArtifact()); 31 | } 32 | return result; 33 | } 34 | 35 | public static CollectRequest getCollectRequest(MavenProject project, List repos, String scope){ 36 | Artifact a = new DefaultArtifact( project.getArtifact().toString() ); 37 | DefaultArtifact pom = new DefaultArtifact( a.getGroupId(), a.getArtifactId(), "pom", a.getVersion() ); 38 | CollectRequest collectRequest = new CollectRequest(); 39 | collectRequest.setRoot(new Dependency(pom, scope )); 40 | collectRequest.setRepositories(repos); 41 | return collectRequest; 42 | } 43 | 44 | } 45 | -------------------------------------------------------------------------------- /src/main/java/com/versioneye/DeleteMojo.java: -------------------------------------------------------------------------------- 1 | package com.versioneye; 2 | 3 | 4 | import com.versioneye.utils.HttpUtils; 5 | import org.apache.maven.plugin.MojoExecutionException; 6 | import org.apache.maven.plugin.MojoFailureException; 7 | import org.apache.maven.plugins.annotations.LifecyclePhase; 8 | import org.apache.maven.plugins.annotations.Mojo; 9 | import org.apache.maven.plugins.annotations.Parameter; 10 | 11 | import java.io.File; 12 | 13 | @Mojo( name = "delete", defaultPhase = LifecyclePhase.PROCESS_SOURCES ) 14 | public class DeleteMojo extends ProjectMojo { 15 | 16 | @Parameter( property = "resource", defaultValue = "/projects") 17 | private String resource; 18 | 19 | public void execute() throws MojoExecutionException, MojoFailureException { 20 | try{ 21 | setProxy(); 22 | prettyPrintStart(); 23 | deleteProject(); 24 | deletePropertiesFile(); 25 | } catch( Exception exception ){ 26 | exception.printStackTrace(); 27 | throw new MojoExecutionException("Oh no! Something went wrong. " + 28 | "Get in touch with the VersionEye guys and give them feedback. " + 29 | "You find them on Twitter at https//twitter.com/VersionEye. ", exception); 30 | } 31 | } 32 | 33 | protected void deleteProject() throws Exception { 34 | String apiKey = fetchApiKey(); 35 | String projectId = fetchProjectId(); 36 | String url = fetchBaseUrl() + apiPath + resource + "/" + projectId + "?api_key=" + apiKey; 37 | 38 | HttpUtils.delete(url); 39 | } 40 | 41 | protected void deletePropertiesFile() throws Exception{ 42 | String propertiesPath = getPropertiesPath(); 43 | File file = new File(propertiesPath); 44 | file.delete(); 45 | } 46 | 47 | protected void prettyPrintStart(){ 48 | getLog().info("."); 49 | getLog().info("Starting to delete this project from the VersionEye server. This can take a couple seconds ... "); 50 | getLog().info("."); 51 | } 52 | } 53 | -------------------------------------------------------------------------------- /src/main/java/com/versioneye/SecurityCheckMojo.java: -------------------------------------------------------------------------------- 1 | package com.versioneye; 2 | 3 | import com.versioneye.dto.ProjectJsonResponse; 4 | import org.apache.maven.plugin.MojoExecutionException; 5 | import org.apache.maven.plugin.MojoFailureException; 6 | import org.apache.maven.plugins.annotations.LifecyclePhase; 7 | import org.apache.maven.plugins.annotations.Mojo; 8 | 9 | import java.io.ByteArrayOutputStream; 10 | 11 | @Mojo( name = "securityCheck", defaultPhase = LifecyclePhase.VERIFY ) 12 | public class SecurityCheckMojo extends UpdateMojo { 13 | 14 | public void execute() throws MojoExecutionException, MojoFailureException { 15 | try{ 16 | setProxy(); 17 | prettyPrintStart(); 18 | 19 | ByteArrayOutputStream jsonDependenciesStream = null; 20 | if (transitiveDependencies == true){ 21 | jsonDependenciesStream = getTransitiveDependenciesJsonStream(nameStrategy); 22 | } else { 23 | jsonDependenciesStream = getDirectDependenciesJsonStream(nameStrategy); 24 | } 25 | 26 | if (jsonDependenciesStream == null){ 27 | prettyPrint0End(); 28 | return ; 29 | } 30 | 31 | ProjectJsonResponse response = uploadDependencies(jsonDependenciesStream); 32 | System.out.println("sv_count: " + response.getSv_count()); 33 | if (response.getSv_count() > 0){ 34 | throw new MojoExecutionException("Some components have security vulnerabilities! " + 35 | "More details here: " + fetchBaseUrl() + "/user/projects/" + response.getId() ); 36 | } 37 | 38 | prettyPrint( response ); 39 | } catch( Exception exception ){ 40 | exception.printStackTrace(); 41 | throw new MojoExecutionException("Oh no! Something went wrong. " + 42 | "Get in touch with the VersionEye guys and give them feedback. " + 43 | "You find them on Twitter at https//twitter.com/VersionEye. ", exception); 44 | } 45 | } 46 | 47 | } 48 | -------------------------------------------------------------------------------- /src/main/java/com/versioneye/dto/ProjectDependency.java: -------------------------------------------------------------------------------- 1 | package com.versioneye.dto; 2 | 3 | 4 | import org.codehaus.jackson.annotate.JsonIgnoreProperties; 5 | 6 | @JsonIgnoreProperties(ignoreUnknown = true) 7 | public class ProjectDependency { 8 | 9 | private String name; 10 | private String prod_key; 11 | private String group_id; 12 | private String artifact_id; 13 | private String language; 14 | private String version_current; 15 | private String version_requested; 16 | private Boolean outdated; 17 | 18 | public String getName() { 19 | return name; 20 | } 21 | 22 | public void setName(String name) { 23 | this.name = name; 24 | } 25 | 26 | public String getLanguage() { 27 | return language; 28 | } 29 | 30 | public void setLanguage(String language) { 31 | this.language = language; 32 | } 33 | 34 | public Boolean getOutdated() { 35 | return outdated; 36 | } 37 | 38 | public void setOutdated(Boolean outdated) { 39 | this.outdated = outdated; 40 | } 41 | 42 | public String getProd_key() { 43 | return prod_key; 44 | } 45 | 46 | public void setProd_key(String prod_key) { 47 | this.prod_key = prod_key; 48 | } 49 | 50 | public String getGroup_id() { 51 | return group_id; 52 | } 53 | 54 | public void setGroup_id(String group_id) { 55 | this.group_id = group_id; 56 | } 57 | 58 | public String getArtifact_id() { 59 | return artifact_id; 60 | } 61 | 62 | public void setArtifact_id(String artifact_id) { 63 | this.artifact_id = artifact_id; 64 | } 65 | 66 | public String getVersion_current() { 67 | return version_current; 68 | } 69 | 70 | public void setVersion_current(String version_current) { 71 | this.version_current = version_current; 72 | } 73 | 74 | public String getVersion_requested() { 75 | return version_requested; 76 | } 77 | 78 | public void setVersion_requested(String version_requested) { 79 | this.version_requested = version_requested; 80 | } 81 | } 82 | -------------------------------------------------------------------------------- /src/main/java/com/versioneye/PingMojo.java: -------------------------------------------------------------------------------- 1 | package com.versioneye; 2 | 3 | import org.apache.maven.plugin.MojoExecutionException; 4 | import org.apache.maven.plugin.MojoFailureException; 5 | import org.apache.maven.plugins.annotations.LifecyclePhase; 6 | import org.apache.maven.plugins.annotations.Mojo; 7 | 8 | import javax.net.ssl.HttpsURLConnection; 9 | import java.io.BufferedReader; 10 | import java.io.InputStream; 11 | import java.io.InputStreamReader; 12 | import java.net.URL; 13 | import java.net.URLConnection; 14 | 15 | /** 16 | * Ping the VersionEye API. Expects a pong in response. 17 | */ 18 | @Mojo( name = "ping", defaultPhase = LifecyclePhase.PROCESS_SOURCES ) 19 | public class PingMojo extends SuperMojo { 20 | 21 | public void execute() throws MojoExecutionException, MojoFailureException { 22 | try{ 23 | setProxy(); 24 | initTls(); 25 | InputStream inputStream = getInputStream(fetchBaseUrl() + apiPath + "/services/ping"); 26 | BufferedReader input = new BufferedReader( new InputStreamReader( inputStream ) ); 27 | String line = ""; 28 | getLog().info(""); 29 | while((line = input.readLine())!=null){ 30 | getLog().info(line); 31 | } 32 | getLog().info(""); 33 | input.close(); 34 | } catch (Exception ex){ 35 | throw new MojoExecutionException( "Oh no! The API or your internet connection seems to be down. " + 36 | "Get in touch with the VersionEye guys and give them feedback. " + 37 | "You find them on Twitter at https//twitter.com/VersionEye. ", ex ); 38 | } 39 | } 40 | 41 | private InputStream getInputStream( String urlPath ) throws Exception { 42 | URL url = new URL( urlPath ); 43 | if (urlPath.startsWith("https")){ 44 | System.out.println("https"); 45 | HttpsURLConnection con = (HttpsURLConnection) url.openConnection(); 46 | return con.getInputStream(); 47 | } else { 48 | System.out.println("http"); 49 | URLConnection urlConnection = url.openConnection(); 50 | return urlConnection.getInputStream(); 51 | } 52 | } 53 | 54 | } 55 | -------------------------------------------------------------------------------- /src/main/java/com/versioneye/LicenseCheckMojo.java: -------------------------------------------------------------------------------- 1 | package com.versioneye; 2 | 3 | import com.versioneye.dto.ProjectJsonResponse; 4 | import org.apache.maven.plugin.MojoExecutionException; 5 | import org.apache.maven.plugin.MojoFailureException; 6 | import org.apache.maven.plugins.annotations.LifecyclePhase; 7 | import org.apache.maven.plugins.annotations.Mojo; 8 | 9 | import java.io.ByteArrayOutputStream; 10 | 11 | /** 12 | * Updates an existing project at VersionEye with the dependencies from the current project AND 13 | * ensures that all used licenses are on a whitelist. If that is not the case it breaks the build. 14 | */ 15 | @Mojo( name = "licenseCheck", defaultPhase = LifecyclePhase.VERIFY ) 16 | public class LicenseCheckMojo extends UpdateMojo { 17 | 18 | public void execute() throws MojoExecutionException, MojoFailureException { 19 | try{ 20 | setProxy(); 21 | prettyPrintStart(); 22 | 23 | ByteArrayOutputStream jsonDependenciesStream = null; 24 | if (transitiveDependencies == true){ 25 | jsonDependenciesStream = getTransitiveDependenciesJsonStream(nameStrategy); 26 | } else { 27 | jsonDependenciesStream = getDirectDependenciesJsonStream(nameStrategy); 28 | } 29 | 30 | if (jsonDependenciesStream == null){ 31 | prettyPrint0End(); 32 | return ; 33 | } 34 | 35 | ProjectJsonResponse response = uploadDependencies(jsonDependenciesStream); 36 | System.out.println(response.getLicenses_red()); 37 | if (response.getLicenses_red() > 0){ 38 | throw new MojoExecutionException("Some components violate the license whitelist! " + 39 | "More details here: " + fetchBaseUrl() + "/user/projects/" + response.getId() ); 40 | } 41 | 42 | if (response.getLicenses_unknown() > 0 && licenseCheckBreakByUnknown == true ){ 43 | throw new MojoExecutionException("Some components are without any license! " + 44 | "More details here: " + fetchBaseUrl() + "/user/projects/" + response.getId() ); 45 | } 46 | 47 | prettyPrint( response ); 48 | } catch( Exception exception ){ 49 | exception.printStackTrace(); 50 | throw new MojoExecutionException("Oh no! Something went wrong. " + 51 | "Get in touch with the VersionEye guys and give them feedback. " + 52 | "You find them on Twitter at https//twitter.com/VersionEye. ", exception); 53 | } 54 | } 55 | 56 | } 57 | -------------------------------------------------------------------------------- /src/main/java/com/versioneye/dto/ProjectJsonResponse.java: -------------------------------------------------------------------------------- 1 | package com.versioneye.dto; 2 | 3 | import org.codehaus.jackson.annotate.JsonIgnoreProperties; 4 | 5 | /** 6 | * Java representation of the project JSON response from VersionEye API. 7 | */ 8 | @JsonIgnoreProperties(ignoreUnknown = true) 9 | public class ProjectJsonResponse { 10 | 11 | private String name; 12 | private String group_id; 13 | private String artifact_id; 14 | private String id; 15 | private Integer dep_number; 16 | private Integer out_number; 17 | private Integer licenses_red = 0; 18 | private Integer licenses_unknown = 0; 19 | private Integer sv_count = 0; 20 | 21 | public String getGroup_id() { 22 | return group_id; 23 | } 24 | 25 | public void setGroup_id(String group_id) { 26 | this.group_id = group_id; 27 | } 28 | 29 | public String getArtifact_id() { 30 | return artifact_id; 31 | } 32 | 33 | public void setArtifact_id(String artifact_id) { 34 | this.artifact_id = artifact_id; 35 | } 36 | 37 | public Integer getSv_count() { 38 | return sv_count; 39 | } 40 | 41 | public void setSv_count(Integer sv_count) { 42 | this.sv_count = sv_count; 43 | } 44 | 45 | private ProjectDependency[] dependencies; 46 | 47 | public Integer getLicenses_red() { 48 | return licenses_red; 49 | } 50 | 51 | public void setLicenses_red(Integer licenses_red) { 52 | this.licenses_red = licenses_red; 53 | } 54 | 55 | public Integer getLicenses_unknown() { 56 | return licenses_unknown; 57 | } 58 | 59 | public void setLicenses_unknown(Integer licenses_unknown) { 60 | this.licenses_unknown = licenses_unknown; 61 | } 62 | 63 | public String getName() { 64 | return name; 65 | } 66 | 67 | public void setName(String name) { 68 | this.name = name; 69 | } 70 | 71 | public String getId() { 72 | return id; 73 | } 74 | 75 | public void setId(String id) { 76 | this.id = id; 77 | } 78 | 79 | public Integer getDep_number() { 80 | return dep_number; 81 | } 82 | 83 | public void setDep_number(Integer dep_number) { 84 | this.dep_number = dep_number; 85 | } 86 | 87 | public Integer getOut_number() { 88 | return out_number; 89 | } 90 | 91 | public void setOut_number(Integer out_number) { 92 | this.out_number = out_number; 93 | } 94 | 95 | public ProjectDependency[] getDependencies() { 96 | return dependencies; 97 | } 98 | 99 | public void setDependencies(ProjectDependency[] dependencies) { 100 | this.dependencies = dependencies; 101 | } 102 | } 103 | -------------------------------------------------------------------------------- /src/main/java/com/versioneye/SecurityAndLicenseCheckMojo.java: -------------------------------------------------------------------------------- 1 | package com.versioneye; 2 | 3 | import com.versioneye.dto.ProjectJsonResponse; 4 | import org.apache.maven.plugin.MojoExecutionException; 5 | import org.apache.maven.plugin.MojoFailureException; 6 | import org.apache.maven.plugins.annotations.LifecyclePhase; 7 | import org.apache.maven.plugins.annotations.Mojo; 8 | 9 | import java.io.ByteArrayOutputStream; 10 | 11 | @Mojo( name = "securityAndLicenseCheck", defaultPhase = LifecyclePhase.VERIFY ) 12 | public class SecurityAndLicenseCheckMojo extends UpdateMojo { 13 | 14 | public void execute() throws MojoExecutionException, MojoFailureException { 15 | try{ 16 | setProxy(); 17 | prettyPrintStart(); 18 | 19 | ByteArrayOutputStream jsonDependenciesStream = null; 20 | if (transitiveDependencies == true){ 21 | jsonDependenciesStream = getTransitiveDependenciesJsonStream(nameStrategy); 22 | } else { 23 | jsonDependenciesStream = getDirectDependenciesJsonStream(nameStrategy); 24 | } 25 | 26 | if (jsonDependenciesStream == null){ 27 | prettyPrint0End(); 28 | return ; 29 | } 30 | 31 | ProjectJsonResponse response = uploadDependencies(jsonDependenciesStream); 32 | System.out.println("sv_count: " + response.getSv_count()); 33 | if (response.getSv_count() > 0){ 34 | throw new MojoExecutionException("Some components have security vulnerabilities! " + 35 | "More details here: " + fetchBaseUrl() + "/user/projects/" + response.getId() ); 36 | } 37 | 38 | System.out.println("licenses_red: " + response.getLicenses_red()); 39 | 40 | if (response.getLicenses_red() > 0){ 41 | throw new MojoExecutionException("Some components violate the license whitelist! " + 42 | "More details here: " + fetchBaseUrl() + "/user/projects/" + response.getId() ); 43 | } 44 | 45 | if (response.getLicenses_unknown() > 0 && licenseCheckBreakByUnknown == true ){ 46 | throw new MojoExecutionException("Some components are without any license! " + 47 | "More details here: " + fetchBaseUrl() + "/user/projects/" + response.getId() ); 48 | } 49 | 50 | prettyPrint( response ); 51 | } catch( Exception exception ){ 52 | exception.printStackTrace(); 53 | throw new MojoExecutionException("Oh no! Something went wrong. " + 54 | "Get in touch with the VersionEye guys and give them feedback. " + 55 | "You find them on Twitter at https//twitter.com/VersionEye. ", exception); 56 | } 57 | } 58 | 59 | } 60 | -------------------------------------------------------------------------------- /src/main/java/com/versioneye/CreateMojo.java: -------------------------------------------------------------------------------- 1 | package com.versioneye; 2 | 3 | import com.versioneye.dto.ProjectJsonResponse; 4 | import com.versioneye.utils.HttpUtils; 5 | import com.versioneye.utils.PropertiesUtils; 6 | import org.apache.maven.plugin.MojoExecutionException; 7 | import org.apache.maven.plugin.MojoFailureException; 8 | import org.apache.maven.plugins.annotations.LifecyclePhase; 9 | import org.apache.maven.plugins.annotations.Mojo; 10 | import org.apache.maven.plugins.annotations.Parameter; 11 | import org.apache.maven.project.MavenProject; 12 | import org.codehaus.jackson.map.ObjectMapper; 13 | 14 | import java.io.ByteArrayOutputStream; 15 | import java.io.Reader; 16 | import java.util.Properties; 17 | 18 | /** 19 | * Creates a project at VersionEye based on the dependencies from the current project. 20 | */ 21 | @Mojo( name = "create", defaultPhase = LifecyclePhase.PROCESS_SOURCES ) 22 | public class CreateMojo extends ProjectMojo { 23 | 24 | @Parameter( property = "resource", defaultValue = "/projects?api_key=") 25 | private String resource; 26 | 27 | 28 | public void execute() throws MojoExecutionException, MojoFailureException { 29 | try{ 30 | setProxy(); 31 | prettyPrintStart(); 32 | 33 | ByteArrayOutputStream jsonDependenciesStream = null; 34 | if (transitiveDependencies == true){ 35 | jsonDependenciesStream = getTransitiveDependenciesJsonStream(nameStrategy); 36 | } else { 37 | jsonDependenciesStream = getDirectDependenciesJsonStream(nameStrategy); 38 | } 39 | 40 | if (jsonDependenciesStream == null){ 41 | prettyPrint0End(); 42 | return ; 43 | } 44 | 45 | ProjectJsonResponse response = uploadDependencies(jsonDependenciesStream); 46 | 47 | if (mavenSession.getTopLevelProject().getId().equals(mavenSession.getCurrentProject().getId())){ 48 | mavenSession.getTopLevelProject().setContextValue("veye_project_id", response.getId()); 49 | } 50 | 51 | merge( response.getId() ); 52 | if (updatePropertiesAfterCreate) { 53 | writeProperties( response ); 54 | } 55 | prettyPrint(response); 56 | } catch( Exception exception ){ 57 | throw new MojoExecutionException("Oh no! Something went wrong :-( " + 58 | "Get in touch with the VersionEye guys and give them feedback." + 59 | "You find them on Twitter at https//twitter.com/VersionEye. ", exception); 60 | } 61 | } 62 | 63 | 64 | private ProjectJsonResponse uploadDependencies(ByteArrayOutputStream outStream) throws Exception { 65 | return createNewProject(resource, outStream); 66 | } 67 | 68 | 69 | private void prettyPrintStart(){ 70 | getLog().info("."); 71 | getLog().info("Starting to upload dependencies. This can take a couple seconds ... "); 72 | getLog().info("."); 73 | } 74 | 75 | 76 | } 77 | -------------------------------------------------------------------------------- /src/main/java/com/versioneye/UpdateMojo.java: -------------------------------------------------------------------------------- 1 | package com.versioneye; 2 | 3 | import com.versioneye.dto.ProjectJsonResponse; 4 | import org.apache.maven.plugin.MojoExecutionException; 5 | import org.apache.maven.plugin.MojoFailureException; 6 | import org.apache.maven.plugins.annotations.LifecyclePhase; 7 | import org.apache.maven.plugins.annotations.Mojo; 8 | import org.apache.maven.plugins.annotations.Parameter; 9 | 10 | import java.io.ByteArrayOutputStream; 11 | 12 | /** 13 | * Updates an existing project at VersionEye with the dependencies from the current project. 14 | */ 15 | @Mojo( name = "update", defaultPhase = LifecyclePhase.PACKAGE ) 16 | public class UpdateMojo extends ProjectMojo { 17 | 18 | @Parameter( property = "resource", defaultValue = "/projects") 19 | private String resource; 20 | 21 | 22 | public void execute() throws MojoExecutionException, MojoFailureException { 23 | try{ 24 | setProxy(); 25 | prettyPrintStart(); 26 | 27 | ByteArrayOutputStream jsonDependenciesStream = null; 28 | if (transitiveDependencies == true){ 29 | jsonDependenciesStream = getTransitiveDependenciesJsonStream(nameStrategy); 30 | } else { 31 | jsonDependenciesStream = getDirectDependenciesJsonStream(nameStrategy); 32 | } 33 | 34 | if (jsonDependenciesStream == null){ 35 | prettyPrint0End(); 36 | return ; 37 | } 38 | 39 | ProjectJsonResponse response = uploadDependencies(jsonDependenciesStream); 40 | prettyPrint( response ); 41 | } catch( Exception exception ){ 42 | exception.printStackTrace(); 43 | throw new MojoExecutionException("Oh no! Something went wrong. " + 44 | "Get in touch with the VersionEye guys and give them feedback. " + 45 | "You find them on Twitter at https//twitter.com/VersionEye. ", exception); 46 | } 47 | } 48 | 49 | 50 | protected ProjectJsonResponse uploadDependencies(ByteArrayOutputStream outStream) throws Exception { 51 | try { 52 | String projectId = fetchProjectId(); 53 | if (mavenSession.getTopLevelProject().getId().equals(mavenSession.getCurrentProject().getId())){ 54 | mavenSession.getTopLevelProject().setContextValue("veye_project_id", projectId); 55 | } 56 | return updateExistingProject(resource, projectId, outStream); 57 | } catch (Exception ex) { 58 | getLog().error("Error in UpdateMojo.uploadDependencies " + ex.getMessage()); 59 | ProjectJsonResponse response = createNewProject("/projects?api_key=", outStream); 60 | if (updatePropertiesAfterCreate) { 61 | writeProperties( response ); 62 | } 63 | merge( response.getId() ); 64 | return response; 65 | } 66 | } 67 | 68 | 69 | protected void prettyPrintStart(){ 70 | getLog().info("."); 71 | getLog().info("Starting to update dependencies to server. This can take a couple seconds ... "); 72 | getLog().info("."); 73 | } 74 | 75 | 76 | } 77 | -------------------------------------------------------------------------------- /src/main/java/com/versioneye/ListMojo.java: -------------------------------------------------------------------------------- 1 | package com.versioneye; 2 | 3 | import com.versioneye.utils.DependencyUtils; 4 | import org.apache.maven.model.Dependency; 5 | import org.apache.maven.plugin.MojoExecutionException; 6 | import org.apache.maven.plugins.annotations.LifecyclePhase; 7 | import org.apache.maven.plugins.annotations.Mojo; 8 | import org.eclipse.aether.artifact.Artifact; 9 | import org.eclipse.aether.graph.DependencyNode; 10 | import org.eclipse.aether.util.graph.visitor.PreorderNodeListGenerator; 11 | 12 | import java.util.ArrayList; 13 | import java.util.List; 14 | 15 | /** 16 | * Lists all direct and recursive dependencies. 17 | */ 18 | @Mojo( name = "list", defaultPhase = LifecyclePhase.PROCESS_SOURCES ) 19 | public class ListMojo extends ProjectMojo { 20 | 21 | public void execute() throws MojoExecutionException { 22 | versionEyeOutput(); 23 | try{ 24 | PreorderNodeListGenerator nlg = new PreorderNodeListGenerator(); 25 | DependencyNode root = getDependencyNode(nlg); 26 | List dependencies = DependencyUtils.collectAllDependencies(nlg.getDependencies(true)); 27 | List directDependencies = DependencyUtils.collectDirectDependencies(root.getChildren()); 28 | List recursiveDependencies = new ArrayList(dependencies); 29 | recursiveDependencies.removeAll(directDependencies); 30 | List deps = project.getDependencies(); 31 | produceNiceOutput(deps, recursiveDependencies); 32 | } catch( Exception exception ){ 33 | throw new MojoExecutionException( "Oh no! Something went wrong. " + 34 | "Get in touch with the VersionEye guys and give them feedback. " + 35 | "You find them on Twitter at https//twitter.com/VersionEye. ", exception ); 36 | } 37 | } 38 | 39 | private void produceNiceOutput(List directDependencies, List recursiveDependencies){ 40 | productNiceOutputForDirectDependencies(directDependencies); 41 | productNiceOutputForRecursiveDependencies(recursiveDependencies); 42 | produceNiceOutputSummary(directDependencies.size(), recursiveDependencies.size()); 43 | } 44 | 45 | private void versionEyeOutput(){ 46 | getLog().info(""); 47 | getLog().info("************* \\_/ VersionEye \\_/ *************"); 48 | getLog().info(""); 49 | } 50 | 51 | private void productNiceOutputForDirectDependencies(List directDependencies){ 52 | getLog().info(""); 53 | getLog().info(directDependencies.size() + " Direct Dependencies: "); 54 | getLog().info("--------------------"); 55 | for (Dependency dependency : directDependencies){ 56 | getLog().info( dependency.getGroupId() + ":" + dependency.getArtifactId() + ":" + dependency.getVersion()); 57 | } 58 | getLog().info(""); 59 | } 60 | 61 | private void productNiceOutputForRecursiveDependencies(List recursiveDependencies){ 62 | getLog().info(""); 63 | getLog().info(recursiveDependencies.size() + " Transitive Dependencies: "); 64 | getLog().info("--------------------"); 65 | for (Artifact artifact : recursiveDependencies){ 66 | getLog().info(artifact.getGroupId() + ":" + artifact.getArtifactId() + ":" + artifact.getVersion()); 67 | } 68 | getLog().info(""); 69 | } 70 | 71 | private void produceNiceOutputSummary(int directCount, int recursiveCount) { 72 | int allCount = directCount + recursiveCount; 73 | getLog().info(""); 74 | getLog().info(directCount + " Direct dependencies and " + 75 | recursiveCount + " transitive dependencies. This project has " + 76 | allCount + " dependencies."); 77 | getLog().info(""); 78 | getLog().info(""); 79 | } 80 | 81 | } 82 | -------------------------------------------------------------------------------- /src/main/java/com/versioneye/utils/JsonUtils.java: -------------------------------------------------------------------------------- 1 | package com.versioneye.utils; 2 | 3 | import org.apache.maven.model.Dependency; 4 | import org.apache.maven.model.Plugin; 5 | import org.apache.maven.project.MavenProject; 6 | import org.codehaus.jackson.JsonParser; 7 | import org.codehaus.jackson.map.ObjectMapper; 8 | import org.eclipse.aether.artifact.Artifact; 9 | 10 | import java.io.ByteArrayOutputStream; 11 | import java.io.File; 12 | import java.io.FileOutputStream; 13 | import java.io.OutputStream; 14 | import java.util.*; 15 | 16 | /** 17 | * Methods to deal with JSON. 18 | */ 19 | public class JsonUtils { 20 | 21 | public ByteArrayOutputStream dependenciesToJson(MavenProject project, List dependencies, List plugins, String nameStrategy) throws Exception { 22 | List> dependencyHashes = new ArrayList>(); 23 | if ((dependencies != null && !dependencies.isEmpty()) 24 | || (plugins != null && !plugins.isEmpty())) { 25 | dependencyHashes = getDependencyHashes(dependencies, plugins); 26 | } 27 | ByteArrayOutputStream outstream = new ByteArrayOutputStream(); 28 | toJson(outstream, getJsonPom(project, dependencyHashes, nameStrategy)); 29 | return outstream; 30 | } 31 | 32 | public ByteArrayOutputStream artifactsToJson(List directDependencies) throws Exception { 33 | List> hashes = getHashes(directDependencies); 34 | ByteArrayOutputStream outstream = new ByteArrayOutputStream(); 35 | toJson(outstream, hashes); 36 | return outstream; 37 | } 38 | 39 | public void dependenciesToJsonFile(String name, Map directDependencies, String file) throws Exception { 40 | File targetFile = getTargetFile(file); 41 | toJson(new FileOutputStream(targetFile), directDependencies); 42 | } 43 | 44 | public void dependenciesToJsonFile(MavenProject project, List directDependencies, String file, String nameStrategy) throws Exception { 45 | List> dependencyHashes = getHashes(directDependencies); 46 | File targetFile = getTargetFile(file); 47 | toJson(new FileOutputStream(targetFile), getJsonPom(project, dependencyHashes, nameStrategy)); 48 | } 49 | 50 | public static void toJson(OutputStream output, Object input) throws Exception { 51 | ObjectMapper mapper = new ObjectMapper(); 52 | mapper.configure(JsonParser.Feature.ALLOW_UNQUOTED_FIELD_NAMES, true); 53 | mapper.writeValue(output, input); 54 | } 55 | 56 | public List> getHashes(List directDependencies){ 57 | List> hashes = (List>) new Vector>(directDependencies.size()); 58 | hashes.addAll( generateHashForJsonOutput( directDependencies)); 59 | return hashes; 60 | } 61 | 62 | public List> getDependencyHashes(List directDependencies, List plugins){ 63 | List> hashes = (List>) new Vector>(); 64 | if (directDependencies != null && directDependencies.size() > 0){ 65 | hashes.addAll( generateHashFromDependencyList( directDependencies)); 66 | } 67 | if (plugins != null && plugins.size() > 0){ 68 | hashes.addAll( generateHashFromPluginList(plugins)); 69 | } 70 | return hashes; 71 | } 72 | 73 | public static List> generateHashForJsonOutput(List input) { 74 | List> output = new Vector>(input.size()); 75 | for (Artifact artifact : input) { 76 | HashMap hash = new HashMap(2); 77 | hash.put("version", artifact.getVersion()); 78 | hash.put("name", artifact.getGroupId() + ":" + artifact.getArtifactId()); 79 | output.add(hash); 80 | } 81 | return output; 82 | } 83 | 84 | public static List> generateHashFromDependencyList(List input) { 85 | if (input == null || input.isEmpty()){ 86 | return null; 87 | } 88 | List> output = new Vector>(input.size()); 89 | for (Dependency dependency : input) { 90 | HashMap hash = new HashMap(2); 91 | hash.put("version", dependency.getVersion()); 92 | hash.put("name", dependency.getGroupId() + ":" + dependency.getArtifactId()); 93 | hash.put("scope", dependency.getScope() ); 94 | output.add(hash); 95 | } 96 | return output; 97 | } 98 | 99 | public static List> generateHashFromPluginList(List input) { 100 | if (input == null || input.isEmpty()){ 101 | return null; 102 | } 103 | List> output = new Vector>(input.size()); 104 | for (Plugin plugin : input) { 105 | HashMap hash = new HashMap(2); 106 | hash.put("version", plugin.getVersion()); 107 | hash.put("name", plugin.getGroupId() + ":" + plugin.getArtifactId()); 108 | hash.put("scope", "plugin" ); 109 | output.add(hash); 110 | } 111 | return output; 112 | } 113 | 114 | public Map getJsonPom(MavenProject project, List> dependencyHashes, String nameStrategy){ 115 | Map pom = new HashMap(); 116 | pom.put("name", getNameFor(project, nameStrategy)); 117 | pom.put("group_id", project.getGroupId()); 118 | pom.put("artifact_id", project.getArtifactId()); 119 | pom.put("version", project.getVersion()); 120 | pom.put("language", "Java"); 121 | pom.put("prod_type", "Maven2"); 122 | pom.put("licenses", project.getLicenses()); 123 | pom.put("dependencies", dependencyHashes); 124 | return pom; 125 | } 126 | 127 | private String getNameFor(MavenProject project, String nameStrategy){ 128 | String name = "project"; 129 | if (nameStrategy == null || nameStrategy.isEmpty()){ 130 | nameStrategy = "name"; 131 | } 132 | if (nameStrategy.equals("name")){ 133 | name = project.getName(); 134 | if (name == null || name.isEmpty()){ 135 | name = project.getArtifactId(); 136 | } 137 | } else if (nameStrategy.equals("artifact_id")){ 138 | name = project.getArtifactId(); 139 | } else if (nameStrategy.equals("GA")){ 140 | name = project.getGroupId() + "/" + project.getArtifactId(); 141 | } 142 | return name; 143 | } 144 | 145 | private File getTargetFile(String file){ 146 | File targetFile = new File(file); 147 | File parent = targetFile.getParentFile(); 148 | if (!parent.exists()){ 149 | parent.mkdirs(); 150 | } 151 | return targetFile; 152 | } 153 | 154 | } 155 | -------------------------------------------------------------------------------- /src/main/java/com/versioneye/utils/HttpUtils.java: -------------------------------------------------------------------------------- 1 | package com.versioneye.utils; 2 | 3 | import com.versioneye.dto.ErrorJsonResponse; 4 | import org.apache.http.HttpHost; 5 | import org.apache.http.HttpResponse; 6 | import org.apache.http.auth.AuthScope; 7 | import org.apache.http.auth.UsernamePasswordCredentials; 8 | import org.apache.http.client.CredentialsProvider; 9 | import org.apache.http.client.HttpClient; 10 | import org.apache.http.client.config.RequestConfig; 11 | import org.apache.http.client.methods.HttpPost; 12 | import org.apache.http.entity.mime.MultipartEntity; 13 | import org.apache.http.entity.mime.content.ByteArrayBody; 14 | import org.apache.http.entity.mime.content.StringBody; 15 | import org.apache.http.impl.client.BasicCredentialsProvider; 16 | import org.apache.http.impl.client.HttpClients; 17 | import org.apache.http.impl.client.SystemDefaultHttpClient; 18 | import org.codehaus.jackson.map.ObjectMapper; 19 | 20 | import java.io.BufferedReader; 21 | import java.io.InputStream; 22 | import java.io.InputStreamReader; 23 | import java.io.Reader; 24 | import java.net.*; 25 | 26 | /** 27 | * Methods to deal with the HTTP protocol. 28 | */ 29 | public class HttpUtils { 30 | 31 | public static Integer ONE_SECOND = 1000; 32 | public static Integer ONE_MINUTE = ONE_SECOND * 60; 33 | public static Integer TEN_MINUTE = ONE_MINUTE * 10; 34 | 35 | public static String get(String url) throws Exception { 36 | HttpURLConnection con = createConnection(url); 37 | setProxyAuthIfAvailable(); 38 | con.setRequestMethod("GET"); 39 | con.setConnectTimeout(TEN_MINUTE); 40 | con.setReadTimeout(TEN_MINUTE); 41 | con.setRequestProperty("User-Agent", "VersionEye Maven Plugin"); 42 | 43 | 44 | int responseCode = con.getResponseCode(); 45 | System.out.println("\nSending 'GET' request to URL : " + url); 46 | System.out.println("Response Code : " + responseCode); 47 | 48 | BufferedReader in = new BufferedReader(new InputStreamReader(con.getInputStream())); 49 | String inputLine; 50 | StringBuffer response = new StringBuffer(); 51 | while ((inputLine = in.readLine()) != null) { 52 | response.append(inputLine); 53 | } 54 | in.close(); 55 | return response.toString(); 56 | } 57 | 58 | public static Reader post(String url, byte[] data, String dataName, String visibility, String name, String orga_name, String team) throws Exception { 59 | HttpClient client = createHttpClient(); 60 | HttpPost httpPost = new HttpPost(url); 61 | ByteArrayBody byteArrayBody = new ByteArrayBody(data, "application/json", "pom.json"); 62 | MultipartEntity multipartEntity = new MultipartEntity(); 63 | multipartEntity.addPart(dataName, byteArrayBody); 64 | 65 | if (visibility != null && !visibility.isEmpty()) 66 | multipartEntity.addPart("visibility", new StringBody(visibility)); 67 | 68 | if (name != null && !name.isEmpty()) 69 | multipartEntity.addPart("name", new StringBody(name)); 70 | 71 | if (orga_name != null && !orga_name.isEmpty()) 72 | multipartEntity.addPart("orga_name", new StringBody(orga_name)); 73 | 74 | if (team != null && !team.isEmpty()) 75 | multipartEntity.addPart("team_name", new StringBody(team)); 76 | 77 | httpPost.setEntity(multipartEntity); 78 | 79 | setProxyIfAvailable(httpPost); 80 | HttpResponse response = client.execute(httpPost); 81 | 82 | int statusCode = response.getStatusLine().getStatusCode(); 83 | if (statusCode != 200 && statusCode != 201){ 84 | String err = getErrorMessage(response); 85 | String errMsg = "Status Code: " + statusCode + " -> " + err + " for URL: " + url; 86 | throw new Exception(errMsg); 87 | } 88 | 89 | return new InputStreamReader(response.getEntity().getContent()); 90 | } 91 | 92 | public static String delete(String url) throws Exception { 93 | HttpURLConnection con = createConnection(url); 94 | setProxyAuthIfAvailable(); 95 | con.setRequestMethod("GET"); 96 | con.setConnectTimeout(TEN_MINUTE); 97 | con.setReadTimeout(TEN_MINUTE); 98 | con.setRequestProperty("User-Agent", "VersionEye Maven Plugin"); 99 | con.setRequestMethod("DELETE"); 100 | 101 | int responseCode = con.getResponseCode(); 102 | System.out.println("\nSending 'DELETE' request to URL : " + url); 103 | System.out.println("Response Code : " + responseCode); 104 | 105 | BufferedReader in = new BufferedReader(new InputStreamReader(con.getInputStream())); 106 | String inputLine; 107 | StringBuffer response = new StringBuffer(); 108 | while ((inputLine = in.readLine()) != null) { 109 | response.append(inputLine); 110 | } 111 | in.close(); 112 | return response.toString(); 113 | } 114 | 115 | 116 | private static String getErrorMessage(HttpResponse response) throws Exception { 117 | String errorMsg = getErrorFromJson(response); 118 | if (errorMsg != null){ 119 | return errorMsg; 120 | } 121 | return getPureBodyString(response); 122 | } 123 | 124 | private static String getErrorFromJson(HttpResponse response){ 125 | try { 126 | ObjectMapper mapper = new ObjectMapper(); 127 | ErrorJsonResponse error = mapper.readValue(response.getEntity().getContent(), ErrorJsonResponse.class); 128 | return error.getError(); 129 | } catch (Exception exception) { 130 | exception.printStackTrace(); 131 | return null; 132 | } 133 | } 134 | 135 | private static String getPureBodyString(HttpResponse response){ 136 | try { 137 | InputStream content = response.getEntity().getContent(); 138 | BufferedReader in = new BufferedReader(new InputStreamReader( content ) ); 139 | String inputLine; 140 | StringBuffer body = new StringBuffer(); 141 | while ((inputLine = in.readLine()) != null) { 142 | body.append(inputLine); 143 | } 144 | in.close(); 145 | return body.toString(); 146 | } catch (Exception exception) { 147 | exception.printStackTrace(); 148 | return ""; 149 | } 150 | 151 | } 152 | 153 | private static HttpClient createHttpClient(){ 154 | HttpClient client = null; 155 | String host = System.getProperty("https.proxyHost"); 156 | String port = System.getProperty("https.proxyPort"); 157 | String user = System.getProperty("https.proxyUser"); 158 | String pass = System.getProperty("https.proxyPassword"); 159 | if (user != null && !user.isEmpty() && pass != null && !pass.isEmpty() && 160 | host != null && !host.isEmpty() && port != null && !port.isEmpty()){ 161 | CredentialsProvider credsProvider = new BasicCredentialsProvider(); 162 | credsProvider.setCredentials(new AuthScope(host, Integer.parseInt(port)), new UsernamePasswordCredentials(user, pass)); 163 | client = HttpClients.custom().setDefaultCredentialsProvider(credsProvider).build(); 164 | } else { 165 | client = new SystemDefaultHttpClient(); 166 | } 167 | return client; 168 | } 169 | 170 | 171 | private static void setProxyIfAvailable(HttpPost httpPost){ 172 | String host = System.getProperty("https.proxyHost"); 173 | String port = System.getProperty("https.proxyPort"); 174 | if (host != null && !host.isEmpty() && port != null && !port.isEmpty()){ 175 | HttpHost proxy = new HttpHost(host, Integer.parseInt(port)); 176 | RequestConfig config = RequestConfig.custom().setProxy(proxy).build(); 177 | httpPost.setConfig(config); 178 | } 179 | } 180 | 181 | 182 | private static HttpURLConnection createConnection(String url) throws Exception{ 183 | URL obj = new URL(url); 184 | HttpURLConnection con = null; 185 | String host = System.getProperty("https.proxyHost"); 186 | String port = System.getProperty("https.proxyPort"); 187 | if (host != null && !host.isEmpty() && port != null && !port.isEmpty()){ 188 | Proxy proxy = new Proxy(Proxy.Type.HTTP, new InetSocketAddress(host, Integer.parseInt(port))); 189 | con = (HttpURLConnection) obj.openConnection(proxy); 190 | } else { 191 | con = (HttpURLConnection) obj.openConnection(); 192 | } 193 | return con; 194 | } 195 | 196 | private static void setProxyAuthIfAvailable(){ 197 | String user = System.getProperty("https.proxyUser"); 198 | String pass = System.getProperty("https.proxyPassword"); 199 | if (user != null && !user.isEmpty() && pass != null && !pass.isEmpty()){ 200 | Authenticator.setDefault(new ProxyAuthenticator(user, pass)); 201 | } 202 | } 203 | 204 | } 205 | -------------------------------------------------------------------------------- /pom.xml: -------------------------------------------------------------------------------- 1 | 3 | 4.0.0 4 | 5 | 6 | 7 | 3.1 8 | 9 | 10 | com.versioneye 11 | versioneye-maven-plugin 12 | 3.11.4 13 | maven-plugin 14 | 15 | versioneye-maven-plugin 16 | https://github.com/versioneye/versioneye_maven_plugin 17 | 18 | This is the maven plugin for http://www.VersionEye.com. It allows you to create and update 19 | a project at VersionEye. You can find a complete documentation of this project on GitHub: 20 | https://github.com/versioneye/versioneye_maven_plugin. 21 | 22 | 23 | 24 | scm:git:https://github.com/versioneye/versioneye_maven_plugin.git 25 | scm:git:https://github.com/versioneye/versioneye_maven_plugin.git 26 | https://github.com/versioneye/versioneye_maven_plugin.git 27 | 28 | 29 | 30 | 31 | MIT 32 | http://choosealicense.com/licenses/mit/ 33 | 34 | 35 | 36 | 37 | 38 | Robert Reiz 39 | reiz 40 | VersionEye 41 | https://www.VersionEye.com 42 | 43 | 44 | 45 | 46 | http://repo1.maven.org/maven2/com/versioneye/versioneye-maven-plugin 47 | 48 | ossrh 49 | https://oss.sonatype.org/service/local/staging/deploy/maven2/ 50 | 51 | 52 | 53 | 54 | 55 | 3.5.0 56 | 1.9.13 57 | 4.5.3 58 | 59 | 60 | 61 | 62 | org.apache.maven 63 | maven-plugin-api 64 | ${maven.version} 65 | 66 | 67 | org.apache.maven 68 | maven-core 69 | ${maven.version} 70 | 71 | 72 | org.apache.maven.plugin-tools 73 | maven-plugin-annotations 74 | 3.5 75 | provided 76 | 77 | 78 | org.codehaus.jackson 79 | jackson-core-lgpl 80 | ${jackson.version} 81 | 82 | 83 | org.codehaus.jackson 84 | jackson-mapper-lgpl 85 | ${jackson.version} 86 | 87 | 88 | org.apache.httpcomponents 89 | httpclient 90 | ${httpcomponents.version} 91 | 92 | 93 | org.apache.httpcomponents 94 | httpmime 95 | ${httpcomponents.version} 96 | 97 | 98 | org.testng 99 | testng 100 | 6.11 101 | test 102 | 103 | 108 | 109 | 110 | 111 | 112 | 113 | 114 | com.versioneye 115 | versioneye-maven-plugin 116 | 3.11.4 117 | 118 | 119 | 120 | 121 | 122 | 123 | 124 | 125 | 126 | 127 | 128 | 129 | 130 | 131 | 132 | 133 | 134 | 135 | 136 | 137 | 138 | 139 | 140 | 141 | org.sonatype.plugins 142 | nexus-staging-maven-plugin 143 | 1.6.8 144 | true 145 | 146 | ossrh 147 | https://oss.sonatype.org/ 148 | true 149 | 150 | 151 | 152 | 153 | 154 | 155 | 156 | 157 | 158 | org.apache.maven.plugins 159 | maven-gpg-plugin 160 | 161 | 162 | sign-artifacts 163 | verify 164 | 165 | sign 166 | 167 | 168 | 169 | 170 | 171 | 172 | org.apache.maven.plugins 173 | maven-plugin-plugin 174 | 3.5 175 | 176 | versioneye 177 | true 178 | 179 | 180 | 181 | mojo-descriptor 182 | 183 | descriptor 184 | 185 | 186 | 187 | help-goal 188 | 189 | helpmojo 190 | 191 | 192 | 193 | 194 | 195 | 196 | org.apache.maven.plugins 197 | maven-source-plugin 198 | 3.0.1 199 | 200 | 201 | attach-sources 202 | 203 | jar-no-fork 204 | 205 | 206 | 207 | 208 | 209 | 210 | org.apache.maven.plugins 211 | maven-javadoc-plugin 212 | 213 | 214 | attach-javadocs 215 | 216 | jar 217 | 218 | 219 | 220 | 221 | 222 | 223 | 224 | 225 | 226 | 227 | 228 | org.apache.maven.plugins 229 | maven-changelog-plugin 230 | 2.3 231 | 232 | tag 233 | 234 | 3.11.3 235 | 3.11.4 236 | 237 | 238 | 239 | 240 | 241 | 242 | 243 | -------------------------------------------------------------------------------- /src/main/java/com/versioneye/ProjectMojo.java: -------------------------------------------------------------------------------- 1 | package com.versioneye; 2 | 3 | import com.versioneye.dto.ProjectDependency; 4 | import com.versioneye.dto.ProjectJsonResponse; 5 | import com.versioneye.utils.DependencyUtils; 6 | import com.versioneye.utils.HttpUtils; 7 | import com.versioneye.utils.JsonUtils; 8 | import com.versioneye.utils.PropertiesUtils; 9 | import org.apache.maven.model.Dependency; 10 | import org.apache.maven.model.Plugin; 11 | import org.codehaus.jackson.map.ObjectMapper; 12 | import org.eclipse.aether.artifact.Artifact; 13 | import org.eclipse.aether.collection.CollectRequest; 14 | import org.eclipse.aether.graph.DependencyNode; 15 | import org.eclipse.aether.resolution.DependencyRequest; 16 | import org.eclipse.aether.util.artifact.JavaScopes; 17 | import org.eclipse.aether.util.graph.visitor.PreorderNodeListGenerator; 18 | import org.w3c.dom.Document; 19 | import org.w3c.dom.Node; 20 | import org.w3c.dom.NodeList; 21 | 22 | import javax.xml.parsers.DocumentBuilder; 23 | import javax.xml.parsers.DocumentBuilderFactory; 24 | import javax.xml.xpath.XPath; 25 | import javax.xml.xpath.XPathConstants; 26 | import javax.xml.xpath.XPathExpression; 27 | import javax.xml.xpath.XPathFactory; 28 | import java.io.ByteArrayOutputStream; 29 | import java.io.File; 30 | import java.io.Reader; 31 | import java.util.ArrayList; 32 | import java.util.List; 33 | import java.util.Map; 34 | import java.util.Properties; 35 | 36 | /** 37 | * Methods required to deal with projects resource 38 | */ 39 | public class ProjectMojo extends SuperMojo { 40 | 41 | protected ByteArrayOutputStream getTransitiveDependenciesJsonStream(String nameStrategy) throws Exception { 42 | PreorderNodeListGenerator nlg = new PreorderNodeListGenerator(); 43 | DependencyNode root = getDependencyNode(nlg); 44 | List transDependencies = nlg.getDependencies(true); 45 | List directDependencies = DependencyUtils.collectDirectDependencies(root.getChildren()); 46 | List dependencies = new ArrayList(); 47 | for (org.eclipse.aether.graph.Dependency dependency : transDependencies) { 48 | getLog().info(" scope: " + dependency.getScope()); 49 | Dependency dep = new Dependency(); 50 | Artifact artifact = dependency.getArtifact(); 51 | dep.setGroupId(artifact.getGroupId()); 52 | dep.setArtifactId(artifact.getArtifactId()); 53 | dep.setVersion(artifact.getVersion()); 54 | dep.setScope(dependency.getScope()); 55 | if (directDependencies.contains(artifact)) { 56 | dep.setScope(dependency.getScope() + "_direct"); 57 | } else { 58 | dep.setScope(dependency.getScope() + "_transitive"); 59 | } 60 | dependencies.add(dep); 61 | } 62 | JsonUtils jsonUtils = new JsonUtils(); 63 | return jsonUtils.dependenciesToJson(project, dependencies, null, nameStrategy); 64 | } 65 | 66 | protected ByteArrayOutputStream getDirectDependenciesJsonStream(String nameStrategy) throws Exception { 67 | List plugins = new ArrayList(); 68 | if (trackPlugins){ 69 | plugins = getPluginsFromXml(); 70 | } 71 | 72 | List dependencies = project.getDependencies(); 73 | if (ignoreDependencyManagement == false && 74 | project.getDependencyManagement() != null && 75 | project.getDependencyManagement().getDependencies() != null && 76 | project.getDependencyManagement().getDependencies().size() > 0){ 77 | dependencies.addAll(project.getDependencyManagement().getDependencies()); 78 | } 79 | List filteredDependencies = filterForScopes(dependencies); 80 | JsonUtils jsonUtils = new JsonUtils(); 81 | return jsonUtils.dependenciesToJson(project, filteredDependencies, plugins, nameStrategy); 82 | } 83 | 84 | protected Map getDirectDependenciesJsonMap(String nameStrategy) throws Exception { 85 | List dependencies = project.getDependencies(); 86 | if (dependencies == null || dependencies.isEmpty()){ 87 | return null; 88 | } else { 89 | iterateThrough(dependencies); 90 | } 91 | JsonUtils jsonUtils = new JsonUtils(); 92 | List> dependencyHashes = jsonUtils.getDependencyHashes(dependencies, project.getPluginManagement().getPlugins()); 93 | return jsonUtils.getJsonPom(project, dependencyHashes, nameStrategy); 94 | } 95 | 96 | protected ByteArrayOutputStream getDirectArtifactsJsonStream() throws Exception { 97 | DependencyNode root = getDependencyNode(new PreorderNodeListGenerator()); 98 | List directDependencies = DependencyUtils.collectDirectDependencies(root.getChildren()); 99 | JsonUtils jsonUtils = new JsonUtils(); 100 | return jsonUtils.artifactsToJson(directDependencies); 101 | } 102 | 103 | protected DependencyNode getDependencyNode(PreorderNodeListGenerator nlg) throws Exception { 104 | CollectRequest collectRequest = DependencyUtils.getCollectRequest(project, repos, JavaScopes.RUNTIME); 105 | DependencyNode root = system.collectDependencies(session, collectRequest).getRoot(); 106 | DependencyRequest dependencyRequest = new DependencyRequest(root, null); 107 | system.resolveDependencies(session, dependencyRequest); 108 | root.accept(nlg); 109 | return root; 110 | } 111 | 112 | protected void prettyPrint0End() throws Exception { 113 | getLog().info("."); 114 | getLog().info("There are no dependencies in this project! - " + project.getId() ); 115 | getLog().info("."); 116 | } 117 | 118 | protected void prettyPrint(ProjectJsonResponse response) throws Exception { 119 | getLog().info("."); 120 | getLog().info("Project id: " + response.getId()); 121 | getLog().info("Project name: " + response.getName()); 122 | getLog().info("Project groupId: " + response.getGroup_id()); 123 | getLog().info("Project artifactId: " + response.getArtifact_id()); 124 | getLog().info("Dependencies: " + response.getDep_number()); 125 | getLog().info("Outdated: " + response.getOut_number()); 126 | for (ProjectDependency dependency : response.getDependencies() ){ 127 | if (dependency.getOutdated() == false){ 128 | continue; 129 | } 130 | getLog().info(" - " + dependency.getProd_key() + ":" + dependency.getVersion_requested() + " -> " + dependency.getVersion_current()); 131 | } 132 | getLog().info(""); 133 | String projectID = (String) mavenSession.getTopLevelProject().getContextValue("veye_project_id"); 134 | getLog().info("You can find your updated project here: " + fetchBaseUrl() + "/user/projects/" + projectID); 135 | getLog().info(""); 136 | } 137 | 138 | protected ProjectJsonResponse updateExistingProject(String resource, String projectId, ByteArrayOutputStream outStream) throws Exception { 139 | String apiKey = fetchApiKey(); 140 | String url = fetchBaseUrl() + apiPath + resource + "/" + projectId + "?api_key=" + apiKey; 141 | Reader reader = HttpUtils.post(url, outStream.toByteArray(), "project_file", null, null, null, null); 142 | ObjectMapper mapper = new ObjectMapper(); 143 | return mapper.readValue(reader, ProjectJsonResponse.class ); 144 | } 145 | 146 | 147 | protected ProjectJsonResponse createNewProject(String resource, ByteArrayOutputStream outStream) throws Exception { 148 | String apiKey = fetchApiKey(); 149 | String url = fetchBaseUrl() + apiPath + resource + apiKey; 150 | Reader reader = HttpUtils.post(url, outStream.toByteArray(), "upload", visibility, name, organisation, team); 151 | ObjectMapper mapper = new ObjectMapper(); 152 | return mapper.readValue(reader, ProjectJsonResponse.class ); 153 | } 154 | 155 | protected void merge(String childId) { 156 | if (mergeAfterCreate == false) { 157 | return ; 158 | } 159 | try { 160 | if (mavenSession.getTopLevelProject().getId().equals(mavenSession.getCurrentProject().getId())){ 161 | return ; 162 | } 163 | 164 | String parentProjectId = (String) mavenSession.getTopLevelProject().getContextValue("veye_project_id"); 165 | getLog().debug("parentProjectId: " + parentProjectId); 166 | String url = fetchBaseUrl() + apiPath + "/projects/" + parentProjectId + "/merge/" + childId + "?api_key=" + fetchApiKey(); 167 | 168 | String response = HttpUtils.get(url); 169 | getLog().debug("merge response: " + response); 170 | } catch (Exception ex) { 171 | getLog().error(ex); 172 | } 173 | } 174 | 175 | protected void writeProperties(ProjectJsonResponse response) throws Exception { 176 | Properties properties = fetchProjectProperties(); 177 | if (response.getId() != null) { 178 | properties.setProperty("project_id", response.getId()); 179 | } 180 | PropertiesUtils utils = new PropertiesUtils(); 181 | utils.writeProperties(properties, getPropertiesPath()); 182 | } 183 | 184 | private void iterateThrough(List dependencies){ 185 | for(Dependency dep: dependencies){ 186 | getLog().info(" - dependency: " + dep.getGroupId() + "/" + dep.getArtifactId() + " " + dep.getVersion()); 187 | } 188 | } 189 | 190 | private List getPluginsFromXml(){ 191 | List plugins = new ArrayList(); 192 | try { 193 | File pom = project.getModel().getPomFile(); 194 | 195 | DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance(); 196 | DocumentBuilder builder = factory.newDocumentBuilder(); 197 | Document doc = builder.parse(pom); 198 | XPathFactory xPathfactory = XPathFactory.newInstance(); 199 | XPath xpath = xPathfactory.newXPath(); 200 | XPathExpression expr = xpath.compile("//plugins/plugin"); 201 | 202 | NodeList nl = (NodeList) expr.evaluate(doc, XPathConstants.NODESET); 203 | for (int i = 0 ; i < nl.getLength() ; i++){ 204 | Node node = nl.item(i); 205 | Plugin plugin = new Plugin(); 206 | fillPlugin(node, plugin); 207 | if (plugin.getGroupId() != null && plugin.getArtifactId() != null){ 208 | plugins.add(plugin); 209 | } 210 | } 211 | } catch (Exception exc){ 212 | getLog().error(exc); 213 | } 214 | return plugins; 215 | } 216 | 217 | private void fillPlugin(Node node, Plugin plugin){ 218 | for (int xi = 0 ; xi < node.getChildNodes().getLength() ; xi++ ){ 219 | Node child = node.getChildNodes().item(xi); 220 | if (child == null){ 221 | return ; 222 | } 223 | if (child.getNodeName().equals("groupId")){ 224 | plugin.setGroupId(child.getTextContent().trim()); 225 | } 226 | if (child.getNodeName().equals("artifactId")){ 227 | plugin.setArtifactId(child.getTextContent().trim()); 228 | } 229 | if (child.getNodeName().equals("version")){ 230 | String version = parseVersionString( child.getTextContent().trim() ); 231 | plugin.setVersion(version); 232 | } 233 | } 234 | } 235 | 236 | private String parseVersionString(String version){ 237 | if (version.startsWith("${")){ 238 | String verValue = version.replaceAll("\\$\\{", "").replaceAll("\\}", ""); 239 | version = (String) project.getProperties().get(verValue); 240 | } 241 | return version; 242 | } 243 | 244 | private List filterForScopes(List dependencies){ 245 | if (skipScopes == null || skipScopes.trim().isEmpty() || dependencies == null || dependencies.isEmpty()) 246 | return dependencies; 247 | 248 | String[] scopes = skipScopes.split(","); 249 | List filtered = new ArrayList(); 250 | for (Dependency dependency : dependencies){ 251 | boolean ignoreScope = false; 252 | for ( String scope : scopes ) { 253 | if (scope != null && 254 | dependency != null && 255 | dependency.getScope() != null && 256 | dependency.getScope().toLowerCase().equals(scope.toLowerCase())) 257 | { 258 | ignoreScope = true; 259 | } 260 | } 261 | if (ignoreScope == false ){ 262 | filtered.add(dependency); 263 | } 264 | } 265 | return filtered; 266 | } 267 | 268 | } 269 | -------------------------------------------------------------------------------- /src/main/java/com/versioneye/SuperMojo.java: -------------------------------------------------------------------------------- 1 | package com.versioneye; 2 | 3 | import com.versioneye.utils.PropertiesUtils; 4 | import org.apache.maven.execution.MavenSession; 5 | import org.apache.maven.plugin.AbstractMojo; 6 | import org.apache.maven.plugin.MojoExecutionException; 7 | import org.apache.maven.plugin.MojoFailureException; 8 | import org.apache.maven.plugins.annotations.Component; 9 | import org.apache.maven.plugins.annotations.Parameter; 10 | import org.apache.maven.project.MavenProject; 11 | import org.eclipse.aether.RepositorySystem; 12 | import org.eclipse.aether.RepositorySystemSession; 13 | import org.eclipse.aether.repository.RemoteRepository; 14 | 15 | import javax.net.ssl.HttpsURLConnection; 16 | import javax.net.ssl.SSLContext; 17 | import javax.net.ssl.TrustManager; 18 | import javax.net.ssl.X509TrustManager; 19 | import java.io.File; 20 | import java.io.IOException; 21 | import java.security.SecureRandom; 22 | import java.security.cert.X509Certificate; 23 | import java.util.List; 24 | import java.util.Properties; 25 | 26 | /** 27 | * The Mother of all Mojos! 28 | */ 29 | public class SuperMojo extends AbstractMojo { 30 | 31 | protected static final String propertiesFile = "versioneye.properties"; 32 | 33 | @Component 34 | protected RepositorySystem system; 35 | 36 | @Component 37 | protected MavenSession mavenSession; 38 | 39 | @Parameter( defaultValue="${repositorySystemSession}" ) 40 | protected RepositorySystemSession session; 41 | 42 | @Parameter( defaultValue="${project}" ) 43 | protected MavenProject project; 44 | 45 | @Parameter( defaultValue="${reactorProjects}" ) 46 | protected List reactorProjects; 47 | 48 | @Parameter( defaultValue = "${project.remoteProjectRepositories}") 49 | protected List repos; 50 | 51 | @Parameter( defaultValue = "${basedir}", property = "basedir", required = true) 52 | protected File projectDirectory; 53 | 54 | @Parameter( defaultValue = "${project.build.directory}", property = "outputDir", required = true ) 55 | protected File outputDirectory; 56 | 57 | @Parameter( defaultValue = "${user.home}" ) 58 | protected File homeDirectory; 59 | 60 | @Parameter( property = "baseUrl", defaultValue = "https://www.versioneye.com" ) 61 | protected String baseUrl; 62 | 63 | @Parameter( property = "apiPath", defaultValue = "/api/v2" ) 64 | protected String apiPath; 65 | 66 | @Parameter( property = "projectId" ) 67 | protected String projectId; 68 | 69 | @Parameter( property = "apiKey" ) 70 | protected String apiKey; 71 | 72 | @Parameter( property = "propertiesPath" ) 73 | protected String propertiesPath = null; 74 | 75 | @Parameter( property = "proxyHost" ) 76 | protected String proxyHost = null; 77 | 78 | @Parameter( property = "proxyPort" ) 79 | protected String proxyPort = null; 80 | 81 | @Parameter( property = "proxyUser" ) 82 | protected String proxyUser = null; 83 | 84 | @Parameter( property = "proxyPassword" ) 85 | protected String proxyPassword = null; 86 | 87 | @Parameter( property = "updatePropertiesAfterCreate" ) 88 | protected boolean updatePropertiesAfterCreate = true; 89 | 90 | @Parameter( property = "mergeAfterCreate" ) 91 | protected boolean mergeAfterCreate = true; 92 | 93 | @Parameter( property = "parentGroupId" ) 94 | protected String parentGroupId = null; 95 | 96 | @Parameter( property = "parentArtifactId" ) 97 | protected String parentArtifactId = null; 98 | 99 | @Parameter( property = "nameStrategy" ) 100 | protected String nameStrategy = "name"; 101 | 102 | @Parameter( property = "trackPlugins" ) 103 | protected Boolean trackPlugins = Boolean.TRUE; 104 | 105 | @Parameter( property = "licenseCheckBreakByUnknown" ) 106 | protected Boolean licenseCheckBreakByUnknown = Boolean.FALSE; 107 | 108 | @Parameter( property = "skipScopes" ) 109 | protected String skipScopes = null; 110 | 111 | @Parameter( property = "organisation" ) 112 | protected String organisation = null; 113 | 114 | @Parameter( property = "team" ) 115 | protected String team = null; 116 | 117 | @Parameter( property = "visibility" ) 118 | protected String visibility = null; 119 | 120 | @Parameter( property = "name" ) 121 | protected String name = null; 122 | 123 | @Parameter( property = "ignoreDependencyManagement" ) 124 | protected boolean ignoreDependencyManagement = false; 125 | 126 | @Parameter( property = "transitiveDependencies" ) 127 | protected boolean transitiveDependencies = false; 128 | 129 | protected Properties properties = null; // Properties in src/main/resources 130 | protected Properties homeProperties = null; // Properties in ~/.m2/ 131 | 132 | public void execute() throws MojoExecutionException, MojoFailureException { } 133 | 134 | 135 | protected String fetchApiKey() throws Exception { 136 | if (apiKey != null && !apiKey.isEmpty() ) 137 | return apiKey; 138 | 139 | apiKey = System.getenv().get("VERSIONEYE_API_KEY"); 140 | 141 | String propertiesPath = homeDirectory + "/.m2/" + propertiesFile; 142 | String key = getPropertyFromPath(propertiesPath, "api_key"); 143 | if (key != null && !key.isEmpty()){ 144 | apiKey = key; 145 | } 146 | 147 | propertiesPath = projectDirectory + "/src/qa/resources/" + propertiesFile; 148 | key = getPropertyFromPath(propertiesPath, "api_key"); 149 | if (key != null && !key.isEmpty()){ 150 | apiKey = key; 151 | } 152 | 153 | propertiesPath = projectDirectory + "/src/main/resources/" + propertiesFile; 154 | key = getPropertyFromPath(propertiesPath, "api_key"); 155 | if (key != null && !key.isEmpty()){ 156 | apiKey = key; 157 | } 158 | 159 | if (apiKey == null){ 160 | getLog().error("API Key can not be found!"); 161 | throw new Exception("API Key can not be found!"); 162 | } 163 | 164 | return apiKey; 165 | } 166 | 167 | 168 | protected String fetchBaseUrl() throws Exception { 169 | if (baseUrl != null && !baseUrl.isEmpty() ) 170 | return baseUrl; 171 | 172 | baseUrl = System.getenv().get("VERSIONEYE_BASE_URL"); 173 | 174 | String propertiesPath = homeDirectory + "/.m2/" + propertiesFile; 175 | String key = getPropertyFromPath(propertiesPath, "base_url"); 176 | if (key != null && !key.isEmpty()){ 177 | baseUrl = key; 178 | } 179 | 180 | propertiesPath = projectDirectory + "/src/qa/resources/" + propertiesFile; 181 | key = getPropertyFromPath(propertiesPath, "base_url"); 182 | if (key != null && !key.isEmpty()){ 183 | baseUrl = key; 184 | } 185 | 186 | propertiesPath = projectDirectory + "/src/main/resources/" + propertiesFile; 187 | key = getPropertyFromPath(propertiesPath, "base_url"); 188 | if (key != null && !key.isEmpty()){ 189 | baseUrl = key; 190 | } 191 | 192 | return baseUrl; 193 | } 194 | 195 | 196 | protected String fetchProjectId() throws Exception { 197 | if (projectId != null && !projectId.isEmpty() ) 198 | return projectId; 199 | 200 | if (propertiesPath != null && !propertiesPath.isEmpty()){ 201 | String project_id = getPropertyFromPath(propertiesPath, "project_id"); 202 | if (project_id != null && !project_id.isEmpty()){ 203 | projectId = project_id; 204 | } 205 | } 206 | 207 | String pPath1 = projectDirectory + "/src/qa/resources/" + propertiesFile; 208 | String project_id = getPropertyFromPath(pPath1, "project_id"); 209 | if (project_id != null && !project_id.isEmpty()){ 210 | projectId = project_id; 211 | propertiesPath = pPath1; 212 | } 213 | 214 | String pPath2 = projectDirectory + "/src/main/resources/" + propertiesFile; 215 | project_id = getPropertyFromPath(pPath2, "project_id"); 216 | if (project_id != null && !project_id.isEmpty()){ 217 | projectId = project_id; 218 | propertiesPath = pPath2; 219 | } 220 | 221 | if (projectId == null || projectId.isEmpty()){ 222 | String msg = "Searched in [" + pPath1 + ", " + pPath2 + ", "+ propertiesPath +"] for project_id but could't find any."; 223 | getLog().error(msg); 224 | throw new MojoExecutionException(msg); 225 | } 226 | 227 | return projectId; 228 | } 229 | 230 | 231 | protected Properties fetchProjectProperties() throws Exception { 232 | if (properties != null) 233 | return properties; 234 | String propertiesPath = getPropertiesPath(); 235 | System.out.println("propertiesPath: " + propertiesPath); 236 | File file = new File(propertiesPath); 237 | if (!file.exists()) 238 | createPropertiesFile(file); 239 | PropertiesUtils propertiesUtils = new PropertiesUtils(); 240 | properties = propertiesUtils.readProperties(propertiesPath); 241 | return properties; 242 | } 243 | 244 | 245 | protected String getPropertiesPath() throws Exception { 246 | if (this.propertiesPath != null && !this.propertiesPath.isEmpty()) 247 | return this.propertiesPath; 248 | String propertiesPath = projectDirectory + "/src/qa/resources/" + propertiesFile; 249 | File file = new File(propertiesPath); 250 | if (!file.exists()) { 251 | propertiesPath = projectDirectory + "/src/main/resources/" + propertiesFile; 252 | new File(propertiesPath); 253 | } 254 | this.propertiesPath = propertiesPath; 255 | return propertiesPath; 256 | } 257 | 258 | 259 | private void createPropertiesFile(File file) throws IOException { 260 | File parent = file.getParentFile(); 261 | if (!parent.exists()){ 262 | File grandpa = parent.getParentFile(); 263 | if (!grandpa.exists()){ 264 | grandpa.mkdirs(); 265 | } 266 | parent.mkdirs(); 267 | } 268 | file.createNewFile(); 269 | } 270 | 271 | 272 | protected void initTls(){ 273 | TrustManager[] trustAllCerts = new TrustManager[]{new X509TrustManager(){ 274 | public X509Certificate[] getAcceptedIssuers(){return null;} 275 | public void checkClientTrusted(X509Certificate[] certs, String authType){} 276 | public void checkServerTrusted(X509Certificate[] certs, String authType){} 277 | }}; 278 | try { 279 | SSLContext sc = SSLContext.getInstance("TLS"); 280 | sc.init(null, trustAllCerts, new SecureRandom()); 281 | HttpsURLConnection.setDefaultSSLSocketFactory(sc.getSocketFactory()); 282 | } catch (Exception e) { 283 | e.printStackTrace(); 284 | } 285 | } 286 | 287 | 288 | protected void setProxy(){ 289 | try{ 290 | proxyHost = fetchProxyHost(); 291 | proxyPort = fetchProxyPort(); 292 | proxyUser = fetchProxyUser(); 293 | proxyPassword = fetchProxyPassword(); 294 | 295 | boolean emptyProxyHost = proxyHost == null || proxyHost.isEmpty(); 296 | boolean emptyProxyPort = proxyPort == null || proxyPort.isEmpty(); 297 | if (emptyProxyHost && emptyProxyPort){ 298 | return ; 299 | } 300 | 301 | System.setProperty("proxySet", "true"); 302 | System.setProperty("http.proxyHost", proxyHost); 303 | System.setProperty("http.proxyPort", proxyPort); 304 | System.setProperty("https.proxyHost", proxyHost); 305 | System.setProperty("https.proxyPort", proxyPort); 306 | 307 | boolean emptyProxyUser = proxyUser == null || proxyUser.isEmpty(); 308 | boolean emptyProxyPass = proxyPassword == null || proxyPassword.isEmpty(); 309 | if (emptyProxyUser && emptyProxyPass ) { 310 | return ; 311 | } 312 | 313 | System.setProperty("http.proxyUser", proxyUser); 314 | System.setProperty("http.proxyPassword", proxyPassword); 315 | System.setProperty("https.proxyUser", proxyUser); 316 | System.setProperty("https.proxyPassword", proxyPassword); 317 | } catch (Exception ex) { 318 | ex.printStackTrace(); 319 | } 320 | } 321 | 322 | 323 | private String fetchProxyHost(){ 324 | if (proxyHost != null && !proxyHost.isEmpty()){ 325 | return proxyHost; 326 | } 327 | try{ 328 | String propertiesPath = homeDirectory + "/.m2/" + propertiesFile; 329 | String host = getPropertyFromPath(propertiesPath, "proxyHost"); 330 | if (host != null && !host.isEmpty()){ 331 | proxyHost = host; 332 | return proxyHost; 333 | } 334 | } catch (Exception ex) { 335 | ex.printStackTrace(); 336 | } 337 | String host = System.getenv().get("VERSIONEYE_PROXY_HOST"); 338 | if (host != null && !host.isEmpty()){ 339 | proxyHost = host; 340 | return proxyHost; 341 | } 342 | return null; 343 | } 344 | 345 | private String fetchProxyPort(){ 346 | if (proxyPort != null && !proxyPort.isEmpty()){ 347 | return proxyPort; 348 | } 349 | try{ 350 | String propertiesPath = homeDirectory + "/.m2/" + propertiesFile; 351 | String port = getPropertyFromPath(propertiesPath, "proxyPort"); 352 | if (port != null && !port.isEmpty()){ 353 | proxyPort = port; 354 | return proxyPort; 355 | } 356 | } catch (Exception ex) { 357 | ex.printStackTrace(); 358 | } 359 | String port = System.getenv().get("VERSIONEYE_PROXY_PORT"); 360 | if (port != null && !port.isEmpty()){ 361 | proxyPort = port; 362 | return proxyPort; 363 | } 364 | return null; 365 | } 366 | 367 | private String fetchProxyUser(){ 368 | if (proxyUser != null && !proxyUser.isEmpty()){ 369 | return proxyUser; 370 | } 371 | try{ 372 | String propertiesPath = homeDirectory + "/.m2/" + propertiesFile; 373 | String user = getPropertyFromPath(propertiesPath, "proxyUser"); 374 | if (user != null && !user.isEmpty()){ 375 | proxyUser = user; 376 | return proxyUser; 377 | } 378 | } catch (Exception ex) { 379 | ex.printStackTrace(); 380 | } 381 | String user = System.getenv().get("VERSIONEYE_PROXY_USER"); 382 | if (user != null && !user.isEmpty()){ 383 | proxyUser = user; 384 | return proxyUser; 385 | } 386 | return null; 387 | } 388 | 389 | private String fetchProxyPassword(){ 390 | if (proxyPassword != null && !proxyPassword.isEmpty()){ 391 | return proxyPassword; 392 | } 393 | try{ 394 | String propertiesPath = homeDirectory + "/.m2/" + propertiesFile; 395 | String pass = getPropertyFromPath(propertiesPath, "proxyPassword"); 396 | if (pass != null && !pass.isEmpty()){ 397 | proxyPassword = pass; 398 | return proxyPassword; 399 | } 400 | } catch (Exception ex) { 401 | ex.printStackTrace(); 402 | } 403 | String password = System.getenv().get("VERSIONEYE_PROXY_PASSWORD"); 404 | if (password != null && !password.isEmpty()){ 405 | proxyPassword = password; 406 | return proxyPassword; 407 | } 408 | return null; 409 | } 410 | 411 | 412 | private String getPropertyFromPath(String propertiesPath, String propertiesKey ) throws Exception { 413 | File file = new File(propertiesPath); 414 | if (file.exists()){ 415 | PropertiesUtils propertiesUtils = new PropertiesUtils(); 416 | Properties homeProperties = propertiesUtils.readProperties(propertiesPath); 417 | return homeProperties.getProperty(propertiesKey); 418 | } else { 419 | getLog().debug("File " + propertiesPath + " does not exist"); 420 | } 421 | return null; 422 | } 423 | 424 | } 425 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | [![VersionEye Dependencies](src/site/images/VersionEyeLogo.png)](https://www.versioneye.com) 2 | 3 | [![Dependency Status](https://www.versioneye.com/user/projects/595f2eae368b080016eb8701/badge.svg?style=flat-square)](https://www.versioneye.com/user/projects/595f2eae368b080016eb8701) 4 | 5 | # VersionEye Maven Plugin 6 | 7 | The [maven](http://maven.apache.org/) plugin for [VersionEye](http://www.versioneye.com) helps you to create/update a project at VersionEye, which is a Notification System for Software Libraries. It will help you to keep your projects up-to-date and automatically notify you about outdated dependencies and license violations. You can check it out here: [www.versioneye.com](http://www.versioneye.com). 8 | 9 | Summary 10 | 11 | - [Install binary](#install-binary) 12 | - [Install from source](#install-from-source) 13 | - [Getting started](#getting-started) 14 | - [API Key](#api-key) 15 | - [mvn versioneye:create](#mvn-versioneyecreate) 16 | - [mvn versioneye:update](#mvn-versioneyeupdate) 17 | - [mvn versioneye:licenseCheck](#mvn-versioneyelicensecheck) 18 | - [mvn versioneye:securityCheck](#mvn-versioneyesecuritycheck) 19 | - [mvn versioneye:securityAndLicenseCheck](#mvn-versioneyesecurityandlicensecheck) 20 | - [mvn versioneye:delete](#mvn-versioneyedelete) 21 | - [Proxy](#proxy) 22 | - [VersionEye Enterprise](#versioneye-enterprise) 23 | - [Multi-Module Projects](#multi-module-projects) 24 | - [Configuration Options](#configuration-options) 25 | - [Feedback](#feedback) 26 | - [License](#license) 27 | 28 | ## Minimum Requirement 29 | 30 | We at VersionEye are using [LetsEncrypt](https://letsencrypt.org/) for our SSL certificates. Old Java versions don't support that certificate. The minimum required version is 8u101. More details on [StackOverflow](https://stackoverflow.com/questions/34110426/does-java-support-lets-encrypt-certificates/34111150#34111150). 31 | 32 | ## Install binary 33 | 34 | The VersionEye Maven plugin is available on the [Maven Central Repository](http://search.maven.org). 35 | That means Maven will find it automatically, without adding any other 36 | repositories! And you can find the project on [bintray](https://bintray.com/versioneye/versioneye/versioneye-maven-plugin/) 37 | as well. 38 | 39 | Switch to the project where you want to use this plugin. 40 | You can add the plugin to your project by adding this snippet to your 41 | `pom.xml` file. 42 | 43 | ```xml 44 | 45 | 46 | 47 | com.versioneye 48 | versioneye-maven-plugin 49 | 3.11.4 50 | 51 | 52 | 53 | ``` 54 | 55 | The `versioneye-maven-plugin` is tested against Maven 3.3.9. 56 | If you are using Maven 3.0.5 or older you should use the 57 | `versioneye-maven-plugin` version 2.0.1. 58 | 59 | Alternatively you can add `versioneye` to the plugin group search path. You do this by adding 60 | ```xml 61 | 62 | com.versioneye 63 | 64 | ``` 65 | 66 | to the user's Maven settings file (`~/.m2/settings.xml`). This will allow to use the `versioneye:*` 67 | command line goals interactively in all projects. 68 | 69 | ## Install from source 70 | 71 | If you wanna install the plugin from source, you have to follow this steps. 72 | 73 | ``` 74 | git clone https://github.com/versioneye/versioneye_maven_plugin.git 75 | ``` 76 | 77 | Switch to the root directory of the project: 78 | 79 | ``` 80 | cd versioneye_maven_plugin 81 | ``` 82 | 83 | And install it in your local maven repository: 84 | 85 | ``` 86 | mvn clean install 87 | ``` 88 | 89 | Now the plugin is installed on your local machine! 90 | 91 | 92 | ## Getting Started 93 | 94 | You can check out all goals like this 95 | 96 | ``` 97 | mvn versioneye:help 98 | ``` 99 | 100 | That will output all possible goals on the versioneye plugin. 101 | 102 | Now you can check if the [VersionEye API](https://www.versioneye.com/api?version=v2) is available: 103 | 104 | ``` 105 | mvn versioneye:ping 106 | ``` 107 | 108 | That should return an output like this: 109 | 110 | ``` 111 | {"success":true,"message":"pong"} 112 | ``` 113 | 114 | Now try this: 115 | 116 | ``` 117 | mvn versioneye:list 118 | ``` 119 | 120 | That will get you a list with all your direct and recursive dependencies and it will tell you how many dependencies you have in your project altogether. 121 | 122 | Here you can convert your `pom.xml` to a `pom.json` 123 | 124 | ``` 125 | mvn versioneye:json 126 | ``` 127 | 128 | It will take all your direct dependencies and convert them into `/target/pom.json`. This is just for fun! You don't really need it, but I thought it's fun to write a small `pom.xml` to `pom.json` converter :-) 129 | 130 | ## API Key 131 | 132 | This plugin can push your dependencies to the VersionEye API, create a project at VersionEye and tell you which of your dependencies are outdated. VersionEye will automatically check your project and notify you about outdated dependencies. You can use some of the resources at the VersionEye API without an *API KEY*, but for the project resource you need one. If you are [signed up](https://www.versioneye.com/signup) you can find your *API KEY* in your organisation under this structure: `https://www.versioneye.com/organisations//apikey`. 133 | 134 | ![VersionEye Dependencies](src/site/images/VersionEyeApiKey.png) 135 | 136 | Now let the versioneye-maven-plugin know what your *API KEY* is. 137 | 138 | ```xml 139 | 140 | 141 | 142 | com.versioneye 143 | versioneye-maven-plugin 144 | 3.11.4 145 | 146 | MY_SECRET_API_KEY 147 | YOUR_ORGANISATION 148 | Owners 149 | 150 | 151 | 152 | 153 | ``` 154 | 155 | If you don't want to store the api key in the `pom.xml`, alternatively you can store it in a `versioneye.properties` file. 156 | 157 | ``` 158 | echo "api_key=YOUR_API_KEY" > versioneye.properties 159 | ``` 160 | 161 | If the API Key is not set directly in the pom.xml file, the versioneye-maven-plugin will try to fetch the API Key from the `versioneye.properties` file and it will look up the file in this places: 162 | 163 | ``` 164 | /src/qa/resources/versioneye.properties 165 | ``` 166 | 167 | If it can't find the file there it will look it up at this place: 168 | 169 | ``` 170 | src/main/resources/versioneye.properties 171 | ``` 172 | 173 | If you want so you can configure another place for the versioneye.properties file. Just set the path explicitly in the pom.xml on the versioneye plugin configuration: 174 | 175 | ```xml 176 | 177 | 178 | 179 | com.versioneye 180 | versioneye-maven-plugin 181 | 3.11.4 182 | 183 | ${basedir}/versioneye.properties 184 | YOUR_ORGANISATION 185 | Owners 186 | 187 | 188 | 189 | 190 | ``` 191 | 192 | If the plugin can't find the API KEY in any of this locations it will look it up at this place: 193 | 194 | ``` 195 | ~/.m2/versioneye.properties 196 | ``` 197 | 198 | That means if you don't want to commit your *API KEY* to the server and share it with your team you can place the file in your *home* directory and keep it for you. But *don't commit this file with secret*. So add it to `.gitignore` exclusions. 199 | 200 | Of course you can store the API key in an environment variable `VERSIONEYE_API_KEY` as well. 201 | 202 | ``` 203 | export VERSIONEYE_API_KEY=my_secret_api_key 204 | ``` 205 | 206 | That's a good way to deal with the API key on an CI system. 207 | 208 | ## mvn versioneye:create 209 | 210 | If your *API KEY* is in place you can create a new project at VersionEye based on the dependencies in your `pom.xml` file with this goal: 211 | 212 | ``` 213 | mvn versioneye:create 214 | ``` 215 | 216 | This command will **not** change your local project. It just sends your dependencies to the VersionEye server and creates, based on that, a new project at [www.versioneye.com](http://www.versioneye.com). If everything went right you will see in the output the URL to your new created VersionEye project. Just copy and paste it into you browser to check it out. Here is an example how it could look like: 217 | 218 | ![VersionEye Dependencies](src/site/images/VersionEyeDependencies.png) 219 | 220 | Besides that, the plugin will add a `project_id` to the `versioneye.properties` file. The `project_id` is the connection between your `pom.xml` and the VersionEye project. If the `versioneye.properties` file doesn't exist yet, it will be created now. 221 | 222 | If you don't want that the versioneye maven plugin creates/updates the `versioneye.properties` file you can skip that step with this line in the plugin configuration: 223 | 224 | ```xml 225 | false 226 | ``` 227 | 228 | If you do so, you have to add the `project_id` by hand to the plugin configuration for the next step, the `versioneye:update` goal. 229 | 230 | ## mvn versioneye:update 231 | 232 | After you created a new project on VersionEye you can update it with the dependencies from the `pom.xml` file with this goal: 233 | 234 | ``` 235 | mvn versioneye:update 236 | ``` 237 | 238 | That will simply update the existing VersionEye project with the dependencies from your `pom.xml` file. It will **not** change your `pom.xml`. This goal usually gets executed on a Continuous Integration server after each build. 239 | 240 | By the way. If you don't like to have a `versioneye.properties` file you can set the `project_id` explicitly in the `pom.xml`. Just like this: 241 | 242 | ```xml 243 | 244 | 245 | 246 | com.versioneye 247 | versioneye-maven-plugin 248 | 3.11.4 249 | 250 | _YOUR_VERSONEYE_PROJECT_ID_ 251 | YOUR_ORGANISATION 252 | Owners 253 | 254 | 255 | 256 | 257 | ``` 258 | 259 | ## mvn versioneye:licenseCheck 260 | 261 | On VersionEye you can have [License Whitelists](http://blog.versioneye.com/2014/09/15/license-whitelist/). If you 262 | are working with License Whitelists you probably want to break the build if there is a license violation. 263 | The next goal will update your VersionEye project with the current dependencies and check them against a 264 | License Whitelist. If there is a violation of the License Whitelist this goal will break your build: 265 | 266 | ``` 267 | mvn versioneye:licenseCheck 268 | ``` 269 | 270 | ## mvn versioneye:securityCheck 271 | 272 | This goald will check if your dependencies have known security vulnerabilities: 273 | 274 | ``` 275 | mvn versioneye:securityCheck 276 | ``` 277 | 278 | If one of project dependencies has a known security vulnerability this goal will break your build! 279 | 280 | ## mvn versioneye:securityAndLicenseCheck 281 | 282 | This goald will check if your dependencies have known security vulnerabilities or if they violate the license whitelist on the server: 283 | 284 | ``` 285 | mvn versioneye:securityAndLicenseCheck 286 | ``` 287 | 288 | If one of the 2 is violated this goal will break your build! 289 | 290 | ## mvn versioneye:delete 291 | 292 | This goal will delete the project from the VersionEye server: 293 | 294 | ``` 295 | mvn versioneye:delete 296 | ``` 297 | 298 | This golad will also remove all related `versioneye.properties` files! 299 | 300 | ## Proxy 301 | 302 | Please configure the proxy settings directly in the configuration of the 303 | VersionEye Maven Plugin: 304 | 305 | ```xml 306 | 307 | 308 | 309 | com.versioneye 310 | versioneye-maven-plugin 311 | 3.11.4 312 | 313 | 127.0.0.1 314 | 8888 315 | proxy_hopsi 316 | dont_tell_anybody 317 | 318 | 319 | 320 | 321 | ``` 322 | 323 | If the proxy settings are defined in the pom.xml file the plugin will check these 324 | global environment variables: 325 | 326 | - VERSIONEYE_PROXY_HOST 327 | - VERSIONEYE_PROXY_PORT 328 | - VERSIONEYE_PROXY_USER 329 | - VERSIONEYE_PROXY_PASSWORD 330 | 331 | If you don't want to store the proxy settings in the source code you should use 332 | the environment variables above. 333 | 334 | Generally a proxy for Maven can be configured in the `${user.home}/.m2/settings.xml)` 335 | file like described here: https://maven.apache.org/guides/mini/guide-proxies.html. 336 | 337 | 338 | ## VersionEye Enterprise 339 | 340 | If you are using the VersionEye Enterprise VM in your own private network you probably want to use this plugin against the VersionEye Enterprise API. In that case you can change the baseUrl with this line: 341 | 342 | 343 | ```xml 344 | http://versioneye.my-company.com 345 | ``` 346 | The whole plugin snippet would look similar to this one. 347 | 348 | ```xml 349 | 350 | 351 | 352 | com.versioneye 353 | versioneye-maven-plugin 354 | 3.11.4 355 | 356 | http://versioneye.my-company.com 357 | _YOUR_VERSONEYE_PROJECT_ID_ 358 | YOUR_ORGANISATION 359 | Owners 360 | 361 | 362 | 363 | 364 | ``` 365 | 366 | ## Multi-Module Projects 367 | 368 | Assume you have a big Java Enterprise multi-module project with Maven and you want to have all modules monitored by VersionEye. I further assume that all modules have the same parent pom and the modules are listed in the parent pom.xml file. In that case all you have to do is configuring the VersionEye Maven Plugin once in the parent pom. 369 | 370 | ```xml 371 | 372 | 373 | 374 | com.versioneye 375 | versioneye-maven-plugin 376 | 3.11.4 377 | 378 | MY_SECRET_API_KEY 379 | YOUR_ORGANISATION 380 | Owners 381 | 382 | 383 | 384 | 385 | ``` 386 | 387 | Now run this command in the parent directory: 388 | 389 | ``` 390 | mvn versioneye:create 391 | ``` 392 | 393 | This command will be executed on each module. The plugin will create for each module a new project on VersionEye. Beside that the plugin will create for each module a `versioneye.properties` file with the corresponding project_id. The file will be created/updated in the `src/main/resources` directory of each module. 394 | 395 | After the projects are created on VersionEye we don't need the `create` goal anymore. Now we can perform the `update` goal on each build. 396 | 397 | ``` 398 | mvn versioneye:update 399 | ``` 400 | 401 | This will update the project on VersionEye with the current dependencies in the modules pom.xml file. Executing this command in the parent pom directory will update all modules. Ideally this goal is executed on the Continuous Integration System after each build. 402 | 403 | Here is a YouTube video which demonstrates how to setup a multi-module project with the VersionEye Maven Plugin. 404 | 405 | [![VersionEye Maven Plugin Video](src/site/images/VersionEyeMavenPlugin.png)](http://www.youtube.com/watch?v=JPVEuqGHbeU) 406 | 407 | ## Configuration Options 408 | 409 | The VersionEye Maven Plugin has many configuration options. 410 | 411 | ```xml 412 | 413 | com.versioneye 414 | versioneye-maven-plugin 415 | 3.11.4 416 | 417 | 544d0ff9512592562c000003 418 | 419 | 420 | 421 | 422 | 423 | 424 | 425 | 426 | 427 | 428 | 429 | 430 | 431 | 432 | 433 | 434 | 435 | 436 | 437 | 438 | 439 | 440 | ``` 441 | Here is a more detailed documentation of the configuration options. 442 | 443 | Config option | Description 444 | ------------- | ----------- 445 | apiKey | Your secret API Key for the VersionEye API. Get it here: [https://www.versioneye.com/settings/api](https://www.versioneye.com/settings/api) 446 | baseUrl | Set the base URL for the VersionEye API. Only needed for VersionEye Enterprise! 447 | proxyHost | Set your proxy host name or IP. 448 | proxyPort | Set your proxy port here. 449 | proxyUser | Set you proxy user name here. 450 | proxyPassword | Set your proxy password here. 451 | updatePropertiesAfterCreate | This is related to this [issue](https://github.com/versioneye/versioneye_maven_plugin/issues/34) 452 | mergeAfterCreate | If the plugin is executed on a multi module project, the plugin will merge all submodules into the parent project by default. If this behaviour is not desired it can be switched off with this configuraiton option! 453 | parentGroupId | If the plugin is executed on a multi module project, the plugin will merge all submodules into the parent project on the server. the parent project is determined from the pom.xml. However it is possible to set the group_id of the parent project exeplicitly! That way the submodules can be merged into any other Java project at VersionEye. 454 | parentArtifactId | If the plugin is executed on a multi module project, the plugin will merge all submodules into the parent project on the server. the parent project is determined from the pom.xml. However it is possible to set the artifact_id of the parent project exeplicitly! That way the submodules can be merged into any other Java project at VersionEye. 455 | nameStrategy | If a new project is created the plugin will take the `name` attribute from the pom.xml as the name of the project at VersionEye. Other naming strategies are possible
  • GA: Takes "GroupID / ArtifactID" as name
  • artifact_id: Takes the "ArtifactID" as name
The project name can be changed on the server afterwards and is not needed to identify a project! 456 | trackPlugins | By default the plugins who are defined in the pom.xml file are handled like regular dependencies with the "plugin" scope. Plugins can be ignored by setting this property to "false". 457 | licenseCheckBreakByUnknown | If this is true then the goal "versioneye:licenseCheck" will break the build if there is a component without any license. 458 | skipScopes | Comma seperated list of scopes which should be ignored by this plugin. 459 | organisation | The name of an organisation at VersionEye. If this is set the project will be assigend to that organisation! 460 | team | The name of the team inside the organisation at VersionEye. If this is set the project will be assigend to that team! The team which is defined here has to exist in the organisation which is defined here! 461 | name | With this property you can set explicitly the name of the VersionEye project. 462 | visibility | 'public' of 'private'. Controls if the project on VersionEye will be public or private. 463 | propertiesPath | The path to the versioneye.properties file. By default it is "/src/main/resources/" 464 | ignoreDependencyManagement | If this attribute is true the dependencies from "DependencyManagement" are ignored. By default it is false! 465 | transitiveDependencies | Resolve and send transitive dependencies to the VersionEye API. In this mode the properties `ignoreDependencyManagement` and `skipScopes` does not work. The transitive dependencies are always with RUNTIME scope. That means that scopes like TEST and PROVIDED are excluded. 466 | 467 | 468 | ## Feedback 469 | 470 | For bugs and feature requests please use the [ticket system](https://github.com/versioneye/versioneye_maven_plugin/issues). Pull Requests are welcome ;-) 471 | 472 | ## Support 473 | 474 | For commercial support send a message to `support@versioneye.com`. 475 | 476 | ## License 477 | 478 | VersionEye-Core is licensed under the MIT license! 479 | 480 | Copyright (c) 2016 VersionEye GmbH 481 | 482 | Permission is hereby granted, free of charge, to any person obtaining a copy 483 | of this software and associated documentation files (the "Software"), to deal 484 | in the Software without restriction, including without limitation the rights 485 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 486 | copies of the Software, and to permit persons to whom the Software is 487 | furnished to do so, subject to the following conditions: 488 | 489 | The above copyright notice and this permission notice shall be included in all 490 | copies or substantial portions of the Software. 491 | 492 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 493 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 494 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 495 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 496 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 497 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 498 | SOFTWARE. 499 | --------------------------------------------------------------------------------