You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@jackrabbit.apache.org by tr...@apache.org on 2013/08/10 07:53:54 UTC
svn commit: r1512568 [33/39] - in /jackrabbit/commons/filevault/trunk: ./
parent/ vault-cli/ vault-cli/src/ vault-cli/src/main/
vault-cli/src/main/appassembler/ vault-cli/src/main/assembly/
vault-cli/src/main/java/ vault-cli/src/main/java/org/ vault-cl...
Added: jackrabbit/commons/filevault/trunk/vault-diff/src/main/java/org/apache/jackrabbit/vault/util/diff/Hunk3.java
URL: http://svn.apache.org/viewvc/jackrabbit/commons/filevault/trunk/vault-diff/src/main/java/org/apache/jackrabbit/vault/util/diff/Hunk3.java?rev=1512568&view=auto
==============================================================================
--- jackrabbit/commons/filevault/trunk/vault-diff/src/main/java/org/apache/jackrabbit/vault/util/diff/Hunk3.java (added)
+++ jackrabbit/commons/filevault/trunk/vault-diff/src/main/java/org/apache/jackrabbit/vault/util/diff/Hunk3.java Sat Aug 10 05:53:42 2013
@@ -0,0 +1,236 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.jackrabbit.vault.util.diff;
+
+import java.io.IOException;
+
+/**
+ * A hunk3 represents a block of a change from the 3-way diff. it can either be
+ * a modification on the left side (for which {@link #getLeftRange()} is not
+ * <code>null</code>), or a change on the right side (for which
+ * {@link #getRightRange()} is not <code>null</code>. if the left and the right
+ * ranges are <code>null</code> this hunk represents an unmodified block of the
+ * base document. if both ranges are NOT <code>null</code> it represents a
+ * conflicting block.
+ */
+public class Hunk3 {
+
+ /**
+ * the left document marker pattern
+ */
+ public static final String[] MARKER_L = new String[]{"<<<<<<< ", ".mine"};
+
+ /**
+ * the right document marker pattern
+ */
+ public static final String[] MARKER_R = new String[]{">>>>>>> ", ".theirs"};
+
+ /**
+ * the base document marker pattern
+ */
+ public static final String[] MARKER_B = new String[]{"||||||| ", ".base"};
+
+ /**
+ * the separation marker pattern
+ */
+ public static final String[] MARKER_M = new String[]{"=======", ""};
+
+ /**
+ * the base range. never <code>null</code>.
+ */
+ private final Range base;
+
+ /**
+ * the left range
+ */
+ private final Range left;
+
+ /**
+ * the right range
+ */
+ private final Range right;
+
+ /**
+ * the next hunk in this chain
+ */
+ private Hunk3 next;
+
+ /**
+ * Constructs a new hunk and appends it to the previous one.
+ * @param base the base document
+ * @param left the left document
+ * @param right the right document
+ * @param prev the previous hunk
+ */
+ public Hunk3(Range base, Range left, Range right, Hunk3 prev) {
+ this.base = base;
+ this.left = left;
+ this.right = right;
+ if (prev != null) {
+ prev.next = this;
+ }
+ }
+
+ /**
+ * Returns the next hunk in this chain or <code>null</code> of this hunk is
+ * the last one.
+ * @return the next hunk.
+ */
+ public Hunk3 next() {
+ return next;
+ }
+
+ /**
+ * Returns the range of the base document this hunk spans.
+ * @return the base range.
+ */
+ public Range getBaseRange() {
+ return base;
+ }
+
+ /**
+ * Returns the range of the left document this hunk spans.
+ * can be <code>null</code>.
+ * @return the left range.
+ */
+ public Range getLeftRange() {
+ return left;
+ }
+
+ /**
+ * Returns the range of the right document this hunk spans.
+ * can be <code>null</code>.
+ * @return the right range.
+ */
+ public Range getRightRange() {
+ return right;
+ }
+
+ /**
+ * Writes this hunk to a writer. if this hunk represents a conflict it is
+ * included in a merge-like manner using the separators defined above.
+ *
+ * @param out the writer
+ * @param showBase include the block of the base document in case of a
+ * conflict as well.
+ * @throws IOException if a I/O error occurs.
+ */
+ public void write(DiffWriter out, boolean showBase) throws IOException {
+ boolean conflict = left != null && right != null;
+ if (conflict) {
+ out.write(getMarker(MARKER_L, left.doc));
+ out.writeNewLine();
+ } else {
+ showBase = left == null && right == null;
+ }
+
+ if (left != null) {
+ int len = Math.min(left.high, left.doc.getElements().length);
+ for (int i = left.low; i < len; i++) {
+ out.write(left.doc.getElements()[i].getString());
+ }
+ }
+ if (showBase) {
+ if (conflict) {
+ out.write(getMarker(MARKER_B, base.doc));
+ out.writeNewLine();
+ }
+ int len = Math.min(base.high, base.doc.getElements().length);
+ for (int i = base.low; i < len; i++) {
+ out.write(base.doc.getElements()[i].getString());
+ }
+ }
+ if (conflict) {
+ out.write(getMarker(MARKER_M, null));
+ out.writeNewLine();
+ }
+ if (right != null) {
+ int len = Math.min(right.high, right.doc.getElements().length);
+ for (int i = right.low; i < len; i++) {
+ out.write(right.doc.getElements()[i].getString());
+ }
+ }
+ if (conflict) {
+ out.write(getMarker(MARKER_R, right.doc));
+ out.writeNewLine();
+ }
+ }
+
+ /**
+ * generate a debug string
+ * @return a debug string
+ */
+ public String toString() {
+ StringBuffer buf = new StringBuffer();
+ buf.append("@@ =").append(base).append(" -").append(left).append(" +").append(right).append(" @@\n");
+ if (left != null) {
+ for (int i = 0; i < left.len(); i++) {
+ addLineNumbers(buf, i);
+ buf.append("< ");
+ buf.append(left.doc.getElements()[i + left.low]);
+ }
+ }
+ if (base != null) {
+ for (int i = 0; i < base.len(); i++) {
+ addLineNumbers(buf, i);
+ buf.append("= ");
+ buf.append(base.doc.getElements()[i + base.low]);
+ }
+ }
+ if (right != null) {
+ for (int i = 0; i < right.len(); i++) {
+ addLineNumbers(buf, i);
+ buf.append("> ");
+ buf.append(right.doc.getElements()[i + right.low]);
+ }
+ }
+ return buf.toString();
+ }
+
+ /**
+ * adds some line numbers to the string buffer
+ * @param buf the buffer
+ * @param i the index
+ */
+ private void addLineNumbers(StringBuffer buf, int i) {
+ buf.append("(").append(i + base.low);
+ if (left != null) {
+ buf.append(",").append(i + left.low);
+ }
+ if (right != null) {
+ buf.append(",").append(i + right.low);
+ }
+ buf.append(") ");
+ }
+
+ /**
+ * Returns the marker string for the given format and document
+ * @param fmt the marker format
+ * @param doc the document or <code>null</code>.
+ * @return the marker string
+ */
+ public static String getMarker(String[] fmt, Document doc) {
+ StringBuffer buf = new StringBuffer(fmt[0]);
+ if (doc != null && doc.getSource() != null && doc.getSource().getLabel() != null) {
+ buf.append(doc.getSource().getLabel());
+ } else {
+ buf.append(fmt[1]);
+ }
+ return buf.toString();
+ }
+
+}
\ No newline at end of file
Added: jackrabbit/commons/filevault/trunk/vault-diff/src/main/java/org/apache/jackrabbit/vault/util/diff/InlineChangeListener.java
URL: http://svn.apache.org/viewvc/jackrabbit/commons/filevault/trunk/vault-diff/src/main/java/org/apache/jackrabbit/vault/util/diff/InlineChangeListener.java?rev=1512568&view=auto
==============================================================================
--- jackrabbit/commons/filevault/trunk/vault-diff/src/main/java/org/apache/jackrabbit/vault/util/diff/InlineChangeListener.java (added)
+++ jackrabbit/commons/filevault/trunk/vault-diff/src/main/java/org/apache/jackrabbit/vault/util/diff/InlineChangeListener.java Sat Aug 10 05:53:42 2013
@@ -0,0 +1,90 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.jackrabbit.vault.util.diff;
+
+import java.io.PrintWriter;
+
+/**
+ */
+public class InlineChangeListener implements ChangeListener {
+
+ private final PrintWriter out;
+
+ public InlineChangeListener(PrintWriter out) {
+ this.out = out;
+ }
+
+ public void onDocumentsStart(Document left, Document right) {
+ // ignore
+ }
+
+ public void onDocumentsEnd(Document left, Document right) {
+ out.flush();
+ }
+
+ public void onChangeStart(int leftLine, int leftLen, int rightLine, int rightLen) {
+ // ignore
+ }
+
+ public void onChangeEnd() {
+ out.flush();
+ }
+
+ public void onUnmodified(int leftLine, int rightLine, Document.Element text) {
+ out.print(text);
+ }
+
+ public void onDeleted(int leftLine, int rightLine, Document.Element text) {
+ String author = null;
+ if (text instanceof Document.AnnotatedElement) {
+ Document.AnnotatedElement t = (Document.AnnotatedElement) text;
+ if (t.getDocumentSource() instanceof DefaultDocumentSource) {
+ DefaultDocumentSource src = (DefaultDocumentSource) t.getDocumentSource();
+ author = src.getAuthor();
+ }
+ }
+ out.print("<del");
+ if (author != null) {
+ out.print(" title=\"");
+ out.print(author);
+ out.print("\"");
+ }
+ out.print(">");
+ out.print(text);
+ out.print("</del>");
+ }
+
+ public void onInserted(int leftLine, int rightLine, Document.Element text) {
+ String author = null;
+ if (text instanceof Document.AnnotatedElement) {
+ Document.AnnotatedElement t = (Document.AnnotatedElement) text;
+ if (t.getDocumentSource() instanceof DefaultDocumentSource) {
+ DefaultDocumentSource src = (DefaultDocumentSource) t.getDocumentSource();
+ author = src.getAuthor();
+ }
+ }
+ out.print("<ins");
+ if (author != null) {
+ out.print(" title=\"");
+ out.print(author);
+ out.print("\"");
+ }
+ out.print(">");
+ out.print(text);
+ out.print("</ins>");
+ }
+}
Added: jackrabbit/commons/filevault/trunk/vault-diff/src/main/java/org/apache/jackrabbit/vault/util/diff/LineElementsFactory.java
URL: http://svn.apache.org/viewvc/jackrabbit/commons/filevault/trunk/vault-diff/src/main/java/org/apache/jackrabbit/vault/util/diff/LineElementsFactory.java?rev=1512568&view=auto
==============================================================================
--- jackrabbit/commons/filevault/trunk/vault-diff/src/main/java/org/apache/jackrabbit/vault/util/diff/LineElementsFactory.java (added)
+++ jackrabbit/commons/filevault/trunk/vault-diff/src/main/java/org/apache/jackrabbit/vault/util/diff/LineElementsFactory.java Sat Aug 10 05:53:42 2013
@@ -0,0 +1,286 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.jackrabbit.vault.util.diff;
+
+import java.io.FileInputStream;
+import java.io.FileReader;
+import java.io.IOException;
+import java.io.InputStreamReader;
+import java.io.Reader;
+import java.io.StringReader;
+import java.util.ArrayList;
+
+/**
+ * Implements an element factory that creates elements from the lines of an
+ * input text.
+ */
+public class LineElementsFactory implements ElementsFactory {
+
+ /**
+ * the maximum numbers of lines
+ */
+ private static final int MAX_ELEMENTS = 100000;
+
+ /**
+ * the elements
+ */
+ private final Document.Element[] elements;
+
+ /**
+ * private constructor
+ * @param elements the elements
+ */
+ private LineElementsFactory(Document.Element[] elements) {
+ this.elements = elements;
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ public Document.Element[] getElements() {
+ return elements;
+ }
+
+ /**
+ * Create a new line element factory for the given text.
+ * @param source the document source
+ * @param text the text
+ * @param ignoreWs if <code>true</code> white spaces are ignored for the diff
+ * @return the new factory
+ *
+ * todo: create non-annotated variant
+ */
+ public static LineElementsFactory create(DocumentSource source, String text, boolean ignoreWs) {
+ try {
+ Reader reader = new StringReader(text);
+ return create(source, reader, ignoreWs);
+ } catch (IOException e) {
+ throw new IllegalArgumentException(e.toString());
+ }
+ }
+
+ /**
+ * Create a new line element factory for the given source.
+ * @param source the file source
+ * @param ignoreWs if <code>true</code> white spaces are ignored for the diff
+ * @param charset the charset
+ * @return the new factory
+ * @throws IOException if an I/O error occurs
+ *
+ * todo: create non-annotated variant
+ */
+ public static LineElementsFactory create(FileDocumentSource source, boolean ignoreWs, String charset)
+ throws IOException {
+ Reader text = charset == null
+ ? new FileReader(source.getFile())
+ : new InputStreamReader(new FileInputStream(source.getFile()), charset);
+ try {
+ return create(source, text, ignoreWs);
+ } finally {
+ try {
+ text.close();
+ } catch (IOException e) {
+ // ignore
+ }
+ }
+ }
+
+ /**
+ * Create a new line element factory for the given source.
+ * @param source the source
+ * @param text the text
+ * @param ignoreWs if <code>true</code> white spaces are ignored for the diff
+ * @return the new factory
+ * @throws IOException if an I/O error occurs
+ *
+ * todo: create non-annotated variant
+ */
+ public static LineElementsFactory create(DocumentSource source, Reader text, boolean ignoreWs)
+ throws IOException {
+ Document.Element[] elements = getElements(source, text, ignoreWs);
+ return new LineElementsFactory(elements);
+ }
+
+ /**
+ * Read the input and split into elements
+ * @param source the source
+ * @param r the text
+ * @param ignoreWS ignore flag
+ * @return the elements array
+ * @throws IOException if an I/O error occurs
+ */
+ private static Document.Element[] getElements(DocumentSource source, Reader r, boolean ignoreWS)
+ throws IOException {
+ if (r == null) {
+ return new Document.Element[0];
+ }
+ ArrayList lines = new ArrayList();
+ char[] buffer = new char[8192];
+ int start = 0;
+ int pos = 0;
+ int end = r.read(buffer);
+ while (pos < end) {
+ char c = buffer[pos++];
+ if (c == '\n') {
+ String line = new String(buffer, start, pos - start);
+ if (ignoreWS) {
+ lines.add(new LineElementsFactory.IStringElement(source, line));
+ } else {
+ lines.add(new LineElementsFactory.StringElement(source, line));
+ }
+ start = pos;
+ if (lines.size() == MAX_ELEMENTS) {
+ break;
+ }
+ }
+ if (pos == end) {
+ // shift buffer and read more
+ int len = end - start;
+ if (len == buffer.length) {
+ // line very long - double buffer size
+ char[] newBuffer = new char[buffer.length * 2];
+ System.arraycopy(buffer, start, newBuffer, 0, len);
+ buffer = newBuffer;
+ } else if (len > 0) {
+ System.arraycopy(buffer, start, buffer, 0, len);
+ }
+ end = len;
+ start = 0;
+ pos = 0;
+ int read = r.read(buffer, end, buffer.length - end);
+ if (read < 0) {
+ break;
+ }
+ end += read;
+ }
+ }
+
+ // add last line if not terminated by a line feed
+ if (start < end) {
+ String line = new String(buffer, start, end - start);
+ if (ignoreWS) {
+ lines.add(new LineElementsFactory.IStringElement(source, line));
+ } else {
+ lines.add(new LineElementsFactory.StringElement(source, line));
+ }
+ }
+ if (ignoreWS) {
+ return (LineElementsFactory.IStringElement[]) lines.toArray(new LineElementsFactory.IStringElement[lines.size()]);
+ } else {
+ return (LineElementsFactory.StringElement[]) lines.toArray(new LineElementsFactory.StringElement[lines.size()]);
+ }
+ }
+
+ /**
+ * An element that is based on a string
+ * todo: create non-annotated varian
+ */
+ public static class StringElement implements Document.AnnotatedElement {
+
+ private final DocumentSource source;
+
+ private final String string;
+
+ public StringElement(DocumentSource source, String string) {
+ this.source = source;
+ this.string = string;
+ }
+
+ public String getString() {
+ return string;
+ }
+
+ public DocumentSource getDocumentSource() {
+ return source;
+ }
+
+ public int hashCode() {
+ return string.hashCode();
+ }
+
+
+ public String toString() {
+ return string;
+ }
+
+ public boolean equals(Object obj) {
+ if (obj == this) {
+ return true;
+ }
+ if (obj instanceof LineElementsFactory.StringElement) {
+ return ((LineElementsFactory.StringElement) obj).string.equals(string);
+ }
+ return false;
+ }
+ }
+
+ /**
+ * An element that is based on a string but ignores the whitespaces in the
+ * equals method.
+ * todo: create non-annotated varian
+ */
+ public static class IStringElement implements Document.AnnotatedElement {
+
+ private final DocumentSource source;
+
+ private final String string;
+
+ private String stripped;
+
+
+ public DocumentSource getDocumentSource() {
+ return source;
+ }
+
+ public String getString() {
+ return string;
+ }
+
+ public IStringElement(DocumentSource source, String string) {
+ this.source = source;
+ this.string = string;
+ }
+
+ private String getStripped() {
+ if (stripped == null) {
+ StringBuffer buf = new StringBuffer(string.length());
+ for (int i = 0; i < string.length(); i++) {
+ char c = string.charAt(i);
+ if (!Character.isWhitespace(c)) {
+ buf.append(c);
+ }
+ }
+ stripped = buf.toString();
+ }
+ return stripped;
+ }
+
+ public int hashCode() {
+ return getStripped().hashCode();
+ }
+
+ public boolean equals(Object obj) {
+ assert obj instanceof LineElementsFactory.IStringElement;
+ return getStripped().equals(((LineElementsFactory.IStringElement) obj).getStripped());
+ }
+
+ public String toString() {
+ return string;
+ }
+ }
+
+}
Added: jackrabbit/commons/filevault/trunk/vault-diff/src/main/java/org/apache/jackrabbit/vault/util/diff/Range.java
URL: http://svn.apache.org/viewvc/jackrabbit/commons/filevault/trunk/vault-diff/src/main/java/org/apache/jackrabbit/vault/util/diff/Range.java?rev=1512568&view=auto
==============================================================================
--- jackrabbit/commons/filevault/trunk/vault-diff/src/main/java/org/apache/jackrabbit/vault/util/diff/Range.java (added)
+++ jackrabbit/commons/filevault/trunk/vault-diff/src/main/java/org/apache/jackrabbit/vault/util/diff/Range.java Sat Aug 10 05:53:42 2013
@@ -0,0 +1,82 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.jackrabbit.vault.util.diff;
+
+/**
+ * Specifies a range in a document
+ */
+public class Range {
+
+ /**
+ * the document this range points to
+ */
+ public final Document doc;
+
+ /**
+ * the low line of this range
+ */
+ public final int low;
+
+ /**
+ * the high line of this range. actually points to the line after the one
+ * included in this range.
+ */
+ public final int high;
+
+ /**
+ * Creates a new range
+ * @param doc the document
+ * @param low the low line
+ * @param high the high line
+ */
+ public Range(Document doc, int low, int high) {
+ assert low >= 0;
+ assert high >= low;
+ this.doc = doc;
+ this.low = low;
+ this.high = high;
+ }
+
+ /**
+ * Returns the length of this range
+ * @return the length.
+ */
+ public int len() {
+ return high - low;
+ }
+
+ /**
+ * Returns a debug string
+ * @return a debug string
+ */
+ public String toString() {
+ return low + "-" + high;
+ }
+
+ /**
+ * Returns a string suitable for inclusion in a diff output (line number is
+ * incremented by one).
+ * @return a string for output
+ */
+ public String toRangeString() {
+ if (len() == 1) {
+ return String.valueOf(low+1);
+ } else {
+ return (low + 1) + "," + len();
+ }
+ }
+}
\ No newline at end of file
Added: jackrabbit/commons/filevault/trunk/vault-diff/src/main/java/org/apache/jackrabbit/vault/util/diff/WordsElementsFactory.java
URL: http://svn.apache.org/viewvc/jackrabbit/commons/filevault/trunk/vault-diff/src/main/java/org/apache/jackrabbit/vault/util/diff/WordsElementsFactory.java?rev=1512568&view=auto
==============================================================================
--- jackrabbit/commons/filevault/trunk/vault-diff/src/main/java/org/apache/jackrabbit/vault/util/diff/WordsElementsFactory.java (added)
+++ jackrabbit/commons/filevault/trunk/vault-diff/src/main/java/org/apache/jackrabbit/vault/util/diff/WordsElementsFactory.java Sat Aug 10 05:53:42 2013
@@ -0,0 +1,128 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.jackrabbit.vault.util.diff;
+
+import java.io.BufferedReader;
+import java.io.IOException;
+import java.io.Reader;
+import java.io.StringReader;
+import java.util.ArrayList;
+
+/**
+ * Implements an element factory that creates the elements out from words of
+ * the given input stream.
+ */
+public class WordsElementsFactory implements ElementsFactory {
+
+ private static final int MAX_ELEMENTS = 100000;
+
+ private final Document.Element[] elements;
+
+ public WordsElementsFactory(Document.Element[] elements) {
+ this.elements = elements;
+ }
+
+ public Document.Element[] getElements() {
+ return elements;
+ }
+
+ public static WordsElementsFactory create(DocumentSource source, String text) {
+ try {
+ Reader reader = new StringReader(text);
+ return create(source, reader);
+ } catch (IOException e) {
+ throw new IllegalArgumentException(e.toString());
+ }
+ }
+
+ public static WordsElementsFactory create(DocumentSource source, Reader text)
+ throws IOException {
+ Document.Element[] elements = getElements(source, text);
+ return new WordsElementsFactory(elements);
+ }
+
+ private static Document.Element[] getElements(DocumentSource source, Reader text)
+ throws IOException {
+ BufferedReader r;
+ if (text instanceof BufferedReader) {
+ r = (BufferedReader) text;
+ } else {
+ r = new BufferedReader(text);
+ }
+ ArrayList lines = new ArrayList();
+ StringBuffer gutter = new StringBuffer();
+ StringBuffer word = new StringBuffer();
+ int c;
+ while ((c=r.read()) >=0 && lines.size()<MAX_ELEMENTS) {
+ if (Character.isLetterOrDigit((char) c)) {
+ if (gutter.length() > 0) {
+ lines.add(new WordElement(source, word.toString(), gutter.toString()));
+ gutter.setLength(0);
+ word.setLength(0);
+ }
+ word.append((char) c);
+ } else {
+ gutter.append((char) c);
+ }
+ }
+ if (word.length() > 0) {
+ lines.add(new WordElement(source, word.toString(), gutter.toString()));
+ }
+ return (WordElement[]) lines.toArray(new WordElement[lines.size()]);
+ }
+
+ public static class WordElement implements Document.Element {
+
+ private final DocumentSource source;
+
+ private final String word;
+
+ private final String gutter;
+
+ public WordElement(DocumentSource source, String word, String gutter) {
+ this.source = source;
+ this.word = word;
+ this.gutter = gutter;
+ }
+
+ public String getString() {
+ return word + gutter;
+ }
+
+ public DocumentSource getDocumentSource() {
+ return source;
+ }
+
+ public int hashCode() {
+ return word.hashCode();
+ }
+
+ public String toString() {
+ return getString();
+ }
+
+ public boolean equals(Object obj) {
+ if (obj == this) {
+ return true;
+ }
+ if (obj instanceof WordElement) {
+ return ((WordElement) obj).word.equals(word);
+ }
+ return false;
+ }
+ }
+}
Added: jackrabbit/commons/filevault/trunk/vault-diff/src/test/java/org/apache/jackrabbit/vault/util/diff/Diff3Test.java
URL: http://svn.apache.org/viewvc/jackrabbit/commons/filevault/trunk/vault-diff/src/test/java/org/apache/jackrabbit/vault/util/diff/Diff3Test.java?rev=1512568&view=auto
==============================================================================
--- jackrabbit/commons/filevault/trunk/vault-diff/src/test/java/org/apache/jackrabbit/vault/util/diff/Diff3Test.java (added)
+++ jackrabbit/commons/filevault/trunk/vault-diff/src/test/java/org/apache/jackrabbit/vault/util/diff/Diff3Test.java Sat Aug 10 05:53:42 2013
@@ -0,0 +1,149 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.jackrabbit.vault.util.diff;
+
+import junit.framework.TestCase;
+
+/**
+ * <code>Diff3Test</code>...
+ */
+public class Diff3Test extends TestCase {
+
+ private static final String base = "a,b,c,d,e,f,g,";
+
+ public void testModifyNothing() {
+ doTest(base, base, base, base, false);
+ }
+
+ public void testModify() {
+ String change = "a,b,c2,d,e,f,g,";
+ doTest(base, change, base, change, false);
+ doTest(base, base, change, change, false);
+ }
+
+ public void testInsert() {
+ String change = "a,b,c,cc,d,e,f,g,";
+ doTest(base, change, base, change, false);
+ doTest(base, base, change, change, false);
+ }
+
+ public void testDelete() {
+ String change = "a,b,f,g,";
+ doTest(base, change, base, change, false);
+ doTest(base, base, change, change, false);
+ }
+
+ public void testModifySame() {
+ String change = "a,b,c2,d,e,f,g,";
+ doTest(base, change, change, change, false);
+ }
+
+ public void testDeleteBoth() {
+ String change = "a,b,f,g,";
+ doTest(base, change, change, change, false);
+ }
+
+ public void testInsertBoth() {
+ String change = "a,b,c,cc,ccc,d,e,f,g,";
+ doTest(base, change, change, change, false);
+ }
+
+ public void testDeleteInclusive() {
+ String left = "a,b,e,f,g,";
+ String right = "a,b,g,";
+ String result = "a,b," + conflict("c,d,e,f,", "e,f,", "") + "g,";
+ doTest(base, left, right, result, true);
+ }
+
+ public void testDeleteAndInsertSame() {
+ String left = "a,b,c2,e,f,g,";
+ String right = "a,b,c2,g,";
+ String result = "a,b," + conflict("c,d,e,f,", "c2,e,f,", "c2,") + "g,";
+ doTest(base, left, right, result, true);
+ }
+
+ public void testModifyDifferent() {
+ String left = "a,b,c1,d1,e,f,g,";
+ String right = "a,b,c2,d2,e,f,g,";
+ String result = "a,b," + conflict("c,d,", "c1,d1,", "c2,d2,") + "e,f,g,";
+ doTest(base, left, right, result, true);
+ }
+
+ public void testInsertLeftModifyRight() {
+ String left = "a,b,b1,c,d,e,f,g,";
+ String right = "a,b,c2,d,e,f,g,";
+ String result = "a,b," + conflict("c,", "b1,c,", "c2,") + "d,e,f,g,";
+ doTest(base, left, right, result, true);
+ }
+
+ public void testDeleteLeftModifyRight() {
+ String left = "a,b,e,f,g,";
+ String right = "a,b,c2,d2,e,f,g,";
+ String result = "a,b," + conflict("c,d,", "", "c2,d2,") + "e,f,g,";
+ doTest(base, left, right, result, true);
+ }
+
+ public void testDeleteSameInsertDifferent() {
+ String left = "a,b,b1,b2,g,";
+ String right = "a,b,c1,g,";
+ String result = "a,b," + conflict("c,d,e,f,", "b1,b2,", "c1,") + "g,";
+ doTest(base, left, right, result, true);
+ }
+
+ public void testDeleteOverlapping() {
+ String left = "a,f,g,";
+ String right = "a,b,c,g,";
+ String result = "a," + conflict("b,c,d,e,f,", "f,", "b,c,") + "g,";
+ doTest(base, left, right, result, true);
+ }
+
+ public void testNoLastEOL() {
+ String left = "a,b,c";
+ String right = "a,b,c";
+ String result = "a,b,c";
+ doTest(base, left, right, result, false);
+ }
+
+ private String conflict(String base, String left, String right) {
+ base = base.replaceAll(",", "\n");
+ left = left.replaceAll(",", "\n");
+ right = right.replaceAll(",", "\n");
+ return Hunk3.getMarker(Hunk3.MARKER_L, null) + "\n" +
+ left +
+ Hunk3.getMarker(Hunk3.MARKER_B, null) + "\n" +
+ base +
+ Hunk3.getMarker(Hunk3.MARKER_M, null) + "\n" +
+ right +
+ Hunk3.getMarker(Hunk3.MARKER_R, null) + "\n";
+ }
+
+ private void doTest(String base, String left, String right, String result, boolean hasConflicts) {
+ base = base.replaceAll(",", "\n");
+ left = left.replaceAll(",", "\n");
+ right = right.replaceAll(",", "\n");
+ result = result.replaceAll(",", "\n");
+ Document d1 = new Document(null, LineElementsFactory.create(null, base, false));
+ Document d2 = new Document(null, LineElementsFactory.create(null, left, false));
+ Document d3 = new Document(null, LineElementsFactory.create(null, right, false));
+
+ DocumentDiff3 diff = d1.diff3(d2, d3);
+ StringBuffer buf = new StringBuffer();
+ diff.write(buf, DiffWriter.LS_UNIX, true);
+ assertEquals("result", result, buf.toString());
+ assertEquals("conflicts", hasConflicts, diff.hasConflicts());
+ }
+}
\ No newline at end of file
Added: jackrabbit/commons/filevault/trunk/vault-diff/src/test/java/org/apache/jackrabbit/vault/util/diff/DiffTest.java
URL: http://svn.apache.org/viewvc/jackrabbit/commons/filevault/trunk/vault-diff/src/test/java/org/apache/jackrabbit/vault/util/diff/DiffTest.java?rev=1512568&view=auto
==============================================================================
--- jackrabbit/commons/filevault/trunk/vault-diff/src/test/java/org/apache/jackrabbit/vault/util/diff/DiffTest.java (added)
+++ jackrabbit/commons/filevault/trunk/vault-diff/src/test/java/org/apache/jackrabbit/vault/util/diff/DiffTest.java Sat Aug 10 05:53:42 2013
@@ -0,0 +1,67 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.jackrabbit.vault.util.diff;
+
+import java.io.IOException;
+import java.io.InputStream;
+
+import org.apache.commons.io.IOUtils;
+
+import junit.framework.TestCase;
+
+/**
+ * <code>DiffTest</code>...
+ */
+public class DiffTest extends TestCase {
+
+ public void testBaseLeft0() throws IOException {
+ doTest("base.txt", "left.txt", 0, "base-left-0.txt");
+ }
+
+ public void testBaseLeft1() throws IOException {
+ doTest("base.txt", "left.txt", 1, "base-left-1.txt");
+ }
+
+ public void testBaseLeft2() throws IOException {
+ doTest("base.txt", "left.txt", 2, "base-left-2.txt");
+ }
+
+ public void testBaseLeft100() throws IOException {
+ doTest("base.txt", "left.txt", 100, "base-left-100.txt");
+ }
+
+ private void doTest(String baseName, String leftName, int numCtx, String resultName)
+ throws IOException {
+ String base = getResource(baseName);
+ String left = getResource(leftName);
+ String result = getResource(resultName);
+
+ Document d1 = new Document(null, LineElementsFactory.create(null, base, false));
+ Document d2 = new Document(null, LineElementsFactory.create(null, left, false));
+
+ DocumentDiff diff = d1.diff(d2);
+ StringBuffer buf = new StringBuffer();
+ diff.write(buf, DiffWriter.LS_UNIX, numCtx);
+ assertEquals("result", result, buf.toString());
+
+ }
+
+ private String getResource(String name) throws IOException {
+ InputStream in = this.getClass().getClassLoader().getResourceAsStream(name);
+ return IOUtils.toString(in);
+ }
+}
\ No newline at end of file
Added: jackrabbit/commons/filevault/trunk/vault-diff/src/test/java/org/apache/jackrabbit/vault/util/diff/LineElementTest.java
URL: http://svn.apache.org/viewvc/jackrabbit/commons/filevault/trunk/vault-diff/src/test/java/org/apache/jackrabbit/vault/util/diff/LineElementTest.java?rev=1512568&view=auto
==============================================================================
--- jackrabbit/commons/filevault/trunk/vault-diff/src/test/java/org/apache/jackrabbit/vault/util/diff/LineElementTest.java (added)
+++ jackrabbit/commons/filevault/trunk/vault-diff/src/test/java/org/apache/jackrabbit/vault/util/diff/LineElementTest.java Sat Aug 10 05:53:42 2013
@@ -0,0 +1,76 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.jackrabbit.vault.util.diff;
+
+import junit.framework.TestCase;
+
+/**
+ * <code>LineElementTest</code>...
+ */
+public class LineElementTest extends TestCase {
+
+ public void testLineElements() {
+ String[] lines = new String[]{
+ "a\n",
+ "b\n",
+ "c\r\n",
+ "\n",
+ "f",
+ };
+ test(lines);
+ }
+
+ public void testLargeLineElements() {
+ String[] lines = new String[4];
+ StringBuffer buf = new StringBuffer(10001);
+ for (int i=0; i<10000; i++) {
+ buf.append('c');
+ }
+ buf.append('\n');
+ String line = buf.toString();
+ for (int i=0;i<lines.length; i++) {
+ lines[i] = line;
+ }
+ test(lines);
+ }
+
+ public void testManyLineElements() {
+ String[] lines = new String[1024];
+ StringBuffer buf = new StringBuffer(32);
+ for (int i=0; i<32; i++) {
+ buf.append('c');
+ }
+ buf.append('\n');
+ String line = buf.toString();
+ for (int i=0;i<lines.length; i++) {
+ lines[i] = line;
+ }
+ test(lines);
+ }
+
+ private void test(String[] lines) {
+ StringBuffer text = new StringBuffer();
+ for (int i=0; i<lines.length; i++) {
+ text.append(lines[i]);
+ }
+ Document.Element[] elems = LineElementsFactory.create(null, text.toString(), false).getElements();
+ assertEquals(lines.length, elems.length);
+ for (int i=0;i <lines.length; i++) {
+ assertEquals(lines[i], elems[i].toString());
+ }
+ }
+}
\ No newline at end of file
Added: jackrabbit/commons/filevault/trunk/vault-diff/src/test/java/org/apache/jackrabbit/vault/util/diff/Test.java
URL: http://svn.apache.org/viewvc/jackrabbit/commons/filevault/trunk/vault-diff/src/test/java/org/apache/jackrabbit/vault/util/diff/Test.java?rev=1512568&view=auto
==============================================================================
--- jackrabbit/commons/filevault/trunk/vault-diff/src/test/java/org/apache/jackrabbit/vault/util/diff/Test.java (added)
+++ jackrabbit/commons/filevault/trunk/vault-diff/src/test/java/org/apache/jackrabbit/vault/util/diff/Test.java Sat Aug 10 05:53:42 2013
@@ -0,0 +1,39 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.jackrabbit.vault.util.diff;
+
+import java.io.File;
+
+
+/**
+ * <code>Test</code>...
+ */
+public class Test {
+
+ public static void main(String[] args) throws Exception {
+ FileDocumentSource ds1 = new FileDocumentSource((new File(args[0])));
+ FileDocumentSource ds2 = new FileDocumentSource((new File(args[1])));
+
+ Document d1 = new Document(ds1, LineElementsFactory.create(ds1, false, "utf-8"));
+ Document d2 = new Document(ds2, LineElementsFactory.create(ds2, false, "utf-8"));
+
+ DocumentDiff diff = d1.diff(d2);
+ StringBuffer buf = new StringBuffer();
+ diff.write(buf, DiffWriter.LS_UNIX, 1);
+ System.out.println(buf);
+ }
+}
Added: jackrabbit/commons/filevault/trunk/vault-diff/src/test/java/org/apache/jackrabbit/vault/util/diff/Test3.java
URL: http://svn.apache.org/viewvc/jackrabbit/commons/filevault/trunk/vault-diff/src/test/java/org/apache/jackrabbit/vault/util/diff/Test3.java?rev=1512568&view=auto
==============================================================================
--- jackrabbit/commons/filevault/trunk/vault-diff/src/test/java/org/apache/jackrabbit/vault/util/diff/Test3.java (added)
+++ jackrabbit/commons/filevault/trunk/vault-diff/src/test/java/org/apache/jackrabbit/vault/util/diff/Test3.java Sat Aug 10 05:53:42 2013
@@ -0,0 +1,46 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.jackrabbit.vault.util.diff;
+
+import java.io.File;
+
+/**
+ * <code>Test</code>...
+ */
+public class Test3 {
+
+ public static void main(String[] args) throws Exception {
+ FileDocumentSource ds1 = new FileDocumentSource((new File(args[0])));
+ FileDocumentSource ds2 = new FileDocumentSource((new File(args[1])));
+ FileDocumentSource ds3 = new FileDocumentSource((new File(args[2])));
+
+ Document d1 = new Document(ds1, LineElementsFactory.create(ds1, false, "utf-8"));
+ Document d2 = new Document(ds2, LineElementsFactory.create(ds2, false, "utf-8"));
+ Document d3 = new Document(ds3, LineElementsFactory.create(ds3, false, "utf-8"));
+
+ //DocumentDiff diff = new DocumentDiff(d1, d2);
+ DocumentDiff3 diff = new DocumentDiff3(d1, d2, d3);
+ for (Hunk3 hunk = diff.getHunks(); hunk != null; hunk = hunk.next()) {
+ System.out.print(hunk);
+ }
+ System.out.println("---------------------------- final ------------------");
+ StringBuffer buf = new StringBuffer();
+ diff.write(buf, DiffWriter.LS_UNIX, true);
+ System.out.print(buf);
+
+ }
+}
\ No newline at end of file
Added: jackrabbit/commons/filevault/trunk/vault-diff/src/test/resources/base-left-0.txt
URL: http://svn.apache.org/viewvc/jackrabbit/commons/filevault/trunk/vault-diff/src/test/resources/base-left-0.txt?rev=1512568&view=auto
==============================================================================
--- jackrabbit/commons/filevault/trunk/vault-diff/src/test/resources/base-left-0.txt (added)
+++ jackrabbit/commons/filevault/trunk/vault-diff/src/test/resources/base-left-0.txt Sat Aug 10 05:53:42 2013
@@ -0,0 +1,68 @@
+--- .mine
++++ .theirs
+@@ -3,2 +2,0 @@
+-C
+-D
+@@ -17,3 +15 @@
+-C
+-D
+-E
++C1
+@@ -23 +19 @@
+-this ist the first line.
++this is the first line.
+@@ -25,0 +22 @@
++some new on the left
+@@ -30 +26,0 @@
+-import java.io.FileReader;
+@@ -32,0 +29,2 @@
++added
++two lines.
+@@ -34,0 +33 @@
++same mod
+@@ -36 +35 @@
+-import javax.sound.midi.Patch;
++import javax.sound.midi.Patsch;
+@@ -40,2 +38,0 @@
+-C
+-D
+@@ -48,4 +44,0 @@
+-C
+-D
+-E
+-F
+@@ -56,2 +49,2 @@
+-C
+-D
++B'
++B''
+@@ -64,3 +56,0 @@
+-C
+-D
+-E
+@@ -72,0 +63 @@
++C'
+@@ -80,4 +71,2 @@
+-C
+-D
+-E
+-F
++C1
++C2
+@@ -86 +75 @@
+-intermediate base.
++intermediate left.
+@@ -90,4 +79,2 @@
+-C
+-D
+-E
+-F
++B'
++B''
+@@ -97,3 +83,0 @@
+-B
+-C
+-D
+@@ -105 +89 @@
+-last change
++last change.
Added: jackrabbit/commons/filevault/trunk/vault-diff/src/test/resources/base-left-1.txt
URL: http://svn.apache.org/viewvc/jackrabbit/commons/filevault/trunk/vault-diff/src/test/resources/base-left-1.txt?rev=1512568&view=auto
==============================================================================
--- jackrabbit/commons/filevault/trunk/vault-diff/src/test/resources/base-left-1.txt (added)
+++ jackrabbit/commons/filevault/trunk/vault-diff/src/test/resources/base-left-1.txt Sat Aug 10 05:53:42 2013
@@ -0,0 +1,98 @@
+--- .mine
++++ .theirs
+@@ -2,4 +2,2 @@
+ B
+-C
+-D
+ E
+@@ -16,5 +14,3 @@
+ B
+-C
+-D
+-E
++C1
+ F
+@@ -22,5 +18,6 @@
+
+-this ist the first line.
++this is the first line.
+
+ import org.apache.jackrabbit.jcrfs.util.FileUtil;
++some new on the left
+ import org.apache.commons.io.FileUtils;
+@@ -29,9 +26,11 @@
+ import java.io.BufferedReader;
+-import java.io.FileReader;
+ import java.util.LinkedList;
+ import java.util.Vector;
++added
++two lines.
+ import java.util.Enumeration;
+ import java.util.List;
++same mod
+
+-import javax.sound.midi.Patch;
++import javax.sound.midi.Patsch;
+
+@@ -39,4 +38,2 @@
+ B
+-C
+-D
+ E
+@@ -47,6 +44,2 @@
+ B
+-C
+-D
+-E
+-F
+ G
+@@ -55,4 +48,4 @@
+ B
+-C
+-D
++B'
++B''
+ E
+@@ -63,5 +56,2 @@
+ B
+-C
+-D
+-E
+ F
+@@ -72,2 +62,3 @@
+ C
++C'
+ D
+@@ -79,9 +70,7 @@
+ B
+-C
+-D
+-E
+-F
++C1
++C2
+ G
+
+-intermediate base.
++intermediate left.
+
+@@ -89,6 +78,4 @@
+ B
+-C
+-D
+-E
+-F
++B'
++B''
+ G
+@@ -96,5 +83,2 @@
+ A - delete overlapping
+-B
+-C
+-D
+ E
+@@ -104,3 +88,3 @@
+
+-last change
++last change.
+ and this ist the last line
\ No newline at end of file
Added: jackrabbit/commons/filevault/trunk/vault-diff/src/test/resources/base-left-100.txt
URL: http://svn.apache.org/viewvc/jackrabbit/commons/filevault/trunk/vault-diff/src/test/resources/base-left-100.txt?rev=1512568&view=auto
==============================================================================
--- jackrabbit/commons/filevault/trunk/vault-diff/src/test/resources/base-left-100.txt (added)
+++ jackrabbit/commons/filevault/trunk/vault-diff/src/test/resources/base-left-100.txt Sat Aug 10 05:53:42 2013
@@ -0,0 +1,125 @@
+--- .mine
++++ .theirs
+@@ -1,106 +1,90 @@
+ A - delete both
+ B
+-C
+-D
+ E
+ F
+
+ A
+ B
+ C
+ D
+ E
+ F
+
+ A - mod and insert
+ B
+-C
+-D
+-E
++C1
+ F
+ G
+
+-this ist the first line.
++this is the first line.
+
+ import org.apache.jackrabbit.jcrfs.util.FileUtil;
++some new on the left
+ import org.apache.commons.io.FileUtils;
+
+ import java.io.File;
+ import java.io.BufferedReader;
+-import java.io.FileReader;
+ import java.util.LinkedList;
+ import java.util.Vector;
++added
++two lines.
+ import java.util.Enumeration;
+ import java.util.List;
++same mod
+
+-import javax.sound.midi.Patch;
++import javax.sound.midi.Patsch;
+
+ A - delete left and right (left inclusive)
+ B
+-C
+-D
+ E
+ F
+ G
+
+ A - delete left and right (right inclusive)
+ B
+-C
+-D
+-E
+-F
+ G
+
+ A - delete left and right, insert same
+ B
+-C
+-D
++B'
++B''
+ E
+ F
+ G
+
+ A - delete left, modify right
+ B
+-C
+-D
+-E
+ F
+ G
+
+ A - insert left, modify right
+ B
+ C
++C'
+ D
+ E
+ F
+ G
+
+ A - modify same
+ B
+-C
+-D
+-E
+-F
++C1
++C2
+ G
+
+-intermediate base.
++intermediate left.
+
+ A - delete same, insert different
+ B
+-C
+-D
+-E
+-F
++B'
++B''
+ G
+
+ A - delete overlapping
+-B
+-C
+-D
+ E
+ F
+ G
+
+
+-last change
++last change.
+ and this ist the last line
\ No newline at end of file
Added: jackrabbit/commons/filevault/trunk/vault-diff/src/test/resources/base-left-2.txt
URL: http://svn.apache.org/viewvc/jackrabbit/commons/filevault/trunk/vault-diff/src/test/resources/base-left-2.txt?rev=1512568&view=auto
==============================================================================
--- jackrabbit/commons/filevault/trunk/vault-diff/src/test/resources/base-left-2.txt (added)
+++ jackrabbit/commons/filevault/trunk/vault-diff/src/test/resources/base-left-2.txt Sat Aug 10 05:53:42 2013
@@ -0,0 +1,113 @@
+--- .mine
++++ .theirs
+@@ -1,6 +1,4 @@
+ A - delete both
+ B
+-C
+-D
+ E
+ F
+@@ -15,29 +13,28 @@
+ A - mod and insert
+ B
+-C
+-D
+-E
++C1
+ F
+ G
+
+-this ist the first line.
++this is the first line.
+
+ import org.apache.jackrabbit.jcrfs.util.FileUtil;
++some new on the left
+ import org.apache.commons.io.FileUtils;
+
+ import java.io.File;
+ import java.io.BufferedReader;
+-import java.io.FileReader;
+ import java.util.LinkedList;
+ import java.util.Vector;
++added
++two lines.
+ import java.util.Enumeration;
+ import java.util.List;
++same mod
+
+-import javax.sound.midi.Patch;
++import javax.sound.midi.Patsch;
+
+ A - delete left and right (left inclusive)
+ B
+-C
+-D
+ E
+ F
+@@ -46,14 +43,10 @@
+ A - delete left and right (right inclusive)
+ B
+-C
+-D
+-E
+-F
+ G
+
+ A - delete left and right, insert same
+ B
+-C
+-D
++B'
++B''
+ E
+ F
+@@ -62,7 +55,4 @@
+ A - delete left, modify right
+ B
+-C
+-D
+-E
+ F
+ G
+@@ -71,4 +61,5 @@
+ B
+ C
++C'
+ D
+ E
+@@ -78,24 +69,17 @@
+ A - modify same
+ B
+-C
+-D
+-E
+-F
++C1
++C2
+ G
+
+-intermediate base.
++intermediate left.
+
+ A - delete same, insert different
+ B
+-C
+-D
+-E
+-F
++B'
++B''
+ G
+
+ A - delete overlapping
+-B
+-C
+-D
+ E
+ F
+@@ -103,4 +87,4 @@
+
+
+-last change
++last change.
+ and this ist the last line
\ No newline at end of file
Added: jackrabbit/commons/filevault/trunk/vault-diff/src/test/resources/base.txt
URL: http://svn.apache.org/viewvc/jackrabbit/commons/filevault/trunk/vault-diff/src/test/resources/base.txt?rev=1512568&view=auto
==============================================================================
--- jackrabbit/commons/filevault/trunk/vault-diff/src/test/resources/base.txt (added)
+++ jackrabbit/commons/filevault/trunk/vault-diff/src/test/resources/base.txt Sat Aug 10 05:53:42 2013
@@ -0,0 +1,106 @@
+A - delete both
+B
+C
+D
+E
+F
+
+A
+B
+C
+D
+E
+F
+
+A - mod and insert
+B
+C
+D
+E
+F
+G
+
+this ist the first line.
+
+import org.apache.jackrabbit.jcrfs.util.FileUtil;
+import org.apache.commons.io.FileUtils;
+
+import java.io.File;
+import java.io.BufferedReader;
+import java.io.FileReader;
+import java.util.LinkedList;
+import java.util.Vector;
+import java.util.Enumeration;
+import java.util.List;
+
+import javax.sound.midi.Patch;
+
+A - delete left and right (left inclusive)
+B
+C
+D
+E
+F
+G
+
+A - delete left and right (right inclusive)
+B
+C
+D
+E
+F
+G
+
+A - delete left and right, insert same
+B
+C
+D
+E
+F
+G
+
+A - delete left, modify right
+B
+C
+D
+E
+F
+G
+
+A - insert left, modify right
+B
+C
+D
+E
+F
+G
+
+A - modify same
+B
+C
+D
+E
+F
+G
+
+intermediate base.
+
+A - delete same, insert different
+B
+C
+D
+E
+F
+G
+
+A - delete overlapping
+B
+C
+D
+E
+F
+G
+
+
+last change
+and this ist the last line
\ No newline at end of file
Added: jackrabbit/commons/filevault/trunk/vault-diff/src/test/resources/left.txt
URL: http://svn.apache.org/viewvc/jackrabbit/commons/filevault/trunk/vault-diff/src/test/resources/left.txt?rev=1512568&view=auto
==============================================================================
--- jackrabbit/commons/filevault/trunk/vault-diff/src/test/resources/left.txt (added)
+++ jackrabbit/commons/filevault/trunk/vault-diff/src/test/resources/left.txt Sat Aug 10 05:53:42 2013
@@ -0,0 +1,90 @@
+A - delete both
+B
+E
+F
+
+A
+B
+C
+D
+E
+F
+
+A - mod and insert
+B
+C1
+F
+G
+
+this is the first line.
+
+import org.apache.jackrabbit.jcrfs.util.FileUtil;
+some new on the left
+import org.apache.commons.io.FileUtils;
+
+import java.io.File;
+import java.io.BufferedReader;
+import java.util.LinkedList;
+import java.util.Vector;
+added
+two lines.
+import java.util.Enumeration;
+import java.util.List;
+same mod
+
+import javax.sound.midi.Patsch;
+
+A - delete left and right (left inclusive)
+B
+E
+F
+G
+
+A - delete left and right (right inclusive)
+B
+G
+
+A - delete left and right, insert same
+B
+B'
+B''
+E
+F
+G
+
+A - delete left, modify right
+B
+F
+G
+
+A - insert left, modify right
+B
+C
+C'
+D
+E
+F
+G
+
+A - modify same
+B
+C1
+C2
+G
+
+intermediate left.
+
+A - delete same, insert different
+B
+B'
+B''
+G
+
+A - delete overlapping
+E
+F
+G
+
+
+last change.
+and this ist the last line
\ No newline at end of file
Added: jackrabbit/commons/filevault/trunk/vault-diff/src/test/resources/right.txt
URL: http://svn.apache.org/viewvc/jackrabbit/commons/filevault/trunk/vault-diff/src/test/resources/right.txt?rev=1512568&view=auto
==============================================================================
--- jackrabbit/commons/filevault/trunk/vault-diff/src/test/resources/right.txt (added)
+++ jackrabbit/commons/filevault/trunk/vault-diff/src/test/resources/right.txt Sat Aug 10 05:53:42 2013
@@ -0,0 +1,90 @@
+A - delete both
+B
+E
+F
+
+A
+B
+C
+D
+D2
+E
+F
+
+A - mod and insert
+B
+C
+D1
+F
+G
+
+this is the first line.
+
+import org.apache.jackrabbit.jcrfs.util.FileUtil;
+import org.apache.commons.io.FileUtils;
+new line on server.
+
+import java.io.File;
+import java.io.BufferedReader;
+import java.io.FileReader;
+import java.util.LinkedList;
+import java.util.Vector;
+import java.util.Enumeration;
+import java.util.List;
+same mod
+
+import javax.sound.midi.Batch;
+
+A - delete left and right (left inclusive)
+B
+G
+
+A - delete left and right (right inclusive)
+B
+E
+F
+G
+
+A - delete left and right, insert same
+B
+B'
+B''
+G
+
+A - delete left, modify right
+B
+C2
+D2
+E
+F
+G
+
+A - insert left, modify right
+B
+C
+D2
+E
+F
+G
+
+A - modify same
+B
+C1
+C2
+G
+
+intermediate right.
+
+A - delete same, insert different
+B
+C2
+G
+
+A - delete overlapping
+B
+C
+G
+
+
+last change!
+and this ist the last line
Added: jackrabbit/commons/filevault/trunk/vault-hook-example/assembly.xml
URL: http://svn.apache.org/viewvc/jackrabbit/commons/filevault/trunk/vault-hook-example/assembly.xml?rev=1512568&view=auto
==============================================================================
--- jackrabbit/commons/filevault/trunk/vault-hook-example/assembly.xml (added)
+++ jackrabbit/commons/filevault/trunk/vault-hook-example/assembly.xml Sat Aug 10 05:53:42 2013
@@ -0,0 +1,38 @@
+<!--
+ Licensed to the Apache Software Foundation (ASF) under one or more
+ contributor license agreements. See the NOTICE file distributed with
+ this work for additional information regarding copyright ownership.
+ The ASF licenses this file to You under the Apache License, Version 2.0
+ (the "License"); you may not use this file except in compliance with
+ the License. You may obtain a copy of the License at
+
+ http://www.apache.org/licenses/LICENSE-2.0
+
+ Unless required by applicable law or agreed to in writing, software
+ distributed under the License is distributed on an "AS IS" BASIS,
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ See the License for the specific language governing permissions and
+ limitations under the License.
+ -->
+<assembly>
+ <id>package</id>
+ <formats>
+ <format>zip</format>
+ </formats>
+ <includeBaseDirectory>false</includeBaseDirectory>
+ <fileSets>
+ <fileSet>
+ <directory>src/main/content</directory>
+ <outputDirectory></outputDirectory>
+ </fileSet>
+ </fileSets>
+ <dependencySets>
+ <dependencySet>
+ <useProjectArtifact>true</useProjectArtifact>
+ <outputDirectory>META-INF/vault/hooks</outputDirectory>
+ <includes>
+ <include>org.apache.jackrabbit.vault:vault-hook-example</include>
+ </includes>
+ </dependencySet>
+ </dependencySets>
+</assembly>
\ No newline at end of file
Added: jackrabbit/commons/filevault/trunk/vault-hook-example/pom.xml
URL: http://svn.apache.org/viewvc/jackrabbit/commons/filevault/trunk/vault-hook-example/pom.xml?rev=1512568&view=auto
==============================================================================
--- jackrabbit/commons/filevault/trunk/vault-hook-example/pom.xml (added)
+++ jackrabbit/commons/filevault/trunk/vault-hook-example/pom.xml Sat Aug 10 05:53:42 2013
@@ -0,0 +1,122 @@
+<?xml version="1.0"?><!--
+ Licensed to the Apache Software Foundation (ASF) under one or more
+ contributor license agreements. See the NOTICE file distributed with
+ this work for additional information regarding copyright ownership.
+ The ASF licenses this file to You under the Apache License, Version 2.0
+ (the "License"); you may not use this file except in compliance with
+ the License. You may obtain a copy of the License at
+
+ http://www.apache.org/licenses/LICENSE-2.0
+
+ Unless required by applicable law or agreed to in writing, software
+ distributed under the License is distributed on an "AS IS" BASIS,
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ See the License for the specific language governing permissions and
+ limitations under the License.
+ -->
+<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd ">
+ <modelVersion>4.0.0</modelVersion>
+ <!-- ====================================================================== -->
+ <!-- P A R E N T P R O J E C T D E S C R I P T I O N -->
+ <!-- ====================================================================== -->
+ <parent>
+ <groupId>org.apache.jackrabbit.vault</groupId>
+ <artifactId>parent</artifactId>
+ <relativePath>../parent/pom.xml</relativePath>
+ <version>3.0.0-SNAPSHOT</version>
+ </parent>
+
+ <!-- ====================================================================== -->
+ <!-- P R O J E C T D E S C R I P T I O N -->
+ <!-- ====================================================================== -->
+ <artifactId>vault-hook-example</artifactId>
+ <version>3.0.0-SNAPSHOT</version>
+ <packaging>jar</packaging>
+
+ <name>Apache Jackrabbit FileVault Package Hook Example</name>
+ <description>
+ Provides an example of a package install hook
+ </description>
+
+ <!-- ====================================================================== -->
+ <!-- S C M D E F I N I T I O N -->
+ <!-- ====================================================================== -->
+ <scm>
+ <connection>scm:svn:http://svn.apache.org/repos/asf/jackrabbit/commons/filevault/trunk/vault-hook-example</connection>
+ <developerConnection>scm:svn:https://svn.apache.org/repos/asf/jackrabbit/commons/filevault/trunk/vault-hook-example</developerConnection>
+ <url>http://svn.apache.org/viewvc/asf/jackrabbit/commons/filevault/trunk/vault-hook-example</url>
+ </scm>
+
+ <!-- ====================================================================== -->
+ <!-- B U I L D D E F I N I T I O N -->
+ <!-- ====================================================================== -->
+ <build>
+ <plugins>
+ <!-- assemble dist -->
+ <plugin>
+ <artifactId>maven-assembly-plugin</artifactId>
+ <version>2.2</version>
+ <executions>
+ <execution>
+ <id>assemble-distribution</id>
+ <configuration>
+ <descriptors>
+ <descriptor>assembly.xml</descriptor>
+ </descriptors>
+ </configuration>
+ <phase>package</phase>
+ <goals>
+ <goal>directory-inline</goal>
+ <goal>attached</goal>
+ </goals>
+ </execution>
+ </executions>
+ </plugin>
+ <!-- set main class -->
+ <plugin>
+ <groupId>org.apache.maven.plugins</groupId>
+ <artifactId>maven-jar-plugin</artifactId>
+ <version>2.3.1</version>
+ <configuration>
+ <archive>
+ <manifest>
+ <mainClass>org.apache.jackrabbit.vault.packaging.hooks.ExampleHook</mainClass>
+ <addClasspath>true</addClasspath>
+ </manifest>
+ </archive>
+ </configuration>
+ </plugin>
+ </plugins>
+ </build>
+
+ <!-- ====================================================================== -->
+ <!-- D E P E N D E N C I E S -->
+ <!-- ====================================================================== -->
+ <dependencies>
+ <dependency>
+ <groupId>org.apache.jackrabbit.vault</groupId>
+ <artifactId>org.apache.jackrabbit.vault</artifactId>
+ <version>3.0.0-SNAPSHOT</version>
+ </dependency>
+
+ <!-- JCR Stuff -->
+ <dependency>
+ <groupId>javax.jcr</groupId>
+ <artifactId>jcr</artifactId>
+ <optional>true</optional>
+ </dependency>
+
+ <!-- SLF4j / Log4j -->
+ <dependency>
+ <groupId>org.slf4j</groupId>
+ <artifactId>slf4j-log4j12</artifactId>
+ <optional>true</optional>
+ </dependency>
+ <dependency>
+ <groupId>log4j</groupId>
+ <artifactId>log4j</artifactId>
+ <optional>true</optional>
+ </dependency>
+ </dependencies>
+
+</project>
Added: jackrabbit/commons/filevault/trunk/vault-hook-example/src/main/content/META-INF/vault/config.xml
URL: http://svn.apache.org/viewvc/jackrabbit/commons/filevault/trunk/vault-hook-example/src/main/content/META-INF/vault/config.xml?rev=1512568&view=auto
==============================================================================
--- jackrabbit/commons/filevault/trunk/vault-hook-example/src/main/content/META-INF/vault/config.xml (added)
+++ jackrabbit/commons/filevault/trunk/vault-hook-example/src/main/content/META-INF/vault/config.xml Sat Aug 10 05:53:42 2013
@@ -0,0 +1,93 @@
+<!--
+ Licensed to the Apache Software Foundation (ASF) under one or more
+ contributor license agreements. See the NOTICE file distributed with
+ this work for additional information regarding copyright ownership.
+ The ASF licenses this file to You under the Apache License, Version 2.0
+ (the "License"); you may not use this file except in compliance with
+ the License. You may obtain a copy of the License at
+
+ http://www.apache.org/licenses/LICENSE-2.0
+
+ Unless required by applicable law or agreed to in writing, software
+ distributed under the License is distributed on an "AS IS" BASIS,
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ See the License for the specific language governing permissions and
+ limitations under the License.
+ -->
+<vaultfs version="1.1">
+ <!--
+ Defines the content aggregation. The order of the defined aggregates
+ is important for finding the correct aggregator.
+ -->
+ <aggregates>
+ <!--
+ Defines an aggregate that handles nt:file and nt:resource nodes.
+ -->
+ <aggregate type="file" title="File Aggregate"/>
+
+ <!--
+ Defines an aggregate that handles file/folder like nodes. It matches
+ all nt:hierarchyNode nodes that have or define a jcr:content
+ child node and excludes child nodes that are nt:hierarchyNodes.
+ -->
+ <aggregate type="filefolder" title="File/Folder Aggregate"/>
+
+ <!--
+ Defines an aggregate that handles nt:nodeType nodes and serializes
+ them into .cnd notation.
+ -->
+ <aggregate type="nodetype" title="Node Type Aggregate" />
+
+ <!--
+ Defines an aggregate that defines full coverage for certain node
+ types that cannot be covered by the default aggregator.
+ -->
+ <aggregate type="full" title="Full Coverage Aggregate">
+ <matches>
+ <include nodeType="rep:AccessControl" respectSupertype="true" />
+ <include nodeType="rep:Policy" respectSupertype="true" />
+ <include nodeType="cq:Widget" respectSupertype="true" />
+ <include nodeType="cq:EditConfig" respectSupertype="true" />
+ <include nodeType="cq:WorkflowModel" respectSupertype="true" />
+ <include nodeType="vlt:FullCoverage" respectSupertype="true" />
+ <include nodeType="mix:language" respectSupertype="true" />
+ <include nodeType="sling:OsgiConfig" respectSupertype="true" />
+ </matches>
+ </aggregate>
+
+ <!--
+ Defines an aggregate that handles nt:folder like nodes.
+ -->
+ <aggregate type="generic" title="Folder Aggregate">
+ <matches>
+ <include nodeType="nt:folder" respectSupertype="true" />
+ </matches>
+ <contains>
+ <exclude isNode="true" />
+ </contains>
+ </aggregate>
+
+ <!--
+ Defines the default aggregate
+ -->
+ <aggregate type="generic" title="Default Aggregator" isDefault="true">
+ <matches>
+ <!-- all -->
+ </matches>
+ <contains>
+ <exclude nodeType="nt:hierarchyNode" respectSupertype="true" />
+ </contains>
+ </aggregate>
+
+ </aggregates>
+
+ <!--
+ defines the input handlers
+ -->
+ <handlers>
+ <handler type="folder"/>
+ <handler type="file"/>
+ <handler type="nodetype"/>
+ <handler type="generic"/>
+ </handlers>
+</vaultfs>
Added: jackrabbit/commons/filevault/trunk/vault-hook-example/src/main/content/META-INF/vault/definition/.content.xml
URL: http://svn.apache.org/viewvc/jackrabbit/commons/filevault/trunk/vault-hook-example/src/main/content/META-INF/vault/definition/.content.xml?rev=1512568&view=auto
==============================================================================
--- jackrabbit/commons/filevault/trunk/vault-hook-example/src/main/content/META-INF/vault/definition/.content.xml (added)
+++ jackrabbit/commons/filevault/trunk/vault-hook-example/src/main/content/META-INF/vault/definition/.content.xml Sat Aug 10 05:53:42 2013
@@ -0,0 +1,35 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+ Licensed to the Apache Software Foundation (ASF) under one or more
+ contributor license agreements. See the NOTICE file distributed with
+ this work for additional information regarding copyright ownership.
+ The ASF licenses this file to You under the Apache License, Version 2.0
+ (the "License"); you may not use this file except in compliance with
+ the License. You may obtain a copy of the License at
+
+ http://www.apache.org/licenses/LICENSE-2.0
+
+ Unless required by applicable law or agreed to in writing, software
+ distributed under the License is distributed on an "AS IS" BASIS,
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ See the License for the specific language governing permissions and
+ limitations under the License.
+ -->
+<jcr:root xmlns:vlt="http://www.day.com/jcr/vault/1.0" xmlns:jcr="http://www.jcp.org/jcr/1.0" xmlns:nt="http://www.jcp.org/jcr/nt/1.0"
+ jcr:created="{Date}2009-10-29T14:12:42.626+01:00"
+ jcr:createdBy="admin"
+ jcr:description=""
+ jcr:lastModified="{Date}2009-10-29T14:12:42.627+01:00"
+ jcr:lastModifiedBy="admin"
+ jcr:primaryType="vlt:PackageDefinition"
+ acHandling="ignore"
+ buildCount="1"
+ lastUnwrapped="{Date}2009-10-29T14:12:42.626+01:00"
+ lastUnwrappedBy="admin"
+ version="1.0">
+ <filter jcr:primaryType="nt:unstructured">
+ <f0
+ jcr:primaryType="nt:unstructured"
+ root="/testroot"/>
+ </filter>
+</jcr:root>
Added: jackrabbit/commons/filevault/trunk/vault-hook-example/src/main/content/META-INF/vault/filter.xml
URL: http://svn.apache.org/viewvc/jackrabbit/commons/filevault/trunk/vault-hook-example/src/main/content/META-INF/vault/filter.xml?rev=1512568&view=auto
==============================================================================
--- jackrabbit/commons/filevault/trunk/vault-hook-example/src/main/content/META-INF/vault/filter.xml (added)
+++ jackrabbit/commons/filevault/trunk/vault-hook-example/src/main/content/META-INF/vault/filter.xml Sat Aug 10 05:53:42 2013
@@ -0,0 +1,20 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+ Licensed to the Apache Software Foundation (ASF) under one or more
+ contributor license agreements. See the NOTICE file distributed with
+ this work for additional information regarding copyright ownership.
+ The ASF licenses this file to You under the Apache License, Version 2.0
+ (the "License"); you may not use this file except in compliance with
+ the License. You may obtain a copy of the License at
+
+ http://www.apache.org/licenses/LICENSE-2.0
+
+ Unless required by applicable law or agreed to in writing, software
+ distributed under the License is distributed on an "AS IS" BASIS,
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ See the License for the specific language governing permissions and
+ limitations under the License.
+ -->
+<workspaceFilter version="1.0">
+ <filter root="/testroot"/>
+</workspaceFilter>
Added: jackrabbit/commons/filevault/trunk/vault-hook-example/src/main/content/META-INF/vault/nodetypes.cnd
URL: http://svn.apache.org/viewvc/jackrabbit/commons/filevault/trunk/vault-hook-example/src/main/content/META-INF/vault/nodetypes.cnd?rev=1512568&view=auto
==============================================================================
--- jackrabbit/commons/filevault/trunk/vault-hook-example/src/main/content/META-INF/vault/nodetypes.cnd (added)
+++ jackrabbit/commons/filevault/trunk/vault-hook-example/src/main/content/META-INF/vault/nodetypes.cnd Sat Aug 10 05:53:42 2013
@@ -0,0 +1,11 @@
+<'rep'='internal'>
+<'nt'='http://www.jcp.org/jcr/nt/1.0'>
+
+[rep:Configurations]
+ + * (nt:configuration) = nt:configuration abort
+ + * (rep:Configurations) = rep:Configurations abort
+
+[rep:Activities]
+ + * (nt:activity) = nt:activity protected abort
+ + * (rep:Activities) = rep:Activities protected abort
+
Added: jackrabbit/commons/filevault/trunk/vault-hook-example/src/main/content/META-INF/vault/properties.xml
URL: http://svn.apache.org/viewvc/jackrabbit/commons/filevault/trunk/vault-hook-example/src/main/content/META-INF/vault/properties.xml?rev=1512568&view=auto
==============================================================================
--- jackrabbit/commons/filevault/trunk/vault-hook-example/src/main/content/META-INF/vault/properties.xml (added)
+++ jackrabbit/commons/filevault/trunk/vault-hook-example/src/main/content/META-INF/vault/properties.xml Sat Aug 10 05:53:42 2013
@@ -0,0 +1,37 @@
+<?xml version="1.0" encoding="utf-8"?>
+<!--
+ Licensed to the Apache Software Foundation (ASF) under one or more
+ contributor license agreements. See the NOTICE file distributed with
+ this work for additional information regarding copyright ownership.
+ The ASF licenses this file to You under the Apache License, Version 2.0
+ (the "License"); you may not use this file except in compliance with
+ the License. You may obtain a copy of the License at
+
+ http://www.apache.org/licenses/LICENSE-2.0
+
+ Unless required by applicable law or agreed to in writing, software
+ distributed under the License is distributed on an "AS IS" BASIS,
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ See the License for the specific language governing permissions and
+ limitations under the License.
+ -->
+<!DOCTYPE properties SYSTEM "http://java.sun.com/dtd/properties.dtd">
+<properties>
+ <comment>FileVault Package Properties</comment>
+ <entry key="createdBy">admin</entry>
+ <entry key="name">hooktest</entry>
+ <entry key="lastModified">2009-10-29T14:12:42.627+01:00</entry>
+ <entry key="lastModifiedBy">2009-10-29T14:12:42.627+01:00</entry>
+ <entry key="acHandling">ignore</entry>
+ <entry key="created">2009-10-29T14:12:42.980+01:00</entry>
+ <entry key="buildCount">1</entry>
+ <entry key="version">1.0</entry>
+ <entry key="dependencies"></entry>
+ <entry key="packageFormatVersion">2</entry>
+ <entry key="description"></entry>
+ <entry key="group"></entry>
+ <entry key="path">/etc/packages/hooktest</entry>
+ <entry key="hook-example-copyfrom">/testroot/testnode</entry>
+ <entry key="hook-example-copyto">/testbackup</entry>
+ <entry key="hook-example-testnode">/testroot</entry>
+</properties>
Added: jackrabbit/commons/filevault/trunk/vault-hook-example/src/main/content/jcr_root/.content.xml
URL: http://svn.apache.org/viewvc/jackrabbit/commons/filevault/trunk/vault-hook-example/src/main/content/jcr_root/.content.xml?rev=1512568&view=auto
==============================================================================
--- jackrabbit/commons/filevault/trunk/vault-hook-example/src/main/content/jcr_root/.content.xml (added)
+++ jackrabbit/commons/filevault/trunk/vault-hook-example/src/main/content/jcr_root/.content.xml Sat Aug 10 05:53:42 2013
@@ -0,0 +1,26 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+ Licensed to the Apache Software Foundation (ASF) under one or more
+ contributor license agreements. See the NOTICE file distributed with
+ this work for additional information regarding copyright ownership.
+ The ASF licenses this file to You under the Apache License, Version 2.0
+ (the "License"); you may not use this file except in compliance with
+ the License. You may obtain a copy of the License at
+
+ http://www.apache.org/licenses/LICENSE-2.0
+
+ Unless required by applicable law or agreed to in writing, software
+ distributed under the License is distributed on an "AS IS" BASIS,
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ See the License for the specific language governing permissions and
+ limitations under the License.
+ -->
+<jcr:root xmlns:jcr="http://www.jcp.org/jcr/1.0" xmlns:rep="internal"
+ jcr:mixinTypes="[rep:AccessControllable]"
+ jcr:primaryType="rep:root">
+ <jcr:system/>
+ <rep:policy/>
+ <etc/>
+ <testroot/>
+ <home/>
+</jcr:root>
Added: jackrabbit/commons/filevault/trunk/vault-hook-example/src/main/content/jcr_root/testroot/.content.xml
URL: http://svn.apache.org/viewvc/jackrabbit/commons/filevault/trunk/vault-hook-example/src/main/content/jcr_root/testroot/.content.xml?rev=1512568&view=auto
==============================================================================
--- jackrabbit/commons/filevault/trunk/vault-hook-example/src/main/content/jcr_root/testroot/.content.xml (added)
+++ jackrabbit/commons/filevault/trunk/vault-hook-example/src/main/content/jcr_root/testroot/.content.xml Sat Aug 10 05:53:42 2013
@@ -0,0 +1,22 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+ Licensed to the Apache Software Foundation (ASF) under one or more
+ contributor license agreements. See the NOTICE file distributed with
+ this work for additional information regarding copyright ownership.
+ The ASF licenses this file to You under the Apache License, Version 2.0
+ (the "License"); you may not use this file except in compliance with
+ the License. You may obtain a copy of the License at
+
+ http://www.apache.org/licenses/LICENSE-2.0
+
+ Unless required by applicable law or agreed to in writing, software
+ distributed under the License is distributed on an "AS IS" BASIS,
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ See the License for the specific language governing permissions and
+ limitations under the License.
+ -->
+<jcr:root xmlns:jcr="http://www.jcp.org/jcr/1.0" xmlns:nt="http://www.jcp.org/jcr/nt/1.0"
+ jcr:primaryType="nt:unstructured">
+ <testnode jcr:primaryType="nt:unstructured"/>
+ <testfolder/>
+</jcr:root>
Added: jackrabbit/commons/filevault/trunk/vault-hook-example/src/main/java/org/apache/jackrabbit/vault/packaging/hooks/ExampleHook.java
URL: http://svn.apache.org/viewvc/jackrabbit/commons/filevault/trunk/vault-hook-example/src/main/java/org/apache/jackrabbit/vault/packaging/hooks/ExampleHook.java?rev=1512568&view=auto
==============================================================================
--- jackrabbit/commons/filevault/trunk/vault-hook-example/src/main/java/org/apache/jackrabbit/vault/packaging/hooks/ExampleHook.java (added)
+++ jackrabbit/commons/filevault/trunk/vault-hook-example/src/main/java/org/apache/jackrabbit/vault/packaging/hooks/ExampleHook.java Sat Aug 10 05:53:42 2013
@@ -0,0 +1,116 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.jackrabbit.vault.packaging.hooks;
+
+import java.util.Calendar;
+import java.util.Properties;
+
+import javax.jcr.Node;
+import javax.jcr.RepositoryException;
+
+import org.apache.jackrabbit.vault.packaging.InstallContext;
+import org.apache.jackrabbit.vault.packaging.InstallHook;
+import org.apache.jackrabbit.vault.packaging.PackageException;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+/**
+ * <code>ExampleHook</code>...
+ */
+public class ExampleHook implements InstallHook {
+
+ public static String PROP_COPY_FROM = "hook-example-copyfrom";
+
+ public static String PROP_COPY_TO = "hook-example-copyto";
+
+ public static String PROP_TEST_NODE = "hook-example-testnode";
+
+ private String testNodePath;
+
+ /**
+ * default logger
+ */
+ private static final Logger log = LoggerFactory.getLogger(ExampleHook.class);
+
+ public void execute(InstallContext ctx) throws PackageException {
+ log.info("Executing Hook in phase {}", ctx.getPhase());
+ try {
+ switch (ctx.getPhase()) {
+ case END:
+ doEnd(ctx);
+ break;
+ case INSTALLED:
+ doInstalled(ctx);
+ break;
+ case INSTALL_FAILED:
+ doInstallFailed(ctx);
+ break;
+ case PREPARE:
+ doPreprare(ctx);
+ break;
+ case PREPARE_FAILED:
+ doPreprareFailed(ctx);
+ break;
+ }
+ } catch (RepositoryException e) {
+ throw new PackageException(e);
+ }
+ }
+
+ private void doPreprare(InstallContext ctx) throws PackageException, RepositoryException {
+ // read the properties from the package
+ Properties props = ctx.getPackage().getMetaInf().getProperties();
+ String copyFrom = props.getProperty(PROP_COPY_FROM, "");
+ if (copyFrom.length() == 0) {
+ throw new PackageException("hook-example needs " + PROP_COPY_FROM + " property set in properties.xml");
+ }
+ String copyTo = props.getProperty(PROP_COPY_TO, "");
+ if (copyTo.length() == 0) {
+ throw new PackageException("hook-example needs " + PROP_COPY_TO + " property set in properties.xml");
+ }
+ testNodePath = props.getProperty(PROP_TEST_NODE, "");
+ if (testNodePath.length() == 0) {
+ throw new PackageException("hook-example needs " + PROP_TEST_NODE + " property set in properties.xml");
+ }
+ copyTo += "_" + System.currentTimeMillis();
+ ctx.getSession().getWorkspace().copy(copyFrom, copyTo);
+ log.info("hook-example copied {} to {}", copyFrom, copyTo);
+
+ }
+
+ private void doPreprareFailed(InstallContext ctx) {
+ // this is invoked when any of the hooks (including our self) threw a
+ // package exception during prepare
+ }
+
+ private void doEnd(InstallContext ctx) {
+ // here we could clean up any allocated resources
+ }
+
+ private void doInstalled(InstallContext ctx) throws RepositoryException {
+ // update a property in the install
+ Node testNode = ctx.getSession().getNode(testNodePath);
+ testNode.setProperty("hook-example", Calendar.getInstance());
+ testNode.save();
+ }
+
+ private void doInstallFailed(InstallContext ctx) {
+ // this is called when installation failed
+ }
+
+
+}
\ No newline at end of file
Added: jackrabbit/commons/filevault/trunk/vault-hook-externalclass-test/assembly.xml
URL: http://svn.apache.org/viewvc/jackrabbit/commons/filevault/trunk/vault-hook-externalclass-test/assembly.xml?rev=1512568&view=auto
==============================================================================
--- jackrabbit/commons/filevault/trunk/vault-hook-externalclass-test/assembly.xml (added)
+++ jackrabbit/commons/filevault/trunk/vault-hook-externalclass-test/assembly.xml Sat Aug 10 05:53:42 2013
@@ -0,0 +1,38 @@
+<!--
+ Licensed to the Apache Software Foundation (ASF) under one or more
+ contributor license agreements. See the NOTICE file distributed with
+ this work for additional information regarding copyright ownership.
+ The ASF licenses this file to You under the Apache License, Version 2.0
+ (the "License"); you may not use this file except in compliance with
+ the License. You may obtain a copy of the License at
+
+ http://www.apache.org/licenses/LICENSE-2.0
+
+ Unless required by applicable law or agreed to in writing, software
+ distributed under the License is distributed on an "AS IS" BASIS,
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ See the License for the specific language governing permissions and
+ limitations under the License.
+ -->
+<assembly>
+ <id>pkg</id>
+ <formats>
+ <format>zip</format>
+ </formats>
+ <includeBaseDirectory>false</includeBaseDirectory>
+ <fileSets>
+ <fileSet>
+ <directory>src/main/content</directory>
+ <outputDirectory></outputDirectory>
+ </fileSet>
+ </fileSets>
+ <dependencySets>
+ <dependencySet>
+ <useProjectArtifact>true</useProjectArtifact>
+ <outputDirectory>META-INF/vault/hooks</outputDirectory>
+ <includes>
+ <include>org.apache.jackrabbit.vault:vault-hook-externalclass-test</include>
+ </includes>
+ </dependencySet>
+ </dependencySets>
+</assembly>
\ No newline at end of file