Package org.sonatype.nexus.proxy.attributes

Examples of org.sonatype.nexus.proxy.attributes.JacksonJSONMarshaller


    FileUtils.copyDirectory(getTestResourceAsFile("storage/"), storageWorkDir);

    // now setup all the attributes
    File attributesInfo = getTestResourceAsFile("attributes.info");

    final Marshaller marshaller = new JacksonJSONMarshaller();

    final long now = System.currentTimeMillis();

    try (BufferedReader reader = new BufferedReader(new FileReader(attributesInfo))) {

      String line = reader.readLine();
      while (line != null) {
        final String[] parts = line.split(" ");
        final String repoFilePart = parts[0];
        final String repoId = repoFilePart.substring(0, repoFilePart.indexOf('/'));
        final String filePart = repoFilePart.substring(repoFilePart.indexOf('/'), repoFilePart.length());
        long offset = TimeUnit.DAYS.toMillis(Long.parseLong(parts[1]));

        // get the file
        File itemFile = new File(storageWorkDir, repoFilePart);
        if (itemFile.isFile()) {
          this.pathMap.put(repoFilePart, Integer.parseInt(parts[1]));

                    /*
                     * groups are not checked, so the hashes are left behind, see: NEXUS-3026
                     */
          if (repoFilePart.startsWith("releases/") || repoFilePart.startsWith("releases-m1/")
              || repoFilePart.startsWith("public/") || repoFilePart.startsWith("snapshots/")
              || repoFilePart.startsWith("thirdparty/") || repoFilePart.contains(".meta")
              || repoFilePart.contains(".index")) {
            neverDeleteFiles.add(repoFilePart);
          }

          // modify the file corresponding attribute
          final File attributeFile = new File(new File(new File(storageWorkDir, repoId), ".nexus/attributes"), filePart);
          Attributes attributes;
          try (FileInputStream in = new FileInputStream(attributeFile)) {
            attributes = marshaller.unmarshal(in);
          }

          // set new value
          attributes.setLastRequested(now + offset);

          // write it out
          try (FileOutputStream out = new FileOutputStream(attributeFile)) {
            marshaller.marshal(attributes, out);
          }
        }

        line = reader.readLine();
      }
View Full Code Here


    // clean unused
    TaskScheduleUtil.runTask(taskName, EvictUnusedItemsTaskDescriptor.ID, repo, age);
  }

  private Marshaller getMarshaller() {
    return new JacksonJSONMarshaller();
  }
View Full Code Here

TOP

Related Classes of org.sonatype.nexus.proxy.attributes.JacksonJSONMarshaller

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.