SVNKit: How to get the revision number from a working directory - svnkit

I would like to implement a method that can get the svn revision number from the path where a SVN repository has been checked out. The method declaration would look something like this:
long getRevisionNumber(String localPath) { ... }
I'm trying to use SVNKit for this, but it seems to require an SVN URL to start with. Is there any way to start with a local path?

public static long getRevisionNumber(String localPath) throws SVNException {
final SVNStatus status = SVNClientManager.newInstance().getStatusClient().doStatus(new File(localPath), false);
return status != null ? status.getRevision().getNumber() : -1;
}

Also you can use getCommittedRevision() method. It returns revision for a particular file when it was last commited.
clientManager.getStatusClient().doStatus(destination, false).getCommittedRevision().getNumber();

Related

BluetoothLeScanner never calls any of its callback methods

I'm very new to Android and Kotlin so I may be getting something very simple wrong, but as far as I can see when I call BluetoothLeScanner.startScan() none of the possible callback methods of the ScanCallback class which I've created is ever called.
I've understood that at API level 23 & above just putting the location permissions in the manifest may not be enough so I've written code to handle that & am satisfied that my App has both COARSE and FINE location permissions
Here's my override of the OnScanResult method:
override fun onScanResult(callbackType: Int, result: ScanResult?) {
super.onScanResult(callbackType, result)
mScan = true
}
I've put a break point in each of the callback methods and when I hover over these breakpoints while the code is running, I see the message "No executable code found at line..." That's a pretty disturbing message (and I suspect is pointing to where the problem lies) but (a) how can there be no code there when everything builds OK and (b) what do you do about it?
Update on that: I think that message is a red herring. I've now moved the break points to elsewhere within the callback functions and I no longer see the 'no executable code' message. Looks like Android Studio lets you put a break point on a line with no actual code in it!
So we're back to the original question - why are we getting no callbacks?
Looks like this is now solved:
(1) I did find a setting on the phone as distinct from turning on Location. It was enable Bluetooth scanning. However it actually made no difference (2) What looks to have been the real issue is a misunderstanding of the meaning of the string which you pass to the ScanFilter Builder with setDeviceName(). There is a string in our hardware Bluetooth module which we're trying to scan for which is called device name, and I was scanning for that. When I looked instead for the Beacon advertising data, it found it.
Many thanks for suggestions (only 1 I think)
Giving permissions in the manifest is not the same as the app using it.
For ble you need to give the location and bluetooth permission. Then:
in the app(on the phone) browse your open apps
find your app and click the 3 dots in the top left
Click app info
Permissions
Toggle location to on
Also the following is a handy bit of code:
public void checkPermission() {
if (Build.VERSION.SDK_INT >= 23) {
if (checkSelfPermission(Manifest.permission.ACCESS_FINE_LOCATION) == PackageManager.PERMISSION_GRANTED && checkSelfPermission(android.Manifest.permission.ACCESS_COARSE_LOCATION) == PackageManager.PERMISSION_GRANTED) {
} else {
ActivityCompat.requestPermissions(this, new String[]{
Manifest.permission.ACCESS_FINE_LOCATION,
Manifest.permission.ACCESS_COARSE_LOCATION,}, 1);
}
}
}
#Override
public void onRequestPermissionsResult(int requestCode, #NonNull String[] permissions, #NonNull int[] grantResults) {
if (requestCode == 1 && grantResults[0] == PackageManager.PERMISSION_GRANTED && grantResults[1] == PackageManager.PERMISSION_GRANTED) {
} else {
checkPermission();
}
}
Ps Be safe all

get attributes, even if they do not exist

Please don't hate me, yes I want to do something really stupid.
I want to get null on every attribute if it does not exist. I found out that I can create the propertyMissing method:
class User {
String name = "A"
}
Object.metaClass.propertyMissing() {
null
}
u = new User();
println u?.name
println u?.namee
This prints:
A
null
Now I have the "great" Hybris system in my back :D
If I add the propertyMissing part on top of my script and run this in the Hybris groovy console, I still get the MissingPropertyException.
Is there another way to avoid the MissingPropertyException exception without having to work with hundreds of try catch? (or hundreds of println u?.namee ? u.namee : null isn't working)
/Edit: 1
I have the following use case (for the Hybris system):
I want to get all necessary information in a dynamic output from some pages. Why dynamic? Some page components have the attribute headline other teaserHeadline and some other title. To avoid to create each time an try catch or if else, I created a function which loops through possible attributes and if it's null it skips that one. For that I need to return null on attributes which doesn't exist.
Here is an example which should work, but it doesn't (don't run it on your live system):
import de.hybris.platform.servicelayer.search.FlexibleSearchQuery;
import de.hybris.platform.servicelayer.search.SearchResult;
flexibleSearch = spring.getBean("flexibleSearchService")
FlexibleSearchQuery query = new FlexibleSearchQuery("select {pk} from {ContentPage}");
SearchResult searchResult = flexibleSearch.search(query);
def i = 0;
def max = 1;
searchResult.result.each { page ->
if (i < max) {
gatherCMSPageInformation(page)
}
i++;
}
def gatherCMSPageInformation(page) {
page.class.metaClass.propertyMissing() {
null
}
println page.title2
}
Weird thing is, that if I run it a few times in a small interval, it starts to work. But I can't overwrite "null" to something else like "a". Also I noticed, to overwrite the Object class isn't working at all in Hybris.
/Edit 2:
I noticed, that I'm fighting against the groovy cache. Just try the first example, change null with a and then try to change it again to b in the same context, without restarting the system.
Is there a way to clear the cache?
why don't you use the groovy elvis operator?
println u?.namee ?: null

Rename file in-place using Spring Integration FileWritingMessageHandler

I am attempting to write a simple test of renaming files in-place using a FileWritingMessageHandler, however I can't seem to figure out how to properly specify the target destination directory.
Since I am recursively scanning a directory tree I would ultimately like to simply read the parent path from the file payload and rename it using the FileNameGenerator, but that doesn't appear to work.
The 'payload.name' in the DefaultFileNameGenerator resolves properly, but 'payload.path' does not.
How do I properly determine the source file's location and use that in the handler?
Edit
Here is the channel adapter that scans for files. I had to use .setUseWatchService(true) to achieve recursive scanning.
#Bean
#InboundChannelAdapter(channel = "sourceFileChannel", poller = #Poller(fixedRate = "5000", maxMessagesPerPoll = "-1"))
public MessageSource<File> sourceFiles() {
CompositeFileListFilter<File> filters = new CompositeFileListFilter<>();
filters.addFilter(new SimplePatternFileListFilter(sourceFilenamePattern));
filters.addFilter(persistentFilter());
FileReadingMessageSource source = new FileReadingMessageSource();
source.setAutoCreateDirectory(true);
source.setDirectory(new File(sourceDirectory));
source.setFilter(filters);
source.setUseWatchService(true);
return source;
}
UPDATE
Artem helped me understand my mistake.
I was able to achieve the desired result by using the SpelExpressionParser as Artem outlined.
The key piece being:
new SpelExpressionParser().parseExpression("payload.parent")
Where "payload.parent" resolves to the file parent path properly.
#Bean
#ServiceActivator(inputChannel = "processingFileChannel")
public MessageHandler copyFileForProcessingOutboundChannelAdapter() {
FileWritingMessageHandler adapter = new FileWritingMessageHandler(new SpelExpressionParser().parseExpression("payload.parent"));
adapter.setDeleteSourceFiles(false);
adapter.setAutoCreateDirectory(true);
adapter.setExpectReply(false);
adapter.setFileNameGenerator(processingFileNameGenerator());
return adapter;
}
#Bean
public DefaultFileNameGenerator processingFileNameGenerator() {
DefaultFileNameGenerator defaultFileNameGenerator = new DefaultFileNameGenerator();
defaultFileNameGenerator.setExpression("'p_' + payload.name");
return defaultFileNameGenerator;
}
The 'payload.name' in the DefaultFileNameGenerator resolves properly, but 'payload.path' does not.
Well, I'm not sure what should be in your case, but for me that always returns the full, absolute path for source file, including the root directory to scan.
Since you have it there as a sourceDirectory, how about to use it in your processingFileNameGenerator to sever the root dir from the target path to use? For example if my root dir is /root and I get a file from the subdir /root/foo/my_file.txt, I could do payload.path.replaceFirst('/root', ''). So in the end I have just /foo/my_file.txt.
At least that is what I'm going to do in that JIRA to populate FileHeaders.FILENAME with the relative path from the provided directory to scan.
UPDATE
Oh! I see. No, that isn't going to work that way. See FileWritingMessageHandler ctors. The String once accepts static target directory. Root for our case. The code like new LiteralExpression("payload.path") isn't going to work a desired way, too. See LiteralExpression JavaDocs. It is just an Expression variant to always return the same static value. In your case it is payload.path.
If you are really going to evaluate against an incoming Message, you should use new SpeLexpressionParser().parseExpression("payload.path"). But as I said before, it returns the absolute path for any file in the sub-directories.

Is it possible to remove carriage returns from messages written to logs using the log4net framework

I want to remove carriage returns from strings before they are written to log4net.
Example:
string query = string.Format(#"select
*
from
<a table>
There are three \n there so if I log it via:
log.Debug(query);
I get somewhat of a messy log
The ideal output would have \n stripped. I can do this:
log.Debug(query.Replace("\n",""));
But have to remember to do for each call to the log method...
I'm not sure how to do this with the conversion pattern printf like syntax in the web.config. However, if you want to do this for all levels all the time, you could download the source and alter the internals.
Otherwise, you could create an extension method like so:
public static void Debug(this ILog logger, string message, bool removeNewLines)
{
if (logger == null)
throw new ArgumentNullException("logger");
logger.Debug(removeNewLines ? message.Replace("\n", string.Empty) : message);
}
..and then call it like this:
log.Debug(query, true);
Only problem is you sill have to remember to call this:
log.Debug(query, true);
Instead of this:
log.Debug(query);

Revit Api Load Command - Auto Reload

I'm working with the revit api, and one of its problems is that it locks the .dll once the command's run. You have to exit revit before the command can be rebuilt, very time consuming.
After some research, I came across this post on GitHub, that streams the command .dll into memory, thus hiding it from Revit. Letting you rebuild the VS project as much as you like.
The AutoReload Class impliments the revit IExteneralCommand Class which is the link into the Revit Program.
But the AutoReload class hides the actual source DLL from revit. So revit can't lock the DLL and lets one rebuilt the source file.
Only problem is I cant figure out how to implement it, and have revit execute the command. I guess my C# general knowledge is still too limited.
I created an entry in the RevitAddin.addin manifest that points to the AutoReload Method command, but nothing happens.
I've tried to follow all the comments in the posted code, but nothing seems to work; and no luck finding a contact for the developer.
Found at: https://gist.github.com/6084730.git
using System;
namespace Mine
{
// helper class
public class PluginData
{
public DateTime _creation_time;
public Autodesk.Revit.UI.IExternalCommand _instance;
public PluginData(Autodesk.Revit.UI.IExternalCommand instance)
{
_instance = instance;
}
}
//
// Base class for auto-reloading external commands that reside in other dll's
// (that Revit never knows about, and therefore cannot lock)
//
public class AutoReload : Autodesk.Revit.UI.IExternalCommand
{
// keep a static dictionary of loaded modules (so the data persists between calls to Execute)
static System.Collections.Generic.Dictionary<string, PluginData> _dictionary;
String _path; // to the dll
String _class_full_name;
public AutoReload(String path, String class_full_name)
{
if (_dictionary == null)
{
_dictionary = new System.Collections.Generic.Dictionary<string, PluginData>();
}
if (!_dictionary.ContainsKey(class_full_name))
{
PluginData data = new PluginData(null);
_dictionary.Add(class_full_name, data);
}
_path = path;
_class_full_name = class_full_name;
}
public Autodesk.Revit.UI.Result Execute(
Autodesk.Revit.UI.ExternalCommandData commandData,
ref string message,
Autodesk.Revit.DB.ElementSet elements)
{
PluginData data = _dictionary[_class_full_name];
DateTime creation_time = new System.IO.FileInfo(_path).LastWriteTime;
if (creation_time.CompareTo(data._creation_time) > 0)
{
// dll file has been modified, or this is the first time we execute this command.
data._creation_time = creation_time;
byte[] assembly_bytes = System.IO.File.ReadAllBytes(_path);
System.Reflection.Assembly assembly = System.Reflection.Assembly.Load(assembly_bytes);
foreach (Type type in assembly.GetTypes())
{
if (type.IsClass && type.FullName == _class_full_name)
{
data._instance = Activator.CreateInstance(type) as Autodesk.Revit.UI.IExternalCommand;
break;
}
}
}
// now actually call the command
return data._instance.Execute(commandData, ref message, elements);
}
}
//
// Derive a class from AutoReload for every auto-reloadable command. Hardcode the path
// to the dll and the full name of the IExternalCommand class in the constructor of the base class.
//
[Autodesk.Revit.Attributes.Transaction(Autodesk.Revit.Attributes.TransactionMode.Manual)]
[Autodesk.Revit.Attributes.Regeneration(Autodesk.Revit.Attributes.RegenerationOption.Manual)]
public class AutoReloadExample : AutoReload
{
public AutoReloadExample()
: base("C:\\revit2014plugins\\ExampleCommand.dll", "Mine.ExampleCommand")
{
}
}
}
There is an easier approach: Add-in Manager
Go to Revit Developer Center and download the Revit SDK, unzip/install it, the check at \Revit 2016 SDK\Add-In Manager folder. With this tool you can load/reload DLLs without having to modify your code.
There is also some additional information at this blog post.
this is how you can use the above code:
Create a new VS class project; name it anything (eg. AutoLoad)
Copy&Paste the above code in-between the namespace region
reference revitapi.dll & revitapiui.dll
Scroll down to AutoReloadExample class and replace the path to point
your dll
Replace "Mine.ExampleCommand" with your plugins namespace.mainclass
Build the solution
Create an .addin manifest to point this new loader (eg.
AutoLoad.dll)
your .addin should include "FullClassName" AutoLoad.AutoReloadExample
This method uses reflection to create an instance of your plugin and prevent Revit to lock your dll file! You can add more of your commands just by adding new classes like AutoReloadExample and point them with seperate .addin files.
Cheers

Resources