I have tried to get all the solution files(*.sln) in a given path and print it individually by split the string(each solution file path) using comma delimiter. Programming script language am using is Jenkins Groovy. Am getting the below specified error when build the Jenkins job. Any one please look into this and guide me to proceed in a right way.
def finder = new FileNameFinder()
def files = finder.getFileNames 'D:\jobs', '**/*.sln'
def resultList = files.tokenize(",")
for(i=0; i<resultList.size();i++)
{
println resultList[i]
}
Error Details:
hudson.remoting.ProxyException: groovy.lang.MissingMethodException: No signature of method: java.util.ArrayList.tokenize() is applicable for argument types: (java.lang.String) values: [,]
Possible solutions: toUnique(), toUnique(), toUnique(java.util.Comparator), takeWhile(groovy.lang.Closure), toUnique(groovy.lang.Closure), toUnique(java.util.Comparator)
Thanks in advance!!
Myself itself found an answer for my above problem. Please find below the modified working code.
def finder = new FileNameFinder()
def files = finder.getFileNames 'D:\jobs', '**/*.sln'
assert files instanceof List
println files.size()+" solution files found in the given path. Below are the found solution files details. \n"
for(i=0;i<files.size();i++)
{
println files[i];
}
Thanks
Related
I am testing to see if ANTLR-4.7.1 is working properly by using a sample, provided by my professor, to match these results for the same printed set of tokens:
% java -jar ./antlr-4.7.1-complete.jar HelloExample.g4
% javac -cp antlr-4.7.1-complete.jar HelloExample*.java
% java -cp .:antlr-4.7.1-complete.jar org.antlr.v4.gui.TestRig HelloExample greeting helloworld.greeting -tokens
[#0,0:4='Hello',<1>,1:0]
[#1,6:10='World',<3>,1:6]
[#2,12:12='!',<2>,1:12]
[#3,14:13='<EOF>',<-1>,2:0]
(greeting Hello World !)
However, after getting to the 3rd command, my output was instead:
[#0,0:4='Hello',<'Hello'>,1:0]
[#1,6:10='World',<Name>,1:6]
[#2,12:12='!',<'!'>,1:12]
[#3,13:12='<EOF>',<EOF>,1:13]
In my output, there are no numbers inside < >, which I believe should be defined from the HelloExample.tokens file that contain:
Hello=1
Bang=2
Name=3
WS=4
'Hello'=1
'!'=2
I get no error information and antlr seemed to have generated all the files I needed, so I don't know where I should be looking to resolve this, please help. And I'm not sure if it'll be of use, but my working directory started with helloworld.greeting and HelloExample.g4 and final directory now contains
helloworld.greeting
HelloExample.g4
HelloExample.interp
HelloExample.tokens
HelloExampleBaseListener.class
HelloExampleBaseListener.java
HelloExampleLexer.class
HelloExampleLexer.inerp
HelloExampleLexer.java
HelloExampleLexer.tokens
HelloExampleListener.class
HelloExampleListener.java
HelloExampleParser$GreetingContext.class
HelloExampleParser.class
HelloExampleParser.java
As rici already pointed out in the comments, getting the actual rule names instead of their numbers in the token output is a feature and shouldn't worry you.
In order to get the (greeting Hello World !) output at the end, you'll want to add the -tree flag after -tokens.
I am running into an issue with trying to validate the existence of a file in a directory utilizing a wildcard.
The method is supposed to determine if a file with name FAACIFP_(year)(cycle).DAT could be found in the current directory.
I've tried running a PathMaker.matches("glob:FAACIFP_18") with IF/ELSE and when I tested it, it would always evaluate TRUE. So, I tried a lambda function, and it won't find the file.
Shouldn't the lambda below print the file name, or am I misunderstanding/misusing it?
static void getCnvrtdCifpName() throws IOException{
String cnvFileName = "FAACIFP_"+Year.now()
.format(DateTimeFormatter.ofPattern("yy"));
Path cnvFilePath = Paths.get(System.getProperty("user.dir"));
Files.find(cnvFilePath,0,(path,attr) ->
path.getFileName().startsWith(cnvFileName)).forEach(System.out::println);
System.out.println("EVALUATING METHOD....\t SEARCH PATH: "+cnvFilePath
+" \n\t\t\t FILE STRING: "+cnvFileName);
}
Output:
run:
Located RAW CIFP file FAACIFP18
EVALUATING METHOD.... SEARCH PATH: C:\Users\u314170\Documents\Personal\Java\NetBeans\A424Parser
FILE STRING: FAACIFP_18
BUILD SUCCESSFUL (total time: 0 seconds)
Two problems:
1) change the maxdepth in your find call to 1 (from zero)
2) path.getFileName() returns a full pathname. You will want to evaluate only the filename portion (look at getName(getNameCount()-1)
After the suggestions, I finally found a resolution:
static void getCnvrtdCifpName() throws IOException{
String cnvFileName = "FAACIFP_"+Year.now()
.format(DateTimeFormatter.ofPattern("yy"));
Path cnvFilePath = Paths.get(System.getProperty("user.dir"));
DirectoryStream<Path> cnvFileStream = Files.newDirectoryStream(cnvFilePath,cnvFileName+"*");
System.out.println("EVALUATING METHOD....\t SEARCH PATH: "+cnvFilePath
+" \n\t\t\t FILE STRING: "+cnvFileName);
List cnvDirList = new ArrayList();
for(Path file: cnvFileStream){
cnvDirList.add(file.getFileName().toString());
}
cnvFileStream.close();
System.out.println(cnvDirList);
}
With output:
run:
EVALUATING METHOD.... SEARCH PATH: C:\Users\u314170\Documents\Personal\Java\NetBeans\A424Parser
FILE STRING: FAACIFP_18
[FAACIFP_1808.dat, FAACIFP_1810.txt, FAACIFP_1811.txt]
BUILD SUCCESSFUL (total time: 0 seconds)
I really enjoy the problem-solving challenges while learning Java. There are so many resources out there, and many different ways to resolve an issue.
I am new to apache spark and trying to run the wordcount example . But intellij editor gives me the error at line 47 Cannot resolve method 'flatMap()' error.
Edit :
This is the line where I am getting the error
JavaRDD<String> words = lines.flatMap(s -> Arrays.asList(SPACE.split(s)).iterator());
It looks like you're using an older version of Spark that expects Iterable rather than Iterator from the flatMap() function. Try this:
JavaRDD<String> words = lines.flatMap(s -> Arrays.asList(SPACE.split(s)));
See also Spark 2.0.0 Arrays.asList not working - incompatible types
Stream#flatMap is used for combining multiple streams into one, so the supplier method you provided must return a Stream result.
you can try like this:
lines.stream().flatMap(line -> Stream.of(SPACE.split(line)))
.map(word -> // map to JavaRDD)
flatMap method take a FlatMapFunctionas parameter which is not annotated with #FunctionalInterface. So indeed you can not use it as a lambda.
Just build a real FlatMapFunctionobject as parameter and you will be sure of it.
flatMap() is Java 8 Stream API. I think you should check the IDEA compile java version.
compile java version
I have been using the JavaImp.vim script for auto importing Java statements in VIM
But trying out different directories in the JavaImpPaths, I am still unable to make JavaImp parse the Java files in the source to make auto imports possible
this is how my .vimrc looks like
let g:JavaImpPaths = "~/Documents/android-sdks/sources/android-21/android/content/"
let g:JavaImpClassList = "~/.vim/JavaImp/JavaImp.txt"
let g:JavaImpJarCache = "~/.vim/JavaImp/cache/"
This is what I get running JIG in new Vim window
:JIG
Do you want to create the directory ~/.vim/JavaImp/cache/?
Searching in path (package): ~/Documents/android-sdks/sources/android-21/android
/content/ ()
Sorting the classes, this may take a while ...
Assuring uniqueness...
Error detected while processing function <SNR>10_JavaImpGenerate:
line 75:
E37: No write since last change (add ! to override)
Done. Found 1 classes (0 unique)
Press ENTER or type command to continue
It might be late, but if anyone else comes along this might help them...
I got it working with the following changes to the script:
line 181 from
close
to
close!
And lines 207/208 from
let l:javaList = glob(a:cpath . "/**/*.java", 1, 1)
let l:clssList = glob(a:cpath . "/**/*.class", 1, 1)
to
let l:javaList = split(glob(a:cpath . "/**/*.java"), "\n")
let l:clssList = split(glob(a:cpath . "/**/*.class"), "\n")
In cpp file I have std::round(double)
Please can I know the equivalent code in Java
Edit: I am already using java.lang.Math.round(double) and getting match in 99% cases. But in some places iam getting mismatch. For example:
std::round(4816.5058) = 4816 and Math.round(4816.5058) = 4817
std::round(4466.49996) = 4467 and Math.round(4466.49997) = 4466
java.lang.Math.round(double)