org.codehaus.plexus.components.interactivity.Prompter Java Examples

The following examples show how to use org.codehaus.plexus.components.interactivity.Prompter. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: Shell.java    From carnotzet with Apache License 2.0 6 votes vote down vote up
/**
 * Lists services and prompts the user to choose one
 */
private static Container promptForContainer(List<Container> containers, Prompter prompter, Log log) throws MojoExecutionException {

	log.info("");
	log.info("SERVICE");
	log.info("");
	Map<Integer, Container> options = new HashMap<>();
	Integer i = 1;

	for (Container container : containers) {
		options.put(i, container);
		log.info(String.format("%2d", i) + " : " + container.getServiceName());
		i = i + 1;
	}
	log.info("");
	try {
		String prompt = prompter.prompt("Choose a service");
		return options.get(Integer.valueOf(prompt));
	}
	catch (PrompterException e) {
		throw new MojoExecutionException("Prompter error" + e.getMessage());
	}
}
 
Example #2
Source File: ReleaseUtil.java    From unleash-maven-plugin with Eclipse Public License 1.0 6 votes vote down vote up
/**
 * Calculates the release version depending on several strategies such as prompting the user or applying a default
 * version.
 *
 * @param version the initial version from which the release version shall be derived.
 * @param defaultReleaseVersion the default release version that should be taken into account.
 * @param prompter a {@link Prompter} for prompting the user for a release version.
 * @return the release version derived after applying several calculation strategies.
 */
public static String getReleaseVersion(String version, Optional<String> defaultReleaseVersion,
    Optional<Prompter> prompter) {
  if (defaultReleaseVersion.isPresent()) {
    return defaultReleaseVersion.get();
  }

  String releaseVersion = MavenVersionUtil.calculateReleaseVersion(version);
  if (prompter.isPresent()) {
    try {
      releaseVersion = prompter.get().prompt("Please specify the release version", releaseVersion);
    } catch (PrompterException e) {
      // in case of an error the calculated version is used
    }
  }

  return releaseVersion;
}
 
Example #3
Source File: ReleaseUtil.java    From unleash-maven-plugin with Eclipse Public License 1.0 6 votes vote down vote up
/**
 * Calculates the next development version depending on several strategies such as prompting the user or applying a
 * default
 * version.
 *
 * @param version the initial version from which the development version shall be derived.
 * @param defaultDevelopmentVersion the default development version that should be taken into account.
 * @param prompter a {@link Prompter} for prompting the user for a version.
 * @param upgradeStrategy the strategy which determines the version segment to increase.
 * @return the development version derived after applying several calculation strategies.
 */
public static String getNextDevelopmentVersion(String version, Optional<String> defaultDevelopmentVersion,
    Optional<Prompter> prompter, VersionUpgradeStrategy upgradeStrategy) {
  if (defaultDevelopmentVersion.isPresent()) {
    return defaultDevelopmentVersion.get();
  }

  String devVersion = MavenVersionUtil.calculateNextSnapshotVersion(version, upgradeStrategy);
  if (prompter.isPresent()) {
    try {
      devVersion = prompter.get().prompt("Please specify the next development version", devVersion);
    } catch (PrompterException e) {
      // in case of an error the calculated version is used
    }
  }

  return devVersion;
}
 
Example #4
Source File: A_UsageStatisticsManager.java    From deadcode4j with Apache License 2.0 6 votes vote down vote up
@Before
public void setUp() throws Exception {
    objectUnderTest = new UsageStatisticsManager() {
        @Override
        protected HttpURLConnection openUrlConnection() throws IOException {
            super.openUrlConnection(); // cover this ;)
            return urlConnectionMock;
        }
    };
    MavenRuntime mavenRuntimeMock = mock(MavenRuntime.class);
    when(mavenRuntimeMock.getProjectProperties(any(Class.class))).thenReturn(
            new MavenProjectProperties("de.is24", "junit", "42.23"));
    setVariableValueInObject(objectUnderTest, "mavenRuntime", mavenRuntimeMock);

    Prompter prompterMock = mock(Prompter.class);
    when(prompterMock.prompt(anyString(), anyList(), anyString())).thenReturn("N");
    setVariableValueInObject(objectUnderTest, "prompter", prompterMock);

    givenHttpTransferResultsIn(200);
}
 
Example #5
Source File: Shell.java    From carnotzet with Apache License 2.0 5 votes vote down vote up
public static void execute(ContainerOrchestrationRuntime runtime, Prompter prompter, Log log, String service)
		throws MojoExecutionException, MojoFailureException {
	List<Container> containers = runtime.getContainers();
	if (containers.isEmpty()) {
		log.info("There doesn't seem to be any containers created yet for this carnotzet, please make sure the carnotzet is started");
		return;
	}
	Container container = containers.stream().filter(c -> c.getServiceName().equals(service)).findFirst().orElse(null);
	if (container == null) {
		container = promptForContainer(containers, prompter, log);
	}

	runtime.shell(container);
}
 
Example #6
Source File: CalculateVersions.java    From unleash-maven-plugin with Eclipse Public License 1.0 5 votes vote down vote up
@Override
public void execute(ExecutionContext context) throws MojoExecutionException, MojoFailureException {
  this.log.info("Calculating required versions for all modules.");

  for (MavenProject project : this.reactorProjects) {
    this.log.info("\tVersions of module " + ProjectToString.EXCLUDE_VERSION.apply(project) + ":");

    ArtifactCoordinates preReleaseCoordinates = this.metadata
        .getArtifactCoordinatesByPhase(project.getGroupId(), project.getArtifactId()).get(ReleasePhase.PRE_RELEASE);
    this.log.info("\t\t" + ReleasePhase.PRE_RELEASE + " = " + preReleaseCoordinates.getVersion());

    Optional<Prompter> prompterToUse = this.settings.isInteractiveMode() ? Optional.of(this.prompter)
        : Optional.<Prompter> absent();

    String releaseVersion = calculateReleaseVersion(project.getVersion(), prompterToUse);
    ArtifactCoordinates releaseCoordinates = new ArtifactCoordinates(project.getGroupId(), project.getArtifactId(),
        releaseVersion, PomUtil.ARTIFACT_TYPE_POM);
    this.metadata.addArtifactCoordinates(releaseCoordinates, ReleasePhase.RELEASE);
    this.log.info("\t\t" + ReleasePhase.RELEASE + " = " + releaseVersion);

    String nextDevVersion = calculateDevelopmentVersion(project.getVersion(), prompterToUse);
    ArtifactCoordinates postReleaseCoordinates = new ArtifactCoordinates(project.getGroupId(),
        project.getArtifactId(), nextDevVersion, PomUtil.ARTIFACT_TYPE_POM);
    this.metadata.addArtifactCoordinates(postReleaseCoordinates, ReleasePhase.POST_RELEASE);
    this.log.info("\t\t" + ReleasePhase.POST_RELEASE + " = " + nextDevVersion);
  }
}
 
Example #7
Source File: CalculateVersions.java    From unleash-maven-plugin with Eclipse Public License 1.0 5 votes vote down vote up
private String calculateReleaseVersion(String version, Optional<Prompter> prompter) {

    if (!MavenVersionUtil.isSnapshot(version) && this.preserveFixedModuleVersions) {
      return version;
    }
    return ReleaseUtil.getReleaseVersion(version, Optional.fromNullable(this.defaultReleaseVersion), prompter);
  }
 
Example #8
Source File: CalculateVersions.java    From unleash-maven-plugin with Eclipse Public License 1.0 5 votes vote down vote up
private String calculateDevelopmentVersion(String version, Optional<Prompter> prompter) {
  if (!MavenVersionUtil.isSnapshot(version) && this.preserveFixedModuleVersions) {
    return version;
  }
  return ReleaseUtil.getNextDevelopmentVersion(version, Optional.fromNullable(this.defaultDevelopmentVersion),
      prompter, this.upgradeStrategy);
}
 
Example #9
Source File: ReleaseUtilTest.java    From unleash-maven-plugin with Eclipse Public License 1.0 5 votes vote down vote up
@Test
@DataProvider({ "1-SNAPSHOT,null,1", "1.0.0-SNAPSHOT,null,1.0.0", "3.1,null,3.1", "3.Alpha1-SNAPSHOT,null,3.Alpha1",
    "2.4,3,3", "2.1-SNAPSHOT,3,3" })
public void testGetReleaseVersion(String version, String defaultReleaseVersion, String expected) {
  Assert.assertEquals(expected, ReleaseUtil.getReleaseVersion(version, Optional.fromNullable(defaultReleaseVersion),
      Optional.<Prompter> absent()));
}
 
Example #10
Source File: ReleaseUtilTest.java    From unleash-maven-plugin with Eclipse Public License 1.0 5 votes vote down vote up
@Test
@DataProvider({ "1-SNAPSHOT,null,4,4", "2-SNAPSHOT,8,4,8" })
public void testGetReleaseVersion_Prompter(String version, String defaultReleaseVersion, String userInput,
    String expected) throws Exception {
  Prompter prompter = Mockito.mock(Prompter.class);
  Mockito.when(prompter.prompt((String) Matchers.notNull(), (String) Matchers.notNull())).thenReturn(userInput);
  Assert.assertEquals(expected,
      ReleaseUtil.getReleaseVersion(version, Optional.fromNullable(defaultReleaseVersion), Optional.of(prompter)));
}
 
Example #11
Source File: ReleaseUtilTest.java    From unleash-maven-plugin with Eclipse Public License 1.0 5 votes vote down vote up
@Test
@DataProvider({ "1-SNAPSHOT,null,2-SNAPSHOT", "1.0.0-SNAPSHOT,null,1.0.1-SNAPSHOT", "3.1,null,3.2-SNAPSHOT",
    "3.Alpha1-SNAPSHOT,null,3.Alpha2-SNAPSHOT", "2.4,3-SNAPSHOT,3-SNAPSHOT",
    "2.1.Alpha-SNAPSHOT,null,2.2.Alpha-SNAPSHOT" })
public void testGetNextDevelopmentVersion(String version, String defaultDevVersion, String expected) {
  Assert.assertEquals(expected, ReleaseUtil.getNextDevelopmentVersion(version,
      Optional.fromNullable(defaultDevVersion), Optional.<Prompter> absent(), VersionUpgradeStrategy.DEFAULT));
}
 
Example #12
Source File: ReleaseUtilTest.java    From unleash-maven-plugin with Eclipse Public License 1.0 5 votes vote down vote up
@Test
@DataProvider({ "1-SNAPSHOT,null,4-SNAPSHOT,4-SNAPSHOT", "2-SNAPSHOT,8-SNAPSHOT,4-SNAPSHOT,8-SNAPSHOT" })
public void testGetNextDevelopmentVersion_Prompter(String version, String defaultReleaseVersion, String userInput,
    String expected) throws Exception {
  Prompter prompter = Mockito.mock(Prompter.class);
  Mockito.when(prompter.prompt((String) Matchers.notNull(), (String) Matchers.notNull())).thenReturn(userInput);
  Assert.assertEquals(expected, ReleaseUtil.getNextDevelopmentVersion(version,
      Optional.fromNullable(defaultReleaseVersion), Optional.of(prompter), VersionUpgradeStrategy.DEFAULT));
}
 
Example #13
Source File: A_UsageStatisticsManager.java    From deadcode4j with Apache License 2.0 5 votes vote down vote up
private void givenUserAgreesToSendStatistics(String comment) throws IllegalAccessException, PrompterException {
    Prompter mock = mock(Prompter.class);
    when(mock.prompt(anyString(), anyList(), anyString())).thenReturn("Y");
    if (comment != null) {
        when(mock.prompt(anyString())).thenReturn(comment);
    }
    setVariableValueInObject(objectUnderTest, "prompter", mock);
}
 
Example #14
Source File: A_UsageStatisticsManager.java    From deadcode4j with Apache License 2.0 4 votes vote down vote up
private void givenPrompterFails() throws IllegalAccessException, PrompterException {
    Prompter mock = mock(Prompter.class);
    when(mock.prompt(anyString(), anyList(), anyString())).thenThrow(new PrompterException("Prompt You!"));
    setVariableValueInObject(objectUnderTest, "prompter", mock);
}