Skip to content

Commit

Permalink
update to include classpath service, to check between previous runs
Browse files Browse the repository at this point in the history
  • Loading branch information
ahmadsebak committed Jun 21, 2015
1 parent dfc0c39 commit 02978f1
Show file tree
Hide file tree
Showing 7 changed files with 92 additions and 50 deletions.
3 changes: 3 additions & 0 deletions META-INF/plugin.xml
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,9 @@
<configurationType implementation="com.atsebak.embeddedlinuxjvm.runner.conf.EmbeddedLinuxJVMConfigurationType"/>
<projectService serviceImplementation="com.atsebak.embeddedlinuxjvm.console.EmbeddedLinuxJVMConsoleView"/>
<moduleBuilder builderClass="com.atsebak.embeddedlinuxjvm.project.RPiJavaModuleBuilder"/>

<projectService serviceImplementation="com.atsebak.embeddedlinuxjvm.services.ClasspathService"
serviceInterface="com.atsebak.embeddedlinuxjvm.services.ClasspathService"/>
</extensions>

</idea-plugin>
2 changes: 1 addition & 1 deletion embeddedlinux-jvmdebugger.iml
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
<sourceFolder url="file://$MODULE_DIR$/Resources" type="java-resource" />
<sourceFolder url="file://$MODULE_DIR$/test" isTestSource="true" />
</content>
<orderEntry type="jdk" jdkName="IntelliJ IDEA Community Edition IC-141.178.9 (1)" jdkType="IDEA JDK" />
<orderEntry type="inheritedJdk" />
<orderEntry type="sourceFolder" forTests="false" />
<orderEntry type="library" name="lombok" level="project" />
<orderEntry type="library" name="bcprov-ext-jdk15on-1.47" level="project" />
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,13 @@

import com.atsebak.embeddedlinuxjvm.console.EmbeddedLinuxJVMConsoleView;
import com.atsebak.embeddedlinuxjvm.console.EmbeddedLinuxJVMOutputForwarder;
import com.atsebak.embeddedlinuxjvm.deploy.DeployedLibrary;
import com.atsebak.embeddedlinuxjvm.deploy.DeploymentTarget;
import com.atsebak.embeddedlinuxjvm.localization.EmbeddedLinuxJVMBundle;
import com.atsebak.embeddedlinuxjvm.protocol.ssh.SSH;
import com.atsebak.embeddedlinuxjvm.protocol.ssh.SSHHandlerTarget;
import com.atsebak.embeddedlinuxjvm.runner.conf.EmbeddedLinuxJVMRunConfiguration;
import com.atsebak.embeddedlinuxjvm.runner.data.EmbeddedLinuxJVMRunConfigurationRunnerParameters;
import com.atsebak.embeddedlinuxjvm.services.ClasspathService;
import com.atsebak.embeddedlinuxjvm.utils.FileUtilities;
import com.atsebak.embeddedlinuxjvm.utils.RemoteCommandLineBuilder;
import com.intellij.execution.*;
Expand All @@ -25,6 +25,7 @@
import com.intellij.openapi.actionSystem.CommonDataKeys;
import com.intellij.openapi.application.Application;
import com.intellij.openapi.application.ApplicationManager;
import com.intellij.openapi.components.ServiceManager;
import com.intellij.openapi.module.Module;
import com.intellij.openapi.module.ModuleManager;
import com.intellij.openapi.progress.ProgressIndicator;
Expand All @@ -48,7 +49,9 @@

import java.io.File;
import java.io.IOException;
import java.util.*;
import java.util.ArrayList;
import java.util.Collection;
import java.util.List;

public class AppCommandLineState extends JavaCommandLineState {
@NonNls
Expand Down Expand Up @@ -202,8 +205,9 @@ public void run() {
@Override
public void run() {
try {
ClasspathService service = ServiceManager.getService(project, ClasspathService.class);
List<File> hostLibraries = invokeClassPathResolver(classPath.getPathList(), manager.getProjectSdk());
File classpathArchive = FileUtilities.createClasspathArchive(deltaOfDeployedJars(hostLibraries), project);
File classpathArchive = FileUtilities.createClasspathArchive(service.deltaOfDeployedJars(hostLibraries), project);
invokeDeployment(classpathArchive.getPath(), commandLineTarget);
} catch (Exception e) {
EmbeddedLinuxJVMConsoleView.getInstance(project).print(EmbeddedLinuxJVMBundle.message("pi.connection.failed", e.getLocalizedMessage()),
Expand Down Expand Up @@ -269,48 +273,6 @@ private void invokeDeployment(String projectOutput, CommandLineTarget commandLin
target.upload(new File(projectOutput), commandLineTarget.toString());
}

/**
* Gets deployed jars
*/
private List<DeployedLibrary> invokeFindDeployedJars() throws IOException, RuntimeConfigurationException {
EmbeddedLinuxJVMRunConfigurationRunnerParameters runnerParameters = configuration.getRunnerParameters();
SSHHandlerTarget target = SSHHandlerTarget.builder().piRunnerParameters(runnerParameters)
.consoleView(EmbeddedLinuxJVMConsoleView.getInstance(project))
.ssh(SSH.builder()
.connectionTimeout(30000)
.timeout(30000)
.build()).build();
return target.listAlreadyUploadedJars();
}

/**
* Gets the delta of jars between host and target machines
*
* @param hostLibraries
* @return targetLibraries
*/
private List<File> deltaOfDeployedJars(List<File> hostLibraries) throws IOException, RuntimeConfigurationException {
List<DeployedLibrary> targetLibraries = invokeFindDeployedJars();
Set<String> filesToDeploy = new HashSet<String>(); //hash what files exist
//todo improve based on last modified date, size, and the name of the file and not just the filename
for (DeployedLibrary deployedLibrary : targetLibraries) {
for (File hostFile : hostLibraries) {
if (deployedLibrary.getJarName().equals(hostFile.getName())) {
filesToDeploy.add(hostFile.getName());
break;
}
}
}

//add files that do not exist on target
List<File> newLibraries = new ArrayList<File>();
for (File hostFile : hostLibraries) {
if (!filesToDeploy.contains(hostFile.getName())) {
newLibraries.add(hostFile);
}
}
return newLibraries;
}

/**
* Creates debugging settings for server
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,13 @@ public class SSHHandlerTarget {
private EmbeddedLinuxJVMConsoleView consoleView;
private SSH ssh;

/**
* Can get this information from the IDE
*
* @return
* @throws IOException
* @throws RuntimeConfigurationException
*/
public List<DeployedLibrary> listAlreadyUploadedJars() throws IOException, RuntimeConfigurationException {
final String remoteDir = FileUtilities.SEPARATOR + "home" + FileUtilities.SEPARATOR
+ piRunnerParameters.getUsername() + FileUtilities.SEPARATOR + OUTPUT_LOCATION;
Expand Down
70 changes: 70 additions & 0 deletions src/com/atsebak/embeddedlinuxjvm/services/ClasspathService.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
package com.atsebak.embeddedlinuxjvm.services;


import com.atsebak.embeddedlinuxjvm.console.EmbeddedLinuxJVMConsoleView;
import com.atsebak.embeddedlinuxjvm.deploy.DeployedLibrary;
import com.atsebak.embeddedlinuxjvm.protocol.ssh.SSH;
import com.atsebak.embeddedlinuxjvm.protocol.ssh.SSHHandlerTarget;
import com.atsebak.embeddedlinuxjvm.runner.data.EmbeddedLinuxJVMRunConfigurationRunnerParameters;
import com.intellij.execution.configurations.RuntimeConfigurationException;
import com.intellij.openapi.project.Project;
import org.jetbrains.annotations.NotNull;

import java.io.File;
import java.io.IOException;
import java.util.ArrayList;
import java.util.List;

public class ClasspathService {
@NotNull
private final Project project;
private List<File> previousDeployFiles;

/**
* Clear up static file list of deployments
*/
public ClasspathService(@NotNull Project project) {
this.project = project;
previousDeployFiles = new ArrayList<File>();
}

/**
* Gets the delta of jars between host and target machines. It will always add the normal project output path but not necessarily the external libs
* Some potential problems can be that the user stops it midway while deploying so the jars don't go on the target.
*
* @param hostLibraries
* @return targetLibraries
*/
public List<File> deltaOfDeployedJars(List<File> hostLibraries) throws IOException, RuntimeConfigurationException {
List<File> newLibraries = new ArrayList<File>();
for (File hostFile : hostLibraries) {
if (!hostFile.getName().contains("jar")) {
newLibraries.add(hostFile);
} else if (!previousDeployFiles.contains(hostFile)) {
newLibraries.add(hostFile);
}
}
previousDeployFiles = hostLibraries;
return newLibraries;
}

/**
* Gets the deployed jars on target machine
*
* @return
* @throws IOException
* @throws RuntimeConfigurationException
* @deprecated use deltaOfDeployedJars instead
*/
@Deprecated
public List<DeployedLibrary> invokeFindDeployedJars(EmbeddedLinuxJVMRunConfigurationRunnerParameters runnerParameters)
throws IOException, RuntimeConfigurationException {
SSHHandlerTarget target = SSHHandlerTarget.builder().piRunnerParameters(runnerParameters)
.consoleView(EmbeddedLinuxJVMConsoleView.getInstance(project))
.ssh(SSH.builder()
.connectionTimeout(30000)
.timeout(30000)
.build()).build();
return target.listAlreadyUploadedJars();
}
}
6 changes: 3 additions & 3 deletions src/com/atsebak/embeddedlinuxjvm/utils/FileUtilities.java
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ public static void unzip(InputStream inputStream, String outputFolder) {
continue;
}
fileName = new File(fileName).getName();
File newFile = new File(outputFolder + FileUtilities.SEPARATOR + fileName);
File newFile = new File(outputFolder + SEPARATOR + fileName);
new File(newFile.getParent()).mkdirs();

FileOutputStream fos = new FileOutputStream(newFile);
Expand Down Expand Up @@ -115,7 +115,7 @@ public static File createClasspathArchive(Collection<File> classpathEntries, Pro
private static void writeClassPath(LinkedList<String> pathElements, File entry, TarArchiveOutputStream archiveOutputStream) throws IOException {
if (entry.isFile()) {
archiveOutputStream.setLongFileMode(TarArchiveOutputStream.LONGFILE_GNU);
archiveOutputStream.putArchiveEntry(new TarArchiveEntry(entry, getPath(pathElements) + FileUtilities.SEPARATOR + entry.getName()));
archiveOutputStream.putArchiveEntry(new TarArchiveEntry(entry, getPath(pathElements) + SEPARATOR + entry.getName()));
copy(entry, archiveOutputStream);
archiveOutputStream.closeArchiveEntry();
} else {
Expand Down Expand Up @@ -156,7 +156,7 @@ public static String getPath(LinkedList<String> pathElements) {
StringBuilder buf = new StringBuilder();
for (int i = 0; i < pathElements.size(); i++) {
if (i != 0) {
buf.append(FileUtilities.SEPARATOR);
buf.append(SEPARATOR);
}
buf.append(pathElements.get(i));
}
Expand Down
2 changes: 1 addition & 1 deletion src/com/atsebak/embeddedlinuxjvm/utils/Notifications.java
Original file line number Diff line number Diff line change
Expand Up @@ -5,5 +5,5 @@ public class Notifications {
/**
* ID for notifications
*/
public static final String GROUPDISPLAY_ID = "Raspbery PI Notifications";
public static final String GROUPDISPLAY_ID = "EmbeddedLinux JVM Notifications";
}

0 comments on commit 02978f1

Please sign in to comment.