Skip to content

Commit

Permalink
updated project creation for raspberry pi
Browse files Browse the repository at this point in the history
  • Loading branch information
asebak committed Jun 14, 2015
1 parent 2e1552e commit d196245
Show file tree
Hide file tree
Showing 4 changed files with 34 additions and 65 deletions.
22 changes: 9 additions & 13 deletions META-INF/plugin.xml
Original file line number Diff line number Diff line change
@@ -1,15 +1,21 @@
<idea-plugin version="2">
<id>com.atsebak.raspberrypi</id>
<name>Embedded Linux JVM Debugger (Raspberry Pi, Intel x86, ARM processors)</name>
<version>0.40</version>
<version>0.41</version>
<vendor email="[email protected]" url="http://www.atsebak.com">At Sebak</vendor>

<description><![CDATA[
<p>Java Debugger for Embedded Systems that run on Embedded Linux</p>
<p>Java Debugger for Embedded Systems that run on Embedded Linux or on the <a href="https://www.yoctoproject.org/">Yocto Project Kernel</a></p>
]]></description>

<change-notes><![CDATA[
<b>Version 0.40</b>
<b>Version 0.41</b>
<ul>
<li>
Fixed Raspberry PI Project Templates Generation
</li>
</ul>
<b>Version 0.40</b>
<ul>
<li>
Fixed the way java process gets terminated on remote target.
Expand Down Expand Up @@ -70,14 +76,4 @@
<moduleBuilder builderClass="com.atsebak.embeddedlinuxjvm.project.RPiJavaModuleBuilder"/>
</extensions>

<application-components>
</application-components>

<project-components>
</project-components>

<actions>
</actions>


</idea-plugin>
Binary file added Resources/pi4j.zip
Binary file not shown.
71 changes: 22 additions & 49 deletions src/com/atsebak/embeddedlinuxjvm/project/RPiJavaModuleBuilder.java
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,8 @@
import com.intellij.testFramework.PsiTestUtil;
import lombok.NoArgsConstructor;
import lombok.Setter;
import lombok.SneakyThrows;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;

import javax.swing.*;
Expand All @@ -45,10 +47,8 @@
public class RPiJavaModuleBuilder extends JavaModuleBuilder {
public static final ProjectType PI_PROJECT_TYPE = new ProjectType("PI_JAVA");
private static final String PROJECT_NAME = "Raspberry PI";
private static final String PI4J_DOWNLOAD = "http://get.pi4j.com/download/";
private static final String PI4J_FILENAME = "pi4j-1.1-SNAPSHOT.zip";
private static final String PI4J_INSTALLPATH = "/opt/pi4j/lib";
private String packageName;
@Nullable
private File[] jarsToAdd;

/**
Expand Down Expand Up @@ -82,30 +82,26 @@ public void setupRootModel(final ModifiableRootModel rootModel) throws Configura
* @param rootModel
* @param project
*/
private void createProjectFiles(final ModifiableRootModel rootModel, final Project project) {
private void createProjectFiles(@NotNull final ModifiableRootModel rootModel,@NotNull final Project project) {
ProjectUtils.runWhenInitialized(project, new DumbAwareRunnable() {
public void run() {
String srcPath = project.getBasePath() + "/src";
String libPath = project.getBasePath() + "/lib";
try {
//todo fix
// VfsUtil.createDirectories(libPath);
addJarFiles(libPath, rootModel.getModule());
String[] directorysToMake = packageName.split(Pattern.quote("."));
for (String directory : directorysToMake) {
String srcPath = project.getBasePath() + File.separator + "src";
addJarFiles(rootModel.getModule());
String[] directoriesToMake = packageName.split(Pattern.quote("."));
for (String directory : directoriesToMake) {
try {
VfsUtil.createDirectories(srcPath + FileUtilities.separator + directory);
srcPath += FileUtilities.separator + directory;
}
} catch (IOException e) {
} catch (IOException e) {

}
srcPath += FileUtilities.separator + directory;
}
Template.builder().name("main.ftl")
.classContext(this.getClass())
.outputFile(srcPath + FileUtilities.separator + "Main.java")
.data(new HashMap<String, Object>() {{
put("packagename", packageName);
}})
.build()
}}).build()
.toFile();
ProjectUtils.addProjectConfiguration(rootModel.getModule(), project, packageName + ".Main");
}
Expand Down Expand Up @@ -200,31 +196,15 @@ public String getDescription() {
* @param module
* @throws ConfigurationException
*/
@SneakyThrows(IOException.class)
@Override
protected void setupModule(Module module) throws ConfigurationException {
super.setupModule(module);
File pi4j = new File(PI4J_INSTALLPATH);

//user installed library already
if (pi4j.exists()) {
jarsToAdd = pi4j.listFiles();
} else {
try {
//download library
File pi4jZip = new File(System.getProperty("java.io.tmpdir") + FileUtilities.separator + PI4J_FILENAME);
if (!pi4jZip.exists()) {
UrlDownloader.saveUrl(System.getProperty("java.io.tmpdir") + FileUtilities.separator + PI4J_FILENAME, PI4J_DOWNLOAD + PI4J_FILENAME);
}
//unzip to temp
String output = System.getProperty("java.io.tmpdir") + FileUtilities.separator + "pi4j";
File pi4jUnziped = new File(output);
if (!pi4jUnziped.exists()) {
FileUtilities.unzip(pi4jZip.getPath(), output);
}
jarsToAdd = pi4jUnziped.listFiles();
} catch (IOException e) {
}
}
final String libPath = module.getProject().getBasePath() + File.separator + "lib";
VfsUtil.createDirectories(libPath);
File outputFiles = new File(libPath);
FileUtilities.unzip(getClass().getResourceAsStream("/pi4j.zip"), outputFiles.getAbsolutePath());
jarsToAdd = outputFiles.listFiles();
}

/**
Expand All @@ -236,23 +216,16 @@ protected ProjectType getProjectType() {
return PI_PROJECT_TYPE;
}

private void addJarFiles(String outputPath, Module module) {
private void addJarFiles(Module module) {
if (jarsToAdd == null) {
return;
}
//todo fix
// for (final File fileEntry : jarsToAdd) {
// if (!fileEntry.isDirectory() && Files.getFileExtension(fileEntry.getName()).contains("jar")) {
// String jarLocation = outputPath + FileUtilities.separator;
// FileUtils.copyFile(fileEntry, new File(jarLocation + fileEntry.getName()));
// }
// }

for (final File fileEntry : jarsToAdd) {
if (!fileEntry.isDirectory() && Files.getFileExtension(fileEntry.getName()).contains("jar")) {
PsiTestUtil.addLibrary(module, "pi4j", fileEntry.getParentFile().getPath(), fileEntry.getName());
PsiTestUtil.addLibrary(module, fileEntry.getName(), fileEntry.getParentFile().getPath(), fileEntry.getName());
}
}
PsiTestUtil.addLibrary(module, outputPath);
}

/**
Expand Down
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 @@ -20,17 +20,17 @@ public class FileUtilities {
/**
* Unzips a file all into one directory
*
* @param zipFile
* @param inputStream
* @param outputFolder
*/
public static void unzip(String zipFile, String outputFolder) {
public static void unzip(InputStream inputStream, String outputFolder) {
byte[] buffer = new byte[1024];
try {
File folder = new File(outputFolder);
if (!folder.exists()) {
folder.mkdir();
}
ZipInputStream zis = new ZipInputStream(new FileInputStream(zipFile));
ZipInputStream zis = new ZipInputStream(inputStream);
ZipEntry ze = zis.getNextEntry();

while (ze != null) {
Expand Down

0 comments on commit d196245

Please sign in to comment.