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.obr/.classpath b/sigil/org.cauldron.sigil.obr/.classpath
new file mode 100644
index 0000000..64c5e31
--- /dev/null
+++ b/sigil/org.cauldron.sigil.obr/.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.obr/.project b/sigil/org.cauldron.sigil.obr/.project
new file mode 100644
index 0000000..7990e04
--- /dev/null
+++ b/sigil/org.cauldron.sigil.obr/.project
@@ -0,0 +1,28 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<projectDescription>
+	<name>org.cauldron.sigil.obr</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.obr/.settings/org.eclipse.jdt.core.prefs b/sigil/org.cauldron.sigil.obr/.settings/org.eclipse.jdt.core.prefs
new file mode 100644
index 0000000..902de9d
--- /dev/null
+++ b/sigil/org.cauldron.sigil.obr/.settings/org.eclipse.jdt.core.prefs
@@ -0,0 +1,7 @@
+#Wed Aug 27 13:25:05 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.obr/META-INF/MANIFEST.MF b/sigil/org.cauldron.sigil.obr/META-INF/MANIFEST.MF
new file mode 100644
index 0000000..9a09325
--- /dev/null
+++ b/sigil/org.cauldron.sigil.obr/META-INF/MANIFEST.MF
@@ -0,0 +1,16 @@
+Manifest-Version: 1.0
+Bundle-ManifestVersion: 2
+Bundle-Name: OBR Plug-in
+Bundle-SymbolicName: org.cauldron.sigil.obr;singleton:=true
+Bundle-Version: 0.8.0.qualifier
+Bundle-Activator: org.cauldron.sigil.obr.Activator
+Bundle-Vendor: Paremus Ltd
+Require-Bundle: org.eclipse.ui,
+ org.eclipse.core.runtime,
+ org.cauldron.sigil.core;bundle-version="0.6.0",
+ org.cauldron.sigil.ui;bundle-version="0.6.0",
+ org.cauldron.bld.core
+Bundle-RequiredExecutionEnvironment: J2SE-1.5
+Bundle-ActivationPolicy: lazy
+Import-Package: org.cauldron.bld.obr,
+ org.cauldron.sigil.model
diff --git a/sigil/org.cauldron.sigil.obr/build.properties b/sigil/org.cauldron.sigil.obr/build.properties
new file mode 100644
index 0000000..e9863e2
--- /dev/null
+++ b/sigil/org.cauldron.sigil.obr/build.properties
@@ -0,0 +1,5 @@
+source.. = src/
+output.. = bin/
+bin.includes = META-INF/,\
+               .,\
+               plugin.xml
diff --git a/sigil/org.cauldron.sigil.obr/plugin.xml b/sigil/org.cauldron.sigil.obr/plugin.xml
new file mode 100644
index 0000000..03b79c1
--- /dev/null
+++ b/sigil/org.cauldron.sigil.obr/plugin.xml
@@ -0,0 +1,39 @@
+<?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.cauldron.sigil.repositoryprovider">
+      <provider
+            class="org.cauldron.bld.obr.OBRRepositoryProvider"
+            dynamic="true"
+            id="org.cauldron.sigil.obr.provider"
+            type="OSGi Bundle Repository (OBR)">
+      </provider>
+   </extension>
+   <extension
+         point="org.cauldron.sigil.ui.repositorywizard">
+      <wizard
+            class="org.cauldron.sigil.obr.OBRRepositoryWizard"
+            repository="org.cauldron.sigil.obr.provider">
+      </wizard>
+   </extension>
+
+</plugin>
diff --git a/sigil/org.cauldron.sigil.obr/src/org/cauldron/sigil/obr/Activator.java b/sigil/org.cauldron.sigil.obr/src/org/cauldron/sigil/obr/Activator.java
new file mode 100644
index 0000000..4bad94b
--- /dev/null
+++ b/sigil/org.cauldron.sigil.obr/src/org/cauldron/sigil/obr/Activator.java
@@ -0,0 +1,69 @@
+/*
+ * 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.obr;
+
+import org.eclipse.ui.plugin.AbstractUIPlugin;
+import org.osgi.framework.BundleContext;
+
+/**
+ * The activator class controls the plug-in life cycle
+ */
+public class Activator extends AbstractUIPlugin {
+
+	// The plug-in ID
+	public static final String PLUGIN_ID = "org.cauldron.sigil.obr";
+
+	// The shared instance
+	private static Activator plugin;
+	
+	/**
+	 * The constructor
+	 */
+	public Activator() {
+	}
+
+	/*
+	 * (non-Javadoc)
+	 * @see org.eclipse.ui.plugin.AbstractUIPlugin#start(org.osgi.framework.BundleContext)
+	 */
+	public void start(BundleContext context) throws Exception {
+		super.start(context);
+		plugin = this;
+	}
+
+	/*
+	 * (non-Javadoc)
+	 * @see org.eclipse.ui.plugin.AbstractUIPlugin#stop(org.osgi.framework.BundleContext)
+	 */
+	public void stop(BundleContext context) throws Exception {
+		plugin = null;
+		super.stop(context);
+	}
+
+	/**
+	 * Returns the shared instance
+	 *
+	 * @return the shared instance
+	 */
+	public static Activator getDefault() {
+		return plugin;
+	}
+
+}
diff --git a/sigil/org.cauldron.sigil.obr/src/org/cauldron/sigil/obr/OBRRepositoryWizard.java b/sigil/org.cauldron.sigil.obr/src/org/cauldron/sigil/obr/OBRRepositoryWizard.java
new file mode 100644
index 0000000..79e0e72
--- /dev/null
+++ b/sigil/org.cauldron.sigil.obr/src/org/cauldron/sigil/obr/OBRRepositoryWizard.java
@@ -0,0 +1,30 @@
+/*
+ * 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.obr;
+
+import org.cauldron.sigil.ui.wizard.repository.RepositoryWizard;
+
+public class OBRRepositoryWizard extends RepositoryWizard {
+	
+	@Override
+	public void addPages() {
+		addPage( new OBRRepositoryWizardPage(this) );
+	}
+}
diff --git a/sigil/org.cauldron.sigil.obr/src/org/cauldron/sigil/obr/OBRRepositoryWizardPage.java b/sigil/org.cauldron.sigil.obr/src/org/cauldron/sigil/obr/OBRRepositoryWizardPage.java
new file mode 100644
index 0000000..a607ac1
--- /dev/null
+++ b/sigil/org.cauldron.sigil.obr/src/org/cauldron/sigil/obr/OBRRepositoryWizardPage.java
@@ -0,0 +1,111 @@
+/*
+ * 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.obr;
+
+import java.io.File;
+import java.net.MalformedURLException;
+import java.net.URL;
+
+import org.cauldron.sigil.ui.wizard.repository.RepositoryWizard;
+import org.cauldron.sigil.ui.wizard.repository.RepositoryWizardPage;
+import org.eclipse.core.runtime.IPath;
+import org.eclipse.jface.preference.BooleanFieldEditor;
+import org.eclipse.jface.preference.DirectoryFieldEditor;
+import org.eclipse.jface.preference.StringFieldEditor;
+import org.eclipse.jface.wizard.IWizardPage;
+import org.eclipse.swt.events.ModifyEvent;
+import org.eclipse.swt.events.ModifyListener;
+
+public class OBRRepositoryWizardPage extends RepositoryWizardPage implements IWizardPage {
+
+	private StringFieldEditor urlEditor;
+	private StringFieldEditor cacheEditor;
+
+	protected OBRRepositoryWizardPage(RepositoryWizard parent) {
+		super("OSGi Bundle Repository", parent);
+	}
+
+	@Override
+	public void createFieldEditors() {
+		createField( urlEditor = new StringFieldEditor("url", "URL:", getFieldEditorParent()) );
+		createField( cacheEditor = new DirectoryFieldEditor("cache", "Cache:", getFieldEditorParent()) );
+		addField( new BooleanFieldEditor( "inmemory", "In Memory:", getFieldEditorParent() ));
+	}
+
+	private void createField(StringFieldEditor editor) {
+		editor.getTextControl(getFieldEditorParent()).addModifyListener( new ModifyListener() {
+			public void modifyText(ModifyEvent e) {
+				checkPageComplete();
+			}
+		});
+		addField(editor);
+	}
+
+	@Override
+	protected void checkPageComplete() {
+		super.checkPageComplete();
+		if ( isPageComplete() && checkURLComplete() ) {
+			checkCacheComplete();
+		}
+	}
+
+	private boolean checkCacheComplete() {
+		setPageComplete(cacheEditor.getStringValue().length() > 0);
+		
+		if ( isPageComplete() ) {
+			if ( new File( cacheEditor.getStringValue() ).isDirectory() ) {
+				setErrorMessage(null);				
+			}
+			else {
+				setErrorMessage("Invalid cache directory");
+				setPageComplete(false);
+			}
+		}
+		
+		return isPageComplete();
+	}
+
+	private boolean checkURLComplete() {
+		setPageComplete(urlEditor.getStringValue().length() > 0);
+		
+		if ( isPageComplete() ) {
+			try {
+				new URL(urlEditor.getStringValue());
+				setErrorMessage(null);
+			}
+			catch (MalformedURLException e) {
+				if ( !new File(urlEditor.getStringValue()).isFile() ) {
+					setErrorMessage("Invalid repository url: " + e.getMessage());
+					setPageComplete(false);
+				}
+			}
+		}
+		
+		return isPageComplete();
+	}
+
+	@Override
+	public void storeFields() {
+		super.storeFields();
+		IPath dir = Activator.getDefault().getStateLocation();
+		getModel().getPreferences().setValue( "index", dir.append( getModel().getId() + ".obr" ).toOSString() );
+	}
+	
+}