BazelDependencyFormatter implements DependencySynonymFormatter { @Override public String getDependencySnippet(ArtifactCoordinates artifactCoordinates) { MavenArtifactCoordinates coordinates = (MavenArtifactCoordinates) artifactCoordinates; return "maven_jar(" +"\n"+" name ="+" " +"\""+coordinates.getArtifactId()+"\""+","+ (coordinates.getArtifactId() != null && coordinates.getGroupId() != null && coordinates.getVersion() != null ? "\n artifact = " + "\""+ coordinates.getGroupId()+":"+coordinates.getArtifactId()+":"+coordinates.getVersion()+"\""+",\n)\n": "\n)\n"); }  @PostConstruct @Override void register(); @Override String getLayout(); String getFormatAlias(); @Override String getDependencySnippet(ArtifactCoordinates artifactCoordinates); static final String ALIAS; }
@Test public void testBazelDependencyGeneration() throws ProviderImplementationException { DependencySynonymFormatter formatter = compatibleDependencyFormatRegistry.getProviderImplementation( Maven2LayoutProvider.ALIAS, BazelDependencyFormatter.ALIAS); assertThat(formatter).as("Failed to look up dependency synonym formatter!").isNotNull(); MavenArtifactCoordinates coordinates = new MavenArtifactCoordinates(); coordinates.setGroupId("org.carlspring.strongbox"); coordinates.setArtifactId("maven-snippet"); coordinates.setVersion("1.0"); coordinates.setExtension("jar"); String snippet = formatter.getDependencySnippet(coordinates); System.out.print(snippet); assertThat("maven_jar(\n name = \"maven-snippet\"," + "\n artifact = \"org.carlspring.strongbox:maven-snippet:1.0\",\n)\n") .as("Failed to generate dependency!") .isEqualTo(snippet); }
@Test public void testBazelDependencyGenerationWithoutArtifactField() throws ProviderImplementationException { DependencySynonymFormatter formatter = compatibleDependencyFormatRegistry.getProviderImplementation( Maven2LayoutProvider.ALIAS, BazelDependencyFormatter.ALIAS); assertThat(formatter).as("Failed to look up dependency synonym formatter!").isNotNull(); MavenArtifactCoordinates coordinates = new MavenArtifactCoordinates() { @Override public String getArtifactId() { return "maven-snippet"; } }; String snippet = formatter.getDependencySnippet(coordinates); System.out.print(snippet); assertThat("maven_jar(\n name = \"maven-snippet\",\n)\n") .as("Failed to generate dependency!").isEqualTo(snippet); }