org.springframework.roo.support.util.FileUtils类的使用及代码示例

x33g5p2x  于2022-01-19 转载在 其他  
字(13.2k)|赞(0)|评价(0)|浏览(109)

本文整理了Java中org.springframework.roo.support.util.FileUtils类的一些代码示例,展示了FileUtils类的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。FileUtils类的具体详情如下:
包路径:org.springframework.roo.support.util.FileUtils
类名称:FileUtils

FileUtils介绍

[英]Utilities for handling File instances.
[中]用于处理文件实例的实用程序。

代码示例

代码示例来源:origin: spring-projects/spring-roo

/**
 * 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();
}

代码示例来源:origin: spring-projects/spring-roo

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);

代码示例来源:origin: spring-projects/spring-roo

/**
 * 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;
}

代码示例来源:origin: spring-projects/spring-roo

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);
}

代码示例来源:origin: spring-projects/spring-roo

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);
}

代码示例来源:origin: spring-projects/spring-roo

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, '.');
}

代码示例来源:origin: spring-projects/spring-roo

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());

代码示例来源:origin: org.gvnix/org.gvnix.web.exception.handler.roo.addon.addon

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 + "'");

代码示例来源:origin: spring-projects/spring-roo

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;
}

代码示例来源:origin: spring-projects/spring-roo

/**
 * 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);
  }
 }
}

代码示例来源:origin: spring-projects/spring-roo

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";
}

代码示例来源:origin: spring-projects/spring-roo

/**
 * 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()));
}

代码示例来源:origin: spring-projects/spring-roo

public InputStream getMessageBundle() {
  return FileUtils.getInputStream(getClass(), "messages.properties");
 }
}

代码示例来源:origin: spring-projects/spring-roo

/**
 * 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);
}

代码示例来源:origin: spring-projects/spring-roo

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));
}

代码示例来源:origin: org.springframework.roo/org.springframework.roo.classpath

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;
}

代码示例来源:origin: org.springframework.roo/org.springframework.roo.classpath

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, '.');
}

代码示例来源:origin: org.springframework.roo/org.springframework.roo.file.monitor

/**
 * 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()));
}

代码示例来源:origin: spring-projects/spring-roo

public InputStream getMessageBundle() {
  return FileUtils.getInputStream(getClass(), "messages_es.properties");
 }
}

代码示例来源:origin: spring-projects/spring-roo

public String getCanonicalPath() {
 return FileUtils.getCanonicalPath(file);
}

相关文章