public ResourceAndInfo buildResourceAndInfo()

in shared/api/src/main/java/org/apache/sling/ide/sync/content/impl/DefaultSyncCommandFactory.java [220:311]


   public ResourceAndInfo buildResourceAndInfo(WorkspaceResource resource, Repository repository) throws IOException {

       if ( !resource.exists() ) {
           return null;
       }

       if ( resource.isIgnored()) {
           logger.trace("Skipping team-private resource {0}", resource);
           return null;
       }

       Long modificationTimestamp = (Long) resource.getTransientProperty(PN_IMPORT_MODIFICATION_TIMESTAMP);

       if (modificationTimestamp != null && modificationTimestamp >= resource.getLastModified()) {
           logger.trace("Change for resource {0} ignored as the import timestamp {1} >= modification timestamp {2}",
                           resource, modificationTimestamp, resource.getLastModified());
           return null;
       }

       FileInfo info = createFileInfo(resource);
       logger.trace("For {0} built fileInfo {1}", resource, info);

       WorkspaceDirectory syncDirectory = resource.getProject().getSyncDirectory();
       File syncDirectoryAsFile = syncDirectory.getOSPath().toFile();

       ResourceProxy resourceProxy = null;

       if (serializationManager.isSerializationFile(resource.getOSPath().toString())) {
           WorkspaceFile file = (WorkspaceFile) resource;
           try (InputStream contents = file.getContents()) {
               String resourceLocation = file.getPathRelativeToSyncDir().asPortableString();
               resourceProxy = serializationManager.readSerializationData(resourceLocation, contents);
               normaliseResourceChildren(file, resourceProxy, repository);


               // TODO - not sure if this 100% correct, but we definitely should not refer to the FileInfo as the
               // .serialization file, since for nt:file/nt:resource nodes this will overwrite the file contents
               String primaryType = (String) resourceProxy.getProperties().get(Repository.JCR_PRIMARY_TYPE);
               if (Repository.NT_FILE.equals(primaryType)) {
                   // TODO move logic to serializationManager
                   File locationFile = new File(info.getLocation());
                   String locationFileParent = locationFile.getParent();
                   int endIndex = locationFileParent.length() - ".dir".length();
                   File actualFile = new File(locationFileParent.substring(0, endIndex));
                   String newLocation = actualFile.getAbsolutePath();
                   String newName = actualFile.getName();
                   String newRelativeLocation = actualFile.getAbsolutePath().substring(
                           syncDirectoryAsFile.getAbsolutePath().length());
                   info = new FileInfo(newLocation, newRelativeLocation, newName);

                   logger.trace("Adjusted original location from {0} to {1}", resourceLocation, newLocation);

               }
           }
       } else {

           // TODO - move logic to serializationManager
           // possible .dir serialization holder
           if (resource instanceof WorkspaceDirectory && resource.getName().endsWith(".dir")) {
               WorkspaceDirectory folder = (WorkspaceDirectory) resource;
               WorkspaceResource contentXml = folder.getFile(new WorkspacePath(".content.xml"));
               // .dir serialization holder ; nothing to process here, the .content.xml will trigger the actual work
               if (contentXml.exists()
                       && serializationManager.isSerializationFile(contentXml.getOSPath().toString())) {
                   return null;
               }
           }

           resourceProxy = buildResourceProxyForPlainFileOrFolder(resource, repository);
       }
       
       if ( resourceProxy == null )
           throw new RuntimeException("ResourceProxy is null for resource " + resource);

       FilterResult filterResult = resource.getProject().getFilter().filter(resourceProxy.getPath());

       switch (filterResult) {

           case ALLOW:
               return new ResourceAndInfo(resourceProxy, info);
           case PREREQUISITE:
               // never try to 'create' the root node, we assume it exists
               if (!resourceProxy.getPath().equals("/")) {
                   // we don't explicitly set the primary type, which will allow the the repository to choose the best
                   // suited one ( typically nt:unstructured )
                   return new ResourceAndInfo(new ResourceProxy(resourceProxy.getPath()), null, true);
               }
           case DENY: // falls through
           default:
               return null;
       }
   }