Problem with loading vp-file of 5.1 version in plugin

Ruslan Vildanov shared this problem 6 years ago
Solved

I've updated .vp file in Justinmind 5.1.


I've tried to open new .vp file in plugin which is made according to http://www.justinmind.com/plugin-mark...


In that line:


IPrototype prototype = API.getPrototypeLoader().loadPrototype("prototype",temp_directory+File.separator+"work");


I've got this error:


java.lang.NullPointerException at com.justinmind.evc.model.projects.EVCProjectManagerModel.loadPrototype(EVCProjectManagerModel.java:149)

Comments (6)

photo
1

Hi Ruslan,


The correct forum to post this kind of questions is this one https://www.justinmind.com/community...


Anyway, would you mind to send your plugin to jim.support at justinmind.com ? We will take a look at it.

photo
1

Thank you, Victor.


I've sent e-mail them.

photo
1

In version 5.0 we introduced a major change in the file structure of the ‘.vp’ files. The loadPrototype method of the IPrototypeLoader interface fails because is expecting to open a prototype with the old file structure.


We just fixed this API method, however until we release the next update of Justinmind Prototyper we can’t update our Justinmind Plugin SDK.


Meanwhile if you want you can use this code as a workaround:


//Adapt unzipped folder to the new .vp file structure introduced in version 5.0


private static void checkPrototypeFolder(String testProjectDir, String prototypeFolderName) throws IOException{


File prototypeFolder = new File(testProjectDir + File.separator+prototypeFolderName);


if(!prototypeFolder.exists())


FileUtils.copyDirectoryTo(testProjectDir, prototypeFolder.getAbsolutePath());


}


/**


* @param args


*/


public static void main(String[] args) {


String tmpDir = System.getProperty("java.io.tmpdir");


String testProjectDir = tmpDir + File.separator + "testDirectory";


String prototypeFolderName = "prototype";


FileUtils.deepDeleteDirExceptRoot(testProjectDir);


FileDialog dialog = new FileDialog(new Shell());


String pathToVp = dialog.open();


try {


FileUtils.unZip(pathToVp, testProjectDir);


checkPrototypeFolder(testProjectDir,prototypeFolderName);


IPrototype prototype = API.getPrototypeLoader().loadPrototype(prototypeFolderName, testProjectDir);


List canvases = prototype.getApiCanvases();


for (ICanvas canvas : canvases) {


System.out.println(canvas.getApiName());


}


}


catch (Exception e) {


e.printStackTrace();


}


}

photo
1

Thank you very much, Victor :)

photo
1

Hi Victor!


I found a problem with that function:


private static void checkPrototypeFolder(String testProjectDir, String prototypeFolderName) throws IOException{


File prototypeFolder = new File(testProjectDir + File.separator+prototypeFolderName);


if(!prototypeFolder.exists())


FileUtils.copyDirectoryTo(testProjectDir, prototypeFolder.getAbsolutePath());


}


on Windows 7 it creates many subfolders in temp directory (OS crushes in the blue-screen) of prototypeFolderName ("prototype")


I fixed it next way:


private static void checkPrototypeFolder(String testProjectDir, final String prototypeFolderName) throws IOException {


File prototypeFolder = new File(testProjectDir + File.separator + prototypeFolderName);


if(!prototypeFolder.exists()) {


org.apache.commons.io.FileUtils.copyDirectory(


new File(testProjectDir),


new File(prototypeFolder.getAbsolutePath()),


new FileFilter () {


@Override


public boolean accept(File arg0) {


return !arg0.getName().equals(prototypeFolderName);


}


});


}


}

photo
1

Fixed in the new api