public void packIndex()

in indexer-core/src/main/java/org/apache/maven/index/packer/DefaultIndexPacker.java [66:156]


    public void packIndex(IndexPackingRequest request) throws IOException, IllegalArgumentException {
        if (request.getTargetDir() == null) {
            throw new IllegalArgumentException("The target dir is null");
        }

        if (request.getTargetDir().exists()) {
            if (!request.getTargetDir().isDirectory()) {
                throw new IllegalArgumentException( //
                        String.format(
                                "Specified target path %s is not a directory",
                                request.getTargetDir().getAbsolutePath()));
            }
            if (!request.getTargetDir().canWrite()) {
                throw new IllegalArgumentException(String.format(
                        "Specified target path %s is not writtable",
                        request.getTargetDir().getAbsolutePath()));
            }
        } else {
            if (!request.getTargetDir().mkdirs()) {
                throw new IllegalArgumentException(
                        "Can't create " + request.getTargetDir().getAbsolutePath());
            }
        }

        // These are all of the files we'll be dealing with (except for the incremental chunks of course)
        File v1File = new File(request.getTargetDir(), IndexingContext.INDEX_FILE_PREFIX + ".gz");

        Properties info;

        try {
            // Note that for incremental indexes to work properly, a valid index.properties file
            // must be present
            info = readIndexProperties(request);

            if (request.isCreateIncrementalChunks()) {
                List<Integer> chunk = incrementalHandler.getIncrementalUpdates(request, info);

                if (chunk == null) {
                    getLogger().debug("Problem with Chunks, forcing regeneration of whole index");
                    incrementalHandler.initializeProperties(info);
                } else if (chunk.isEmpty()) {
                    getLogger().debug("No incremental changes, not writing new incremental chunk");
                } else {
                    File file = new File(
                            request.getTargetDir(), //
                            IndexingContext.INDEX_FILE_PREFIX + "."
                                    + info.getProperty(IndexingContext.INDEX_CHUNK_COUNTER) + ".gz");

                    writeIndexData(request, chunk, file);

                    if (request.isCreateChecksumFiles()) {
                        FileUtils.fileWrite(
                                new File(file.getParentFile(), file.getName() + ".sha1").getAbsolutePath(),
                                DigesterUtils.getSha1Digest(file));

                        FileUtils.fileWrite(
                                new File(file.getParentFile(), file.getName() + ".md5").getAbsolutePath(),
                                DigesterUtils.getMd5Digest(file));
                    }
                }
            }
        } catch (IOException e) {
            getLogger().info("Unable to read properties file, will force index regeneration");
            info = new Properties();
            incrementalHandler.initializeProperties(info);
        }

        Date timestamp = request.getContext().getTimestamp();

        if (timestamp == null) {
            timestamp = new Date(0); // never updated
        }

        if (request.getFormats().contains(IndexPackingRequest.IndexFormat.FORMAT_V1)) {
            info.setProperty(IndexingContext.INDEX_TIMESTAMP, format(timestamp));

            writeIndexData(request, null, v1File);

            if (request.isCreateChecksumFiles()) {
                FileUtils.fileWrite(
                        new File(v1File.getParentFile(), v1File.getName() + ".sha1").getAbsolutePath(),
                        DigesterUtils.getSha1Digest(v1File));

                FileUtils.fileWrite(
                        new File(v1File.getParentFile(), v1File.getName() + ".md5").getAbsolutePath(),
                        DigesterUtils.getMd5Digest(v1File));
            }
        }

        writeIndexProperties(request, info);
    }