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.
Related
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 "almost" new on Elastic Search. I've been using it for a while but never used Analyzers before.
I can make a full text search on my project but the problem is, when I try to find a name like "Alex", I should completely type down the name correcly. It doesn't work with "Al" or "Ale". It says something like "no match found".
I found some source codes from different sites, but it makes me confused.
What should I do is:
1) Creating a nGram tokenizer
2) Then mapping it with my all indexes?
I have lots of indexes already created and I got errors while creating a mapping on them.
Should I create my analyzer settings and mapping very in the beggining just before indexing my records ?
I'm working on a Java project, so answers on JAVA API will be very appreciated.
Thanks a lot!
mappings should always be created first and then the data should be indexed. if possible, delete your old indices and recreate with new mapping. if you are concerned about loosing your data, then just create a new type for an existing index. the new type can use the new mapping.
for example, here is a piece that uses the Java API to create a custom mapping
public class MappingCreator {
static Logger log = Logger.getLogger(MappingCreator.class.getName());
final static String indexName = "indexName";
final static String typeName = "typeName";
final static String mappingFileName = "pathToMapping.jsonFile";
final static String clusterName = "elasticsearch"; // or name of your cluster
final static String hostName = "localhost";
public static void main(String args[]) throws IOException
{
MappingCreator mapCreator = new MappingCreator();
Client myESclient = getClient();
IndicesExistsResponse res = myESclient.admin().indices().prepareExists(indexName).execute().actionGet();
if (res.isExists()) {
log.warn("Index "+indexName +" already exists. Will be deleted");
final DeleteIndexRequestBuilder deleteIndexBuilder = myESclient.admin().indices().prepareDelete(indexName);
deleteIndexBuilder.execute().actionGet();
}
final CreateIndexRequestBuilder createIndexBuilder = myESclient.admin().indices().prepareCreate(indexName)
.addMapping(typeName, mapCreator.getIndexFieldMapping());
CreateIndexResponse createIndexResponse = createIndexBuilder.execute().actionGet();
log.debug("Created mapping "+createIndexResponse.toString());
myESclient.close();
}
private String getIndexFieldMapping() throws IOException {
return IOUtils.toString(getClass().getClassLoader().getResourceAsStream(mappingFileName));
}
private static Client getClient() {
TransportClient transportClient = null;
try
{
Settings settings = ImmutableSettings.settingsBuilder().put("cluster.name", clusterName).build();
transportClient = new TransportClient(settings);
transportClient = transportClient.addTransportAddress(new InetSocketTransportAddress(hostName, 9300));
/* be very careful about the port number here. by default its 9300. note that this is the TCP port which the java api will use. unlike the http port which is 9200 */
}
catch (Exception e)
{
log.error("Error in MappingCreator creating Elastic Search Client\n"
+ "Message "+e.getMessage()+"\n"
+ "StackTrace "+e.getStackTrace()
);
}
return (Client) transportClient;
}
}
i hope this helps. by the way its really cool that you are making your own nGram tokenizer. i would love to see the code for that and how it is done :)
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))
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.
I'm trying to use Eclipse ASTParser in order to analyse and, if possible, add some code to some classes. One of the information I need requires to have bindings, but because this is a standalone project (the final goal it's a command line tool, independent from eclipse) I can't have them (requireBinding() returns null).
After reading a lot of posts, the far that I can go is using this examples in order to use FileASTRequestor but that's not the way to go since it seems to me that we have to give the KEY to bind before generating the AST tree.
I've found somewhere that we can use ASTParser.setEnvironment method in order to use the bindings in a standalone java application, but I don't think I'm doing it correctly. What's wrong with the code below?
private static final String rootDir = "D:\\workspace\\stateless\\";
private static final String[] classpath = java.lang.System.getProperty( "java.class.path" ).split(";");
private static final String source =
"package de.siemens.tools.stateless.test.examples; " +
"public class ClassWithFinalMemberVariables {" +
"private final int _memberIntVariable = 0;" +
"public void method() {" +
"int localVariable = 0;" +
"System.out.println(_memberIntVariable + localVariable);" +
"}" +
"}";
public static void main(String[] args) throws CoreException {
Document document = new Document(source);
ASTParser parser = ASTParser.newParser(AST.JLS4);
parser.setKind(ASTParser.K_COMPILATION_UNIT);
parser.setEnvironment(classpath, new String[] { rootDir },
new String[] { "UTF8" }, true);
parser.setSource(document.get().toCharArray());
parser.setResolveBindings(true);
parser.setBindingsRecovery(true);
CompilationUnit unit = (CompilationUnit)parser.createAST(null);
unit.recordModifications();
unit.accept(new ASTVisitor() {
#Override
public void endVisit(VariableDeclarationFragment node) {
IVariableBinding bind = node.resolveBinding();
if(bind == null)
System.out.println("ERROR: bind is null");
super.endVisit(node);
}
Output is always "ERROR: bind is null".
I've already solved it, the code is here:
http://pasteit.com/19433
Even though I prefer the ASTVisitor model, this one gives me every binding available.
And here is the discussion about the problem, for those of you who are curious: https://bugs.eclipse.org/bugs/show_bug.cgi?id=206391
EDIT: I don't have any idea if this is the best solution or not, if you have any suggestion please let me know