Java Code Examples for io.fabric8.utils.Files#isDirectory()

The following examples show how to use io.fabric8.utils.Files#isDirectory() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: HelmUpdater.java    From updatebot with Apache License 2.0 6 votes vote down vote up
protected boolean fileExistsInDir(File dir, String fileName) {
    if (dir.isFile()) {
        return dir.getName().equals(fileName);
    } else if (dir.isDirectory()) {
        if (isFile(new File(dir, fileName))) {
            return true;
        }
        File[] files = dir.listFiles();
        if (files != null) {
            for (File file : files) {
                if (Files.isDirectory(file)) {
                    if (fileExistsInDir(file, fileName)) {
                        return true;
                    }
                }
            }
        }
    }
    return false;
}
 
Example 2
Source File: SpringBootFabric8SetupTest.java    From fabric8-forge with Apache License 2.0 6 votes vote down vote up
protected void removeSnapshotFabric8Artifacts() {
    File fabric8Folder = new File(localMavenRepo, "io/fabric8");
    if (Files.isDirectory(fabric8Folder)) {
        File[] artifactFolders = fabric8Folder.listFiles();
        if (artifactFolders != null) {
            for (File artifactFolder : artifactFolders) {
                File[] versionFolders = artifactFolder.listFiles();
                if (versionFolders != null) {
                    for (File versionFolder : versionFolders) {
                        if (versionFolder.getName().toUpperCase().endsWith("-SNAPSHOT")) {
                            LOG.info("Removing snapshot version from local maven repo: " + versionFolder);
                            Files.recursiveDelete(versionFolder);
                        }
                    }
                }
            }
        }
    }
}
 
Example 3
Source File: PopulateMavenRepositoryTest.java    From fabric8-forge with Apache License 2.0 6 votes vote down vote up
protected void removeSnapshotFabric8Artifacts() {
    File fabric8Folder = new File(localMavenRepo, "io/fabric8");
    if (Files.isDirectory(fabric8Folder)) {
        File[] artifactFolders = fabric8Folder.listFiles();
        if (artifactFolders != null) {
            for (File artifactFolder : artifactFolders) {
                File[] versionFolders = artifactFolder.listFiles();
                if (versionFolders != null) {
                    for (File versionFolder : versionFolders) {
                        if (versionFolder.getName().toUpperCase().endsWith("-SNAPSHOT")) {
                            LOG.info("Removing snapshot version from local maven repo: " + versionFolder);
                            Files.recursiveDelete(versionFolder);
                        }
                    }
                }
            }
        }
    }
}
 
Example 4
Source File: PushSourceChanges.java    From updatebot with Apache License 2.0 5 votes vote down vote up
@Override
protected void validateConfiguration(Configuration configuration) throws IOException {
    File dir = configuration.getSourceDir();
    if (this.cloneUrl == null) {
        if (dir != null) {
            if (!Files.isDirectory(dir)) {
                throw new ParameterException("Directory does not exist " + dir);
            }
            String url;
            try {
                url = GitHelpers.extractGitUrl(dir);
            } catch (IOException e) {
                throw new ParameterException("Could not find the git clone URL in " + dir + ". " + e, e);
            }
            if (url != null) {
                setCloneUrl(GitHelper.removeUsernamePassword(url));
            }
        }
    }
    validateCloneUrl();

    if (sourceRepository == null) {
        sourceRepository = findLocalRepository(configuration);
    }
    if (sourceRepository == null) {
        File sourceDir = configuration.getSourceDir();
        if (sourceDir != null) {
            GitRepository repo = new GitRepository(dir.getName());
            // TODO create a GitHubRepository if we can figure that out
            repo.setCloneUrl(getCloneUrl());
            this.sourceRepository = new LocalRepository(repo, dir);
        }
    }

    if (dir != null) {
        configuration.setSourceDir(dir);
    }
}
 
Example 5
Source File: HelmUpdater.java    From updatebot with Apache License 2.0 5 votes vote down vote up
protected boolean pushVersionsForDir(CommandContext context, List<DependencyVersionChange> changes, File dir) throws IOException {
    File chartsFile = new File(dir, CHART_YAML);
    boolean answer = false;
    if (isFile(chartsFile)) {
        File requirementsFile = new File(dir, REQUIREMENTS_YAML);
        if (isFile(requirementsFile)) {
            Requirements requirements;
            try {
                requirements = MarkupHelper.loadYaml(requirementsFile, Requirements.class);
            } catch (IOException e) {
                throw new IOException("Failed to load chart requirements " + requirementsFile + ". " + e, e);
            }
            if (requirements != null) {
                if (applyRequirementsChanges(context, changes, requirements, requirementsFile)) {
                    answer = true;
                }
            }
        }
    } else {
        File[] files = dir.listFiles();
        if (files != null) {
            for (File file : files) {
                if (Files.isDirectory(file)) {
                    if (pushVersionsForDir(context, changes, file)) {
                        answer = true;
                    }
                }
            }
        }
    }
    return answer;
}
 
Example 6
Source File: ProjectFileSystem.java    From fabric8-forge with Apache License 2.0 5 votes vote down vote up
public File cloneOrPullRepo(UserDetails userDetails, File projectFolder, String cloneUrl, File sshPrivateKey, File sshPublicKey) {
    File gitFolder = new File(projectFolder, ".git");
    CredentialsProvider credentialsProvider = userDetails.createCredentialsProvider();
    if (!Files.isDirectory(gitFolder) || !Files.isDirectory(projectFolder)) {
        // lets clone the git repository!
        cloneRepo(projectFolder, cloneUrl, credentialsProvider, sshPrivateKey, sshPublicKey, this.remote, this.jenkinsfileLibraryGitTag);
    } else {
        doPull(gitFolder, credentialsProvider, userDetails.getBranch(), userDetails.createPersonIdent(), userDetails);
    }
    return projectFolder;
}
 
Example 7
Source File: ProjectFileSystem.java    From fabric8-forge with Apache License 2.0 5 votes vote down vote up
public File cloneRepoIfNotExist(UserDetails userDetails, File projectFolder, String cloneUrl) {
    File gitFolder = new File(projectFolder, ".git");
    CredentialsProvider credentialsProvider = userDetails.createCredentialsProvider();
    if (!Files.isDirectory(gitFolder) || !Files.isDirectory(projectFolder)) {
        // lets clone the git repository!
        cloneRepo(projectFolder, cloneUrl, credentialsProvider, userDetails.getSshPrivateKey(), userDetails.getSshPublicKey(), this.remote);

    }
    return projectFolder;
}
 
Example 8
Source File: AbstractDevOpsCommand.java    From fabric8-forge with Apache License 2.0 5 votes vote down vote up
protected boolean hasProjectFile(UIContext context, String fileName) {
    UISelection<Object> selection = context.getSelection();
    if (selection != null) {
        Object object = selection.get();
        if (object instanceof Resource) {
            File folder = ResourceUtil.getContextFile((Resource<?>) object);
            if (folder != null && Files.isDirectory(folder)) {
                File file = new File(folder, fileName);
                return file != null && file.exists() && file.isFile();
            }
        }
    }
    return false;
}
 
Example 9
Source File: AbstractDevOpsCommand.java    From fabric8-forge with Apache License 2.0 5 votes vote down vote up
protected File getSelectionFolder(UIContext context) {
    UISelection<Object> selection = context.getSelection();
    if (selection != null) {
        Object object = selection.get();
        if (object instanceof Resource) {
            File folder = ResourceUtil.getContextFile((Resource<?>) object);
            if (folder != null && Files.isDirectory(folder)) {
                return folder;
            }
        }
    }
    return null;
}