Author: adamw Date: 2005-10-15 16:48:54 -0400 (Sat, 15 Oct 2005) New Revision: 1394 Added: trunk/forge/portal-extensions/shotoku/shotoku-aop/src/java/org/jboss/shotoku/aop/DirectoryInject.java trunk/forge/portal-extensions/shotoku/shotoku-aop/src/java/org/jboss/shotoku/aop/NodeInject.java trunk/forge/portal-extensions/shotoku/shotoku-aop/src/java/org/jboss/shotoku/aop/ResourceInjectAspect.java trunk/forge/portal-extensions/shotoku/shotoku-test/src/java/org/jboss/shotoku/test/ResourceInjectTest.java Modified: trunk/forge/portal-extensions/binaries/maven-repo-addons/tmate/jars/javasvn-javahl.jar trunk/forge/portal-extensions/binaries/maven-repo-addons/tmate/jars/javasvn.jar trunk/forge/portal-extensions/shotoku/shotoku-aop/src/etc/META-INF/jboss-aop.xml trunk/forge/portal-extensions/shotoku/shotoku-aop/src/java/org/jboss/shotoku/aop/InjectAspect.java trunk/forge/portal-extensions/shotoku/shotoku-base/src/java/org/jboss/shotoku/ContentManager.java trunk/forge/portal-extensions/shotoku/shotoku-svn-service/src/java/org/jboss/shotoku/svn/service/SvnRepository.java trunk/forge/portal-extensions/shotoku/shotoku-svn-service/src/java/org/jboss/shotoku/svn/service/SvnServiceImpl.java trunk/forge/portal-extensions/shotoku/shotoku-svn/src/java/org/jboss/shotoku/svn/SvnHeadNode.java trunk/forge/portal-extensions/shotoku/shotoku-svn/src/java/org/jboss/shotoku/svn/SvnService.java trunk/forge/portal-extensions/shotoku/shotoku-test/project.xml trunk/forge/portal-extensions/shotoku/shotoku-test/src/java/org/jboss/shotoku/test/ShotokuTest.java trunk/forge/portal-extensions/shotoku/shotoku-test/src/java/org/jboss/shotoku/test/SimpleDirectoryTest.java trunk/forge/portal-extensions/shotoku/shotoku-test/src/java/org/jboss/shotoku/test/servlet/ShotokuServlet.java Log: http://jira.jboss.com/jira/browse/JBSHOTOKU-16 - done http://jira.jboss.com/jira/browse/JBSHOTOKU-11 - new tmate svn libraries http://jira.jboss.com/jira/browse/JBSHOTOKU-18 - @NodeInject, @DirectoryInject annotations Modified: trunk/forge/portal-extensions/binaries/maven-repo-addons/tmate/jars/javasvn-javahl.jar =================================================================== (Binary files differ) Modified: trunk/forge/portal-extensions/binaries/maven-repo-addons/tmate/jars/javasvn.jar =================================================================== (Binary files differ) Modified: trunk/forge/portal-extensions/shotoku/shotoku-aop/src/etc/META-INF/jboss-aop.xml =================================================================== --- trunk/forge/portal-extensions/shotoku/shotoku-aop/src/etc/META-INF/jboss-aop.xml 2005-10-15 20:23:35 UTC (rev 1393) +++ trunk/forge/portal-extensions/shotoku/shotoku-aop/src/etc/META-INF/jboss-aop.xml 2005-10-15 20:48:54 UTC (rev 1394) @@ -1,8 +1,3 @@ <aop> - <aspect class="org.jboss.shotoku.aop.InjectAspect" scope="PER_CLASS_JOINPOINT" /> - - <bind pointcut="field(org.jboss.shotoku.ContentManager *->@org.jboss.shotoku.aop.Inject)"> - <advice name="access" aspect="org.jboss.shotoku.aop.InjectAspect"/> - </bind> </aop> Added: trunk/forge/portal-extensions/shotoku/shotoku-aop/src/java/org/jboss/shotoku/aop/DirectoryInject.java =================================================================== --- trunk/forge/portal-extensions/shotoku/shotoku-aop/src/java/org/jboss/shotoku/aop/DirectoryInject.java 2005-10-15 20:23:35 UTC (rev 1393) +++ trunk/forge/portal-extensions/shotoku/shotoku-aop/src/java/org/jboss/shotoku/aop/DirectoryInject.java 2005-10-15 20:48:54 UTC (rev 1394) @@ -0,0 +1,13 @@ +package org.jboss.shotoku.aop; + +import java.lang.annotation.ElementType; +import java.lang.annotation.Retention; +import java.lang.annotation.RetentionPolicy; +import java.lang.annotation.Target; + +@Target({ElementType.FIELD}) +@Retention(RetentionPolicy.RUNTIME) +public @interface DirectoryInject { + String value(); +} + Modified: trunk/forge/portal-extensions/shotoku/shotoku-aop/src/java/org/jboss/shotoku/aop/InjectAspect.java =================================================================== --- trunk/forge/portal-extensions/shotoku/shotoku-aop/src/java/org/jboss/shotoku/aop/InjectAspect.java 2005-10-15 20:23:35 UTC (rev 1393) +++ trunk/forge/portal-extensions/shotoku/shotoku-aop/src/java/org/jboss/shotoku/aop/InjectAspect.java 2005-10-15 20:48:54 UTC (rev 1394) @@ -1,12 +1,19 @@ package org.jboss.shotoku.aop; +import org.jboss.aop.Aspect; +import org.jboss.aop.Bind; +import org.jboss.aop.advice.Scope; import org.jboss.aop.joinpoint.*; import org.jboss.shotoku.ContentManager; +@Aspect(scope=Scope.PER_CLASS_JOINPOINT) public class InjectAspect { + private static final String INJECT_POINTCUT = + "field(org.jboss.shotoku.ContentManager *->@org.jboss.shotoku.aop.Inject)"; + + @Bind(pointcut=INJECT_POINTCUT) public Object access(FieldReadInvocation invocation) throws Throwable { Inject current = invocation.getField().getAnnotation(Inject.class); - if (current == null) throw new RuntimeException("This aspect should be used only with " + "@Inject!"); @@ -15,13 +22,15 @@ if (prefix == null) prefix = ""; String id = current.id(); - if ((id == null) || ("".equals(id))) + + if ((id == null) || ("".equals(id))) { return ContentManager.getContentManager(prefix); - else + } else { return ContentManager.getContentManager(id, prefix); - + } } + @Bind(pointcut=INJECT_POINTCUT) public Object access(FieldWriteInvocation invocation) throws Throwable { throw new RuntimeException("Setting an @Inject-ed variable is illegal"); } Added: trunk/forge/portal-extensions/shotoku/shotoku-aop/src/java/org/jboss/shotoku/aop/NodeInject.java =================================================================== --- trunk/forge/portal-extensions/shotoku/shotoku-aop/src/java/org/jboss/shotoku/aop/NodeInject.java 2005-10-15 20:23:35 UTC (rev 1393) +++ trunk/forge/portal-extensions/shotoku/shotoku-aop/src/java/org/jboss/shotoku/aop/NodeInject.java 2005-10-15 20:48:54 UTC (rev 1394) @@ -0,0 +1,13 @@ +package org.jboss.shotoku.aop; + +import java.lang.annotation.ElementType; +import java.lang.annotation.Retention; +import java.lang.annotation.RetentionPolicy; +import java.lang.annotation.Target; + +@Target({ElementType.FIELD}) +@Retention(RetentionPolicy.RUNTIME) +public @interface NodeInject { + String value(); +} + Added: trunk/forge/portal-extensions/shotoku/shotoku-aop/src/java/org/jboss/shotoku/aop/ResourceInjectAspect.java =================================================================== --- trunk/forge/portal-extensions/shotoku/shotoku-aop/src/java/org/jboss/shotoku/aop/ResourceInjectAspect.java 2005-10-15 20:23:35 UTC (rev 1393) +++ trunk/forge/portal-extensions/shotoku/shotoku-aop/src/java/org/jboss/shotoku/aop/ResourceInjectAspect.java 2005-10-15 20:48:54 UTC (rev 1394) @@ -0,0 +1,54 @@ +package org.jboss.shotoku.aop; + +import org.jboss.aop.Aspect; +import org.jboss.aop.Bind; +import org.jboss.aop.advice.Scope; +import org.jboss.aop.joinpoint.FieldInvocation; +import org.jboss.aop.joinpoint.FieldReadInvocation; +import org.jboss.aop.joinpoint.FieldWriteInvocation; +import org.jboss.shotoku.ContentManager; +@Aspect(scope=Scope.PER_JOINPOINT) +public class ResourceInjectAspect { + @Inject + private ContentManager cm; + + private NodeInject getCurrentNode(FieldInvocation invocation) { + NodeInject current = invocation.getField().getAnnotation(NodeInject.class); + if (current == null) + throw new RuntimeException("This aspect should be used only with " + + "@NodeInject!"); + + return current; + } + + private DirectoryInject getCurrentDirectory(FieldInvocation invocation) { + DirectoryInject current = invocation.getField().getAnnotation(DirectoryInject.class); + if (current == null) + throw new RuntimeException("This aspect should be used only with " + + "@DirectoryInject!"); + + return current; + } + + @Bind(pointcut="field(org.jboss.shotoku.Directory *->@org.jboss.shotoku.aop.DirectoryInject)") + public Object accessDirectory(FieldReadInvocation invocation) throws Throwable { + return cm.getDirectory(getCurrentDirectory(invocation).value()); + } + + @Bind(pointcut="field(org.jboss.shotoku.Node *->@org.jboss.shotoku.aop.NodeInject)") + public Object accessNode(FieldReadInvocation invocation) throws Throwable { + return cm.getNode(getCurrentNode(invocation).value()); + } + + @Bind(pointcut="field(java.lang.String *->@org.jboss.shotoku.aop.NodeInject)") + public Object accessString(FieldReadInvocation invocation) throws Throwable { + return cm.getNode(getCurrentNode(invocation).value()).getContent(); + } + + @Bind(pointcut="field(org.jboss.shotoku.Node *->@org.jboss.shotoku.aop.NodeInject) " + + "OR field(org.jboss.shotoku.Directory *->@org.jboss.shotoku.aop.DirectoryInject) " + + "OR field(java.lang.String *->@org.jboss.shotoku.aop.NodeInject)") + public Object access(FieldWriteInvocation invocation) throws Throwable { + throw new RuntimeException("You cannot set a @NodeInject-ed variable!"); + } +} Modified: trunk/forge/portal-extensions/shotoku/shotoku-base/src/java/org/jboss/shotoku/ContentManager.java =================================================================== --- trunk/forge/portal-extensions/shotoku/shotoku-base/src/java/org/jboss/shotoku/ContentManager.java 2005-10-15 20:23:35 UTC (rev 1393) +++ trunk/forge/portal-extensions/shotoku/shotoku-base/src/java/org/jboss/shotoku/ContentManager.java 2005-10-15 20:48:54 UTC (rev 1394) @@ -171,7 +171,7 @@ try { return (ContentManager) constructor.newInstance(new Object[] { id, prefix }); - } catch (Exception e) { + } catch (Throwable e) { // TODO e.printStackTrace(); return null; Modified: trunk/forge/portal-extensions/shotoku/shotoku-svn/src/java/org/jboss/shotoku/svn/SvnHeadNode.java =================================================================== --- trunk/forge/portal-extensions/shotoku/shotoku-svn/src/java/org/jboss/shotoku/svn/SvnHeadNode.java 2005-10-15 20:23:35 UTC (rev 1393) +++ trunk/forge/portal-extensions/shotoku/shotoku-svn/src/java/org/jboss/shotoku/svn/SvnHeadNode.java 2005-10-15 20:48:54 UTC (rev 1394) @@ -60,7 +60,14 @@ } public long getLastModfication() { - return file.lastModified(); + if (checkForChanges()) + return file.lastModified(); + else + try { + return service.getLastCommited(id, fullPath); + } catch (SvnOperationFailed e) { + throw new RepositoryException(e); + } } protected boolean checkForChanges() { Modified: trunk/forge/portal-extensions/shotoku/shotoku-svn/src/java/org/jboss/shotoku/svn/SvnService.java =================================================================== --- trunk/forge/portal-extensions/shotoku/shotoku-svn/src/java/org/jboss/shotoku/svn/SvnService.java 2005-10-15 20:23:35 UTC (rev 1393) +++ trunk/forge/portal-extensions/shotoku/shotoku-svn/src/java/org/jboss/shotoku/svn/SvnService.java 2005-10-15 20:48:54 UTC (rev 1394) @@ -157,6 +157,19 @@ throws SvnOperationFailed; /** + * Gets a last commited time of the given resource. + * + * @param id + * Id of the repository. + * @param path + * Path to the resource. + * @return Time of last commit of the given resource. + * @throws SvnOperationFailed + */ + public abstract long getLastCommited(String id, String path) + throws SvnOperationFailed; + + /** * <code>SVN_SERVICE_NAME</code> - name under which the svn service is * registered. */ Modified: trunk/forge/portal-extensions/shotoku/shotoku-svn-service/src/java/org/jboss/shotoku/svn/service/SvnRepository.java =================================================================== --- trunk/forge/portal-extensions/shotoku/shotoku-svn-service/src/java/org/jboss/shotoku/svn/service/SvnRepository.java 2005-10-15 20:23:35 UTC (rev 1393) +++ trunk/forge/portal-extensions/shotoku/shotoku-svn-service/src/java/org/jboss/shotoku/svn/service/SvnRepository.java 2005-10-15 20:48:54 UTC (rev 1394) @@ -196,8 +196,6 @@ SVNStatusType currentStatus = ourClientManager.getStatusClient(). doStatus(file, false).getContentsStatus(); - System.out.println(currentStatus.getID()); - // Checking if this item is under version control // already. If not - returning null, as it cannot have // any saved properties. @@ -291,4 +289,15 @@ throw new SvnOperationFailed(e); } } + + public long getLastCommited(String path) + throws SvnOperationFailed { + try { + return ourClientManager.getWCClient().doInfo( + new File(getFileSystemPath(path)), + SVNRevision.WORKING).getCommittedDate().getTime(); + } catch (SVNException e) { + throw new SvnOperationFailed(e); + } + } } Modified: trunk/forge/portal-extensions/shotoku/shotoku-svn-service/src/java/org/jboss/shotoku/svn/service/SvnServiceImpl.java =================================================================== --- trunk/forge/portal-extensions/shotoku/shotoku-svn-service/src/java/org/jboss/shotoku/svn/service/SvnServiceImpl.java 2005-10-15 20:23:35 UTC (rev 1393) +++ trunk/forge/portal-extensions/shotoku/shotoku-svn-service/src/java/org/jboss/shotoku/svn/service/SvnServiceImpl.java 2005-10-15 20:48:54 UTC (rev 1394) @@ -187,4 +187,9 @@ throws SvnOperationFailed { return repositories.get(id).getLogMessage(path); } + + public long getLastCommited(String id, String path) + throws SvnOperationFailed { + return repositories.get(id).getLastCommited(path); + } } Modified: trunk/forge/portal-extensions/shotoku/shotoku-test/project.xml =================================================================== --- trunk/forge/portal-extensions/shotoku/shotoku-test/project.xml 2005-10-15 20:23:35 UTC (rev 1393) +++ trunk/forge/portal-extensions/shotoku/shotoku-test/project.xml 2005-10-15 20:48:54 UTC (rev 1394) @@ -21,27 +21,18 @@ <groupId>shotoku</groupId> <artifactId>shotoku-base</artifactId> <jar>shotoku-base.jar</jar> - <properties> - <war.bundle>true</war.bundle> - </properties> </dependency> <dependency> <groupId>shotoku</groupId> <artifactId>shotoku-aop</artifactId> <jar>shotoku-aop.jar</jar> - <!-- <properties> - <war.bundle>true</war.bundle> - </properties>--> </dependency> <dependency> <groupId>shotoku</groupId> <artifactId>shotoku-svn</artifactId> <jar>shotoku-svn.jar</jar> - <properties> - <war.bundle>true</war.bundle> - </properties> </dependency> <dependency> Added: trunk/forge/portal-extensions/shotoku/shotoku-test/src/java/org/jboss/shotoku/test/ResourceInjectTest.java =================================================================== --- trunk/forge/portal-extensions/shotoku/shotoku-test/src/java/org/jboss/shotoku/test/ResourceInjectTest.java 2005-10-15 20:23:35 UTC (rev 1393) +++ trunk/forge/portal-extensions/shotoku/shotoku-test/src/java/org/jboss/shotoku/test/ResourceInjectTest.java 2005-10-15 20:48:54 UTC (rev 1394) @@ -0,0 +1,43 @@ +package org.jboss.shotoku.test; + +import org.jboss.shotoku.Directory; +import org.jboss.shotoku.Node; +import org.jboss.shotoku.aop.DirectoryInject; +import org.jboss.shotoku.aop.NodeInject; + +public class ResourceInjectTest extends ShotokuTest { + private final static String TEST_NODE = "node-inject-test"; + private final static String TEST_DIR = "dir-inject-test"; + private final static String TEST_TEXT = "text"; + private final static String TEST_LOG = "log"; + + public void setUp() { + Node testNode = cm.getRootDirectory().newNode(TEST_NODE); + testNode.setContent(TEST_TEXT); + testNode.save(TEST_LOG); + + Directory testDir = cm.getRootDirectory().newDirectory(TEST_DIR); + testDir.save(TEST_LOG); + } + + @NodeInject(SHOTOKU_TEST_DIR + "/" + TEST_NODE) + private Node injectedNode; + + @DirectoryInject(SHOTOKU_TEST_DIR + "/" + TEST_DIR) + private Directory injectedDir; + + @NodeInject(SHOTOKU_TEST_DIR + "/" + TEST_NODE) + private String injectedString; + + public void testInjects() { + assertTrue(TEST_TEXT.equals(injectedString)); + assertTrue(TEST_TEXT.equals(injectedNode.getContent())); + assertTrue(TEST_LOG.equals(injectedNode.getLogMessage())); + assertTrue(TEST_LOG.equals(injectedDir.getLogMessage())); + } + + public void tearDown() { + cm.getNode(TEST_NODE).delete(); + cm.getDirectory(TEST_DIR).delete(); + } +} Modified: trunk/forge/portal-extensions/shotoku/shotoku-test/src/java/org/jboss/shotoku/test/ShotokuTest.java =================================================================== --- trunk/forge/portal-extensions/shotoku/shotoku-test/src/java/org/jboss/shotoku/test/ShotokuTest.java 2005-10-15 20:23:35 UTC (rev 1393) +++ trunk/forge/portal-extensions/shotoku/shotoku-test/src/java/org/jboss/shotoku/test/ShotokuTest.java 2005-10-15 20:48:54 UTC (rev 1394) @@ -6,6 +6,7 @@ import junit.framework.TestCase; public abstract class ShotokuTest extends TestCase { - @Inject(prefix="shotoku-test") + protected final static String SHOTOKU_TEST_DIR = "shotoku-test"; + @Inject(prefix=SHOTOKU_TEST_DIR) protected ContentManager cm; } Modified: trunk/forge/portal-extensions/shotoku/shotoku-test/src/java/org/jboss/shotoku/test/SimpleDirectoryTest.java =================================================================== --- trunk/forge/portal-extensions/shotoku/shotoku-test/src/java/org/jboss/shotoku/test/SimpleDirectoryTest.java 2005-10-15 20:23:35 UTC (rev 1393) +++ trunk/forge/portal-extensions/shotoku/shotoku-test/src/java/org/jboss/shotoku/test/SimpleDirectoryTest.java 2005-10-15 20:48:54 UTC (rev 1394) @@ -5,7 +5,7 @@ import org.jboss.shotoku.exceptions.ResourceDoesNotExist; public class SimpleDirectoryTest extends ShotokuTest { - /*public void testAddDeleteDirectory() { + public void testAddDeleteDirectory() { // Creating the directory. Directory newDir = cm.getRootDirectory().newDirectory("new-dir-test"); @@ -25,7 +25,7 @@ assertTrue("test".equals(cm.getNode( "new-dir-test/node2").getContent())); - }*/ + } public void testNames() { // Checking name of the root directory. @@ -46,11 +46,9 @@ assertTrue("new-node".equals(cm.getRootDirectory().getDirectory( "new-dir-test").getNode("new-node").getName())); - // TODO: - /* This tests passes, but causes an exception in the service. That's because - * the directory gets deleted after the tests, but before the node commit. - * A solution would be: locking a path a/b/c would also paths a/b/c/d to be - * locked. */ + /* This tests passes, but causes an exception in the service. That's + * because the directory gets deleted after the tests, but before the + * node commit. */ } @Override Modified: trunk/forge/portal-extensions/shotoku/shotoku-test/src/java/org/jboss/shotoku/test/servlet/ShotokuServlet.java =================================================================== --- trunk/forge/portal-extensions/shotoku/shotoku-test/src/java/org/jboss/shotoku/test/servlet/ShotokuServlet.java 2005-10-15 20:23:35 UTC (rev 1393) +++ trunk/forge/portal-extensions/shotoku/shotoku-test/src/java/org/jboss/shotoku/test/servlet/ShotokuServlet.java 2005-10-15 20:48:54 UTC (rev 1394) @@ -2,9 +2,6 @@ import java.io.IOException; import java.io.PrintWriter; -import java.text.DateFormat; -import java.util.Calendar; -import java.util.List; import javax.servlet.ServletException; import javax.servlet.http.HttpServlet; @@ -14,12 +11,18 @@ import org.jboss.shotoku.ContentManager; import org.jboss.shotoku.Node; import org.jboss.shotoku.aop.Inject; -import org.jboss.shotoku.exceptions.ResourceDoesNotExist; +import org.jboss.shotoku.aop.NodeInject; public class ShotokuServlet extends HttpServlet { @Inject(prefix="shotoku-test") ContentManager test; + @NodeInject("shotoku-test/test") + Node injectedNode; + + @NodeInject("shotoku-test/test") + String injectedString; + @Override protected void service(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { @@ -28,34 +31,14 @@ pw.write("Depends test: " + test + "<br />"); pw.write("<br />"); - ContentManager cm = ContentManager.getContentManager("shotoku-test"); + Node newNode = test.getRootDirectory().newNode("test"); - Node n; + newNode.setContent("zzz"); + newNode.save("Z"); - try { - n = cm.getNode("history-test.txt"); - } catch (ResourceDoesNotExist e) { - System.out.println("Creating ..."); - n = cm.getRootDirectory().newNode("history-test.txt"); - n.save("create"); - } - - String now = DateFormat.getTimeInstance().format(Calendar.getInstance().getTime()); - - n.setContent("Content " + now); - n.save(now); - - List<Node> revs = n.getHistory().getAllRevisions().toList(); - - pw.write("History: <br />"); - pw.write("<br />"); - for (Node h : revs) { - pw.write("Content: " + h.getContent() + "<br />"); - pw.write("Log: " + h.getLogMessage() + "<br />"); - pw.write("Rel rev: " + h.getRevisionNumber() + "<br />"); - pw.write("Last mod: " + h.getLastModfication() + "<br />"); - pw.write("<br />"); - } + pw.write("Content 1:" + newNode.getContent() + "<br />"); + pw.write("Content 2:" + injectedNode.getContent() + "<br />"); + pw.write("Content 3:" + injectedString + "<br />"); } } |