X-Git-Url: http://git.argeo.org/?a=blobdiff_plain;f=runtime%2Forg.argeo.slc.repo%2Fsrc%2Fmain%2Fjava%2Forg%2Fargeo%2Fslc%2Frepo%2Fmaven%2Fproxy%2FMavenProxyServiceImpl.java;h=ee5c5ff5c84c62f3a0019f003cd8d1d478492baf;hb=44c43b9c874d7c6edd4327f180d5506b3e9c99e6;hp=19df339a27b44b96c74c65853fcfb31be45e1e34;hpb=912cf5554a61dc35fb61183da39673656b668467;p=gpl%2Fargeo-slc.git diff --git a/runtime/org.argeo.slc.repo/src/main/java/org/argeo/slc/repo/maven/proxy/MavenProxyServiceImpl.java b/runtime/org.argeo.slc.repo/src/main/java/org/argeo/slc/repo/maven/proxy/MavenProxyServiceImpl.java index 19df339a2..ee5c5ff5c 100644 --- a/runtime/org.argeo.slc.repo/src/main/java/org/argeo/slc/repo/maven/proxy/MavenProxyServiceImpl.java +++ b/runtime/org.argeo.slc.repo/src/main/java/org/argeo/slc/repo/maven/proxy/MavenProxyServiceImpl.java @@ -1,3 +1,18 @@ +/* + * Copyright (C) 2007-2012 Mathieu Baudier + * + * Licensed 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.argeo.slc.repo.maven.proxy; import java.util.ArrayList; @@ -6,6 +21,8 @@ import java.util.List; import javax.jcr.Node; import javax.jcr.NodeIterator; import javax.jcr.RepositoryException; +import javax.jcr.Session; +import javax.jcr.nodetype.NodeType; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; @@ -14,6 +31,7 @@ import org.argeo.jcr.JcrUtils; import org.argeo.jcr.proxy.AbstractUrlProxy; import org.argeo.slc.SlcException; import org.argeo.slc.jcr.SlcNames; +import org.argeo.slc.jcr.SlcTypes; import org.argeo.slc.repo.RepoConstants; import org.sonatype.aether.repository.RemoteRepository; @@ -25,16 +43,24 @@ public class MavenProxyServiceImpl extends AbstractUrlProxy implements private List defaultRepositories = new ArrayList(); + private boolean rootNodeIsArtifactBase = RepoConstants.ARTIFACTS_BASE_PATH + .equals("/"); + + /** Inititalizes the artifacts area. */ @Override - protected void beforeInitSessionSave() throws RepositoryException { - JcrUtils.mkdirs(getJcrAdminSession(), RepoConstants.ARTIFACTS_BASE_PATH); - Node proxiedRepositories = JcrUtils.mkdirs(getJcrAdminSession(), + protected void beforeInitSessionSave(Session session) + throws RepositoryException { + JcrUtils.mkdirsSafe(session, RepoConstants.ARTIFACTS_BASE_PATH); + Node proxiedRepositories = JcrUtils.mkdirsSafe(session, RepoConstants.PROXIED_REPOSITORIES); for (RemoteRepository repository : defaultRepositories) { if (!proxiedRepositories.hasNode(repository.getId())) { Node proxiedRepository = proxiedRepositories.addNode(repository .getId()); - proxiedRepository.setProperty(SLC_URL, repository.getUrl()); + proxiedRepository.addMixin(NodeType.MIX_REFERENCEABLE); + JcrUtils.urlToAddressProperties(proxiedRepository, + repository.getUrl()); + // proxiedRepository.setProperty(SLC_URL, repository.getUrl()); proxiedRepository.setProperty(SLC_TYPE, repository.getContentType()); } @@ -44,41 +70,52 @@ public class MavenProxyServiceImpl extends AbstractUrlProxy implements /** * Retrieve and add this file to the repository */ - protected String retrieve(String path) { + @Override + protected Node retrieve(Session session, String path) { try { + if (session.hasPendingChanges()) + throw new SlcException("Session has pending changed"); Node node = null; - baseUrls: for (String baseUrl : getBaseUrls()) { - node = proxyUrl(baseUrl, path); - if (node != null) - break baseUrls; - } - - if (node != null) - return node.getIdentifier(); - else { - log.warn("Could not proxy " + path); - return null; + for (Node proxiedRepository : getBaseUrls(session)) { + String baseUrl = JcrUtils + .urlFromAddressProperties(proxiedRepository); + node = proxyUrl(session, baseUrl, path); + if (node != null) { + node.addMixin(SlcTypes.SLC_KNOWN_ORIGIN); + Node origin = node + .addNode(SLC_ORIGIN, SlcTypes.SLC_PROXIED); + origin.setProperty(SLC_PROXY, proxiedRepository); + JcrUtils.urlToAddressProperties(origin, baseUrl + path); + if (log.isDebugEnabled()) + log.debug("Imported " + baseUrl + path + " to " + node); + return node; + } } - } catch (RepositoryException e) { + if (log.isDebugEnabled()) + log.warn("No proxy found for " + path); + return null; + } catch (Exception e) { throw new SlcException("Cannot proxy " + path, e); } } - protected synchronized List getBaseUrls() + protected synchronized List getBaseUrls(Session session) throws RepositoryException { - List baseUrls = new ArrayList(); - for (NodeIterator nit = getJcrAdminSession().getNode( + List baseUrls = new ArrayList(); + for (NodeIterator nit = session.getNode( RepoConstants.PROXIED_REPOSITORIES).getNodes(); nit.hasNext();) { Node proxiedRepository = nit.nextNode(); - String repoUrl = proxiedRepository.getProperty(SLC_URL).getString(); - baseUrls.add(repoUrl); + baseUrls.add(proxiedRepository); } return baseUrls; } /** The JCR path where this file could be found */ public String getNodePath(String path) { - return RepoConstants.ARTIFACTS_BASE_PATH + path; + if (rootNodeIsArtifactBase) + return path; + else + return RepoConstants.ARTIFACTS_BASE_PATH + path; } public void setDefaultRepositories(