MavenProfileLoader { public static String[] determineProfiles() { if (!profilesDiscovered) { String commandLine = System.getProperty(ENV_MAVEN_CMD_LINE_ARGS); if (commandLine != null) { MavenArgsParser args = MavenArgsParser.parse(commandLine); Optional<String> p_arg = args.get(MavenArgsParser.ARG.P); if (p_arg.isPresent()) { profiles = p_arg.get().split(","); } profilesDiscovered = true; } } return profiles; } private  MavenProfileLoader(); static PomEquippedResolveStage loadPom(ConfigurableMavenResolverSystem resolver); static String[] determineProfiles(); static final String ENV_MAVEN_CMD_LINE_ARGS; }
@Test public void testNullCommand() throws Exception { System.clearProperty("env.MAVEN_CMD_LINE_ARGS"); String[] profiles = MavenProfileLoader.determineProfiles(); assertThat(profiles).hasSize(0); }
@Test public void testEmptyCommand() throws Exception { System.setProperty("env.MAVEN_CMD_LINE_ARGS", ""); String[] profiles = MavenProfileLoader.determineProfiles(); assertThat(profiles).hasSize(0); }
@Test public void testNoProfile() throws Exception { System.setProperty("env.MAVEN_CMD_LINE_ARGS", "mvn clean install"); String[] profiles = MavenProfileLoader.determineProfiles(); assertThat(profiles).hasSize(0); }
@Test public void testOneProfile() throws Exception { System.setProperty("env.MAVEN_CMD_LINE_ARGS", "mvn clean install -Pwildfly"); String[] profiles = MavenProfileLoader.determineProfiles(); assertThat(profiles).hasSize(1); assertThat(profiles[0]).contains("wildfly"); }
@Test public void testTwoProfiles() throws Exception { System.setProperty("env.MAVEN_CMD_LINE_ARGS", "mvn clean install -Pwildfly,testing"); String[] profiles = MavenProfileLoader.determineProfiles(); assertThat(profiles).hasSize(2); assertThat(profiles[0]).contains("wildfly"); assertThat(profiles[1]).contains("testing"); }
@Test public void testThreeProfiles() throws Exception { System.setProperty("env.MAVEN_CMD_LINE_ARGS", "mvn clean install -Pwildfly,testing,another"); String[] profiles = MavenProfileLoader.determineProfiles(); assertThat(profiles).hasSize(3); assertThat(profiles[0]).contains("wildfly"); assertThat(profiles[1]).contains("testing"); assertThat(profiles[2]).contains("another"); }