Permalink
Browse files

Incorporated the color patch.

Fixed the project creation and competed the removal of the labrepl as a sample project.
  • Loading branch information...
1 parent 11a1ca4 commit 9fca504a0444afba93938e96be4aabb1ce45f049 @EricThorsen committed Sep 10, 2010
@@ -70,7 +70,8 @@
(defn filter-project-file [fo istr name]
(with-open [o (.getOutputStream fo)]
(binding [*out* o]
- (emit (update-project-name (parse istr) name)))))
+ (emit (update-project-name (parse istr) name)))
+ (.flush o)))
(defn filter-project-XML [fo istr name]
(ClojureTemplateWizardIterator/filterProjectXML fo istr name))
@@ -107,20 +108,37 @@
(loop [l (.readLine s)]
(when l
(.println t (transform-string l tag-map))
- (recur (.readLine s)))))))
+ (recur (.readLine s)))))
+ (.flush t)))
+
+(defn transform-file2 [source target-ostr tag-map]
+ (with-open [t (PrintWriter. target-ostr)]
+ (let [s (LineNumberReader. (InputStreamReader. source))]
+ (loop [l (.readLine s)]
+ (when l
+ (.println t (transform-string l tag-map))
+ (recur (.readLine s)))))
+ (.flush t)))
+
(defn file-tags [namespace]
- {"src/default/" (str "src" (root-directory namespace))
- "src/default/core.clj" (str "src" (root-resource namespace) ".clj")
- "src/default/core" (str "src" (root-resource namespace))})
+ {"src/main/clojure/sample/" (str "src/main/clojure" (root-directory namespace))
+ "src/main/clojure/sample/core.clj" (str "src/main/clojure" (root-resource namespace) ".clj")
+ "src/main/clojure/sample" (str "src/main/clojure" (root-resource namespace))
+ "src/test/clojure/sample/" (str "src/test/clojure" (root-directory namespace))
+ "src/test/clojure/sample/core_test.clj" (str "src/test/clojure" (root-resource namespace) ".clj")
+ "src/test/clojure/sample" (str "src/test/clojure" (root-resource namespace))
+ })
(defn package-tags [pkg project-name]
{
;"default." (subs pkg 0 (.lastIndexOf pkg "."))
"default.core" pkg
+ "sample.core" pkg
"ClojureProjectTemplate" project-name
"libs.Clojure.classpath"
- (str "libs." (platform-options/get-clojure-default-lib) ".classpath")})
+ (str "libs." (platform-options/get-clojure-default-lib) ".classpath")
+ })
(def *file-name-map*
{"src/main.clj" "~~CLJ-FILENAME~~.clj"
@@ -193,6 +211,8 @@
{:root project-root :package package-name :istr istr :java-class java-class})
(recur (.getNextEntry istr))))))
+(def --skip-these-- #{".DS_Store"})
+
(defn unzip-project-files
"unzips project template"
[source project-root package-name project-name]
@@ -204,7 +224,7 @@
is-source (.startsWith temp-name "src/")
; Conversion of any file names are done here.
entry-name (or (file-tags temp-name) temp-name)]
- (println entry-name)
+ (println "Project creation " entry-name)
(if (.isDirectory entry)
(FileUtil/createFolder project-root entry-name)
(cond (= "nbproject/project.xml" entry-name)
@@ -218,6 +238,45 @@
(package-tags package-name project-name)))))
(recur (.getNextEntry istr)))))))
+(defn unzip-and-create-project-files
+ "unzips project template"
+ [source project-root package-name project-name]
+ (with-open [istr (ZipInputStream. source)]
+ (let [file-tags (file-tags package-name)]
+; (println file-tags)
+ (loop [entry (.getNextEntry istr) files []]
+ ; (println (.getName entry))
+ (if entry
+ (let [temp-name (.getName entry)
+ is-source (.startsWith temp-name "src/")
+ ; Conversion of any file names are done here.
+ entry-name (or (file-tags temp-name) temp-name)
+ f (File. (str project-root) (str entry-name))]
+ (println "Project creation " entry-name)
+ (if (not (some #(.contains temp-name %) --skip-these--))
+ (do
+ (if (.isDirectory entry)
+ (.mkdirs f)
+ (transform-file2 istr
+ (FileOutputStream. f)
+ (package-tags package-name project-name)))
+ (recur (.getNextEntry istr) (conj files f)))
+ (recur (.getNextEntry istr) files)))
+ files)))))
+
+(defn realize-files-in-nbs [files]
+ (doseq [f files]
+ (if (.isDirectory f)
+ (FileUtil/createFolder f)
+ (FileUtil/createData f)))
+ files)
+
+(defn unzip-create-and-reg-project
+ [source project-root package-name project-name]
+ (let [files (unzip-and-create-project-files
+ source project-root package-name project-name)]
+ (realize-files-in-nbs files)))
+
(defn test-unzip []
(let [z (FileInputStream. "/Users/ericthorsen/new-enclojure/src/enclojure/org.enclojure.ide.nb.clojure_plugin_suite/org.enclojure.ide.nb.editor/src/org/enclojure/ide/nb/editor/ClojureProjectTemplate.zip")
f (when-let [f (File. "/Users/ericthorsen/aaaatesting2")]
@@ -228,6 +287,18 @@
(print "can u see this?")
(unzip-project-files z f p)))
+(def --testzip--
+ "/Users/ericthor/Dev/enclojure-work/enclojure/netbeans/plugins/org-enclojure-plugin/src/main/resources/org/enclojure/ide/templates/project/Clojure-1.2/Clojure-1.2.zip")
+
+(defn test-unzip2 []
+ (let [z (FileInputStream. --testzip--)
+ f (when-let [f (File. "/Users/ericthor/nb-zip")]
+ (.mkdirs f) f)
+ proj-name "MyProject"
+ p "org.mycompany.different.package"]
+ (print "can u see this?")
+ (unzip-and-create-project-files z f p proj-name)))
+
(defn select-location [panel path]
(let [chooser (JFileChooser.)]
(FileUtil/preventFileChooserSymlinkTraversal chooser nil)
@@ -238,4 +309,3 @@
(.setSelectedFile chooser f)))
(if (= JFileChooser/APPROVE_OPTION (.showOpenDialog chooser panel))
(.getSelectedFile chooser))))
-
@@ -51,6 +51,7 @@
import org.xml.sax.InputSource;
import java.util.logging.Level;
import org.enclojure.ide.core.LogAdapter;
+import org.netbeans.api.project.Project;
public class ClojureTemplateWizardIterator implements WizardDescriptor./*Progress*/InstantiatingIterator {
@@ -81,26 +82,31 @@ public static ClojureTemplateWizardIterator createIterator() {
};
}
+
public Set/*<FileObject>*/ instantiate(/*ProgressHandle handle*/) throws IOException {
Set<FileObject> resultSet = new LinkedHashSet<FileObject>();
- File dirF = FileUtil.normalizeFile((File) wiz.getProperty("projdir"));
+// File dirF = FileUtil.normalizeFile((File) wiz.getProperty("projdir"));
+// dirF.mkdirs();
+//
+// FileObject template = Templates.getTemplate(wiz);
+// FileObject dir = FileUtil.toFileObject(dirF);
+ File dirF = (File) wiz.getProperty("projdir");
dirF.mkdirs();
-
FileObject template = Templates.getTemplate(wiz);
- FileObject dir = FileUtil.toFileObject(dirF);
+ //FileObject dir = FileUtil.toFileObject(dirF);
try {
//FF - exclide thie lib/clojure.jar if the user selects another clojure reference
//if( dir.getPath().startsWith(ClojureTemplatePanelVisual.getDefaultClojureReferencePath()))
ClojureTemplatePanelVisual component = (ClojureTemplatePanelVisual)current().getComponent();
unZipFile(template.getInputStream()
- , dir
+ , dirF
,component.packageNameTextField.getText()
,component.getProjectName());
} catch (Exception ex) {
Exceptions.printStackTrace(ex);
}
-
+ FileObject dir = FileUtil.toFileObject(dirF);
// Always open top dir as a project:
resultSet.add(dir);
// Look for nested projects to open as well:
@@ -116,12 +122,16 @@ public static ClojureTemplateWizardIterator createIterator() {
if (parent != null && parent.exists()) {
ProjectChooser.setProjectsFolder(parent);
}
-
- //FF - change the project.properties file
- // String projPropPath = dirF.getAbsolutePath() + File.separator + "nbproject" + File.separator + "project.properties";
- //String cljRef = (String)wiz.getProperty("cljRef");
- //replacePropertyFileValue(projPropPath, "file.reference.clojure.jar", cljRef);
-
+// //ET As a final step, see if saving all fixes the maven problem
+// Project p = ProjectManager.getDefault().findProject(dir);
+// if(p!=null)
+// {
+// ProjectManager.getDefault().saveProject(p);
+// }
+// else
+// {
+//// throw new Exception("Unable to find project");
+// }
return resultSet;
}
@@ -203,11 +213,11 @@ private static void replacePropertyFileValue(String filePath, String key, String
props.store(new FileOutputStream(filePath), "Replaced [key=" + key +"] with [" + value + "].");
}
- private static void unZipFile(InputStream source, FileObject projectRoot,String defPackage,String projectName) throws IOException, Exception {
+ private static void unZipFile(InputStream source, File projectRoot,String defPackage,String projectName) throws IOException, Exception {
try {
//ET Temporary solution to make sure there is a clojure library setup in the users netbeans environment"
//clojure.lang.RT.var("org.enclojure.ide.nb.editor.utils","ensure-clojure-lib").invoke("Clojure-1.0.0");
- clojure.lang.RT.var("org.enclojure.ide.nb.clojure.project.create","unzip-project-files")
+ clojure.lang.RT.var("org.enclojure.ide.nb.clojure.project.create","unzip-create-and-reg-project")
.invoke(source,projectRoot,defPackage,projectName);
} catch (Exception ex) {
LOG.log(Level.FINEST, ex.getMessage());
@@ -222,6 +232,7 @@ public static void writeFile(ZipInputStream str, FileObject fo) throws IOExcepti
try {
FileUtil.copy(str, out);
} finally {
+ out.flush();
out.close();
}
}
@@ -248,6 +259,7 @@ public static void filterProjectXML(FileObject fo, ZipInputStream str, String na
try {
XMLUtil.write(doc, out, "UTF-8");
} finally {
+ out.flush();
out.close();
}
} catch (Exception ex) {
@@ -450,9 +450,6 @@
</file>
</folder>
<folder name="Window">
-<!-- <folder name="ClojureRepl">
- <attr name="SystemFileSystem.localizingBundle" stringvalue="org.netbeans.core.io.ui.Bundle"/>
- <attr name="position" intvalue="1250"/> -->
<file name="org-enclojure-nbmodule-separatorBefore.instance">
<attr name="instanceClass" stringvalue="javax.swing.JSeparator"/>
<attr name="position" intvalue="1775"/>
@@ -461,10 +458,6 @@
<attr name="originalFile" stringvalue="Actions/Clojure/org-enclojure-ide-nb-actions-ConnectExternalReplAction.instance"/>
<attr name="position" intvalue="1776"/>
</file>
-<!-- <file name="org-enclojure-ide-nb-actions-CreateStandaloneReplAction.shadow">
- <attr name="originalFile" stringvalue="Actions/Clojure/org-enclojure-ide-nb-actions-CreateStandaloneReplAction.instance"/>
- <attr name="position" intvalue="1777"/>
- </file>-->
<file name="ReplAction.shadow">
<attr name="originalFile" stringvalue="Actions/Clojure/org-enclojure-ide-nb-editor-ReplAction.instance"/>
<attr name="position" intvalue="1778"/>
@@ -473,7 +466,6 @@
<attr name="instanceClass" stringvalue="javax.swing.JSeparator"/>
<attr name="position" intvalue="1779"/>
</file>
- <!-- </folder> -->
</folder>
<folder name="Edit">
<file name="org-enclojure-nbmodule-separatorBefore.instance">
@@ -605,14 +597,6 @@
<folder name="Templates">
<folder name="Clojure">
<attr name="position" intvalue="300"/>
-<!-- <file name="Clojure Source File" url="ClojureSourceTemplate.clj">
- <attr name="SystemFileSystem.localizingBundle" stringvalue="org.enclojure.ide.nb.editor.Bundle"/>
- <attr name="SystemFileSystem.icon" urlvalue="nbresloc:/org/enclojure/ide/nb/editor/resources/Clojure file 16x16.png"/>
- <attr name="template" boolvalue="true"/>
- <attr name="javax.script.ScriptEngine" stringvalue="freemarker"/>
- <attr name="instantiatingIterator" methodvalue="org.netbeans.spi.project.ui.templates.support.Templates.createSimpleTargetChooser"/>
- </file>
--->
<file name="Clojure File - Basic source (ns def only) " url="nbresloc:/org/enclojure/ide/nb/source/ClojureNamespaceTemplate.clj.template">
<attr name="SystemFileSystem.icon" urlvalue="nbresloc:/org/enclojure/ide/nb/clojure/project/enclojure 16x16.png"/>
<attr name="SystemFileSystem.localizingBundle" stringvalue="org.enclojure.ide.nb.editor.Bundle"/>
@@ -634,7 +618,7 @@
<folder name="Project">
<folder name="Clojure">
<attr name="position" intvalue="104"/>
- <file name="Clojure Application" url="nbresloc:/org/enclojure/ide/templates/project/ClojureProjectTemplate-1.1-distribution.zip">
+<!-- <file name="Clojure Application" url="nbresloc:/org/enclojure/ide/templates/project/ClojureProjectTemplate-1.1-distribution.zip">
<attr name="SystemFileSystem.localizingBundle" stringvalue="org.enclojure.ide.nb.editor.Bundle"/>
<attr name="instantiatingWizardURL"
urlvalue="nbresloc:/org/enclojure/ide/nb/clojure/project/ClojureTemplateDescription.html"/>
@@ -643,7 +627,7 @@
<attr name="template" boolvalue="true"/>
<attr name="SystemFileSystem.icon"
urlvalue="nbresloc:/org/enclojure/ide/nb/clojure/project/enclojure 16x16.png"/>
- </file>
+ </file>-->
<file name="Clojure 1.1 Maven Project" url="nbresloc:/org/enclojure/ide/templates/project/Clojure-1.1/Clojure-1.1.zip">
<attr name="SystemFileSystem.localizingBundle" stringvalue="org.enclojure.ide.nb.editor.Bundle"/>
<attr name="instantiatingWizardURL"
@@ -654,7 +638,7 @@
<attr name="SystemFileSystem.icon"
urlvalue="nbresloc:/org/enclojure/ide/nb/clojure/project/enclojure 16x16.png"/>
</file>
- <file name="Clojure 1.2-SNAPSHOT Maven Project" url="nbresloc:/org/enclojure/ide/templates/project/Clojure-1.2-SNAPSHOT/Clojure-1.2-SNAPSHOT.zip">
+ <file name="Clojure 1.2 Maven Project" url="nbresloc:/org/enclojure/ide/templates/project/Clojure-1.2/Clojure-1.2.zip">
<attr name="SystemFileSystem.localizingBundle" stringvalue="org.enclojure.ide.nb.editor.Bundle"/>
<attr name="instantiatingWizardURL"
urlvalue="nbresloc:/org/enclojure/ide/nb/clojure/project/ClojureTemplateDescription.html"/>
@@ -665,19 +649,19 @@
urlvalue="nbresloc:/org/enclojure/ide/nb/clojure/project/enclojure 16x16.png"/>
</file>
</folder>
- <folder name="Samples">
+<!-- <folder name="Samples">
<folder name="Clojure">
-<!-- <file name="Relevance LabRepl Project" url="nbresloc:/org/enclojure/ide/templates/project/RelevanceLabReplProject.zip">
+ <file name="Relevance LabRepl Project" url="nbresloc:/org/enclojure/ide/templates/project/RelevanceLabReplProject.zip">
<attr name="displayName"
bundlevalue="org.enclojure.ide.project.samples.Bundle#Relevance.LabRepl.name"/>
<attr name="instantiatingIterator"
methodvalue="org.enclojure.ide.project.samples.RelevanceLabReplWizardIterator.createIterator"/>
<attr name="instantiatingWizardURL"
urlvalue="nbresloc:/org/enclojure/ide/project/samples/RelevanceLabReplDescription.html"/>
<attr name="template" boolvalue="true"/>
- </file>-->
+ </file>
</folder>
- </folder>
+ </folder>-->
</folder>
</folder>
@@ -11,38 +11,31 @@
<name>ClojureProjectTemplate</name>
<description>ClojureProjectTemplate</description>
<build>
- <resources>
- <resource>
- <directory>src/main/java</directory>
- <includes>
- <include>**/*.clj</include>
- </includes>
- </resource>
- <resource>
- <directory>src/main/resources</directory>
- </resource>
- </resources>
- <testResources>
- <testResource>
- <directory>src/test/java</directory>
- <includes>
- <include>**/*.clj</include>
- </includes>
- </testResource>
- </testResources>
+ <sourceDirectory>src/main/clojure</sourceDirectory>
+ <testSourceDirectory>src/test/clojure</testSourceDirectory>
+ <resources>
+ <resource>
+ <directory>src/main/clojure</directory>
+ </resource>
+ <resource>
+ <directory>src/main/resources</directory>
+ </resource>
+ </resources>
+ <testResources>
+ <testResource>
+ <directory>src/test/clojure</directory>
+ </testResource>
+ </testResources>
<plugins>
<plugin>
<groupId>com.theoryinpractise</groupId>
<artifactId>clojure-maven-plugin</artifactId>
<version>1.3.2</version>
<configuration>
- <sourceDirectories>
- <sourceDirectory>src/main/java</sourceDirectory>
- </sourceDirectories>
- <testSourceDirectories>
- <testSourceDirectory>src/test/java</testSourceDirectory>
- </testSourceDirectories>
- <clojureOptions>-Xmx1G</clojureOptions>
+ <sourceDirectories>
+ <sourceDirectory>src/main/clojure</sourceDirectory>
+ </sourceDirectories>
+ <clojureOptions>-Xmx1G</clojureOptions>
</configuration>
<executions>
<execution>
Oops, something went wrong.

0 comments on commit 9fca504

Please sign in to comment.