SDK:
- allow editing private project properties with ProjectExtensionProperties - add ZipExtensionTool to extract zip files with extensions to settings folder git-svn-id: https://jmonkeyengine.googlecode.com/svn/trunk@9900 75d07b2b-3a1a-0410-a2c5-0572b91ccdca
This commit is contained in:
parent
b41952025b
commit
d30f6fe686
@ -54,6 +54,7 @@ public class ProjectExtensionProperties {
|
||||
private String[] keyList;
|
||||
private Project project;
|
||||
private EditableProperties properties;
|
||||
private String propertyFileName;
|
||||
|
||||
/**
|
||||
* Allows accessing a defined set of properties of a jMonkeyPlatform project
|
||||
@ -61,14 +62,29 @@ public class ProjectExtensionProperties {
|
||||
* @param keyList A list of all property keys this list should use
|
||||
*/
|
||||
public ProjectExtensionProperties(Project project, String[] keyList) {
|
||||
this(project, keyList, false);
|
||||
}
|
||||
|
||||
/**
|
||||
* Allows accessing a defined set of properties of a jMonkeyPlatform project
|
||||
* @param project The project to which the properties are stored
|
||||
* @param keyList A list of all property keys this list should use
|
||||
* @param privateProps If true, saves settings to private (local) properties file
|
||||
*/
|
||||
public ProjectExtensionProperties(Project project, String[] keyList, boolean privateProps) {
|
||||
this.project = project;
|
||||
this.keyList = keyList;
|
||||
properties = new EditableProperties(true);
|
||||
if (project instanceof J2SEProject) {
|
||||
load();
|
||||
}
|
||||
if(privateProps){
|
||||
propertyFileName = AntProjectHelper.PRIVATE_PROPERTIES_PATH;
|
||||
}else{
|
||||
propertyFileName = AntProjectHelper.PROJECT_PROPERTIES_PATH;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public EditableProperties getProperties() {
|
||||
return properties;
|
||||
}
|
||||
@ -101,7 +117,7 @@ public class ProjectExtensionProperties {
|
||||
}
|
||||
|
||||
public void store() throws IOException {
|
||||
final FileObject projPropsFO = project.getProjectDirectory().getFileObject(AntProjectHelper.PROJECT_PROPERTIES_PATH);
|
||||
final FileObject projPropsFO = project.getProjectDirectory().getFileObject(propertyFileName);
|
||||
if (projPropsFO == null) {
|
||||
return;
|
||||
}
|
||||
|
258
sdk/jme3-core/src/com/jme3/gde/core/util/ZipExtensionTool.java
Normal file
258
sdk/jme3-core/src/com/jme3/gde/core/util/ZipExtensionTool.java
Normal file
@ -0,0 +1,258 @@
|
||||
/*
|
||||
* Copyright (c) 2003-2012 jMonkeyEngine
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions are
|
||||
* met:
|
||||
*
|
||||
* * Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
*
|
||||
* * Redistributions in binary form must reproduce the above copyright
|
||||
* notice, this list of conditions and the following disclaimer in the
|
||||
* documentation and/or other materials provided with the distribution.
|
||||
*
|
||||
* * Neither the name of 'jMonkeyEngine' nor the names of its contributors
|
||||
* may be used to endorse or promote products derived from this software
|
||||
* without specific prior written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
|
||||
* TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
|
||||
* PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
|
||||
* CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
|
||||
* EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
|
||||
* PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
|
||||
* PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
|
||||
* LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
|
||||
* NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
||||
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*/
|
||||
package com.jme3.gde.core.util;
|
||||
|
||||
import java.io.BufferedInputStream;
|
||||
import java.io.BufferedOutputStream;
|
||||
import java.io.BufferedReader;
|
||||
import java.io.File;
|
||||
import java.io.FileOutputStream;
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.io.InputStreamReader;
|
||||
import java.net.URL;
|
||||
import java.util.logging.Level;
|
||||
import java.util.logging.Logger;
|
||||
import java.util.zip.ZipEntry;
|
||||
import java.util.zip.ZipInputStream;
|
||||
import org.netbeans.api.progress.ProgressHandle;
|
||||
import org.netbeans.api.progress.ProgressHandleFactory;
|
||||
import org.openide.DialogDisplayer;
|
||||
import org.openide.NotifyDescriptor;
|
||||
import org.openide.util.Exceptions;
|
||||
import org.openide.util.Utilities;
|
||||
|
||||
/**
|
||||
* Tool that extracts zip files specific per platform to the settings directory
|
||||
* of the SDK. All zip files have to be in the package defined by packageName
|
||||
* and be named like (extensionName)-(os).zip, where (os) can be linux, windows
|
||||
* or mac. The suffixes can be changed for extraction so one package can be used
|
||||
* for multiple platforms.
|
||||
*
|
||||
* @author normenhansen
|
||||
*/
|
||||
public class ZipExtensionTool {
|
||||
|
||||
static final int BUFFER = 2048;
|
||||
private final String settingsFolder = System.getProperty("netbeans.user");
|
||||
public String SUFFIX_WIN = "windows";
|
||||
public String SUFFIX_LINUX = "linux";
|
||||
public String SUFFIX_OSX = "mac";
|
||||
private final String packageName;
|
||||
private final String extensionName;
|
||||
private ProgressHandle progress;
|
||||
|
||||
public ZipExtensionTool(String packageName, String extensionName) {
|
||||
this.packageName = "/" + packageName.replace('.', '/');
|
||||
this.extensionName = extensionName;
|
||||
}
|
||||
|
||||
public void install() {
|
||||
ProgressHandle progressHandle = ProgressHandleFactory.createHandle("Installing " + extensionName + " data");
|
||||
progressHandle.start();
|
||||
if (new File(settingsFolder + File.separator + extensionName).exists()) {
|
||||
return;
|
||||
}
|
||||
if (Utilities.isWindows()) {
|
||||
extractToolsJava(packageName + "/" + extensionName + "-" + SUFFIX_WIN + ".zip", settingsFolder + File.separator + extensionName);
|
||||
} else if (Utilities.isMac()) {
|
||||
extractToolsShell(packageName + "/" + extensionName + "-" + SUFFIX_OSX + ".zip", settingsFolder + File.separator + extensionName);
|
||||
} else if (Utilities.isUnix()) {
|
||||
extractToolsShell(packageName + "/" + extensionName + "-" + SUFFIX_LINUX + ".zip", settingsFolder + File.separator + extensionName);
|
||||
}
|
||||
progressHandle.finish();
|
||||
}
|
||||
|
||||
private boolean extractToolsShell(String zipPath, String extractionPath) {
|
||||
File path = new File(extractionPath);
|
||||
if (!path.exists()) {
|
||||
path.mkdirs();
|
||||
}
|
||||
BufferedInputStream in = null;
|
||||
BufferedOutputStream out = null;
|
||||
URL url = null;
|
||||
try {
|
||||
String tempFileName = extractionPath + "_tmp.zip";
|
||||
System.out.println("ZipPath: " + zipPath);
|
||||
url = new URL("nbres:" + zipPath);
|
||||
in = new BufferedInputStream(url.openStream());
|
||||
out = new BufferedOutputStream(new FileOutputStream(tempFileName));
|
||||
int inbyte = in.read();
|
||||
while (inbyte != -1) {
|
||||
out.write(inbyte);
|
||||
inbyte = in.read();
|
||||
}
|
||||
in.close();
|
||||
out.close();
|
||||
String[] cmdStrings = new String[]{
|
||||
"unzip",
|
||||
"-o",
|
||||
"-q",
|
||||
tempFileName,
|
||||
"-d",
|
||||
extractionPath
|
||||
};
|
||||
Process p = Runtime.getRuntime().exec(cmdStrings);
|
||||
OutputReader outReader = new OutputReader(p.getInputStream());
|
||||
OutputReader errReader = new OutputReader(p.getErrorStream());
|
||||
outReader.start();
|
||||
errReader.start();
|
||||
p.waitFor();
|
||||
File zipFile = new File(tempFileName);
|
||||
zipFile.delete();
|
||||
if (p.exitValue() != 0) {
|
||||
return false;
|
||||
}
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
NotifyDescriptor.Confirmation msg = new NotifyDescriptor.Confirmation(
|
||||
"Error extracting " + extensionName,
|
||||
NotifyDescriptor.DEFAULT_OPTION,
|
||||
NotifyDescriptor.ERROR_MESSAGE);
|
||||
DialogDisplayer.getDefault().notify(msg);
|
||||
return false;
|
||||
} finally {
|
||||
if (in != null) {
|
||||
try {
|
||||
in.close();
|
||||
} catch (IOException ex) {
|
||||
Exceptions.printStackTrace(ex);
|
||||
}
|
||||
}
|
||||
if (out != null) {
|
||||
try {
|
||||
out.close();
|
||||
} catch (IOException ex) {
|
||||
Exceptions.printStackTrace(ex);
|
||||
}
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
private boolean extractToolsJava(String zipPath, String extractionPath) {
|
||||
File path = new File(extractionPath);
|
||||
if (!path.exists()) {
|
||||
path.mkdirs();
|
||||
}
|
||||
|
||||
try {
|
||||
File scriptsFolderFile = new File(extractionPath);
|
||||
if (!scriptsFolderFile.exists()) {
|
||||
NotifyDescriptor.Confirmation msg = new NotifyDescriptor.Confirmation(
|
||||
"Error extracting " + extensionName,
|
||||
NotifyDescriptor.DEFAULT_OPTION,
|
||||
NotifyDescriptor.ERROR_MESSAGE);
|
||||
DialogDisplayer.getDefault().notify(msg);
|
||||
return false;
|
||||
}
|
||||
BufferedOutputStream dest = null;
|
||||
ZipInputStream zis = new ZipInputStream(new BufferedInputStream(getClass().getResourceAsStream(zipPath)));
|
||||
ZipEntry entry;
|
||||
while ((entry = zis.getNextEntry()) != null) {
|
||||
int count;
|
||||
byte data[] = new byte[BUFFER];
|
||||
if (entry.getName().contains(".svn") || entry.getName().contains(".DS_Store")) {
|
||||
continue;
|
||||
}
|
||||
if (entry.isDirectory()) {
|
||||
File dir = new File(extractionPath + File.separator + entry.getName());
|
||||
dir.mkdirs();
|
||||
continue;
|
||||
}
|
||||
// write the files to the disk
|
||||
FileOutputStream fos = new FileOutputStream(extractionPath + File.separator + entry.getName());
|
||||
dest = new BufferedOutputStream(fos, BUFFER);
|
||||
while ((count = zis.read(data, 0, BUFFER))
|
||||
!= -1) {
|
||||
dest.write(data, 0, count);
|
||||
}
|
||||
dest.flush();
|
||||
dest.close();
|
||||
}
|
||||
zis.close();
|
||||
} catch (IOException ex) {
|
||||
NotifyDescriptor.Confirmation msg = new NotifyDescriptor.Confirmation(
|
||||
"Error extracting " + extensionName + ":" + ex.toString(),
|
||||
NotifyDescriptor.DEFAULT_OPTION,
|
||||
NotifyDescriptor.ERROR_MESSAGE);
|
||||
DialogDisplayer.getDefault().notify(msg);
|
||||
Exceptions.printStackTrace(ex);
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param progress the progress to set
|
||||
*/
|
||||
public void setProgress(ProgressHandle progress) {
|
||||
this.progress = progress;
|
||||
}
|
||||
|
||||
public class OutputReader implements Runnable {
|
||||
|
||||
private Thread thread;
|
||||
private BufferedReader in;
|
||||
|
||||
public OutputReader(InputStream in) {
|
||||
this.in = new BufferedReader(new InputStreamReader(in));
|
||||
}
|
||||
|
||||
public OutputReader(BufferedReader in) {
|
||||
this.in = in;
|
||||
}
|
||||
|
||||
public void start() {
|
||||
thread = new Thread(this);
|
||||
thread.start();
|
||||
}
|
||||
|
||||
public void run() {
|
||||
try {
|
||||
String line;
|
||||
while ((line = in.readLine()) != null) {
|
||||
if (line.trim().length() > 0) {
|
||||
if (progress != null) {
|
||||
progress.progress(line);
|
||||
} else {
|
||||
Logger.getLogger(this.getClass().getName()).log(Level.INFO, line);
|
||||
}
|
||||
}
|
||||
}
|
||||
} catch (Exception e) {
|
||||
Exceptions.printStackTrace(e);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
Loading…
x
Reference in New Issue
Block a user