Example usage for java.nio.file Path toAbsolutePath

List of usage examples for java.nio.file Path toAbsolutePath

Introduction

In this page you can find the example usage for java.nio.file Path toAbsolutePath.

Prototype

Path toAbsolutePath();

Source Link

Document

Returns a Path object representing the absolute path of this path.

Usage

From source file:at.ac.tuwien.ims.latex2mobiformulaconv.converter.Converter.java

/**
 * This will save the HTML markup + css file to a specified folder
 *
 * @param tempFilepath the temp folder where
 * @return//from ww  w  . j av  a 2 s. c  o m
 */
private Path exportMarkup(Path tempFilepath) {
    Path resultPath;
    if (outputPath != null) {
        resultPath = outputPath;
    } else {
        resultPath = workingDirectory;
    }

    Path markupDir = resultPath.resolve(title + "-markup");
    try {
        try {
            Files.createDirectory(markupDir);
        } catch (FileAlreadyExistsException e) {
            // do nothing
        }

        Path tempDirPath = tempFilepath.getParent();
        File tempDir = tempDirPath.toFile();

        // Copy all files from temp folder to the markup output folder
        String[] files = tempDir.list(FileFileFilter.FILE);
        for (int i = 0; i < files.length; i++) {
            Files.copy(tempDirPath.resolve(files[i]), markupDir.resolve(files[i]),
                    StandardCopyOption.REPLACE_EXISTING);
        }

        logger.info("Exported markup to folder: " + markupDir.toAbsolutePath().toString());
    } catch (IOException e) {
        logger.error("Error saving markup files: " + e.getMessage(), e);
        return null;
    }
    return markupDir;
}

From source file:codes.thischwa.c5c.impl.LocalConnector.java

@Override
public boolean rename(String oldBackendPath, String sanitizedName) throws C5CException {
    Path src = buildRealPath(oldBackendPath);
    boolean isDirectory = Files.isDirectory(src);
    if (!Files.exists(src)) {
        logger.error("Source file not found: {}", src.toString());
        FilemanagerException.Key key = (isDirectory) ? FilemanagerException.Key.DirectoryNotExist
                : FilemanagerException.Key.FileNotExists;
        throw new FilemanagerException(FilemanagerAction.RENAME, key, FilenameUtils.getName(oldBackendPath));
    }//w ww . j a v a2 s  .c  om

    Path dest = src.resolveSibling(sanitizedName);
    try {
        Files.move(src, dest);
    } catch (SecurityException | IOException e) {
        logger.warn(String.format("Error while renaming [%s] to [%s]", src.getFileName().toString(),
                dest.getFileName().toString()), e);
        FilemanagerException.Key key = (Files.isDirectory(src))
                ? FilemanagerException.Key.ErrorRenamingDirectory
                : FilemanagerException.Key.ErrorRenamingFile;
        throw new FilemanagerException(FilemanagerAction.RENAME, key, FilenameUtils.getName(oldBackendPath),
                sanitizedName);
    } catch (FileSystemAlreadyExistsException e) {
        logger.warn("Destination file already exists: {}", dest.toAbsolutePath());
        FilemanagerException.Key key = (Files.isDirectory(dest))
                ? FilemanagerException.Key.DirectoryAlreadyExists
                : FilemanagerException.Key.FileAlreadyExists;
        throw new FilemanagerException(FilemanagerAction.RENAME, key, sanitizedName);
    }
    return isDirectory;
}

From source file:org.finra.herd.dao.Log4jOverridableConfigurerTest.java

/**
 * Reads the contents of the resource location, substitutes the filename token (if it exists), and inserts the contents of the resource to the database.
 *
 * @param resourceLocation the resource location of the Log4J configuration.
 * @param outputPath the Log4J output path.
 * @param log4jConfigurationColumn the column name for the Log4J configuration column
 * @param configEntityKey the configuration entity key.
 *
 * @throws Exception if the file contents couldn't be read or the database record couldn't be inserted.
 *///from  w w  w.  j  ava 2s . c om
private void updateDbLog4JConfigurationFromResourceLocation(String resourceLocation, Path outputPath,
        String log4jConfigurationColumn, String configEntityKey) throws Exception {
    // Get the Log4J configuration contents from the classpath file.
    String log4JFileContents = IOUtils.toString(resourceLoader.getResource(resourceLocation).getInputStream());

    // Update the refresh interval to 1 second.
    log4JFileContents = log4JFileContents.replace("monitorInterval=\"0\"", "monitorInterval=\"1\"");

    // Change the tokenized output filename (if it exists) and replace it with a random filename to support multiple invocations of the JUnit.
    log4JFileContents = log4JFileContents.replace(LOG4J_FILENAME_TOKEN,
            outputPath.toAbsolutePath().toString().replace("\\", "/"));

    // Update the data.
    String sql = String.format("UPDATE %s SET %s=? WHERE %s=?", ConfigurationEntity.TABLE_NAME,
            log4jConfigurationColumn, ConfigurationEntity.COLUMN_KEY);
    executePreparedStatement(sql, log4JFileContents, configEntityKey);
}

From source file:com.anritsu.mcreleaseportal.tcintegration.ProcessTCRequest.java

public Result saveChangesXML(String changesXMLFileName) {
    try {/*from  www. j  a  va 2  s. c  o  m*/
        File tempFile = File.createTempFile(changesXMLFileName, "changes.xml");
        String changesXMLUrl = artifactsLocation + "/" + changesXMLFileName;
        System.out.println("Downloading " + changesXMLUrl);
        FileUtils.copyURLToFile(new URL(changesXMLUrl), tempFile);

        Path source = Paths.get((String) tempFile.getAbsolutePath());
        new File(new File("").getAbsolutePath() + "/" + Configuration.getInstance().getSavePath() + "/"
                + mcPackage.getPackageName()).mkdirs();
        Path destination = Paths.get(new File("").getAbsolutePath() + "/"
                + Configuration.getInstance().getSavePath() + "/" + mcPackage.getPackageName() + "/"
                + changesXMLFileName + "_" + mcPackage.getStatus() + "_" + System.currentTimeMillis());

        Files.move(source, destination, StandardCopyOption.REPLACE_EXISTING);
        System.out.println(source.toString() + " renamed to " + destination.toAbsolutePath().toString());
        result.setResultMessage(destination.toAbsolutePath().toString());

    } catch (IOException ex) {
        Logger.getLogger(ProcessTCRequest.class.getName()).log(Level.SEVERE, null, ex);
        result.setResultCode("1");
        result.setResultMessage(ex.getMessage());
    }
    return result;
}

From source file:org.finra.herd.dao.Log4jOverridableConfigurerTest.java

@Test
public void testLog4JExistentOverrideLocation() throws Exception {
    Path configPath = getRandomLog4jConfigPath();
    Path outputPath = getRandomLog4jOutputPath();

    try {//from w ww  .j  ava 2s  .  c om
        // Write a Log4J configuration file that will create a random output file.
        writeFileFromResourceLocation(LOG4J_CONFIG_FILENAME, configPath, outputPath, 1);

        loggingHelper.shutdownLogging();

        Log4jOverridableConfigurer log4jConfigurer = new Log4jOverridableConfigurer();
        log4jConfigurer.setApplicationContext(applicationContext);
        log4jConfigurer
                .setDefaultResourceLocation(DaoEnvTestSpringModuleConfig.TEST_LOG4J_CONFIG_RESOURCE_LOCATION);
        log4jConfigurer.setOverrideResourceLocation(configPath.toAbsolutePath().toUri().toURL().toString());
        log4jConfigurer.postProcessBeforeInitialization(null, null);

        // The override location does exist and should create a log file.
        assertTrue("Log4J output file doesn't exist, but should.", Files.exists(outputPath));
    } finally {
        cleanup(configPath, outputPath);
    }
}

From source file:io.redlink.solrlib.standalone.SolrServerConnector.java

@Override
@SuppressWarnings("squid:S3776")
protected void init(ExecutorService executorService) throws IOException, SolrServerException {
    Preconditions.checkState(initialized.compareAndSet(false, true));
    Preconditions.checkArgument(Objects.nonNull(solrBaseUrl));

    if (configuration.isDeployCores() && Objects.nonNull(configuration.getSolrHome())) {
        final Path solrHome = configuration.getSolrHome();
        Files.createDirectories(solrHome);
        final Path libDir = solrHome.resolve("lib");
        Files.createDirectories(libDir);

        try (HttpSolrClient solrClient = new HttpSolrClient.Builder(solrBaseUrl).build()) {
            for (SolrCoreDescriptor coreDescriptor : coreDescriptors) {
                final String coreName = coreDescriptor.getCoreName();
                if (availableCores.containsKey(coreName)) {
                    log.warn("CoreName-Clash: {} already initialized. Skipping {}", coreName,
                            coreDescriptor.getClass());
                    continue;
                }//  w w w.  j ava  2  s .c o m
                final String remoteName = createRemoteName(coreName);

                final Path coreHome = solrHome.resolve(remoteName);
                coreDescriptor.initCoreDirectory(coreHome, libDir);

                final Path corePropertiesFile = coreHome.resolve("core.properties");
                // core.properties is created by the CreateCore-Command.
                Files.deleteIfExists(corePropertiesFile);

                if (coreDescriptor.getNumShards() > 1 || coreDescriptor.getReplicationFactor() > 1) {
                    log.warn("Deploying {} to SolrServerConnector, ignoring config of shards={},replication={}",
                            coreName, coreDescriptor.getNumShards(), coreDescriptor.getReplicationFactor());
                }

                // Create or reload the core
                if (CoreAdminRequest.getStatus(remoteName, solrClient).getStartTime(remoteName) == null) {
                    final CoreAdminResponse adminResponse = CoreAdminRequest.createCore(remoteName,
                            coreHome.toAbsolutePath().toString(), solrClient);
                } else {
                    final CoreAdminResponse adminResponse = CoreAdminRequest.reloadCore(remoteName, solrClient);
                }
                // schedule client-side core init
                final boolean isNewCore = findInNamedList(
                        CoreAdminRequest.getStatus(remoteName, solrClient).getCoreStatus(remoteName), "index",
                        "lastModified") == null;
                scheduleCoreInit(executorService, coreDescriptor, isNewCore);

                availableCores.put(coreName, coreDescriptor);
            }
        }
    } else {
        try (HttpSolrClient solrClient = new HttpSolrClient.Builder(solrBaseUrl).build()) {
            for (SolrCoreDescriptor coreDescriptor : coreDescriptors) {
                final String coreName = coreDescriptor.getCoreName();
                if (availableCores.containsKey(coreName)) {
                    log.warn("CoreName-Clash: {} already initialized. Skipping {}", coreName,
                            coreDescriptor.getClass());
                    continue;
                }
                final String remoteName = createRemoteName(coreName);
                if (CoreAdminRequest.getStatus(remoteName, solrClient).getStartTime(remoteName) == null) {
                    // Core does not exists
                    log.warn("Collection {} (remote: {}) not available in Solr '{}' "
                            + "but deployCores is set to false", coreName, remoteName, solrBaseUrl);
                } else {
                    log.debug("Collection {} exists in Solr '{}' as {}", coreName, solrBaseUrl, remoteName);
                    scheduleCoreInit(executorService, coreDescriptor, false);
                    availableCores.put(coreName, coreDescriptor);
                }
            }
        }
    }
}

From source file:com.facebook.buck.jvm.java.JarDirectoryStepTest.java

@Test
public void shouldNotifyEventBusWhenDuplicateClassesAreFound() throws IOException {
    Path jarDirectory = folder.newFolder("jarDir");

    Path first = createZip(jarDirectory.resolve("a.jar"), "com/example/Main.class",
            "com/example/common/Helper.class");
    Path second = createZip(jarDirectory.resolve("b.jar"), "com/example/common/Helper.class");

    final Path outputPath = Paths.get("output.jar");
    JarDirectoryStep step = new JarDirectoryStep(new ProjectFilesystem(jarDirectory), outputPath,
            ImmutableSortedSet.of(first.getFileName(), second.getFileName()), "com.example.Main",
            /* manifest file */ null);
    ExecutionContext context = TestExecutionContext.newInstance();

    final BuckEventBusFactory.CapturingConsoleEventListener listener = new BuckEventBusFactory.CapturingConsoleEventListener();
    context.getBuckEventBus().register(listener);

    step.execute(context);//  www.  j  a  v  a2 s .  co  m
    final String expectedMessage = String.format(
            "Duplicate found when adding 'com/example/common/Helper.class' to '%s' from '%s'",
            outputPath.toAbsolutePath(), second.toAbsolutePath());
    assertThat(listener.getLogMessages(), hasItem(expectedMessage));
}

From source file:org.tinymediamanager.ui.movies.settings.MovieSettingsPanel.java

/**
 * Instantiates a new movie settings panel.
 *///from  ww  w.  j av  a 2 s .  co m
public MovieSettingsPanel() {
    setLayout(new FormLayout(
            new ColumnSpec[] { FormSpecs.RELATED_GAP_COLSPEC, ColumnSpec.decode("default:grow"),
                    FormSpecs.RELATED_GAP_COLSPEC, ColumnSpec.decode("default:grow"),
                    FormSpecs.RELATED_GAP_COLSPEC, },
            new RowSpec[] { FormSpecs.RELATED_GAP_ROWSPEC, FormSpecs.DEFAULT_ROWSPEC,
                    FormSpecs.RELATED_GAP_ROWSPEC, FormSpecs.DEFAULT_ROWSPEC, FormSpecs.LINE_GAP_ROWSPEC,
                    RowSpec.decode("default:grow"), }));

    JPanel panelGeneral = new JPanel();
    panelGeneral.setBorder(new TitledBorder(null, BUNDLE.getString("Settings.general"), TitledBorder.LEADING, //$NON-NLS-1$
            TitledBorder.TOP, null, null));
    add(panelGeneral, "2, 2, fill, fill");
    panelGeneral.setLayout(new FormLayout(
            new ColumnSpec[] { FormSpecs.RELATED_GAP_COLSPEC, FormSpecs.DEFAULT_COLSPEC,
                    FormSpecs.RELATED_GAP_COLSPEC, FormSpecs.DEFAULT_COLSPEC, FormSpecs.RELATED_GAP_COLSPEC,
                    FormSpecs.DEFAULT_COLSPEC, FormSpecs.RELATED_GAP_COLSPEC, FormSpecs.DEFAULT_COLSPEC,
                    FormSpecs.RELATED_GAP_COLSPEC, FormSpecs.DEFAULT_COLSPEC, FormSpecs.RELATED_GAP_COLSPEC,
                    ColumnSpec.decode("default:grow"), FormSpecs.RELATED_GAP_COLSPEC, },
            new RowSpec[] { FormSpecs.RELATED_GAP_ROWSPEC, FormSpecs.DEFAULT_ROWSPEC,
                    FormSpecs.LABEL_COMPONENT_GAP_ROWSPEC, FormSpecs.DEFAULT_ROWSPEC,
                    FormSpecs.UNRELATED_GAP_ROWSPEC, FormSpecs.DEFAULT_ROWSPEC, FormSpecs.RELATED_GAP_ROWSPEC,
                    FormSpecs.DEFAULT_ROWSPEC, FormSpecs.RELATED_GAP_ROWSPEC, FormSpecs.DEFAULT_ROWSPEC,
                    FormSpecs.RELATED_GAP_ROWSPEC, FormSpecs.DEFAULT_ROWSPEC, FormSpecs.RELATED_GAP_ROWSPEC,
                    FormSpecs.DEFAULT_ROWSPEC, FormSpecs.RELATED_GAP_ROWSPEC, FormSpecs.DEFAULT_ROWSPEC,
                    FormSpecs.RELATED_GAP_ROWSPEC, FormSpecs.DEFAULT_ROWSPEC,
                    FormSpecs.RELATED_GAP_ROWSPEC, }));

    JLabel lblVisiblecolumns = new JLabel(BUNDLE.getString("Settings.movie.visiblecolumns")); //$NON-NLS-1$
    panelGeneral.add(lblVisiblecolumns, "2, 2, right, default");

    chckbxYear = new JCheckBox(BUNDLE.getString("metatag.year")); //$NON-NLS-1$
    panelGeneral.add(chckbxYear, "4, 2");

    chckbxRating = new JCheckBox(BUNDLE.getString("metatag.rating")); //$NON-NLS-1$
    panelGeneral.add(chckbxRating, "6, 2");

    chckbxNfo = new JCheckBox(BUNDLE.getString("metatag.nfo")); //$NON-NLS-1$
    panelGeneral.add(chckbxNfo, "8, 2");

    chckbxMetadata = new JCheckBox(BUNDLE.getString("tmm.metadata")); //$NON-NLS-1$
    panelGeneral.add(chckbxMetadata, "10, 2");

    chckbxDateAdded = new JCheckBox(BUNDLE.getString("metatag.dateadded")); //$NON-NLS-1$
    panelGeneral.add(chckbxDateAdded, "12, 2");

    chckbxImages = new JCheckBox(BUNDLE.getString("metatag.images")); //$NON-NLS-1$
    panelGeneral.add(chckbxImages, "4, 4");

    chckbxTrailer = new JCheckBox(BUNDLE.getString("metatag.trailer")); //$NON-NLS-1$
    panelGeneral.add(chckbxTrailer, "6, 4");

    chckbxSubtitles = new JCheckBox(BUNDLE.getString("metatag.subtitles")); //$NON-NLS-1$
    panelGeneral.add(chckbxSubtitles, "8, 4");

    chckbxWatched = new JCheckBox(BUNDLE.getString("metatag.watched")); //$NON-NLS-1$
    panelGeneral.add(chckbxWatched, "10, 4");

    JLabel lblSaveUiFilter = new JLabel(BUNDLE.getString("Settings.movie.persistuifilter")); //$NON-NLS-1$
    panelGeneral.add(lblSaveUiFilter, "2, 6, right, default");

    chckbxSaveUiFilter = new JCheckBox("");
    panelGeneral.add(chckbxSaveUiFilter, "4, 6");

    JSeparator separator_4 = new JSeparator();
    panelGeneral.add(separator_4, "2, 8, 11, 1");

    JLabel lblImageCache = new JLabel(BUNDLE.getString("Settings.imagecacheimport"));
    panelGeneral.add(lblImageCache, "2, 10, right, default");

    chckbxImageCache = new JCheckBox(BUNDLE.getString("Settings.imagecacheimporthint")); //$NON-NLS-1$
    TmmFontHelper.changeFont(chckbxImageCache, 0.833);
    panelGeneral.add(chckbxImageCache, "4, 10, 7, 1");

    JLabel lblRuntimeFromMedia = new JLabel(BUNDLE.getString("Settings.runtimefrommediafile"));
    panelGeneral.add(lblRuntimeFromMedia, "2, 12, right, default");

    chckbxRuntimeFromMf = new JCheckBox("");
    panelGeneral.add(chckbxRuntimeFromMf, "4, 12");

    JSeparator separator = new JSeparator();
    panelGeneral.add(separator, "2, 14, 11, 1");

    final JLabel lblAutomaticRename = new JLabel(BUNDLE.getString("Settings.movie.automaticrename")); //$NON-NLS-1$
    panelGeneral.add(lblAutomaticRename, "2, 16, right, default");

    chckbxRename = new JCheckBox(BUNDLE.getString("Settings.movie.automaticrename.desc")); //$NON-NLS-1$
    panelGeneral.add(chckbxRename, "4, 16, 7, 1");

    JLabel lblTraktTv = new JLabel(BUNDLE.getString("Settings.trakt"));//$NON-NLS-1$
    panelGeneral.add(lblTraktTv, "2, 18");

    chckbxTraktTv = new JCheckBox("");
    panelGeneral.add(chckbxTraktTv, "4, 18");

    JButton btnClearTraktTvMovies = new JButton(BUNDLE.getString("Settings.trakt.clearmovies"));//$NON-NLS-1$
    btnClearTraktTvMovies.addActionListener(new ActionListener() {
        @Override
        public void actionPerformed(ActionEvent e) {
            int confirm = JOptionPane.showOptionDialog(null,
                    BUNDLE.getString("Settings.trakt.clearmovies.hint"),
                    BUNDLE.getString("Settings.trakt.clearmovies"), JOptionPane.YES_NO_OPTION, //$NON-NLS-1$
                    JOptionPane.QUESTION_MESSAGE, null, null, null);
            if (confirm == JOptionPane.YES_OPTION) {
                TmmTask task = new ClearTraktTvTask(true, false);
                TmmTaskManager.getInstance().addUnnamedTask(task);
            }
        }
    });
    panelGeneral.add(btnClearTraktTvMovies, "6, 18, 3, 1, left, default");

    JPanel panelMovieDataSources = new JPanel();

    panelMovieDataSources.setBorder(new TitledBorder(null, BUNDLE.getString("Settings.movie.datasource"), //$NON-NLS-1$
            TitledBorder.LEADING, TitledBorder.TOP, null, null));
    add(panelMovieDataSources, "2, 4, 3, 1, fill, fill");
    panelMovieDataSources.setLayout(new FormLayout(
            new ColumnSpec[] { FormSpecs.RELATED_GAP_COLSPEC, FormSpecs.DEFAULT_COLSPEC,
                    FormSpecs.RELATED_GAP_COLSPEC, FormSpecs.DEFAULT_COLSPEC, FormSpecs.RELATED_GAP_COLSPEC,
                    ColumnSpec.decode("150dlu:grow"), FormSpecs.RELATED_GAP_COLSPEC, FormSpecs.DEFAULT_COLSPEC,
                    FormSpecs.RELATED_GAP_COLSPEC, FormSpecs.UNRELATED_GAP_COLSPEC,
                    FormSpecs.RELATED_GAP_COLSPEC, ColumnSpec.decode("150dlu:grow(2)"),
                    FormSpecs.RELATED_GAP_COLSPEC, FormSpecs.DEFAULT_COLSPEC, FormSpecs.RELATED_GAP_COLSPEC, },
            new RowSpec[] { FormSpecs.RELATED_GAP_ROWSPEC, FormSpecs.DEFAULT_ROWSPEC,
                    FormSpecs.LABEL_COMPONENT_GAP_ROWSPEC, RowSpec.decode("100px:grow"),
                    FormSpecs.RELATED_GAP_ROWSPEC, FormSpecs.DEFAULT_ROWSPEC, FormSpecs.RELATED_GAP_ROWSPEC,
                    FormSpecs.DEFAULT_ROWSPEC, FormSpecs.RELATED_GAP_ROWSPEC, }));

    JLabel lblDataSource = new JLabel(BUNDLE.getString("Settings.source")); //$NON-NLS-1$
    panelMovieDataSources.add(lblDataSource, "2, 2, 5, 1");

    JLabel lblIngore = new JLabel(BUNDLE.getString("Settings.ignore")); //$NON-NLS-1$
    panelMovieDataSources.add(lblIngore, "12, 2");

    JScrollPane scrollPaneDataSources = new JScrollPane();
    panelMovieDataSources.add(scrollPaneDataSources, "2, 4, 5, 1, fill, fill");

    listDataSources = new JList<>();
    scrollPaneDataSources.setViewportView(listDataSources);

    JPanel panelMovieSourcesButtons = new JPanel();
    panelMovieDataSources.add(panelMovieSourcesButtons, "8, 4, fill, top");
    panelMovieSourcesButtons
            .setLayout(new FormLayout(new ColumnSpec[] { FormSpecs.DEFAULT_COLSPEC, }, new RowSpec[] {
                    FormSpecs.DEFAULT_ROWSPEC, FormSpecs.RELATED_GAP_ROWSPEC, FormSpecs.DEFAULT_ROWSPEC, }));

    JButton btnAdd = new JButton(IconManager.LIST_ADD);
    btnAdd.setToolTipText(BUNDLE.getString("Button.add")); //$NON-NLS-1$
    btnAdd.setMargin(new Insets(2, 2, 2, 2));
    btnAdd.addActionListener(new ActionListener() {
        @Override
        public void actionPerformed(ActionEvent arg0) {
            Path file = TmmUIHelper.selectDirectory(BUNDLE.getString("Settings.datasource.folderchooser")); //$NON-NLS-1$
            if (file != null && Files.isDirectory(file)) {
                settings.addMovieDataSources(file.toAbsolutePath().toString());
            }
        }
    });

    panelMovieSourcesButtons.add(btnAdd, "1, 1, fill, top");

    JButton btnRemove = new JButton(IconManager.LIST_REMOVE);
    btnRemove.setToolTipText(BUNDLE.getString("Button.remove")); //$NON-NLS-1$
    btnRemove.setMargin(new Insets(2, 2, 2, 2));
    btnRemove.addActionListener(new ActionListener() {
        @Override
        public void actionPerformed(ActionEvent arg0) {
            int row = listDataSources.getSelectedIndex();
            if (row != -1) { // nothing selected
                String path = MovieModuleManager.MOVIE_SETTINGS.getMovieDataSource().get(row);
                String[] choices = { BUNDLE.getString("Button.continue"), BUNDLE.getString("Button.abort") }; //$NON-NLS-1$
                int decision = JOptionPane.showOptionDialog(null,
                        String.format(BUNDLE.getString("Settings.movie.datasource.remove.info"), path),
                        BUNDLE.getString("Settings.datasource.remove"), JOptionPane.YES_NO_OPTION,
                        JOptionPane.PLAIN_MESSAGE, null, choices, BUNDLE.getString("Button.abort")); //$NON-NLS-1$
                if (decision == 0) {
                    setCursor(Cursor.getPredefinedCursor(Cursor.WAIT_CURSOR));
                    MovieModuleManager.MOVIE_SETTINGS.removeMovieDataSources(path);
                    setCursor(Cursor.getPredefinedCursor(Cursor.DEFAULT_CURSOR));
                }
            }
        }
    });
    panelMovieSourcesButtons.add(btnRemove, "1, 3, fill, top");

    JScrollPane scrollPaneIgnore = new JScrollPane();
    panelMovieDataSources.add(scrollPaneIgnore, "12, 4, fill, fill");

    listIgnore = new JList<>();
    scrollPaneIgnore.setViewportView(listIgnore);

    JPanel panelIgnoreButtons = new JPanel();
    panelMovieDataSources.add(panelIgnoreButtons, "14, 4, fill, fill");
    panelIgnoreButtons.setLayout(new FormLayout(new ColumnSpec[] { FormSpecs.DEFAULT_COLSPEC, }, new RowSpec[] {
            FormSpecs.DEFAULT_ROWSPEC, FormSpecs.RELATED_GAP_ROWSPEC, FormSpecs.DEFAULT_ROWSPEC, }));

    JButton btnAddIgnore = new JButton(IconManager.LIST_ADD);
    btnAddIgnore.setToolTipText(BUNDLE.getString("Settings.addignore")); //$NON-NLS-1$
    btnAddIgnore.setMargin(new Insets(2, 2, 2, 2));
    btnAddIgnore.addActionListener(new ActionListener() {
        @Override
        public void actionPerformed(ActionEvent e) {
            Path file = TmmUIHelper.selectDirectory(BUNDLE.getString("Settings.ignore")); //$NON-NLS-1$
            if (file != null && Files.isDirectory(file)) {
                settings.addMovieSkipFolder(file.toAbsolutePath().toString());
            }
        }
    });
    panelIgnoreButtons.add(btnAddIgnore, "1, 1");

    JButton btnRemoveIgnore = new JButton(IconManager.LIST_REMOVE);
    btnRemoveIgnore.setToolTipText(BUNDLE.getString("Settings.removeignore")); //$NON-NLS-1$
    btnRemoveIgnore.setMargin(new Insets(2, 2, 2, 2));
    btnRemoveIgnore.addActionListener(new ActionListener() {
        @Override
        public void actionPerformed(ActionEvent e) {
            int row = listIgnore.getSelectedIndex();
            if (row != -1) { // nothing selected
                String ingore = settings.getMovieSkipFolders().get(row);
                settings.removeMovieSkipFolder(ingore);
            }
        }
    });
    panelIgnoreButtons.add(btnRemoveIgnore, "1, 3");

    JPanel panel = new JPanel();
    panelMovieDataSources.add(panel, "2, 8, 13, 1, fill, fill");
    panel.setLayout(new FormLayout(
            new ColumnSpec[] { FormSpecs.DEFAULT_COLSPEC, FormSpecs.RELATED_GAP_COLSPEC,
                    FormSpecs.DEFAULT_COLSPEC, FormSpecs.RELATED_GAP_COLSPEC, ColumnSpec.decode("20dlu"),
                    FormSpecs.RELATED_GAP_COLSPEC, FormSpecs.DEFAULT_COLSPEC, FormSpecs.RELATED_GAP_COLSPEC,
                    FormSpecs.DEFAULT_COLSPEC, FormSpecs.RELATED_GAP_COLSPEC, ColumnSpec.decode("default:grow"),
                    FormSpecs.RELATED_GAP_COLSPEC, FormSpecs.DEFAULT_COLSPEC, },
            new RowSpec[] { FormSpecs.DEFAULT_ROWSPEC, FormSpecs.DEFAULT_ROWSPEC, FormSpecs.DEFAULT_ROWSPEC,
                    FormSpecs.RELATED_GAP_ROWSPEC, FormSpecs.DEFAULT_ROWSPEC, }));

    JLabel lblNfoFormat = new JLabel(BUNDLE.getString("Settings.nfoFormat"));
    panel.add(lblNfoFormat, "1, 1, right, default");

    cbNfoFormat = new JComboBox(MovieConnectors.values());
    panel.add(cbNfoFormat, "3, 1, fill, default");

    JLabel lblNfoFileNaming = new JLabel(BUNDLE.getString("Settings.nofFileNaming")); //$NON-NLS-1$
    panel.add(lblNfoFileNaming, "7, 1, right, default");

    cbMovieNfoFilename1 = new JCheckBox(BUNDLE.getString("Settings.moviefilename") + ".nfo"); //$NON-NLS-1$
    panel.add(cbMovieNfoFilename1, "9, 1");

    cbMovieNfoFilename2 = new JCheckBox("movie.nfo");
    panel.add(cbMovieNfoFilename2, "9, 2");
    cbMovieNfoFilename2.addItemListener(new ItemListener() {
        @Override
        public void itemStateChanged(ItemEvent e) {
            checkChanges();
        }
    });

    cbMovieNfoFilename3 = new JCheckBox(BUNDLE.getString("Settings.nfo.discstyle")); //$NON-NLS-1$
    panel.add(cbMovieNfoFilename3, "9, 3");
    cbMovieNfoFilename3.addItemListener(new ItemListener() {
        @Override
        public void itemStateChanged(ItemEvent e) {
            checkChanges();
        }
    });

    final JLabel lblCertificationStyle = new JLabel(BUNDLE.getString("Settings.certificationformat")); //$NON-NLS-1$
    panel.add(lblCertificationStyle, "1, 5, right, default");

    cbCertificationStyle = new JComboBox();
    panel.add(cbCertificationStyle, "3, 5, 7, 1, fill, default");

    JPanel panelBadWords = new JPanel();
    panelBadWords.setBorder(new TitledBorder(null, BUNDLE.getString("Settings.movie.badwords"), //$NON-NLS-1$
            TitledBorder.LEADING, TitledBorder.TOP, null, null));
    add(panelBadWords, "4, 2, fill, fill");
    panelBadWords.setLayout(new FormLayout(
            new ColumnSpec[] { FormFactory.RELATED_GAP_COLSPEC, ColumnSpec.decode("50px:grow"),
                    FormFactory.RELATED_GAP_COLSPEC, FormFactory.DEFAULT_COLSPEC, },
            new RowSpec[] { FormFactory.RELATED_GAP_ROWSPEC, FormFactory.DEFAULT_ROWSPEC,
                    FormFactory.RELATED_GAP_ROWSPEC, RowSpec.decode("default:grow"),
                    FormFactory.RELATED_GAP_ROWSPEC, FormFactory.DEFAULT_ROWSPEC, }));

    JTextPane txtpntBadWordsHint = new JTextPane();
    txtpntBadWordsHint.setBackground(UIManager.getColor("Panel.background"));
    txtpntBadWordsHint.setText(BUNDLE.getString("Settings.movie.badwords.hint")); //$NON-NLS-1$
    TmmFontHelper.changeFont(txtpntBadWordsHint, 0.833);
    panelBadWords.add(txtpntBadWordsHint, "2, 2, 3, 1, fill, default");

    JScrollPane scpBadWords = new JScrollPane();
    panelBadWords.add(scpBadWords, "2, 4, fill, fill");

    listBadWords = new JList<>();
    scpBadWords.setViewportView(listBadWords);

    JButton btnRemoveBadWord = new JButton(IconManager.LIST_REMOVE);
    btnRemoveBadWord.setToolTipText(BUNDLE.getString("Button.remove")); //$NON-NLS-1$
    btnRemoveBadWord.setMargin(new Insets(2, 2, 2, 2));
    btnRemoveBadWord.addActionListener(new ActionListener() {
        @Override
        public void actionPerformed(ActionEvent arg0) {
            int row = listBadWords.getSelectedIndex();
            if (row != -1) {
                String badWord = MovieModuleManager.MOVIE_SETTINGS.getBadWords().get(row);
                MovieModuleManager.MOVIE_SETTINGS.removeBadWord(badWord);
            }
        }
    });
    panelBadWords.add(btnRemoveBadWord, "4, 4, default, bottom");

    tfAddBadword = new JTextField();
    tfAddBadword.setColumns(10);
    panelBadWords.add(tfAddBadword, "2, 6, fill, default");

    JButton btnAddBadWord = new JButton(IconManager.LIST_ADD);
    btnAddBadWord.setToolTipText(BUNDLE.getString("Button.add")); //$NON-NLS-1$
    btnAddBadWord.setMargin(new Insets(2, 2, 2, 2));
    btnAddBadWord.addActionListener(new ActionListener() {
        @Override
        public void actionPerformed(ActionEvent e) {
            if (StringUtils.isNotEmpty(tfAddBadword.getText())) {
                MovieModuleManager.MOVIE_SETTINGS.addBadWord(tfAddBadword.getText());
                tfAddBadword.setText("");
            }
        }
    });
    panelBadWords.add(btnAddBadWord, "4, 6");

    initDataBindings();

    {
        // NFO filenames
        List<MovieNfoNaming> movieNfoFilenames = settings.getMovieNfoFilenames();
        if (movieNfoFilenames.contains(MovieNfoNaming.FILENAME_NFO)) {
            cbMovieNfoFilename1.setSelected(true);
        }
        if (movieNfoFilenames.contains(MovieNfoNaming.MOVIE_NFO)) {
            cbMovieNfoFilename2.setSelected(true);
        }
        if (movieNfoFilenames.contains(MovieNfoNaming.DISC_NFO)) {
            cbMovieNfoFilename3.setSelected(true);
        }

        if (!Globals.isDonator()) {
            chckbxTraktTv.setSelected(false);
            chckbxTraktTv.setEnabled(false);
            btnClearTraktTvMovies.setEnabled(false);
        }

        // set default certification style
        cbNfoFormat.addItemListener(new ItemListener() {
            @Override
            public void itemStateChanged(ItemEvent e) {
                if (cbNfoFormat.getSelectedItem() == MovieConnectors.MP) {
                    for (int i = 0; i < cbCertificationStyle.getItemCount(); i++) {
                        CertificationStyleWrapper wrapper = cbCertificationStyle.getItemAt(i);
                        if (wrapper.style == CertificationStyle.TECHNICAL) {
                            cbCertificationStyle.setSelectedItem(wrapper);
                            break;
                        }
                    }
                } else if (cbNfoFormat.getSelectedItem() == MovieConnectors.XBMC
                        || cbNfoFormat.getSelectedItem() == MovieConnectors.KODI) {
                    for (int i = 0; i < cbCertificationStyle.getItemCount(); i++) {
                        CertificationStyleWrapper wrapper = cbCertificationStyle.getItemAt(i);
                        if (wrapper.style == CertificationStyle.LARGE) {
                            cbCertificationStyle.setSelectedItem(wrapper);
                            break;
                        }
                    }
                }
            }
        });

        // certification examples
        for (CertificationStyle style : CertificationStyle.values()) {
            CertificationStyleWrapper wrapper = new CertificationStyleWrapper();
            wrapper.style = style;
            cbCertificationStyle.addItem(wrapper);
            if (style == settings.getMovieCertificationStyle()) {
                cbCertificationStyle.setSelectedItem(wrapper);
            }
        }

        cbCertificationStyle.addItemListener(new ItemListener() {
            @Override
            public void itemStateChanged(ItemEvent e) {
                checkChanges();
            }
        });

        // item listener
        cbMovieNfoFilename1.addItemListener(new ItemListener() {
            @Override
            public void itemStateChanged(ItemEvent e) {
                checkChanges();
            }
        });
    }

}

From source file:org.codice.ddf.configuration.migration.ExportMigrationContextImplTest.java

@Test
public void testEntriesWithAbsolutePathUnderDDFHome() throws Exception {
    final Path etc = createDirectory("etc");
    final Path ks = createDirectory("etc", "keystores");
    final Path other = createDirectory("other");
    final List<Path> paths = createFiles(etc, "test.cfg", "test2.config", "test3.properties");

    createFiles(paths, ks, "serverKeystore.jks", "serverTruststore.jks");
    createFiles(other, "a", "b");
    createDirectory("etc", "keystores", "empty");

    final List<ExportMigrationEntry> entries = context.entries(etc.toAbsolutePath())
            .collect(Collectors.toList());

    Assert.assertThat(entries.stream().map(ExportMigrationEntry::getPath).collect(Collectors.toList()),
            Matchers.containsInAnyOrder(paths.toArray()));
    // finally make sure no warnings or errors were recorded
    Assert.assertThat(report.hasErrors(), Matchers.equalTo(false));
    Assert.assertThat(report.hasWarnings(), Matchers.equalTo(false));
}