@Test public void initNoArgs() throws Exception { File projDir = resources.getBasedir("parent-with-jar"); MavenExecution mavenExec = verifier.forProject(projDir) .withCliOption("-e"); final String srcdepsVersion = Constants.SRCDEPS_MAVEN_VERSION; Assert.assertEquals(projectVersion, srcdepsVersion); final File srcdepsYamlPath = new File(projDir, "srcdeps.yaml"); Assert.assertFalse( String.format("The file [%s] must not exist before the test", srcdepsYamlPath.getAbsolutePath()), srcdepsYamlPath.exists()); final File extensionsXmlPath = new File(projDir, ".mvn/extensions.xml"); Assert.assertFalse( String.format("The file [%s] must not exist before the test", extensionsXmlPath.getAbsolutePath()), extensionsXmlPath.exists()); mavenExec .execute("org.srcdeps.mvn:srcdeps-maven-plugin:" + projectVersion + ":init") .assertErrorFreeLog(); String srcdepsYamlContent = new String(Files.readAllBytes(srcdepsYamlPath.toPath()), "utf-8"); Assert.assertEquals(SRCDEPS_YAML_EXPECTED, srcdepsYamlContent); String extensionsXmlContent = new String(Files.readAllBytes(extensionsXmlPath.toPath()), "utf-8"); Assert.assertEquals(String.format(EXTENSIONS_XML_TEMPLATE, srcdepsVersion, srcdepsVersion), extensionsXmlContent); }
@Override public void execute() throws MojoExecutionException, MojoFailureException { super.execute(); org.srcdeps.core.GavSet.Builder gavSetBuilder = GavSet.builder() .includes(includes) .excludes(excludes); if (excludeSnapshots) { gavSetBuilder.excludeSnapshots(); } this.gavSet = gavSetBuilder.build(); log.info("srcdeps: Using includes and excludes [{}]", gavSet); log.info("srcdeps: Supported SCMs: [{}]", scms); if (skip) { log.info("srcdeps: ["+ getClass().getSimpleName() + "] skipped per skip parameter"); } else if (!multiModuleRootDir.equals(session.getCurrentProject().getBasedir())) { log.info("srcdeps: ["+ getClass().getSimpleName() + "] skipped because multiModuleRootDir ["+ multiModuleRootDir +"] != current project basedir ["+ session.getCurrentProject().getBasedir() +"]"); } else { Configuration.Builder config = Configuration.builder() .configModelVersion(Configuration.getLatestConfigModelVersion()).commentBefore("") .commentBefore("srcdeps.yaml - the srcdeps configuration file") .commentBefore("") .commentBefore( "The full srcdeps.yaml reference can be found under https: .commentBefore("") .commentBefore("This file was generated by the following command:") .commentBefore("") .commentBefore(" mvn org.srcdeps.mvn:srcdeps-maven-plugin:init") .commentBefore("") ; ScmRepositoryIndex index = new ScmRepositoryIndex(session, repoSession, repositorySystem, projectBuilder, scms); log.debug("srcdeps: Going over [{}] reactor projects", reactorProjects.size()); for (MavenProject project : reactorProjects) { index.ignoreGav(project.getGroupId(), project.getArtifactId(), project.getVersion()); } for (MavenProject project : reactorProjects) { final List<Dependency> dependencies = project.getDependencies(); log.info("srcdeps: Project [{}] has [{}] dependencies", project.getArtifactId(), dependencies == null ? 0 : dependencies.size()); if (dependencies != null) { for (Dependency dependency : dependencies) { final String g = dependency.getGroupId(); final String a = dependency.getArtifactId(); final String v = dependency.getVersion(); if (!"system".equals(dependency.getScope()) && gavSet.contains(g, a, v)) { index.addGav(g, a, v, failOnUnresolvable); } } } final DependencyManagement dependencyManagement = project.getDependencyManagement(); if (dependencyManagement != null) { final List<Dependency> managedDeps = dependencyManagement.getDependencies(); if (managedDeps != null) { for (Dependency dependency : managedDeps) { final String g = dependency.getGroupId(); final String a = dependency.getArtifactId(); final String v = dependency.getVersion(); if (!"system".equals(dependency.getScope()) && gavSet.contains(g, a, v)) { index.addGav(g, a, v, false); } } } } MavenProject parent = project.getParent(); if (parent != null) { final String g = parent.getGroupId(); final String a = parent.getArtifactId(); final String v = parent.getVersion(); if (gavSet.contains(g, a, v)) { index.addGav(g, a, v, failOnUnresolvable); } } } Map<String, Builder> repos = index.createSortedScmRepositoryMap(); if (repos.size() == 0) { ScmRepository.Builder dummyRepo = ScmRepository.builder() .commentBefore( "FIXME: srcdeps-maven-plugin could not authomatically identify any SCM URLs for dependencies in this project") .commentBefore( " and has added this dummy repository only as a starting point for you to proceed manually") .id("org.my-group") .include("org.my-group") .url("git:https: ; repos.put(dummyRepo.getName(), dummyRepo); } config .repositories(repos) .accept(new OverrideVisitor(System.getProperties())) .accept(new DefaultsAndInheritanceVisitor()) ; final Path srcdepsYamlPath = multiModuleRootDir.toPath().resolve("srcdeps.yaml"); try { YamlWriterConfiguration yamlWriterConfiguration = YamlWriterConfiguration.builder().build(); try (Writer out = Files.newBufferedWriter(srcdepsYamlPath, Charset.forName(encoding))) { config.accept(new YamlWriterVisitor(out, yamlWriterConfiguration)); } } catch (IOException e) { throw new MojoExecutionException(String.format("Could not write [%s]", srcdepsYamlPath), e); } } }
SrcdepsInitMojo extends SrcdepsUpgradeMojo { @Override public void execute() throws MojoExecutionException, MojoFailureException { super.execute(); org.srcdeps.core.GavSet.Builder gavSetBuilder = GavSet.builder() .includes(includes) .excludes(excludes); if (excludeSnapshots) { gavSetBuilder.excludeSnapshots(); } this.gavSet = gavSetBuilder.build(); log.info("srcdeps: Using includes and excludes [{}]", gavSet); log.info("srcdeps: Supported SCMs: [{}]", scms); if (skip) { log.info("srcdeps: ["+ getClass().getSimpleName() + "] skipped per skip parameter"); } else if (!multiModuleRootDir.equals(session.getCurrentProject().getBasedir())) { log.info("srcdeps: ["+ getClass().getSimpleName() + "] skipped because multiModuleRootDir ["+ multiModuleRootDir +"] != current project basedir ["+ session.getCurrentProject().getBasedir() +"]"); } else { Configuration.Builder config = Configuration.builder() .configModelVersion(Configuration.getLatestConfigModelVersion()).commentBefore("") .commentBefore("srcdeps.yaml - the srcdeps configuration file") .commentBefore("") .commentBefore( "The full srcdeps.yaml reference can be found under https: .commentBefore("") .commentBefore("This file was generated by the following command:") .commentBefore("") .commentBefore(" mvn org.srcdeps.mvn:srcdeps-maven-plugin:init") .commentBefore("") ; ScmRepositoryIndex index = new ScmRepositoryIndex(session, repoSession, repositorySystem, projectBuilder, scms); log.debug("srcdeps: Going over [{}] reactor projects", reactorProjects.size()); for (MavenProject project : reactorProjects) { index.ignoreGav(project.getGroupId(), project.getArtifactId(), project.getVersion()); } for (MavenProject project : reactorProjects) { final List<Dependency> dependencies = project.getDependencies(); log.info("srcdeps: Project [{}] has [{}] dependencies", project.getArtifactId(), dependencies == null ? 0 : dependencies.size()); if (dependencies != null) { for (Dependency dependency : dependencies) { final String g = dependency.getGroupId(); final String a = dependency.getArtifactId(); final String v = dependency.getVersion(); if (!"system".equals(dependency.getScope()) && gavSet.contains(g, a, v)) { index.addGav(g, a, v, failOnUnresolvable); } } } final DependencyManagement dependencyManagement = project.getDependencyManagement(); if (dependencyManagement != null) { final List<Dependency> managedDeps = dependencyManagement.getDependencies(); if (managedDeps != null) { for (Dependency dependency : managedDeps) { final String g = dependency.getGroupId(); final String a = dependency.getArtifactId(); final String v = dependency.getVersion(); if (!"system".equals(dependency.getScope()) && gavSet.contains(g, a, v)) { index.addGav(g, a, v, false); } } } } MavenProject parent = project.getParent(); if (parent != null) { final String g = parent.getGroupId(); final String a = parent.getArtifactId(); final String v = parent.getVersion(); if (gavSet.contains(g, a, v)) { index.addGav(g, a, v, failOnUnresolvable); } } } Map<String, Builder> repos = index.createSortedScmRepositoryMap(); if (repos.size() == 0) { ScmRepository.Builder dummyRepo = ScmRepository.builder() .commentBefore( "FIXME: srcdeps-maven-plugin could not authomatically identify any SCM URLs for dependencies in this project") .commentBefore( " and has added this dummy repository only as a starting point for you to proceed manually") .id("org.my-group") .include("org.my-group") .url("git:https: ; repos.put(dummyRepo.getName(), dummyRepo); } config .repositories(repos) .accept(new OverrideVisitor(System.getProperties())) .accept(new DefaultsAndInheritanceVisitor()) ; final Path srcdepsYamlPath = multiModuleRootDir.toPath().resolve("srcdeps.yaml"); try { YamlWriterConfiguration yamlWriterConfiguration = YamlWriterConfiguration.builder().build(); try (Writer out = Files.newBufferedWriter(srcdepsYamlPath, Charset.forName(encoding))) { config.accept(new YamlWriterVisitor(out, yamlWriterConfiguration)); } } catch (IOException e) { throw new MojoExecutionException(String.format("Could not write [%s]", srcdepsYamlPath), e); } } } }
SrcdepsInitMojo extends SrcdepsUpgradeMojo { @Override public void execute() throws MojoExecutionException, MojoFailureException { super.execute(); org.srcdeps.core.GavSet.Builder gavSetBuilder = GavSet.builder() .includes(includes) .excludes(excludes); if (excludeSnapshots) { gavSetBuilder.excludeSnapshots(); } this.gavSet = gavSetBuilder.build(); log.info("srcdeps: Using includes and excludes [{}]", gavSet); log.info("srcdeps: Supported SCMs: [{}]", scms); if (skip) { log.info("srcdeps: ["+ getClass().getSimpleName() + "] skipped per skip parameter"); } else if (!multiModuleRootDir.equals(session.getCurrentProject().getBasedir())) { log.info("srcdeps: ["+ getClass().getSimpleName() + "] skipped because multiModuleRootDir ["+ multiModuleRootDir +"] != current project basedir ["+ session.getCurrentProject().getBasedir() +"]"); } else { Configuration.Builder config = Configuration.builder() .configModelVersion(Configuration.getLatestConfigModelVersion()).commentBefore("") .commentBefore("srcdeps.yaml - the srcdeps configuration file") .commentBefore("") .commentBefore( "The full srcdeps.yaml reference can be found under https: .commentBefore("") .commentBefore("This file was generated by the following command:") .commentBefore("") .commentBefore(" mvn org.srcdeps.mvn:srcdeps-maven-plugin:init") .commentBefore("") ; ScmRepositoryIndex index = new ScmRepositoryIndex(session, repoSession, repositorySystem, projectBuilder, scms); log.debug("srcdeps: Going over [{}] reactor projects", reactorProjects.size()); for (MavenProject project : reactorProjects) { index.ignoreGav(project.getGroupId(), project.getArtifactId(), project.getVersion()); } for (MavenProject project : reactorProjects) { final List<Dependency> dependencies = project.getDependencies(); log.info("srcdeps: Project [{}] has [{}] dependencies", project.getArtifactId(), dependencies == null ? 0 : dependencies.size()); if (dependencies != null) { for (Dependency dependency : dependencies) { final String g = dependency.getGroupId(); final String a = dependency.getArtifactId(); final String v = dependency.getVersion(); if (!"system".equals(dependency.getScope()) && gavSet.contains(g, a, v)) { index.addGav(g, a, v, failOnUnresolvable); } } } final DependencyManagement dependencyManagement = project.getDependencyManagement(); if (dependencyManagement != null) { final List<Dependency> managedDeps = dependencyManagement.getDependencies(); if (managedDeps != null) { for (Dependency dependency : managedDeps) { final String g = dependency.getGroupId(); final String a = dependency.getArtifactId(); final String v = dependency.getVersion(); if (!"system".equals(dependency.getScope()) && gavSet.contains(g, a, v)) { index.addGav(g, a, v, false); } } } } MavenProject parent = project.getParent(); if (parent != null) { final String g = parent.getGroupId(); final String a = parent.getArtifactId(); final String v = parent.getVersion(); if (gavSet.contains(g, a, v)) { index.addGav(g, a, v, failOnUnresolvable); } } } Map<String, Builder> repos = index.createSortedScmRepositoryMap(); if (repos.size() == 0) { ScmRepository.Builder dummyRepo = ScmRepository.builder() .commentBefore( "FIXME: srcdeps-maven-plugin could not authomatically identify any SCM URLs for dependencies in this project") .commentBefore( " and has added this dummy repository only as a starting point for you to proceed manually") .id("org.my-group") .include("org.my-group") .url("git:https: ; repos.put(dummyRepo.getName(), dummyRepo); } config .repositories(repos) .accept(new OverrideVisitor(System.getProperties())) .accept(new DefaultsAndInheritanceVisitor()) ; final Path srcdepsYamlPath = multiModuleRootDir.toPath().resolve("srcdeps.yaml"); try { YamlWriterConfiguration yamlWriterConfiguration = YamlWriterConfiguration.builder().build(); try (Writer out = Files.newBufferedWriter(srcdepsYamlPath, Charset.forName(encoding))) { config.accept(new YamlWriterVisitor(out, yamlWriterConfiguration)); } } catch (IOException e) { throw new MojoExecutionException(String.format("Could not write [%s]", srcdepsYamlPath), e); } } } @Inject  SrcdepsInitMojo(Set<org.srcdeps.core.Scm> scms); }
SrcdepsInitMojo extends SrcdepsUpgradeMojo { @Override public void execute() throws MojoExecutionException, MojoFailureException { super.execute(); org.srcdeps.core.GavSet.Builder gavSetBuilder = GavSet.builder() .includes(includes) .excludes(excludes); if (excludeSnapshots) { gavSetBuilder.excludeSnapshots(); } this.gavSet = gavSetBuilder.build(); log.info("srcdeps: Using includes and excludes [{}]", gavSet); log.info("srcdeps: Supported SCMs: [{}]", scms); if (skip) { log.info("srcdeps: ["+ getClass().getSimpleName() + "] skipped per skip parameter"); } else if (!multiModuleRootDir.equals(session.getCurrentProject().getBasedir())) { log.info("srcdeps: ["+ getClass().getSimpleName() + "] skipped because multiModuleRootDir ["+ multiModuleRootDir +"] != current project basedir ["+ session.getCurrentProject().getBasedir() +"]"); } else { Configuration.Builder config = Configuration.builder() .configModelVersion(Configuration.getLatestConfigModelVersion()).commentBefore("") .commentBefore("srcdeps.yaml - the srcdeps configuration file") .commentBefore("") .commentBefore( "The full srcdeps.yaml reference can be found under https: .commentBefore("") .commentBefore("This file was generated by the following command:") .commentBefore("") .commentBefore(" mvn org.srcdeps.mvn:srcdeps-maven-plugin:init") .commentBefore("") ; ScmRepositoryIndex index = new ScmRepositoryIndex(session, repoSession, repositorySystem, projectBuilder, scms); log.debug("srcdeps: Going over [{}] reactor projects", reactorProjects.size()); for (MavenProject project : reactorProjects) { index.ignoreGav(project.getGroupId(), project.getArtifactId(), project.getVersion()); } for (MavenProject project : reactorProjects) { final List<Dependency> dependencies = project.getDependencies(); log.info("srcdeps: Project [{}] has [{}] dependencies", project.getArtifactId(), dependencies == null ? 0 : dependencies.size()); if (dependencies != null) { for (Dependency dependency : dependencies) { final String g = dependency.getGroupId(); final String a = dependency.getArtifactId(); final String v = dependency.getVersion(); if (!"system".equals(dependency.getScope()) && gavSet.contains(g, a, v)) { index.addGav(g, a, v, failOnUnresolvable); } } } final DependencyManagement dependencyManagement = project.getDependencyManagement(); if (dependencyManagement != null) { final List<Dependency> managedDeps = dependencyManagement.getDependencies(); if (managedDeps != null) { for (Dependency dependency : managedDeps) { final String g = dependency.getGroupId(); final String a = dependency.getArtifactId(); final String v = dependency.getVersion(); if (!"system".equals(dependency.getScope()) && gavSet.contains(g, a, v)) { index.addGav(g, a, v, false); } } } } MavenProject parent = project.getParent(); if (parent != null) { final String g = parent.getGroupId(); final String a = parent.getArtifactId(); final String v = parent.getVersion(); if (gavSet.contains(g, a, v)) { index.addGav(g, a, v, failOnUnresolvable); } } } Map<String, Builder> repos = index.createSortedScmRepositoryMap(); if (repos.size() == 0) { ScmRepository.Builder dummyRepo = ScmRepository.builder() .commentBefore( "FIXME: srcdeps-maven-plugin could not authomatically identify any SCM URLs for dependencies in this project") .commentBefore( " and has added this dummy repository only as a starting point for you to proceed manually") .id("org.my-group") .include("org.my-group") .url("git:https: ; repos.put(dummyRepo.getName(), dummyRepo); } config .repositories(repos) .accept(new OverrideVisitor(System.getProperties())) .accept(new DefaultsAndInheritanceVisitor()) ; final Path srcdepsYamlPath = multiModuleRootDir.toPath().resolve("srcdeps.yaml"); try { YamlWriterConfiguration yamlWriterConfiguration = YamlWriterConfiguration.builder().build(); try (Writer out = Files.newBufferedWriter(srcdepsYamlPath, Charset.forName(encoding))) { config.accept(new YamlWriterVisitor(out, yamlWriterConfiguration)); } } catch (IOException e) { throw new MojoExecutionException(String.format("Could not write [%s]", srcdepsYamlPath), e); } } } @Inject  SrcdepsInitMojo(Set<org.srcdeps.core.Scm> scms); @Override void execute(); }
SrcdepsInitMojo extends SrcdepsUpgradeMojo { @Override public void execute() throws MojoExecutionException, MojoFailureException { super.execute(); org.srcdeps.core.GavSet.Builder gavSetBuilder = GavSet.builder() .includes(includes) .excludes(excludes); if (excludeSnapshots) { gavSetBuilder.excludeSnapshots(); } this.gavSet = gavSetBuilder.build(); log.info("srcdeps: Using includes and excludes [{}]", gavSet); log.info("srcdeps: Supported SCMs: [{}]", scms); if (skip) { log.info("srcdeps: ["+ getClass().getSimpleName() + "] skipped per skip parameter"); } else if (!multiModuleRootDir.equals(session.getCurrentProject().getBasedir())) { log.info("srcdeps: ["+ getClass().getSimpleName() + "] skipped because multiModuleRootDir ["+ multiModuleRootDir +"] != current project basedir ["+ session.getCurrentProject().getBasedir() +"]"); } else { Configuration.Builder config = Configuration.builder() .configModelVersion(Configuration.getLatestConfigModelVersion()).commentBefore("") .commentBefore("srcdeps.yaml - the srcdeps configuration file") .commentBefore("") .commentBefore( "The full srcdeps.yaml reference can be found under https: .commentBefore("") .commentBefore("This file was generated by the following command:") .commentBefore("") .commentBefore(" mvn org.srcdeps.mvn:srcdeps-maven-plugin:init") .commentBefore("") ; ScmRepositoryIndex index = new ScmRepositoryIndex(session, repoSession, repositorySystem, projectBuilder, scms); log.debug("srcdeps: Going over [{}] reactor projects", reactorProjects.size()); for (MavenProject project : reactorProjects) { index.ignoreGav(project.getGroupId(), project.getArtifactId(), project.getVersion()); } for (MavenProject project : reactorProjects) { final List<Dependency> dependencies = project.getDependencies(); log.info("srcdeps: Project [{}] has [{}] dependencies", project.getArtifactId(), dependencies == null ? 0 : dependencies.size()); if (dependencies != null) { for (Dependency dependency : dependencies) { final String g = dependency.getGroupId(); final String a = dependency.getArtifactId(); final String v = dependency.getVersion(); if (!"system".equals(dependency.getScope()) && gavSet.contains(g, a, v)) { index.addGav(g, a, v, failOnUnresolvable); } } } final DependencyManagement dependencyManagement = project.getDependencyManagement(); if (dependencyManagement != null) { final List<Dependency> managedDeps = dependencyManagement.getDependencies(); if (managedDeps != null) { for (Dependency dependency : managedDeps) { final String g = dependency.getGroupId(); final String a = dependency.getArtifactId(); final String v = dependency.getVersion(); if (!"system".equals(dependency.getScope()) && gavSet.contains(g, a, v)) { index.addGav(g, a, v, false); } } } } MavenProject parent = project.getParent(); if (parent != null) { final String g = parent.getGroupId(); final String a = parent.getArtifactId(); final String v = parent.getVersion(); if (gavSet.contains(g, a, v)) { index.addGav(g, a, v, failOnUnresolvable); } } } Map<String, Builder> repos = index.createSortedScmRepositoryMap(); if (repos.size() == 0) { ScmRepository.Builder dummyRepo = ScmRepository.builder() .commentBefore( "FIXME: srcdeps-maven-plugin could not authomatically identify any SCM URLs for dependencies in this project") .commentBefore( " and has added this dummy repository only as a starting point for you to proceed manually") .id("org.my-group") .include("org.my-group") .url("git:https: ; repos.put(dummyRepo.getName(), dummyRepo); } config .repositories(repos) .accept(new OverrideVisitor(System.getProperties())) .accept(new DefaultsAndInheritanceVisitor()) ; final Path srcdepsYamlPath = multiModuleRootDir.toPath().resolve("srcdeps.yaml"); try { YamlWriterConfiguration yamlWriterConfiguration = YamlWriterConfiguration.builder().build(); try (Writer out = Files.newBufferedWriter(srcdepsYamlPath, Charset.forName(encoding))) { config.accept(new YamlWriterVisitor(out, yamlWriterConfiguration)); } } catch (IOException e) { throw new MojoExecutionException(String.format("Could not write [%s]", srcdepsYamlPath), e); } } } @Inject  SrcdepsInitMojo(Set<org.srcdeps.core.Scm> scms); @Override void execute();  }