Refine search
/** * Returns the root element of the given XML file. * * @param clazz the class from whose package to open the file (required) * @param xmlFilePath the path of the XML file relative to the given class' * package (required) * @return a non-<code>null</code> element * @see Document#getDocumentElement() */ public static Element getRootElement(final Class<?> clazz, final String xmlFilePath) { final InputStream inputStream = FileUtils.getInputStream(clazz, xmlFilePath); Validate.notNull(inputStream, "Could not open the file '%s'", xmlFilePath); return readXml(inputStream).getDocumentElement(); }
Validate.notBlank(sourceAntPath, "Source path required"); Validate.notBlank(targetDirectory, "Target directory required"); final String path = FileUtils.getPath(getClass(), sourceAntPath); final Iterable<URL> urls = OSGiUtils.findEntriesByPattern(context, path); Validate.notNull(urls, "Could not search bundles for resources for Ant Path '%s'", path); for (final URL url : urls) { final String fileName = url.getPath().substring(url.getPath().lastIndexOf("/") + 1);
/** * Constructor * * @param logicalPath (required) * @param location the physical location of this path (required) */ public PhysicalPath(final LogicalPath logicalPath, final File location) { Validate.notNull(logicalPath, "Module path required"); Validate.notNull(location, "Location required"); canonicalPath = FileUtils.getCanonicalPath(location); this.logicalPath = logicalPath; this.location = location; }
public String getIdentifier(final LogicalPath logicalPath, final String relativePath) { Validate.notNull(logicalPath, "Path required"); Validate.notNull(relativePath, "Relative path cannot be null, although it can be empty"); String initialPath = FileUtils.getCanonicalPath(getPath(logicalPath)); initialPath = FileUtils.ensureTrailingSeparator(initialPath); return initialPath + StringUtils.strip(relativePath, File.separator); }
public Pom getModuleForFileIdentifier(final String fileIdentifier) { updatePomCache(); String startingPoint = FileUtils.getFirstDirectory(fileIdentifier); String pomPath = FileUtils.ensureTrailingSeparator(startingPoint) + DEFAULT_POM_NAME; File pom = new File(pomPath); while (!pom.exists()) { if (startingPoint.equals(SEPARATOR)) { break; } startingPoint = StringUtils.removeEnd(startingPoint, SEPARATOR); if (startingPoint.lastIndexOf(SEPARATOR) < 0) { break; } startingPoint = startingPoint.substring(0, startingPoint.lastIndexOf(SEPARATOR)); startingPoint = StringUtils.removeEnd(startingPoint, SEPARATOR); pomPath = FileUtils.ensureTrailingSeparator(startingPoint) + DEFAULT_POM_NAME; pom = new File(pomPath); } return getPomFromPath(pomPath); }
private String getProposedJavaType(final String fileCanonicalPath) { Validate.notBlank(fileCanonicalPath, "File canonical path required"); // Determine the JavaType for this file String relativePath = ""; final Pom moduleForFileIdentifier = getProjectOperations().getModuleForFileIdentifier(fileCanonicalPath); if (moduleForFileIdentifier == null) { return relativePath; } for (final PhysicalPath physicalPath : moduleForFileIdentifier.getPhysicalPaths()) { final String moduleCanonicalPath = FileUtils.ensureTrailingSeparator(FileUtils.getCanonicalPath(physicalPath.getLocation())); if (fileCanonicalPath.startsWith(moduleCanonicalPath)) { relativePath = File.separator + StringUtils.replace(fileCanonicalPath, moduleCanonicalPath, "", 1); break; } } Validate.notBlank(relativePath, "Could not determine compilation unit name for file '%s'", fileCanonicalPath); Validate.isTrue(relativePath.startsWith(File.separator), "Relative path unexpectedly dropped the '%s' prefix (received '%s' from '%s')", File.separator, relativePath, fileCanonicalPath); relativePath = relativePath.substring(1); Validate.isTrue(relativePath.endsWith(".java"), "The relative path unexpectedly dropped the .java extension for file '%s'", fileCanonicalPath); relativePath = relativePath.substring(0, relativePath.lastIndexOf(".java")); return relativePath.replace(File.separatorChar, '.'); }
StringUtils.isNotBlank(module) && StringUtils.isNotBlank(pomModuleTemplate); Validate.isTrue(isModule || StringUtils.isNotBlank(javaVersion), "Java version required"); Validate.notNull(topLevelPackage, "Top level package required"); pom = XmlUtils.readXml(FileUtils.getInputStream(getClass(), pomTemplate)); groupId = getGroupId(topLevelPackage); } else { pom = XmlUtils.readXml(FileUtils.getInputStream(getClass(), pomModuleTemplate)); groupId = parentPom.getGroupId(); Validate.notBlank(artifactId, "Maven artifactIds cannot be blank"); DomUtils.createChildIfNotExists("artifactId", root, pom).setTextContent(artifactId.trim());
try { InputStream templateInputStream = FileUtils.getInputStream( getClass(), ITD_TEMPLATE); Validate.isTrue(template.length() > 0, "The template doesn't exists."); Validate.notNull(mutableFile, "Could not create ITD file '" + exceptionFilename + "'");
private PhysicalPath getPhysicalPath(final JavaType javaType) { Validate.notNull(javaType, "Java type required"); final String parentPath = getParentPath(javaType); if (parentPath == null) { return null; } for (final Pom pom : getProjectOperations().getPoms()) { for (final PhysicalPath physicalPath : pom.getPhysicalPaths()) { if (physicalPath.isSource()) { final String pathLocation = FileUtils.ensureTrailingSeparator(physicalPath.getLocationPath()); if (pathLocation.startsWith(parentPath)) { getTypeCache().cacheTypeAgainstModule(pom, javaType); return physicalPath; } } } } return null; }
/** * This method creates a banner.txt file inside generated project that will * be displayed when the generated Spring Boot application starts. * * @param Pom * module where banner.txt should be generated */ private void addBannerFile(Pom module) { LogicalPath resourcesPath = LogicalPath.getInstance(Path.SRC_MAIN_RESOURCES, module.getModuleName()); String sourceAntPath = "banner/banner.txt"; String targetDirectory = getPathResolver().getIdentifier(resourcesPath, ""); if (!getFileManager().exists(targetDirectory)) { getFileManager().createDirectory(targetDirectory); } final String path = FileUtils.getPath(getClass(), sourceAntPath); final Iterable<URL> urls = OSGiUtils.findEntriesByPattern(context, path); Validate.notNull(urls, "Could not search bundles for resources for Ant Path '%s'", path); for (final URL url : urls) { final String fileName = url.getPath().substring(url.getPath().lastIndexOf("/") + 1); try { String contents = IOUtils.toString(url); getFileManager().createOrUpdateTextFileIfRequired(targetDirectory + fileName, contents, false); } catch (final Exception e) { throw new IllegalStateException(e); } } }
public String backup() { Validate.isTrue(isBackupPossible(), "Project metadata unavailable"); // For Windows, make a date format that can legally form part of a // filename (ROO-277) final String pattern = File.separatorChar == '\\' ? "yyyy-MM-dd_HH.mm.ss" : "yyyy-MM-dd_HH:mm:ss"; final DateFormat df = new SimpleDateFormat(pattern); final long start = System.nanoTime(); ZipOutputStream zos = null; try { final File projectDirectory = new File(getProjectOperations().getPathResolver().getFocusedIdentifier(Path.ROOT, ".")); final MutableFile file = getFileManager().createFile( FileUtils.getCanonicalPath(new File(projectDirectory, getProjectOperations() .getFocusedProjectName() + "_" + df.format(new Date()) + ".zip"))); zos = new ZipOutputStream(file.getOutputStream()); zip(projectDirectory, projectDirectory, zos); } catch (final FileNotFoundException e) { LOGGER.fine("Could not determine project directory"); } catch (final IOException e) { LOGGER.fine("Could not create backup archive"); } finally { IOUtils.closeQuietly(zos); } final long milliseconds = (System.nanoTime() - start) / 1000000; return "Backup completed in " + milliseconds + " ms"; }
/** * Indicates whether the presented canonical path is a child of the current * {@link FileDetails} instance. Put differently, returning true indicates * the current instance is a parent directory of the presented * possibleChildCanonicalPath. * <p> * This method will return true if the presented child is a child of the * current instance, or if the presented child is identical to the current * instance. * * @param possibleChildCanonicalPath to evaluate (required) * @return true if the presented possible child is indeed a child of the * current instance */ public boolean isParentOf(final String possibleChildCanonicalPath) { Validate.notBlank(possibleChildCanonicalPath, "Possible child to evaluate is required"); return FileUtils.ensureTrailingSeparator(possibleChildCanonicalPath).startsWith( FileUtils.ensureTrailingSeparator(getCanonicalPath())); }
public InputStream getMessageBundle() { return FileUtils.getInputStream(getClass(), "messages.properties"); } }
/** * Each {@link FileDetails} is known by its canonical file name, which is * also the format used for Ant path matching etc. This method provides the * canonical file name without forcing the user to deal with the exceptions * that would arise from using {@link File} directly. * * @return the canonical path. */ public String getCanonicalPath() { return FileUtils.getCanonicalPath(file); }
private String getModuleName(final String pomDirectory) { final String normalisedRootPath = FileUtils.ensureTrailingSeparator(projectRootDirectory); final String normalisedPomDirectory = FileUtils.ensureTrailingSeparator(pomDirectory); final String moduleDirectory = StringUtils.removeStart(normalisedPomDirectory, normalisedRootPath); return FilenameUtils.getBaseName(StringUtils.stripEnd(moduleDirectory, SEPARATOR)); }
private PhysicalPath getPhysicalPath(final JavaType javaType) { Validate.notNull(javaType, "Java type required"); final String parentPath = getParentPath(javaType); if (parentPath == null) { return null; } for (final Pom pom : getProjectOperations().getPoms()) { for (final PhysicalPath physicalPath : pom.getPhysicalPaths()) { if (physicalPath.isSource()) { final String pathLocation = FileUtils.ensureTrailingSeparator(physicalPath.getLocationPath()); if (pathLocation.startsWith(parentPath)) { getTypeCache().cacheTypeAgainstModule(pom, javaType); return physicalPath; } } } } return null; }
private String getProposedJavaType(final String fileCanonicalPath) { Validate.notBlank(fileCanonicalPath, "File canonical path required"); // Determine the JavaType for this file String relativePath = ""; final Pom moduleForFileIdentifier = getProjectOperations().getModuleForFileIdentifier(fileCanonicalPath); if (moduleForFileIdentifier == null) { return relativePath; } for (final PhysicalPath physicalPath : moduleForFileIdentifier.getPhysicalPaths()) { final String moduleCanonicalPath = FileUtils.ensureTrailingSeparator(FileUtils.getCanonicalPath(physicalPath.getLocation())); if (fileCanonicalPath.startsWith(moduleCanonicalPath)) { relativePath = File.separator + StringUtils.replace(fileCanonicalPath, moduleCanonicalPath, "", 1); break; } } Validate.notBlank(relativePath, "Could not determine compilation unit name for file '%s'", fileCanonicalPath); Validate.isTrue(relativePath.startsWith(File.separator), "Relative path unexpectedly dropped the '%s' prefix (received '%s' from '%s')", File.separator, relativePath, fileCanonicalPath); relativePath = relativePath.substring(1); Validate.isTrue(relativePath.endsWith(".java"), "The relative path unexpectedly dropped the .java extension for file '%s'", fileCanonicalPath); relativePath = relativePath.substring(0, relativePath.lastIndexOf(".java")); return relativePath.replace(File.separatorChar, '.'); }
/** * Indicates whether the presented canonical path is a child of the current * {@link FileDetails} instance. Put differently, returning true indicates * the current instance is a parent directory of the presented * possibleChildCanonicalPath. * <p> * This method will return true if the presented child is a child of the * current instance, or if the presented child is identical to the current * instance. * * @param possibleChildCanonicalPath to evaluate (required) * @return true if the presented possible child is indeed a child of the * current instance */ public boolean isParentOf(final String possibleChildCanonicalPath) { Validate.notBlank(possibleChildCanonicalPath, "Possible child to evaluate is required"); return FileUtils.ensureTrailingSeparator(possibleChildCanonicalPath).startsWith( FileUtils.ensureTrailingSeparator(getCanonicalPath())); }
public InputStream getMessageBundle() { return FileUtils.getInputStream(getClass(), "messages_es.properties"); } }
public String getCanonicalPath() { return FileUtils.getCanonicalPath(file); }