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

The following examples show how to use io.fabric8.utils.Files#isFile() . 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: LocalRepository.java    From updatebot with Apache License 2.0 5 votes vote down vote up
/**
 * Returns a local repository from a directory.
 */
public static LocalRepository fromDirectory(Configuration configuration, File dir) throws IOException {
    LocalRepository localRepository = new LocalRepository(new GitRepository(dir.getName()), dir);
    File configFile = new File(dir, DEFAULT_CONFIG_FILE);
    if (Files.isFile(configFile)) {
        RepositoryConfig config = RepositoryConfigs.loadRepositoryConfig(configuration, DEFAULT_CONFIG_FILE, dir);
        if (config != null) {
            GitRepositoryConfig local = config.getLocal();
            if (local != null) {
                localRepository.getRepo().setRepositoryDetails(local);
            }
        }
    }
    return localRepository;
}
 
Example 2
Source File: ProcessHelper.java    From updatebot with Apache License 2.0 5 votes vote down vote up
protected static String loadFile(File file) {
    String output = null;
    if (Files.isFile(file)) {
        try {
            output = IOHelpers.readFully(file);
        } catch (IOException e) {
            LOG.error("Failed to load " + file + ". " + e, e);
        }
    }
    return output;
}
 
Example 3
Source File: MavenUpdater.java    From updatebot with Apache License 2.0 5 votes vote down vote up
@Override
public void addVersionChangesFromSource(CommandContext context, Dependencies dependencyConfig, List<DependencyVersionChange> list) throws IOException {
    File file = context.file("pom.xml");
    if (Files.isFile(file)) {
        // lets run the maven plugin to generate the export versions file
        Configuration configuration = context.getConfiguration();
        String configFile = configuration.getConfigFile();
        File versionsFile = createVersionsYamlFile(context);
        Map<String, String> env = configuration.getMvnEnvironmentVariables();
        String mvnCommand = configuration.getMvnCommand();
        String updateBotPluginVersion = VersionHelper.updateBotVersion();
        if (ProcessHelper.runCommandAndLogOutput(context.getConfiguration(), LOG, context.getDir(), env, mvnCommand,
                "-B",
                "io.fabric8.updatebot:updatebot-maven-plugin:" + updateBotPluginVersion + ":export",
                "-DdestFile=" + versionsFile, "-DupdateBotYaml=" + configFile)) {
            if (!Files.isFile(versionsFile)) {
                LOG.warn("Should have generated the export versions file " + versionsFile);
                return;
            }

            MavenArtifactVersionChanges changes;
            try {
                changes = MarkupHelper.loadYaml(versionsFile, MavenArtifactVersionChanges.class);
            } catch (IOException e) {
                throw new IOException("Failed to load " + versionsFile + ". " + e, e);
            }
            List<MavenArtifactVersionChange> changeList = changes.getChanges();
            if (list != null) {
                for (MavenArtifactVersionChange change : changeList) {
                    list.add(change.createDependencyVersionChange());
                }

                PrintStream printStream = configuration.getPrintStream();
                if (!changeList.isEmpty() && printStream != null) {
                    printStream.println("\n");
                }
            }
        }
    }
}
 
Example 4
Source File: MavenUpdater.java    From updatebot with Apache License 2.0 5 votes vote down vote up
@Override
public boolean pushVersions(CommandContext context, List<DependencyVersionChange> changes) throws IOException {
    File file = context.file("pom.xml");
    boolean answer = false;
    if (Files.isFile(file)) {
        if (PomHelper.updatePomVersionsInPoms(context.getDir(), changes)) {
            return true;
        }
    }
    return answer;

}
 
Example 5
Source File: PackageJsonUpdater.java    From updatebot with Apache License 2.0 5 votes vote down vote up
protected JsonNode getJsonFile(CommandContext context, String fileName) {
    JsonNode tree = null;
    File file = context.file(fileName);
    if (Files.isFile(file)) {
        try {
            tree = MarkupHelper.loadJson(file);
        } catch (IOException e) {
            LOG.warn("Failed to parse JSON " + file + ". " + e, e);
        }
    }
    return tree;
}
 
Example 6
Source File: FileUpdater.java    From updatebot with Apache License 2.0 5 votes vote down vote up
@Override
public boolean pushVersions(CommandContext context, List<DependencyVersionChange> changes) throws IOException {
    File file = context.file("pom.xml");
    boolean answer = false;
    if (Files.isFile(file)) {
        if (PomHelper.updatePomVersionsInPoms(context.getDir(), changes)) {
            return true;
        }
    }
    return answer;

}
 
Example 7
Source File: NpmTests.java    From updatebot with Apache License 2.0 5 votes vote down vote up
private static boolean generateDummyChangePackageJson(File dir, String value, String... paths) {
    File file = new File(dir, "package.json");
    if (Files.isFile(file)) {
        try {
            JsonNode jsonNode = MarkupHelper.loadJson(file);
            MarkupAssertions.assertSetValue(jsonNode, value, paths);
            MarkupHelper.savePrettyJson(file, jsonNode);
            return true;
        } catch (IOException e) {
            LOG.warn("Failed to modify " + file + " due to: " + e, e);
        }
    }
    return false;
}
 
Example 8
Source File: CamelXmlHelper.java    From fabric8-forge with Apache License 2.0 5 votes vote down vote up
public static List<ContextDto> loadCamelContext(CamelCatalog camelCatalog, UIContext context, Project project, String xmlResourceName) throws Exception {
    List<ContextDto> camelContexts = null;

    // try with src/main/resources or src/main/webapp/WEB-INF
    String xmlFileName = joinPaths("src/main/resources", xmlResourceName);
    File xmlFile = CommandHelpers.getProjectContextFile(context, project, xmlFileName);
    if (!Files.isFile(xmlFile)) {
        xmlFileName = joinPaths("src/main/webapp/", xmlResourceName);
        xmlFile = CommandHelpers.getProjectContextFile(context, project, xmlFileName);
    }
    if (Files.isFile(xmlFile)) {
        camelContexts = parseCamelContexts(camelCatalog, xmlFile);
    }
    return camelContexts;
}
 
Example 9
Source File: EnableFabric8.java    From updatebot with Apache License 2.0 4 votes vote down vote up
protected boolean hasFile(EnableFabric8Context context, String name) {
    return Files.isFile(new File(context.getDir(), name));
}
 
Example 10
Source File: DevOpsEditStep.java    From fabric8-forge with Apache License 2.0 4 votes vote down vote up
private boolean hasLocalJenkinsFile(UIContext context, Project project) {
    File jenkinsFile = CommandHelpers.getProjectContextFile(context, project, "Jenkinsfile");
    boolean hasJenkinsFile = Files.isFile(jenkinsFile);
    LOG.debug("Has Jenkinsfile " + hasJenkinsFile + " with file: " + jenkinsFile);
    return hasJenkinsFile;
}