Enrich Java analysis

69 views
Skip to first unread message

Michael Bulla

unread,
Dec 3, 2017, 2:34:29 PM12/3/17
to jQAssistant
Hi Marc,

I'm trying to enrich some information to the type- and method node from java scanner. I created a new scanner-project like explained in jQAssitant User Manual with a dependency to jqa-java-plugin. I created a new type like this

public interface JacocoClassFileDescriptor extends ClassFileDescriptor, JacocoClassDescriptor {
}

and a ScannerPlugin like this

public class JacocoClassScannerPlugin extends AbstractScannerPlugin<FileResource, JacocoClassFileDescriptor> {
   
@Override
   
public JacocoClassFileDescriptor scan(FileResource item, String path, Scope scope,
           
Scanner scanner) throws IOException {
       
final Store store = scanner.getContext().getStore();
       
final JacocoClassFileDescriptor fileDescriptor = store.create(JacocoClassFileDescriptor.class);
       
       
for (String probeName : Arrays.asList("1", "2", "3")) {
           
final JacocoProbe probe = store.create(JacocoProbe.class);
            probe
.setName(new File(path).getName().replace(".class", "") + ":" + probeName);
            fileDescriptor
.getProbes().add(probe);
       
}
       
       
       
return fileDescriptor;
   
}
}

I added that to my scanned projects pom.xml

             <plugin>
               
<groupId>com.buschmais.jqassistant</groupId>
               
<artifactId>jqassistant-maven-plugin</artifactId>
               
<version>1.3.0</version>
               
<executions>
                   
<execution>
                       
<goals>
                           
<goal>scan</goal>
                           
<goal>analyze</goal>
                       
</goals>
                       
<configuration>
                           
<failOnSeverity>MAJOR</failOnSeverity>
                           
<store>
                               
<uri>bolt://localhost:7687</uri>
                               
<username>neo4j</username>
                               
<password>12345</password>
                           
</store>
                       
</configuration>
                   
</execution>
               
</executions>
               
<dependencies>
                   
<dependency>
                       
<groupId>de.bulla</groupId>
                       
<artifactId>myScanner</artifactId>
                       
<version>0.0.1-SNAPSHOT</version>
                   
</dependency>
               
</dependencies>
           
</plugin>

This all works fine, except not the exisiting nodes from java scanning are enriched, but new ones are created with no relation to the existing one. How can I do better?

Regards,
Michael

Btw. I had a hard time getting the example from Manual working because of inconsistent classes, when using my scanner like above. I ended up setting jqa dependencies as provided

                <dependency>
                       
<groupId>com.buschmais.jqassistant.core</groupId>
                       
<artifactId>jqassistant.core.scanner</artifactId>
                       
<version>1.0.0</version>
                       
<scope>provided</scope>
               
</dependency>
               
<dependency>
                       
<groupId>com.buschmais.jqassistant.plugin</groupId>
                       
<artifactId>jqassistant.plugin.common</artifactId>
                       
<version>1.0.0</version>
                       
<scope>provided</scope>
               
</dependency>


Not sure if that's best practise

Michael Bulla

unread,
Dec 3, 2017, 2:37:56 PM12/3/17
to jQAssistant
Hi Dirk, of course...

Dirk Mahler

unread,
Dec 4, 2017, 4:53:31 AM12/4/17
to jqass...@googlegroups.com
Hi Michael,

thanks for trying jQA! Before getting into the details: Jens Nerche
(Kontext E) already provides a JaCoCo scanner plugin, the project URL is
https://github.com/kontext-e/jqassistant-plugins.

Your current implementation creates a completely isolated graph by
calling "fileDescriptor =
store.create(JacocoClassFileDescriptor.class);".

It would make sense to at least connect it to the File nodes created by
the jQA file scanners. Therefore you need to tell your plugin that it
requires the FileDescriptor (i.e. file node) that has already been
created:

@Requires(FileDescriptor.class)
public class JacocoClassScannerPlugin extends
AbstractScannerPlugin<FileResource, JacocoClassFileDescriptor>

Instead of creating a new node you can now migrate the existing file
node by adding your labels:

ScannerContext context = scanner.getContext();
Store store = context.getStore();
FileDescriptor fileDescriptor =
context.getCurrentDescriptor();JacocoClassFileDescriptor fileDescriptor
= JacocoClassFileDescriptor jacocoFileDescriptor =
store.addDescriptorType(fileDescriptor, JacocoClassFileDescriptor
.class);

For an example have a look at
https://github.com/buschmais/jqa-java-plugin/blob/master/src/main/java/com/buschmais/jqassistant/plugin/java/impl/scanner/PropertyFileScannerPlugin.java#L26.

Regarding documentation: the current documentation sadly does not
contain the scanner plugin example (this will be fixed with 1.4.0. Which
link did you use?). But you're right, the dependencies to the jQA
framework and other plugins should be in scope "provided".

Cheers,

Dirk
> --
> You received this message because you are subscribed to the Google
> Groups "jQAssistant" group.
> To unsubscribe from this group and stop receiving emails from it, send
> an email to jqassistant...@googlegroups.com.
> To post to this group, send email to jqass...@googlegroups.com.
> Visit this group at https://groups.google.com/group/jqassistant.
> To view this discussion on the web visit
> https://groups.google.com/d/msgid/jqassistant/09d5d5c4-c9e8-48ff-b930-4604ee2fbe44%40googlegroups.com
> [1].
> For more options, visit https://groups.google.com/d/optout.
>
>
> Links:
> ------
> [1]
> https://groups.google.com/d/msgid/jqassistant/09d5d5c4-c9e8-48ff-b930-4604ee2fbe44%40googlegroups.com?utm_medium=email&utm_source=footer

--
Dirk Mahler
Senior Consultant IT
buschmais GbR

-----------------------------------------------------------------
Inhaber Torsten Busch, Frank Schwarz, Dirk Mahler, Tobias Israel
Adresse buschmais GbR, Leipziger Straße 93, 01127 Dresden
Telefon +49 (0) 351 3209 23-0
Fax +49 (0) 351 3209 23-29
Mobil +49 (0) 177 3137411
E-Mail dirk....@buschmais.com
Internet http://www.buschmais.de
-----------------------------------------------------------------

Diese E-Mail enthält vertrauliche undoder rechtlich geschützte
Informationen. Wenn Sie diese E-Mail irrtümlich erhalten haben,
bitten wir Sie diese E-Mail umgehend zu löschen. Das unerlaubte
Kopieren sowie die unbefugte Weitergabe dieser E-Mail ist nicht
gestattet.

This e-mail may contain confidential or privileged information. If
you are not the intended recipient we kindly request you to delete
this e-mail immediately. Any unauthorized copying, disclosure or
distribution of the material in this e-mail is strictly forbidden.

Michael Bulla

unread,
Dec 4, 2017, 3:28:15 PM12/4/17
to jQAssistant
Hi Dirk,

thanks for your fast response. Jens' project seems to be a great hint. I'll take a look at it.
Your suggested solution worked (almost) like a charme. I get an exception while scanning. But however, data seems zu be correct in neo4j.

[WARNING] Cannot scan class '/de/bulla/studentenverwaltung/student/service/StudentService.class'.
com
.buschmais.xo.api.XOException: Invalid access to an un-managed instance.
        at com
.buschmais.xo.impl.proxy.InstanceInvocationHandler.invoke(InstanceInvocationHandler.java:21)
        at com
.sun.proxy.$Proxy96.getDelegate(Unknown Source)
        at com
.buschmais.xo.impl.AbstractInstanceManager.isInstance(AbstractInstanceManager.java:162)
        at com
.buschmais.xo.impl.proxy.entity.object.EqualsMethod.invoke(EqualsMethod.java:22)
        at com
.buschmais.xo.impl.proxy.AbstractProxyMethodService.invoke(AbstractProxyMethodService.java:26)
        at com
.buschmais.xo.impl.proxy.InstanceInvocationHandler.invoke(InstanceInvocationHandler.java:23)
        at com
.sun.proxy.$Proxy88.equals(Unknown Source)
        at com
.buschmais.jqassistant.plugin.java.api.scanner.TypeCache$CachedType.equals(TypeCache.java:142)
        at com
.buschmais.jqassistant.plugin.java.impl.scanner.visitor.VisitorHelper.resolveType(VisitorHelper.java:47)
        at com
.buschmais.jqassistant.plugin.java.impl.scanner.visitor.ClassVisitor.visitField(ClassVisitor.java:80)
        at com
.buschmais.jqassistant.plugin.java.impl.scanner.visitor.ClassVisitor.visitField(ClassVisitor.java:16)
        at org
.objectweb.asm.ClassReader.a(Unknown Source)
        at org
.objectweb.asm.ClassReader.accept(Unknown Source)
        at org
.objectweb.asm.ClassReader.accept(Unknown Source)
        at com
.buschmais.jqassistant.plugin.java.impl.scanner.ClassFileScannerPlugin$1.execute(ClassFileScannerPlugin.java:66)
        at com
.buschmais.jqassistant.plugin.java.impl.scanner.ClassFileScannerPlugin$1.execute(ClassFileScannerPlugin.java:63)
        at com
.buschmais.jqassistant.plugin.common.api.scanner.MD5DigestDelegate.digest(MD5DigestDelegate.java:79)
        at com
.buschmais.jqassistant.plugin.java.impl.scanner.ClassFileScannerPlugin.scan(ClassFileScannerPlugin.java:63)
        at com
.buschmais.jqassistant.plugin.java.impl.scanner.ClassFileScannerPlugin.scan(ClassFileScannerPlugin.java:27)
        at com
.buschmais.jqassistant.core.scanner.impl.ScannerImpl.scan(ScannerImpl.java:82)
        at com
.buschmais.jqassistant.core.scanner.impl.ScannerImpl.scan(ScannerImpl.java:59)
        at com
.buschmais.jqassistant.plugin.common.api.scanner.AbstractContainerScannerPlugin.scan(AbstractContainerScannerPlugin.java:50)
        at com
.buschmais.jqassistant.plugin.common.api.scanner.AbstractContainerScannerPlugin.scan(AbstractContainerScannerPlugin.java:29)
        at com
.buschmais.jqassistant.core.scanner.impl.ScannerImpl.scan(ScannerImpl.java:82)
        at com
.buschmais.jqassistant.core.scanner.impl.ScannerImpl.scan(ScannerImpl.java:59)
        at com
.buschmais.jqassistant.plugin.maven3.impl.scanner.MavenProjectScannerPlugin.scanPath(MavenProjectScannerPlugin.java:328)
        at com
.buschmais.jqassistant.plugin.maven3.impl.scanner.MavenProjectScannerPlugin.scanPath(MavenProjectScannerPlugin.java:299)
        at com
.buschmais.jqassistant.plugin.maven3.impl.scanner.MavenProjectScannerPlugin.scanClassesDirectory(MavenProjectScannerPlugin.java:277)
        at com
.buschmais.jqassistant.plugin.maven3.impl.scanner.MavenProjectScannerPlugin.scan(MavenProjectScannerPlugin.java:86)
        at com
.buschmais.jqassistant.plugin.maven3.impl.scanner.MavenProjectScannerPlugin.scan(MavenProjectScannerPlugin.java:39)
        at com
.buschmais.jqassistant.core.scanner.impl.ScannerImpl.scan(ScannerImpl.java:82)
        at com
.buschmais.jqassistant.core.scanner.impl.ScannerImpl.scan(ScannerImpl.java:59)
        at com
.buschmais.jqassistant.scm.maven.ScanMojo.execute(ScanMojo.java:93)
        at com
.buschmais.jqassistant.scm.maven.AbstractModuleMojo$1.run(AbstractModuleMojo.java:21)
        at com
.buschmais.jqassistant.scm.maven.AbstractMojo.execute(AbstractMojo.java:326)
        at com
.buschmais.jqassistant.scm.maven.AbstractModuleMojo.execute(AbstractModuleMojo.java:24)
        at com
.buschmais.jqassistant.scm.maven.AbstractMojo.execute(AbstractMojo.java:211)
        at org
.apache.maven.plugin.DefaultBuildPluginManager.executeMojo(DefaultBuildPluginManager.java:134)
        at org
.apache.maven.lifecycle.internal.MojoExecutor.execute(MojoExecutor.java:207)
        at org
.apache.maven.lifecycle.internal.MojoExecutor.execute(MojoExecutor.java:153)
        at org
.apache.maven.lifecycle.internal.MojoExecutor.execute(MojoExecutor.java:145)
        at org
.apache.maven.lifecycle.internal.LifecycleModuleBuilder.buildProject(LifecycleModuleBuilder.java:116)
        at org
.apache.maven.lifecycle.internal.LifecycleModuleBuilder.buildProject(LifecycleModuleBuilder.java:80)
        at org
.apache.maven.lifecycle.internal.builder.singlethreaded.SingleThreadedBuilder.build(SingleThreadedBuilder.java:51)
        at org
.apache.maven.lifecycle.internal.LifecycleStarter.execute(LifecycleStarter.java:128)
        at org
.apache.maven.DefaultMaven.doExecute(DefaultMaven.java:307)
        at org
.apache.maven.DefaultMaven.doExecute(DefaultMaven.java:193)
        at org
.apache.maven.DefaultMaven.execute(DefaultMaven.java:106)
        at org
.apache.maven.cli.MavenCli.execute(MavenCli.java:863)
        at org
.apache.maven.cli.MavenCli.doMain(MavenCli.java:288)
        at org
.apache.maven.cli.MavenCli.main(MavenCli.java:199)
        at sun
.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
        at sun
.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
        at sun
.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
        at java
.lang.reflect.Method.invoke(Method.java:483)
        at org
.codehaus.plexus.classworlds.launcher.Launcher.launchEnhanced(Launcher.java:289)
        at org
.codehaus.plexus.classworlds.launcher.Launcher.launch(Launcher.java:229)
        at org
.codehaus.plexus.classworlds.launcher.Launcher.mainWithExitCode(Launcher.java:415)
        at org
.codehaus.plexus.classworlds.launcher.Launcher.main(Launcher.java:356)

Regards,
Michael

Dirk Mahler

unread,
Dec 6, 2017, 11:22:13 AM12/6/17
to jqass...@googlegroups.com
Hi Michael,

this exception happens if "addDescriptorType" has been used on descriptor and the old one is used afterwards (it gets invalidated). Even if I do not have a detailed idea what happened in your case...

But it seems to be related to the fact that JacocoClassFileDescriptor extends from ClassFileDescriptor which I assume is the one from the jQA Java plugin. Is it correct to assume that want to enrich the already scanned class nodes (In my first answer I assumed that you wanted to create a parallel structure, didn't read your question carefully enough...)?

Cheers

Dirk

------ Originalnachricht ------
Von: "Michael Bulla" <michae...@gmail.com>
An: "jQAssistant" <jqass...@googlegroups.com>
Gesendet: 04.12.2017 21:28:14
Betreff: Re: [jQAssistant] Enrich Java analysis

Reply all
Reply to author
Forward
0 new messages