summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorpelder2006-08-23 18:53:49 (EDT)
committer pelder2006-08-23 18:53:49 (EDT)
commitadb89ec24fcf8f1e1b37a0397235351fa142658b (patch)
tree193ce01eadf4e22dc72e425bcf6bc81abc4636e4
parente2896a50c80f016295cad63dadb0a1a5ff50183d (diff)
downloadorg.eclipse.jet-adb89ec24fcf8f1e1b37a0397235351fa142658b.zip
org.eclipse.jet-adb89ec24fcf8f1e1b37a0397235351fa142658b.tar.gz
org.eclipse.jet-adb89ec24fcf8f1e1b37a0397235351fa142658b.tar.bz2
[132674] Add 'location' attribute to <ws:project> tag.
-rw-r--r--doc/org.eclipse.jet.doc/references/taglibs/workspaceTags/projectTag.html14
-rw-r--r--plugins/org.eclipse.jet/src/org/eclipse/jet/internal/taglib/workspace/ProjectTag.java11
-rw-r--r--plugins/org.eclipse.jet/src/org/eclipse/jet/internal/taglib/workspace/WsProjectAction.java9
-rw-r--r--plugins/org.eclipse.jet/src/org/eclipse/jet/taglib/workspace/ActionsUtil.java83
4 files changed, 87 insertions, 30 deletions
diff --git a/doc/org.eclipse.jet.doc/references/taglibs/workspaceTags/projectTag.html b/doc/org.eclipse.jet.doc/references/taglibs/workspaceTags/projectTag.html
index f6143bf..5f92b09 100644
--- a/doc/org.eclipse.jet.doc/references/taglibs/workspaceTags/projectTag.html
+++ b/doc/org.eclipse.jet.doc/references/taglibs/workspaceTags/projectTag.html
@@ -35,7 +35,7 @@
<TR>
<TD width="10%">full tag</TD>
<TD><SPAN style="font-family: monospace">
- &lt;ws:project name=&quot;<I>value</I>&quot;&gt;<br>
+ &lt;ws:project name=&quot;<I>value</I>&quot; location=&quot;<I>value</I>&quot;&gt;<br>
&nbsp;&nbsp;&nbsp;&nbsp;<I>content to be written</I><BR>
&lt;/ws:project&gt;
</SPAN></TD>
@@ -59,6 +59,18 @@
<TABLE border="1" width="100%">
<TBODY>
<TR>
+ <TH colspan="2" align="left">Optional Attributes</TH></TR>
+ <TR>
+ <TR>
+ <TD width="10%">location</TD>
+ <TD><BR> An optional absolute file-system location for the new project. If not specified, the project is created in a directory under the workspace directory.<BR> </TD>
+ </TR>
+ </TBODY>
+</TABLE>
+<HR>
+<TABLE border="1" width="100%">
+ <TBODY>
+ <TR>
<TH colspan="2" align="left">Example</TH></TR>
<TR>
<TD width="10%"></TD>
diff --git a/plugins/org.eclipse.jet/src/org/eclipse/jet/internal/taglib/workspace/ProjectTag.java b/plugins/org.eclipse.jet/src/org/eclipse/jet/internal/taglib/workspace/ProjectTag.java
index e705339..f990f63 100644
--- a/plugins/org.eclipse.jet/src/org/eclipse/jet/internal/taglib/workspace/ProjectTag.java
+++ b/plugins/org.eclipse.jet/src/org/eclipse/jet/internal/taglib/workspace/ProjectTag.java
@@ -19,7 +19,9 @@ package org.eclipse.jet.internal.taglib.workspace;
import org.eclipse.core.resources.IProject;
+import org.eclipse.core.resources.IProjectDescription;
import org.eclipse.core.resources.ResourcesPlugin;
+import org.eclipse.core.runtime.Path;
import org.eclipse.jet.JET2Context;
import org.eclipse.jet.JET2Writer;
import org.eclipse.jet.taglib.AbstractContainerTag;
@@ -54,6 +56,7 @@ public class ProjectTag extends AbstractContainerTag
public void doBeforeBody(TagInfo td, JET2Context context, JET2Writer out) throws JET2TagException
{
String name = getAttribute(NAME__ATTR);
+ String location = getAttribute("location"); //$NON-NLS-1$
WorkspaceContextExtender wsExtender = new WorkspaceContextExtender(context);
@@ -67,8 +70,14 @@ public class ProjectTag extends AbstractContainerTag
throw new JET2TagException(e.getMessage(), e);
}
+ final IProjectDescription projectDescription = ResourcesPlugin.getWorkspace().newProjectDescription(name);
+ if(location != null) {
+
+ projectDescription.setLocation(new Path(location));
+
+ }
TransformContextExtender tce = new TransformContextExtender(context);
- wsExtender.addAction(new WsProjectAction(context, tce.getTemplatePath(), td, project));
+ wsExtender.addAction(new WsProjectAction(context, tce.getTemplatePath(), td, project, projectDescription));
wsExtender.pushContainer(project);
containerPushed = true;
diff --git a/plugins/org.eclipse.jet/src/org/eclipse/jet/internal/taglib/workspace/WsProjectAction.java b/plugins/org.eclipse.jet/src/org/eclipse/jet/internal/taglib/workspace/WsProjectAction.java
index e8907f1..e780edd 100644
--- a/plugins/org.eclipse.jet/src/org/eclipse/jet/internal/taglib/workspace/WsProjectAction.java
+++ b/plugins/org.eclipse.jet/src/org/eclipse/jet/internal/taglib/workspace/WsProjectAction.java
@@ -21,6 +21,7 @@ package org.eclipse.jet.internal.taglib.workspace;
import java.text.MessageFormat;
import org.eclipse.core.resources.IProject;
+import org.eclipse.core.resources.IProjectDescription;
import org.eclipse.core.resources.IResource;
import org.eclipse.core.runtime.IProgressMonitor;
import org.eclipse.jet.JET2Context;
@@ -48,18 +49,22 @@ public class WsProjectAction extends AbstractWorkspaceAction implements IWorkspa
private final JET2Context context;
+ private final IProjectDescription description;
+
/**
*
* @param context
* @param templatePath
* @param tagInfo
* @param project
+ * @param description
*/
- public WsProjectAction(JET2Context context, String templatePath, TagInfo tagInfo, IProject project)
+ public WsProjectAction(JET2Context context, String templatePath, TagInfo tagInfo, IProject project, IProjectDescription description)
{
super(tagInfo, templatePath);
this.context = context;
this.project = project;
+ this.description = description;
}
/* (non-Javadoc)
@@ -83,7 +88,7 @@ public class WsProjectAction extends AbstractWorkspaceAction implements IWorkspa
*/
public void performAction(IProgressMonitor monitor) throws JET2TagException
{
- ActionsUtil.createProject(project, monitor);
+ ActionsUtil.createProject(project, description, monitor);
final String createMessage = MessageFormat.format(JET2Messages.WsProjectAction_CreatingProject, new Object []{ project.getName() });
RuntimeLoggerContextExtender.log(context, createMessage, getTagInfo(), getTemplatePath(), RuntimeLoggerContextExtender.INFO_LEVEL);
diff --git a/plugins/org.eclipse.jet/src/org/eclipse/jet/taglib/workspace/ActionsUtil.java b/plugins/org.eclipse.jet/src/org/eclipse/jet/taglib/workspace/ActionsUtil.java
index 037b094..55f4e1d 100644
--- a/plugins/org.eclipse.jet/src/org/eclipse/jet/taglib/workspace/ActionsUtil.java
+++ b/plugins/org.eclipse.jet/src/org/eclipse/jet/taglib/workspace/ActionsUtil.java
@@ -33,6 +33,7 @@ import java.util.Arrays;
import org.eclipse.core.resources.IFile;
import org.eclipse.core.resources.IFolder;
import org.eclipse.core.resources.IProject;
+import org.eclipse.core.resources.IProjectDescription;
import org.eclipse.core.resources.ResourcesPlugin;
import org.eclipse.core.runtime.CoreException;
import org.eclipse.core.runtime.IPath;
@@ -62,6 +63,7 @@ public final class ActionsUtil
* Constant that identifies the UTF-8 character encoding schema.
*/
private static final String CHARSET_UTF_8 = "UTF-8"; //$NON-NLS-1$
+
/**
* Constant that identifies the Byte-Order-Mark for contents encoded with
* the UTF-8 character encoding scheme.
@@ -95,17 +97,23 @@ public final class ActionsUtil
* @see JET2Writer#finalizeContent(Object)
* @see JET2Writer#contentCommitted(Object)
*/
- public static boolean writeTextFileFromWriter(IFile file, boolean replace, String encoding, boolean derived, JET2Writer writer, IProgressMonitor monitor) throws JET2TagException
+ public static boolean writeTextFileFromWriter(
+ IFile file,
+ boolean replace,
+ String encoding,
+ boolean derived,
+ JET2Writer writer,
+ IProgressMonitor monitor) throws JET2TagException
{
writer.finalizeContent(file);
-
- boolean written = writeTextFile(file, replace, encoding, derived, writer.toString(), monitor);
-
+
+ boolean written = writeTextFile(file, replace, encoding, derived, writer.toString(), monitor);
+
if (written)
{
writer.contentCommitted(file);
}
-
+
return written;
}
@@ -120,7 +128,13 @@ public final class ActionsUtil
* @return <code>false</code> <code>replace</code> was <code>true</code> and the file existed; <code>true</code> otherwise.
* @throws JET2TagException if the file cannot be created or written, or the encoding is invalid.
*/
- public static boolean writeTextFile(IFile file, boolean replace, String encoding, boolean derived, final String contents, IProgressMonitor monitor) throws JET2TagException
+ public static boolean writeTextFile(
+ IFile file,
+ boolean replace,
+ String encoding,
+ boolean derived,
+ final String contents,
+ IProgressMonitor monitor) throws JET2TagException
{
try
{
@@ -134,7 +148,7 @@ public final class ActionsUtil
{
return false;
}
-
+
// Step 1: make sure file exists - necessary for proper encoding handling...
if (!file.exists())
{
@@ -175,14 +189,15 @@ public final class ActionsUtil
boolean hasBOM = false;
IContentDescription description = file.getContentDescription();
hasBOM = description != null && description.getProperty(IContentDescription.BYTE_ORDER_MARK) != null;
- if(hasBOM && CHARSET_UTF_8.equals(file.getCharset())) {
+ if (hasBOM && CHARSET_UTF_8.equals(file.getCharset()))
+ {
source = new SequenceInputStream(new ByteArrayInputStream(IContentDescription.BOM_UTF_8), source);
}
monitor.worked(1);
// Step 5: write the contents - we created the file in step 1, so we only need to set its proper contents
file.setContents(source, false, true, new SubProgressMonitor(monitor, 2));
-
+
// RuntimeLoggerContextExtender.log(context, fileMessage, tagInfo, templatePath);
// Step 6: Apply generated file properties...
file.setDerived(derived);
@@ -209,7 +224,7 @@ public final class ActionsUtil
* @param monitor a progress montiro
* @throws JET2TagException if the folder cannot be created
*/
- public static void ensureFolderExists(IFolder folder, IProgressMonitor monitor) throws JET2TagException
+ public static void ensureFolderExists(IFolder folder, IProgressMonitor monitor) throws JET2TagException
{
IProject project = folder.getProject();
IPath relPath = folder.getProjectRelativePath();
@@ -284,7 +299,7 @@ public final class ActionsUtil
{
file.create(input, false, new SubProgressMonitor(monitor, 1));
}
-// RuntimeLoggerContextExtender.log(context, fileMessage, tagInfo, templatePath);
+ // RuntimeLoggerContextExtender.log(context, fileMessage, tagInfo, templatePath);
return true;
}
catch (CoreException e)
@@ -296,8 +311,7 @@ public final class ActionsUtil
monitor.done();
}
}
-
-
+
/**
* Return the contents of the text file at the specified URL.
* @return the file contents
@@ -312,7 +326,7 @@ public final class ActionsUtil
input = url.openStream();
if (encoding != null)
{
- if(encoding.equals(CHARSET_UTF_8))
+ if (encoding.equals(CHARSET_UTF_8))
{
input = stripByteOrderMark(input);
}
@@ -340,7 +354,8 @@ public final class ActionsUtil
finally
{
// ensure stream and reader are closed.
- if(reader != null) {
+ if (reader != null)
+ {
try
{
reader.close();
@@ -350,7 +365,8 @@ public final class ActionsUtil
// ignore
}
}
- if(input != null) {
+ if (input != null)
+ {
try
{
input.close();
@@ -373,7 +389,8 @@ public final class ActionsUtil
private static InputStream stripByteOrderMark(InputStream input) throws IOException
{
// need to look for and remove any Byte-order-mark - a JRE bug means that Java doesn't do this for UTF-8.
- if(!input.markSupported()) {
+ if (!input.markSupported())
+ {
// wrap with a buffered input stream, we'll need to rewind if we don't find the BOM.
input = new BufferedInputStream(input);
}
@@ -387,8 +404,9 @@ public final class ActionsUtil
if (bytes == -1)
throw new IOException();
bytesRead += bytes;
- } while (bytesRead < bomLength);
- if(!Arrays.equals(BOM_UTF_8, bomStore))
+ }
+ while (bytesRead < bomLength);
+ if (!Arrays.equals(BOM_UTF_8, bomStore))
{
input.reset(); // wasn't a bom, rewind to our mark and continue.
}
@@ -450,21 +468,34 @@ public final class ActionsUtil
/**
* Create a new project.
- * @param project
- * @param monitor
- * @throws JET2TagException
+ * @param project the project to create
+ * @param monitor a progress monitor
+ * @throws JET2TagException if an error occurs
*/
public static void createProject(IProject project, IProgressMonitor monitor) throws JET2TagException
{
+ createProject(project, null, monitor);
+ }
+
+ /**
+ * Create a new project.
+ * @param project the project to create
+ * @param description an option project description
+ * @param monitor a progress monitor
+ * @throws JET2TagException if an error occurs
+ * @since 0.7.1
+ */
+ public static void createProject(IProject project, IProjectDescription description, IProgressMonitor monitor) throws JET2TagException
+ {
final String createMessage = MessageFormat.format(JET2Messages.WsProjectAction_CreatingProject, new Object []{ project.getName() });
monitor.beginTask(createMessage, 2); // two ticks: create & open
-
+
try
{
// create...
if (!project.exists())
{
- project.create(new SubProgressMonitor(monitor, 1));
+ project.create(description, new SubProgressMonitor(monitor, 1));
}
else
{
@@ -480,7 +511,7 @@ public final class ActionsUtil
monitor.worked(1);
}
}
- catch(IllegalArgumentException e)
+ catch (IllegalArgumentException e)
{
// create project throws this if the project name is invalid
throw new JET2TagException(e);
@@ -530,7 +561,7 @@ public final class ActionsUtil
public static void checkpointWorkspace(boolean build, IProgressMonitor monitor)
{
ResourcesPlugin.getWorkspace().checkpoint(build);
- if(build)
+ if (build)
{
waitForBuildToComplete(monitor);
}