List of usage examples for org.apache.commons.io FilenameUtils separatorsToUnix
public static String separatorsToUnix(String path)
From source file:com.searchcode.app.jobs.repository.IndexGitRepoJob.java
/** * Update a git repository and return if it has changed and the differences *//* w w w. j a v a2 s . c om*/ public RepositoryChanged updateGitRepository(String repoName, String repoRemoteLocation, String repoUserName, String repoPassword, String repoLocations, String branch, boolean useCredentials) { boolean changed = false; List<String> changedFiles = new ArrayList<>(); List<String> deletedFiles = new ArrayList<>(); Singleton.getLogger().info("Attempting to pull latest from " + repoRemoteLocation + " for " + repoName); Repository localRepository = null; Git git = null; try { localRepository = new FileRepository(new File(repoLocations + "/" + repoName + "/.git")); Ref head = localRepository.getRef("HEAD"); git = new Git(localRepository); git.reset(); git.clean(); PullCommand pullCmd = git.pull(); if (useCredentials) { pullCmd.setCredentialsProvider(new UsernamePasswordCredentialsProvider(repoUserName, repoPassword)); } pullCmd.call(); Ref newHEAD = localRepository.getRef("HEAD"); if (!head.toString().equals(newHEAD.toString())) { changed = true; // Get the differences between the the heads which we updated at // and use these to just update the differences between them ObjectId oldHead = localRepository.resolve(head.getObjectId().getName() + "^{tree}"); ObjectId newHead = localRepository.resolve(newHEAD.getObjectId().getName() + "^{tree}"); ObjectReader reader = localRepository.newObjectReader(); CanonicalTreeParser oldTreeIter = new CanonicalTreeParser(); oldTreeIter.reset(reader, oldHead); CanonicalTreeParser newTreeIter = new CanonicalTreeParser(); newTreeIter.reset(reader, newHead); List<DiffEntry> entries = git.diff().setNewTree(newTreeIter).setOldTree(oldTreeIter).call(); for (DiffEntry entry : entries) { if ("DELETE".equals(entry.getChangeType().name())) { deletedFiles.add(FilenameUtils.separatorsToUnix(entry.getOldPath())); } else { changedFiles.add(FilenameUtils.separatorsToUnix(entry.getNewPath())); } } } } catch (IOException | GitAPIException | InvalidPathException ex) { changed = false; Singleton.getLogger().warning("ERROR - caught a " + ex.getClass() + " in " + this.getClass() + " updateGitRepository for " + repoName + "\n with message: " + ex.getMessage()); } finally { Singleton.getHelpers().closeQuietly(localRepository); Singleton.getHelpers().closeQuietly(git); } return new RepositoryChanged(changed, changedFiles, deletedFiles); }
From source file:com.google.jenkins.plugins.storage.AbstractUpload.java
/** * This is the workhorse API for performing the actual uploads. It is * performed at the workspace, so that all of the {@link FilePath}s should * be local./*from w w w . j a v a 2s . c o m*/ */ private void performUploads(Map<String, String> metadata, String bucketName, String objectPrefix, GoogleRobotCredentials credentials, UploadSpec uploads, TaskListener listener) throws UploadException { try { Storage service = module.getStorageService(credentials); Executor executor = module.newExecutor(); // Ensure the bucket exists, fetching it regardless so that we can // attach its default ACLs to the objects we upload. Bucket bucket = getOrCreateBucket(service, credentials, executor, bucketName); for (FilePath include : uploads.inclusions) { String relativePath = getRelative(include, uploads.workspace); String uploadedFileName = getStrippedFilename(relativePath); String finalName = FilenameUtils .separatorsToUnix(FilenameUtils.concat(objectPrefix, uploadedFileName)); StorageObject object = new StorageObject().setName(finalName).setMetadata(metadata) .setContentDisposition(HttpHeaders.getContentDisposition(include.getName())) .setContentType(detectMIMEType(include.getName())) .setSize(BigInteger.valueOf(include.length())); if (isSharedPublicly()) { object.setAcl(addPublicReadAccess(getDefaultObjectAcl(bucket, listener))); } // Give clients an opportunity to decorate the storage // object before we store it. annotateObject(object, listener); // Log that we are uploading the file and begin executing the upload. listener.getLogger().println(module.prefix(Messages.AbstractUpload_Uploading(relativePath))); performUploadWithRetry(executor, service, bucket, object, include); } } catch (ForbiddenException e) { // If the user doesn't own a bucket then they will end up here. throw new UploadException(Messages.AbstractUpload_ForbiddenFileUpload(), e); } catch (ExecutorException e) { throw new UploadException(Messages.AbstractUpload_ExceptionFileUpload(), e); } catch (IOException e) { throw new UploadException(Messages.AbstractUpload_ExceptionFileUpload(), e); } catch (InterruptedException e) { throw new UploadException(Messages.AbstractUpload_ExceptionFileUpload(), e); } }
From source file:MSUmpire.DIA.DIAPack.java
public String GetQ2Pepxml() { return FilenameUtils.separatorsToUnix(FilenameUtils.getFullPath(Filename) + "interact-" + FilenameUtils.getBaseName(GetQ2Name()) + ".pep.xml"); }
From source file:MSUmpire.DIA.DIAPack.java
public String GetQ3Pepxml() { return FilenameUtils.separatorsToUnix(FilenameUtils.getFullPath(Filename) + "interact-" + FilenameUtils.getBaseName(GetQ3Name()) + ".pep.xml"); }
From source file:eu.asterics.mw.services.ResourceRegistry.java
/** * Resolves the given nonURIConformingFilePath to the given baseURI URI. The string may contain normal file path characters like space and supports \\ and / as seperators if parameter slashify=true * @param baseURIPath//from w w w .java 2 s .c om * @param nonURIConformingFilePath * @param slashify true: Convert seperators to unix-style / * @return */ public static File resolveRelativeFilePath(URI baseURIPath, String nonURIConformingFilePath, boolean slashify) { if (slashify) { nonURIConformingFilePath = FilenameUtils.separatorsToUnix(nonURIConformingFilePath); } //File resolvedFile=new File(new File(baseURI),nonURIConformingFilePath); //return resolvedFile; File absFile = new File(nonURIConformingFilePath); if (!absFile.isAbsolute()) { absFile = new File(new File(baseURIPath), nonURIConformingFilePath); } return absFile; }
From source file:com.searchcode.app.jobs.repository.IndexBaseRepoJob.java
/** * Indexes all the documents in the path provided. Will also remove anything from the index if not on disk * Generally this is a slow update used only for the initial clone of a repository * NB this can be used for updates but it will be much slower as it needs to to walk the contents of the disk *//*from w w w .j a v a2 s. c o m*/ public void indexDocsByPath(Path path, String repoName, String repoLocations, String repoRemoteLocation, boolean existingRepo) { String fileRepoLocations = FilenameUtils.separatorsToUnix(repoLocations); SearchcodeFileVisitor<Path> searchcodeFileVisitor = new SearchcodeFileVisitor<>(this, repoName, fileRepoLocations, repoRemoteLocation); try { if (this.FOLLOWLINKS) { Files.walkFileTree(path, EnumSet.of(FileVisitOption.FOLLOW_LINKS), Integer.MAX_VALUE, searchcodeFileVisitor); } else { Files.walkFileTree(path, searchcodeFileVisitor); } } catch (IOException ex) { Singleton.getLogger().warning("ERROR - caught a " + ex.getClass() + " in " + this.getClass() + " indexDocsByPath walkFileTree\n with message: " + ex.getMessage()); } if (this.LOGINDEXED) { logIndexed(repoName, searchcodeFileVisitor.reportList); } if (existingRepo) { CodeSearcher codeSearcher = new CodeSearcher(); this.cleanMissingPathFiles(codeSearcher, repoName, searchcodeFileVisitor.fileLocationsMap); } }
From source file:com.iyonger.apm.web.controller.FileEntryController.java
private void upload(User user, String path, String description, MultipartFile file) throws IOException { FileEntry fileEntry = new FileEntry(); fileEntry.setContentBytes(file.getBytes()); fileEntry.setDescription(description); fileEntry.setPath(FilenameUtils.separatorsToUnix(FilenameUtils.concat(path, file.getOriginalFilename()))); fileEntryService.save(user, fileEntry); }
From source file:eu.asterics.mw.services.ResourceRegistry.java
/** * Resolves the given nonURIConformingFilePath to the given baseURI URI. The string may contain normal file path characters like space and supports \\ and / as seperators if parameter slashify=true * @param baseURIPath/*from w w w. j a v a 2 s . c om*/ * @param nonURIConformingFilePath * @param slashify true: Convert seperators to unix-style / * @return */ public static File resolveRelativeFilePath(File baseURIPath, String nonURIConformingFilePath, boolean slashify) { if (slashify) { nonURIConformingFilePath = FilenameUtils.separatorsToUnix(nonURIConformingFilePath); } File absFile = new File(nonURIConformingFilePath); if (!absFile.isAbsolute()) { absFile = new File(baseURIPath, nonURIConformingFilePath); } return absFile; }
From source file:endrov.ioImageCollections.EvIONamebasedImageset.java
/** * Get the relative path from one file to another, specifying the directory separator. * If one of the provided resources does not exist, it is assumed to be a file unless it ends with '/' or * '\'.//from w ww. j a va 2 s . c om * * @param targetPath targetPath is calculated to this file * @param basePath basePath is calculated from this file * @param pathSeparator directory separator. The platform default is not assumed so that we can test Unix behaviour when running on Windows (for example) * @return */ public static String getRelativePath(String targetPath, String basePath, String pathSeparator) { // Normalize the paths String normalizedTargetPath = FilenameUtils.normalizeNoEndSeparator(targetPath); String normalizedBasePath = FilenameUtils.normalizeNoEndSeparator(basePath); // Undo the changes to the separators made by normalization if (pathSeparator.equals("/")) { normalizedTargetPath = FilenameUtils.separatorsToUnix(normalizedTargetPath); normalizedBasePath = FilenameUtils.separatorsToUnix(normalizedBasePath); } else if (pathSeparator.equals("\\")) { normalizedTargetPath = FilenameUtils.separatorsToWindows(normalizedTargetPath); normalizedBasePath = FilenameUtils.separatorsToWindows(normalizedBasePath); } else { throw new IllegalArgumentException("Unrecognised dir separator '" + pathSeparator + "'"); } String[] base = normalizedBasePath.split(Pattern.quote(pathSeparator)); String[] target = normalizedTargetPath.split(Pattern.quote(pathSeparator)); // First get all the common elements. Store them as a string, // and also count how many of them there are. StringBuffer common = new StringBuffer(); int commonIndex = 0; while (commonIndex < target.length && commonIndex < base.length && target[commonIndex].equals(base[commonIndex])) { common.append(target[commonIndex] + pathSeparator); commonIndex++; } if (commonIndex == 0) { // No single common path element. This most // likely indicates differing drive letters, like C: and D:. // These paths cannot be relativized. throw new PathResolutionException("No common path element found for '" + normalizedTargetPath + "' and '" + normalizedBasePath + "'"); } // The number of directories we have to backtrack depends on whether the // base is a file or a dir // For example, the relative path from // // /foo/bar/baz/gg/ff to /foo/bar/baz // // ".." if ff is a file // "../.." if ff is a directory // // The following is a heuristic to figure out if the base refers to a file // or dir. It's not perfect, because // the resource referred to by this path may not actually exist, but it's // the best I can do boolean baseIsFile = true; File baseResource = new File(normalizedBasePath); if (baseResource.exists()) { baseIsFile = baseResource.isFile(); } else if (basePath.endsWith(pathSeparator)) { baseIsFile = false; } StringBuffer relative = new StringBuffer(); if (base.length != commonIndex) { int numDirsUp = baseIsFile ? base.length - commonIndex - 1 : base.length - commonIndex; for (int i = 0; i < numDirsUp; i++) relative.append(".." + pathSeparator); } relative.append(normalizedTargetPath.substring(common.length())); return relative.toString(); }
From source file:com.thoughtworks.go.util.SelectorUtils.java
public static String rtrimStandardrizedWildcardTokens(String input) { return rtrimWildcardTokens(FilenameUtils.separatorsToUnix(input).replace('/', File.separatorChar)); }