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 2018/04/17 07:39:36 UTC
[sling-ide-tooling] 02/04: SLING-5618 - Make the
ResourceChangeCommandFactory independent from Eclipse
This is an automated email from the ASF dual-hosted git repository.
rombert pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/sling-ide-tooling.git
commit d64693aeeaee9e771d72900e972a43bdac0cf4e8
Author: Robert Munteanu <ro...@apache.org>
AuthorDate: Fri Apr 13 18:04:38 2018 +0300
SLING-5618 - Make the ResourceChangeCommandFactory independent from Eclipse
Completely remove the ResourceChangeCommandFactory
---
.../internal/ResourceChangeCommandFactory.java | 64 ----------------------
.../core/internal/SlingLaunchpadBehaviour.java | 12 ++--
eclipse/eclipse-m2e-ui/META-INF/MANIFEST.MF | 3 +-
.../org/apache/sling/ide/test/impl/Activator.java | 11 ++++
...est.java => DefaultCommandFactoryImplTest.java} | 56 ++++++++++---------
.../ide/eclipse/ui/internal/ExportWizard.java | 1 -
.../ui/internal/ImportRepositoryContentAction.java | 1 -
7 files changed, 48 insertions(+), 100 deletions(-)
diff --git a/eclipse/eclipse-core/src/org/apache/sling/ide/eclipse/core/internal/ResourceChangeCommandFactory.java b/eclipse/eclipse-core/src/org/apache/sling/ide/eclipse/core/internal/ResourceChangeCommandFactory.java
deleted file mode 100644
index 4e6a9f8..0000000
--- a/eclipse/eclipse-core/src/org/apache/sling/ide/eclipse/core/internal/ResourceChangeCommandFactory.java
+++ /dev/null
@@ -1,64 +0,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.
- */
-package org.apache.sling.ide.eclipse.core.internal;
-
-import java.io.IOException;
-
-import org.apache.sling.ide.eclipse.core.EclipseResources;
-import org.apache.sling.ide.transport.Command;
-import org.apache.sling.ide.transport.Repository;
-import org.eclipse.core.resources.IResource;
-import org.eclipse.core.runtime.CoreException;
-import org.eclipse.core.runtime.Status;
-
-/**
- * The <tt>ResourceChangeCommandFactory</tt> creates new {@link #Command commands} correspoding to resource addition,
- * change, or removal
- *
- * @deprecated - Use the {@link DefaultCommandFactory} instead. This class is present until the tests are migrated off it
- */
-@Deprecated
-public class ResourceChangeCommandFactory {
-
- public Command<?> newCommandForAddedOrUpdated(Repository repository, IResource addedOrUpdated) throws CoreException {
-
- try {
- return Activator.getDefault().getCommandFactory().newCommandForAddedOrUpdatedResource(repository, EclipseResources.create(addedOrUpdated));
- } catch (IOException e) {
- throw new CoreException(new Status(Status.ERROR, Activator.PLUGIN_ID, "Failed updating " + addedOrUpdated,
- e));
- }
- }
-
- public Command<?> newCommandForRemovedResources(Repository repository, IResource removed) throws CoreException {
- try {
- return Activator.getDefault().getCommandFactory().newCommandForRemovedResource(repository, EclipseResources.create(removed));
- } catch (IOException e) {
- throw new CoreException(new Status(Status.ERROR, Activator.PLUGIN_ID, "Failed removing" + removed, e));
- }
- }
-
- public Command<Void> newReorderChildNodesCommand(Repository repository, IResource res) throws CoreException {
- try {
- return Activator.getDefault().getCommandFactory().newReorderChildNodesCommand(repository, EclipseResources.create(res));
- } catch (IOException e) {
- throw new CoreException(new Status(Status.ERROR, Activator.PLUGIN_ID, "Failed reordering child nodes for "
- + res, e));
- }
- }
-
-}
diff --git a/eclipse/eclipse-core/src/org/apache/sling/ide/eclipse/core/internal/SlingLaunchpadBehaviour.java b/eclipse/eclipse-core/src/org/apache/sling/ide/eclipse/core/internal/SlingLaunchpadBehaviour.java
index 47aa0fe..d33145b 100644
--- a/eclipse/eclipse-core/src/org/apache/sling/ide/eclipse/core/internal/SlingLaunchpadBehaviour.java
+++ b/eclipse/eclipse-core/src/org/apache/sling/ide/eclipse/core/internal/SlingLaunchpadBehaviour.java
@@ -30,12 +30,14 @@ import java.util.Set;
import org.apache.sling.ide.artifacts.EmbeddedArtifact;
import org.apache.sling.ide.artifacts.EmbeddedArtifactLocator;
+import org.apache.sling.ide.eclipse.core.EclipseResources;
import org.apache.sling.ide.eclipse.core.ISlingLaunchpadServer;
import org.apache.sling.ide.eclipse.core.ServerUtil;
import org.apache.sling.ide.log.Logger;
import org.apache.sling.ide.osgi.OsgiClient;
import org.apache.sling.ide.osgi.OsgiClientException;
import org.apache.sling.ide.serialization.SerializationException;
+import org.apache.sling.ide.sync.content.SyncCommandFactory;
import org.apache.sling.ide.transport.Batcher;
import org.apache.sling.ide.transport.Command;
import org.apache.sling.ide.transport.Repository;
@@ -65,7 +67,7 @@ import org.osgi.framework.Version;
public class SlingLaunchpadBehaviour extends ServerBehaviourDelegateWithModulePublishSupport {
- private ResourceChangeCommandFactory commandFactory;
+ private SyncCommandFactory commandFactory;
private ILaunch launch;
private JVMDebuggerConnection debuggerConnection;
@@ -196,7 +198,7 @@ public class SlingLaunchpadBehaviour extends ServerBehaviourDelegateWithModulePu
Logger logger = Activator.getDefault().getPluginLogger();
if (commandFactory == null) {
- commandFactory = new ResourceChangeCommandFactory();
+ commandFactory = Activator.getDefault().getCommandFactory();
}
logger.trace(traceOperation(kind, deltaKind, module));
@@ -566,7 +568,7 @@ public class SlingLaunchpadBehaviour extends ServerBehaviourDelegateWithModulePu
return null;
}
- return commandFactory.newCommandForAddedOrUpdated(repository, res);
+ return commandFactory.newCommandForAddedOrUpdatedResource(repository, EclipseResources.create(res));
}
private Command<?> reorderChildNodesCommand(Repository repository, IModuleResource resource) throws CoreException,
@@ -578,7 +580,7 @@ public class SlingLaunchpadBehaviour extends ServerBehaviourDelegateWithModulePu
return null;
}
- return commandFactory.newReorderChildNodesCommand(repository, res);
+ return commandFactory.newReorderChildNodesCommand(repository, EclipseResources.create(res));
}
private IResource getResource(IModuleResource resource) {
@@ -608,6 +610,6 @@ public class SlingLaunchpadBehaviour extends ServerBehaviourDelegateWithModulePu
return null;
}
- return commandFactory.newCommandForRemovedResources(repository, deletedResource);
+ return commandFactory.newCommandForRemovedResource(repository, EclipseResources.create(deletedResource));
}
}
diff --git a/eclipse/eclipse-m2e-ui/META-INF/MANIFEST.MF b/eclipse/eclipse-m2e-ui/META-INF/MANIFEST.MF
index b0e67ef..1480c68 100644
--- a/eclipse/eclipse-m2e-ui/META-INF/MANIFEST.MF
+++ b/eclipse/eclipse-m2e-ui/META-INF/MANIFEST.MF
@@ -66,6 +66,5 @@ Import-Package: org.apache.commons.httpclient;version="3.1.0",
org.osgi.framework;version="1.6.0",
org.osgi.util.tracker;version="1.5.0"
Bundle-ActivationPolicy: lazy
-Export-Package: org.apache.sling.ide.eclipse.m2e,org.apache.sling.ide.
- eclipse.ui.wizards.np
+Export-Package: org.apache.sling.ide.eclipse.ui.wizards.np
SlingIDE-PluginLoggerEnabled: true
diff --git a/eclipse/eclipse-test/src/org/apache/sling/ide/test/impl/Activator.java b/eclipse/eclipse-test/src/org/apache/sling/ide/test/impl/Activator.java
index 5ccd3d5..60c983e 100644
--- a/eclipse/eclipse-test/src/org/apache/sling/ide/test/impl/Activator.java
+++ b/eclipse/eclipse-test/src/org/apache/sling/ide/test/impl/Activator.java
@@ -20,6 +20,7 @@ import org.apache.sling.ide.artifacts.EmbeddedArtifactLocator;
import org.apache.sling.ide.eclipse.core.ServiceUtil;
import org.apache.sling.ide.osgi.OsgiClientFactory;
import org.apache.sling.ide.serialization.SerializationManager;
+import org.apache.sling.ide.sync.content.SyncCommandFactory;
import org.eclipse.core.runtime.Plugin;
import org.osgi.framework.BundleContext;
import org.osgi.util.tracker.ServiceTracker;
@@ -34,6 +35,8 @@ public class Activator extends Plugin {
private ServiceTracker<SerializationManager, SerializationManager> serializationManager;
+ private ServiceTracker <SyncCommandFactory, SyncCommandFactory> commandFactory;
+
@Override
public void start(BundleContext context) throws Exception {
super.start(context);
@@ -46,6 +49,9 @@ public class Activator extends Plugin {
serializationManager = new ServiceTracker<>(context, SerializationManager.class, null);
serializationManager.open();
+
+ commandFactory = new ServiceTracker<>(context, SyncCommandFactory.class, null);
+ commandFactory.open();
INSTANCE = this;
}
@@ -56,6 +62,7 @@ public class Activator extends Plugin {
artifactLocator.close();
osgiClientFactory.close();
serializationManager.close();
+ commandFactory.close();
INSTANCE = null;
@@ -80,4 +87,8 @@ public class Activator extends Plugin {
return ServiceUtil.getNotNull(serializationManager);
}
+
+ public SyncCommandFactory getCommandFactory() {
+ return ServiceUtil.getNotNull(commandFactory);
+ }
}
diff --git a/eclipse/eclipse-test/src/org/apache/sling/ide/test/impl/ResourceChangeCommandFactoryTest.java b/eclipse/eclipse-test/src/org/apache/sling/ide/test/impl/DefaultCommandFactoryImplTest.java
similarity index 83%
rename from eclipse/eclipse-test/src/org/apache/sling/ide/test/impl/ResourceChangeCommandFactoryTest.java
rename to eclipse/eclipse-test/src/org/apache/sling/ide/test/impl/DefaultCommandFactoryImplTest.java
index c5a328d..7c7c89a 100644
--- a/eclipse/eclipse-test/src/org/apache/sling/ide/test/impl/ResourceChangeCommandFactoryTest.java
+++ b/eclipse/eclipse-test/src/org/apache/sling/ide/test/impl/DefaultCommandFactoryImplTest.java
@@ -31,7 +31,8 @@ import java.util.List;
import java.util.Map;
import java.util.Set;
-import org.apache.sling.ide.eclipse.core.internal.ResourceChangeCommandFactory;
+import org.apache.sling.ide.eclipse.core.EclipseResources;
+import org.apache.sling.ide.sync.content.SyncCommandFactory;
import org.apache.sling.ide.test.impl.helpers.ProjectAdapter;
import org.apache.sling.ide.test.impl.helpers.SpyCommand;
import org.apache.sling.ide.test.impl.helpers.SpyRepository;
@@ -47,13 +48,14 @@ import org.junit.Before;
import org.junit.Rule;
import org.junit.Test;
-public class ResourceChangeCommandFactoryTest {
+// TODO - move out of the eclipse-test module and make this a regular Maven test
+public class DefaultCommandFactoryImplTest {
@Rule
public TemporaryProject projectRule = new TemporaryProject();
private IProject contentProject;
private ProjectAdapter project;
- private ResourceChangeCommandFactory factory;
+ private SyncCommandFactory factory;
private Repository spyRepo;
@Before
@@ -72,7 +74,7 @@ public class ResourceChangeCommandFactoryTest {
Set<String> ignoredFileNames = new HashSet<>();
ignoredFileNames.add(".gitignore");
- factory = new ResourceChangeCommandFactory();
+ factory = Activator.getDefault().getCommandFactory();
spyRepo = new SpyRepository();
}
@@ -85,11 +87,11 @@ public class ResourceChangeCommandFactoryTest {
project.createOrUpdateFile(Path.fromPortableString("jcr_root/content/test-root/nested/.gitignore"),
inputStream);
}
- SpyCommand<?> command = (SpyCommand<?>) factory.newCommandForAddedOrUpdated(spyRepo,
- contentProject.findMember("jcr_root/content/test-root/nested/.gitignore"));
+ SpyCommand<?> command = (SpyCommand<?>) factory.newCommandForAddedOrUpdatedResource(spyRepo,
+ EclipseResources.create(contentProject.findMember("jcr_root/content/test-root/nested/.gitignore")));
assertNull(command);
- command = (SpyCommand<?>) factory.newCommandForRemovedResources(spyRepo,
- contentProject.findMember("jcr_root/content/test-root/nested/.gitignore"));
+ command = (SpyCommand<?>) factory.newCommandForRemovedResource(spyRepo,
+ EclipseResources.create(contentProject.findMember("jcr_root/content/test-root/nested/.gitignore")));
assertNull(command);
}
@@ -101,30 +103,30 @@ public class ResourceChangeCommandFactoryTest {
project.createOrUpdateFile(Path.fromPortableString("jcr_root/content/test-root/nested/gitignore"),
inputStream);
}
- SpyCommand<?> command = (SpyCommand<?>) factory.newCommandForAddedOrUpdated(spyRepo,
- contentProject.findMember("jcr_root/content/test-root/nested/gitignore"));
+ SpyCommand<?> command = (SpyCommand<?>) factory.newCommandForAddedOrUpdatedResource(spyRepo,
+ EclipseResources.create(contentProject.findMember("jcr_root/content/test-root/nested/gitignore")));
assertThat("command.path", command.getPath(), nullValue());
assertThat("command.resource.path", command.getResourceProxy().getPath(), equalTo("/content/test-root/nested/gitignore"));
assertThat("command.resource.properties", command.getResourceProxy().getProperties(),
equalTo(singletonMap("jcr:primaryType", (Object) "nt:file")));
assertThat("command.kind", command.getSpyKind(), equalTo(SpyCommand.Kind.ADD_OR_UPDATE));
- command = (SpyCommand<?>) factory.newCommandForRemovedResources(spyRepo,
- contentProject.findMember("jcr_root/content/test-root/nested/gitignore"));
+ command = (SpyCommand<?>) factory.newCommandForRemovedResource(spyRepo,
+ EclipseResources.create(contentProject.findMember("jcr_root/content/test-root/nested/gitignore")));
assertThat("command.path", command.getPath(), equalTo("/content/test-root/nested/gitignore"));
assertThat("command.kind", command.getSpyKind(), equalTo(SpyCommand.Kind.DELETE));
}
@Test
- public void commandForAddedOrUpdatedNtFolder() throws CoreException {
+ public void commandForAddedOrUpdatedNtFolder() throws CoreException, IOException {
// create a sling:Folder at /content/test-root/nested
InputStream childContentXml = getClass().getResourceAsStream("sling-folder-nodetype.xml");
project.createOrUpdateFile(Path.fromPortableString("jcr_root/content/test-root/nested/.content.xml"),
childContentXml);
- SpyCommand<?> command = (SpyCommand<?>) factory.newCommandForAddedOrUpdated(spyRepo,
- contentProject.findMember("jcr_root/content/test-root"));
+ SpyCommand<?> command = (SpyCommand<?>) factory.newCommandForAddedOrUpdatedResource(spyRepo,
+ EclipseResources.create(contentProject.findMember("jcr_root/content/test-root")));
assertThat("command.path", command.getPath(), nullValue());
assertThat("command.resource.path", command.getResourceProxy().getPath(), equalTo("/content/test-root"));
@@ -135,15 +137,15 @@ public class ResourceChangeCommandFactoryTest {
}
@Test
- public void commandForAddedOrUpdatedSlingFolder() throws CoreException {
+ public void commandForAddedOrUpdatedSlingFolder() throws CoreException, IOException {
// create a sling:Folder at /content/test-root/nested
InputStream childContentXml = getClass().getResourceAsStream("sling-folder-nodetype-with-title.xml");
project.createOrUpdateFile(Path.fromPortableString("jcr_root/content/test-root/nested/.content.xml"),
childContentXml);
- SpyCommand<?> command = (SpyCommand<?>) factory.newCommandForAddedOrUpdated(spyRepo,
- contentProject.findMember("jcr_root/content/test-root/nested"));
+ SpyCommand<?> command = (SpyCommand<?>) factory.newCommandForAddedOrUpdatedResource(spyRepo,
+ EclipseResources.create(contentProject.findMember("jcr_root/content/test-root/nested")));
Map<String, Object> props = new HashMap<>();
props.put("jcr:primaryType", "sling:Folder");
@@ -157,7 +159,7 @@ public class ResourceChangeCommandFactoryTest {
}
@Test
- public void commandForSlingOrderedFolder_children() throws CoreException {
+ public void commandForSlingOrderedFolder_children() throws CoreException, IOException {
// create a sling:OrderedFolder at /content/test-root
project.createOrUpdateFile(Path.fromPortableString("jcr_root/content/test-root/.content.xml"), getClass()
@@ -165,8 +167,8 @@ public class ResourceChangeCommandFactoryTest {
// create the child folder listed in the .content.xml file
contentProject.getFolder("jcr_root/content/test-root/folder").create(true, true, new NullProgressMonitor());
- SpyCommand<?> command = (SpyCommand<?>) factory.newCommandForAddedOrUpdated(spyRepo,
- contentProject.findMember("jcr_root/content/test-root"));
+ SpyCommand<?> command = (SpyCommand<?>) factory.newCommandForAddedOrUpdatedResource(spyRepo,
+ EclipseResources.create(contentProject.findMember("jcr_root/content/test-root")));
List<ResourceProxy> children = command.getResourceProxy().getChildren();
@@ -174,14 +176,14 @@ public class ResourceChangeCommandFactoryTest {
}
@Test
- public void commandForSlingOrderedFolder_childrenMissingFromFilesystem() throws CoreException {
+ public void commandForSlingOrderedFolder_childrenMissingFromFilesystem() throws CoreException, IOException {
// create a sling:OrderedFolder at /content/test-root
project.createOrUpdateFile(Path.fromPortableString("jcr_root/content/test-root/.content.xml"), getClass()
.getResourceAsStream("sling-ordered-folder-with-children.xml"));
- SpyCommand<?> command = (SpyCommand<?>) factory.newCommandForAddedOrUpdated(spyRepo,
- contentProject.findMember("jcr_root/content/test-root"));
+ SpyCommand<?> command = (SpyCommand<?>) factory.newCommandForAddedOrUpdatedResource(spyRepo,
+ EclipseResources.create(contentProject.findMember("jcr_root/content/test-root")));
List<ResourceProxy> children = command.getResourceProxy().getChildren();
@@ -189,7 +191,7 @@ public class ResourceChangeCommandFactoryTest {
}
@Test
- public void commandForSlingOrderedFolder_extraChildrenInTheFilesystem() throws CoreException {
+ public void commandForSlingOrderedFolder_extraChildrenInTheFilesystem() throws CoreException, IOException {
// create a sling:OrderedFolder at /content/test-root
project.createOrUpdateFile(Path.fromPortableString("jcr_root/content/test-root/.content.xml"), getClass()
@@ -199,8 +201,8 @@ public class ResourceChangeCommandFactoryTest {
// create an extra folder not listed in the .content.xml file
contentProject.getFolder("jcr_root/content/test-root/folder2").create(true, true, new NullProgressMonitor());
- SpyCommand<?> command = (SpyCommand<?>) factory.newCommandForAddedOrUpdated(spyRepo,
- contentProject.findMember("jcr_root/content/test-root"));
+ SpyCommand<?> command = (SpyCommand<?>) factory.newCommandForAddedOrUpdatedResource(spyRepo,
+ EclipseResources.create(contentProject.findMember("jcr_root/content/test-root")));
List<ResourceProxy> children = command.getResourceProxy().getChildren();
diff --git a/eclipse/eclipse-ui/src/org/apache/sling/ide/eclipse/ui/internal/ExportWizard.java b/eclipse/eclipse-ui/src/org/apache/sling/ide/eclipse/ui/internal/ExportWizard.java
index e647e34..2f3611c 100644
--- a/eclipse/eclipse-ui/src/org/apache/sling/ide/eclipse/ui/internal/ExportWizard.java
+++ b/eclipse/eclipse-ui/src/org/apache/sling/ide/eclipse/ui/internal/ExportWizard.java
@@ -21,7 +21,6 @@ import java.lang.reflect.InvocationTargetException;
import org.apache.sling.ide.eclipse.core.EclipseResources;
import org.apache.sling.ide.eclipse.core.ServerUtil;
-import org.apache.sling.ide.eclipse.core.internal.ResourceChangeCommandFactory;
import org.apache.sling.ide.eclipse.ui.WhitelabelSupport;
import org.apache.sling.ide.sync.content.SyncCommandFactory;
import org.apache.sling.ide.transport.Command;
diff --git a/eclipse/eclipse-ui/src/org/apache/sling/ide/eclipse/ui/internal/ImportRepositoryContentAction.java b/eclipse/eclipse-ui/src/org/apache/sling/ide/eclipse/ui/internal/ImportRepositoryContentAction.java
index e5e9196..d3ef371 100644
--- a/eclipse/eclipse-ui/src/org/apache/sling/ide/eclipse/ui/internal/ImportRepositoryContentAction.java
+++ b/eclipse/eclipse-ui/src/org/apache/sling/ide/eclipse/ui/internal/ImportRepositoryContentAction.java
@@ -33,7 +33,6 @@ import org.apache.sling.ide.eclipse.core.EclipseResources;
import org.apache.sling.ide.eclipse.core.ProjectUtil;
import org.apache.sling.ide.eclipse.core.ResourceUtil;
import org.apache.sling.ide.eclipse.core.ServerUtil;
-import org.apache.sling.ide.eclipse.core.internal.ResourceChangeCommandFactory;
import org.apache.sling.ide.eclipse.core.progress.ProgressUtils;
import org.apache.sling.ide.filter.Filter;
import org.apache.sling.ide.filter.FilterResult;
--
To stop receiving notification emails like this one, please contact
rombert@apache.org.