protected boolean checkTemplates(String location, String templateName) { // Check if provided template exists and has .ftl extension return fileManager.exists(location.concat("/").concat(templateName).concat(".ftl")); }
/** * This method check if the provided viewPath file exists * * @param viewName * @return true if exists the provided view path */ protected boolean existsFile(String viewPath) { return getFileManager().exists(viewPath); }
@Override public boolean existsSpringConfigFile(String moduleName, String profile) { return fileManager.exists(getSpringConfigLocation(moduleName, profile)); }
@Override public boolean existsSpringConfigFile(String moduleName) { return fileManager.exists(getSpringConfigLocation(moduleName)); }
@Override public boolean existsProjectSettingsFile() { return getFileManager().exists(getProjectSettingsLocation()); }
@Override public Map<String, String> getProperties(final LogicalPath propertyFilePath, final String propertyFilename) { Validate.notNull(propertyFilePath, "Property file path required"); Validate.notBlank(propertyFilename, "Property filename required"); final String filePath = getProjectOperations().getPathResolver().getIdentifier(propertyFilePath, propertyFilename); final Properties props = new Properties(); try { if (getFileManager().exists(filePath)) { loadProperties(props, new BufferedInputStream(new FileInputStream(filePath))); } else { throw new IllegalStateException(String.format( "ERROR: '%s' properties file doesn't exists.", filePath)); } } catch (final IOException ioe) { throw new IllegalStateException(ioe); } final Map<String, String> result = new HashMap<String, String>(); for (final Object key : props.keySet()) { result.put(key.toString(), props.getProperty(key.toString())); } return Collections.unmodifiableMap(result); }
@Override public SoapBindingType getBindingTypeFromWsdlFile(String wsdlPath) { // Check if provided wsdl file exists if (getFileManager().exists(wsdlPath)) { // Obtain document final Document document = XmlUtils.readXml(getFileManager().getInputStream(wsdlPath)); // Get soap attribute String soapAttr = document.getDocumentElement().getAttribute("xmlns:soap"); if ("http://schemas.xmlsoap.org/wsdl/soap/".equals(soapAttr)) { return SoapBindingType.SOAP11; } else if ("http://schemas.xmlsoap.org/wsdl/soap12/".equals(soapAttr)) { return SoapBindingType.SOAP12; } else if (soapAttr == null || "".equals(soapAttr)) { // Maybe attribute is called soap12 String soap12Attr = document.getDocumentElement().getAttribute("xmlns:soap12"); if ("http://schemas.xmlsoap.org/wsdl/soap12/".equals(soap12Attr)) { return SoapBindingType.SOAP12; } } } return null; }
@Override public String getTargetNameSpaceFromWsdlFile(String wsdlPath) { // Check if provided wsdl file exists if (getFileManager().exists(wsdlPath)) { // Obtain document final Document document = XmlUtils.readXml(getFileManager().getInputStream(wsdlPath)); // Return targetNamespace return document.getDocumentElement().getAttribute("targetNamespace"); } return null; }
@Override public List<String> getEndPointsFromWsdlFile(String wsdlPath) { List<String> availableEndPoints = new ArrayList<String>(); // Check if provided wsdl file exists if (getFileManager().exists(wsdlPath)) { // Obtain document final Document document = XmlUtils.readXml(getFileManager().getInputStream(wsdlPath)); // Finding service elements List<Element> services = XmlUtils.findElements("service", document.getDocumentElement()); for (Element service : services) { NodeList ports = service.getChildNodes(); for (int i = 0; i < ports.getLength(); i++) { Element port = (Element) ports.item(1); if (port != null && port.getAttribute("name") != null) { availableEndPoints.add(port.getAttribute("name")); } } } } return availableEndPoints; }
@Override public List<String> getApplicationProfiles(String moduleName) { List<String> profiles = new ArrayList<String>(); final String applicationConfigFilename = StringUtils.removeEnd(getSpringConfigLocation(moduleName), DEFAULT_APPLICATION_CONFIG_FILE_EXTENSION); // Find application config files for (final FileDetails applicationConfig : fileManager .findMatchingAntPath(applicationConfigFilename + "*" + DEFAULT_APPLICATION_CONFIG_FILE_EXTENSION)) { final String applicationConfigPath = applicationConfig.getCanonicalPath(); if (!fileManager.exists(applicationConfigPath)) { continue; } // Extract profile String profile = StringUtils.substringBetween(applicationConfigPath, applicationConfigFilename, ".properties"); profiles.add(StringUtils.removeStart(profile, "-")); } return profiles; }
@Override public String getProperty(LogicalPath propertyFilePath, String propertyFilename, String prefix, String key) { Validate.notNull(prefix, "Prefix could be blank but not null"); Validate.notNull(propertyFilePath, "Property file path required"); Validate.notBlank(propertyFilename, "Property filename required"); Validate.notBlank(key, "Key required"); final String filePath = getProjectOperations().getPathResolver().getIdentifier(propertyFilePath, propertyFilename); MutableFile mutableFile = null; final Properties props = new Properties(); if (getFileManager().exists(filePath)) { mutableFile = getFileManager().updateFile(filePath); loadProperties(props, mutableFile.getInputStream()); } else { return null; } // Including prefix if needed if (StringUtils.isNotBlank(prefix)) { key = prefix.concat(".").concat(key); } return props.getProperty(key); }
@Override public void removePropertiesByPrefix(LogicalPath propertyFilePath, String propertyFilename, String prefix) { Validate.notBlank(prefix, "Prefix required"); Validate.notNull(propertyFilePath, "Property file path required"); Validate.notBlank(propertyFilename, "Property filename required"); final String filePath = getProjectOperations().getPathResolver().getIdentifier(propertyFilePath, propertyFilename); MutableFile mutableFile = null; final Properties props = new Properties(); if (getFileManager().exists(filePath)) { mutableFile = getFileManager().updateFile(filePath); loadProperties(props, mutableFile.getInputStream()); } else { throw new IllegalStateException(String.format("ERROR: '%s' properties file doesn't exists.", filePath)); } for (Entry property : props.entrySet()) { String key = (String) property.getKey(); if (key != null && key.startsWith(prefix)) { props.remove(key); } } storeProps(props, mutableFile.getOutputStream(), "Updated at " + new Date()); }
private void copyFile(String fileName, String folder) { String file; LogicalPath rootPath = LogicalPath.getInstance(Path.ROOT, ""); if (folder != null) { file = pathResolver.getIdentifier(rootPath, folder + "/src/main/resources/" + fileName); } else { file = pathResolver.getIdentifier(rootPath, fileName); } InputStream inputStream = null; OutputStream outputStream = null; try { inputStream = FileUtils.getInputStream(getClass(), "resources/" + fileName); if (!fileManager.exists(file)) { outputStream = fileManager.createFile(file).getOutputStream(); } if (outputStream != null) { IOUtils.copy(inputStream, outputStream); } } catch (final IOException ioe) { throw new IllegalStateException(ioe); } finally { IOUtils.closeQuietly(inputStream); if (outputStream != null) { IOUtils.closeQuietly(outputStream); } } }
public MetadataItem get(final String metadataId) { Validate.isTrue(ProjectMetadata.isValid(metadataId), "Unexpected metadata request '%s' for this provider", metadataId); // Just rebuild on demand. We always do this as we expect // MetadataService to cache on our behalf final Pom pom = pomManagementService.getPomFromModuleName(ProjectMetadata.getModuleName(metadataId)); // Read the file, if it is available if (pom == null || !fileManager.exists(pom.getPath())) { return null; } return new ProjectMetadata(pom); }
/** * Return a list of installed languages in the provided application module. * * @param moduleName * the module name to search for installed languages. * @return a list with the available languages. */ @Override public List<I18n> getInstalledLanguages(String moduleName) { final LogicalPath resourcesPath = LogicalPath.getInstance(Path.SRC_MAIN_RESOURCES, moduleName); final String targetDirectory = getPathResolver().getIdentifier(resourcesPath, ""); // Create list for installed languages List<I18n> installedLanguages = new ArrayList<I18n>(); // Get all available languages Set<I18n> supportedLanguages = getI18nSupport().getSupportedLanguages(); for (I18n i18n : supportedLanguages) { String messageBundle = String.format("messages_%s.properties", i18n.getLocale().getLanguage()); String bundlePath = String.format("%s%s%s", targetDirectory, AntPathMatcher.DEFAULT_PATH_SEPARATOR, messageBundle); if (getFileManager().exists(bundlePath)) { installedLanguages.add(i18n); } } // Always add English language as default installedLanguages.add(new EnglishLanguage()); return Collections.unmodifiableList(installedLanguages); }
/** * This method is an autocomplete indicator of 'ws client' command. * * It provides all existing endpoints inside the provided .wsdl file. * * @param context * @return */ @CliOptionAutocompleteIndicator( command = "ws client", param = "endpoint", help = "--endpoint parameter should be completed with the attribute 'name' " + "of the 'port' element inside the 'service' element of the provided .wsdl file." + " If the provided .wsdl file doesn't exists in 'src/main/resources', this parameter will not be autocompleted." + " If the provided .wsdl exists and any --endpoint is autocompleted, check if your wsdl file has a valid format.") public List<String> getEndPointForProvidedWsdl(ShellContext context) { List<String> availableEndPoints = new ArrayList<String>(); // First of all, get the provided .wsdl file String wsdlParam = context.getParameters().get("wsdl"); // Check if the provided .wsdl file exists String wsdlLocation = getWsOperations().getWsdlAbsolutePathFromWsdlName(wsdlParam); // If exists, obtain the available enpoints if (getFileManager().exists(wsdlLocation)) { availableEndPoints.addAll(getWsOperations().getEndPointsFromWsdlFile(wsdlLocation)); } return availableEndPoints; }
@Override public void deleteEntity(JavaType entity) { final String entityFilePathIdentifier = getPathResolver().getCanonicalPath(entity.getModule(), Path.SRC_MAIN_JAVA, entity); if (getFileManager().exists(entityFilePathIdentifier)) { getFileManager().delete(entityFilePathIdentifier); } }
/** * Add labels to all installed languages * * @param moduleName * @param labels */ @Override public void addOrUpdateLabels(String moduleName, final Map<String, String> labels) { final LogicalPath resourcesPath = LogicalPath.getInstance(Path.SRC_MAIN_RESOURCES, moduleName); final String targetDirectory = getPathResolver().getIdentifier(resourcesPath, ""); Set<I18n> supportedLanguages = getI18nSupport().getSupportedLanguages(); for (I18n i18n : supportedLanguages) { String messageBundle = String.format("messages_%s.properties", i18n.getLocale().getLanguage()); String bundlePath = String.format("%s%s%s", targetDirectory, AntPathMatcher.DEFAULT_PATH_SEPARATOR, messageBundle); if (getFileManager().exists(bundlePath)) { // Adding labels if not exists already getPropFilesManager().addPropertiesIfNotExists(resourcesPath, messageBundle, labels, true, false); } } // Allways update english message bundles if label not exists already getPropFilesManager().addPropertiesIfNotExists(resourcesPath, "messages.properties", labels, true, false); }
public String getPhysicalTypeCanonicalPath(final String physicalTypeId) { final LogicalPath logicalPath = PhysicalTypeIdentifier.getPath(physicalTypeId); final JavaType javaType = PhysicalTypeIdentifier.getJavaType(physicalTypeId); final Pom pom = getProjectOperations().getPomFromModuleName(logicalPath.getModule()); final String canonicalFilePath = pom.getPathLocation(logicalPath.getPath()) + javaType.getRelativeFileName(); if (getFileManager().exists(canonicalFilePath)) { getTypeCache().cacheTypeAgainstModule(pom, javaType); getTypeCache().cacheFilePathAgainstTypeIdentifier(canonicalFilePath, physicalTypeId); } return canonicalFilePath; }
private void cacheType(final String fileCanonicalPath) { Validate.notBlank(fileCanonicalPath, "File canonical path required"); if (doesPathIndicateJavaType(fileCanonicalPath)) { final String id = getPhysicalTypeIdentifier(fileCanonicalPath); if (id != null && PhysicalTypeIdentifier.isValid(id)) { // Change to Java, so drop the cache final ClassOrInterfaceTypeDetails cid = lookupClassOrInterfaceTypeDetails(id); if (cid == null) { if (!getFileManager().exists(fileCanonicalPath)) { getTypeCache().removeType(id); final JavaType type = getTypeCache().getTypeDetails(id).getName(); updateChanges(type.getFullyQualifiedTypeName(), true); } return; } getTypeCache().cacheType(fileCanonicalPath, cid); updateAttributeCache(cid); updateChanges(cid.getName().getFullyQualifiedTypeName(), false); } } }