|
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 (InvocationTarg...
[truncated message content] |