You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@sling.apache.org by ro...@apache.org on 2014/05/16 16:21:08 UTC
svn commit: r1595203 - in
/sling/trunk/tooling/ide/eclipse-test/src/org/apache/sling/ide/test/impl/helpers:
EclipseResourceMatchers.java HasFileMatcher.java HasFolderMatcher.java
Author: rombert
Date: Fri May 16 14:21:07 2014
New Revision: 1595203
URL: http://svn.apache.org/r1595203
Log:
SLING-3161 - SlingIDE Import Content wizard should respect .vltignore
files
Added EclipseResourceMatchers
Added:
sling/trunk/tooling/ide/eclipse-test/src/org/apache/sling/ide/test/impl/helpers/EclipseResourceMatchers.java (with props)
sling/trunk/tooling/ide/eclipse-test/src/org/apache/sling/ide/test/impl/helpers/HasFileMatcher.java (with props)
sling/trunk/tooling/ide/eclipse-test/src/org/apache/sling/ide/test/impl/helpers/HasFolderMatcher.java (with props)
Added: sling/trunk/tooling/ide/eclipse-test/src/org/apache/sling/ide/test/impl/helpers/EclipseResourceMatchers.java
URL: http://svn.apache.org/viewvc/sling/trunk/tooling/ide/eclipse-test/src/org/apache/sling/ide/test/impl/helpers/EclipseResourceMatchers.java?rev=1595203&view=auto
==============================================================================
--- sling/trunk/tooling/ide/eclipse-test/src/org/apache/sling/ide/test/impl/helpers/EclipseResourceMatchers.java (added)
+++ sling/trunk/tooling/ide/eclipse-test/src/org/apache/sling/ide/test/impl/helpers/EclipseResourceMatchers.java Fri May 16 14:21:07 2014
@@ -0,0 +1,31 @@
+/*
+ * 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.sling.ide.test.impl.helpers;
+
+import org.eclipse.core.resources.IProject;
+import org.hamcrest.Matcher;
+
+public class EclipseResourceMatchers {
+
+ public static Matcher<IProject> hasFile(String path, byte[] contents) {
+ return new HasFileMatcher(path, contents);
+ }
+
+ public static Matcher<IProject> hasFolder(String path) {
+ return new HasFolderMatcher(path);
+ }
+}
Propchange: sling/trunk/tooling/ide/eclipse-test/src/org/apache/sling/ide/test/impl/helpers/EclipseResourceMatchers.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: sling/trunk/tooling/ide/eclipse-test/src/org/apache/sling/ide/test/impl/helpers/EclipseResourceMatchers.java
------------------------------------------------------------------------------
svn:keywords = Author Date Id Revision Rev URL
Added: sling/trunk/tooling/ide/eclipse-test/src/org/apache/sling/ide/test/impl/helpers/HasFileMatcher.java
URL: http://svn.apache.org/viewvc/sling/trunk/tooling/ide/eclipse-test/src/org/apache/sling/ide/test/impl/helpers/HasFileMatcher.java?rev=1595203&view=auto
==============================================================================
--- sling/trunk/tooling/ide/eclipse-test/src/org/apache/sling/ide/test/impl/helpers/HasFileMatcher.java (added)
+++ sling/trunk/tooling/ide/eclipse-test/src/org/apache/sling/ide/test/impl/helpers/HasFileMatcher.java Fri May 16 14:21:07 2014
@@ -0,0 +1,88 @@
+/*
+ * 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.sling.ide.test.impl.helpers;
+
+import java.io.ByteArrayOutputStream;
+import java.io.IOException;
+import java.io.InputStream;
+import java.util.Arrays;
+
+import org.apache.commons.io.IOUtils;
+import org.eclipse.core.resources.IFile;
+import org.eclipse.core.resources.IProject;
+import org.eclipse.core.resources.IResource;
+import org.eclipse.core.runtime.CoreException;
+import org.hamcrest.Description;
+import org.hamcrest.TypeSafeMatcher;
+
+public class HasFileMatcher extends TypeSafeMatcher<IProject> {
+
+ public static final HasFileMatcher hasFile(String filePath, byte[] contents) {
+ return new HasFileMatcher(filePath, contents);
+ }
+
+ private final String fileName;
+ private final byte[] contents;
+
+
+ public HasFileMatcher(String fileName, byte[] contents) {
+ this.fileName = fileName;
+ this.contents = contents;
+ }
+
+ @Override
+ public void describeTo(Description description) {
+ description.appendText("project with a filed named " + fileName + " and contents (elided)");
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see org.hamcrest.TypeSafeMatcher#matchesSafely(java.lang.Object)
+ */
+ @Override
+ protected boolean matchesSafely(IProject item) {
+ if (item == null) {
+ return false;
+ }
+
+ IResource maybeFile = item.findMember(fileName);
+
+ if (maybeFile == null || maybeFile.getType() != IResource.FILE) {
+ return false;
+ }
+
+ IFile file = (IFile) maybeFile;
+ ByteArrayOutputStream out = new ByteArrayOutputStream();
+
+ InputStream in = null;
+ try {
+ in = file.getContents();
+
+ IOUtils.copy(in, out);
+ } catch (CoreException e) {
+ throw new RuntimeException(e);
+ } catch (IOException e) {
+ throw new RuntimeException(e);
+ } finally {
+ IOUtils.closeQuietly(in);
+ }
+
+ return Arrays.equals(out.toByteArray(), contents);
+ }
+
+}
\ No newline at end of file
Propchange: sling/trunk/tooling/ide/eclipse-test/src/org/apache/sling/ide/test/impl/helpers/HasFileMatcher.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: sling/trunk/tooling/ide/eclipse-test/src/org/apache/sling/ide/test/impl/helpers/HasFileMatcher.java
------------------------------------------------------------------------------
svn:keywords = Author Date Id Revision Rev URL
Added: sling/trunk/tooling/ide/eclipse-test/src/org/apache/sling/ide/test/impl/helpers/HasFolderMatcher.java
URL: http://svn.apache.org/viewvc/sling/trunk/tooling/ide/eclipse-test/src/org/apache/sling/ide/test/impl/helpers/HasFolderMatcher.java?rev=1595203&view=auto
==============================================================================
--- sling/trunk/tooling/ide/eclipse-test/src/org/apache/sling/ide/test/impl/helpers/HasFolderMatcher.java (added)
+++ sling/trunk/tooling/ide/eclipse-test/src/org/apache/sling/ide/test/impl/helpers/HasFolderMatcher.java Fri May 16 14:21:07 2014
@@ -0,0 +1,58 @@
+/*
+ * 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.sling.ide.test.impl.helpers;
+
+import org.eclipse.core.resources.IProject;
+import org.eclipse.core.resources.IResource;
+import org.hamcrest.Description;
+import org.hamcrest.TypeSafeMatcher;
+
+public class HasFolderMatcher extends TypeSafeMatcher<IProject> {
+
+ public static final HasFolderMatcher hasFolder(String folderPath) {
+ return new HasFolderMatcher(folderPath);
+ }
+
+ private final String folderName;
+
+
+ public HasFolderMatcher(String folderPath) {
+ this.folderName = folderPath;
+ }
+
+ @Override
+ public void describeTo(Description description) {
+ description.appendText("project with a folder located at " + folderName);
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see org.hamcrest.TypeSafeMatcher#matchesSafely(java.lang.Object)
+ */
+ @Override
+ protected boolean matchesSafely(IProject item) {
+ if (item == null) {
+ return false;
+ }
+
+ IResource maybeFolder = item.findMember(folderName);
+
+ return maybeFolder != null && maybeFolder.getType() == IResource.FOLDER;
+ }
+
+}
\ No newline at end of file
Propchange: sling/trunk/tooling/ide/eclipse-test/src/org/apache/sling/ide/test/impl/helpers/HasFolderMatcher.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: sling/trunk/tooling/ide/eclipse-test/src/org/apache/sling/ide/test/impl/helpers/HasFolderMatcher.java
------------------------------------------------------------------------------
svn:keywords = Author Date Id Revision Rev URL