Author: koen.aers(a)jboss.com
Date: 2011-02-23 10:07:02 -0500 (Wed, 23 Feb 2011)
New Revision: 29285
Removed:
trunk/forge/plugins/org.jboss.tools.seam.forge/src/org/jboss/tools/seam/forge/importer/ProjectRecord.java
Modified:
trunk/forge/plugins/org.jboss.tools.seam.forge/META-INF/MANIFEST.MF
trunk/forge/plugins/org.jboss.tools.seam.forge/src/org/jboss/tools/seam/forge/console/CommandRecorder.java
trunk/forge/plugins/org.jboss.tools.seam.forge/src/org/jboss/tools/seam/forge/importer/ProjectImporter.java
Log:
import created project as maven project after new-project command
Modified: trunk/forge/plugins/org.jboss.tools.seam.forge/META-INF/MANIFEST.MF
===================================================================
--- trunk/forge/plugins/org.jboss.tools.seam.forge/META-INF/MANIFEST.MF 2011-02-23
14:12:55 UTC (rev 29284)
+++ trunk/forge/plugins/org.jboss.tools.seam.forge/META-INF/MANIFEST.MF 2011-02-23
15:07:02 UTC (rev 29285)
@@ -5,14 +5,14 @@
Bundle-Version: 1.0.0.qualifier
Require-Bundle: org.eclipse.ui,
org.eclipse.core.runtime,
- org.eclipse.ui.console;bundle-version="3.5.0",
- org.eclipse.jface.text;bundle-version="3.6.1",
- org.eclipse.debug.ui;bundle-version="3.6.1",
- org.eclipse.jdt.launching;bundle-version="3.5.100",
- org.eclipse.core.variables;bundle-version="3.2.400",
- org.eclipse.ui.editors;bundle-version="3.6.1",
- org.eclipse.ui.ide;bundle-version="3.6.1",
- org.maven.ide.eclipse;bundle-version="0.12.0"
+ org.eclipse.ui.console,
+ org.eclipse.jface.text,
+ org.eclipse.debug.ui,
+ org.eclipse.jdt.launching,
+ org.eclipse.ui.editors,
+ org.eclipse.ui.ide,
+ org.maven.ide.eclipse,
+ org.maven.ide.eclipse.maven_embedder;bundle-version="0.12.1"
Bundle-RequiredExecutionEnvironment: JavaSE-1.6
Bundle-ActivationPolicy: lazy
Bundle-Activator: org.jboss.tools.seam.forge.Activator
Modified:
trunk/forge/plugins/org.jboss.tools.seam.forge/src/org/jboss/tools/seam/forge/console/CommandRecorder.java
===================================================================
---
trunk/forge/plugins/org.jboss.tools.seam.forge/src/org/jboss/tools/seam/forge/console/CommandRecorder.java 2011-02-23
14:12:55 UTC (rev 29284)
+++
trunk/forge/plugins/org.jboss.tools.seam.forge/src/org/jboss/tools/seam/forge/console/CommandRecorder.java 2011-02-23
15:07:02 UTC (rev 29285)
@@ -2,6 +2,7 @@
import org.eclipse.jface.text.DocumentEvent;
import org.eclipse.jface.text.IDocumentListener;
+import org.jboss.tools.seam.forge.importer.ProjectImporter;
public class CommandRecorder implements IDocumentListener {
@@ -63,8 +64,30 @@
}
private void postProcessCurrentCommand() {
- System.out.println("post processing current command : " + currentCommand);
- System.out.println("beforePrompt :\n" + beforePrompt);
+ if ("pwd".equals(currentCommand)) {
+ // do nothing
+ } else if ("new-project".equals(currentCommand)) {
+ int index = beforePrompt.lastIndexOf("Wrote ");
+ if (index == -1) return;
+ if (index + 6 > beforePrompt.length()) return;
+ String str = beforePrompt.substring(index + 6);
+ index = str.lastIndexOf("/src/main/resources/META-INF/forge.xml\n***SUCCESS***
Created project [");
+ if (index == -1) return;
+ if (index + 70 > str.length()) return;
+ String projectPath = str.substring(0, index);
+ str = str.substring(index + 70);
+ index = str.indexOf("] in new working directory [");
+ if (index == -1) return;
+ if (index + 28 > str.length()) return;
+ str = str.substring(index + 28);
+ index = str.indexOf("]");
+ if (index == -1) return;
+ String projectDirName = str.substring(0, index);
+ index = projectPath.indexOf(projectDirName);
+ if (index == -1) return;
+ String projectBaseDirPath = projectPath.substring(0, index - 1);
+ new ProjectImporter(projectBaseDirPath, projectDirName).importProject();
+ }
}
}
Modified:
trunk/forge/plugins/org.jboss.tools.seam.forge/src/org/jboss/tools/seam/forge/importer/ProjectImporter.java
===================================================================
---
trunk/forge/plugins/org.jboss.tools.seam.forge/src/org/jboss/tools/seam/forge/importer/ProjectImporter.java 2011-02-23
14:12:55 UTC (rev 29284)
+++
trunk/forge/plugins/org.jboss.tools.seam.forge/src/org/jboss/tools/seam/forge/importer/ProjectImporter.java 2011-02-23
15:07:02 UTC (rev 29285)
@@ -1,26 +1,69 @@
package org.jboss.tools.seam.forge.importer;
import java.io.File;
+import java.util.ArrayList;
+import java.util.Collection;
+import org.apache.maven.model.Model;
+import org.eclipse.core.resources.WorkspaceJob;
+import org.eclipse.core.runtime.CoreException;
+import org.eclipse.core.runtime.IProgressMonitor;
+import org.eclipse.core.runtime.IStatus;
+import org.eclipse.core.runtime.Status;
import org.eclipse.core.runtime.jobs.Job;
import org.maven.ide.eclipse.MavenPlugin;
-import org.maven.ide.eclipse.project.LocalProjectScanner;
+import org.maven.ide.eclipse.core.IMavenConstants;
+import org.maven.ide.eclipse.project.MavenProjectInfo;
+import org.maven.ide.eclipse.project.ProjectImportConfiguration;
public class ProjectImporter {
- LocalProjectScanner localProjectScanner;
+ private String baseDirPath;
+ private String projectName;
- File workspaceRoot;
+ public ProjectImporter(String baseDirPath, String projectName) {
+ this.baseDirPath = baseDirPath;
+ this.projectName = projectName;
+ }
+ public void importProject() {
+ final MavenPlugin mavenPlugin = MavenPlugin.getDefault();
+ Job job = new WorkspaceJob("Importing Forge project") {
+ public IStatus runInWorkspace(IProgressMonitor monitor) {
+ try {
+ mavenPlugin.getProjectConfigurationManager().importProjects(
+ getProjectToImport(),
+ new ProjectImportConfiguration(),
+ monitor);
+ } catch(CoreException ex) {
+ return ex.getStatus();
+ }
+ return Status.OK_STATUS;
+ }
+ };
+ job.setRule(mavenPlugin.getProjectConfigurationManager().getRule());
+ job.schedule();
+ }
- public void importProject() {
-
- MavenPlugin mavenPlugin = MavenPlugin.getDefault();
-
-// Job job = new org.maven.ide.eclipse.internal.project.
-
-// localProjectScanner = new LocalProjectScanner
+ private MavenProjectInfo createMavenProjectInfo() {
+ MavenProjectInfo result = null;
+ try {
+ File projectDir = new File(baseDirPath, projectName);
+ File pomFile = new File(projectDir, IMavenConstants.POM_FILE_NAME);
+ Model model =
MavenPlugin.getDefault().getMavenModelManager().readMavenModel(pomFile);
+ String pomName = projectName + "/" + IMavenConstants.POM_FILE_NAME;
+ result = new MavenProjectInfo(pomName, pomFile, model, null);
+ } catch (CoreException e) {
+
+ }
+ return result;
}
+
+ private Collection<MavenProjectInfo> getProjectToImport() {
+ ArrayList<MavenProjectInfo> result = new ArrayList<MavenProjectInfo>(1);
+ result.add(createMavenProjectInfo());
+ return result;
+ }
}
Deleted:
trunk/forge/plugins/org.jboss.tools.seam.forge/src/org/jboss/tools/seam/forge/importer/ProjectRecord.java
===================================================================
---
trunk/forge/plugins/org.jboss.tools.seam.forge/src/org/jboss/tools/seam/forge/importer/ProjectRecord.java 2011-02-23
14:12:55 UTC (rev 29284)
+++
trunk/forge/plugins/org.jboss.tools.seam.forge/src/org/jboss/tools/seam/forge/importer/ProjectRecord.java 2011-02-23
15:07:02 UTC (rev 29285)
@@ -1,77 +0,0 @@
-package org.jboss.tools.seam.forge.importer;
-
-import java.io.File;
-
-import org.eclipse.core.resources.IProjectDescription;
-import org.eclipse.core.resources.ResourcesPlugin;
-import org.eclipse.core.runtime.CoreException;
-import org.eclipse.core.runtime.IPath;
-import org.eclipse.core.runtime.Path;
-import org.eclipse.core.runtime.Platform;
-
-public class ProjectRecord {
-
- File projectFile;
-
- String projectName;
-
- IProjectDescription description;
-
- /**
- * Create a record for a project based on the info in the file.
- *
- * @param file
- */
- ProjectRecord(File file) {
- projectFile = file;
- setProjectName();
- }
-
- /**
- * Set the name of the project based on the projectFile.
- */
- private void setProjectName() {
- IProjectDescription newDescription = null;
- try {
- IPath path = new Path(projectFile.getPath());
- // if the file is in the default location, use the directory
- // name as the project name
- newDescription = ResourcesPlugin.getWorkspace().loadProjectDescription(path);
-
- if(isDefaultLocation(path)) {
- // projectName = path.segment(path.segmentCount() - 2);
- // newDescription =
ResourcesPlugin.getWorkspace().newProjectDescription(projectName);
- }
- } catch(CoreException e) {
- // no good couldn't get the name
- }
-
- if(newDescription == null) {
- this.description = null;
- projectName = ""; //$NON-NLS-1$
- } else {
- this.description = newDescription;
- projectName = this.description.getName();
- }
- }
-
- /**
- * Returns whether the given project description file path is in the default location
for a project
- *
- * @param path The path to examine
- * @return Whether the given path is the default location for a project
- */
- private boolean isDefaultLocation(IPath path) {
- // The project description file must at least be within the project, which is
within the workspace location
- return path.segmentCount() > 1 &&
path.removeLastSegments(2).toFile().equals(Platform.getLocation().toFile());
- }
-
- /**
- * Get the name of the project
- *
- * @return String
- */
- public String getProjectName() {
- return projectName;
- }
-}
Show replies by date