use of org.tigris.subversion.svnclientadapter.ISVNClientAdapter in project subclipse by subclipse.
the class GenerateDiffFileOperation method createEclipsePatch.
private void createEclipsePatch(IResource[] paths, File outputFile, boolean recurse) throws SVNClientException {
FileOutputStream os = null;
InputStream is = null;
ISVNClientAdapter client = null;
ISVNRepositoryLocation repository = null;
try {
byte[] buffer = new byte[4096];
os = new FileOutputStream(outputFile);
if (paths.length > 0) {
os.write(ECLIPSE_PATCH_HEADER.getBytes());
os.write(EOL.getBytes());
}
Map projectToResources = new HashMap();
for (int i = 0; i < paths.length; i++) {
IResource resource = paths[i];
IProject project = resource.getProject();
List files = (List) projectToResources.get(project);
if (files == null) {
files = new ArrayList();
projectToResources.put(project, files);
}
files.add(resource.getLocation().toFile());
}
for (Iterator iEntry = projectToResources.entrySet().iterator(); iEntry.hasNext(); ) {
Entry entry = (Entry) iEntry.next();
IResource project = (IResource) entry.getKey();
List files = (List) entry.getValue();
repository = SVNWorkspaceRoot.getSVNResourceFor(project).getRepository();
client = repository.getSVNClient();
os.write(ECLIPSE_PROJECT_MARKER.getBytes());
os.write(project.getName().getBytes());
os.write(EOL.getBytes());
File tempFile = File.createTempFile("tempDiff", ".txt");
tempFile.deleteOnExit();
client.createPatch((File[]) files.toArray(new File[files.size()]), project.getLocation().toFile(), tempFile, recurse);
SVNWorkspaceRoot.getSVNResourceFor(project).getRepository().returnSVNClient(client);
client = null;
repository = null;
try {
is = new FileInputStream(tempFile);
int bytes_read;
while ((bytes_read = is.read(buffer)) != -1) os.write(buffer, 0, bytes_read);
} finally {
if (is != null)
try {
is.close();
} catch (IOException e) {
}
}
}
} catch (Exception e) {
throw new SVNClientException(e);
} finally {
if (os != null)
try {
os.close();
} catch (IOException e) {
}
if (repository != null) {
repository.returnSVNClient(client);
}
}
}
use of org.tigris.subversion.svnclientadapter.ISVNClientAdapter in project subclipse by subclipse.
the class GenerateDiffFileOperation method run.
/**
* @see IRunnableWithProgress#run(IProgressMonitor)
*/
public void run(IProgressMonitor monitor) throws InvocationTargetException {
ISVNClientAdapter svnClient = null;
ISVNRepositoryLocation repository = null;
try {
// $NON-NLS-1$
monitor.beginTask("", 500);
// $NON-NLS-1$
monitor.setTaskName(Policy.bind("GenerateSVNDiff.working"));
OutputStream os;
if (toClipboard) {
os = new ByteArrayOutputStream();
} else {
os = new FileOutputStream(outputFile);
}
// $NON-NLS-1$ //$NON-NLS-2$
File tmpFile = File.createTempFile("sub", "");
tmpFile.deleteOnExit();
ISVNLocalResource svnResource = SVNWorkspaceRoot.getSVNResourceFor(resources[0]);
newFiles = new ArrayList();
if (unaddedResources.length > 0) {
// });
for (int i = 0; i < unaddedResources.length; i++) newFiles.add(unaddedResources[i]);
if (newFiles.size() > 0) {
try {
// associate the resources with their respective RepositoryProvider
Hashtable table = getProviderMapping((IResource[]) newFiles.toArray(new IResource[newFiles.size()]));
Set keySet = table.keySet();
Iterator iterator = keySet.iterator();
while (iterator.hasNext()) {
IProgressMonitor subMonitor = Policy.subMonitorFor(monitor, 100);
SVNTeamProvider provider = (SVNTeamProvider) iterator.next();
List list = (List) table.get(provider);
IResource[] providerResources = (IResource[]) list.toArray(new IResource[list.size()]);
provider.add(providerResources, IResource.DEPTH_INFINITE, subMonitor);
}
} catch (TeamException e) {
throw new InvocationTargetException(e);
}
}
}
repository = svnResource.getRepository();
svnClient = repository.getSVNClient();
try {
monitor.worked(100);
File[] files = getVersionedFiles();
if (selectedResources == null)
svnClient.diff(files, tmpFile, recursive);
else {
if (eclipseFormat) {
HashSet includedResources = new HashSet();
includedResources.addAll(Arrays.asList(unaddedResources));
includedResources.addAll(Arrays.asList(resources));
createEclipsePatch((IResource[]) includedResources.toArray(new IResource[0]), tmpFile, recursive);
} else {
File relativeToPath = null;
if (projectRelative) {
relativeToPath = selectedResources[0].getProject().getLocation().toFile();
} else {
relativeToPath = getRelativeToPath();
if (relativeToPath.isFile()) {
relativeToPath = relativeToPath.getParentFile();
}
}
svnClient.createPatch(files, relativeToPath, tmpFile, recursive);
}
}
monitor.worked(300);
InputStream is = new FileInputStream(tmpFile);
byte[] buffer = new byte[30000];
int length;
while ((length = is.read(buffer)) != -1) {
os.write(buffer, 0, length);
}
is.close();
} finally {
os.close();
}
if (newFiles.size() > 0) {
for (int i = 0; i < newFiles.size(); i++) {
IResource resource = (IResource) newFiles.get(i);
try {
SVNWorkspaceRoot.getSVNResourceFor(resource).revert();
} catch (Exception e) {
}
}
}
boolean emptyDiff = false;
if (toClipboard) {
final ByteArrayOutputStream baos = (ByteArrayOutputStream) os;
if (baos.size() == 0) {
emptyDiff = true;
} else {
Display.getDefault().syncExec(new Runnable() {
public void run() {
TextTransfer plainTextTransfer = TextTransfer.getInstance();
Clipboard clipboard = new Clipboard(shell.getDisplay());
clipboard.setContents(new String[] { baos.toString() }, new Transfer[] { plainTextTransfer });
clipboard.dispose();
}
});
}
} else {
if (outputFile.length() == 0) {
emptyDiff = true;
outputFile.delete();
}
}
// check for empty diff and report
if (emptyDiff) {
Display.getDefault().syncExec(new Runnable() {
public void run() {
MessageDialog.openInformation(shell, // $NON-NLS-1$
Policy.bind("GenerateSVNDiff.noDiffsFoundTitle"), // $NON-NLS-1$
Policy.bind("GenerateSVNDiff.noDiffsFoundMsg"));
}
});
}
} catch (Exception e) {
throw new InvocationTargetException(e);
} finally {
if (repository != null) {
repository.returnSVNClient(svnClient);
}
monitor.done();
}
}
use of org.tigris.subversion.svnclientadapter.ISVNClientAdapter in project subclipse by subclipse.
the class SvnWizardBranchTagPage method updateTagsProperty.
private void updateTagsProperty(SVNUrl toUrl) {
ISVNClientAdapter svnClient = null;
try {
ISVNProperty property = null;
// $NON-NLS-1$
property = svnResource.getSvnProperty("subclipse:tags");
if (property == null)
return;
newAlias = new Alias();
// $NON-NLS-1$
newAlias.setBranch(toUrl.toString().toUpperCase().indexOf("TAGS") == -1);
String relativePath = toUrl.toString().substring(svnResource.getRepository().getUrl().toString().length());
newAlias.setRelativePath(relativePath);
SVNRevision revision = null;
if (revisionButton.getSelection())
revision = SVNRevision.getRevision(revisionText.getText().trim());
else {
svnClient = svnResource.getRepository().getSVNClient();
ISVNInfo svnInfo = svnClient.getInfo(url);
revision = SVNRevision.getRevision(svnInfo.getRevision().toString());
}
newAlias.setRevision(Integer.parseInt(revision.toString()));
newAlias.setName(toUrl.getLastPathSegment());
BranchTagPropertyUpdateDialog dialog = new BranchTagPropertyUpdateDialog(getShell(), resource, newAlias, // $NON-NLS-1$
"BranchTagPropertyUpdateDialog");
if (dialog.open() == BranchTagPropertyUpdateDialog.OK)
newAlias = dialog.getNewAlias();
else
newAlias = null;
} catch (Exception e) {
} finally {
svnResource.getRepository().returnSVNClient(svnClient);
}
}
use of org.tigris.subversion.svnclientadapter.ISVNClientAdapter in project subclipse by subclipse.
the class SVNClientManager method setConfigDir.
/**
* @param configDir The configDir to set.
*/
public void setConfigDir(File configDir) {
this.configDir = configDir;
if (cachedClients == null)
return;
// Update configDir in stored clients
Set<String> keys = cachedClients.keySet();
for (String key : keys) {
ISVNClientAdapter svnClient = cachedClients.get(key);
if (svnClient != null) {
try {
svnClient.setConfigDirectory(configDir);
} catch (SVNClientException e) {
break;
}
}
}
}
use of org.tigris.subversion.svnclientadapter.ISVNClientAdapter in project subclipse by subclipse.
the class SVNRepositoryLocation method getSVNClient.
/**
* get the svn client corresponding to the repository
*
* @throws SVNException
*/
public ISVNClientAdapter getSVNClient() throws SVNException {
ISVNClientAdapter svnClient = SVNProviderPlugin.getPlugin().getSVNClient();
svnClient.addNotifyListener(NotificationListener.getInstance());
return svnClient;
}
Aggregations