Author: rombert Date: Thu Sep 12 15:55:57 2013 New Revision: 1522636 URL: http://svn.apache.org/r1522636 Log: SLING-2989 - [Tooling] integrate with vlt once available
Follow vlt serialization rules closers, particularly in terms for full vs partial coverage. Added: sling/branches/tooling-ide-vlt/tooling/ide/eclipse-ui/src/org/apache/sling/ide/eclipse/ui/internal/SerializationKindManager.java (with props) Modified: sling/branches/tooling-ide-vlt/tooling/ide/api/src/org/apache/sling/ide/util/PathUtil.java sling/branches/tooling-ide-vlt/tooling/ide/eclipse-ui/src/org/apache/sling/ide/eclipse/ui/internal/ImportWizard.java sling/branches/tooling-ide-vlt/tooling/ide/impl-vlt/src/org/apache/sling/ide/impl/vlt/serialization/VltSerializationManager.java sling/branches/tooling-ide-vlt/tooling/ide/vlt-wrapper/META-INF/MANIFEST.MF Modified: sling/branches/tooling-ide-vlt/tooling/ide/api/src/org/apache/sling/ide/util/PathUtil.java URL: http://svn.apache.org/viewvc/sling/branches/tooling-ide-vlt/tooling/ide/api/src/org/apache/sling/ide/util/PathUtil.java?rev=1522636&r1=1522635&r2=1522636&view=diff ============================================================================== --- sling/branches/tooling-ide-vlt/tooling/ide/api/src/org/apache/sling/ide/util/PathUtil.java (original) +++ sling/branches/tooling-ide-vlt/tooling/ide/api/src/org/apache/sling/ide/util/PathUtil.java Thu Sep 12 15:55:57 2013 @@ -32,4 +32,9 @@ public class PathUtil { throw new AssertionError("unreachable"); } + + public static String getName(String path) { + + return path.substring(path.lastIndexOf('/') + 1); + } } Modified: sling/branches/tooling-ide-vlt/tooling/ide/eclipse-ui/src/org/apache/sling/ide/eclipse/ui/internal/ImportWizard.java URL: http://svn.apache.org/viewvc/sling/branches/tooling-ide-vlt/tooling/ide/eclipse-ui/src/org/apache/sling/ide/eclipse/ui/internal/ImportWizard.java?rev=1522636&r1=1522635&r2=1522636&view=diff ============================================================================== --- sling/branches/tooling-ide-vlt/tooling/ide/eclipse-ui/src/org/apache/sling/ide/eclipse/ui/internal/ImportWizard.java (original) +++ sling/branches/tooling-ide-vlt/tooling/ide/eclipse-ui/src/org/apache/sling/ide/eclipse/ui/internal/ImportWizard.java Thu Sep 12 15:55:57 2013 @@ -34,6 +34,7 @@ import org.apache.sling.ide.transport.Re import org.apache.sling.ide.transport.RepositoryException; import org.apache.sling.ide.transport.ResourceProxy; import org.apache.sling.ide.transport.Result; +import org.apache.sling.ide.util.PathUtil; import org.eclipse.core.resources.IFile; import org.eclipse.core.resources.IFolder; import org.eclipse.core.resources.IProject; @@ -42,6 +43,7 @@ import org.eclipse.core.resources.Resour import org.eclipse.core.runtime.CoreException; import org.eclipse.core.runtime.IPath; import org.eclipse.core.runtime.IProgressMonitor; +import org.eclipse.core.runtime.Path; import org.eclipse.core.runtime.Status; import org.eclipse.jface.operation.IRunnableWithProgress; import org.eclipse.jface.viewers.IStructuredSelection; @@ -87,6 +89,7 @@ public class ImportWizard extends Wizard final String repositoryPath = mainPage.getRepositoryPath(); final IFile filterFile = mainPage.getFilterFile(); try { + // TODO the headless logic should move to the service layer of reuse and testing getContainer().run(false, true, new IRunnableWithProgress() { @Override @@ -105,6 +108,15 @@ public class ImportWizard extends Wizard launchpad.setPublishState(ISlingLaunchpadServer.PUBLISH_STATE_NEVER, monitor); } + SerializationKindManager skm; + + try { + skm = new SerializationKindManager(); + skm.init(repository); + } catch (RepositoryException e1) { + throw new InvocationTargetException(e1); + } + Filter filter = null; if (filterFile != null && filterFile.exists()) { FilterLocator filterLocator = Activator.getDefault().getFilterLocator(); @@ -138,7 +150,7 @@ public class ImportWizard extends Wizard // we create the root node and assume this is a folder createRoot(project, projectRelativePath, repositoryPath); - crawlChildrenAndImport(repository, filter, repositoryPath, project, projectRelativePath); + crawlChildrenAndImport(repository, filter, repositoryPath, project, projectRelativePath, skm); monitor.setTaskName("Import Complete"); monitor.worked(100); @@ -210,6 +222,7 @@ public class ImportWizard extends Wizard * @param path the current path to import from * @param project the project to create resources in * @param projectRelativePath the path, relative to the project root, where the resources should be created + * @param skm * @param tracer * @throws JSONException * @throws RepositoryException @@ -218,7 +231,7 @@ public class ImportWizard extends Wizard */ // TODO: This probably should be pushed into the service layer private void crawlChildrenAndImport(Repository repository, Filter filter, String path, IProject project, - IPath projectRelativePath) throws RepositoryException, CoreException, IOException { + IPath projectRelativePath, SerializationKindManager skm) throws RepositoryException, CoreException, IOException { File contentSyncRoot = ProjectUtil.getSyncDirectoryFullPath(project).toFile(); @@ -228,23 +241,63 @@ public class ImportWizard extends Wizard ResourceProxy resource = executeCommand(repository.newListChildrenNodeCommand(path)); String primaryType = (String) resource.getProperties().get(Repository.JCR_PRIMARY_TYPE); - if (Repository.NT_FILE.equals(primaryType)){ - importFile(repository, path, project, projectRelativePath); - }else if (Repository.NT_FOLDER.equals(primaryType)){ - createFolder(project, projectRelativePath.append(path)); - }else if(Repository.NT_RESOURCE.equals(primaryType)){ - //DO NOTHING - } else { - createFolder(project, projectRelativePath.append(path)); - ResourceProxy resourceToSerialize = executeCommand(repository.newGetNodeContentCommand(path)); - - String out = serializationManager.buildSerializationData(contentSyncRoot, - resourceToSerialize, repository.getRepositoryInfo()); - if (out != null) { - createFile(project, projectRelativePath.append(serializationManager.getSerializationFilePath(path)), - out.getBytes("UTF-8")); + System.out.println(primaryType + " -> " + skm.getSerializationKind(primaryType)); + + // TODO we should know all node types for which to create files and folders + + String serializationPath = serializationManager.getSerializationFilePath(path); + switch (skm.getSerializationKind(primaryType)) { + case FILE: + importFile(repository, path, project, projectRelativePath); + // TODO support ${filename}.dir serialization of properties + break; + + case FOLDER: + case METADATA_PARTIAL: { + createFolder(project, projectRelativePath.append(path)); + ResourceProxy resourceToSerialize = executeCommand(repository.newGetNodeContentCommand(path)); + + String out = serializationManager.buildSerializationData(contentSyncRoot, resourceToSerialize, + repository.getRepositoryInfo()); + if (out != null) { + createFile(project, + projectRelativePath.append(serializationPath), + out.getBytes("UTF-8")); + } + break; } - } + + case METADATA_FULL: { + ResourceProxy resourceToSerialize = executeCommand(repository.newGetNodeContentCommand(path)); + + String out = serializationManager.buildSerializationData(contentSyncRoot, resourceToSerialize, + repository.getRepositoryInfo()); + + if (out != null) { + // TODO - picking the base name based on serialization kind is not supported by the API... + // so for now this is one big hack to have vlt-compatible checkouts + IPath serializationPathPath = Path.fromPortableString(serializationPath); + if (!resourceToSerialize.getPath().equals("/") && serializationPath.endsWith(".content.xml")) { + String name = PathUtil.getName(path); + if (name.indexOf(':') != -1) { + name = '_' + name.replace(':', '_'); + } + name += ".xml"; + serializationPath = serializationPath.replace(".content.xml", name); + + // some of the logic should be reused from AbstractArtifact + serializationPathPath = Path.fromPortableString(serializationPath).removeFirstSegments(1); + } + + + + createFile(project, + projectRelativePath.append(serializationPathPath), + out.getBytes("UTF-8")); + } + break; + } + } System.out.println("Children: " + resource.getChildren()); @@ -263,7 +316,7 @@ public class ImportWizard extends Wizard } crawlChildrenAndImport(repository, filter, child.getPath(), project, - projectRelativePath); + projectRelativePath, skm); } } Added: sling/branches/tooling-ide-vlt/tooling/ide/eclipse-ui/src/org/apache/sling/ide/eclipse/ui/internal/SerializationKindManager.java URL: http://svn.apache.org/viewvc/sling/branches/tooling-ide-vlt/tooling/ide/eclipse-ui/src/org/apache/sling/ide/eclipse/ui/internal/SerializationKindManager.java?rev=1522636&view=auto ============================================================================== --- sling/branches/tooling-ide-vlt/tooling/ide/eclipse-ui/src/org/apache/sling/ide/eclipse/ui/internal/SerializationKindManager.java (added) +++ sling/branches/tooling-ide-vlt/tooling/ide/eclipse-ui/src/org/apache/sling/ide/eclipse/ui/internal/SerializationKindManager.java Thu Sep 12 15:55:57 2013 @@ -0,0 +1,131 @@ +/* + * 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.ui.internal; + +import java.util.HashMap; +import java.util.HashSet; +import java.util.Map; +import java.util.Set; + +import org.apache.sling.ide.transport.Repository; +import org.apache.sling.ide.transport.RepositoryException; +import org.apache.sling.ide.transport.ResourceProxy; +import org.apache.sling.ide.transport.Result; +import org.apache.sling.ide.util.PathUtil; + +// TODO this should be made API after merging the vlt branch back to trunk +public class SerializationKindManager { + + // TODO this list should be picked up from the config.xml file, not hardcoded + private final Set<String> fullMetadataNodeTypes = new HashSet<String>(); + { + fullMetadataNodeTypes.add("rep:AccessControl"); + fullMetadataNodeTypes.add("rep:Policy"); + fullMetadataNodeTypes.add("cq:Widget"); + fullMetadataNodeTypes.add("cq:EditConfig"); + fullMetadataNodeTypes.add("cq:WorkflowModel"); + fullMetadataNodeTypes.add("vlt:FullCoverage"); + fullMetadataNodeTypes.add("mix:language"); + fullMetadataNodeTypes.add("sling:OsgiConfig"); + } + private final Set<String> fileNodeTypes = new HashSet<String>(); + private final Set<String> folderNodeTypes = new HashSet<String>(); + + public void init(Repository repository) throws RepositoryException { + + // first pass, init the mappings + Map<String, String[]> nodeTypesToParentNodeTypes = new HashMap<String, String[]>(); + + Result<ResourceProxy> jcrSystem = repository.newListChildrenNodeCommand("/jcr:system/jcr:nodeTypes").execute(); + for (ResourceProxy child : jcrSystem.get().getChildren()) { + String nodeType = PathUtil.getName(child.getPath()); + String[] superTypes = (String[]) child.getProperties().get("jcr:supertypes"); + + if (superTypes.length == 0) { + continue; + } + + nodeTypesToParentNodeTypes.put(nodeType, superTypes); + } + + // detect node types which have an nt:file or nt:folder parent in the hierarchy + for (String nodeType : nodeTypesToParentNodeTypes.keySet()) { + SerializationKind serializationKind = getSerializationKind(nodeType, nodeTypesToParentNodeTypes); + if (serializationKind == null) { + // don't care + continue; + } + switch (serializationKind) { + case FILE: + fileNodeTypes.add(nodeType); + break; + case FOLDER: + folderNodeTypes.add(nodeType); + break; + default: + // don't care + break; + } + + } + } + + private SerializationKind getSerializationKind(String nodeType, Map<String, String[]> nodeTypesToParentNodeTypes) { + + if (Repository.NT_FILE.equals(nodeType)) { + return SerializationKind.FILE; + } + + if (Repository.NT_FOLDER.equals(nodeType)) { + return SerializationKind.FOLDER; + } + + String[] parents = nodeTypesToParentNodeTypes.get(nodeType); + if (parents == null) + return null; + + for (String parent : parents) { + SerializationKind parentSerializationKind = getSerializationKind(parent, nodeTypesToParentNodeTypes); + if (parentSerializationKind != null) { + return parentSerializationKind; + } + } + + return null; + } + + public SerializationKind getSerializationKind(String nodeTypeName) { + + if (fileNodeTypes.contains(nodeTypeName)) { + return SerializationKind.FILE; + } + + if (folderNodeTypes.contains(nodeTypeName)) { + return SerializationKind.FOLDER; + } + + if (fullMetadataNodeTypes.contains(nodeTypeName)) { + return SerializationKind.METADATA_FULL; + } + + return SerializationKind.METADATA_PARTIAL; + } + + enum SerializationKind { + FILE, FOLDER, METADATA_PARTIAL, METADATA_FULL; + } +} Propchange: sling/branches/tooling-ide-vlt/tooling/ide/eclipse-ui/src/org/apache/sling/ide/eclipse/ui/internal/SerializationKindManager.java ------------------------------------------------------------------------------ svn:eol-style = native Propchange: sling/branches/tooling-ide-vlt/tooling/ide/eclipse-ui/src/org/apache/sling/ide/eclipse/ui/internal/SerializationKindManager.java ------------------------------------------------------------------------------ svn:keywords = Author Date Id Revision Rev URL Modified: sling/branches/tooling-ide-vlt/tooling/ide/impl-vlt/src/org/apache/sling/ide/impl/vlt/serialization/VltSerializationManager.java URL: http://svn.apache.org/viewvc/sling/branches/tooling-ide-vlt/tooling/ide/impl-vlt/src/org/apache/sling/ide/impl/vlt/serialization/VltSerializationManager.java?rev=1522636&r1=1522635&r2=1522636&view=diff ============================================================================== --- sling/branches/tooling-ide-vlt/tooling/ide/impl-vlt/src/org/apache/sling/ide/impl/vlt/serialization/VltSerializationManager.java (original) +++ sling/branches/tooling-ide-vlt/tooling/ide/impl-vlt/src/org/apache/sling/ide/impl/vlt/serialization/VltSerializationManager.java Thu Sep 12 15:55:57 2013 @@ -20,16 +20,19 @@ import java.io.ByteArrayOutputStream; import java.io.File; import java.io.IOException; import java.io.InputStream; +import java.net.URISyntaxException; import java.util.Map; import javax.jcr.Credentials; import javax.jcr.Repository; import javax.jcr.RepositoryException; import javax.jcr.Session; +import javax.jcr.SimpleCredentials; import javax.xml.parsers.ParserConfigurationException; import javax.xml.parsers.SAXParser; import javax.xml.parsers.SAXParserFactory; +import org.apache.jackrabbit.vault.fs.Mounter; import org.apache.jackrabbit.vault.fs.api.Aggregate; import org.apache.jackrabbit.vault.fs.api.RepositoryAddress; import org.apache.jackrabbit.vault.fs.api.VaultFile; @@ -37,6 +40,8 @@ import org.apache.jackrabbit.vault.fs.ap import org.apache.jackrabbit.vault.fs.config.ConfigurationException; import org.apache.jackrabbit.vault.fs.impl.io.DocViewSerializer; import org.apache.jackrabbit.vault.util.Constants; +import org.apache.jackrabbit.vault.util.PlatformNameFormat; +import org.apache.jackrabbit.vault.util.RepositoryProvider; import org.apache.sling.ide.impl.vlt.RepositoryUtils; import org.apache.sling.ide.impl.vlt.VaultFsLocator; import org.apache.sling.ide.serialization.SerializationManager; @@ -46,6 +51,32 @@ import org.xml.sax.SAXException; public class VltSerializationManager implements SerializationManager { + public static void main(String[] args) throws RepositoryException, URISyntaxException, IOException { + RepositoryAddress address = new RepositoryAddress("http://localhost:8080/server/root"); + Repository repo = new RepositoryProvider().getRepository(address); + Session session = repo.login(new SimpleCredentials("admin", "admin".toCharArray())); + + VaultFileSystem fs = Mounter.mount(null, null, address, "/", session); + + String[] attempts = new String[] { "/rep:policy", "/var" }; + + for (String attempt : attempts) { + VaultFile vaultFile = fs.getFile(attempt); + + System.out.println(attempt + " -> " + vaultFile); + } + + for (String attempt : attempts) { + + attempt = PlatformNameFormat.getPlatformPath(attempt) + ".xml"; + + VaultFile vaultFile = fs.getFile(attempt); + + System.out.println(attempt + " -> " + vaultFile); + } + + } + private VaultFsLocator fsLocator; @Override @@ -75,6 +106,8 @@ public class VltSerializationManager imp this.fsLocator = null; } + // TODO - the return type could look like (byte[] contents, String nameHint, SerializationKind sk) + @Override public String buildSerializationData(File contentSyncRoot, ResourceProxy resource, RepositoryInfo repositoryInfo) throws IOException { @@ -95,12 +128,20 @@ public class VltSerializationManager imp VaultFile vaultFile = fs.getFile(resource.getPath()); if (vaultFile == null) { - // TODO proper logging ; discover if this is expected or not - System.err.println("No vaultFile at path " + resource.getPath()); - return null; + + // TODO - not sure why we need to try both ... not a performance impact but ugly nonetheless + String platformPath = PlatformNameFormat.getPlatformPath(resource.getPath()) + ".xml"; + vaultFile = fs.getFile(platformPath); + + if (vaultFile == null) { + // TODO proper logging ; discover if this is expected or not + System.err.println("No vaultFile at path " + resource.getPath()); + return null; + } } Aggregate aggregate = vaultFile.getAggregate(); + if (aggregate == null) throw new IllegalArgumentException("No aggregate found for path " + resource.getPath()); Modified: sling/branches/tooling-ide-vlt/tooling/ide/vlt-wrapper/META-INF/MANIFEST.MF URL: http://svn.apache.org/viewvc/sling/branches/tooling-ide-vlt/tooling/ide/vlt-wrapper/META-INF/MANIFEST.MF?rev=1522636&r1=1522635&r2=1522636&view=diff ============================================================================== --- sling/branches/tooling-ide-vlt/tooling/ide/vlt-wrapper/META-INF/MANIFEST.MF (original) +++ sling/branches/tooling-ide-vlt/tooling/ide/vlt-wrapper/META-INF/MANIFEST.MF Thu Sep 12 15:55:57 2013 @@ -45,6 +45,7 @@ Import-Package: org.apache.commons.httpc org.apache.commons.httpclient.methods.multipart;version="3.1.0", org.apache.commons.httpclient.params;version="3.1.0", org.apache.commons.httpclient.util;version="3.1.0", + org.apache.commons.collections, org.apache.commons.collections.map, org.apache.commons.collections.list, org.apache.commons.collections.iterators,