From: Mathieu Baudier Date: Sun, 26 May 2013 14:21:27 +0000 (+0000) Subject: Introduce RPM Factory X-Git-Tag: argeo-slc-2.1.7~352 X-Git-Url: http://git.argeo.org/?a=commitdiff_plain;ds=sidebyside;h=c99e24b88d70ff503272b0654782aedd81086e9f;p=gpl%2Fargeo-slc.git Introduce RPM Factory git-svn-id: https://svn.argeo.org/slc/trunk@6303 4cfe0d0a-d680-48aa-b62c-e0a02a3f76cc --- diff --git a/runtime/org.argeo.slc.rpmfactory/pom.xml b/runtime/org.argeo.slc.rpmfactory/pom.xml index bb8b16133..d8ef23fe3 100644 --- a/runtime/org.argeo.slc.rpmfactory/pom.xml +++ b/runtime/org.argeo.slc.rpmfactory/pom.xml @@ -22,6 +22,8 @@ org.argeo.slc.rpmfactory.* + javax.jcr.nodetype, + org.argeo.slc.repo, * diff --git a/runtime/org.argeo.slc.rpmfactory/src/main/java/org/argeo/slc/rpmfactory/MavenProxyService.java b/runtime/org.argeo.slc.rpmfactory/src/main/java/org/argeo/slc/rpmfactory/MavenProxyService.java deleted file mode 100644 index d2469f829..000000000 --- a/runtime/org.argeo.slc.rpmfactory/src/main/java/org/argeo/slc/rpmfactory/MavenProxyService.java +++ /dev/null @@ -1,22 +0,0 @@ -/* - * Copyright (C) 2007-2012 Argeo GmbH - * - * 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.rpmfactory; - -import org.argeo.jcr.proxy.ResourceProxy; - -/** Marker interface (useful for OSGi servcies references), maybe extended later */ -public interface MavenProxyService extends ResourceProxy { -} diff --git a/runtime/org.argeo.slc.rpmfactory/src/main/java/org/argeo/slc/rpmfactory/RpmProxyService.java b/runtime/org.argeo.slc.rpmfactory/src/main/java/org/argeo/slc/rpmfactory/RpmProxyService.java new file mode 100644 index 000000000..bd59838ee --- /dev/null +++ b/runtime/org.argeo.slc.rpmfactory/src/main/java/org/argeo/slc/rpmfactory/RpmProxyService.java @@ -0,0 +1,22 @@ +/* + * Copyright (C) 2007-2012 Argeo GmbH + * + * 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.rpmfactory; + +import org.argeo.jcr.proxy.ResourceProxy; + +/** Marker interface (useful for OSGi servcies references), maybe extended later */ +public interface RpmProxyService extends ResourceProxy { +} diff --git a/runtime/org.argeo.slc.rpmfactory/src/main/java/org/argeo/slc/rpmfactory/core/MavenProxyServiceImpl.java b/runtime/org.argeo.slc.rpmfactory/src/main/java/org/argeo/slc/rpmfactory/core/MavenProxyServiceImpl.java deleted file mode 100644 index 4f8a022d0..000000000 --- a/runtime/org.argeo.slc.rpmfactory/src/main/java/org/argeo/slc/rpmfactory/core/MavenProxyServiceImpl.java +++ /dev/null @@ -1,129 +0,0 @@ -/* - * Copyright (C) 2007-2012 Argeo GmbH - * - * 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.rpmfactory.core; - -import java.util.ArrayList; -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; -import org.argeo.jcr.ArgeoNames; -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.argeo.slc.rpmfactory.MavenProxyService; -import org.argeo.slc.rpmfactory.RpmRepository; - -/** Synchronizes the node repository with remote Maven repositories */ -public class MavenProxyServiceImpl extends AbstractUrlProxy implements - MavenProxyService, ArgeoNames, SlcNames { - private final static Log log = LogFactory - .getLog(MavenProxyServiceImpl.class); - - private List defaultRepositories = new ArrayList(); - - private String artifactsBasePath = RepoConstants.DEFAULT_ARTIFACTS_BASE_PATH; - - /** Inititalizes the artifacts area. */ - @Override - protected void beforeInitSessionSave(Session session) - throws RepositoryException { - JcrUtils.mkdirsSafe(session, RepoConstants.DEFAULT_ARTIFACTS_BASE_PATH); - Node proxiedRepositories = JcrUtils.mkdirsSafe(session, - RepoConstants.PROXIED_REPOSITORIES); - for (RpmRepository repository : defaultRepositories) { - if (!proxiedRepositories.hasNode(repository.getId())) { - Node proxiedRepository = proxiedRepositories.addNode(repository - .getId()); - proxiedRepository.addMixin(NodeType.MIX_REFERENCEABLE); - JcrUtils.urlToAddressProperties(proxiedRepository, - repository.getUrl()); - // proxiedRepository.setProperty(SLC_URL, repository.getUrl()); - // proxiedRepository.setProperty(SLC_TYPE, - // repository.getContentType()); - } - } - } - - /** - * Retrieve and add this file to the repository - */ - @Override - protected Node retrieve(Session session, String path) { - try { - if (session.hasPendingChanges()) - throw new SlcException("Session has pending changed"); - Node node = 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; - } - } - 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(Session session) - throws RepositoryException { - List baseUrls = new ArrayList(); - for (NodeIterator nit = session.getNode( - RepoConstants.PROXIED_REPOSITORIES).getNodes(); nit.hasNext();) { - Node proxiedRepository = nit.nextNode(); - baseUrls.add(proxiedRepository); - } - return baseUrls; - } - - /** The JCR path where this file could be found */ - public String getNodePath(String path) { - if (artifactsBasePath.equals(RepoConstants.DEFAULT_ARTIFACTS_BASE_PATH)) - return path; - else - return artifactsBasePath + path; - } - - public void setDefaultRepositories(List defaultRepositories) { - this.defaultRepositories = defaultRepositories; - } - - public void setArtifactsBasePath(String artifactsBasePath) { - this.artifactsBasePath = artifactsBasePath; - } - -} diff --git a/runtime/org.argeo.slc.rpmfactory/src/main/java/org/argeo/slc/rpmfactory/core/RpmProxyServiceImpl.java b/runtime/org.argeo.slc.rpmfactory/src/main/java/org/argeo/slc/rpmfactory/core/RpmProxyServiceImpl.java new file mode 100644 index 000000000..72958ba0a --- /dev/null +++ b/runtime/org.argeo.slc.rpmfactory/src/main/java/org/argeo/slc/rpmfactory/core/RpmProxyServiceImpl.java @@ -0,0 +1,129 @@ +/* + * Copyright (C) 2007-2012 Argeo GmbH + * + * 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.rpmfactory.core; + +import java.util.ArrayList; +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; +import org.argeo.jcr.ArgeoNames; +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.argeo.slc.rpmfactory.RpmProxyService; +import org.argeo.slc.rpmfactory.RpmRepository; + +/** Synchronizes the node repository with remote Maven repositories */ +public class RpmProxyServiceImpl extends AbstractUrlProxy implements + RpmProxyService, ArgeoNames, SlcNames { + private final static Log log = LogFactory + .getLog(RpmProxyServiceImpl.class); + + private List defaultRepositories = new ArrayList(); + + private String artifactsBasePath = RepoConstants.DEFAULT_ARTIFACTS_BASE_PATH; + + /** Inititalizes the artifacts area. */ + @Override + protected void beforeInitSessionSave(Session session) + throws RepositoryException { + JcrUtils.mkdirsSafe(session, RepoConstants.DEFAULT_ARTIFACTS_BASE_PATH); + Node proxiedRepositories = JcrUtils.mkdirsSafe(session, + RepoConstants.PROXIED_REPOSITORIES); + for (RpmRepository repository : defaultRepositories) { + if (!proxiedRepositories.hasNode(repository.getId())) { + Node proxiedRepository = proxiedRepositories.addNode(repository + .getId()); + proxiedRepository.addMixin(NodeType.MIX_REFERENCEABLE); + JcrUtils.urlToAddressProperties(proxiedRepository, + repository.getUrl()); + // proxiedRepository.setProperty(SLC_URL, repository.getUrl()); + // proxiedRepository.setProperty(SLC_TYPE, + // repository.getContentType()); + } + } + } + + /** + * Retrieve and add this file to the repository + */ + @Override + protected Node retrieve(Session session, String path) { + try { + if (session.hasPendingChanges()) + throw new SlcException("Session has pending changed"); + Node node = 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; + } + } + 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(Session session) + throws RepositoryException { + List baseUrls = new ArrayList(); + for (NodeIterator nit = session.getNode( + RepoConstants.PROXIED_REPOSITORIES).getNodes(); nit.hasNext();) { + Node proxiedRepository = nit.nextNode(); + baseUrls.add(proxiedRepository); + } + return baseUrls; + } + + /** The JCR path where this file could be found */ + public String getNodePath(String path) { + if (artifactsBasePath.equals(RepoConstants.DEFAULT_ARTIFACTS_BASE_PATH)) + return path; + else + return artifactsBasePath + path; + } + + public void setDefaultRepositories(List defaultRepositories) { + this.defaultRepositories = defaultRepositories; + } + + public void setArtifactsBasePath(String artifactsBasePath) { + this.artifactsBasePath = artifactsBasePath; + } + +}