GolangBuildMojo extends AbstractGoPackageAndDependencyAwareMojo { @Override @Nonnull @MustNotContainNull public String[] getCommandFlags() { final List<String> flags = new ArrayList<>(); flags.add("-buildmode=" + this.getBuildMode()); final List<String> linkerflags = this.getLdflagsAsList(); if (this.strip) { if (!linkerflags.contains("-s")) { linkerflags.add("-s"); } if (!linkerflags.contains("-w")) { linkerflags.add("-w"); } } if (!linkerflags.isEmpty()) { flags.add("-ldflags"); final StringBuilder buffer = new StringBuilder(); for (final String s : linkerflags) { if (buffer.length() > 0) { buffer.append(' '); } buffer.append(s); } flags.add(buffer.toString()); } final String[] selectedPackages = this.getPackages(); final String selectedResultName = this.getResultName(); if (selectedPackages == null || selectedPackages.length < 2) { if ("none".equals(selectedResultName.trim())) { this.getLog().info("Result name is not defined so that '-o' option is not added."); } else { flags.add("-o"); flags.add(this.getResultFile().getAbsolutePath()); } } return flags.toArray(new String[0]); }  @MustNotContainNull @Nonnull List<String> getLdflagsAsList(); boolean isStrip(); void setStrip(final boolean flag); @Nonnull String getBuildMode(); void setBuilMode(@Nullable final String buildMode); @Nonnull String getResultFolder(); void setResultFolder(@Nonnull final String folder); @Nonnull String getResultName(); void setResultName(@Nonnull final String resultName); @Override @Nonnull String getGoCommand(); @Override void beforeExecution(@Nullable final ProxySettings proxySettings); @Override void afterExecution(@Nullable final ProxySettings proxySettings, final boolean error); @Override boolean isCommandSupportVerbose(); @Override @Nonnull @MustNotContainNull String[] getCommandFlags();  }
@Test public void testPackageTest_Multiple() throws Exception { final GolangBuildMojo buildMojo = makeBuildMojo(); assertTrue(buildMojo.getPackages().length > 1); assertThat(asList(buildMojo.getCommandFlags()), not(hasItem("-o"))); assertThat(asList(buildMojo.getCommandFlags()), not(hasItem(endsWith("targetName")))); }
@Test public void testPackageTest_Single() throws Exception { final GolangBuildMojo buildMojo = makeBuildMojo(); buildMojo.setPackages(copyOfRange(buildMojo.getPackages(), 0, 1)); assertEquals(1, buildMojo.getPackages().length); assertThat(asList(buildMojo.getCommandFlags()), hasItem("-o")); assertThat(asList(buildMojo.getCommandFlags()), hasItem(endsWith("targetName"))); }