Skip to content

Commit

Permalink
refactoring extracting JstackTextualFormatParser. Fix warnings
Browse files Browse the repository at this point in the history
  • Loading branch information
Haim Yadid committed Dec 2, 2022
1 parent 58e2647 commit 157c737
Show file tree
Hide file tree
Showing 6 changed files with 106 additions and 98 deletions.
40 changes: 0 additions & 40 deletions assembly/bin.xml

This file was deleted.

37 changes: 22 additions & 15 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,28 @@
<target>${java.compiler.target}</target>
</configuration>
</plugin>
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>exec-maven-plugin</artifactId>
<version>3.1.0</version>
<executions>
<execution>
<goals>
<goal>exec</goal>
</goals>
<phase>process-classes</phase>
</execution>
</executions>
<configuration>
<executable>java</executable>
<arguments>
<argument>-classpath</argument>
<classpath/>
<argument>com.performizeit.mjprof.plugin.PluginRepoBuilder</argument>
<argument>${project.build.outputDirectory}/supported_monads.txt</argument>
</arguments>
</configuration>
</plugin>

<plugin>
<groupId>org.apache.maven.plugins</groupId>
Expand All @@ -58,21 +80,6 @@
<goal>single</goal>
</goals>
</execution>
<execution>
<id>create-zip</id>
<configuration>
<descriptors>
<descriptor>assembly/bin.xml</descriptor>
</descriptors>
<finalName>mjprof${project.version}</finalName>
</configuration>

<phase>package</phase>
<!-- bind to the packaging phase -->
<goals>
<goal>single</goal>
</goals>
</execution>
</executions>
</plugin>

Expand Down
41 changes: 33 additions & 8 deletions src/main/java/com/performizeit/mjprof/monads/StepsRepository.java
Original file line number Diff line number Diff line change
Expand Up @@ -17,24 +17,49 @@

package com.performizeit.mjprof.monads;

import java.io.BufferedInputStream;
import java.lang.reflect.InvocationTargetException;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.Set;

import org.reflections.Reflections;

import com.performizeit.mjprof.api.Plugin;

public class StepsRepository {
static HashMap<String, StepInfo> repo = new HashMap<>();

static {
Reflections reflections = new Reflections("com.performizeit");
Set<Class<?>> annotatedPlugin = reflections.getTypesAnnotatedWith(Plugin.class);
for (Class cla : annotatedPlugin) {
Plugin pluginAnnotation = (Plugin) cla.getAnnotation(Plugin.class);
StepInfo stepInit = new StepInfo(cla, pluginAnnotation.params(), pluginAnnotation.description());
repo.put(pluginAnnotation.name(), stepInit);
ArrayList<Class> plugins = new ArrayList<>();

try {
String inputStream = new String(new BufferedInputStream(StepsRepository.class.getResourceAsStream("/supported_monads.txt")).readAllBytes());
for (var line : inputStream.split("\n")) {
try {
plugins.add(Class.forName(line));
} catch (Exception e) {
System.out.println("Unable to find class "+line);
throw new RuntimeException(e);
}
}
} catch (Exception e) {

throw new RuntimeException(e);
}
for (Class cla : plugins) {
addPluginToRepo(cla);
}
}

private static void addPluginToRepo(Class cla) {
Plugin pluginAnnotation = (Plugin) cla.getAnnotation(Plugin.class);
StepInfo stepInit = new StepInfo(cla, pluginAnnotation.params(), pluginAnnotation.description());
try {
var cons = cla.getConstructor(stepInit.getParamTypes());
System.out.println("Cons"+ cons.getName());
} catch (NoSuchMethodException e) {
throw new RuntimeException(e);
}
repo.put(pluginAnnotation.name(), stepInit);
}

public static boolean stepValid(MJStep a) {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
package com.performizeit.mjprof.plugin;

import com.performizeit.mjprof.api.Plugin;
import org.reflections.Reflections;

import java.io.BufferedWriter;
import java.io.FileWriter;
import java.io.IOException;
import java.util.ArrayList;
import java.util.Set;

public class PluginRepoBuilder {


// java -cp `mvn dependency:build-classpath | grep jar:`:target/classes com.performizeit.mjprof.plugin.PluginRepoBuilder
//java -jar -agentlib:native-image-agent=config-output-dir=META_INF/native-config -jar target/mjprof-1.0-jar-with-dependencies.jar
//native-image -H:ReflectionConfigurationFiles=META-INF/native-config/reflect-config.json -H:IncludeResources=".*/*.txt" -jar target/mjprof-1.0-jar-with-dependencies.jar mjprof
public static ArrayList<Class> resolvePluginListFromClassPath(ArrayList<Class> discoveredClasses) {

Reflections reflections = new Reflections("com.performizeit");
Set<Class<?>> annotatedPlugin = reflections.getTypesAnnotatedWith(Plugin.class);
for (Class cla : annotatedPlugin) {
discoveredClasses.add(cla);
}
return discoveredClasses;
}

public static void main(String[] args) {
System.out.println("I got this file to write to :" + args[0]);
ArrayList<Class> plugins = new ArrayList<>();
resolvePluginListFromClassPath(plugins);
try (var f = new BufferedWriter(new FileWriter(args[0]))) {
for (Class cla : plugins) {
f.write(cla.getName());
f.newLine();
}
} catch (IOException e) {
throw new RuntimeException(e);
}

}
}
32 changes: 5 additions & 27 deletions src/main/java/com/performizeit/mjprof/plugin/PluginUtils.java
Original file line number Diff line number Diff line change
Expand Up @@ -17,14 +17,10 @@

package com.performizeit.mjprof.plugin;

import java.lang.reflect.Constructor;
import java.lang.reflect.InvocationTargetException;
import java.util.HashMap;
import java.util.Set;
import com.performizeit.mjprof.plugin.types.DataSource;
import com.performizeit.mjprof.plugin.types.Outputer;

import com.performizeit.mjprof.api.*;
import com.performizeit.mjprof.plugin.types.*;
import org.reflections.Reflections;
import java.lang.reflect.Constructor;


public class PluginUtils {
Expand All @@ -41,27 +37,9 @@ public static Object initObj(Class<?> clazz, Class[] paramTypes, Object[] paramA


//conParameter - constructor parameters
public static HashMap<Class, Class> getAllPlugins() throws NoSuchMethodException, SecurityException, IllegalAccessException, IllegalArgumentException, InvocationTargetException, InstantiationException, ClassNotFoundException {
HashMap<Class, Class> map = new HashMap<>();
//TODO
Reflections reflections = new Reflections("com.performizeit");
Set<Class<?>> annotatedPlugin = reflections.getTypesAnnotatedWith(Plugin.class);

for (Class cla : annotatedPlugin) {
if (BasePlugin.class.isAssignableFrom(cla)) {
invokeGetHelpLine(cla);
map.put(cla, cla);
} else {
System.out.println("ERROR: class " + cla.getName() + " needs to extend BasePlugin child");
}
}
return map;
}

private static String invokeGetHelpLine(Class<?> cla) {
Plugin pluginAnnotation = cla.getAnnotation(Plugin.class);
return pluginAnnotation.description();
}




public static boolean isDataSource(Object o) {
Expand Down
12 changes: 4 additions & 8 deletions src/test/java/com/performizeit/mjprof/plugin/PluginTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -6,18 +6,14 @@
import java.util.Set;

import com.performizeit.mjprof.MJProf;
import com.performizeit.mjprof.plugins.mappers.GroupByProp;
import com.performizeit.mjprof.plugins.mappers.singlethread.StackTop;
import com.performizeit.mjprof.plugins.terminals.ListProps;
import org.junit.jupiter.api.Test;
import org.reflections.Reflections;

import com.performizeit.mjprof.api.Plugin;
import com.performizeit.mjprof.plugins.mappers.singlethread.StackFrameContains;
import com.performizeit.mjprof.monads.StepInfo;

import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertNotNull;
import static org.junit.jupiter.api.Assertions.assertTrue;

public class PluginTest {
Expand Down Expand Up @@ -54,10 +50,10 @@ public class PluginTest {
""";

@Test
/*@Test
public void testPlugin() throws Exception {
assertNotNull(PluginUtils.getAllPlugins().get(GroupByProp.class));
}
}*/

@Test
public void testInitObject() {
Expand All @@ -77,7 +73,7 @@ public void testSynopsis() {
assertTrue(MJProf.getSynopsisString().contains(ListProps.class.getAnnotation(Plugin.class).description()));

}

/*
@Test
public void testGetDtaSourcePlugins() {
HashMap<String, StepInfo> repo = new HashMap<String, StepInfo>();
Expand All @@ -88,5 +84,5 @@ public void testGetDtaSourcePlugins() {
StepInfo stepInit = new StepInfo(cla, pluginAnnotation.params(),pluginAnnotation.description());
repo.put(pluginAnnotation.name(), stepInit);
}
}
}*/
}

0 comments on commit 157c737

Please sign in to comment.