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

The following examples show how to use org.codehaus.plexus.components.interactivity.PrompterException. 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: UsageStatisticsManager.java    From deadcode4j with Apache License 2.0 6 votes vote down vote up
/**
 * @return {@code null} if sending statistics should be aborted
 */
private boolean askForPermissionAndComment(DeadCodeStatistics deadCodeStatistics, SystemProperties systemProperties) {
    final Logger logger = getLogger();
    StringBuilder buffy = listStatistics(deadCodeStatistics, systemProperties);
    try {
        buffy.append("\nMay I report those usage statistics (via HTTPS)?");
        String answer = prompter.prompt(buffy.toString(), asList("Y", "N"), "Y");
        if ("N".equals(answer)) {
            logger.info("Sending usage statistics is aborted.");
            logger.info("You may configure deadcode4j to permanently disable sending usage statistics.");
            return false;
        }
        if (deadCodeStatistics.getUsageStatisticsComment() == null) {
            deadCodeStatistics.setUsageStatisticsComment(prompter.prompt(
                    "Awesome! Would you like to state a testimonial or give a comment? Here you can"));
        }
        return true;
    } catch (PrompterException e) {
        logger.debug("Prompter failed!", e);
        logger.info("Failed to interact with the user!");
        return false;
    }
}
 
Example #5
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 #6
Source File: GitFlowReleaseStartMojo.java    From gitflow-maven-plugin with Apache License 2.0 4 votes vote down vote up
private String getReleaseVersion() throws MojoFailureException, VersionParseException, CommandLineException {
    // get current project version from pom
    final String currentVersion = getCurrentProjectVersion();

    String defaultVersion = null;
    if (tychoBuild) {
        defaultVersion = currentVersion;
    } else {
        // get default release version
        defaultVersion = new GitFlowVersionInfo(currentVersion)
                .getReleaseVersionString();
    }

    if (defaultVersion == null) {
        throw new MojoFailureException(
                "Cannot get default project version.");
    }

    String version = null;
    if (settings.isInteractiveMode()) {
        try {
            while (version == null) {
                version = prompter.prompt("What is release version? ["
                        + defaultVersion + "]");

                if (!"".equals(version)
                        && (!GitFlowVersionInfo.isValidVersion(version) || !validBranchName(version))) {
                    getLog().info("The version is not valid.");
                    version = null;
                }
            }
        } catch (PrompterException e) {
            throw new MojoFailureException("release-start", e);
        }
    } else {
        version = releaseVersion;
    }

    if (StringUtils.isBlank(version)) {
        getLog().info("Version is blank. Using default version.");
        version = defaultVersion;
    }

    return version;
}
 
Example #7
Source File: GitFlowFeatureFinishMojo.java    From gitflow-maven-plugin with Apache License 2.0 4 votes vote down vote up
private String promptBranchName() throws MojoFailureException, CommandLineException {
    // git for-each-ref --format='%(refname:short)' refs/heads/feature/*
    final String featureBranches = gitFindBranches(gitFlowConfig.getFeatureBranchPrefix(), false);

    final String currentBranch = gitCurrentBranch();

    if (StringUtils.isBlank(featureBranches)) {
        throw new MojoFailureException("There are no feature branches.");
    }

    final String[] branches = featureBranches.split("\\r?\\n");

    List<String> numberedList = new ArrayList<String>();
    String defaultChoice = null;
    StringBuilder str = new StringBuilder("Feature branches:").append(LS);
    for (int i = 0; i < branches.length; i++) {
        str.append((i + 1) + ". " + branches[i] + LS);
        numberedList.add(String.valueOf(i + 1));
        if (branches[i].equals(currentBranch)) {
            defaultChoice = String.valueOf(i + 1);
        }
    }
    str.append("Choose feature branch to finish");

    String featureNumber = null;
    try {
        while (StringUtils.isBlank(featureNumber)) {
            featureNumber = prompter.prompt(str.toString(), numberedList, defaultChoice);
        }
    } catch (PrompterException e) {
        throw new MojoFailureException("feature-finish", e);
    }

    String featureBranchName = null;
    if (featureNumber != null) {
        int num = Integer.parseInt(featureNumber);
        featureBranchName = branches[num - 1];
    }

    return featureBranchName;
}
 
Example #8
Source File: GitFlowHotfixFinishMojo.java    From gitflow-maven-plugin with Apache License 2.0 4 votes vote down vote up
private String promptBranchName() throws MojoFailureException, CommandLineException {
    // git for-each-ref --format='%(refname:short)' refs/heads/hotfix/*
    String hotfixBranches = gitFindBranches(gitFlowConfig.getHotfixBranchPrefix(), false);

    // find hotfix support branches
    if (!gitFlowConfig.getHotfixBranchPrefix().endsWith("/")) {
        String supportHotfixBranches = gitFindBranches(gitFlowConfig.getHotfixBranchPrefix() + "*/*", false);
        hotfixBranches = hotfixBranches + supportHotfixBranches;
    }

    if (StringUtils.isBlank(hotfixBranches)) {
        throw new MojoFailureException("There are no hotfix branches.");
    }

    String[] branches = hotfixBranches.split("\\r?\\n");

    List<String> numberedList = new ArrayList<String>();
    StringBuilder str = new StringBuilder("Hotfix branches:").append(LS);
    for (int i = 0; i < branches.length; i++) {
        str.append((i + 1) + ". " + branches[i] + LS);
        numberedList.add(String.valueOf(i + 1));
    }
    str.append("Choose hotfix branch to finish");

    String hotfixNumber = null;
    try {
        while (StringUtils.isBlank(hotfixNumber)) {
            hotfixNumber = prompter.prompt(str.toString(), numberedList);
        }
    } catch (PrompterException e) {
        throw new MojoFailureException("hotfix-finish", e);
    }

    String hotfixBranchName = null;
    if (hotfixNumber != null) {
        int num = Integer.parseInt(hotfixNumber);
        hotfixBranchName = branches[num - 1];
    }

    return hotfixBranchName;
}
 
Example #9
Source File: A_UsageStatisticsManager.java    From deadcode4j with Apache License 2.0 4 votes vote down vote up
private void givenUserAgreesToSendStatistics() throws IllegalAccessException, PrompterException {
    givenUserAgreesToSendStatistics(null);
}
 
Example #10
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);
}