Skip to content

Commit

Permalink
MInor checkstyle fixes and formattings
Browse files Browse the repository at this point in the history
harder ones to go
  • Loading branch information
judovana committed Oct 6, 2023
1 parent c7ef012 commit dc6a4a1
Show file tree
Hide file tree
Showing 24 changed files with 273 additions and 202 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,10 @@ public AgentAttachManager(VmManager vmManager) {
public VmDecompilerStatus attachAgentToVm(String vmId, int vmPid, AgentConfig agntConfig) {
List<KnownAgent> knownAgentsOnPid = KnownAgents.getInstance().findAgents(vmPid);
if (knownAgentsOnPid.size() > 1) {
Logger.getLogger().log(Logger.Level.DEBUG, "warning, but more then one agent found " + vmId + " Taking " +
"first one - " + knownAgentsOnPid.get(0).toString());
Logger.getLogger().log(
Logger.Level.DEBUG,
"warning, but more then one agent found " + vmId + " Taking " + "first one - " + knownAgentsOnPid.get(0).toString()
);
Logger.getLogger().log("reusing " + knownAgentsOnPid.get(0).toString());
VmDecompilerStatus status = new VmDecompilerStatus(true);
status.setHostname(knownAgentsOnPid.get(0).getHost());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ public class KnownAgent {
private final int port;
private final int pid;

private BytemanCompanion bytemanCompanion = null;
private BytemanCompanion bytemanCompanion;
private final String host;
private final long owner; //to close only my connections on exit

Expand Down Expand Up @@ -82,10 +82,10 @@ public String toString() {
}

public String toPrint() {
return "" + "local pid " + pid + " = " + host + ':' + port + " (owner pid=" + owner + ", ttl=" + ttl + ", " +
"deadSince=" + deadSince +
bytemanCompanion==null?"no companion":", companionBytemanPort=" + bytemanCompanion.getBytemanPort() +
", " + "afterBytemanCompanion=" + bytemanCompanion.getPostBytemanAgentPort() + ')';
return "" + "local pid " + pid + " = " + host + ':' + port + " (owner pid=" + owner + ", ttl=" + ttl + ", " + "deadSince=" +
deadSince + bytemanCompanion == null ? "no companion" :
", companionBytemanPort=" + bytemanCompanion.getBytemanPort() + ", " + "afterBytemanCompanion=" +
bytemanCompanion.getPostBytemanAgentPort() + ')';
}

public boolean verify() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,7 @@ public List<KnownAgent> findAgents(String hostname, int listenPort) {
}
return result;
}

public List<KnownAgent> findAgents(int pid, int port) {
List<KnownAgent> result = new ArrayList<>();
for (KnownAgent agent : agents) {
Expand Down Expand Up @@ -201,9 +202,9 @@ public List<KnownAgent> getAgents() {
public void setBytemanCompanion(int vmPid, int port, BytemanCompanion bytemanCompanion) {
load();
List<KnownAgent> agnets = KnownAgents.getInstance().findAgents(vmPid, port);
if (agnets == null || agnets.size()!=1){
Logger.getLogger().log(Logger.Level.ALL, "no suitable agent found for pid " + vmPid + ", port " + port +
" to save byteman companion.");
if (agnets == null || agnets.size() != 1) {
Logger.getLogger()
.log(Logger.Level.ALL, "no suitable agent found for pid " + vmPid + ", port " + port + " to save byteman companion.");
} else {
agnets.get(0).setBytemanCompanion(bytemanCompanion);
Logger.getLogger().log(Logger.Level.DEBUG, "set byteman companion for pid" + vmPid + ", port " + port);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,10 @@ public static DepndenceNumbers fromString(String s) throws IllegalArgumentExcept
}

public enum AdditionalAgentAction {
ADD, ADD_AND_SAVE, ASK, NOTHING;
ADD,
ADD_AND_SAVE,
ASK,
NOTHING;

public static AdditionalAgentAction fromString(String s) throws IllegalArgumentException {
return Arrays.stream(AdditionalAgentAction.values()).filter(v -> v.toString().equals(s)).findFirst()
Expand Down Expand Up @@ -234,8 +237,8 @@ public DepndenceNumbers doDepndenceNumbers() {
}

public AdditionalAgentAction getAdditionalAgentAction() {
return AdditionalAgentAction.fromString((configMap.getOrDefault(ADDITIONAL_AGENT_ACTION_KEY,
AdditionalAgentAction.ASK.toString())).toString());
return AdditionalAgentAction
.fromString((configMap.getOrDefault(ADDITIONAL_AGENT_ACTION_KEY, AdditionalAgentAction.ASK.toString())).toString());
}

public void setNestedJarExtensions(List<String> extensions) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ public static String getConfigDirectory() {
}

public static File getBytemanDirectory() {
String s = getXdgJrdBaseDir() + XDG_BYTEMAN_SUFFIX;
String s = getXdgJrdBaseDir() + XDG_BYTEMAN_SUFFIX;
File f = new File(s);
f.mkdir();
return f;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,15 @@

import org.jrd.backend.decompiling.PluginManager;

public class Model {
public final class Model {

private VmManager vmManager = new VmManager();
private PluginManager pluginManager = new PluginManager();

private static final Model MODEL = new Model();

private Model(){};
private Model() {
}

public VmManager getVmManager() {
return vmManager;
Expand All @@ -19,7 +20,7 @@ public PluginManager getPluginManager() {
return pluginManager;
}

public static Model getMODEL() {
public static Model getModel() {
return MODEL;
}
}
21 changes: 9 additions & 12 deletions runtime-decompiler/src/main/java/org/jrd/backend/data/VmInfo.java
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@
import edu.umd.cs.findbugs.annotations.SuppressFBWarnings;

import org.jboss.byteman.agent.install.Install;
import org.jrd.backend.core.AgentLoader;
import org.jrd.backend.core.Logger;
import org.jrd.backend.core.VmDecompilerStatus;
import org.jrd.backend.core.agentstore.KnownAgent;
Expand Down Expand Up @@ -50,16 +49,15 @@ public enum Type {
private Type type;
private java.util.List<File> cp;

private static final Comparator<VmInfo> HOSTNAME_COMPARATOR =
Comparator.comparing(info -> {
if (info.getVmDecompilerStatus()!=null) {
return info.getVmDecompilerStatus().getHostname();
} else {
return "localhost";
}
}, String::compareTo);
private static final Comparator<VmInfo> HOSTNAME_COMPARATOR = Comparator.comparing(info -> {
if (info.getVmDecompilerStatus() != null) {
return info.getVmDecompilerStatus().getHostname();
} else {
return "localhost";
}
}, String::compareTo);
private static final Comparator<VmInfo> PORT_COMPARATOR = Comparator.comparingInt(info -> {
if (info.getVmDecompilerStatus()!=null) {
if (info.getVmDecompilerStatus() != null) {
return info.getVmDecompilerStatus().getListenPort();
} else {
return -1;
Expand Down Expand Up @@ -239,8 +237,7 @@ public BytemanCompanion setBytemanCompanion(boolean boot, int parentPort)
AgentConfig aconf = AgentConfig.getAnnonymousForcingPermanentAgent();
int secondJrdPort = NewAgentDialog.manualAttach(null, aconf, pid, true/*?*/);
vmDecompilerStatus.setBytemanCompanion(new BytemanCompanion(bytemanPort, secondJrdPort));
KnownAgents.getInstance().setBytemanCompanion(vmPid, parentPort,
vmDecompilerStatus.getBytemanCompanion());
KnownAgents.getInstance().setBytemanCompanion(vmPid, parentPort, vmDecompilerStatus.getBytemanCompanion());

}
return vmDecompilerStatus.getBytemanCompanion();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -85,13 +85,13 @@ private void loadSavedRemoteVms() {
return;
}
for (VmInfo savedVm : savedVms) {
try{
VmDecompilerStatus status = new VmDecompilerStatus();
status.setVmId(savedVm.getVmId());
status.setHostname(savedVm.getVmName());
status.setListenPort(Integer.parseInt(savedVm.getVmId().split(PORT_ID_SPLIT)[0]));
savedVm.setVmDecompilerStatus(status);
vmInfoSet.add(savedVm);
try {
VmDecompilerStatus status = new VmDecompilerStatus();
status.setVmId(savedVm.getVmId());
status.setHostname(savedVm.getVmName());
status.setListenPort(Integer.parseInt(savedVm.getVmId().split(PORT_ID_SPLIT)[0]));
savedVm.setVmDecompilerStatus(status);
vmInfoSet.add(savedVm);
} catch (Exception e) {
Logger.getLogger().log(Logger.Level.ALL, "Failed to prepare saved remote VMs. Cause: ");
Logger.getLogger().log(Logger.Level.ALL, e);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -215,7 +215,8 @@ public void consumeCli() throws Exception {
operatedOn.add(patchVmInfo);
break;
case OVERWRITE:
VmInfo vmInfo5 = new OverwriteAndUpload(filteredArgs, getVmManager(), isBoot, isHex).overwrite(ReceivedType.OVERWRITE_CLASS);
VmInfo vmInfo5 =
new OverwriteAndUpload(filteredArgs, getVmManager(), isBoot, isHex).overwrite(ReceivedType.OVERWRITE_CLASS);
operatedOn.add(vmInfo5);
break;
case ADD_CLASS:
Expand All @@ -224,7 +225,8 @@ public void consumeCli() throws Exception {
operatedOn.add(vmInfoAddClass);
break;
case ADD_JAR:
VmInfo vmInfoAddJar = new OverwriteAndUpload(filteredArgs, getVmManager(), isBoot, isHex).overwrite(ReceivedType.ADD_JAR);
VmInfo vmInfoAddJar =
new OverwriteAndUpload(filteredArgs, getVmManager(), isBoot, isHex).overwrite(ReceivedType.ADD_JAR);
operatedOn.add(vmInfoAddJar);
break;
case ADD_CLASSES:
Expand Down Expand Up @@ -371,10 +373,10 @@ public List<String> getFilteredArgs() {
}

public VmManager getVmManager() {
return Model.getMODEL().getVmManager();
return Model.getModel().getVmManager();
}

public PluginManager getPluginManager() {
return Model.getMODEL().getPluginManager();
return Model.getModel().getPluginManager();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ public final class AgentConfig {
public static AgentConfig getDefaultSinglePermanentAgent() {
return new AgentConfig(AgentLoneliness.SINGLE_INSTANCE, AgentLiveliness.PERMANENT, Optional.empty());
}

public static AgentConfig getAnnonymousForcingPermanentAgent() {
return new AgentConfig(AgentLoneliness.AF, AgentLiveliness.PERMANENT, Optional.empty());
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -228,14 +228,28 @@ public void mouseClicked(MouseEvent mouseEvent) {
new JListPopupMenu<>(localVmList, true, bytecodeDecompilerView.getDependenciesReader())
.addItem("name(s)", VmInfo::getVmName, true)
.addItem("PID(s)", vmInfo -> String.valueOf(vmInfo.getVmPid()), false)
.addItem("PORT(s)", vmInfo -> vmInfo.getVmDecompilerStatus()!=null?
String.valueOf(vmInfo.getVmDecompilerStatus().getListenPort()):"not yet connected", false)
.addItem("Byteman companion port(s)",
vmInfo -> vmInfo.getBytemanCompanion()!=null?
String.valueOf(vmInfo.getBytemanCompanion().getBytemanPort()):"0", false)
.addItem("Post byteman port(s)", vmInfo -> vmInfo.getBytemanCompanion()!=null?
String.valueOf(vmInfo.getBytemanCompanion().getPostBytemanAgentPort()):"0", false)
.show(localVmList, mouseEvent.getX(), mouseEvent.getY());
.addItem(
"PORT(s)",
vmInfo -> vmInfo.getVmDecompilerStatus() != null ?
String.valueOf(vmInfo.getVmDecompilerStatus().getListenPort()) :
"not yet connected",
false
)
.addItem(
"Byteman companion port(s)",
vmInfo -> vmInfo.getBytemanCompanion() != null ?
String.valueOf(vmInfo.getBytemanCompanion().getBytemanPort()) :
"0",
false
)
.addItem(
"Post byteman port(s)",
vmInfo ->
vmInfo.getBytemanCompanion() != null ?
String.valueOf(vmInfo.getBytemanCompanion().getPostBytemanAgentPort()) :
"0",
false
).show(localVmList, mouseEvent.getX(), mouseEvent.getY());
}
}
});
Expand Down
Loading

0 comments on commit dc6a4a1

Please sign in to comment.