This is an automated email from the ASF dual-hosted git repository. rombert pushed a commit to branch issue/SLING-12796 in repository https://gitbox.apache.org/repos/asf/sling-ide-tooling.git
commit 0396dadfde88f752400970be914d5fdf82c34457 Author: Robert Munteanu <[email protected]> AuthorDate: Wed May 21 16:30:46 2025 +0200 SLING-12796 - Remove resource-based implementation --- eclipse/target-definition/Sling IDE Tooling.launch | 2 - shared/impl-resource/.project | 24 --- shared/impl-resource/README.md | 3 - shared/impl-resource/bnd.bnd | 0 shared/impl-resource/pom.xml | 79 -------- .../ide/impl/resource/filter/SimpleFilter.java | 50 ----- .../impl/resource/filter/SimpleFilterLocator.java | 70 ------- .../SimpleXmlSerializationManager.java | 225 --------------------- .../impl/resource/transport/AbstractCommand.java | 81 -------- .../impl/resource/transport/AbstractResult.java | 62 ------ .../impl/resource/transport/DeleteNodeCommand.java | 59 ------ .../impl/resource/transport/GetNodeCommand.java | 61 ------ .../resource/transport/GetNodeContentCommand.java | 82 -------- .../resource/transport/ListChildrenCommand.java | 107 ---------- .../resource/transport/RepositoryFactoryImpl.java | 65 ------ .../impl/resource/transport/RepositoryImpl.java | 92 --------- .../resource/transport/UpdateContentCommand.java | 93 --------- .../sling/ide/impl/resource/util/Constants.java | 22 -- .../SimpleXmlSerializationManagerTest.java | 194 ------------------ ...lizationManagerTest.serializedDataIsEscaped.xml | 20 -- ...rializationManagerTest.stringSerializedData.xml | 21 -- shared/pom.xml | 1 - 22 files changed, 1413 deletions(-) diff --git a/eclipse/target-definition/Sling IDE Tooling.launch b/eclipse/target-definition/Sling IDE Tooling.launch index 78b41075..718ba18f 100644 --- a/eclipse/target-definition/Sling IDE Tooling.launch +++ b/eclipse/target-definition/Sling IDE Tooling.launch @@ -199,7 +199,6 @@ <setEntry value="org.apache.sling.ide.eclipse-m2e-test@default:false"/> <setEntry value="org.apache.sling.ide.eclipse-m2e-ui@default:default"/> <setEntry value="org.apache.sling.ide.eclipse-ui@default:default"/> - <setEntry value="org.apache.sling.ide.impl-resource@default:default"/> <setEntry value="org.apache.sling.ide.impl-vlt@default:default"/> <setEntry value="org.apache.sling.ide.vlt-wrapper@default:default"/> </setAttribute> @@ -208,7 +207,6 @@ <booleanAttribute key="tracing" value="false"/> <mapAttribute key="tracingOptions"> <mapEntry key="org.apache.sling.ide.eclipse-core/debug" value="true"/> - <mapEntry key="org.apache.sling.ide.impl-resource/debug" value="true"/> <mapEntry key="org.eclipse.core.contenttype/debug" value="false"/> <mapEntry key="org.eclipse.core.expressions/debug/TypeExtensionManager" value="false"/> <mapEntry key="org.eclipse.core.expressions/tracePropertyResolving" value="false"/> diff --git a/shared/impl-resource/.project b/shared/impl-resource/.project deleted file mode 100644 index f4e01544..00000000 --- a/shared/impl-resource/.project +++ /dev/null @@ -1,24 +0,0 @@ -<?xml version="1.0" encoding="UTF-8"?> -<projectDescription> - <name>org.apache.sling.ide.impl-resource</name> - <comment></comment> - <projects> - </projects> - <buildSpec> - <buildCommand> - <name>org.eclipse.jdt.core.javabuilder</name> - <arguments> - </arguments> - </buildCommand> - <buildCommand> - <name>org.eclipse.m2e.core.maven2Builder</name> - <arguments> - </arguments> - </buildCommand> - </buildSpec> - <natures> - <nature>org.eclipse.jdt.core.javanature</nature> - <nature>org.eclipse.m2e.core.maven2Nature</nature> - <nature>org.eclipse.pde.PluginNature</nature> - </natures> -</projectDescription> diff --git a/shared/impl-resource/README.md b/shared/impl-resource/README.md deleted file mode 100644 index c0728b2f..00000000 --- a/shared/impl-resource/README.md +++ /dev/null @@ -1,3 +0,0 @@ -# Apache Sling IDE Tools Resource-based Implementation - -This module is part of the [Apache Sling](https://sling.apache.org) project. diff --git a/shared/impl-resource/bnd.bnd b/shared/impl-resource/bnd.bnd deleted file mode 100644 index e69de29b..00000000 diff --git a/shared/impl-resource/pom.xml b/shared/impl-resource/pom.xml deleted file mode 100644 index 3850a09c..00000000 --- a/shared/impl-resource/pom.xml +++ /dev/null @@ -1,79 +0,0 @@ -<?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. --> -<project - xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd" - xmlns="http://maven.apache.org/POM/4.0.0" - xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"> - <modelVersion>4.0.0</modelVersion> - <parent> - <groupId>org.apache.sling.ide</groupId> - <artifactId>sling-ide-shared-parent</artifactId> - <version>1.2.3-SNAPSHOT</version> - <relativePath>../parent/</relativePath> - </parent> - - <artifactId>org.apache.sling.ide.impl-resource</artifactId> - <name>Apache Sling IDE Tools Resource-based Implementation</name> - - <scm> - <connection>scm:git:https://gitbox.apache.org/repos/asf/sling-ide-tooling.git</connection> - <developerConnection>scm:git:https://gitbox.apache.org/repos/asf/sling-ide-tooling.git</developerConnection> - <url>https://github.com/apache/sling-ide-tooling.git</url> - </scm> - - <dependencies> - <dependency> - <groupId>org.apache.sling.ide</groupId> - <artifactId>org.apache.sling.ide.api</artifactId> - <version>${project.version}</version> - <scope>provided</scope> - </dependency> - <dependency> - <groupId>commons-httpclient</groupId> - <artifactId>commons-httpclient</artifactId> - <version>3.0</version> - <scope>provided</scope> - </dependency> - <dependency> - <groupId>com.google.code.gson</groupId> - <artifactId>gson</artifactId> - <version>2.8.0</version> - <scope>provided</scope> - </dependency> - - <!-- Note that OSGi annotations are OK since they are not retained - at compile time --> - <dependency> - <groupId>org.osgi</groupId> - <artifactId>org.osgi.service.component.annotations</artifactId> - <scope>provided</scope> - </dependency> - <dependency> - <groupId>org.osgi</groupId> - <artifactId>org.osgi.service.metatype.annotations</artifactId> - <scope>provided</scope> - </dependency> - - <dependency> - <groupId>xmlunit</groupId> - <artifactId>xmlunit</artifactId> - <version>1.4</version> - <scope>test</scope> - </dependency> - <dependency> - <groupId>org.apache.sling.ide</groupId> - <artifactId>org.apache.sling.ide.sync-fs</artifactId> - <version>${project.version}</version> - <scope>provided</scope> - </dependency> - </dependencies> -</project> diff --git a/shared/impl-resource/src/main/java/org/apache/sling/ide/impl/resource/filter/SimpleFilter.java b/shared/impl-resource/src/main/java/org/apache/sling/ide/impl/resource/filter/SimpleFilter.java deleted file mode 100644 index 1df2fa7a..00000000 --- a/shared/impl-resource/src/main/java/org/apache/sling/ide/impl/resource/filter/SimpleFilter.java +++ /dev/null @@ -1,50 +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.impl.resource.filter; - -import java.util.List; - -import org.apache.sling.ide.filter.Filter; -import org.apache.sling.ide.filter.FilterResult; - -public class SimpleFilter implements Filter { - - private final List<String> includedPathPrefixes; - - public SimpleFilter(List<String> includedPathPrefixes) { - this.includedPathPrefixes = includedPathPrefixes; - } - - @Override - public FilterResult filter(String relativeFilePath) { - if (relativeFilePath.isEmpty() || relativeFilePath.charAt(0) != '/') { - relativeFilePath = '/' + relativeFilePath; - } - - if (includedPathPrefixes.isEmpty()) { - return FilterResult.ALLOW; - } - - for (String includePath : includedPathPrefixes) { - if (relativeFilePath.startsWith(includePath)) { - return FilterResult.ALLOW; - } - } - - return FilterResult.DENY; - } -} diff --git a/shared/impl-resource/src/main/java/org/apache/sling/ide/impl/resource/filter/SimpleFilterLocator.java b/shared/impl-resource/src/main/java/org/apache/sling/ide/impl/resource/filter/SimpleFilterLocator.java deleted file mode 100644 index 5277287e..00000000 --- a/shared/impl-resource/src/main/java/org/apache/sling/ide/impl/resource/filter/SimpleFilterLocator.java +++ /dev/null @@ -1,70 +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.impl.resource.filter; - -import java.io.BufferedReader; -import java.io.File; -import java.io.IOException; -import java.io.InputStream; -import java.io.InputStreamReader; -import java.util.ArrayList; -import java.util.List; - -import org.apache.sling.ide.filter.Filter; -import org.apache.sling.ide.filter.FilterLocator; -import org.osgi.service.component.annotations.Component; - -/** - * The <tt>SimpleFilterLocator</tt> looks for a file named {@value #FILTERS_FILE_NAME} in the parent folder of the - * specified <tt>syncDirectory</tt>. - * - * <p> - * Lines starting with '#' are ignored. - * </p> - * - * @see SimpleFilter - * - */ -@Component(service = FilterLocator.class) -public class SimpleFilterLocator implements FilterLocator { - - private static final String FILTERS_FILE_NAME = "filters.txt"; - - @Override - public File findFilterLocation(File syncDirectory) { - String parent = syncDirectory.getParent(); - - return new File(parent, FILTERS_FILE_NAME); - } - - @Override - public Filter loadFilter(InputStream filterFileContents) throws IOException { - - List<String> filters = new ArrayList<>(); - if (filterFileContents != null) { - BufferedReader reader = new BufferedReader(new InputStreamReader(filterFileContents)); - String line; - while ((line = reader.readLine()) != null) { - if (line.charAt(0) == '#') - continue; - filters.add(line); - } - } - - return new SimpleFilter(filters); - } -} diff --git a/shared/impl-resource/src/main/java/org/apache/sling/ide/impl/resource/serialization/SimpleXmlSerializationManager.java b/shared/impl-resource/src/main/java/org/apache/sling/ide/impl/resource/serialization/SimpleXmlSerializationManager.java deleted file mode 100644 index da50fb69..00000000 --- a/shared/impl-resource/src/main/java/org/apache/sling/ide/impl/resource/serialization/SimpleXmlSerializationManager.java +++ /dev/null @@ -1,225 +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.impl.resource.serialization; - -import java.io.ByteArrayOutputStream; -import java.io.File; -import java.io.IOException; -import java.io.InputStream; -import java.util.HashMap; -import java.util.Map; -import java.util.Map.Entry; -import java.util.Set; -import java.util.TreeMap; - -import javax.xml.parsers.ParserConfigurationException; -import javax.xml.parsers.SAXParser; -import javax.xml.parsers.SAXParserFactory; -import javax.xml.transform.OutputKeys; -import javax.xml.transform.Transformer; -import javax.xml.transform.TransformerConfigurationException; -import javax.xml.transform.TransformerFactoryConfigurationError; -import javax.xml.transform.sax.SAXTransformerFactory; -import javax.xml.transform.sax.TransformerHandler; -import javax.xml.transform.stream.StreamResult; - -import org.apache.sling.ide.serialization.SerializationData; -import org.apache.sling.ide.serialization.SerializationDataBuilder; -import org.apache.sling.ide.serialization.SerializationException; -import org.apache.sling.ide.serialization.SerializationKind; -import org.apache.sling.ide.serialization.SerializationManager; -import org.apache.sling.ide.sync.content.WorkspaceDirectory; -import org.apache.sling.ide.sync.content.WorkspaceFile; -import org.apache.sling.ide.sync.content.WorkspacePath; -import org.apache.sling.ide.sync.content.WorkspaceResource; -import org.apache.sling.ide.transport.Repository; -import org.apache.sling.ide.transport.ResourceProxy; -import org.osgi.service.component.annotations.Component; -import org.xml.sax.Attributes; -import org.xml.sax.InputSource; -import org.xml.sax.SAXException; -import org.xml.sax.helpers.AttributesImpl; -import org.xml.sax.helpers.DefaultHandler; - -@Component(service = SerializationManager.class) -public class SimpleXmlSerializationManager implements SerializationManager, SerializationDataBuilder { - - private static final String TAG_PROPERTY = "property"; - private static final String ATT_PROPERTY_NAME = "name"; - private static final String TAG_RESOURCE = "resource"; - - private static final String CONTENT_XML = ".content.xml"; - - @Override - public boolean isSerializationFile(WorkspaceFile file) { - return file.getLocalPath().getName().equals(CONTENT_XML); - } - - @Override - public WorkspaceFile getSerializationFile(WorkspaceResource resource, SerializationKind serializationKind) { - return ( (WorkspaceDirectory) resource).getFile(new WorkspacePath(CONTENT_XML)); - } - - @Override - public ResourceProxy readSerializationData(WorkspaceFile file) throws IOException { - - try { - SAXParserFactory factory = SAXParserFactory.newInstance(); - SAXParser saxParser = factory.newSAXParser(); - - SerializationDataHandler h = new SerializationDataHandler(); - - try (InputStream source = file.getContents()) { - saxParser.parse(new InputSource(source), h); - } - - return new ResourceProxy(file.getPathRelativeToSyncDir().asPortableString(), h.getResult()); - } catch (ParserConfigurationException | SAXException e) { - // TODO proper exception handling - throw new RuntimeException(e); - } - - } - - @Override - public SerializationDataBuilder newBuilder(Repository repository, - File contentSyncRoot) throws SerializationException { - return this; - } - - @Override - public SerializationData buildSerializationData(File contentSyncRoot, ResourceProxy resource) - throws SerializationException { - - if (resource == null) { - return null; - } - - Map<String, Object> content = resource.getProperties(); - - if (content == null || content.isEmpty()) { - return null; - } - - try { - SAXTransformerFactory f = (SAXTransformerFactory) SAXTransformerFactory.newInstance(); - - ByteArrayOutputStream result = new ByteArrayOutputStream(); - StreamResult sr = new StreamResult(result); - - TransformerHandler handler = f.newTransformerHandler(); - Transformer t = handler.getTransformer(); - t.setOutputProperty(OutputKeys.INDENT, "yes"); - handler.setResult(sr); - handler.startDocument(); - startElement(handler, TAG_RESOURCE); - Set<Entry<String, Object>> entrySet = new TreeMap<>(content).entrySet(); - for (Map.Entry<String, Object> property : entrySet) { - Object value = property.getValue(); - if (value instanceof String) { - String tagName = property.getKey(); - String tagValue = (String) value; - AttributesImpl attributes = new AttributesImpl(); - attributes.addAttribute("", ATT_PROPERTY_NAME, ATT_PROPERTY_NAME, null, tagName); - handler.startElement("", TAG_PROPERTY, TAG_PROPERTY, attributes); - handler.characters(tagValue.toCharArray(), 0, tagValue.length()); - handler.endElement("", TAG_PROPERTY, TAG_PROPERTY); - } else { - // TODO multi-valued properties, other primitives - System.err.println("Can't yet handle property " + property.getKey() + " of type " - + value.getClass()); - } - } - - endElement(handler, TAG_RESOURCE); - handler.endDocument(); - - // TODO - also add the serialization type - return new SerializationData(resource.getPath(), CONTENT_XML, result.toByteArray(), null); - } catch (TransformerConfigurationException | TransformerFactoryConfigurationError | SAXException e) { - // TODO proper exception handling - throw new RuntimeException(e); - } - } - - @Override - public String getRepositoryPath(WorkspacePath localPath) { - return localPath.asPortableString(); - } - - @Override - public String getLocalName(String repositoryName) { - if (repositoryName == null || repositoryName.contains("/")) - throw new IllegalArgumentException("Repository name must not be null or contain slashes : " + repositoryName); - return repositoryName; - } - - private void startElement(TransformerHandler handler, String tagName) throws SAXException { - - handler.startElement("", tagName, tagName, null); - } - - private void endElement(TransformerHandler handler, String tagName) throws SAXException { - - handler.endElement("", tagName, tagName); - } - - /* (non-Javadoc) - * @see org.apache.sling.ide.serialization.SerializationManager#destroy() - */ - @Override - public void destroy() { - } - - static class SerializationDataHandler extends DefaultHandler { - private Map<String, Object> result; - private String propertyName; - - @Override - public void startDocument() throws SAXException { - result = new HashMap<>(); - } - - @Override - public void startElement(String uri, String localName, String qName, Attributes attributes) throws SAXException { - - if (TAG_PROPERTY.equals(qName)) { - propertyName = attributes.getValue(ATT_PROPERTY_NAME); - } - } - - @Override - public void characters(char[] ch, int start, int length) throws SAXException { - - if (propertyName != null) { - result.put(propertyName, new String(ch, start, length)); - } - } - - @Override - public void endElement(String uri, String localName, String qName) throws SAXException { - - if (TAG_PROPERTY.equals(qName)) { - propertyName = null; - } - } - - public Map<String, Object> getResult() { - return result; - } - } -} diff --git a/shared/impl-resource/src/main/java/org/apache/sling/ide/impl/resource/transport/AbstractCommand.java b/shared/impl-resource/src/main/java/org/apache/sling/ide/impl/resource/transport/AbstractCommand.java deleted file mode 100644 index 90fb50b2..00000000 --- a/shared/impl-resource/src/main/java/org/apache/sling/ide/impl/resource/transport/AbstractCommand.java +++ /dev/null @@ -1,81 +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.impl.resource.transport; - -import java.util.Collections; -import java.util.Set; - -import org.apache.commons.httpclient.HttpClient; -import org.apache.sling.ide.transport.Command; -import org.apache.sling.ide.transport.Repository.CommandExecutionFlag; -import org.apache.sling.ide.transport.RepositoryException; -import org.apache.sling.ide.transport.RepositoryInfo; -import org.apache.sling.ide.transport.Result; -import org.apache.sling.ide.util.PathUtil; - -public abstract class AbstractCommand<T> implements Command<T> { - - protected RepositoryInfo repositoryInfo; - protected HttpClient httpClient; - protected String path; - - public AbstractCommand(RepositoryInfo repositoryInfo, HttpClient httpClient, String relativePath) { - this.repositoryInfo = repositoryInfo; - this.httpClient = httpClient; - this.path = createFullPath(relativePath); - } - - @Override - public String getPath() { - return path; - } - - private String createFullPath(String relativePath) { - - return repositoryInfo.getUrl().resolve(relativePath).toString(); - } - - protected Result<T> resultForResponseStatus(int responseStatus) { - if (isSuccessStatus(responseStatus)) - return AbstractResult.success(null); - - return failureResultForStatusCode(responseStatus); - } - - protected Result<T> failureResultForStatusCode(int responseStatus) { - return AbstractResult.failure(new RepositoryException("Repository has returned status code " + responseStatus)); - } - - protected boolean isSuccessStatus(int responseStatus) { - - // TODO - consider all 2xx and possibly 3xx as success? - - return responseStatus == 200 /* OK */|| responseStatus == 201 /* CREATED */; - } - - @Override - public Set<CommandExecutionFlag> getFlags() { - // TODO - this is not supported - return Collections.emptySet(); - } - - @Override - public Kind getKind() { - return null; - } - -} diff --git a/shared/impl-resource/src/main/java/org/apache/sling/ide/impl/resource/transport/AbstractResult.java b/shared/impl-resource/src/main/java/org/apache/sling/ide/impl/resource/transport/AbstractResult.java deleted file mode 100644 index e8d993c1..00000000 --- a/shared/impl-resource/src/main/java/org/apache/sling/ide/impl/resource/transport/AbstractResult.java +++ /dev/null @@ -1,62 +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.impl.resource.transport; - -import org.apache.sling.ide.transport.RepositoryException; -import org.apache.sling.ide.transport.Result; - -public class AbstractResult<T> implements Result<T> { - - public static <T> Result<T> success(T payload) { - - return new AbstractResult<>(true, payload, null); - } - - public static <T> Result<T> failure(RepositoryException e) { - - return new AbstractResult<>(false, null, e); - } - - private final boolean success; - private final RepositoryException exception; - private final T payload; - - private AbstractResult(boolean success, T payload, RepositoryException exception) { - this.success = success; - this.exception = exception; - this.payload = payload; - } - - @Override - public T get() throws RepositoryException { - - if ( success ) - return payload; - - throw exception; - } - - public boolean isSuccess() { - return success; - } - - @Override - public String toString() { - - return String.format("%4s %s", success ? "OK" : "FAIL", success ? "" : exception.getMessage() ); - } -} diff --git a/shared/impl-resource/src/main/java/org/apache/sling/ide/impl/resource/transport/DeleteNodeCommand.java b/shared/impl-resource/src/main/java/org/apache/sling/ide/impl/resource/transport/DeleteNodeCommand.java deleted file mode 100644 index 87eaba31..00000000 --- a/shared/impl-resource/src/main/java/org/apache/sling/ide/impl/resource/transport/DeleteNodeCommand.java +++ /dev/null @@ -1,59 +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.impl.resource.transport; - -import org.apache.commons.httpclient.HttpClient; -import org.apache.commons.httpclient.UsernamePasswordCredentials; -import org.apache.commons.httpclient.auth.AuthScope; -import org.apache.commons.httpclient.methods.PostMethod; -import org.apache.commons.httpclient.methods.multipart.MultipartRequestEntity; -import org.apache.commons.httpclient.methods.multipart.Part; -import org.apache.commons.httpclient.methods.multipart.StringPart; -import org.apache.sling.ide.transport.RepositoryException; -import org.apache.sling.ide.transport.RepositoryInfo; -import org.apache.sling.ide.transport.Result; - -class DeleteNodeCommand extends AbstractCommand<Void> { - - - DeleteNodeCommand(String path, RepositoryInfo repositoryInfo, HttpClient httpClient) { - super(repositoryInfo, httpClient, path); - } - - @Override - public Result<Void> execute() { - PostMethod post = new PostMethod(getPath()); - try{ - Part[] parts ={new StringPart(":operation", "delete")}; - post.setRequestEntity(new MultipartRequestEntity(parts,post.getParams())); - httpClient.getState().setCredentials(AuthScope.ANY, new UsernamePasswordCredentials(repositoryInfo.getUsername(),repositoryInfo.getPassword())); - httpClient.getParams().setAuthenticationPreemptive(true); - int responseStatus=httpClient.executeMethod(post); - - return resultForResponseStatus(responseStatus); - } catch(Exception e){ - return AbstractResult.failure(new RepositoryException(e)); - }finally{ - post.releaseConnection(); - } - } - - @Override - public String toString() { - return String.format("%8s %s", "DELETE", getPath()); - } -} \ No newline at end of file diff --git a/shared/impl-resource/src/main/java/org/apache/sling/ide/impl/resource/transport/GetNodeCommand.java b/shared/impl-resource/src/main/java/org/apache/sling/ide/impl/resource/transport/GetNodeCommand.java deleted file mode 100644 index 3ca90753..00000000 --- a/shared/impl-resource/src/main/java/org/apache/sling/ide/impl/resource/transport/GetNodeCommand.java +++ /dev/null @@ -1,61 +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.impl.resource.transport; - -import org.apache.commons.httpclient.Credentials; -import org.apache.commons.httpclient.HttpClient; -import org.apache.commons.httpclient.UsernamePasswordCredentials; -import org.apache.commons.httpclient.auth.AuthScope; -import org.apache.commons.httpclient.methods.GetMethod; -import org.apache.sling.ide.transport.RepositoryException; -import org.apache.sling.ide.transport.RepositoryInfo; -import org.apache.sling.ide.transport.Result; - -class GetNodeCommand extends AbstractCommand<byte[]> { - GetNodeCommand(RepositoryInfo repositoryInfo, HttpClient httpClient, String relativePath) { - super(repositoryInfo, httpClient, relativePath); - } - - @Override - public Result<byte[]> execute() { - - GetMethod get = new GetMethod(getPath()); - - try{ - httpClient.getParams().setAuthenticationPreemptive(true); - Credentials defaultcreds = new UsernamePasswordCredentials(repositoryInfo.getUsername(), repositoryInfo.getPassword()); - //TODO - httpClient.getState().setCredentials(new AuthScope(repositoryInfo.getUrl().getHost(),repositoryInfo.getUrl().getPort(), AuthScope.ANY_REALM), defaultcreds); - int responseStatus=httpClient.executeMethod(get); - - if ( isSuccessStatus(responseStatus) ) - return AbstractResult.success(get.getResponseBody()); - - return failureResultForStatusCode(responseStatus); - } catch (Exception e) { - return AbstractResult.failure(new RepositoryException(e)); - }finally{ - get.releaseConnection(); - } - } - - @Override - public String toString() { - - return String.format("%8s %s", "GETNODE", path); - } -} \ No newline at end of file diff --git a/shared/impl-resource/src/main/java/org/apache/sling/ide/impl/resource/transport/GetNodeContentCommand.java b/shared/impl-resource/src/main/java/org/apache/sling/ide/impl/resource/transport/GetNodeContentCommand.java deleted file mode 100644 index ea9fefbd..00000000 --- a/shared/impl-resource/src/main/java/org/apache/sling/ide/impl/resource/transport/GetNodeContentCommand.java +++ /dev/null @@ -1,82 +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.impl.resource.transport; - - -import java.io.InputStreamReader; - -import org.apache.commons.httpclient.Credentials; -import org.apache.commons.httpclient.HttpClient; -import org.apache.commons.httpclient.UsernamePasswordCredentials; -import org.apache.commons.httpclient.auth.AuthScope; -import org.apache.commons.httpclient.methods.GetMethod; -import org.apache.sling.ide.transport.RepositoryException; -import org.apache.sling.ide.transport.RepositoryInfo; -import org.apache.sling.ide.transport.ResourceProxy; -import org.apache.sling.ide.transport.Result; - -import com.google.gson.stream.JsonReader; -import com.google.gson.stream.JsonToken; - -class GetNodeContentCommand extends AbstractCommand<ResourceProxy> { - - GetNodeContentCommand(RepositoryInfo repositoryInfo, HttpClient httpClient, String relativePath) { - super(repositoryInfo, httpClient, relativePath); - } - - @Override - public Result<ResourceProxy> execute() { - GetMethod get = new GetMethod(getPath()); - try{ - httpClient.getParams().setAuthenticationPreemptive(true); - Credentials defaultcreds = new UsernamePasswordCredentials(repositoryInfo.getUsername(), repositoryInfo.getPassword()); - httpClient.getState().setCredentials(new AuthScope(repositoryInfo.getUrl().getHost(),repositoryInfo.getUrl().getPort(), AuthScope.ANY_REALM), defaultcreds); - int responseStatus=httpClient.executeMethod(get); - //TODO change responseAsString with something like - // return EncodingUtil.getString(rawdata, m.getResponseCharSet()); - if (!isSuccessStatus(responseStatus)) - return failureResultForStatusCode(responseStatus); - - ResourceProxy resource = new ResourceProxy(path); - try (JsonReader jsonReader = new JsonReader( - new InputStreamReader(get.getResponseBodyAsStream(), get.getResponseCharSet()))) { - jsonReader.beginObject(); - while (jsonReader.hasNext()) { - String name = jsonReader.nextName(); - JsonToken token = jsonReader.peek(); - if (token == JsonToken.STRING) { - resource.addProperty(name, jsonReader.nextString()); - } else { - jsonReader.skipValue(); - } - } - jsonReader.endObject(); - } - return AbstractResult.success(resource); - } catch (Exception e) { - return AbstractResult.failure(new RepositoryException(e)); - }finally{ - get.releaseConnection(); - } - } - - @Override - public String toString() { - - return String.format("%8s %s", "GETCONT", path); - } -} \ No newline at end of file diff --git a/shared/impl-resource/src/main/java/org/apache/sling/ide/impl/resource/transport/ListChildrenCommand.java b/shared/impl-resource/src/main/java/org/apache/sling/ide/impl/resource/transport/ListChildrenCommand.java deleted file mode 100644 index 2408ebb1..00000000 --- a/shared/impl-resource/src/main/java/org/apache/sling/ide/impl/resource/transport/ListChildrenCommand.java +++ /dev/null @@ -1,107 +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.impl.resource.transport; - -import java.io.InputStreamReader; - -import org.apache.commons.httpclient.Credentials; -import org.apache.commons.httpclient.HttpClient; -import org.apache.commons.httpclient.UsernamePasswordCredentials; -import org.apache.commons.httpclient.auth.AuthScope; -import org.apache.commons.httpclient.methods.GetMethod; -import org.apache.sling.ide.transport.Repository; -import org.apache.sling.ide.transport.RepositoryException; -import org.apache.sling.ide.transport.RepositoryInfo; -import org.apache.sling.ide.transport.ResourceProxy; -import org.apache.sling.ide.transport.Result; -import org.apache.sling.ide.util.PathUtil; - -import com.google.gson.Gson; -import com.google.gson.annotations.SerializedName; -import com.google.gson.stream.JsonReader; -import com.google.gson.stream.JsonToken; - -class ListChildrenCommand extends AbstractCommand<ResourceProxy> { - - ListChildrenCommand(RepositoryInfo repositoryInfo, HttpClient httpClient, String relativePath) { - super(repositoryInfo, httpClient, relativePath); - } - - - private static final class ResourceWithPrimaryType { - @SerializedName(Repository.JCR_PRIMARY_TYPE) - private String primaryType; - - String getPrimaryType() { - return primaryType; - } - } - @Override - public Result<ResourceProxy> execute() { - GetMethod get = new GetMethod(getPath()); - try{ - httpClient.getParams().setAuthenticationPreemptive(true); - Credentials defaultcreds = new UsernamePasswordCredentials(repositoryInfo.getUsername(), repositoryInfo.getPassword()); - httpClient.getState().setCredentials(new AuthScope(repositoryInfo.getUrl().getHost(),repositoryInfo.getUrl().getPort(), AuthScope.ANY_REALM), defaultcreds); - int responseStatus=httpClient.executeMethod(get); - - //TODO change responseAsString with something like - //return EncodingUtil.getString(rawdata, m.getResponseCharSet()); - if (!isSuccessStatus(responseStatus)) - return failureResultForStatusCode(responseStatus); - - ResourceProxy resource = new ResourceProxy(path); - Gson gson = new Gson(); - try (JsonReader jsonReader = new JsonReader( - new InputStreamReader(get.getResponseBodyAsStream(), get.getResponseCharSet()))) { - jsonReader.beginObject(); - while (jsonReader.hasNext()) { - String name = jsonReader.nextName(); - JsonToken token = jsonReader.peek(); - if (token == JsonToken.BEGIN_OBJECT) { - ResourceProxy child = new ResourceProxy(PathUtil.join(path, name)); - ResourceWithPrimaryType resourceWithPrimaryType = gson.fromJson(jsonReader, ResourceWithPrimaryType.class); - // evaluate its jcr:primaryType as well! - child.addProperty(Repository.JCR_PRIMARY_TYPE, resourceWithPrimaryType.getPrimaryType()); - resource.addChild(child); - } else if (token == JsonToken.STRING) { - if (Repository.JCR_PRIMARY_TYPE.equals(name)) { - String primaryType = jsonReader.nextString(); - if (primaryType != null) { // TODO - needed? - resource.addProperty(Repository.JCR_PRIMARY_TYPE, primaryType); - } - } - } else { - jsonReader.skipValue(); - } - } - jsonReader.endObject(); - } - return AbstractResult.success(resource); - } catch (Exception e) { - return AbstractResult.failure(new RepositoryException(e)); - }finally{ - get.releaseConnection(); - } - } - - @Override - public String toString() { - - return String.format("%8s %s", "LISTCH", path); - } -} \ No newline at end of file diff --git a/shared/impl-resource/src/main/java/org/apache/sling/ide/impl/resource/transport/RepositoryFactoryImpl.java b/shared/impl-resource/src/main/java/org/apache/sling/ide/impl/resource/transport/RepositoryFactoryImpl.java deleted file mode 100644 index fa5e9155..00000000 --- a/shared/impl-resource/src/main/java/org/apache/sling/ide/impl/resource/transport/RepositoryFactoryImpl.java +++ /dev/null @@ -1,65 +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.impl.resource.transport; - -import org.apache.sling.ide.log.Logger; -import org.apache.sling.ide.transport.Repository; -import org.apache.sling.ide.transport.RepositoryException; -import org.apache.sling.ide.transport.RepositoryFactory; -import org.apache.sling.ide.transport.RepositoryInfo; -import org.osgi.service.component.annotations.Activate; -import org.osgi.service.component.annotations.Component; -import org.osgi.service.component.annotations.Reference; - -/** - * The <tt>RepositoryFactoryImpl</tt> creates <tt>RepositoryImpl</tt> instances - * - */ -@Component(service = RepositoryFactory.class) -public class RepositoryFactoryImpl implements RepositoryFactory { - - private final Logger logger; - - /** - * Constructor to create this instance - * - * @param logger the logger - */ - @Activate - public RepositoryFactoryImpl(@Reference Logger logger) { - this.logger = logger; - } - - @Override - public Repository connectRepository(RepositoryInfo repositoryInfo) throws RepositoryException { - //TODO: currently not doing repository-caching - return new RepositoryImpl(repositoryInfo, logger); - } - - @Override - public Repository getRepository(RepositoryInfo repositoryInfo, - boolean acceptsDisconnectedRepository) throws RepositoryException { - //TODO: currently not doing repository-caching - return new RepositoryImpl(repositoryInfo, logger); - } - - @Override - public void disconnectRepository(RepositoryInfo repositoryInfo) { - //TODO: not yet implemented - } - -} diff --git a/shared/impl-resource/src/main/java/org/apache/sling/ide/impl/resource/transport/RepositoryImpl.java b/shared/impl-resource/src/main/java/org/apache/sling/ide/impl/resource/transport/RepositoryImpl.java deleted file mode 100644 index 948c0de9..00000000 --- a/shared/impl-resource/src/main/java/org/apache/sling/ide/impl/resource/transport/RepositoryImpl.java +++ /dev/null @@ -1,92 +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.impl.resource.transport; - -import org.apache.commons.httpclient.HttpClient; -import org.apache.sling.ide.log.Logger; -import org.apache.sling.ide.sync.content.WorkspaceFile; -import org.apache.sling.ide.transport.Command; -import org.apache.sling.ide.transport.CommandContext; -import org.apache.sling.ide.transport.NodeTypeRegistry; -import org.apache.sling.ide.transport.Repository; -import org.apache.sling.ide.transport.RepositoryInfo; -import org.apache.sling.ide.transport.ResourceProxy; -import org.apache.sling.ide.transport.Result; - -public class RepositoryImpl implements Repository { - - private final HttpClient httpClient = new HttpClient(); - private final RepositoryInfo repositoryInfo; - private final Logger logger; - - public RepositoryImpl(RepositoryInfo repositoryInfo, Logger logger) { - this.repositoryInfo = repositoryInfo; - this.logger = logger; - } - - @Override - public Command<Void> newDeleteNodeCommand(final String path) { - return new DeleteNodeCommand(path, repositoryInfo, httpClient); - } - - @Override - public Command<ResourceProxy> newListChildrenNodeCommand(final String path) { - return new ListChildrenCommand(repositoryInfo, httpClient, path + ".1.json"); - } - - @Override - public Command<byte[]> newGetNodeCommand(final String path) { - return new GetNodeCommand(repositoryInfo, httpClient, path); - } - - @Override - public Command<ResourceProxy> newGetNodeContentCommand(final String path) { - return new GetNodeContentCommand(repositoryInfo, httpClient, path + ".json"); - } - - @Override - public Command<Void> newAddOrUpdateNodeCommand(CommandContext context, final WorkspaceFile fileInfo, ResourceProxy resource, - CommandExecutionFlag... flags) { - if (flags.length != 0) { - throw new UnsupportedOperationException("This implementation does not support any flags"); - } - - return new UpdateContentCommand(repositoryInfo, httpClient, fileInfo, - resource.getProperties()); - } - - @Override - public Command<Void> newReorderChildNodesCommand(ResourceProxy resourceProxy) { - return new AbstractCommand<>(repositoryInfo, httpClient, resourceProxy.getPath()) { - @Override - public Result<Void> execute() { - // TODO - this is a no-op - return null; - } - }; - } - - @Override - public RepositoryInfo getRepositoryInfo() { - return repositoryInfo; - } - - @Override - public NodeTypeRegistry getNodeTypeRegistry() { - throw new IllegalStateException("not yet implemented"); - } -} diff --git a/shared/impl-resource/src/main/java/org/apache/sling/ide/impl/resource/transport/UpdateContentCommand.java b/shared/impl-resource/src/main/java/org/apache/sling/ide/impl/resource/transport/UpdateContentCommand.java deleted file mode 100644 index 205b9850..00000000 --- a/shared/impl-resource/src/main/java/org/apache/sling/ide/impl/resource/transport/UpdateContentCommand.java +++ /dev/null @@ -1,93 +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.impl.resource.transport; - -import java.io.File; -import java.util.ArrayList; -import java.util.List; -import java.util.Map; - -import org.apache.commons.httpclient.HttpClient; -import org.apache.commons.httpclient.UsernamePasswordCredentials; -import org.apache.commons.httpclient.auth.AuthScope; -import org.apache.commons.httpclient.methods.PostMethod; -import org.apache.commons.httpclient.methods.multipart.FilePart; -import org.apache.commons.httpclient.methods.multipart.MultipartRequestEntity; -import org.apache.commons.httpclient.methods.multipart.Part; -import org.apache.commons.httpclient.methods.multipart.StringPart; -import org.apache.sling.ide.sync.content.WorkspaceFile; -import org.apache.sling.ide.transport.ProtectedNodes; -import org.apache.sling.ide.transport.RepositoryException; -import org.apache.sling.ide.transport.RepositoryInfo; -import org.apache.sling.ide.transport.Result; - -class UpdateContentCommand extends AbstractCommand<Void> { - - private final Map<String, Object> properties; - private final WorkspaceFile file; - - UpdateContentCommand(RepositoryInfo repositoryInfo, HttpClient httpClient, WorkspaceFile fileInfo, - Map<String, Object> properties) { - super(repositoryInfo, httpClient, fileInfo.getPathRelativeToSyncDir().absolute().asPortableString()); - this.properties = properties; - this.file = fileInfo; - } - - @Override - public Result<Void> execute() { - PostMethod post = new PostMethod(getPath()); - try{ - List<Part> parts = new ArrayList<>(); - for (Map.Entry<String, Object> property : properties.entrySet()) { - if (ProtectedNodes.exists(property.getKey())) { - continue; - } - - Object propValue = property.getValue(); - - if (propValue instanceof String) { - parts.add(new StringPart(property.getKey(), (String) propValue)); - } else if (property != null) { - // TODO handle multi-valued properties - System.err.println("Unable to handle property " + property.getKey() + " of type " - + property.getValue().getClass()); - } - } - File osFile = file.getOSPath().toFile(); - if (osFile.isFile()) { - parts.add(new FilePart(osFile.getName(), osFile)); - } - post.setRequestEntity(new MultipartRequestEntity(parts.toArray(new Part[parts.size()]), post - .getParams())); - httpClient.getState().setCredentials(AuthScope.ANY, new UsernamePasswordCredentials(repositoryInfo.getUsername(),repositoryInfo.getPassword())); - httpClient.getParams().setAuthenticationPreemptive(true); - int responseStatus=httpClient.executeMethod(post); - - return resultForResponseStatus(responseStatus); - } catch(Exception e){ - return AbstractResult.failure(new RepositoryException(e)); - }finally{ - post.releaseConnection(); - } - } - - @Override - public String toString() { - - return String.format("%8s %s", "UPDATE", file.getPathRelativeToSyncDir() + "/" + file.getName()); - } -} \ No newline at end of file diff --git a/shared/impl-resource/src/main/java/org/apache/sling/ide/impl/resource/util/Constants.java b/shared/impl-resource/src/main/java/org/apache/sling/ide/impl/resource/util/Constants.java deleted file mode 100644 index 0bedeceb..00000000 --- a/shared/impl-resource/src/main/java/org/apache/sling/ide/impl/resource/util/Constants.java +++ /dev/null @@ -1,22 +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.impl.resource.util; - -public class Constants { - - public static final String PLUGIN_ID = "org.apache.sling.ide.impl-resource"; -} diff --git a/shared/impl-resource/src/test/java/org/apache/sling/ide/impl/resource/serialization/SimpleXmlSerializationManagerTest.java b/shared/impl-resource/src/test/java/org/apache/sling/ide/impl/resource/serialization/SimpleXmlSerializationManagerTest.java deleted file mode 100644 index a834564c..00000000 --- a/shared/impl-resource/src/test/java/org/apache/sling/ide/impl/resource/serialization/SimpleXmlSerializationManagerTest.java +++ /dev/null @@ -1,194 +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.impl.resource.serialization; - -import static org.custommonkey.xmlunit.XMLAssert.assertXMLEqual; -import static org.hamcrest.CoreMatchers.is; -import static org.hamcrest.CoreMatchers.nullValue; -import static org.junit.Assert.assertThat; - -import java.io.ByteArrayInputStream; -import java.io.File; -import java.io.IOException; -import java.io.InputStream; -import java.nio.file.Path; -import java.nio.file.Paths; -import java.util.HashMap; -import java.util.Map; - -import org.apache.sling.ide.content.sync.fs.impl.FSWorkspaceDirectory; -import org.apache.sling.ide.content.sync.fs.impl.FSWorkspaceFile; -import org.apache.sling.ide.content.sync.fs.impl.FSWorkspaceProject; -import org.apache.sling.ide.serialization.SerializationData; -import org.apache.sling.ide.serialization.SerializationException; -import org.apache.sling.ide.serialization.SerializationKind; -import org.apache.sling.ide.sync.content.WorkspaceDirectory; -import org.apache.sling.ide.sync.content.WorkspaceFile; -import org.apache.sling.ide.transport.ResourceProxy; -import org.custommonkey.xmlunit.XMLUnit; -import org.junit.Before; -import org.junit.BeforeClass; -import org.junit.Test; -import org.xml.sax.InputSource; -import org.xml.sax.SAXException; - -public class SimpleXmlSerializationManagerTest { - - private SimpleXmlSerializationManager sm; - - @BeforeClass - public static void configureXmlUnit() { - XMLUnit.setIgnoreWhitespace(true); - } - - @Before - public void prepare() { - sm = new SimpleXmlSerializationManager(); - } - - @Test - public void emptySerializedData() throws SerializationException, SAXException { - - SerializationData serializationData = sm.newBuilder(null, null).buildSerializationData(null, - newResourceWithProperties(new HashMap<>())); - - assertThat(serializationData, is(nullValue())); - } - - private ResourceProxy newResourceWithProperties(Map<String, Object> properties) { - ResourceProxy resource = new ResourceProxy("/"); - for (Map.Entry<String, Object> entry : properties.entrySet()) { - resource.addProperty(entry.getKey(), entry.getValue()); - } - return resource; - } - - @Test - public void nullSerializedData() throws SerializationException, SAXException { - - SerializationData serializationData = sm.newBuilder(null, null).buildSerializationData(null, null); - - assertThat(serializationData, is(nullValue())); - } - - @Test - public void stringSerializedData() throws SerializationException, SAXException, IOException { - - Map<String, Object> data = new HashMap<>(); - data.put("jcr:createdBy", "admin"); - data.put("jcr:lastModifiedBy", "author"); - - SerializationData serializationData = sm.newBuilder(null, null).buildSerializationData(null, newResourceWithProperties(data)); - - String methodName = "stringSerializedData"; - - assertXmlOutputIsEqualTo(serializationData.getContents(), methodName); - } - - private void assertXmlOutputIsEqualTo(byte[] serializationData, String methodName) throws SAXException, - SerializationException, IOException { - - InputStream doc = readSerializationDataFile(methodName); - - assertXMLEqual(new InputSource(doc), new InputSource(new ByteArrayInputStream(serializationData))); - } - - private InputStream readSerializationDataFile(String methodName) { - String name = getClass().getSimpleName() + "." + methodName + ".xml"; - InputStream doc = getClass().getResourceAsStream(name); - if (doc == null) - throw new RuntimeException("No test file found for '" + methodName + "'"); - return doc; - } - - @Test - public void serializedDataIsEscaped() throws SerializationException, SAXException, IOException { - - Map<String, Object> data = new HashMap<>(); - data.put("jcr:description", "<p class=\"active\">Welcome</p>"); - - SerializationData serializationData = sm.newBuilder(null, null).buildSerializationData(null, newResourceWithProperties(data)); - - String methodName = "serializedDataIsEscaped"; - - assertXmlOutputIsEqualTo(serializationData.getContents(), methodName); - } - - @Test - public void readSerializedData() throws IOException, SAXException { - - Map<String, Object> serializationData = sm - .readSerializationData(newWorkspaceFile(readSerializationDataFile("stringSerializedData"))).getProperties(); - - Map<String, Object> expected = new HashMap<>(); - expected.put("jcr:createdBy", "admin"); - expected.put("jcr:lastModifiedBy", "author"); - - assertThat(serializationData, is(expected)); - } - - @Test - public void serializationFileMatches() { - - assertThat(sm.isSerializationFile(newWorkspaceFile(".content.xml")), is(true)); - - } - - @Test - public void serializationFileDoesNotMatch() { - - assertThat(sm.isSerializationFile(newWorkspaceFile("content.json")), is(false)); - - } - - @Test - public void serializationFileLocation() { - - WorkspaceFile serializationFilePath = sm.getSerializationFile(newWorkspaceDirectory("content"), SerializationKind.FOLDER); - - assertThat(serializationFilePath.getPathRelativeToSyncDir().absolute().asPortableString(), is("/content/.content.xml")); - } - - private WorkspaceFile newWorkspaceFile(InputStream contents) { - - Path project = Paths.get("root", "project"); - - FSWorkspaceProject workspaceProject = new FSWorkspaceProject(project.toFile(), project.toFile(), null); - - Path filePath = project.resolve("jcr_root").resolve("file.xml"); - - return new FSWorkspaceFile(filePath.toFile(), workspaceProject) { - @Override - public InputStream getContents() throws IOException { - return contents; - } - }; - } - - private WorkspaceFile newWorkspaceFile(String fileName) { - File ioFile = Paths.get("root", "project", "jcr_root", fileName).toFile(); - FSWorkspaceProject project = new FSWorkspaceProject(ioFile.getParentFile().getParentFile(), ioFile.getParentFile().getParentFile(), null); - return new FSWorkspaceFile(ioFile, project); - } - - private WorkspaceDirectory newWorkspaceDirectory(String dirName) { - File ioFile = Paths.get("root", "project", "jcr_root", dirName).toFile(); - FSWorkspaceProject project = new FSWorkspaceProject(ioFile.getParentFile().getParentFile(), ioFile.getParentFile().getParentFile(), null); - return new FSWorkspaceDirectory(ioFile, project); - } - -} diff --git a/shared/impl-resource/src/test/resources/org/apache/sling/ide/impl/resource/serialization/SimpleXmlSerializationManagerTest.serializedDataIsEscaped.xml b/shared/impl-resource/src/test/resources/org/apache/sling/ide/impl/resource/serialization/SimpleXmlSerializationManagerTest.serializedDataIsEscaped.xml deleted file mode 100644 index c2f02060..00000000 --- a/shared/impl-resource/src/test/resources/org/apache/sling/ide/impl/resource/serialization/SimpleXmlSerializationManagerTest.serializedDataIsEscaped.xml +++ /dev/null @@ -1,20 +0,0 @@ -<?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. ---> -<resource> - <property name="jcr:description"><p class="active">Welcome</p></property> -</resource> diff --git a/shared/impl-resource/src/test/resources/org/apache/sling/ide/impl/resource/serialization/SimpleXmlSerializationManagerTest.stringSerializedData.xml b/shared/impl-resource/src/test/resources/org/apache/sling/ide/impl/resource/serialization/SimpleXmlSerializationManagerTest.stringSerializedData.xml deleted file mode 100644 index 15a2e9c2..00000000 --- a/shared/impl-resource/src/test/resources/org/apache/sling/ide/impl/resource/serialization/SimpleXmlSerializationManagerTest.stringSerializedData.xml +++ /dev/null @@ -1,21 +0,0 @@ -<?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. ---> -<resource> - <property name="jcr:createdBy">admin</property> - <property name="jcr:lastModifiedBy">author</property> -</resource> diff --git a/shared/pom.xml b/shared/pom.xml index cd49152b..ab016b6b 100644 --- a/shared/pom.xml +++ b/shared/pom.xml @@ -34,7 +34,6 @@ <modules> <module>parent</module> <module>api</module> - <module>impl-resource</module> <module>impl-vlt</module> <module>artifacts</module> <module>sync-fs</module>
