下面列出了怎么用org.apache.maven.plugin.logging.SystemStreamLog的API类实例代码及写法,或者点击链接到github查看源代码。
@Test
public void testEmpty() throws PackagingException, IOException {
AbstractVertxMojo mojo = mock(AbstractVertxMojo.class);
when(mojo.getLog()).thenReturn(new SystemStreamLog());
Archive archive = new Archive();
archive.setIncludeClasses(false);
File output = new File(out, "test-empty.jar");
PackageConfig config = new PackageConfig()
.setMojo(mojo)
.setOutput(output)
.setArchive(archive);
service.doPackage(config);
assertThat(output).isFile();
JarFile jar = new JarFile(output);
List<String> list = jar.stream().map(ZipEntry::getName)
.filter(s -> ! s.endsWith("/")) // Directories
.collect(Collectors.toList());
assertThat(list).containsExactly("META-INF/MANIFEST.MF");
}
@Test
public void testEmbeddingDependencies() throws IOException, PackagingException {
AbstractVertxMojo mojo = mock(AbstractVertxMojo.class);
when(mojo.getLog()).thenReturn(new SystemStreamLog());
Archive archive = new Archive();
archive.setIncludeClasses(false);
archive.setDependencySets(ImmutableList.of(new DependencySet()));
Set<Artifact> artifacts = ImmutableSet.of(getFirstArtifact(), getSecondArtifact());
File output = new File(out, "test-all-dependencies.jar");
PackageConfig config = new PackageConfig()
.setMojo(mojo)
.setOutput(output)
.setArtifacts(artifacts)
.setArchive(archive);
service.doPackage(config);
assertThat(output).isFile();
JarFile jar = new JarFile(output);
List<String> list = jar.stream().map(ZipEntry::getName)
.filter(s -> ! s.endsWith("/")) // Directories
.collect(Collectors.toList());
assertThat(list).containsOnly("META-INF/MANIFEST.MF", "testconfig.yaml", "out/some-config.yaml");
}
@Test
public void testEmbeddingDependenciesUsingInclusion() throws IOException, PackagingException {
AbstractVertxMojo mojo = mock(AbstractVertxMojo.class);
when(mojo.getLog()).thenReturn(new SystemStreamLog());
Archive archive = new Archive();
archive.setIncludeClasses(false);
archive.setDependencySets(ImmutableList.of(new DependencySet().addInclude("org.acme:jar1")));
Set<Artifact> artifacts = ImmutableSet.of(getFirstArtifact(), getSecondArtifact());
File output = new File(out, "test-inclusion.jar");
PackageConfig config = new PackageConfig()
.setMojo(mojo)
.setOutput(output)
.setArtifacts(artifacts)
.setArchive(archive);
service.doPackage(config);
assertThat(output).isFile();
JarFile jar = new JarFile(output);
List<String> list = jar.stream().map(ZipEntry::getName)
.filter(s -> ! s.endsWith("/")) // Directories
.collect(Collectors.toList());
assertThat(list).contains("META-INF/MANIFEST.MF", "testconfig.yaml").hasSize(2);
}
@Test
public void testEmbeddingDependenciesUsingExclusion() throws IOException, PackagingException {
AbstractVertxMojo mojo = mock(AbstractVertxMojo.class);
when(mojo.getLog()).thenReturn(new SystemStreamLog());
Archive archive = new Archive();
archive.setIncludeClasses(false);
archive.setDependencySets(ImmutableList.of(new DependencySet().addExclude("org.acme:jar2")));
Set<Artifact> artifacts = ImmutableSet.of(getFirstArtifact(), getSecondArtifact());
File output = new File(out, "test-exclusion.jar");
PackageConfig config = new PackageConfig()
.setMojo(mojo)
.setOutput(output)
.setArtifacts(artifacts)
.setArchive(archive);
service.doPackage(config);
assertThat(output).isFile();
JarFile jar = new JarFile(output);
List<String> list = jar.stream().map(ZipEntry::getName)
.filter(s -> ! s.endsWith("/")) // Directories
.collect(Collectors.toList());
assertThat(list).contains("META-INF/MANIFEST.MF", "testconfig.yaml").hasSize(2);
}
@Test
public void assemblyFiles(@Injectable final MojoParameters mojoParams,
@Injectable final MavenProject project,
@Injectable final Assembly assembly) throws AssemblyFormattingException, ArchiveCreationException, InvalidAssemblerConfigurationException, MojoExecutionException, AssemblyReadException, IllegalAccessException {
ReflectionUtils.setVariableValueInObject(assemblyManager, "trackArchiver", trackArchiver);
new Expectations() {{
mojoParams.getOutputDirectory();
result = "target/"; times = 3;
mojoParams.getProject();
project.getBasedir();
result = ".";
assemblyReader.readAssemblies((AssemblerConfigurationSource) any);
result = Arrays.asList(assembly);
}};
BuildImageConfiguration buildConfig = createBuildConfig();
assemblyManager.getAssemblyFiles("testImage", buildConfig, mojoParams, new AnsiLogger(new SystemStreamLog(),true,"build"));
}
@Before
public void setUp() throws IOException {
nodeDirectory = new File("target/test/node");
nodeDirectory.mkdirs();
Log log = new SystemStreamLog();
AbstractWisdomMojo mojo = new AbstractWisdomMojo() {
@Override
public void execute() throws MojoExecutionException, MojoFailureException {
// Do nothing.
}
};
mojo.basedir = this.baseDir;
manager = new NodeManager(log, nodeDirectory, mojo);
File assets = new File(baseDir, "src/main/resources/assets");
assets.mkdirs();
FileUtils.copyDirectory(new File("src/test/resources"), assets);
}
@Test
public void testGetValidClasses() throws Exception
{
Log log = new SystemStreamLog();
ApiSource apiSource = new ApiSource();
apiSource.setLocations(Collections.singletonList(this.getClass().getPackage().getName()));
apiSource.setSwaggerDirectory("./");
SpringMavenDocumentSource springMavenDocumentSource = new SpringMavenDocumentSource(apiSource, log, "UTF-8");
Set<Class<?>> validClasses = springMavenDocumentSource.getValidClasses();
Assert.assertEquals(validClasses.size(), 2);
Assert.assertTrue(validClasses.contains(ExampleController1.class));
Assert.assertTrue(validClasses.contains(ExampleController2.class));
}
@Test
public void testEmbeddingDependenciesWithAMissingArtifactFile() throws IOException, PackagingException {
AbstractVertxMojo mojo = mock(AbstractVertxMojo.class);
when(mojo.getLog()).thenReturn(new SystemStreamLog());
Archive archive = new Archive();
archive.setIncludeClasses(false);
archive.setDependencySets(ImmutableList.of(new DependencySet()));
DefaultArtifact artifact = getSecondArtifact();
artifact.setFile(new File("missing-on-purpose"));
Set<Artifact> artifacts = ImmutableSet.of(getFirstArtifact(), artifact);
File output = new File(out, "test-all-dependencies-missing-artifact-file.jar");
PackageConfig config = new PackageConfig()
.setMojo(mojo)
.setOutput(output)
.setArtifacts(artifacts)
.setArchive(archive);
service.doPackage(config);
assertThat(output).isFile();
JarFile jar = new JarFile(output);
List<String> list = jar.stream().map(ZipEntry::getName)
.filter(s -> ! s.endsWith("/")) // Directories
.collect(Collectors.toList());
assertThat(list).containsOnly("META-INF/MANIFEST.MF", "testconfig.yaml");
}
@Test
public void testAddingFileUsingFileSets() throws IOException, PackagingException {
AbstractVertxMojo mojo = mock(AbstractVertxMojo.class);
MavenProject project = mock(MavenProject.class);
when(mojo.getLog()).thenReturn(new SystemStreamLog());
when(project.getBasedir()).thenReturn(new File("."));
when(mojo.getProject()).thenReturn(project);
Archive archive = new Archive();
archive.setIncludeClasses(false);
archive.setDependencySets(Collections.emptyList());
archive.addFileSet(new FileSet()
.setOutputDirectory("config")
.addInclude("*.yaml")
.setDirectory("src/test/resources"));
File output = new File(out, "test-filesets.jar");
PackageConfig config = new PackageConfig()
.setProject(project)
.setMojo(mojo)
.setOutput(output)
.setArtifacts(Collections.emptySet())
.setArchive(archive);
service.doPackage(config);
assertThat(output).isFile();
JarFile jar = new JarFile(output);
List<String> list = jar.stream().map(ZipEntry::getName)
.filter(s -> ! s.endsWith("/")) // Directories
.collect(Collectors.toList());
assertThat(list).contains("META-INF/MANIFEST.MF", "config/testconfig.yaml", "config/testconfig2.yaml").hasSize(3);
}
@Test
public void testAddingFileUsingFileSetsAndExclusion() throws IOException, PackagingException {
AbstractVertxMojo mojo = mock(AbstractVertxMojo.class);
MavenProject project = mock(MavenProject.class);
when(mojo.getLog()).thenReturn(new SystemStreamLog());
when(project.getBasedir()).thenReturn(new File("."));
when(mojo.getProject()).thenReturn(project);
Archive archive = new Archive();
archive.setIncludeClasses(false);
archive.setDependencySets(Collections.emptyList());
archive.addFileSet(new FileSet()
.setOutputDirectory("config")
.addInclude("*.yaml")
.addExclude("*2.yaml")
.setDirectory("src/test/resources"));
File output = new File(out, "test-fileset-with-exclusion.jar");
PackageConfig config = new PackageConfig()
.setProject(project)
.setMojo(mojo)
.setOutput(output)
.setArtifacts(Collections.emptySet())
.setArchive(archive);
service.doPackage(config);
assertThat(output).isFile();
JarFile jar = new JarFile(output);
List<String> list = jar.stream().map(ZipEntry::getName)
.filter(s -> ! s.endsWith("/")) // Directories
.collect(Collectors.toList());
assertThat(list).contains("META-INF/MANIFEST.MF", "config/testconfig.yaml").hasSize(2);
}
@Test
public void testAddingFileUsingFileItem() throws IOException, PackagingException {
AbstractVertxMojo mojo = mock(AbstractVertxMojo.class);
MavenProject project = mock(MavenProject.class);
when(mojo.getLog()).thenReturn(new SystemStreamLog());
when(project.getBasedir()).thenReturn(new File("."));
when(mojo.getProject()).thenReturn(project);
Archive archive = new Archive();
archive.setIncludeClasses(false);
archive.setDependencySets(Collections.emptyList());
archive.addFile(new FileItem()
.setOutputDirectory("config")
.setSource("src/test/resources/testconfig.yaml")
.setDestName("some-config.yaml"));
File output = new File(out, "test-file-item.jar");
PackageConfig config = new PackageConfig()
.setProject(project)
.setMojo(mojo)
.setOutput(output)
.setArtifacts(Collections.emptySet())
.setArchive(archive);
service.doPackage(config);
assertThat(output).isFile();
JarFile jar = new JarFile(output);
List<String> list = jar.stream().map(ZipEntry::getName)
.filter(s -> ! s.endsWith("/")) // Directories
.collect(Collectors.toList());
assertThat(list).contains("META-INF/MANIFEST.MF", "config/some-config.yaml").hasSize(2);
}
@Test
public void issue09() throws MojoExecutionException {
SolidityCompiler solidityCompiler = SolidityCompiler.getInstance(new SystemStreamLog());
Set<String> sources = Collections.singleton("issue-09.sol");
CompilerResult compilerResult = solidityCompiler.compileSrc("src/test/resources/", sources, new String[0], SolidityCompiler.Options.ABI, SolidityCompiler.Options.BIN);
assertFalse(compilerResult.isFailed());
}
private void setUpProject( File pomFile, ExecMojo mojo )
throws Exception
{
super.setUp();
MockitoAnnotations.initMocks( this );
ProjectBuildingRequest buildingRequest = mock( ProjectBuildingRequest.class );
when( session.getProjectBuildingRequest() ).thenReturn( buildingRequest );
MavenRepositorySystemSession repositorySession = new MavenRepositorySystemSession();
repositorySession.setLocalRepositoryManager( new SimpleLocalRepositoryManager( LOCAL_REPO ) );
when( buildingRequest.getRepositorySession() ).thenReturn( repositorySession );
ProjectBuilder builder = lookup( ProjectBuilder.class );
mojo.setBasedir( File.createTempFile( "mvn-temp", "txt" ).getParentFile() );
MavenProject project = builder.build( pomFile, buildingRequest ).getProject();
// this gets the classes for these tests of this mojo (exec plugin) onto the project classpath for the test
project.getBuild().setOutputDirectory( new File( "target/test-classes" ).getAbsolutePath() );
mojo.setProject( project );
mojo.setLog( new SystemStreamLog()
{
public boolean isDebugEnabled()
{
return true;
}
} );
}
@Before
public void setUp() throws Exception {
Log log = new SystemStreamLog()
{
@Override
public boolean isDebugEnabled() {
return true;
}
};
this.scanner = new ClassDefScanner(log);
}
@Test
public void getsFileURIFromJarFileURICorrectly() throws URISyntaxException,
MalformedURLException, IOException {
final URI jarURI = Test.class.getResource("Test.class").toURI();
final String jarURIString = jarURI.toString();
System.out.println(jarURIString);
final String partJarURIString = jarURIString.substring(0,
jarURIString.indexOf(JarURILastModifiedResolver.SEPARATOR));
final URI partJarURI = new URI(partJarURIString);
final URILastModifiedResolver resolver = new CompositeURILastModifiedResolver(
new SystemStreamLog());
final URI fileURI = getClass().getResource(
getClass().getSimpleName() + ".class").toURI();
Assert.assertNotNull(resolver.getLastModified(jarURI));
Assert.assertNotNull(resolver.getLastModified(partJarURI));
Assert.assertNotNull(resolver.getLastModified(fileURI));
// Switch to true to tests HTTP/HTTPs
boolean online = false;
if (online) {
final URI httpsURI = new URI("https://ya.ru/");
final URI httpURI = new URI("http://schemas.opengis.net/ogc_schema_updates.rss");
Assert.assertNotNull(resolver.getLastModified(httpsURI));
Assert.assertNotNull(resolver.getLastModified(httpURI));
}
}
public static void main(String[] args) throws Exception {
// only for local development (in Project root of gen)
CodeGeneratorMojo mojo = new CodeGeneratorMojo();
mojo.processJavaFiles(new File("../../VaadinatorExample/AddressbookExample/src/main/java"),
new File("../../VaadinatorExample/AddressbookExample/target/generated-sources"), new SourceDao(new SystemStreamLog()),
"AddressbookExample", "AddressbookExample", "0.10-SNAPSHOT", true, VaadinatorConfig.ArtifactType.ALL,
VaadinatorConfig.GenType.ALL);
}
@Before
public void setUp() {
nodeDirectory = new File("target/test/node");
nodeDirectory.mkdirs();
log = new SystemStreamLog();
AbstractWisdomMojo mojo = new AbstractWisdomMojo() {
@Override
public void execute() throws MojoExecutionException, MojoFailureException {
// Do nothing.
}
};
mojo.basedir = new File("target/test");
manager = new NodeManager(log, nodeDirectory, mojo);
}
@Before
public void setUp() throws IOException {
nodeDirectory = new File("target/test/node");
nodeDirectory.mkdirs();
Log log = new SystemStreamLog();
mojo = new CoffeeScriptCompilerMojo();
NodeManager manager = new NodeManager(log, nodeDirectory, mojo);
manager.installIfNotInstalled();
mojo.basedir = new File(FAKE_PROJECT);
mojo.buildDirectory = new File(FAKE_PROJECT_TARGET);
mojo.buildDirectory.mkdirs();
mojo.coffeeScriptVersion = CoffeeScriptCompilerMojo.COFFEESCRIPT_VERSION;
cleanup();
}
@Before
public void setUp() throws IOException {
MavenProject project = new MavenProject();
project.setArtifactId("test-artifact");
nodeDirectory = new File("target/test/node");
nodeDirectory.mkdirs();
Log log = new SystemStreamLog();
mojo = new CSSMinifierMojo();
mojo.project = project;
NodeManager manager = new NodeManager(log, nodeDirectory, mojo);
manager.installIfNotInstalled();
mojo.basedir = new File(FAKE_PROJECT);
mojo.buildDirectory = new File(FAKE_PROJECT_TARGET);
mojo.buildDirectory.mkdirs();
mojo.cleanCssVersion = CSSMinifierMojo.CLEANCSS_NPM_VERSION;
mojo.cssMinifierSuffix = "-min";
// Less stuff
less = new LessCompilerMojo();
NodeManager manager2 = new NodeManager(log, nodeDirectory, less);
manager2.installIfNotInstalled();
less.project = project;
less.basedir = new File(FAKE_PROJECT);
less.buildDirectory = new File(FAKE_PROJECT_TARGET);
less.lessVersion = LessCompilerMojo.LESS_VERSION;
cleanup();
}
@Before
public void setUp() throws IOException {
nodeDirectory = new File("target/test/node");
nodeDirectory.mkdirs();
Log log = new SystemStreamLog();
mojo = new TypeScriptCompilerMojo();
mojo.basedir = new File(FAKE_PROJECT);
mojo.buildDirectory = new File(FAKE_PROJECT_TARGET);
mojo.buildDirectory.mkdirs();
mojo.typescript = new TypeScript();
NodeManager manager = new NodeManager(log, nodeDirectory, mojo);
manager.installIfNotInstalled();
}
@Before
public void setUp() throws IOException {
nodeDirectory = new File("target/test/node");
nodeDirectory.mkdirs();
Log log = new SystemStreamLog();
mojo = new LessCompilerMojo();
NodeManager manager = new NodeManager(log, nodeDirectory, mojo);
manager.installIfNotInstalled();
mojo.basedir = new File(FAKE_PROJECT);
mojo.buildDirectory = new File(FAKE_PROJECT_TARGET);
mojo.buildDirectory.mkdirs();
mojo.lessVersion = LessCompilerMojo.LESS_VERSION;
cleanup();
}
@Test
public void testExtractParametersReturnsRetrievedParameters() {
List<Parameter> parameters = new SpringSwaggerExtension(new SystemStreamLog()).extractParameters(
Lists.newArrayList(getTestAnnotation()),
PaginationHelper.class,
Sets.<Type>newHashSet(),
Lists.<SwaggerExtension>newArrayList().iterator());
assertEquals(parameters.size(), 2);
}
@Test
public void testExtractParametersNoModelAttributeAnnotation() {
List<Parameter> parameters = new SpringSwaggerExtension(new SystemStreamLog()).extractParameters(
Lists.newArrayList(),
PaginationHelper.class,
Sets.<Type>newHashSet(),
Lists.<SwaggerExtension>newArrayList().iterator());
assertEquals(parameters.size(), 2);
}
/**
*
*/
@Before
public void setUp() {
setLog(new MavenLog(new SystemStreamLog()));
}
public static BoostLogger getSystemStreamLogger() {
return new BoostLogger(new SystemStreamLog());
}
@Test
public void testCombine() throws Exception {
File jar1 = new File("target/testCombine1.jar");
File jar2 = new File("target/testCombine2.jar");
File jar3 = new File("target/testCombine3.jar");
JavaArchive jarArchive1 = ShrinkWrap.create(JavaArchive.class);
jarArchive1.addAsServiceProvider("com.test.demo.DemoSPI",
"com.test.demo.DemoSPI.impl.DemoSPIImpl");
jarArchive1.as(ZipExporter.class).exportTo(jar1, true);
JavaArchive jarArchive2 = ShrinkWrap.create(JavaArchive.class);
jarArchive2.addAsServiceProvider("com.test.demo.DemoSPI",
"com.test.demo.DemoSPI.impl.DemoSPIImpl2");
jarArchive2.addAsServiceProvider("com.test.demo.DemoSP2",
"com.test.demo.DemoSPI2.impl.DemoSPI2Impl2");
jarArchive2.as(ZipExporter.class).exportTo(jar2, true);
JavaArchive jarArchive3 = ShrinkWrap.create(JavaArchive.class);
jarArchive3.addClass(SPICombineTest.class);
jarArchive3.as(ZipExporter.class).exportTo(jar3, true);
Set<Artifact> artifacts = new LinkedHashSet<>();
Artifact a1 = new DefaultArtifact("org.acme", "a1", "1.0",
"compile", "jar", "", null);
a1.setFile(jar1);
Artifact a2 = new DefaultArtifact("org.acme", "a2", "1.0",
"compile", "jar", "", null);
a2.setFile(jar2);
Artifact a3 = new DefaultArtifact("org.acme", "a3", "1.0",
"compile", "jar", "", null);
a3.setFile(jar3);
artifacts.add(a1);
artifacts.add(a2);
artifacts.add(a3);
MavenProject project = new MavenProject();
project.setVersion("1.0");
project.setArtifactId("foo");
AbstractVertxMojo mojo = new AbstractVertxMojo() {
@Override
public void execute() throws MojoExecutionException, MojoFailureException {
}
};
mojo.setLog(new SystemStreamLog());
Build build = new Build();
build.setOutputDirectory("target/junk");
project.setBuild(build);
ServiceFileCombinationConfig config = new ServiceFileCombinationConfig()
.setProject(project)
.setArtifacts(artifacts)
.setArchive(ServiceUtils.getDefaultFatJar())
.setMojo(mojo);
combiner.doCombine(config);
File merged = new File("target/junk/META-INF/services/com.test.demo.DemoSPI");
assertThat(merged).isFile();
List<String> lines = FileUtils.readLines(merged, "UTF-8");
assertThat(lines).containsExactly("com.test.demo.DemoSPI.impl.DemoSPIImpl",
"com.test.demo.DemoSPI.impl.DemoSPIImpl2");
Stream.of(jar1, jar2, jar3, new File("target/junk")).forEach(FileUtils::deleteQuietly);
}
@Test
public void testCombineDiffSPI() throws Exception {
File jar1 = new File("target/testCombineDiffSPI.jar");
File jar2 = new File("target/testCombineDiffSPI2.jar");
File jar3 = new File("target/testCombineDiffSPI3.jar");
File jar4 = new File("target/testCombineDiffSPI4.jar");
JavaArchive jarArchive1 = ShrinkWrap.create(JavaArchive.class);
jarArchive1.addAsServiceProvider("com.test.demo.DemoSPI",
"com.test.demo.DemoSPI.impl.DemoSPIImpl");
jarArchive1.as(ZipExporter.class).exportTo(jar1, true);
JavaArchive jarArchive2 = ShrinkWrap.create(JavaArchive.class);
jarArchive2.addAsServiceProvider("com.test.demo.DemoSPI",
"com.test.demo.DemoSPI.impl.DemoSPIImpl2");
jarArchive2.as(ZipExporter.class).exportTo(jar2, true);
JavaArchive jarArchive3 = ShrinkWrap.create(JavaArchive.class);
jarArchive3.addClass(SPICombineTest.class);
jarArchive3.as(ZipExporter.class).exportTo(jar3, true);
JavaArchive jarArchive4 = ShrinkWrap.create(JavaArchive.class);
jarArchive4.addAsServiceProvider("com.test.demo.DemoSPI",
"com.test.demo.DemoSPI.impl.DemoSPIImpl4");
jarArchive4.as(ZipExporter.class).exportTo(jar4, true);
Set<Artifact> artifacts = new LinkedHashSet<>();
Artifact a1 = new DefaultArtifact("org.acme", "a1", "1.0",
"compile", "jar", "", null);
a1.setFile(jar1);
Artifact a2 = new DefaultArtifact("org.acme", "a2", "1.0",
"compile", "jar", "", null);
a2.setFile(jar2);
Artifact a3 = new DefaultArtifact("org.acme", "a3", "1.0",
"compile", "jar", "", null);
a3.setFile(jar3);
Artifact a4 = new DefaultArtifact("org.acme", "a4", "1.0",
"compile", "jar", "", null);
a4.setFile(jar4);
artifacts.add(a1);
artifacts.add(a2);
artifacts.add(a3);
artifacts.add(a4);
MavenProject project = new MavenProject();
project.setVersion("1.0");
project.setArtifactId("foo");
AbstractVertxMojo mojo = new AbstractVertxMojo() {
@Override
public void execute() throws MojoExecutionException, MojoFailureException {
}
};
mojo.setLog(new SystemStreamLog());
Build build = new Build();
build.setOutputDirectory("target/junk");
project.setBuild(build);
ServiceFileCombinationConfig config = new ServiceFileCombinationConfig()
.setProject(project)
.setArtifacts(artifacts)
.setArchive(ServiceUtils.getDefaultFatJar())
.setMojo(mojo);
combiner.doCombine(config);
File merged = new File("target/junk/META-INF/services/com.test.demo.DemoSPI");
assertThat(merged).isFile();
List<String> lines = FileUtils.readLines(merged, "UTF-8");
assertThat(lines).hasSize(3).containsExactly(
"com.test.demo.DemoSPI.impl.DemoSPIImpl",
"com.test.demo.DemoSPI.impl.DemoSPIImpl2",
"com.test.demo.DemoSPI.impl.DemoSPIImpl4");
Stream.of(jar1, jar2, jar3, jar4, new File("target/junk")).forEach(FileUtils::deleteQuietly);
}
@Test
public void testCombineWithSpringDescriptors() throws Exception {
File jar1 = new File("target/testCombine1Spring.jar");
File jar2 = new File("target/testCombine2Spring.jar");
File jar3 = new File("target/testCombine3Spring.jar");
JavaArchive jarArchive1 = ShrinkWrap.create(JavaArchive.class);
jarArchive1.add(new StringAsset("com.test.demo.DemoSPI.impl.DemoSPIImpl"),
"/META-INF/spring.foo");
jarArchive1.as(ZipExporter.class).exportTo(jar1, true);
JavaArchive jarArchive2 = ShrinkWrap.create(JavaArchive.class);
jarArchive2.add(new StringAsset("com.test.demo.DemoSPI.impl.DemoSPIImpl2"),
"/META-INF/spring.foo");
jarArchive2.add(new StringAsset("com.test.demo.DemoSPI2.impl.DemoSPI2Impl2"),
"/META-INF/spring.bar");
jarArchive2.as(ZipExporter.class).exportTo(jar2, true);
JavaArchive jarArchive3 = ShrinkWrap.create(JavaArchive.class);
jarArchive3.addClass(SPICombineTest.class);
jarArchive3.as(ZipExporter.class).exportTo(jar3, true);
Set<Artifact> artifacts = new LinkedHashSet<>();
Artifact a1 = new DefaultArtifact("org.acme", "a1", "1.0",
"compile", "jar", "", null);
a1.setFile(jar1);
Artifact a2 = new DefaultArtifact("org.acme", "a2", "1.0",
"compile", "jar", "", null);
a2.setFile(jar2);
Artifact a3 = new DefaultArtifact("org.acme", "a3", "1.0",
"compile", "jar", "", null);
a3.setFile(jar3);
artifacts.add(a1);
artifacts.add(a2);
artifacts.add(a3);
MavenProject project = new MavenProject();
project.setVersion("1.0");
project.setArtifactId("foo");
AbstractVertxMojo mojo = new AbstractVertxMojo() {
@Override
public void execute() throws MojoExecutionException, MojoFailureException {
}
};
mojo.setLog(new SystemStreamLog());
Build build = new Build();
build.setOutputDirectory("target/junk");
project.setBuild(build);
ServiceFileCombinationConfig config = new ServiceFileCombinationConfig()
.setProject(project)
.setArtifacts(artifacts)
.setArchive(ServiceUtils.getDefaultFatJar())
.setMojo(mojo);
combiner.doCombine(config);
File merged = new File("target/junk/META-INF/spring.foo");
assertThat(merged).isFile();
List<String> lines = FileUtils.readLines(merged, "UTF-8");
assertThat(lines).containsExactly("com.test.demo.DemoSPI.impl.DemoSPIImpl",
"com.test.demo.DemoSPI.impl.DemoSPIImpl2");
Stream.of(jar1, jar2, jar3, new File("target/junk")).forEach(FileUtils::deleteQuietly);
}
@Before
public void before() {
Log log = new SystemStreamLog();
configuration = new BotsingConfiguration("crash.log", 1, "bin/botsing-reproduction.jar", log);
}
@Before
public void loadCompiler() throws MojoExecutionException {
solidityCompiler = SolidityCompiler.getInstance(new SystemStreamLog());
}