Initial commit of Sigil contribution. (FELIX-1142)
git-svn-id: https://svn.apache.org/repos/asf/felix/trunk@793581 13f79535-47bb-0310-9956-ffa450edef68
diff --git a/sigil/org.cauldron.sigil.utils/.classpath b/sigil/org.cauldron.sigil.utils/.classpath
new file mode 100644
index 0000000..64c5e31
--- /dev/null
+++ b/sigil/org.cauldron.sigil.utils/.classpath
@@ -0,0 +1,7 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<classpath>
+ <classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/J2SE-1.5"/>
+ <classpathentry kind="con" path="org.eclipse.pde.core.requiredPlugins"/>
+ <classpathentry kind="src" path="src"/>
+ <classpathentry kind="output" path="bin"/>
+</classpath>
diff --git a/sigil/org.cauldron.sigil.utils/.project b/sigil/org.cauldron.sigil.utils/.project
new file mode 100644
index 0000000..0e1390a
--- /dev/null
+++ b/sigil/org.cauldron.sigil.utils/.project
@@ -0,0 +1,28 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<projectDescription>
+ <name>org.cauldron.sigil.utils</name>
+ <comment></comment>
+ <projects>
+ </projects>
+ <buildSpec>
+ <buildCommand>
+ <name>org.eclipse.jdt.core.javabuilder</name>
+ <arguments>
+ </arguments>
+ </buildCommand>
+ <buildCommand>
+ <name>org.eclipse.pde.ManifestBuilder</name>
+ <arguments>
+ </arguments>
+ </buildCommand>
+ <buildCommand>
+ <name>org.eclipse.pde.SchemaBuilder</name>
+ <arguments>
+ </arguments>
+ </buildCommand>
+ </buildSpec>
+ <natures>
+ <nature>org.eclipse.pde.PluginNature</nature>
+ <nature>org.eclipse.jdt.core.javanature</nature>
+ </natures>
+</projectDescription>
diff --git a/sigil/org.cauldron.sigil.utils/.settings/org.eclipse.jdt.core.prefs b/sigil/org.cauldron.sigil.utils/.settings/org.eclipse.jdt.core.prefs
new file mode 100644
index 0000000..0710b5a
--- /dev/null
+++ b/sigil/org.cauldron.sigil.utils/.settings/org.eclipse.jdt.core.prefs
@@ -0,0 +1,7 @@
+#Tue Aug 12 11:45:38 BST 2008
+eclipse.preferences.version=1
+org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.5
+org.eclipse.jdt.core.compiler.compliance=1.5
+org.eclipse.jdt.core.compiler.problem.assertIdentifier=error
+org.eclipse.jdt.core.compiler.problem.enumIdentifier=error
+org.eclipse.jdt.core.compiler.source=1.5
diff --git a/sigil/org.cauldron.sigil.utils/META-INF/MANIFEST.MF b/sigil/org.cauldron.sigil.utils/META-INF/MANIFEST.MF
new file mode 100644
index 0000000..7df73f4
--- /dev/null
+++ b/sigil/org.cauldron.sigil.utils/META-INF/MANIFEST.MF
@@ -0,0 +1,12 @@
+Manifest-Version: 1.0
+Bundle-ManifestVersion: 2
+Bundle-Name: Sigil Utils Plug-in
+Bundle-SymbolicName: org.cauldron.sigil.utils;singleton:=true
+Bundle-Version: 0.8.0.qualifier
+Require-Bundle: org.eclipse.core.runtime
+Bundle-ActivationPolicy: lazy
+Bundle-RequiredExecutionEnvironment: J2SE-1.5
+Import-Package: org.eclipse.core.expressions,
+ org.eclipse.core.resources,
+ org.eclipse.ui
+Export-Package: org.cauldron.sigil.utils
diff --git a/sigil/org.cauldron.sigil.utils/build.properties b/sigil/org.cauldron.sigil.utils/build.properties
new file mode 100644
index 0000000..e9863e2
--- /dev/null
+++ b/sigil/org.cauldron.sigil.utils/build.properties
@@ -0,0 +1,5 @@
+source.. = src/
+output.. = bin/
+bin.includes = META-INF/,\
+ .,\
+ plugin.xml
diff --git a/sigil/org.cauldron.sigil.utils/plugin.xml b/sigil/org.cauldron.sigil.utils/plugin.xml
new file mode 100644
index 0000000..0d14f33
--- /dev/null
+++ b/sigil/org.cauldron.sigil.utils/plugin.xml
@@ -0,0 +1,47 @@
+<?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.
+-->
+<?eclipse version="3.2"?>
+<plugin>
+ <extension
+ point="org.eclipse.core.expressions.propertyTesters">
+ <propertyTester
+ class="org.cauldron.sigil.utils.properties.EditorPropertyTester"
+ id="org.cauldron.sigil.utils.editorPropertyTester"
+ namespace="org.cauldron.sigil"
+ properties="isEditorOfType"
+ type="org.eclipse.ui.IWorkbenchPart">
+ </propertyTester>
+ <propertyTester
+ class="org.cauldron.sigil.utils.properties.PartKindPropertyTester"
+ id="org.cauldron.sigil.runtime.PartKindPropertyTester"
+ namespace="org.cauldron.sigil"
+ properties="partKind,partId"
+ type="org.eclipse.ui.IWorkbenchPart">
+ </propertyTester>
+ <propertyTester
+ class="org.cauldron.sigil.utils.properties.ResourceTypePropertyTester"
+ id="org.cauldron.sigil.utils.ResourcePropertyTester"
+ namespace="org.cauldron.sigil"
+ properties="isResourceOfType"
+ type="org.eclipse.core.resources.IResource">
+ </propertyTester>
+ </extension>
+
+</plugin>
diff --git a/sigil/org.cauldron.sigil.utils/src/org/cauldron/sigil/utils/GlobCompiler.java b/sigil/org.cauldron.sigil.utils/src/org/cauldron/sigil/utils/GlobCompiler.java
new file mode 100644
index 0000000..401c390
--- /dev/null
+++ b/sigil/org.cauldron.sigil.utils/src/org/cauldron/sigil/utils/GlobCompiler.java
@@ -0,0 +1,54 @@
+/*
+ * 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.cauldron.sigil.utils;
+
+import java.util.regex.Pattern;
+
+public class GlobCompiler {
+ public static final Pattern compile(String glob) {
+ char[] chars = glob.toCharArray();
+ if ( chars.length > 0 ) {
+ StringBuilder builder = new StringBuilder(chars.length + 5);
+
+ builder.append('^');
+
+ for (char c : chars) {
+ switch ( c ) {
+ case '*':
+ builder.append(".*");
+ break;
+ case '.':
+ builder.append("\\.");
+ break;
+ case '$':
+ builder.append( "\\$" );
+ break;
+ default:
+ builder.append( c );
+ }
+ }
+
+ return Pattern.compile(builder.toString());
+ }
+ else {
+ return Pattern.compile(glob);
+ }
+ }
+}
diff --git a/sigil/org.cauldron.sigil.utils/src/org/cauldron/sigil/utils/PathHelper.java b/sigil/org.cauldron.sigil.utils/src/org/cauldron/sigil/utils/PathHelper.java
new file mode 100644
index 0000000..00de2b9
--- /dev/null
+++ b/sigil/org.cauldron.sigil.utils/src/org/cauldron/sigil/utils/PathHelper.java
@@ -0,0 +1,43 @@
+/*
+ * 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.cauldron.sigil.utils;
+
+import java.io.File;
+import java.util.List;
+import java.util.regex.Pattern;
+
+import org.eclipse.core.runtime.IPath;
+import org.eclipse.core.runtime.Path;
+
+public class PathHelper {
+
+ public static void scanFiles(List<IPath> paths, IPath path, String pattern, boolean recurse) {
+ Pattern p = GlobCompiler.compile(pattern);
+
+ for ( File f : path.toFile().listFiles() ) {
+ if ( f.isDirectory() && recurse ) {
+ scanFiles( paths, new Path(f.getAbsolutePath()), pattern, recurse);
+ }
+ else if ( f.isFile() && p.matcher(f.getName()).matches() ) {
+ paths.add( new Path(f.getAbsolutePath()) );
+ }
+ }
+ }
+}
diff --git a/sigil/org.cauldron.sigil.utils/src/org/cauldron/sigil/utils/SigilUtils.java b/sigil/org.cauldron.sigil.utils/src/org/cauldron/sigil/utils/SigilUtils.java
new file mode 100644
index 0000000..6f379d6
--- /dev/null
+++ b/sigil/org.cauldron.sigil.utils/src/org/cauldron/sigil/utils/SigilUtils.java
@@ -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.cauldron.sigil.utils;
+
+import org.eclipse.core.resources.IResource;
+import org.eclipse.core.runtime.Platform;
+import org.eclipse.core.runtime.content.IContentType;
+
+public final class SigilUtils {
+ private SigilUtils () {
+ }
+
+ public static boolean isResourceType(IResource resource, String type) {
+ IContentType[] types = Platform.getContentTypeManager().findContentTypesFor(resource.getName());
+ for (IContentType contentType : types) {
+ if(contentType.getId().equals(type)) {
+ return true;
+ }
+ }
+ return false;
+ }
+}
diff --git a/sigil/org.cauldron.sigil.utils/src/org/cauldron/sigil/utils/properties/EditorPropertyTester.java b/sigil/org.cauldron.sigil.utils/src/org/cauldron/sigil/utils/properties/EditorPropertyTester.java
new file mode 100644
index 0000000..ce6ad86
--- /dev/null
+++ b/sigil/org.cauldron.sigil.utils/src/org/cauldron/sigil/utils/properties/EditorPropertyTester.java
@@ -0,0 +1,51 @@
+/*
+ * 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.cauldron.sigil.utils.properties;
+
+import org.cauldron.sigil.utils.SigilUtils;
+import org.eclipse.core.expressions.PropertyTester;
+import org.eclipse.core.resources.IFile;
+import org.eclipse.ui.IEditorInput;
+import org.eclipse.ui.IEditorPart;
+import org.eclipse.ui.IFileEditorInput;
+import org.eclipse.ui.IWorkbenchPart;
+
+public class EditorPropertyTester extends PropertyTester {
+
+ public boolean test(Object receiver, String property, Object[] args, Object expectedValue) {
+ IWorkbenchPart part = (IWorkbenchPart) receiver;
+
+ boolean result = false;
+
+ if(part instanceof IEditorPart) {
+ IEditorInput input = ((IEditorPart) part).getEditorInput();
+ if(input instanceof IFileEditorInput) {
+ IFile file = ((IFileEditorInput) input).getFile();
+
+ if("isEditorOfType".equals(property)) {
+ result = SigilUtils.isResourceType(file, (String) expectedValue);
+ }
+ }
+ }
+
+ return result;
+ }
+
+}
diff --git a/sigil/org.cauldron.sigil.utils/src/org/cauldron/sigil/utils/properties/PartKindPropertyTester.java b/sigil/org.cauldron.sigil.utils/src/org/cauldron/sigil/utils/properties/PartKindPropertyTester.java
new file mode 100644
index 0000000..b0dceee
--- /dev/null
+++ b/sigil/org.cauldron.sigil.utils/src/org/cauldron/sigil/utils/properties/PartKindPropertyTester.java
@@ -0,0 +1,50 @@
+/*
+ * 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.cauldron.sigil.utils.properties;
+
+import org.eclipse.core.expressions.PropertyTester;
+import org.eclipse.ui.IEditorPart;
+import org.eclipse.ui.IViewPart;
+import org.eclipse.ui.IWorkbenchPart;
+
+public class PartKindPropertyTester extends PropertyTester{
+
+ public boolean test(Object receiver, String property, Object[] args, Object expectedValue) {
+ IWorkbenchPart part = (IWorkbenchPart) receiver;
+
+ Object value;
+ if("partKind".equals(property)) {
+ if(part instanceof IEditorPart) {
+ value = "editor";
+ } else if(part instanceof IViewPart) {
+ value = "view";
+ } else {
+ value = null;
+ }
+ } else if("partId".equals(property)) {
+ value = part.getSite().getId();
+ } else {
+ value = null;
+ }
+
+ return expectedValue.equals(value);
+ }
+
+}
diff --git a/sigil/org.cauldron.sigil.utils/src/org/cauldron/sigil/utils/properties/ResourceTypePropertyTester.java b/sigil/org.cauldron.sigil.utils/src/org/cauldron/sigil/utils/properties/ResourceTypePropertyTester.java
new file mode 100644
index 0000000..efc32e3
--- /dev/null
+++ b/sigil/org.cauldron.sigil.utils/src/org/cauldron/sigil/utils/properties/ResourceTypePropertyTester.java
@@ -0,0 +1,52 @@
+/*
+ * 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.cauldron.sigil.utils.properties;
+
+import org.eclipse.core.expressions.PropertyTester;
+import org.eclipse.core.resources.IResource;
+import org.eclipse.core.runtime.Platform;
+import org.eclipse.core.runtime.content.IContentType;
+
+public class ResourceTypePropertyTester extends PropertyTester {
+
+ public boolean test(Object receiver, String property, Object[] args, Object expectedValue) {
+ if (!(receiver instanceof IResource)) {
+ return false;
+ }
+
+ boolean result = false;
+
+ IResource resource = (IResource) receiver;
+ if ("isResourceOfType".equals(property)) {
+ IContentType[] types = Platform.getContentTypeManager().findContentTypesFor(
+ resource.getName());
+
+ for (IContentType type : types) {
+ if (type.getId().equals(expectedValue)) {
+ result = true;
+ break;
+ }
+ }
+ }
+
+ return result;
+ }
+
+}