Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorCarsten Hiesserich2015-09-06 15:31:56 -0400
committerCarsten Hiesserich2015-09-07 09:57:48 -0400
commita44276000440b9096aabaabd862e1d01addda23a (patch)
treeeb06922427d145ecdcabab1bd3105522dd8cbf06
parent2988515ed72d20fc9d45b823c43dab9690d1d996 (diff)
downloadorg.eclipse.mylyn.docs.vex-a44276000440b9096aabaabd862e1d01addda23a.tar.gz
org.eclipse.mylyn.docs.vex-a44276000440b9096aabaabd862e1d01addda23a.tar.xz
org.eclipse.mylyn.docs.vex-a44276000440b9096aabaabd862e1d01addda23a.zip
use relative file paths for plugin project css files
When loading a plugin project, the file paths to css resources where replaced with absolute URI's. As resources belong to the project, the path should be relative. Change-Id: I3479e80dbecd440fb74763c1b5a1be484b7f3b11 Signed-off-by: Carsten Hiesserich <carsten.hie@gmail.com>
-rw-r--r--org.eclipse.vex.ui.tests/src/org/eclipse/vex/ui/internal/config/tests/PluginStyleConfigTest.java73
-rw-r--r--org.eclipse.vex.ui/src/org/eclipse/vex/ui/internal/config/ConfigSource.java21
-rw-r--r--org.eclipse.vex.ui/src/org/eclipse/vex/ui/internal/config/StyleFactory.java4
-rw-r--r--org.eclipse.vex.ui/src/org/eclipse/vex/ui/internal/config/StylePropertyPage.java12
4 files changed, 97 insertions, 13 deletions
diff --git a/org.eclipse.vex.ui.tests/src/org/eclipse/vex/ui/internal/config/tests/PluginStyleConfigTest.java b/org.eclipse.vex.ui.tests/src/org/eclipse/vex/ui/internal/config/tests/PluginStyleConfigTest.java
index 36fdadd3..3dd28dba 100644
--- a/org.eclipse.vex.ui.tests/src/org/eclipse/vex/ui/internal/config/tests/PluginStyleConfigTest.java
+++ b/org.eclipse.vex.ui.tests/src/org/eclipse/vex/ui/internal/config/tests/PluginStyleConfigTest.java
@@ -14,15 +14,18 @@ import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertTrue;
+import java.io.ByteArrayInputStream;
import java.lang.reflect.Field;
import java.util.ArrayList;
+import org.eclipse.core.resources.IFile;
import org.eclipse.core.resources.IProject;
import org.eclipse.core.runtime.CoreException;
import org.eclipse.swt.widgets.Display;
import org.eclipse.swt.widgets.Shell;
import org.eclipse.swt.widgets.Table;
import org.eclipse.swt.widgets.TableItem;
+import org.eclipse.swt.widgets.Text;
import org.eclipse.vex.ui.internal.config.ConfigLoaderJob;
import org.eclipse.vex.ui.internal.config.ConfigurationRegistry;
import org.eclipse.vex.ui.internal.config.ConfigurationRegistryImpl;
@@ -41,6 +44,7 @@ import org.junit.Test;
public class PluginStyleConfigTest {
private IProject pluginProject;
+ private ConfigurationRegistry configurationRegistry;
@After
public void dispose() {
@@ -51,6 +55,11 @@ public class PluginStyleConfigTest {
}
}
pluginProject = null;
+
+ if (configurationRegistry != null) {
+ configurationRegistry.dispose();
+ }
+ configurationRegistry = null;
}
/**
@@ -58,13 +67,14 @@ public class PluginStyleConfigTest {
*/
@Test
public void testCssPropertyPage() throws CoreException, NoSuchFieldException, SecurityException, IllegalArgumentException, IllegalAccessException {
- final IProject pluginProject = PluginProjectTest.createVexPluginProject("PropertyPageTest");
+ pluginProject = PluginProjectTest.createVexPluginProject("PropertyPageTest");
final Display display = Display.getCurrent();
final Shell shell = new Shell(display);
final StylePropertyPage page = new StylePropertyPage();
- page.setElement(pluginProject.getFile(PluginProjectTest.CSS_FILE_NAME));
+ final IFile cssFile = pluginProject.getFile(PluginProjectTest.CSS_FILE_NAME);
+ page.setElement(cssFile);
page.createControl(shell);
// Make sure the table contains the style declared in the plugin project
@@ -85,9 +95,9 @@ public class PluginStyleConfigTest {
@Test
public void testDoctypeStyle() throws Exception {
- final IProject pluginProject = PluginProjectTest.createVexPluginProject("PropertyPageTest");
+ pluginProject = PluginProjectTest.createVexPluginProject("PropertyPageTest");
- final ConfigurationRegistry configurationRegistry = new ConfigurationRegistryImpl(new ConfigLoaderJob());
+ configurationRegistry = new ConfigurationRegistryImpl(new ConfigLoaderJob());
configurationRegistry.loadConfigurations();
assertNotNull(configurationRegistry.getPluginProject(pluginProject));
@@ -97,6 +107,59 @@ public class PluginStyleConfigTest {
assertEquals(styles[0], configurationRegistry.getStyle("PropertyPageTest." + PluginProjectTest.CSS_ID));
- configurationRegistry.dispose();
+ }
+
+ @Test
+ public void testAddStyle() throws Exception {
+ pluginProject = PluginProjectTest.createVexPluginProject("PropertyPageTest");
+
+ final Display display = Display.getCurrent();
+ final Shell shell = new Shell(display);
+ final StylePropertyPage page = new StylePropertyPage();
+
+ // Create a new .css file and open the property page
+ final IFile file = pluginProject.getFile("test_new.css");
+ file.create(new ByteArrayInputStream(new byte[0]), true, null);
+ page.setElement(file);
+ page.createControl(shell);
+
+ // Select the doctype
+ Field f = page.getClass().getDeclaredField("doctypesTable");
+ f.setAccessible(true);
+ final Table doctypesTable = (Table) f.get(page);
+ for (final TableItem item : doctypesTable.getItems()) {
+ if (item.getText().equals(PluginProjectTest.DTD_FILE_NAME)) {
+ item.setChecked(true);
+ }
+ }
+
+ // Set the styles's name
+ f = page.getClass().getDeclaredField("nameText");
+ f.setAccessible(true);
+ final Text nameText = (Text) f.get(page);
+ nameText.setText("css test name");
+
+ // Write the changed configuration
+ page.performOk();
+ page.dispose();
+
+ // Reload the project
+ pluginProject.close(null);
+ pluginProject.open(null);
+
+ //
+ configurationRegistry = new ConfigurationRegistryImpl(new ConfigLoaderJob());
+ configurationRegistry.loadConfigurations();
+
+ Style newStyle = null;
+ final DocumentType doctype = configurationRegistry.getDocumentType(PluginProjectTest.DTD_DOCTYPE_ID, null);
+ for (final Style style : configurationRegistry.getStyles(doctype)) {
+ if (style.getName().equals("css test name")) {
+ newStyle = style;
+ }
+ }
+
+ assertNotNull("New style should be present an apply to the selected doctype", newStyle);
+ assertEquals("test_new.css", newStyle.getResourceUri().toString());
}
}
diff --git a/org.eclipse.vex.ui/src/org/eclipse/vex/ui/internal/config/ConfigSource.java b/org.eclipse.vex.ui/src/org/eclipse/vex/ui/internal/config/ConfigSource.java
index f6c5fa28..ad0000a4 100644
--- a/org.eclipse.vex.ui/src/org/eclipse/vex/ui/internal/config/ConfigSource.java
+++ b/org.eclipse.vex.ui/src/org/eclipse/vex/ui/internal/config/ConfigSource.java
@@ -12,7 +12,9 @@
package org.eclipse.vex.ui.internal.config;
import java.io.IOException;
+import java.net.MalformedURLException;
import java.net.URI;
+import java.net.URISyntaxException;
import java.net.URL;
import java.text.MessageFormat;
import java.util.ArrayList;
@@ -88,9 +90,11 @@ public abstract class ConfigSource {
return null;
}
final ConfigItem item = factory.createItem(this, configElements);
- item.setSimpleId(simpleIdentifier);
- item.setName(name);
- this.addItem(item);
+ if (item != null) {
+ item.setSimpleId(simpleIdentifier);
+ item.setName(name);
+ this.addItem(item);
+ }
return item;
}
@@ -176,7 +180,16 @@ public abstract class ConfigSource {
*/
public ConfigItem getItemForResource(final IResource resource) {
for (final ConfigItem item : items) {
- if (item.getResourceUri().equals(resource.getLocationURI())) {
+ URI uri;
+ try {
+ uri = new URL(getBaseUrl(), item.getResourceUri().toString()).toURI();
+ } catch (final MalformedURLException e) {
+ return null;
+ } catch (final URISyntaxException e) {
+ return null;
+ }
+
+ if (resource.getLocationURI().equals(uri)) {
return item;
}
}
diff --git a/org.eclipse.vex.ui/src/org/eclipse/vex/ui/internal/config/StyleFactory.java b/org.eclipse.vex.ui/src/org/eclipse/vex/ui/internal/config/StyleFactory.java
index 05c44d05..79d504f1 100644
--- a/org.eclipse.vex.ui/src/org/eclipse/vex/ui/internal/config/StyleFactory.java
+++ b/org.eclipse.vex.ui/src/org/eclipse/vex/ui/internal/config/StyleFactory.java
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2004, 2010 John Krasnay and others.
+ * Copyright (c) 2004, 2015 John Krasnay and others.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
@@ -49,7 +49,7 @@ public class StyleFactory implements IConfigItemFactory {
final IConfigElement configElement = configElements[0];
final Style style = new Style(config);
- style.setResourceUri(newUri(config.resolve(null, configElement.getAttribute("css")))); //$NON-NLS-1$
+ style.setResourceUri(newUri(configElement.getAttribute("css"))); //$NON-NLS-1$
final IConfigElement[] doctypeRefs = configElement.getChildren();
diff --git a/org.eclipse.vex.ui/src/org/eclipse/vex/ui/internal/config/StylePropertyPage.java b/org.eclipse.vex.ui/src/org/eclipse/vex/ui/internal/config/StylePropertyPage.java
index 6089bb37..6d4637c3 100644
--- a/org.eclipse.vex.ui/src/org/eclipse/vex/ui/internal/config/StylePropertyPage.java
+++ b/org.eclipse.vex.ui/src/org/eclipse/vex/ui/internal/config/StylePropertyPage.java
@@ -12,6 +12,8 @@
*******************************************************************************/
package org.eclipse.vex.ui.internal.config;
+import java.net.URI;
+import java.net.URISyntaxException;
import java.text.MessageFormat;
import java.util.ArrayList;
import java.util.Arrays;
@@ -121,8 +123,14 @@ public class StylePropertyPage extends PropertyPage {
style = (Style) pluginProject.getItemForResource(file);
if (style == null) {
style = new Style(pluginProject);
- style.setResourceUri(file.getLocationURI());
- pluginProject.addItem(style);
+ URI uri;
+ try {
+ uri = new URI(file.getProjectRelativePath().toString());
+ style.setResourceUri(uri);
+ pluginProject.addItem(style);
+ } catch (final URISyntaxException e) {
+ // This should never happen
+ }
}
// Generate a simple ID for this one if necessary

Back to the top