use of java.nio.file.InvalidPathException in project searchcode-server by boyter.
the class IndexGitRepoJob method updateGitRepository.
/**
* Update a git repository and return if it has changed and the differences
*/
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);
}
use of java.nio.file.InvalidPathException in project searchcode-server by boyter.
the class IndexGitRepoJob method cloneGitRepository.
/**
* Clones the repository from scratch
*/
public RepositoryChanged cloneGitRepository(String repoName, String repoRemoteLocation, String repoUserName, String repoPassword, String repoLocations, String branch, boolean useCredentials) {
boolean successful = false;
Singleton.getLogger().info("Attempting to clone " + repoRemoteLocation);
Git call = null;
try {
CloneCommand cloneCommand = Git.cloneRepository();
cloneCommand.setURI(repoRemoteLocation);
cloneCommand.setDirectory(new File(repoLocations + "/" + repoName + "/"));
cloneCommand.setCloneAllBranches(true);
cloneCommand.setBranch(branch);
if (useCredentials) {
cloneCommand.setCredentialsProvider(new UsernamePasswordCredentialsProvider(repoUserName, repoPassword));
}
call = cloneCommand.call();
successful = true;
} catch (GitAPIException | InvalidPathException ex) {
successful = false;
Singleton.getLogger().warning("ERROR - caught a " + ex.getClass() + " in " + this.getClass() + " cloneGitRepository for " + repoName + "\n with message: " + ex.getMessage());
} finally {
Singleton.getHelpers().closeQuietly(call);
}
RepositoryChanged repositoryChanged = new RepositoryChanged(successful);
repositoryChanged.setClone(true);
return repositoryChanged;
}
use of java.nio.file.InvalidPathException in project SpongeCommon by SpongePowered.
the class WorldMigrator method getOldWorldContainer.
/**
* Gets the old world container used when this server used to be running Bukkit.
*
* @return The world container
*/
public static Path getOldWorldContainer() {
Path worldContainer = Paths.get(".");
final Path bukkitYml = worldContainer.resolve("bukkit.yml");
if (Files.exists(bukkitYml)) {
try {
final ConfigurationNode node = YAMLConfigurationLoader.builder().setPath(bukkitYml).build().load();
final String containerCandidate = node.getNode("settings", "world-container").getString("");
if (!containerCandidate.isEmpty()) {
try {
worldContainer = Paths.get(worldContainer.toString()).resolve(containerCandidate);
} catch (InvalidPathException ipe) {
SpongeImpl.getLogger().warn("Cannot use path [{}] specified under [world-container] in bukkit" + ".yml. Will use [{}] instead.", containerCandidate, worldContainer, ipe);
}
}
} catch (IOException ioe) {
SpongeImpl.getLogger().warn("Cannot load bukkit.yml. Will use [{}] instead.", worldContainer, ioe);
}
}
return worldContainer;
}
use of java.nio.file.InvalidPathException in project EnrichmentMapApp by BaderLab.
the class GSEAResolver method getRptClassFile.
private static Optional<Path> getRptClassFile(Map<String, String> params) {
String classes = params.get("param cls");
// Gsea or GseaPreranked
String method = params.get("producer_class").split("\\p{Punct}")[2];
if (classes != null && method.equalsIgnoreCase("Gsea")) {
String[] classes_split = classes.split("#");
try {
Path path = Paths.get(classes_split[0]);
if (Files.exists(path)) {
return Optional.of(path);
}
} catch (InvalidPathException e) {
e.printStackTrace();
}
}
return Optional.empty();
}
use of java.nio.file.InvalidPathException in project knime-core by knime.
the class SearchReplaceDictNodeModel method configure.
/**
* {@inheritDoc}
*/
@Override
protected DataTableSpec[] configure(final DataTableSpec[] inSpecs) throws InvalidSettingsException {
if (m_dictFileURLString == null) {
throw new InvalidSettingsException("No settings available");
}
File dictFile = null;
try {
dictFile = FileUtil.getFileFromURL(FileUtil.toURL(m_dictFileURLString));
} catch (InvalidPathException | MalformedURLException e) {
throw new InvalidSettingsException("Can't get file from '" + m_dictFileURLString + "'.", e);
}
if (!dictFile.isFile()) {
throw new InvalidSettingsException("No file at \"" + m_dictFileURLString + "\"");
}
if (!inSpecs[0].containsName(m_targetColumnName)) {
throw new InvalidSettingsException("No such column \"" + m_targetColumnName + "\" in input table");
}
if (m_newColumnName != null && inSpecs[0].containsName(m_newColumnName)) {
throw new InvalidSettingsException("Column \"" + m_newColumnName + "\" already exists");
}
ColumnRearranger result = createColumnRearranger(inSpecs[0]);
return new DataTableSpec[] { result.createSpec() };
}
Aggregations