| Previous CloneSet | Next CloneSet | Back to Main Report |
| Clone Mass | Clones in CloneSet | Parameter Count | Clone Similarity | Syntax Category [Sequence Length] |
|---|---|---|---|---|
| 83 | 2 | 1 | 0.999 | class_body_declarations[3] |
| Clone Abstraction | Parameter Bindings |
| Clone Instance (Click to see clone) | Line Count | Source Line | Source File |
|---|---|---|---|
| 1 | 83 | 213 | plugins/org.eclipse.jdt.ui/ui/org/eclipse/jdt/ui/jarpackager/JarWriter.java |
| 2 | 83 | 229 | plugins/org.eclipse.jdt.ui/ui/org/eclipse/jdt/ui/jarpackager/JarWriter2.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);
}
}
}
}
|
| ||||
/**
* 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);
}
}
}
}
|
| |||
[[#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 Index | Clone Instance | Parameter Name | Value |
|---|---|---|---|
| 1 | 1 | [[#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 |
| 1 | 2 | [[#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 |