CloneSet93


Previous CloneSetNext CloneSetBack to Main Report
Clone
Mass
Clones in
CloneSet
Parameter
Count
Clone
Similarity
Syntax Category
[Sequence Length]
83210.999class_body_declarations[3]
Clone AbstractionParameter Bindings
Clone Instance
(Click to see clone)
Line CountSource Line
Source File
183213
plugins/org.eclipse.jdt.ui/ui/org/eclipse/jdt/ui/jarpackager/JarWriter.java
283229
plugins/org.eclipse.jdt.ui/ui/org/eclipse/jdt/ui/jarpackager/JarWriter2.java
Clone Instance
1
Line Count
83
Source Line
213
Source File
plugins/org.eclipse.jdt.ui/ui/org/eclipse/jdt/ui/jarpackager/JarWriter.java

        /**
         * Add the directory entries for the given path to the jar.
         * 
         * @param destinationPath the path to add
         * @param correspondingFile the corresponding file in the file system 
         *  or <code>null</code> if it doesn't exist
         * @throws IOException if an I/O error has occurred  
         */
        private void addDirectories(IPath destinationPath, File correspondingFile) throws IOException {
                String path = destinationPath.toString().replace(File.separatorChar, '/');
                int lastSlash = path.lastIndexOf('/');
                List directories = new ArrayList(2);
                while (lastSlash != -1) {
                        path = path.substring(0, lastSlash + 1);
                        if ( !fDirectories.add(path))
                                break;

                        if (correspondingFile != null)
                                correspondingFile = correspondingFile.getParentFile();
                        long timeStamp = correspondingFile != null && correspondingFile.exists() ?
                                   correspondingFile.lastModified():
                                   System.currentTimeMillis();

                        JarEntry newEntry = new JarEntry(path);
                        newEntry.setMethod(ZipEntry.STORED);
                        newEntry.setSize(0);
                        newEntry.setCrc(0);
                        newEntry.setTime(timeStamp);
                        directories.add(newEntry);

                        lastSlash = path.lastIndexOf('/', lastSlash - 1);
                }

                for (int i = directories.size() - 1; i >= 0; --i) {
                        fJarOutputStream.putNextEntry((JarEntry) directories.get(i));
                }
        }

        /**
         * Checks if the JAR file can be overwritten.
         * If the JAR package setting does not allow to overwrite the JAR
         * then a dialog will ask the user again.
         * 
         * @param       parent  the parent for the dialog,
         *                      or <code>null</code> if no dialog should be presented
         * @return      <code>true</code> if it is OK to create the JAR
         */
        protected boolean canCreateJar(Shell parent) {
                File file = fJarPackage.getAbsoluteJarLocation().toFile();
                if (file.exists()) {
                        if ( !file.canWrite())
                                return false;
                        if (fJarPackage.allowOverwrite())
                                return true;
                        return parent != null && JarPackagerUtil.askForOverwritePermission(parent, fJarPackage.getAbsoluteJarLocation().toOSString());
                }

                // Test if directory exists
                String path = file.getAbsolutePath();
                int separatorIndex = path.lastIndexOf(File.separator);
                if (separatorIndex == -1) // i.e.- default directory, which is fine
                        return true;
                File directory = new File(path.substring(0, separatorIndex));
                if ( !directory.exists()) {
                        if (JarPackagerUtil.askToCreateDirectory(parent, directory))
                                return directory.mkdirs();
                        else
                                return false;
                }
                return true;
        }

        private void registerInWorkspaceIfNeeded() {
                IPath jarPath = fJarPackage.getAbsoluteJarLocation();
                IProject[] projects = ResourcesPlugin.getWorkspace().getRoot().getProjects();
                for (int i = 0; i < projects.length; i++) {
                        IProject project = projects[i];
                        // The Jar is always put into the local file system. So it can only be
                        // part of a project if the project is local as well. So using getLocation
                        // is currently save here.
                        IPath projectLocation = project.getLocation();
                        if (projectLocation != null && projectLocation.isPrefixOf(jarPath)) {
                                try {
                                        jarPath = jarPath.removeFirstSegments(projectLocation.segmentCount());
                                        jarPath = jarPath.removeLastSegments(1);
                                        IResource containingFolder = project.findMember(jarPath);
                                        if (containingFolder != null && containingFolder.isAccessible())
                                                containingFolder.refreshLocal(IResource.DEPTH_ONE, null);
                                } catch (CoreException ex) {
                                        // don't refresh the folder but log the problem
                                        JavaPlugin.log(ex);
                                  }
                        }
                }
        }


Clone Instance
2
Line Count
83
Source Line
229
Source File
plugins/org.eclipse.jdt.ui/ui/org/eclipse/jdt/ui/jarpackager/JarWriter2.java

        /**
         * Creates the directory entries for the given path and writes it to the 
         * current archive.
         * 
         * @param destinationPath       the path to add
         * @param correspondingFile the corresponding file in the file system 
         *                                              or <code>null</code> if it doesn't exist
         * @throws IOException if an I/O error has occurred  
         */
        protected void addDirectories(IPath destinationPath, File correspondingFile) throws IOException {
                String path = destinationPath.toString().replace(File.separatorChar, '/');
                int lastSlash = path.lastIndexOf('/');
                List directories = new ArrayList(2);
                while (lastSlash != -1) {
                        path = path.substring(0, lastSlash + 1);
                        if ( !fDirectories.add(path))
                                break;

                        if (correspondingFile != null)
                                correspondingFile = correspondingFile.getParentFile();
                        long timeStamp = correspondingFile != null && correspondingFile.exists() ?
                                   correspondingFile.lastModified():
                                   System.currentTimeMillis();

                        JarEntry newEntry = new JarEntry(path);
                        newEntry.setMethod(ZipEntry.STORED);
                        newEntry.setSize(0);
                        newEntry.setCrc(0);
                        newEntry.setTime(timeStamp);
                        directories.add(newEntry);

                        lastSlash = path.lastIndexOf('/', lastSlash - 1);
                }

                for (int i = directories.size() - 1; i >= 0; --i) {
                        fJarOutputStream.putNextEntry((JarEntry) directories.get(i));
                }
        }

        /**
         * Checks if the JAR file can be overwritten.
         * If the JAR package setting does not allow to overwrite the JAR
         * then a dialog will ask the user again.
         * 
         * @param       parent  the parent for the dialog,
         *                      or <code>null</code> if no dialog should be presented
         * @return      <code>true</code> if it is OK to create the JAR
         */
        protected boolean canCreateJar(Shell parent) {
                File file = fJarPackage.getAbsoluteJarLocation().toFile();
                if (file.exists()) {
                        if ( !file.canWrite())
                                return false;
                        if (fJarPackage.allowOverwrite())
                                return true;
                        return parent != null && JarPackagerUtil.askForOverwritePermission(parent, fJarPackage.getAbsoluteJarLocation().toOSString());
                }

                // Test if directory exists
                String path = file.getAbsolutePath();
                int separatorIndex = path.lastIndexOf(File.separator);
                if (separatorIndex == -1) // i.e.- default directory, which is fine
                        return true;
                File directory = new File(path.substring(0, separatorIndex));
                if ( !directory.exists()) {
                        if (JarPackagerUtil.askToCreateDirectory(parent, directory))
                                return directory.mkdirs();
                        else
                                return false;
                }
                return true;
        }

        private void registerInWorkspaceIfNeeded() {
                IPath jarPath = fJarPackage.getAbsoluteJarLocation();
                IProject[] projects = ResourcesPlugin.getWorkspace().getRoot().getProjects();
                for (int i = 0; i < projects.length; i++) {
                        IProject project = projects[i];
                        // The Jar is always put into the local file system. So it can only be
                        // part of a project if the project is local as well. So using getLocation
                        // is currently save here.
                        IPath projectLocation = project.getLocation();
                        if (projectLocation != null && projectLocation.isPrefixOf(jarPath)) {
                                try {
                                        jarPath = jarPath.removeFirstSegments(projectLocation.segmentCount());
                                        jarPath = jarPath.removeLastSegments(1);
                                        IResource containingFolder = project.findMember(jarPath);
                                        if (containingFolder != null && containingFolder.isAccessible())
                                                containingFolder.refreshLocal(IResource.DEPTH_ONE, null);
                                } catch (CoreException ex) {
                                        // don't refresh the folder but log the problem
                                        JavaPlugin.log(ex);
                                  }
                        }
                }
        }


Clone AbstractionParameter Count: 1Parameter Bindings

 [[#variableb89cf360]]void addDirectories(IPath destinationPath, File correspondingFile) throws IOException {
  String path = destinationPath.toString().replace(File.separatorChar, '/');
  int lastSlash = path.lastIndexOf('/');
  List directories = new ArrayList(2);
  while (lastSlash != -1) {
    path = path.substring(0, lastSlash + 1);
    if ( !fDirectories.add(path))
      break;
    if (correspondingFile != null)
      correspondingFile = correspondingFile.getParentFile();
    long timeStamp = correspondingFile != null && correspondingFile.exists() ? correspondingFile.lastModified(): System.currentTimeMillis();
    JarEntry newEntry = new JarEntry(path);
    newEntry.setMethod(ZipEntry.STORED);
    newEntry.setSize(0);
    newEntry.setCrc(0);
    newEntry.setTime(timeStamp);
    directories.add(newEntry);
    lastSlash = path.lastIndexOf('/', lastSlash - 1);
  }
  for (int i = directories.size() - 1; i >= 0; --i) {
    fJarOutputStream.putNextEntry((JarEntry) directories.get(i));
  }
}

/**
         * Checks if the JAR file can be overwritten.
         * If the JAR package setting does not allow to overwrite the JAR
         * then a dialog will ask the user again.
         * 
         * @param       parent  the parent for the dialog,
         *                      or <code>null</code> if no dialog should be presented
         * @return      <code>true</code> if it is OK to create the JAR
         */
protected boolean canCreateJar(Shell parent) {
  File file = fJarPackage.getAbsoluteJarLocation().toFile();
  if (file.exists()) {
    if ( !file.canWrite())
      return false;
    if (fJarPackage.allowOverwrite())
      return true;
    return parent != null && JarPackagerUtil.askForOverwritePermission(parent, fJarPackage.getAbsoluteJarLocation().toOSString());
  }
  // Test if directory exists
  String path = file.getAbsolutePath();
  int separatorIndex = path.lastIndexOf(File.separator);
  if (separatorIndex == -1) // i.e.- default directory, which is fine
    return true;
  File directory = new File(path.substring(0, separatorIndex));
  if ( !directory.exists()) {
    if (JarPackagerUtil.askToCreateDirectory(parent, directory))
      return directory.mkdirs();
    else
      return false;
  }
  return true;
}

private void registerInWorkspaceIfNeeded() {
  IPath jarPath = fJarPackage.getAbsoluteJarLocation();
  IProject[] projects = ResourcesPlugin.getWorkspace().getRoot().getProjects();
  for (int i = 0; i < projects.length; i++) {
    IProject project = projects[i];
    // The Jar is always put into the local file system. So it can only be
    // part of a project if the project is local as well. So using getLocation
    // is currently save here.
    IPath projectLocation = project.getLocation();
    if (projectLocation != null && projectLocation.isPrefixOf(jarPath)) {
      try {
        jarPath = jarPath.removeFirstSegments(projectLocation.segmentCount());
        jarPath = jarPath.removeLastSegments(1);
        IResource containingFolder = project.findMember(jarPath);
        if (containingFolder != null && containingFolder.isAccessible())
          containingFolder.refreshLocal(IResource.DEPTH_ONE, null);
      }
      catch (CoreException ex) {
        // don't refresh the folder but log the problem
        JavaPlugin.log(ex);
      }
    }
  }
}
 

CloneAbstraction
Parameter Bindings
Parameter
Index
Clone
Instance
Parameter
Name
Value
11[[#b89cf360]]
/**
 * Creates the directory entries for the given path and writes it to the 
 * current archive.
 * 
 * @param destinationPath       the path to add
 * @param correspondingFile the corresponding file in the file system 
 *                                              or <code>null</code> if it doesn't exist
 * @throws IOException if an I/O error has occurred  
 */
protected 
12[[#b89cf360]]
/**
 * Add the directory entries for the given path to the jar.
 * 
 * @param destinationPath the path to add
 * @param correspondingFile the corresponding file in the file system 
 *  or <code>null</code> if it doesn't exist
 * @throws IOException if an I/O error has occurred  
 */
private