Example usage for java.io File toString

List of usage examples for java.io File toString

Introduction

In this page you can find the example usage for java.io File toString.

Prototype

public String toString() 

Source Link

Document

Returns the pathname string of this abstract pathname.

Usage

From source file:it.cnr.icar.eric.client.xml.registry.util.SecurityUtil.java

private KeyStore loadKeyStore() throws JAXRException {
    String storepass = ProviderProperties.getInstance().getProperty("jaxr-ebxml.security.storepass");

    try {/*  ww w .  j a v  a2s.  c o m*/
        keyStore = KeyStore
                .getInstance(ProviderProperties.getInstance().getProperty("jaxr-ebxml.security.storetype"));
    } catch (KeyStoreException x) {
        throw new JAXRException(x);
    }

    File keyStoreFile = KeystoreUtil.getKeystoreFile();

    if (!keyStoreFile.exists()) {
        throw new JAXRException(JAXRResourceBundle.getInstance().getString("message.error.no.keystore.file",
                new Object[] { keyStoreFile.toString() }));
    }

    try {
        InputStream keyIS = new BufferedInputStream(new FileInputStream(keyStoreFile));
        keyStore.load(keyIS, storepass.toCharArray());
        log.debug("Keystore loaded from '" + keyStoreFile.getCanonicalPath() + "'");
    } catch (IOException x) {
        throw new JAXRException(x);
    } catch (GeneralSecurityException x) {
        throw new JAXRException(x);
    }

    return keyStore;
}

From source file:com.blackducksoftware.integration.hub.detect.detector.nuget.NugetInspectorExtractor.java

public Extraction extract(final File targetDirectory, File outputDirectory, NugetInspector inspector,
        final ExtractionId extractionId) {
    try {//from  w w  w . j a v a  2  s . co  m

        final List<String> options = new ArrayList<>(
                Arrays.asList("--target_path=" + targetDirectory.toString(),
                        "--output_directory=" + outputDirectory.getCanonicalPath(),
                        "--ignore_failure=" + detectConfiguration.getBooleanProperty(
                                DetectProperty.DETECT_NUGET_IGNORE_FAILURE, PropertyAuthority.None)));

        final String nugetExcludedModules = detectConfiguration
                .getProperty(DetectProperty.DETECT_NUGET_EXCLUDED_MODULES, PropertyAuthority.None);
        if (StringUtils.isNotBlank(nugetExcludedModules)) {
            options.add("--excluded_modules=" + nugetExcludedModules);
        }
        final String nugetIncludedModules = detectConfiguration
                .getProperty(DetectProperty.DETECT_NUGET_INCLUDED_MODULES, PropertyAuthority.None);
        if (StringUtils.isNotBlank(nugetIncludedModules)) {
            options.add("--included_modules=" + nugetIncludedModules);
        }
        final String[] nugetPackagesRepo = detectConfiguration
                .getStringArrayProperty(DetectProperty.DETECT_NUGET_PACKAGES_REPO_URL, PropertyAuthority.None);
        if (nugetPackagesRepo.length > 0) {
            final String packagesRepos = Arrays.asList(nugetPackagesRepo).stream()
                    .collect(Collectors.joining(","));
            options.add("--packages_repo_url=" + packagesRepos);
        }
        final String nugetConfigPath = detectConfiguration.getProperty(DetectProperty.DETECT_NUGET_CONFIG_PATH,
                PropertyAuthority.None);
        if (StringUtils.isNotBlank(nugetConfigPath)) {
            options.add("--nuget_config_path=" + nugetConfigPath);
        }
        if (logger.isTraceEnabled()) {
            options.add("-v");
        }

        final ExecutableOutput executableOutput = inspector.execute(targetDirectory, options);

        if (executableOutput.getReturnCode() != 0) {
            return new Extraction.Builder()
                    .failure(String.format("Executing command '%s' returned a non-zero exit code %s",
                            String.join(" ", options), executableOutput.getReturnCode()))
                    .build();
        }

        final List<File> dependencyNodeFiles = detectFileFinder.findFiles(outputDirectory,
                INSPECTOR_OUTPUT_PATTERN);

        final List<NugetParseResult> parseResults = new ArrayList<>();
        for (final File dependencyNodeFile : dependencyNodeFiles) {
            final NugetParseResult result = nugetInspectorPackager.createDetectCodeLocation(dependencyNodeFile);
            parseResults.add(result);
        }

        final List<DetectCodeLocation> codeLocations = parseResults.stream()
                .flatMap(it -> it.codeLocations.stream()).collect(Collectors.toList());

        if (codeLocations.size() <= 0) {
            logger.warn("Unable to extract any dependencies from nuget");
        }

        final Map<String, DetectCodeLocation> codeLocationsBySource = new HashMap<>();
        final DependencyGraphCombiner combiner = new DependencyGraphCombiner();

        codeLocations.stream().forEach(codeLocation -> {
            final String sourcePathKey = codeLocation.getSourcePath().toLowerCase();
            if (codeLocationsBySource.containsKey(sourcePathKey)) {
                logger.info(
                        "Multiple project code locations were generated for: " + targetDirectory.toString());
                logger.info("This most likely means the same project exists in multiple solutions.");
                logger.info(
                        "The code location's dependencies will be combined, in the future they will exist seperately for each solution.");
                final DetectCodeLocation destination = codeLocationsBySource.get(sourcePathKey);
                combiner.addGraphAsChildrenToRoot((MutableDependencyGraph) destination.getDependencyGraph(),
                        codeLocation.getDependencyGraph());
            } else {
                codeLocationsBySource.put(sourcePathKey, codeLocation);
            }
        });

        final List<DetectCodeLocation> uniqueCodeLocations = codeLocationsBySource.values().stream()
                .collect(Collectors.toList());

        final Extraction.Builder builder = new Extraction.Builder().success(uniqueCodeLocations);
        final Optional<NugetParseResult> project = parseResults.stream()
                .filter(it -> StringUtils.isNotBlank(it.projectName)).findFirst();
        if (project.isPresent()) {
            builder.projectName(project.get().projectName);
            builder.projectVersion(project.get().projectVersion);
        }
        return builder.build();
    } catch (final Exception e) {
        return new Extraction.Builder().exception(e).build();
    }
}

From source file:net.doubledoordev.cmd.util.InputFileValidator.java

@Override
public void validate(String name, File value) throws ParameterException {
    //if (!value.exists()) throw new ParameterException(new FileNotFoundException(value.toString()));
    //if (!value.isFile()) throw new ParameterException(value.toString() + " is not a file.");
    String extention = FilenameUtils.getExtension(value.getName());
    if (extention.equalsIgnoreCase("json") || extention.equalsIgnoreCase("zip"))
        return;//www. java2  s  .  c  o  m
    throw new ParameterException(value.toString() + " is not a .json or .zip file.");
}

From source file:com.CodeSeance.JSeance.CodeGenXML.Runtime.java

public String run(File includesDir, File modelsDir, File targetDir, List<File> templateFiles,
        Logger externalLog) {//from  w  w w.  j  a  v  a2s  .  com
    errors = false;
    Log log = LogFactory.getLog("Runtime");

    StringBuffer buffer = new StringBuffer();

    if (!((targetDir.exists() && targetDir.isDirectory()) || targetDir.mkdirs())) {
        String message = ExecutionError.INVALID_TARGET_DIR.getMessage(targetDir);
        externalLog.errorMessage(message);
        log.error(message);
        return null;
    }

    DependencyManager dependencyManager = new DependencyManager(targetDir);

    // access non-option arguments and generate the templates
    for (File templateFile : templateFiles) {
        TemplateDependencies templateDependencies = dependencyManager.getTemplateDependencies(templateFile);

        // Track the processing time
        externalLog.infoMessage(String.format("Processing template file:[%s]", templateFile.toString()));
        long startMillis = System.currentTimeMillis();

        if (!dependencyManager.getTemplateDependencies(templateFile).isUpToDate() || forceRebuild) {
            dependencyManager.clearTemplateDependencies(templateFile);
            try {
                String result = Template.run(templateFile, includesDir, modelsDir, targetDir,
                        ignoreReadOnlyOuputFiles, templateDependencies);
                buffer.append(result);
                dependencyManager.commit();
            } catch (Exception ex) {
                errors = true;
                externalLog.errorMessage(ex.getMessage());
                log.error(ex.getMessage());
            }
        } else {
            String message = String.format(
                    "File dependencies are up to date, skipping template generation:[%s]", templateFile);
            externalLog.infoMessage(message);
            log.info(message);
        }

        long elapsedMillis = System.currentTimeMillis() - startMillis;
        externalLog.infoMessage(String.format("Completed in :[%s] ms", elapsedMillis));
    }
    return buffer.toString();
}

From source file:com.espertech.esperio.db.config.ConfigurationDBAdapter.java

/**
 * Use the ConfigurationDBAdapter specified in the given application
 * file. The format of the file is defined in
 * <tt>esper-configuration-2.0.xsd</tt>.
 *
 * @param configFile <tt>File</tt> from which you wish to load the configuration
 * @return A ConfigurationDBAdapter configured via the file
 * @throws RuntimeException when the file could not be found
 *//*  w  w  w.j a  v  a 2 s .  c o  m*/
public ConfigurationDBAdapter configure(File configFile) throws RuntimeException {
    if (log.isDebugEnabled()) {
        log.debug("configuring from file: " + configFile.getName());
    }
    try {
        ConfigurationDBAdapterParser.doConfigure(this, new FileInputStream(configFile), configFile.toString());
    } catch (FileNotFoundException fnfe) {
        throw new RuntimeException("could not find file: " + configFile, fnfe);
    }
    return this;
}

From source file:uk.co.petertribble.jkstat.gui.KstatBaseChartFrame.java

/**
 * Saves the current chart as an image in png format. The user can select
 * the filename, and is asked to confirm the overwrite of an existing file.
 *//*from  w  w w  .  j  a  va 2  s . c o m*/
public void saveImage() {
    JFileChooser fc = new JFileChooser();
    if (fc.showSaveDialog(this) == JFileChooser.APPROVE_OPTION) {
        File f = fc.getSelectedFile();
        if (f.exists()) {
            int ok = JOptionPane.showConfirmDialog(this,
                    KstatResources.getString("SAVEAS.OVERWRITE.TEXT") + " " + f.toString(),
                    KstatResources.getString("SAVEAS.CONFIRM.TEXT"), JOptionPane.YES_NO_OPTION);
            if (ok != JOptionPane.YES_OPTION) {
                return;
            }
        }
        BufferedImage bi = kbc.getChart().createBufferedImage(500, 300);
        try {
            ImageIO.write(bi, "png", f);
            /*
             * According to the API docs this should throw an IOException
             * on error, but this doesn't seem to be the case. As a result
             * it's necessary to catch exceptions more generally. Even this
             * doesn't work properly, but at least we manage to convey the
             * message to the user that the write failed, even if the
             * error itself isn't handled.
             */
        } catch (Exception ioe) {
            JOptionPane.showMessageDialog(this, ioe.toString(), KstatResources.getString("SAVEAS.ERROR.TEXT"),
                    JOptionPane.ERROR_MESSAGE);
        }
    }
}

From source file:com.obidea.semantika.app.ApplicationFactory.java

public ApplicationFactory configure(File resource) throws ConfigurationException {
    LOG.debug("Reading configuration (file: {})", resource.getName()); //$NON-NLS-1$
    try {/*from ww  w.j a v  a2 s. c om*/
        InputStream stream = new FileInputStream(resource);
        return doConfigure(stream, resource.toString());
    } catch (FileNotFoundException e) {
        throw new ResourceNotFoundException(resource + " is not found", e); //$NON-NLS-1$
    }
}

From source file:com.photon.maven.plugins.android.phase08preparepackage.DexMojo.java

/**
 * Gets the input files for dex.  This is a combination of directories and jar files.
 *
 * @return/*  ww  w  .j a va2 s . co  m*/
 */
private Set<File> getDexInputFiles() {

    Set<File> inputs = new HashSet<File>();

    // ugly, don't know a better way to get this in mvn
    File proguardJar = new File(project.getBuild().getDirectory(), ProguardMojo.PROGUARD_OBFUSCATED_JAR);

    getLog().debug("Checking for existence of: " + proguardJar.toString());

    if (proguardJar.exists()) {
        // progurad has been run, use this jar
        getLog().debug("Obfuscated jar exists, using that as input");
        inputs.add(proguardJar);
    } else {
        getLog().debug("Using non-obfuscated input");
        // no proguard, use original config
        inputs.add(new File(project.getBuild().getOutputDirectory()));
        for (Artifact artifact : getAllRelevantDependencyArtifacts()) {
            inputs.add(artifact.getFile().getAbsoluteFile());
        }
    }

    return inputs;
}

From source file:com.addthis.tutor.tree.TutorTree.java

private TreeMapper createMapper(String configuration, File dir) throws IOException {
    ObjectNode treeConfig = Configs.decodeObject(ObjectNode.class, configuration);
    treeConfig.with("config").put("dir", dir.toString());
    return Jackson.defaultCodec().decodeObject(TreeMapper.class, treeConfig);
}