public void generateProject(ProjectGenerationRequest request, boolean force) throws IOException { ProjectGenerationResponse response = this.initializrService.generate(request); String fileName = (request.getOutput() != null ? request.getOutput() : response.getFileName()); if (shouldExtract(request, response)) { if (isZipArchive(response)) { extractProject(response, request.getOutput(), force); return; } else { Log.info("Could not extract '" + response.getContentType() + "'"); // Use value from the server since we can't extract it fileName = response.getFileName(); } } if (fileName == null) { throw new ReportableException( "Could not save the project, the server did not set a preferred " + "file name and no location was set. Specify the output location " + "for the project."); } writeProject(response, fileName, force); }
private void extractProject(ProjectGenerationResponse entity, String output, boolean overwrite) throws IOException { File outputFolder = (output != null ? new File(output) : new File(System.getProperty("user.dir"))); if (!outputFolder.exists()) { outputFolder.mkdirs(); } ZipInputStream zipStream = new ZipInputStream( new ByteArrayInputStream(entity.getContent())); try { extractFromStream(zipStream, overwrite, outputFolder); fixExecutableFlag(outputFolder, "mvnw"); fixExecutableFlag(outputFolder, "gradlew"); Log.info("Project extracted to '" + outputFolder.getAbsolutePath() + "'"); } finally { zipStream.close(); } }
private void writeProject(ProjectGenerationResponse entity, String output, boolean overwrite) throws IOException { File outputFile = new File(output); if (outputFile.exists()) { if (!overwrite) { throw new ReportableException("File '" + outputFile.getName() + "' already exists. Use --force if you want to " + "overwrite or specify an alternate location."); } if (!outputFile.delete()) { throw new ReportableException( "Failed to delete existing file " + outputFile.getPath()); } } FileCopyUtils.copy(entity.getContent(), outputFile); Log.info("Content saved to '" + output + "'"); }
@Override @SuppressWarnings("unchecked") protected ExitStatus run(OptionSet options) throws Exception { List<String> args = (List<String>) options.nonOptionArguments(); try { if (options.has(this.allOption)) { if (!args.isEmpty()) { throw new IllegalArgumentException( "Please use --all without specifying any dependencies"); } new Installer(options, this).uninstallAll(); } if (args.isEmpty()) { throw new IllegalArgumentException( "Please specify at least one dependency, in the form group:artifact:version, to uninstall"); } new Installer(options, this).uninstall(args); } catch (Exception ex) { String message = ex.getMessage(); Log.error(message != null ? message : ex.getClass().toString()); } return ExitStatus.OK; }
private void extractProject(ProjectGenerationResponse entity, String output, boolean overwrite) throws IOException { File outputFolder = (output != null ? new File(output) : new File(System.getProperty("user.dir"))); if (!outputFolder.exists()) { outputFolder.mkdirs(); } ZipInputStream zipStream = new ZipInputStream( new ByteArrayInputStream(entity.getContent())); try { extractFromStream(zipStream, overwrite, outputFolder); Log.info("Project extracted to '" + outputFolder.getAbsolutePath() + "'"); } finally { zipStream.close(); } }
/** * Generate a project based on the specified {@link ProjectGenerationRequest}. * @param request the generation request * @return an entity defining the project * @throws IOException if generation fails */ public ProjectGenerationResponse generate(ProjectGenerationRequest request) throws IOException { Log.info("Using service at " + request.getServiceUrl()); InitializrServiceMetadata metadata = loadMetadata(request.getServiceUrl()); URI url = request.generateUrl(metadata); CloseableHttpResponse httpResponse = executeProjectGenerationRequest(url); HttpEntity httpEntity = httpResponse.getEntity(); validateResponse(httpResponse, request.getServiceUrl()); return createResponse(httpResponse, httpEntity); }
@Override @SuppressWarnings("unchecked") protected ExitStatus run(OptionSet options) throws Exception { List<String> args = (List<String>) options.nonOptionArguments(); Assert.notEmpty(args, "Please specify at least one " + "dependency, in the form group:artifact:version, to install"); try { new Installer(options, this).install(args); } catch (Exception ex) { String message = ex.getMessage(); Log.error(message != null ? message : ex.getClass().toString()); } return ExitStatus.OK; }
public void install(List<String> artifactIdentifiers) throws Exception { File libDirectory = getDefaultLibDirectory(); libDirectory.mkdirs(); Log.info("Installing into: " + libDirectory); List<File> artifactFiles = this.dependencyResolver.resolve(artifactIdentifiers); for (File artifactFile : artifactFiles) { int installCount = getInstallCount(artifactFile); if (installCount == 0) { FileCopyUtils.copy(artifactFile, new File(libDirectory, artifactFile.getName())); } setInstallCount(artifactFile, installCount + 1); } saveInstallCounts(); }
public void uninstall(List<String> artifactIdentifiers) throws Exception { File libDirectory = getDefaultLibDirectory(); Log.info("Uninstalling from: " + libDirectory); List<File> artifactFiles = this.dependencyResolver.resolve(artifactIdentifiers); for (File artifactFile : artifactFiles) { int installCount = getInstallCount(artifactFile); if (installCount <= 1) { new File(libDirectory, artifactFile.getName()).delete(); } setInstallCount(artifactFile, installCount - 1); } saveInstallCounts(); }
public void uninstallAll() throws Exception { File libDirectory = getDefaultLibDirectory(); Log.info("Uninstalling from: " + libDirectory); for (String name : this.installCounts.stringPropertyNames()) { new File(libDirectory, name).delete(); } this.installCounts.clear(); saveInstallCounts(); }
private void showCommandHints(String starting) { for (Command command : this.commandRunner) { if (isHintMatch(command, starting)) { Log.info(command.getName() + " " + command.getDescription()); } } }
private void showCommandOptionHints(String commandName, List<String> specifiedArguments, String starting) { Command command = this.commandRunner.findCommand(commandName); if (command != null) { for (OptionHelp help : command.getOptionsHelp()) { if (!alreadyUsed(help, specifiedArguments)) { for (String option : help.getOptions()) { if (option.startsWith(starting)) { Log.info(option + " " + help.getUsageHelp()); } } } } } }
@Override public ExitStatus run(String... args) throws Exception { if (args.length == 0) { throw new NoHelpCommandArgumentsException(); } String commandName = args[0]; for (Command command : this.commandRunner) { if (command.getName().equals(commandName)) { Log.info(this.commandRunner.getName() + command.getName() + " - " + command.getDescription()); Log.info(""); if (command.getUsageHelp() != null) { Log.info("usage: " + this.commandRunner.getName() + command.getName() + " " + command.getUsageHelp()); Log.info(""); } if (command.getHelp() != null) { Log.info(command.getHelp()); } Collection<HelpExample> examples = command.getExamples(); if (examples != null) { Log.info(examples.size() == 1 ? "example:" : "examples:"); Log.info(""); for (HelpExample example : examples) { Log.info(" " + example.getDescription() + ":"); Log.info(" $ " + example.getExample()); Log.info(""); } Log.info(""); } return ExitStatus.OK; } } throw new NoSuchCommandException(commandName); }
public MavenSettings readSettings() { Settings settings = loadSettings(); SettingsDecryptionResult decrypted = decryptSettings(settings); if (!decrypted.getProblems().isEmpty()) { Log.error( "Maven settings decryption failed. Some Maven repositories may be inaccessible"); // Continue - the encrypted credentials may not be used } return new MavenSettings(settings, decrypted); }
public MavenSettings readSettings() { Settings settings = loadSettings(); SettingsDecryptionResult decrypted = decryptSettings(settings); if (!decrypted.getProblems().isEmpty()) { Log.error( "Maven settings decryption failed. Some Maven repositories may be inaccessible"); // Continue - the encrypted credentials may not be used } if(Boolean.getBoolean("mavenSettings.offline")) { settings.setOffline(true); } return new MavenSettings(settings, decrypted); }