|
From: <gf...@us...> - 2008-03-18 20:30:20
|
Revision: 1163
http://jason.svn.sourceforge.net/jason/?rev=1163&view=rev
Author: gfronza
Date: 2008-03-18 13:29:50 -0700 (Tue, 18 Mar 2008)
Log Message:
-----------
Fixed problem in the Mas2j editor. Now is possible to open external projects (outside workspace) with the plugin.
New feature was added, now is possible import to workspace external projects created in jEdit.
Modified Paths:
--------------
trunk/applications/jason-eclipse-plugin/.classpath
trunk/applications/jason-eclipse-plugin/META-INF/MANIFEST.MF
trunk/applications/jason-eclipse-plugin/plugin.xml
trunk/applications/jason-eclipse-plugin/src/net/sourceforge/jasonide/core/MAS2JHandler.java
trunk/applications/jason-eclipse-plugin/src/net/sourceforge/jasonide/core/PluginTemplates.java
trunk/applications/jason-eclipse-plugin/src/net/sourceforge/jasonide/editors/ASLEditor.java
trunk/applications/jason-eclipse-plugin/src/net/sourceforge/jasonide/editors/MAS2JEditor.java
trunk/applications/jason-eclipse-plugin/src/net/sourceforge/jasonide/wizards/NewAgentWizard.java
trunk/applications/jason-eclipse-plugin/src/net/sourceforge/jasonide/wizards/NewEnvironmentWizard.java
trunk/applications/jason-eclipse-plugin/src/net/sourceforge/jasonide/wizards/NewEnvironmentWizardPage.java
trunk/applications/jason-eclipse-plugin/src/net/sourceforge/jasonide/wizards/NewInternalActionWizardPage.java
trunk/applications/jason-eclipse-plugin/src/net/sourceforge/jasonide/wizards/NewJasonProjectWizard.java
Added Paths:
-----------
trunk/applications/jason-eclipse-plugin/icons/list.gif
trunk/applications/jason-eclipse-plugin/src/net/sourceforge/jasonide/core/ProjectCreation.java
trunk/applications/jason-eclipse-plugin/src/net/sourceforge/jasonide/importWizards/
trunk/applications/jason-eclipse-plugin/src/net/sourceforge/jasonide/importWizards/JasonProjectImportWizard.java
trunk/applications/jason-eclipse-plugin/src/net/sourceforge/jasonide/importWizards/JasonProjectImportWizardPage.java
Modified: trunk/applications/jason-eclipse-plugin/.classpath
===================================================================
--- trunk/applications/jason-eclipse-plugin/.classpath 2008-03-18 20:12:54 UTC (rev 1162)
+++ trunk/applications/jason-eclipse-plugin/.classpath 2008-03-18 20:29:50 UTC (rev 1163)
@@ -1,6 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>
<classpath>
- <classpathentry kind="src" path="src"/>
+ <classpathentry excluding="**/.svn/|.svn/" kind="src" path="src"/>
<classpathentry exported="true" kind="lib" path="lib/dom4j-mini.jar"/>
<classpathentry exported="true" kind="lib" path="lib/jason.jar"/>
<classpathentry exported="true" kind="lib" path="lib/regexp-1.2-mini.jar"/>
Modified: trunk/applications/jason-eclipse-plugin/META-INF/MANIFEST.MF
===================================================================
--- trunk/applications/jason-eclipse-plugin/META-INF/MANIFEST.MF 2008-03-18 20:12:54 UTC (rev 1162)
+++ trunk/applications/jason-eclipse-plugin/META-INF/MANIFEST.MF 2008-03-18 20:29:50 UTC (rev 1163)
@@ -2,7 +2,7 @@
Bundle-ManifestVersion: 2
Bundle-Name: JasonIDE Plug-in
Bundle-SymbolicName: net.sourceforge.jasonide;singleton:=true
-Bundle-Version: 1.0.0
+Bundle-Version: 1.0.1
Bundle-Activator: net.sourceforge.jasonide.Activator
Bundle-Localization: plugin
Require-Bundle: org.eclipse.ui,
@@ -15,7 +15,8 @@
org.eclipse.jdt.ui,
org.eclipse.jdt.core,
org.eclipse.debug.core,
- org.eclipse.jdt.launching
+ org.eclipse.jdt.launching,
+ org.eclipse.debug.ui
Eclipse-LazyStart: true
Bundle-Vendor: net.sourceforge.jason
Bundle-ClassPath: lib/dom4j-mini.jar,
Added: trunk/applications/jason-eclipse-plugin/icons/list.gif
===================================================================
(Binary files differ)
Property changes on: trunk/applications/jason-eclipse-plugin/icons/list.gif
___________________________________________________________________
Name: svn:mime-type
+ application/octet-stream
Modified: trunk/applications/jason-eclipse-plugin/plugin.xml
===================================================================
--- trunk/applications/jason-eclipse-plugin/plugin.xml 2008-03-18 20:12:54 UTC (rev 1162)
+++ trunk/applications/jason-eclipse-plugin/plugin.xml 2008-03-18 20:29:50 UTC (rev 1163)
@@ -131,5 +131,21 @@
menubarPath="additions"/>
</objectContribution>
</extension>
+ <extension
+ point="org.eclipse.ui.importWizards">
+ <category
+ id="net.sourceforge.jasonide.importWizards"
+ name="Jason"/>
+ <wizard
+ category="net.sourceforge.jasonide.importWizards"
+ class="net.sourceforge.jasonide.importWizards.JasonProjectImportWizard"
+ icon="icons/jason.jpg"
+ id="net.sourceforge.jasonide.importWizards.JasonProjectImportWizard"
+ name="Import Jason Project">
+ <description>
+ Import a file from the local file system into the workspace.
+ </description>
+ </wizard>
+ </extension>
</plugin>
Modified: trunk/applications/jason-eclipse-plugin/src/net/sourceforge/jasonide/core/MAS2JHandler.java
===================================================================
--- trunk/applications/jason-eclipse-plugin/src/net/sourceforge/jasonide/core/MAS2JHandler.java 2008-03-18 20:12:54 UTC (rev 1162)
+++ trunk/applications/jason-eclipse-plugin/src/net/sourceforge/jasonide/core/MAS2JHandler.java 2008-03-18 20:29:50 UTC (rev 1163)
@@ -10,6 +10,7 @@
import java.io.FileNotFoundException;
import java.io.FileReader;
import java.io.FileWriter;
+import java.io.FilenameFilter;
import java.io.IOException;
import java.util.ArrayList;
import java.util.Iterator;
@@ -109,8 +110,38 @@
/**
* Gets the contents of the mas2j file.
*/
- public static String getMas2JFileName(IProject project) throws FileNotFoundException {
- String pathToMas2JFile = project.getLocation().toString() + File.separator + project.getName() + MAS2J_EXT;
+ public static String getMas2JFilePath(String projectDir) throws FileNotFoundException {
+ String pathToMas2JFile = null;
+ File d = new File(projectDir);
+ // list only dirs and *.mas2j
+ File[] files = d.listFiles(
+ new FilenameFilter() {
+ public boolean accept(File dir, String name) {
+ File f = new File(dir, name);
+ if (f.isDirectory()) {
+ return true;
+ }
+ else if (name.toLowerCase().endsWith("mas2j")){
+ return true;
+ }
+ return false;
+ }
+ }
+ );
+ for (int i = 0; i < files.length; i++) {
+ File f = files[i];
+ if (f.isDirectory()) {
+ pathToMas2JFile = getMas2JFilePath(f.getAbsolutePath());
+ if (pathToMas2JFile != null) {
+ break;
+ }
+ }
+ else {
+ return f.getAbsolutePath();
+ }
+ }
+
+
return pathToMas2JFile;
}
@@ -156,7 +187,7 @@
*/
public static String persistMas2JFile(IProject project, String contents) throws JasonPluginException {
try {
- String fileName = getMas2JFileName(project);
+ String fileName = getMas2JFilePath(project.getLocation().toString());
writeTextInFile(fileName, contents);
return fileName;
Modified: trunk/applications/jason-eclipse-plugin/src/net/sourceforge/jasonide/core/PluginTemplates.java
===================================================================
--- trunk/applications/jason-eclipse-plugin/src/net/sourceforge/jasonide/core/PluginTemplates.java 2008-03-18 20:12:54 UTC (rev 1162)
+++ trunk/applications/jason-eclipse-plugin/src/net/sourceforge/jasonide/core/PluginTemplates.java 2008-03-18 20:29:50 UTC (rev 1163)
@@ -28,7 +28,7 @@
public static final String JASON_BUILDER_LAUNCHER = "JasonBuilder.launch";
- public static String getProjectPropertiesContents() {
+ public static String getProjectClasspathContents() {
return
"<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n" +
"<classpath>\n" +
Added: trunk/applications/jason-eclipse-plugin/src/net/sourceforge/jasonide/core/ProjectCreation.java
===================================================================
--- trunk/applications/jason-eclipse-plugin/src/net/sourceforge/jasonide/core/ProjectCreation.java (rev 0)
+++ trunk/applications/jason-eclipse-plugin/src/net/sourceforge/jasonide/core/ProjectCreation.java 2008-03-18 20:29:50 UTC (rev 1163)
@@ -0,0 +1,417 @@
+package net.sourceforge.jasonide.core;
+
+import jason.jeditplugin.Config;
+import jason.mas2j.AgentParameters;
+import jason.mas2j.ClassParameters;
+import jason.mas2j.MAS2JProject;
+
+import java.io.BufferedInputStream;
+import java.io.File;
+import java.io.FileInputStream;
+import java.io.FileNotFoundException;
+import java.io.FileOutputStream;
+import java.io.FileWriter;
+import java.io.IOException;
+import java.util.Enumeration;
+import java.util.Formatter;
+import java.util.Hashtable;
+import java.util.Scanner;
+import java.util.zip.ZipEntry;
+import java.util.zip.ZipFile;
+import java.util.zip.ZipInputStream;
+
+import org.eclipse.core.resources.ICommand;
+import org.eclipse.core.resources.IProject;
+import org.eclipse.core.resources.IProjectDescription;
+import org.eclipse.core.runtime.CoreException;
+import org.eclipse.core.runtime.IProgressMonitor;
+import org.eclipse.debug.core.DebugPlugin;
+import org.eclipse.debug.core.ILaunchConfiguration;
+import org.eclipse.debug.core.ILaunchConfigurationType;
+import org.eclipse.debug.core.ILaunchConfigurationWorkingCopy;
+import org.eclipse.debug.core.ILaunchManager;
+import org.eclipse.jdt.launching.IJavaLaunchConfigurationConstants;
+import org.eclipse.jface.dialogs.MessageDialog;
+import org.eclipse.swt.widgets.Shell;
+
+public class ProjectCreation {
+
+ private Shell shell;
+
+ public ProjectCreation(Shell shell) {
+ this.shell = shell;
+ }
+
+ public Shell getShell() {
+ return this.shell;
+ }
+
+ /**
+ * Creates the empty directories for the new Jason project.
+ */
+ public void createProjectDirs(String projectRootDir) {
+ new File(projectRootDir + File.separator + "src").mkdir();
+ new File(projectRootDir + File.separator + "src" + File.separator + "java").mkdir();
+ new File(projectRootDir + File.separator + "src" + File.separator + "asl").mkdir();
+ new File(projectRootDir + File.separator + "bin").mkdir();
+ new File(projectRootDir + File.separator + "bin" + File.separator + "classes").mkdir();
+ }
+
+ /**
+ * Creates the .classpath file for Jason Project.
+ */
+ public void createClassPathFile(String projectRootDir) {
+ String classPathContent = PluginTemplates.getProjectClasspathContents();
+
+ String jasonJarInProject = Config.get().getJasonJar();
+ classPathContent = new Formatter().format(classPathContent, new Object[] {jasonJarInProject}).toString();
+
+ try {
+ FileWriter fw = new FileWriter(new File(projectRootDir + File.separator + ".classpath"));
+ fw.write(classPathContent);
+ fw.flush();
+ fw.close();
+ } catch (IOException e) {
+ MessageDialog.openError(getShell(), "Error", e.getMessage());
+ }
+ }
+
+ /**
+ * Configures de .project file.
+ * @param project
+ * @param monitor
+ */
+ public void configureProjectEnvironment(IProject project, IProgressMonitor monitor) {
+ try {
+ IProjectDescription pd = project.getDescription();
+
+ ICommand c1 = pd.newCommand();
+ c1.setBuilderName("org.eclipse.jdt.core.javabuilder");
+
+ ICommand c2 = pd.newCommand();
+ c2.setBuilderName("org.eclipse.pde.ManifestBuilder");
+
+ pd.setBuildSpec(new ICommand[] {c1, c2});
+ pd.setNatureIds(new String[] {"org.eclipse.jdt.core.javanature"});
+
+ project.setDescription(pd, monitor);
+ } catch (CoreException e) {
+ MessageDialog.openError(getShell(), "Error", e.getMessage());
+ }
+ }
+
+ /**
+ * Creates the build.properties of the new Jason Project.
+ */
+ public void createBuildPropertiesFile(String projectRootDir) {
+ try {
+ FileWriter fw = new FileWriter(new File(projectRootDir + File.separator + "build.properties"));
+ fw.write(PluginTemplates.getBuildPropertiesContents());
+ fw.flush();
+ fw.close();
+ } catch (IOException e) {
+ MessageDialog.openError(getShell(), "Error", e.getMessage());
+ }
+ }
+
+ /**
+ * Creates the .settings directory for Jason Project.
+ */
+ public void createSettingsDir(String projectRootDir) {
+ String corePrefsContent = PluginTemplates.getProjectCorePrefsContents();
+ String uiPrefsContent = PluginTemplates.getProjectUiPrefsContents();
+
+ try {
+ // make .settings folder
+ new File(projectRootDir + File.separator + ".settings").mkdir();
+
+ // core prefs
+ FileWriter fw = new FileWriter(new File(projectRootDir + File.separator + ".settings" + File.separator + PluginTemplates.CORE_PREFS));
+ fw.write(corePrefsContent);
+ fw.flush();
+ fw.close();
+
+ // ui prefs
+ fw = new FileWriter(new File(projectRootDir + File.separator + ".settings" + File.separator + PluginTemplates.UI_PREFS));
+ fw.write(uiPrefsContent);
+ fw.flush();
+ fw.close();
+ } catch (IOException e) {
+ MessageDialog.openError(getShell(), "Error", e.getMessage());
+ }
+ }
+
+ /**
+ * Creates the Java based Environment.
+ * @param projectRootDir
+ * @param envClassName
+ * @param projectName
+ */
+ public void createEnvironmentClass(String dirRoot, String envClassName, String projectName) {
+ try {
+ // replace "." because it's special symbol in regular expressions.
+ envClassName = envClassName.replace(".", "&");
+
+ String[] items = envClassName.split("&");
+ String className = null;
+ String actualPackage = dirRoot + File.separator + "src" + File.separator + "java";
+ String packages = "";
+
+ if (items.length > 0) {
+ className = items[items.length-1];
+
+ for (int i = 0; i < items.length-1; i++) {
+ File f = new File(actualPackage + File.separator + items[i]);
+ f.mkdir();
+ actualPackage = actualPackage + File.separator + items[i];
+
+ if (packages.length() != 0) {
+ packages = packages.concat(".");
+ }
+ packages = packages.concat(items[i]);
+ }
+ }
+ else {
+ className = "src" + File.separator + "java" + File.separator + envClassName;
+ }
+
+ // is Java code then must be placed in the source Java folder of the project.
+ actualPackage += File.separator;
+
+ File f = new File(actualPackage + File.separator + className + ".java");
+ f.createNewFile();
+
+ String jasonHome = JasonPluginConstants.JASON_HOME;
+ String envTempl = jasonHome +
+ File.separator +
+ PluginTemplates.TEMPLATE_DIR +
+ File.separator +
+ PluginTemplates.ENVIRONMENT;
+
+ StringBuffer buffer = new StringBuffer();
+ Scanner s = new Scanner(new File(envTempl));
+ while (s.hasNextLine()) {
+ buffer.append(s.nextLine().concat("\r\n"));
+ }
+
+ String templateContent = buffer.toString();
+
+ // contains package(s)
+ if (packages.length() != 0) {
+ templateContent = "package ".concat(packages).concat(";\r\n\r\n").concat(templateContent);
+ }
+
+ templateContent = templateContent.replace("<PROJECT_NAME>", projectName);
+ templateContent = templateContent.replace("<ENV_NAME>", className);
+
+ FileWriter fw = new FileWriter(f);
+ fw.write(templateContent);
+ fw.flush();
+ fw.close();
+ } catch (IOException e) {
+ MessageDialog.openError(getShell(), "Error", e.getMessage());
+ }
+ }
+
+ /**
+ * Creates a sample agent named sample.asl.
+ * @param projectRootDir
+ */
+ public void createSampleAgentFile(String projectRootDir, String projectName) {
+ try {
+ File f = new File(projectRootDir + File.separator + JasonPluginConstants.AGENT_DEFAULT_REPOS + File.separator + "sample.asl");
+ f.createNewFile();
+
+ String jasonHome = JasonPluginConstants.JASON_HOME;
+ String envTempl = jasonHome +
+ File.separator +
+ PluginTemplates.TEMPLATE_DIR +
+ File.separator +
+ PluginTemplates.AGENT;
+
+ StringBuffer buffer = new StringBuffer();
+ Scanner s = new Scanner(new File(envTempl));
+ while (s.hasNextLine()) {
+ buffer.append(s.nextLine().concat("\r\n"));
+ }
+
+ String templateContent = buffer.toString();
+
+ templateContent = templateContent.replace("<AG_NAME>", "sample");
+ templateContent = templateContent.replace("<PROJECT_NAME>", projectName);
+
+ FileWriter fw = new FileWriter(f);
+ fw.write(templateContent);
+ fw.flush();
+ fw.close();
+ } catch (IOException e) {
+ MessageDialog.openError(getShell(), "Error", e.getMessage());
+ }
+ }
+
+ /**
+ * Creates the Mas2J file. This file represents a Jason project.
+ * @param projectRootDir
+ * @param projectName
+ * @param infrastructure
+ */
+ public void createMas2JFile(String projectRootDir, String projectName, String infrastructure, String envClassName) {
+ MAS2JProject mas2jProject = new MAS2JProject();
+ mas2jProject.setSocName(projectName.toLowerCase());
+ mas2jProject.setInfrastructure(new ClassParameters(infrastructure));
+ mas2jProject.addSourcePath(JasonPluginConstants.AGENT_DEFAULT_REPOS_MAS2J);
+
+ AgentParameters ag = new AgentParameters();
+ ag.name = JasonPluginConstants.SAMPLE_AGENT_NAME;
+ //ag.setupDefault();
+ mas2jProject.addAgent(ag);
+ mas2jProject.setupDefault();
+
+ if (envClassName.length() > 0) {
+ mas2jProject.setEnvClass(new ClassParameters(envClassName));
+ }
+
+ try {
+ File f = new File(projectRootDir + File.separator + projectName + MAS2JHandler.MAS2J_EXT);
+ f.createNewFile();
+
+ FileWriter fw = new FileWriter(f);
+ fw.write(MAS2JHandler.mas2jProjectToString(mas2jProject));
+ fw.flush();
+ fw.close();
+ } catch (IOException e) {
+ MessageDialog.openError(getShell(), "Error", e.getMessage());
+ }
+ }
+
+ /**
+ * Creates the Launcher for the MAS Project.
+ * @param projectRootDir
+ * @param projectName
+ * @param newProject
+ * @param debug
+ */
+ public void createProjectLaunchConfiguration(String projectRootDir, String projectName, String mas2jFile, IProject newProject, boolean debug) {
+ try {
+ if (mas2jFile == null) {
+ mas2jFile = projectName + MAS2JHandler.MAS2J_EXT;
+ }
+
+ String mas2jFileName = "\"" + projectRootDir + File.separator + mas2jFile + "\"";
+ String launcherConfigName;
+ String secondParameter;
+ String supportsMode;
+ if (debug) {
+ launcherConfigName = "Debug MAS - " + projectName;
+ secondParameter = "debug";
+ supportsMode = ILaunchManager.DEBUG_MODE;
+ }
+ else {
+ launcherConfigName = "Run MAS - " + projectName;
+ secondParameter = "run";
+ supportsMode = ILaunchManager.RUN_MODE;
+ }
+
+ ILaunchManager manager = DebugPlugin.getDefault().getLaunchManager();
+ ILaunchConfigurationType type = manager.getLaunchConfigurationType(IJavaLaunchConfigurationConstants.ID_JAVA_APPLICATION);
+ ILaunchConfiguration[] configurations = manager.getLaunchConfigurations(type);
+ for (int i = 0; i < configurations.length; i++) {
+ ILaunchConfiguration configuration = configurations[i];
+ if (configuration.getName().equals(launcherConfigName)) {
+ configuration.delete();
+ break;
+ }
+ }
+
+ ILaunchConfigurationWorkingCopy workingCopy = type.newInstance(null, launcherConfigName);
+ workingCopy.setAttribute(IJavaLaunchConfigurationConstants.ATTR_PROJECT_NAME, projectName);
+ workingCopy.setAttribute(IJavaLaunchConfigurationConstants.ATTR_MAIN_TYPE_NAME, "jason.mas2j.parser.mas2j");
+ workingCopy.setAttribute(IJavaLaunchConfigurationConstants.ATTR_PROGRAM_ARGUMENTS, mas2jFileName + " " + secondParameter);
+ workingCopy.supportsMode(supportsMode);
+
+ /*ILaunchConfiguration config = */
+ workingCopy.doSave();
+ } catch (CoreException e) {
+ MessageDialog.openError(getShell(), "Error", e.getMessage());
+ }
+ }
+
+ /**
+ * @return Mas2J filename.
+ */
+ public String importResources(String archiveFileName, String projectRootDir) throws IOException, FileNotFoundException {
+ Hashtable htSizes = new Hashtable();
+
+ // extracts just sizes only.
+ ZipFile zf=new ZipFile(archiveFileName);
+ Enumeration e=zf.entries();
+ while (e.hasMoreElements()) {
+ ZipEntry ze=(ZipEntry)e.nextElement();
+ htSizes.put(ze.getName(),new Integer((int)ze.getSize()));
+ }
+ zf.close();
+
+ String mas2jFileName = null;
+
+ FileInputStream fis = new FileInputStream(archiveFileName);
+ BufferedInputStream bis=new BufferedInputStream(fis);
+ ZipInputStream zis=new ZipInputStream(bis);
+ ZipEntry ze=null;
+ while ((ze=zis.getNextEntry())!=null) {
+ if (ze.getName().endsWith(MAS2JHandler.MAS2J_EXT)) {
+ String[] mas2jFileNameParts = ze.getName().split("/");
+ mas2jFileName = mas2jFileNameParts[mas2jFileNameParts.length-1];
+ }
+
+ if ((!projectRootDir.endsWith("/")) || (!ze.getName().startsWith("/"))) {
+ projectRootDir = projectRootDir.concat("/");
+ }
+
+ File newFile = new File(projectRootDir.concat(ze.getName()));
+
+ if (ze.isDirectory()) {
+ //make dir
+ newFile.mkdir();
+ }
+ else { // is a file
+ int size=(int)ze.getSize();
+ // -1 means unknown size.
+ if (size==-1) {
+ size=((Integer)htSizes.get(ze.getName())).intValue();
+ }
+ byte[] b=new byte[(int)size];
+ int rb=0;
+ int chunk=0;
+ while (((int)size - rb) > 0) {
+ chunk = zis.read(b,rb,(int)size - rb);
+ if (chunk==-1) {
+ break;
+ }
+ rb+=chunk;
+ }
+
+ // write contents in a file
+ new FileOutputStream(newFile).write(b);
+ }
+ }
+
+ return mas2jFileName;
+ }
+
+ /**
+ * @return Mas2J filename.
+ */
+ public String getMas2jFileNameInArchiveFile(String archiveFileName) throws IOException, FileNotFoundException {
+ FileInputStream fis = new FileInputStream(archiveFileName);
+ BufferedInputStream bis=new BufferedInputStream(fis);
+ ZipInputStream zis=new ZipInputStream(bis);
+ ZipEntry ze=null;
+ while ((ze=zis.getNextEntry())!=null) {
+ if (ze.getName().endsWith(MAS2JHandler.MAS2J_EXT)) {
+ String[] mas2jFileNameParts = ze.getName().split("/");
+ return mas2jFileNameParts[mas2jFileNameParts.length-1];
+ }
+ }
+ return "";
+ }
+}
Modified: trunk/applications/jason-eclipse-plugin/src/net/sourceforge/jasonide/editors/ASLEditor.java
===================================================================
--- trunk/applications/jason-eclipse-plugin/src/net/sourceforge/jasonide/editors/ASLEditor.java 2008-03-18 20:12:54 UTC (rev 1162)
+++ trunk/applications/jason-eclipse-plugin/src/net/sourceforge/jasonide/editors/ASLEditor.java 2008-03-18 20:29:50 UTC (rev 1163)
@@ -1,17 +1,12 @@
package net.sourceforge.jasonide.editors;
import jason.JasonException;
-import jason.mas2j.MAS2JProject;
-import jason.mas2j.parser.ParseException;
import java.io.File;
import java.io.FileNotFoundException;
import java.io.FileReader;
-import java.util.Iterator;
-import java.util.List;
import net.sourceforge.jasonide.Activator;
-import net.sourceforge.jasonide.core.MAS2JHandler;
import net.sourceforge.jasonide.core.PluginMarkerUtils;
import net.sourceforge.jasonide.editors.cbg.ColoringEditor;
@@ -52,38 +47,16 @@
// delete old markers
PluginMarkerUtils.deleteOldMarkers(ifile);
- String projectLocation = iproject.getLocation().toString();
- try {
- String mas2jFileName = MAS2JHandler.getMas2JFileName(iproject);
- MAS2JProject project = MAS2JHandler.parseForRun(mas2jFileName, projectLocation);
-
- List srcPaths = project.getSourcePaths();
-
- // check if agent source file exists in actual sourcepath
- for (Iterator iter = srcPaths.iterator(); iter.hasNext();) {
- String element = (String) iter.next();
- String asFileName = element + File.separator + ifile.getName();
-
- File file = new File(asFileName);
- if (file.exists()) {
- jason.asSyntax.parser.as2j parser = new jason.asSyntax.parser.as2j(new FileReader(file));
- if (parser != null) {
- parser.agent(null);
- }
- break;
- }
+ try {
+ // absolute project location + filePath relative in project (without project name)
+ String asfileName = iproject.getLocation().toString() + getFilePathWithoutProjectName(ifile);
+ jason.asSyntax.parser.as2j parser = new jason.asSyntax.parser.as2j(new FileReader(new File(asfileName)));
+ if (parser != null) {
+ parser.agent(null);
}
} catch (FileNotFoundException e) {
showError(e.getMessage(), e);
- } catch (ParseException e) {
- String msg = e.getMessage();
-
- int lineError = PluginMarkerUtils.getLineNumberFromMsg(msg);
- PluginMarkerUtils.createMarker(ifile, e.getMessage().replace("\r", "").replace("\n", ""),
- lineError,
- PluginMarkerUtils.getCharStart(document.get(), lineError, msg),
- PluginMarkerUtils.getCharEnd(document.get(), lineError, msg));
} catch (JasonException e) {
String msg = "Problems:" + "\n\n" + e.getMessage();
showError(msg, e);
@@ -108,6 +81,22 @@
}
}
+ /**
+ * Extract only the path of the file, excluding the project name.
+ * @param iFile
+ * @return String
+ */
+ private String getFilePathWithoutProjectName(IFile iFile) {
+ String[] parts = iFile.getFullPath().toString().split("/");
+ StringBuilder sb = new StringBuilder();
+ // first is empty and the second is the project name
+ for(int i = 2; i < parts.length; i++) {
+ sb.append("/");
+ sb.append(parts[i]);
+ }
+ return sb.toString();
+ }
+
private void showError(String msg, Throwable e) {
ErrorDialog.openError(
getSite().getShell(),
Modified: trunk/applications/jason-eclipse-plugin/src/net/sourceforge/jasonide/editors/MAS2JEditor.java
===================================================================
--- trunk/applications/jason-eclipse-plugin/src/net/sourceforge/jasonide/editors/MAS2JEditor.java 2008-03-18 20:12:54 UTC (rev 1162)
+++ trunk/applications/jason-eclipse-plugin/src/net/sourceforge/jasonide/editors/MAS2JEditor.java 2008-03-18 20:29:50 UTC (rev 1163)
@@ -165,10 +165,10 @@
PluginMarkerUtils.deleteOldMarkers(ifile);
IProject project = ifile.getProject();
-
String mas2jFilePath = null;
try {
- mas2jFilePath = MAS2JHandler.getMas2JFileName(project);
+ // absolute project location + filePath relative in project (without project name)
+ mas2jFilePath = project.getLocation().toString() + getFilePathWithoutProjectName(ifile);
// compile Mas2J
MAS2JProject mas2Project = MAS2JHandler.parse(mas2jFilePath);
@@ -192,6 +192,22 @@
}
/**
+ * Extract only the path of the file, excluding the project name.
+ * @param iFile
+ * @return String
+ */
+ private String getFilePathWithoutProjectName(IFile iFile) {
+ String[] parts = iFile.getFullPath().toString().split("/");
+ StringBuilder sb = new StringBuilder();
+ // first is empty and the second is the project name
+ for(int i = 2; i < parts.length; i++) {
+ sb.append("/");
+ sb.append(parts[i]);
+ }
+ return sb.toString();
+ }
+
+ /**
* Extracts informations from Mas2JProject object.
* @param masProject
*/
Added: trunk/applications/jason-eclipse-plugin/src/net/sourceforge/jasonide/importWizards/JasonProjectImportWizard.java
===================================================================
--- trunk/applications/jason-eclipse-plugin/src/net/sourceforge/jasonide/importWizards/JasonProjectImportWizard.java (rev 0)
+++ trunk/applications/jason-eclipse-plugin/src/net/sourceforge/jasonide/importWizards/JasonProjectImportWizard.java 2008-03-18 20:29:50 UTC (rev 1163)
@@ -0,0 +1,121 @@
+/*******************************************************************************
+ * Copyright (c) 2006 IBM Corporation and others.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * IBM Corporation - initial API and implementation
+ *******************************************************************************/
+package net.sourceforge.jasonide.importWizards;
+
+import java.lang.reflect.InvocationTargetException;
+
+import net.sourceforge.jasonide.core.ProjectCreation;
+
+import org.eclipse.core.resources.IProject;
+import org.eclipse.core.resources.IWorkspaceRoot;
+import org.eclipse.core.resources.ResourcesPlugin;
+import org.eclipse.core.runtime.IProgressMonitor;
+import org.eclipse.jface.dialogs.MessageDialog;
+import org.eclipse.jface.operation.IRunnableWithProgress;
+import org.eclipse.jface.viewers.IStructuredSelection;
+import org.eclipse.jface.wizard.Wizard;
+import org.eclipse.ui.IImportWizard;
+import org.eclipse.ui.IWorkbench;
+
+public class JasonProjectImportWizard extends Wizard implements IImportWizard {
+
+ private JasonProjectImportWizardPage page;
+ private ProjectCreation projectCreation;
+
+ public JasonProjectImportWizard() {
+ super();
+ projectCreation = new ProjectCreation(getShell());
+ }
+
+ /* (non-Javadoc)
+ * @see org.eclipse.jface.wizard.Wizard#performFinish()
+ */
+ public boolean performFinish() {
+ final String archiveFileName = page.getExternalProjectArchiveFilePath();
+ final String projectName = page.getProjectName();
+
+ IRunnableWithProgress op = new IRunnableWithProgress() {
+ public void run(IProgressMonitor monitor) throws InvocationTargetException {
+ try {
+ doFinish(archiveFileName, projectName, monitor);
+ } catch (Exception e) {
+ throw new InvocationTargetException(e);
+ } finally {
+ monitor.done();
+ }
+ }
+ };
+ try {
+ getContainer().run(true, false, op);
+ } catch (InterruptedException e) {
+ return false;
+ } catch (InvocationTargetException e) {
+ Throwable realException = e.getTargetException();
+ MessageDialog.openError(getShell(), "Error", realException.getMessage());
+ return false;
+ }
+ return true;
+ }
+
+ private void doFinish(String archiveFileName, String projectName, IProgressMonitor monitor) throws Exception {
+ monitor.beginTask("Creating the project " + projectName, 2);
+
+ // create a new Eclipse Jason Project
+ IProject newProject = ResourcesPlugin.getWorkspace().getRoot().getProject(projectName);
+ newProject.create(monitor);
+ String projectRootDir = newProject.getLocation().toString();
+
+ // create the project directories for sources.
+ projectCreation.createProjectDirs(projectRootDir);
+
+ // create the settings directory and core/ui prefs.
+ projectCreation.createSettingsDir(projectRootDir);
+
+ // create .classpath file
+ projectCreation.createClassPathFile(projectRootDir);
+
+ // open project and refesh local.
+ newProject.open(monitor);
+
+ // create the build.properties of the project.
+ projectCreation.createBuildPropertiesFile(projectRootDir);
+
+ // configure the .project file.
+ projectCreation.configureProjectEnvironment(newProject, monitor);
+
+ // import the resources from archive file.
+ String mas2jFile = projectCreation.importResources(archiveFileName, projectRootDir);
+
+ // create the project launchers (Run e Debug).
+ projectCreation.createProjectLaunchConfiguration(projectRootDir, projectName, mas2jFile, newProject, false);
+ projectCreation.createProjectLaunchConfiguration(projectRootDir, projectName, mas2jFile, newProject, true);
+
+ // refresh the project after all these changes.
+ newProject.getWorkspace().getRoot().refreshLocal(IWorkspaceRoot.DEPTH_INFINITE, monitor);
+ monitor.beginTask("Project created in current workspace", 2);
+ }
+
+ /* (non-Javadoc)
+ * @see org.eclipse.ui.IWorkbenchWizard#init(org.eclipse.ui.IWorkbench, org.eclipse.jface.viewers.IStructuredSelection)
+ */
+ public void init(IWorkbench workbench, IStructuredSelection selection) {
+ setWindowTitle("Jason Project Import Wizard");
+ setNeedsProgressMonitor(true);
+ }
+
+ /* (non-Javadoc)
+ * @see org.eclipse.jface.wizard.IWizard#addPages()
+ */
+ public void addPages() {
+ page = new JasonProjectImportWizardPage("Import Jason Project");
+ addPage(page);
+ }
+}
Added: trunk/applications/jason-eclipse-plugin/src/net/sourceforge/jasonide/importWizards/JasonProjectImportWizardPage.java
===================================================================
--- trunk/applications/jason-eclipse-plugin/src/net/sourceforge/jasonide/importWizards/JasonProjectImportWizardPage.java (rev 0)
+++ trunk/applications/jason-eclipse-plugin/src/net/sourceforge/jasonide/importWizards/JasonProjectImportWizardPage.java 2008-03-18 20:29:50 UTC (rev 1163)
@@ -0,0 +1,98 @@
+/*******************************************************************************
+ * Copyright (c) 2006 IBM Corporation and others.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * IBM Corporation - initial API and implementation
+ *******************************************************************************/
+package net.sourceforge.jasonide.importWizards;
+
+import net.sourceforge.jasonide.core.MAS2JHandler;
+import net.sourceforge.jasonide.core.ProjectCreation;
+
+import org.eclipse.jface.wizard.WizardPage;
+import org.eclipse.swt.SWT;
+import org.eclipse.swt.events.SelectionAdapter;
+import org.eclipse.swt.events.SelectionEvent;
+import org.eclipse.swt.layout.GridData;
+import org.eclipse.swt.layout.GridLayout;
+import org.eclipse.swt.widgets.Button;
+import org.eclipse.swt.widgets.Composite;
+import org.eclipse.swt.widgets.FileDialog;
+import org.eclipse.swt.widgets.Label;
+import org.eclipse.swt.widgets.Text;
+
+public class JasonProjectImportWizardPage extends WizardPage {
+
+ private Text externalProjectText;
+ private Text projectNameText;
+
+ public JasonProjectImportWizardPage(String pageName) {
+ super(pageName);
+ setTitle(pageName);
+ setDescription("Import a external Jason project into the workspace");
+ }
+
+ public void createControl(Composite parent) {
+ Composite container = new Composite(parent, SWT.NULL);
+ GridLayout layout = new GridLayout();
+ container.setLayout(layout);
+ layout.numColumns = 3;
+ layout.verticalSpacing = 9;
+
+ Label label = new Label(container, SWT.NULL);
+ label.setText("&Archive file:");
+
+ externalProjectText = new Text(container, SWT.BORDER | SWT.SINGLE);
+ GridData gd = new GridData(GridData.FILL_HORIZONTAL);
+ externalProjectText.setLayoutData(gd);
+
+ Button button = new Button(container, SWT.PUSH);
+ button.setText("Browse...");
+ button.addSelectionListener(new SelectionAdapter() {
+ public void widgetSelected(SelectionEvent e) {
+ handleBrowseExternalProject();
+ }
+ });
+
+ label = new Label(container, SWT.NULL);
+ label.setText("&Project name:");
+
+ projectNameText = new Text(container, SWT.BORDER | SWT.SINGLE);
+ gd = new GridData(GridData.FILL_HORIZONTAL);
+ projectNameText.setLayoutData(gd);
+
+ setControl(container);
+ }
+
+ private void handleBrowseExternalProject() {
+ FileDialog dialog = new FileDialog(getShell(), SWT.OPEN);
+ dialog.setFilterExtensions(new String[] {"*.zip", "*.tar", "*.jar"});
+
+ String result = dialog.open();
+ if (result != null) {
+ externalProjectText.setText(result);
+
+ try {
+ String name = new ProjectCreation(getShell()).getMas2jFileNameInArchiveFile(result);
+ if (name.endsWith(MAS2JHandler.MAS2J_EXT)) {
+ name = name.replace(MAS2JHandler.MAS2J_EXT, "");
+ }
+ projectNameText.setText(name);
+ } catch (Exception e) {
+ e.printStackTrace();
+ }
+ }
+ }
+
+ public String getExternalProjectArchiveFilePath() {
+ return externalProjectText.getText();
+ }
+
+ public String getProjectName() {
+ return projectNameText.getText();
+ }
+}
Modified: trunk/applications/jason-eclipse-plugin/src/net/sourceforge/jasonide/wizards/NewAgentWizard.java
===================================================================
--- trunk/applications/jason-eclipse-plugin/src/net/sourceforge/jasonide/wizards/NewAgentWizard.java 2008-03-18 20:12:54 UTC (rev 1162)
+++ trunk/applications/jason-eclipse-plugin/src/net/sourceforge/jasonide/wizards/NewAgentWizard.java 2008-03-18 20:29:50 UTC (rev 1163)
@@ -161,15 +161,20 @@
try {
// mas2j editor is open? yes: then modify contents of editor, no: then modify contents of file.
if (document == null) {
- // parse the mas2j file project.
- MAS2JProject project2 = MAS2JHandler.parse(MAS2JHandler.getMas2JFileName(file.getProject()));
- AgentParameters ag = new AgentParameters();
- ag.name = file.getName().replace(MAS2JHandler.AS_EXT, ""); // removes the file extension.
- project2.addAgent(ag);
-
- String mas2jContents = MAS2JHandler.mas2jProjectToString(project2);
- MAS2JHandler.persistMas2JFile(file.getProject(), mas2jContents);
+ // get the mas2j file path, if null then mas2j is not located in project directory.
+ String mas2jFilePath = MAS2JHandler.getMas2JFilePath(file.getProject().getLocation().toString());
+ if (mas2jFilePath != null) {
+ // parse the mas2j file project.
+ MAS2JProject project2 = MAS2JHandler.parse(mas2jFilePath);
+
+ AgentParameters ag = new AgentParameters();
+ ag.name = file.getName().replace(MAS2JHandler.AS_EXT, ""); // removes the file extension.
+ project2.addAgent(ag);
+
+ String mas2jContents = MAS2JHandler.mas2jProjectToString(project2);
+ MAS2JHandler.persistMas2JFile(file.getProject(), mas2jContents);
+ }
}
else {
String tempFileName = MAS2JHandler.persistTempMas2JFile(file.getProject(), document.get());
Modified: trunk/applications/jason-eclipse-plugin/src/net/sourceforge/jasonide/wizards/NewEnvironmentWizard.java
===================================================================
--- trunk/applications/jason-eclipse-plugin/src/net/sourceforge/jasonide/wizards/NewEnvironmentWizard.java 2008-03-18 20:12:54 UTC (rev 1162)
+++ trunk/applications/jason-eclipse-plugin/src/net/sourceforge/jasonide/wizards/NewEnvironmentWizard.java 2008-03-18 20:29:50 UTC (rev 1163)
@@ -183,12 +183,17 @@
try {
// mas2j editor is open? yes: then modify contents of editor, no: then modify contents of file.
if (document == null) {
- // parse the mas2j file project.
- MAS2JProject project2 = MAS2JHandler.parse(MAS2JHandler.getMas2JFileName(file.getProject()));
- project2.setEnvClass(new ClassParameters(className));
- String mas2jContents = MAS2JHandler.mas2jProjectToString(project2);
- MAS2JHandler.persistMas2JFile(file.getProject(), mas2jContents);
+ // get the mas2j file path, if null then mas2j is not located in project directory.
+ String mas2jFilePath = MAS2JHandler.getMas2JFilePath(file.getProject().getLocation().toString());
+ if (mas2jFilePath != null) {
+ // parse the mas2j file project.
+ MAS2JProject project2 = MAS2JHandler.parse(mas2jFilePath);
+ project2.setEnvClass(new ClassParameters(className));
+
+ String mas2jContents = MAS2JHandler.mas2jProjectToString(project2);
+ MAS2JHandler.persistMas2JFile(file.getProject(), mas2jContents);
+ }
}
else {
String tempFileName = MAS2JHandler.persistTempMas2JFile(file.getProject(), document.get());
Modified: trunk/applications/jason-eclipse-plugin/src/net/sourceforge/jasonide/wizards/NewEnvironmentWizardPage.java
===================================================================
--- trunk/applications/jason-eclipse-plugin/src/net/sourceforge/jasonide/wizards/NewEnvironmentWizardPage.java 2008-03-18 20:12:54 UTC (rev 1162)
+++ trunk/applications/jason-eclipse-plugin/src/net/sourceforge/jasonide/wizards/NewEnvironmentWizardPage.java 2008-03-18 20:29:50 UTC (rev 1163)
@@ -17,7 +17,6 @@
import org.eclipse.jdt.core.JavaConventions;
import org.eclipse.jdt.core.JavaCore;
import org.eclipse.jdt.core.JavaModelException;
-import org.eclipse.jdt.internal.core.PackageFragment;
import org.eclipse.jdt.ui.JavaUI;
import org.eclipse.jface.dialogs.IDialogPage;
import org.eclipse.jface.viewers.ISelection;
@@ -97,7 +96,7 @@
else if (firstElement instanceof IPackageFragment) {
IPackageFragment pfr = (IPackageFragment)firstElement;
- String[] names = ((PackageFragment)pfr).names; // TODO: fix that
+ String[] names = ((org.eclipse.jdt.internal.core.PackageFragment)pfr).names; // TODO: fix that
if (names.length > 0) {
packageName = names[0];
for (int i = 1; i < names.length; i++) {
@@ -132,7 +131,7 @@
else if (parent instanceof IPackageFragment) {
if (packageName == null) {
//System.out.println("eh pacote: " + parent.getPath().segments()[parent.getPath().segments().length-1]);
- String[] names = ((PackageFragment)parent).names; // TODO: fix that
+ String[] names = ((org.eclipse.jdt.internal.core.PackageFragment)parent).names; // TODO: fix that
if (names.length > 0) {
packageName = names[0];
for (int i = 1; i < names.length; i++) {
@@ -351,6 +350,7 @@
* the container field.
*/
private void handleBrowseSourceFolder() {
+
ContainerSelectionDialog dialog = new ContainerSelectionDialog(
getShell(), ResourcesPlugin.getWorkspace().getRoot(), false,
"Select new file container");
@@ -371,7 +371,7 @@
if (dialog.open() == SelectionDialog.OK) {
Object[] result = dialog.getResult();
if (result.length == 1) {
- String[] names = ((PackageFragment)result[0]).names; // TODO: fix that
+ String[] names = ((org.eclipse.jdt.internal.core.PackageFragment)result[0]).names; // TODO: fix that
if (names.length > 0) {
packageName = names[0];
for (int i = 1; i < names.length; i++) {
Modified: trunk/applications/jason-eclipse-plugin/src/net/sourceforge/jasonide/wizards/NewInternalActionWizardPage.java
===================================================================
--- trunk/applications/jason-eclipse-plugin/src/net/sourceforge/jasonide/wizards/NewInternalActionWizardPage.java 2008-03-18 20:12:54 UTC (rev 1162)
+++ trunk/applications/jason-eclipse-plugin/src/net/sourceforge/jasonide/wizards/NewInternalActionWizardPage.java 2008-03-18 20:29:50 UTC (rev 1163)
@@ -20,7 +20,6 @@
import org.eclipse.jdt.core.JavaConventions;
import org.eclipse.jdt.core.JavaCore;
import org.eclipse.jdt.core.JavaModelException;
-import org.eclipse.jdt.internal.core.PackageFragment;
import org.eclipse.jdt.ui.JavaUI;
import org.eclipse.jface.dialogs.IDialogPage;
import org.eclipse.jface.viewers.ISelection;
@@ -101,7 +100,7 @@
else if (firstElement instanceof IPackageFragment) {
IPackageFragment pfr = (IPackageFragment)firstElement;
- String[] names = ((PackageFragment)pfr).names; // TODO: fix that
+ String[] names = ((org.eclipse.jdt.internal.core.PackageFragment)pfr).names; // TODO: fix that
if (names.length > 0) {
packageName = names[0];
for (int i = 1; i < names.length; i++) {
@@ -136,7 +135,7 @@
else if (parent instanceof IPackageFragment) {
if (packageName == null) {
//System.out.println("eh pacote: " + parent.getPath().segments()[parent.getPath().segments().length-1]);
- String[] names = ((PackageFragment)parent).names; // TODO: fix that
+ String[] names = ((org.eclipse.jdt.internal.core.PackageFragment)parent).names; // TODO: fix that
if (names.length > 0) {
packageName = names[0];
for (int i = 1; i < names.length; i++) {
@@ -364,7 +363,7 @@
if (dialog.open() == SelectionDialog.OK) {
Object[] result = dialog.getResult();
if (result.length == 1) {
- String[] names = ((PackageFragment)result[0]).names; // TODO: fix that
+ String[] names = ((org.eclipse.jdt.internal.core.PackageFragment)result[0]).names; // TODO: fix that
if (names.length > 0) {
packageName = names[0];
for (int i = 1; i < names.length; i++) {
Modified: trunk/applications/jason-eclipse-plugin/src/net/sourceforge/jasonide/wizards/NewJasonProjectWizard.java
===================================================================
--- trunk/applications/jason-eclipse-plugin/src/net/sourceforge/jasonide/wizards/NewJasonProjectWizard.java 2008-03-18 20:12:54 UTC (rev 1162)
+++ trunk/applications/jason-eclipse-plugin/src/net/sourceforge/jasonide/wizards/NewJasonProjectWizard.java 2008-03-18 20:29:50 UTC (rev 1163)
@@ -1,33 +1,13 @@
package net.sourceforge.jasonide.wizards;
-import jason.jeditplugin.Config;
-import jason.mas2j.AgentParameters;
-import jason.mas2j.ClassParameters;
-import jason.mas2j.MAS2JProject;
-
-import java.io.File;
-import java.io.FileWriter;
-import java.io.IOException;
import java.lang.reflect.InvocationTargetException;
-import java.util.Formatter;
-import java.util.Scanner;
-import net.sourceforge.jasonide.core.JasonPluginConstants;
-import net.sourceforge.jasonide.core.PluginTemplates;
-import net.sourceforge.jasonide.core.MAS2JHandler;
+import net.sourceforge.jasonide.core.ProjectCreation;
-import org.eclipse.core.resources.ICommand;
import org.eclipse.core.resources.IProject;
-import org.eclipse.core.resources.IProjectDescription;
import org.eclipse.core.resources.IWorkspaceRoot;
import org.eclipse.core.runtime.CoreException;
import org.eclipse.core.runtime.IProgressMonitor;
-import org.eclipse.debug.core.DebugPlugin;
-import org.eclipse.debug.core.ILaunchConfiguration;
-import org.eclipse.debug.core.ILaunchConfigurationType;
-import org.eclipse.debug.core.ILaunchConfigurationWorkingCopy;
-import org.eclipse.debug.core.ILaunchManager;
-import org.eclipse.jdt.launching.IJavaLaunchConfigurationConstants;
import org.eclipse.jface.dialogs.MessageDialog;
import org.eclipse.jface.operation.IRunnableWithProgress;
import org.eclipse.jface.viewers.ISelection;
@@ -50,6 +30,7 @@
private NewJasonProjectWizardPage page;
private ISelection selection;
+ private ProjectCreation projectCreation;
/**
* Constructor for NewJasonProjectWizard.
@@ -57,7 +38,8 @@
public NewJasonProjectWizard() {
super();
setNeedsProgressMonitor(true);
- setWindowTitle("Jason Project");
+ setWindowTitle("Jason Project");
+ projectCreation = new ProjectCreation(getShell());
}
/**
@@ -107,7 +89,6 @@
* file if missing or just replace its contents, and open
* the editor on the newly created file.
*/
-
private void doFinish(IProject newProject, String envClassName, String infraStructure, IProgressMonitor monitor) throws CoreException {
monitor.beginTask("Creating the project " + newProject.getName(), 2);
@@ -118,35 +99,35 @@
String projectName = newProject.getName();
// create the project directories for sources.
- createProjectDirs(projectRootDir);
+ projectCreation.createProjectDirs(projectRootDir);
// create the settings directory and core/ui prefs.
- createSettingsDir(projectRootDir);
+ projectCreation.createSettingsDir(projectRootDir);
// create .classpath file
- createClassPathFile(projectRootDir);
+ projectCreation.createClassPathFile(projectRootDir);
// contains environment?
if (envClassName.length() > 0) {
- createEnvironmentClass(projectRootDir, envClassName, projectName);
+ projectCreation.createEnvironmentClass(projectRootDir, envClassName, projectName);
}
// create initial files.
- createSampleAgentFile(projectRootDir, projectName);
- createMas2JFile(projectRootDir, projectName, infraStructure, envClassName);
+ projectCreation.createSampleAgentFile(projectRootDir, projectName);
+ projectCreation.createMas2JFile(projectRootDir, projectName, infraStructure, envClassName);
// open project and refesh local.
newProject.open(monitor);
// create the build.properties of the project.
- createBuildPropertiesFile(projectRootDir);
+ projectCreation.createBuildPropertiesFile(projectRootDir);
// configure the .project file.
- configureProjectEnvironment(newProject, monitor);
+ projectCreation.configureProjectEnvironment(newProject, monitor);
// create the project launchers (Run e Debug).
- createProjectLaunchConfiguration(projectRootDir, projectName, newProject, false);
- createProjectLaunchConfiguration(projectRootDir, projectName, newProject, true);
+ projectCreation.createProjectLaunchConfiguration(projectRootDir, projectName, null, newProject, false);
+ projectCreation.createProjectLaunchConfiguration(projectRootDir, projectName, null, newProject, true);
// refresh the project after all these changes.
newProject.getWorkspace().getRoot().refreshLocal(IWorkspaceRoot.DEPTH_INFINITE, monitor);
@@ -155,294 +136,8 @@
MessageDialog.openError(getShell(), "Error", e.getMessage());
}
}
-
- /**
- * Creates the empty directories for the new Jason project.
- */
- private void createProjectDirs(String projectRootDir) {
- new File(projectRootDir + File.separator + "src").mkdir();
- new File(projectRootDir + File.separator + "src" + File.separator + "java").mkdir();
- new File(projectRootDir + File.separator + "src" + File.separator + "asl").mkdir();
- new File(projectRootDir + File.separator + "bin").mkdir();
- new File(projectRootDir + File.separator + "bin" + File.separator + "classes").mkdir();
- }
/**
- * Creates the .classpath file for Jason Project.
- */
- private void createClassPathFile(String projectRootDir) {
- String classPathContent = PluginTemplates.getProjectPropertiesContents();
-
- String jasonJarInProject = Config.get().getJasonJar();
- classPathContent = new Formatter().format(classPathContent, new Object[] {jasonJarInProject}).toString();
-
- try {
- FileWriter fw = new FileWriter(new File(projectRootDir + File.separator + ".classpath"));
- fw.write(classPathContent);
- fw.flush();
- fw.close();
- } catch (IOException e) {
- MessageDialog.openError(getShell(), "Error", e.getMessage());
- }
- }
-
- /**
- * Configures de .project file.
- * @param project
- * @param monitor
- */
- private void configureProjectEnvironment(IProject project, IProgressMonitor monitor) {
- try {
- IProjectDescription pd = project.getDescription();
-
- ICommand c1 = pd.newCommand();
- c1.setBuilderName("org.eclipse.jdt.core.javabuilder");
-
- ICommand c2 = pd.newCommand();
- c2.setBuilderName("org.eclipse.pde.ManifestBuilder");
-
- pd.setBuildSpec(new ICommand[] {c1, c2});
- pd.setNatureIds(new String[] {"org.eclipse.jdt.core.javanature"});
-
- project.setDescription(pd, monitor);
- } catch (CoreException e) {
- MessageDialog.openError(getShell(), "Error", e.getMessage());
- }
- }
-
- /**
- * Creates the build.properties of the new Jason Project.
- */
- private void createBuildPropertiesFile(String projectRootDir) {
- try {
- FileWriter fw = new FileWriter(new File(projectRootDir + File.separator + "build.properties"));
- fw.write(PluginTemplates.getBuildPropertiesContents());
- fw.flush();
- fw.close();
- } catch (IOException e) {
- MessageDialog.openError(getShell(), "Error", e.getMessage());
- }
- }
-
- /**
- * Creates the .settings directory for Jason Project.
- */
- private void createSettingsDir(String projectRootDir) {
- String corePrefsContent = PluginTemplates.getProjectCorePrefsContents();
- String uiPrefsContent = PluginTemplates.getProjectUiPrefsContents();
-
- try {
- // make .settings folder
- new File(projectRootDir + File.separator + ".settings").mkdir();
-
- // core prefs
- FileWriter fw = new FileWriter(new File(projectRootDir + File.separator + ".settings" + File.separator + PluginTemplates.CORE_PREFS));
- fw.write(corePrefsContent);
- fw.flush();
- fw.close();
-
- // ui prefs
- fw = new FileWriter(new File(projectRootDir + File.separator + ".settings" + File.separator + PluginTemplates.UI_PREFS));
- fw.write(uiPrefsContent);
- fw.flush();
- fw.close();
- } catch (IOException e) {
- MessageDialog.openError(getShell(), "Error", e.getMessage());
- }
- }
-
- /**
- * Creates the Java based Environment.
- * @param projectRootDir
- * @param envClassName
- * @param projectName
- */
- private void createEnvironmentClass(String dirRoot, String envClassName, String projectName) {
- try {
- // replace "." because it's special symbol in regular expressions.
- envClassName = envClassName.replace(".", "&");
-
- String[] items = envClassName.split("&");
- String className = null;
- String actualPackage = dirRoot + File.separator + "src" + File.separator + "java";
- String packages = "";
-
- if (items.length > 0) {
- className = items[items.length-1];
-
- for (int i = 0; i < items.length-1; i++) {
- File f = new File(actualPackage + File.separator + items[i]);
- f.mkdir();
- actualPackage = actualPackage + File.separator + items[i];
-
- if (packages.length() != 0) {
- packages = packages.concat(".");
- }
- packages = packages.concat(items[i]);
- }
- }
- else {
- className = "src" + File.separator + "java" + File.separator + envClassName;
- }
-
- // is Java code then must be placed in the source Java folder of the project.
- actualPackage += File.separator;
-
- File f = new File(actualPackage + File.separator + className + ".java");
- f.createNewFile();
-
- String jasonHome = JasonPluginConstants.JASON_HOME;
- String envTempl = jasonHome +
- File.separator +
- PluginTemplates.TEMPLATE_DIR +
- File.separator +
- PluginTemplates.ENVIRONMENT;
-
- StringBuffer buffer = new StringBuffer();
- Scanner s = new Scanner(new File(envTempl));
- while (s.hasNextLine()) {
- buffer.append(s.nextLine().concat("\r\n"));
- }
-
- String templateContent = buffer.toString();
-
- // contains package(s)
- if (packages.length() != 0) {
- templateContent = "package ".concat(packages).concat(";\r\n\r\n").concat(templateContent);
- }
-
- templateContent = templateContent.replace("<PROJECT_NAME>", projectName);
- templateContent = templateContent.replace("<ENV_NAME>", className);
-
- FileWriter fw = new FileWriter(f);
- fw.write(templateContent);
- fw.flush();
- fw.close();
- } catch (IOException e) {
- MessageDialog.openError(getShell(), "Error", e.getMessage());
- }
- }
-
- /**
- * Creates a sample agent named sample.asl.
- * @param projectRootDir
- */
- private void createSampleAgentFile(String projectRootDir, String projectName) {
- try {
- File f = new File(projectRootDir + File.separator + JasonPluginConstants.AGENT_DEFAULT_REPOS + File.separator + "sample.asl");
- f.createNewFile();
-
- String jasonHome = JasonPluginConstants.JASON_HOME;
- String envTempl = jasonHome +
- File.separator +
- PluginTemplates.TEMPLATE_DIR +
- File.separator +
- PluginTemplates.AGENT;
-
- StringBuffer buffer = new StringBuffer();
- Scanner s = new Scanner(new File(envTempl));
- while (s.hasNextLine()) {
- buffer.append(s.nextLine().concat("\r\n"));
- }
-
- String templateContent = buffer.toString();
-
- templateContent = templateContent.replace("<AG_NAME>", "sample");
- templateContent = templateContent.replace("<PROJECT_NAME>", projectName);
-
- FileWriter fw = new FileWriter(f);
- fw.write(templateContent);
- fw.flush();
- fw.close();
- } catch (IOException e) {
- MessageDialog.openError(getShell(), "Error", e.getMessage());
- }
- }
-
- /**
- * Creates the Mas2J file. This file represents a Jason project.
- * @param projectRootDir
- * @param projectName
- * @param infrastructure
- */
- private void createMas2JFile(String projectRootDir, String projectName, String infrastructure, String envClassName) {
- MAS2JProject mas2jProject = new MAS2JProject();
- mas2jProject.setSocName(projectName.toLowerCase());
- mas2jProject.setInfrastructure(new ClassParameters(infrastructure));
- mas2jProject.addSourcePath(JasonPluginConstants.AGENT_DEFAULT_REPOS_MAS2J);
-
- AgentParameters ag = new AgentParameters();
- ag.name = JasonPluginConstants.SAMPLE_AGENT_NAME;
- //ag.setupDefault();
- mas2jProject.addAgent(ag);
- mas2jProject.setupDefault();
-
- if (envClassName.length() > 0) {
- mas2jProject.setEnvClass(new ClassParameters(envClassName));
- }
-
- try {
- File f = new File(projectRootDir + File.separator + projectName + MAS2JHandler.MAS2J_EXT);
- f.createNewFile();
-
- FileWriter fw = new FileWriter(f);
- fw.write(MAS2JHandler.mas2jProjectToString(mas2jProject));
- fw.flush();
- fw.close();
- } catch (IOException e) {
- MessageDialog.openError(getShell(), "Error", e.getMessage());
- }
- }
-
- /**
- * Creates the Launcher for the MAS Project.
- * @param projectRootDir
- * @param projectName
- * @param newProject
- * @param debug
- */
- private void createProjectLaunchConfiguration(String projectRootDir, String projectName, IProject newProject, boolean debug) {
- try {
- String mas2jFileName = projectRootDir + File.separator + projectName + MAS2JHandler.MAS2J_EXT;
- String launcherConfigName;
- String secondParameter;
- String supportsMode;
- if (debug) {
- launcherConfigName = "Debug MAS - " + projectName;
- secondParameter = "debug";
- supportsMode = ILaunchManager.DEBUG_MODE;
- }
- else {
- launcherConfigName = "Run MAS - " + projectName;
- secondParameter = "run";
- supportsMode = ILaunchManager.RUN_MODE;
- }
-
- ILaunchManager manager = DebugPlugin.getDefault().getLaunchManager();
- ILaunchConfigurationType type = manager.getLaunchConfigurationType(IJavaLaunchConfigurationConstants.ID_JAVA_APPLICATION);
- ILaunchConfiguration[] configurations = manager.getLaunchConfigurations(type);
- for (int i = 0; i < configurations.length; i++) {
- ILaunchConfiguration configuration = configurations[i];
- if (configuration.getName().equals(launcherConfigName)) {
- configuration.delete();
- break;
- }
- }
-
- ILaunchConfigurationWorkingCopy workingCopy = type.newInstance(null, launcherConfigName);
- workingCopy.setAttribute(IJavaLaunchConfigurationConstants.ATTR_PROJECT_NAME, projectName);
- workingCopy.setAttribute(IJavaLaunchConfigurationConstants.ATTR_MAIN_TYPE_NAME, "jason.mas2j.parser.mas2j");
- workingCopy.setAttribute(IJavaLaunchConfigurationConstants.ATTR_PROGRAM_ARGUMENTS, mas2jFileName + " " + secondParameter);
- workingCopy.supportsMode(supportsMode);
-
- /*ILaunchConfiguration config = */
- workingCopy.doSave();
- } catch (CoreException e) {
- MessageDialog.openError(getShell(), "Error", e.getMessage());
- }
- }
-
- /**
* We will accept the selection in the workbench to see if
* we can initialize from it.
* @see IWorkbenchWizard#init(IWorkbench, IStructuredSelection)
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|