Exemplo n.º 1
0
 public long getModificationStamp(IResource resource) {
   if (!(resource instanceof IFile)) return resource.getModificationStamp();
   IFile file = (IFile) resource;
   ITextFileBuffer buffer = getBuffer(file);
   if (buffer == null) {
     return file.getModificationStamp();
   } else {
     IDocument document = buffer.getDocument();
     if (document instanceof IDocumentExtension4) {
       return ((IDocumentExtension4) document).getModificationStamp();
     } else {
       return file.getModificationStamp();
     }
   }
 }
Exemplo n.º 2
0
 private static Map<IFile, Long> createModificationStampMap(List<IFile> files) {
   Map<IFile, Long> map = new HashMap<>();
   for (IFile file : files) {
     map.put(file, new Long(file.getModificationStamp()));
   }
   return map;
 }
Exemplo n.º 3
0
 private static Map createModificationStampMap(List files) {
   Map map = new HashMap();
   for (Iterator iter = files.iterator(); iter.hasNext(); ) {
     IFile file = (IFile) iter.next();
     map.put(file, Long.valueOf(file.getModificationStamp()));
   }
   return map;
 }
  /*
   * (non-Jsdoc)
   *
   * @see org.talend.designer.codegen.AbstractRoutineSynchronizer#doSyncBean(org.talend.core.model.properties.Item,
   * boolean)
   */
  @Override
  protected void doSyncBean(Item item, boolean copyToTemp) throws SystemException {
    if (item instanceof BeanItem) {
      BeanItem beanItem = (BeanItem) item;
      FileOutputStream fos = null;
      try {
        IFile file = getBeanFile(beanItem);
        if (file == null) {
          return;
        }
        if (beanItem.getProperty().getModificationDate() != null) {
          long modificationItemDate = beanItem.getProperty().getModificationDate().getTime();
          long modificationFileDate = file.getModificationStamp();
          if (modificationItemDate <= modificationFileDate) {
            return;
          }
        } else {
          beanItem.getProperty().setModificationDate(new Date());
        }

        if (copyToTemp) {
          String beanContent = new String(beanItem.getContent().getInnerContent());
          // see 14713
          String version = VersionUtils.getVersion();
          if (beanContent.contains("%GENERATED_LICENSE%")) { // $NON-NLS-1$
            IService service =
                GlobalServiceRegister.getDefault().getService(IBrandingService.class);
            if (service instanceof AbstractBrandingService) {
              String routineHeader =
                  ((AbstractBrandingService) service).getRoutineLicenseHeader(version);
              beanContent =
                  beanContent.replace("%GENERATED_LICENSE%", routineHeader); // $NON-NLS-1$
            }
          } // end
          String label = beanItem.getProperty().getLabel();
          if (!label.equals(ITalendSynchronizer.BEAN_TEMPLATE) && beanContent != null) {
            beanContent = beanContent.replaceAll(ITalendSynchronizer.BEAN_TEMPLATE, label);
            File f = file.getLocation().toFile();
            fos = new FileOutputStream(f);
            fos.write(beanContent.getBytes());
            fos.close();
          }
        }
        file.refreshLocal(1, null);
      } catch (CoreException e) {
        throw new SystemException(e);
      } catch (IOException e) {
        throw new SystemException(e);
      } finally {
        try {
          fos.close();
        } catch (Exception e) {
          // ignore me even if i'm null
        }
      }
    }
  }
  /**
   * Method validateEdit.
   *
   * @param file org.eclipse.core.resources.IFile
   * @param context org.eclipse.swt.widgets.Shell
   * @return IStatus
   */
  private static IStatus validateEdit(IFile file, Shell context) {
    if (file == null || !file.exists()) return STATUS_ERROR;
    if (!(file.isReadOnly())) return STATUS_OK;

    IPath location = file.getLocation();

    final long beforeModifiedFromJavaIO =
        (location != null) ? location.toFile().lastModified() : IResource.NULL_STAMP;
    final long beforeModifiedFromIFile = file.getModificationStamp();

    IStatus status = ResourcesPlugin.getWorkspace().validateEdit(new IFile[] {file}, context);
    if (!status.isOK()) return status;

    final long afterModifiedFromJavaIO =
        (location != null) ? location.toFile().lastModified() : IResource.NULL_STAMP;
    final long afterModifiedFromIFile = file.getModificationStamp();

    if (beforeModifiedFromJavaIO != afterModifiedFromJavaIO
        || beforeModifiedFromIFile != afterModifiedFromIFile) {
      IModelManager manager = StructuredModelManager.getModelManager();
      IStructuredModel model = manager.getExistingModelForRead(file);
      if (model != null) {
        if (!model.isDirty()) {
          try {
            file.refreshLocal(IResource.DEPTH_ONE, null);
          } catch (CoreException e) {
            return STATUS_ERROR;
          } finally {
            model.releaseFromRead();
          }
        } else {
          model.releaseFromRead();
        }
      }
    }

    if ((beforeModifiedFromJavaIO != afterModifiedFromJavaIO)
        || (beforeModifiedFromIFile != afterModifiedFromIFile)) {
      // the file is replaced. Modification cannot be
      // applied.
      return STATUS_ERROR;
    }
    return STATUS_OK;
  }
 /** @generated */
 private long computeModificationStamp(ResourceSetInfo info) {
   int result = 0;
   for (Iterator it = info.getResourceSet().getResources().iterator(); it.hasNext(); ) {
     Resource nextResource = (Resource) it.next();
     IFile file = WorkspaceSynchronizer.getFile(nextResource);
     if (file != null) {
       if (file.getLocation() != null) {
         result += file.getLocation().toFile().lastModified();
       } else {
         result += file.getModificationStamp();
       }
     }
   }
   return result;
 }
Exemplo n.º 7
0
 public static void updatePersistentProperties(
     IFile resource, SonarProject sonarProject, ISonarServer sonarServer) {
   try {
     resource.setPersistentProperty(
         MODIFICATION_STAMP_PERSISTENT_PROP_KEY, "" + resource.getModificationStamp());
     resource.setPersistentProperty(
         LAST_ANALYSIS_DATE_PERSISTENT_PROP_KEY,
         ""
             + WSClientFactory.getSonarClient(sonarServer)
                 .getLastAnalysisDate(sonarProject.getKey())
                 .getTime());
   } catch (CoreException e) {
     LOG.error("Unable to update persistent properties", e);
   }
 }
Exemplo n.º 8
0
 @Override
 public String getRevisionIdentification() {
   String path = reachable.getPath();
   if ("file".equals(reachable.getScheme())) {
     File f = new File(path);
     if (f.exists()) {
       return String.valueOf(f.lastModified());
     }
   } else if ("platform".equals(reachable.getScheme())) {
     IFile f = ResourcesPlugin.getWorkspace().getRoot().getFile(new Path(path));
     if (f.exists()) {
       return String.valueOf(f.getModificationStamp());
     }
   }
   return null;
 }
Exemplo n.º 9
0
 private void initializeFile(IFile file) {
   fTextFileBuffer = getBuffer(file);
   if (fTextFileBuffer == null) {
     initializeResource(file);
   } else {
     IDocument document = fTextFileBuffer.getDocument();
     fDirty = fTextFileBuffer.isDirty();
     fReadOnly = isReadOnly(file);
     if (document instanceof IDocumentExtension4) {
       fKind = DOCUMENT;
       fModificationStamp = ((IDocumentExtension4) document).getModificationStamp();
     } else {
       fKind = RESOURCE;
       fModificationStamp = file.getModificationStamp();
     }
   }
 }