@Override public void println() { if (piped) { buffer.append("\n"); } else { shell.println(); } }
private void outputConstraintAdded(String property, Class<? extends java.lang.annotation.Annotation> constraintClass) { shell.println("Constraint " + constraintClass.getSimpleName() + " has been successfully added on property named '" + property + "'\n"); } }
@Override public void println(final String s) { if (piped) { buffer.append(s).append("\n"); } else { shell.println(s); } }
/** * Stop waiting. */ public void stop() { if (isWaiting()) { shell.println(); } complete = true; }
@Override public boolean keyPress(final int key) { if (!shell.isExecuting() && (key == 4)) { if (this.numEOFs < ignoreEOFs) { shell.println(); shell.println("(Press CTRL-D again or type 'exit' to quit.)"); this.numEOFs++; } else { shell.println("exit"); shutdown.fire(new Shutdown(Status.NORMAL)); } return true; } return false; }
@Command("update") public void updateDependencies() { if (!new VersionUpdater(project, shell, this.factory, manager).update()) { shell.println("No nothing to update"); } }
void writeSwitchYardConfig() { FileResource<?> configFile = getSwitchYardConfigFile(); SwitchYardModel config = getSwitchYardConfig(); FileOutputStream fos = null; try { fos = new FileOutputStream(configFile.getUnderlyingResourceObject()); config.write(fos, OutputKey.PRETTY_PRINT); } catch (java.io.IOException ioEx) { _shell.println("Error while saving SwitchYard configuration: " + ioEx.getMessage()); } finally { if (fos != null) { try { fos.close(); } catch (java.io.IOException ioEx) { return; } } } }
@DefaultCommand public void run() { shell.println(shell.getCurrentResource().getFullyQualifiedName()); } }
@DefaultCommand public void run() { shell.println(shell.getCurrentDirectory().getFullyQualifiedName()); } }
@DefaultCommand public void list(@Option(required = false) String filter) { ServletFacet web = project.getFacet(ServletFacet.class); List<Resource<?>> resources = web.getResources(); for (Resource<?> file : resources) { shell.println(file.getFullyQualifiedName()); } } }
/** * Returns the editable SwitchYard configuration for the current project. * The configuration is loaded if a config property has not been associated * with the project, so this method must be synchronized to prevent phantom * config references due to concurrent loading. * @return switchyard configuration */ public synchronized SwitchYardModel getSwitchYardConfig() { SwitchYardModel config = (SwitchYardModel) _shell.getCurrentProject().getAttribute(CONFIG_ATTR); if (config == null) { try { config = readSwitchYardConfig(getSwitchYardConfigFile()); setSwitchYardConfig(config); } catch (java.io.IOException ioEx) { _shell.println("Error while reading SwitchYard configuration: " + ioEx.getMessage()); } } config.orderModelChildren(); return config; }
@Command(value = "temporal", help = "Add a temporal field (java.util.Date) to an existing @Entity class") public void newTemporalField( @Option(name = "type", required = true) final TemporalType temporalType, @Option(name = "named", required = true, description = "The field name", type = PromptType.JAVA_VARIABLE_NAME) final String fieldName) { try { JavaClass entity = getJavaClass(); addTemporalFieldTo(entity, Date.class, fieldName, temporalType); } catch (FileNotFoundException e) { shell.println("Could not locate the @Entity requested. No update was made."); } }
@DefaultCommand public void execScript(@Option(required = true, description = "expr") final String... expr) { StringAppender appender = new StringAppender(); for (String s : expr) { appender.append(s); } Object retVal = eval(appender.toString(), new ScriptContext(), shell.getEnvironment().getProperties()); if (retVal != null) { shell.println(valueOf(retVal)); } }
@DefaultCommand(help = "Removes the given constraint on the given property/property accessor") public void removePropertyConstraint( @Option(name = "property", completer = PropertyCompleter.class, required = true) String property, @Option(name = "named", required = true) String constraint, @Option(name = "onAccessor", flagOnly = true) boolean onAccessor) throws FileNotFoundException { final JavaClass clazz = getJavaClassFromResource(shell.getCurrentResource()); final Member<JavaClass, ?> member = getMember(clazz, property, onAccessor); if (member == null) { throw new IllegalStateException("There is no property named '" + property + "' or accessor for this property"); } if (!removeConstraint(member, constraint)) { throw new IllegalStateException("There is no constraint named '" + constraint + "' on " + member.getName()); } // save java source project.getFacet(JavaSourceFacet.class).saveJavaSource(clazz); shell.println("Constraint named '" + constraint + "' has been successfully removed.\n"); }
private String promptApplicationName() { MetadataFacet metadataFacet = getProject().getFacet(MetadataFacet.class); String projectName = Strings.cleanseTrimToNull(metadataFacet != null ? metadataFacet.getProjectName() : null); String enteredName = null; String cleansedName = null; while (cleansedName == null) { if (enteredName != null) { _shell.println(ShellColor.RED, "Illegal Application name: " + enteredName); } if (projectName != null) { enteredName = _shell.prompt("Application name", projectName); } else { enteredName = _shell.prompt("Application name (e.g. myApp)"); } cleansedName = Strings.cleanseTrimToNull(enteredName); } return cleansedName; }
private Field<JavaClass> addFieldTo(final JavaClass targetEntity, final String fieldType, final String fieldName, final Class<Column> annotation) throws FileNotFoundException { if (targetEntity.hasField(fieldName)) { throw new IllegalStateException("Entity already has a field named [" + fieldName + "]"); } JavaSourceFacet java = project.getFacet(JavaSourceFacet.class); Field<JavaClass> field = targetEntity.addField(); field.setName(fieldName).setPrivate().setType(Types.toSimpleName(fieldType)).addAnnotation(annotation); if (!targetEntity.getCanonicalName().equals(fieldType)) { targetEntity.addImport(fieldType); } Refactory.createGetterAndSetter(targetEntity, field); updateToString(targetEntity); java.saveJavaSource(targetEntity); shell.println("Added field to " + targetEntity.getQualifiedName() + ": " + field); return field; }
@Command(value = "get", help = "Adds or modifies an entry in this resource bundle") public void getProperty(@Option(name = "key", required = true, completer = BundleCompleter.class) String key, @Option(name = "locale") String locale) { assertPropertiesInContext(); String propertyValue = null; if (locale == null) { propertyValue = propertiesFileResource.getProperty(key); } else { String bundleName = getBaseBundleName(propertiesFileResource.getName()) + "_" + locale + ".properties"; PropertiesFileResource newFilePropertiesResource = getOrCreate(bundleName); propertyValue = newFilePropertiesResource.getProperty(key); } shell.println(propertyValue); }
private Field<JavaClass> addFieldTo(final JavaClass targetEntity, final JavaClass fieldEntity, final String fieldName, final Class<? extends java.lang.annotation.Annotation> annotation) throws FileNotFoundException { if (targetEntity.hasField(fieldName)) { throw new IllegalStateException("Entity [" + targetEntity.getCanonicalName() + "] already has a field named [" + fieldName + "]"); } JavaSourceFacet java = project.getFacet(JavaSourceFacet.class); Field<JavaClass> field = targetEntity.addField(); field.setName(fieldName).setPrivate().setType(fieldEntity.getName()).addAnnotation(annotation); if (!targetEntity.getCanonicalName().equals(fieldEntity.getCanonicalName())) { targetEntity.addImport(fieldEntity.getQualifiedName()); } Refactory.createGetterAndSetter(targetEntity, field); updateToString(targetEntity); java.saveJavaSource(targetEntity); shell.println("Added field to " + targetEntity.getQualifiedName() + ": " + field); return field; }
public void observeProjectChanged(@Observes ProjectChanged projectChanged, Shell shell) { Project newProject = projectChanged.getNewProject(); if (newProject != null && shell.isVerbose()) { MetadataFacet metadata = newProject.getFacet(MetadataFacet.class); PackagingFacet packaging = newProject.getFacet(PackagingFacet.class); ShellMessages.info(shell, "Project found"); ShellMessages.info(shell, "Name: \t" + shell.renderColor(ShellColor.BOLD, metadata.getProjectName())); ShellMessages.info(shell, "Version: \t" + shell.renderColor(ShellColor.BOLD, metadata.getProjectVersion())); ShellMessages.info(shell, "Type: \t" + shell.renderColor(ShellColor.BOLD, packaging.getPackagingType().getDescription())); shell.println(); } } }
@Command(value = "faces-setup", help = "Setup this bundle as a ResourceBundle in faces-config.xml") public void setupFaces( @Option(name = "var", description = "The name by which this ResourceBundle instance is retrieved by a call to Application.getResourceBundle()", required = true, defaultValue = "msg") String varName) { assertPropertiesInContext(); FacesFacet facesFacet = project.getFacet(FacesFacet.class); FileResource<?> configFile = facesFacet.getConfigFile(); String baseBundleName = getBaseBundleName(propertiesFileResource.getName()); Node facesConfig = XMLParser.parse(configFile.getResourceInputStream()); Node applicationNode = facesConfig.getOrCreate("application"); Node resourceBundleNode = applicationNode.getOrCreate("resource-bundle"); resourceBundleNode.getOrCreate("base-name").text(baseBundleName); resourceBundleNode.getOrCreate("var").text(varName); configFile.setContents(XMLParser.toXMLInputStream(facesConfig)); shell.println("Faces config has been updated."); }