Search in sources :

Example 61 with InvalidPathException

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);
}
Also used : FileRepository(org.eclipse.jgit.internal.storage.file.FileRepository) PullCommand(org.eclipse.jgit.api.PullCommand) UsernamePasswordCredentialsProvider(org.eclipse.jgit.transport.UsernamePasswordCredentialsProvider) ArrayList(java.util.ArrayList) CanonicalTreeParser(org.eclipse.jgit.treewalk.CanonicalTreeParser) InvalidPathException(java.nio.file.InvalidPathException) GitAPIException(org.eclipse.jgit.api.errors.GitAPIException) RepositoryChanged(com.searchcode.app.dto.RepositoryChanged) FileRepository(org.eclipse.jgit.internal.storage.file.FileRepository) Git(org.eclipse.jgit.api.Git) DiffEntry(org.eclipse.jgit.diff.DiffEntry)

Example 62 with InvalidPathException

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;
}
Also used : CloneCommand(org.eclipse.jgit.api.CloneCommand) GitAPIException(org.eclipse.jgit.api.errors.GitAPIException) RepositoryChanged(com.searchcode.app.dto.RepositoryChanged) UsernamePasswordCredentialsProvider(org.eclipse.jgit.transport.UsernamePasswordCredentialsProvider) Git(org.eclipse.jgit.api.Git) InvalidPathException(java.nio.file.InvalidPathException)

Example 63 with InvalidPathException

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;
}
Also used : Path(java.nio.file.Path) ConfigurationNode(ninja.leaping.configurate.ConfigurationNode) IOException(java.io.IOException) InvalidPathException(java.nio.file.InvalidPathException)

Example 64 with InvalidPathException

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();
}
Also used : Path(java.nio.file.Path) InvalidPathException(java.nio.file.InvalidPathException)

Example 65 with InvalidPathException

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() };
}
Also used : MalformedURLException(java.net.MalformedURLException) DataTableSpec(org.knime.core.data.DataTableSpec) ColumnRearranger(org.knime.core.data.container.ColumnRearranger) InvalidSettingsException(org.knime.core.node.InvalidSettingsException) File(java.io.File) InvalidPathException(java.nio.file.InvalidPathException)

Aggregations

InvalidPathException (java.nio.file.InvalidPathException)111 Path (java.nio.file.Path)58 IOException (java.io.IOException)30 File (java.io.File)17 URL (java.net.URL)15 MalformedURLException (java.net.MalformedURLException)12 Test (org.junit.Test)11 AlluxioURI (alluxio.AlluxioURI)7 ArrayList (java.util.ArrayList)7 Resource (org.springframework.core.io.Resource)7 Nullable (org.springframework.lang.Nullable)7 URI (java.net.URI)6 URISyntaxException (java.net.URISyntaxException)6 FileDoesNotExistException (alluxio.exception.FileDoesNotExistException)5 BufferedReader (java.io.BufferedReader)5 URIStatus (alluxio.client.file.URIStatus)4 ViewResolve (com.nvlad.yii2support.views.entities.ViewResolve)4 RepositoryChanged (com.searchcode.app.dto.RepositoryChanged)4 InputStream (java.io.InputStream)4 InputStreamReader (java.io.InputStreamReader)4