I need to get the current revision of a local working copy.
So far I've come up with this: (EDITED)
private static long resolve(File workingDirectory) throws SVNException {
SvnOperationFactory svnOpFactory = new SvnOperationFactory();
SvnGetStatus svnGetStatus = svnOpFactory.createGetStatus();
svnGetStatus.setSingleTarget(SvnTarget.fromFile(workingDirectory));
svnGetStatus.setDepth(SVNDepth.EMPTY);
SvnStatus status = svnGetStatus.run();
return status.getRevision();
}
I can't find a place to actually specify the location of my working copy, not even in the documentation.
How can I tell SvnGetStatus where to look for the working copy?
Try setting it as the target of the operation:
svnGetStatus.setSingleTarget(SvnTarget.fromFile(wcLocation))
Related
I'm doing a coursework project for university and I'm in charge of getting the profile system functioning. Our lecturer has given us some sample code to get a file-upload working which I'm going to use for the user's profile picture however even though my code looks to be very similar I just can't seem to get it working. The issue is that the file won't actually create and save in my project, yet the code my lecturer gave me does!
Here is the code the lecturer gave me:
NewsStory newsstory = new NewsStory();
newsstory.uniqueid = "story_"+System.currentTimeMillis();
newsstory.dateItWasPublished = System.currentTimeMillis();
newsstory.title = toProcess.params.get("title");
newsstory.description = toProcess.params.get("description");
newsstory.journalists.add(toProcess.params.get("journalist"));
newsstory.filepathToImage = toProcess.params.get("fileupload");
File uploaded = new File(newsstory.filepathToImage);
int ind = newsstory.filepathToImage.lastIndexOf('.');
String extension = newsstory.filepathToImage.substring(ind);
uploaded.renameTo(new File("httpdocs/"+newsstory.uniqueid+extension));
newsstory.filepathToImage = newsstory.uniqueid+extension;
//At this point you would normally add the newsstory to the database
MVMap<String, NewsStory> newsStories = db.s.openMap("NewsStories");
newsStories.put(newsstory.uniqueid, newsstory);
This basically takes in a String from a fileupload paramater passed in through a form and runs the code below. Here is my code:
user.userEmail = toProcess.params.get("email");
user.profilePicturePath = toProcess.params.get("filepath");
System.out.println(user.profilePicturePath);
File uploaded = new File(user.profilePicturePath);
int ind = user.profilePicturePath.lastIndexOf('.');
String extension = user.profilePicturePath.substring(ind);
uploaded.renameTo(new File("httpdocs/"+user.username+"ProfilePicture"+extension));
user.profilePicturePath = user.username+"ProfilePicture"+extension;
System.out.println(user.profilePicturePath);
users.put(user.username, user);
db.commit();
Does anyone know why I might be having this issue?
I'm simply trying to update a customfield value in jira using java. I had created a method updateCustomField which accepts 3 parameters (customFieldCode, value, jiraId). Had tried using transition but all it did is change the jira status from "Open" to "Resolved 2". I googled everywhere but they suggest to use JSON which I have no idea how to apply.
here's my update method:
public void updateCustomField(String customFieldCode, String value, String jiraId) throws Exception {
final IssueRestClient issueRestClient = jiraClient.getIssueClient();
final Issue issue = issueRestClient.getIssue(jiraId).get();
FieldInput fieldInput = new FieldInput(customFieldCode, value);
List <FieldInput> fields = new ArrayList <FieldInput> ();
fields.add(fieldInput);
TransitionInput transision = new TransitionInput(1, fields);
issueRestClient.transition(issue, transision);
}
For those who want to simply update jira using java, you can try this jira-client library.
I'm unable to get the last published date of a resource. There is no way to do that with OpenCms API.
http://files.opencms.org/javadoc/core/org/opencms/file/CmsResource.html
That's very weird, it has to be stored in some place because OpenCms Workplace shows this information in the History option.
The method getDateReleased() from CmsResource class always returns DATE_RELEASED_DEFAULT until you set the availability of the resource.
Any thoughts?
Thanks!
Finally I achieve this by digging in the source code from OpenCms.
I found the solution here, in the getListItems method:
https://github.com/alkacon/opencms-core/blob/branch_8_5_x/src/org/opencms/workplace/commons/CmsHistoryList.java
So I built this method to get the last published date from any resource:
public static Date getLastPublishedDate(CmsJspActionElement cms, CmsResource resource) throws Exception {
CmsObject cmso = cms.getCmsObject();
String sitePath = cmso.getSitePath(resource);
if (cmso.readAllAvailableVersions(sitePath).size() > 0) {
I_CmsHistoryResource histRes = cmso.readAllAvailableVersions(sitePath).get(0);
int publishTag = histRes.getPublishTag();
CmsHistoryProject project = cmso.readHistoryProject(publishTag);
return new Date(project.getPublishingDate());
} else {
return null;
}
}
If NULL is returned then the resource has not been published yet.
Hi how to get the last modified by value for a file using SVNkit.
Scenario : the file is updated from SVN and itr is available in local repo(working copy).
You could use svn keywords http://svnbook.red-bean.com/en/1.4/svn.advanced.props.special.keywords.html 'modified by' should be author.
You have to ensure, that the file with the keywords will be changed before every check in. This could be done with an ant script.
The keyword could be used in a constant with a second constant extracting the interesting part:
private static final String SVN_AUTHOR_BASE = "$Author: 113665 $";
/** Is filled in automatically on check in */
public static final String SVN_AUTHOR = SVN_AUTHOR_BASE.
substring(9,SVN_AUTHOR_BASE.indexOf('$', 9) - 1);
public static String getLastModifiedBy(File localPath) throws SVNException {
final SVNStatus status = SVNClientManager.newInstance().getStatusClient().doStatus(localPath, false);
return status != null ? status.getAuthor() : null;
}
SVNProperties props=new SVNProperties();
repository.getFile(filePath,new Long(-1),props,null);
String author=props.getSVNPropertyValue("svn:entry:last-author").toString();
is working fine.
Is it possible to rename a database already created in android?
On my apps update I would like to rename the old database and install a new then compare some values and finally delete the old.
I am doing the creation from an sqlite file in the assets folder. This is why I cannot rename all the tables and insert the new ones.
Clarification:
The old database will contain only one table that I need to compare values from against the new (from the update) database.
Both databases have been copied over from an sqlite file in the assets folder.
Once I have compared a values from the old database to new I will delete the old and use the new in its place with the values I compared.
What i was thinking of doing was rename the old create the new in its place and do everything above.
Just rename the File. Make sure the database is closed first!
Call this in your activity class:
private void renameDatabase()
{
File databaseFile = getDatabasePath("yourdb.whatever");
File oldDatabaseFile = new File(databaseFile.getParentFile(), "yourdb_old.whatever");
databaseFile.renameTo(oldDatabaseFile);
}
Response to clarification. Rename the old db (as above), copy the new one from the assets folder, open both databases and do your compare. Then delete the old file.
Lord Flash is right, you should delete the old db and copy the new oneā¦
Assuming you use a SQLiteOpenHelper, you could use a createDatabaseIfRequired(); method in getReadableDatabase() and getWritableDatabase()
private boolean checkOldDatabase() {
Log.d(Constants.LOGTAG, "OperationDbHelper.checkDatabase");
File f = new File(DB_PATH + OLD_DB_NAME);
return f.exists();
}
public void createDatabaseIfRequired() throws IOException, SQLiteException {
if (!checkOldDatabase()) {
// do db comparison / delete old db / copy new db
}
}
It's not possible to rename a sql table directly.
But you may copy it creating a new and deleting the old one.
Thanks to Kevin Galligan's answer, I was able to create a function in my Kotlin Android app that I can use whenever it might ever be necessary, to rename the database files.
If you're using Java, you'll need to change the syntax a bit but the code should hopefully be somewhat self-explanatory.
val x: String = "Hello"
//in Kotlin would be
String x = "Hello";
//in Java, for example.
Anyway, here's my code, feel free to ask questions if you have any:
private fun checkAndRenameDatabase(oldName: String, newName: String) {
val oldDatabaseFile: File = getDatabasePath(oldName)
val oldDatabaseJournal: File = getDatabasePath("${oldName}-journal")
// Can use this to check files beforehand, using breakpoints
//val files = oldDatabaseFile.parentFile.listFiles()
if(oldDatabaseFile.exists() || oldDatabaseJournal.exists()) {
db.close() // Ensure existing database is closed
val newDatabaseFile: File = getDatabasePath(newName)
val newDatabaseJournal: File = getDatabasePath("${newName}-journal")
if(oldDatabaseFile.exists()) {
if(newDatabaseFile.exists()) {
newDatabaseFile.delete()
}
oldDatabaseFile.renameTo(newDatabaseFile)
}
if(oldDatabaseJournal.exists()) {
if(newDatabaseJournal.exists()) {
newDatabaseJournal.delete()
}
oldDatabaseJournal.renameTo(newDatabaseJournal)
}
// Use with breakpoints to ensure files are now in order
//val newFiles = oldDatabaseFile.parentFile.listFiles()
// Re-open database with new name
db = SQLiteDBHelper(applicationContext, newName)
}
}