Introduce RPM Factory
authorMathieu Baudier <mbaudier@argeo.org>
Sun, 26 May 2013 14:09:46 +0000 (14:09 +0000)
committerMathieu Baudier <mbaudier@argeo.org>
Sun, 26 May 2013 14:09:46 +0000 (14:09 +0000)
git-svn-id: https://svn.argeo.org/slc/trunk@6302 4cfe0d0a-d680-48aa-b62c-e0a02a3f76cc

runtime/org.argeo.slc.rpmfactory/.classpath [new file with mode: 0644]
runtime/org.argeo.slc.rpmfactory/.project [new file with mode: 0644]
runtime/org.argeo.slc.rpmfactory/.settings/org.eclipse.jdt.core.prefs [new file with mode: 0644]
runtime/org.argeo.slc.rpmfactory/.settings/org.eclipse.pde.core.prefs [new file with mode: 0644]
runtime/org.argeo.slc.rpmfactory/build.properties [new file with mode: 0644]
runtime/org.argeo.slc.rpmfactory/pom.xml [new file with mode: 0644]
runtime/org.argeo.slc.rpmfactory/src/main/java/org/argeo/slc/rpmfactory/MavenProxyService.java [new file with mode: 0644]
runtime/org.argeo.slc.rpmfactory/src/main/java/org/argeo/slc/rpmfactory/RpmRepository.java [new file with mode: 0644]
runtime/org.argeo.slc.rpmfactory/src/main/java/org/argeo/slc/rpmfactory/core/MavenProxyServiceImpl.java [new file with mode: 0644]
runtime/pom.xml

diff --git a/runtime/org.argeo.slc.rpmfactory/.classpath b/runtime/org.argeo.slc.rpmfactory/.classpath
new file mode 100644 (file)
index 0000000..8cf7f48
--- /dev/null
@@ -0,0 +1,7 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<classpath>
+       <classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-1.6"/>
+       <classpathentry kind="con" path="org.eclipse.pde.core.requiredPlugins"/>
+       <classpathentry kind="src" path="src/main/java"/>
+       <classpathentry kind="output" path="target/classes"/>
+</classpath>
diff --git a/runtime/org.argeo.slc.rpmfactory/.project b/runtime/org.argeo.slc.rpmfactory/.project
new file mode 100644 (file)
index 0000000..f32b7a9
--- /dev/null
@@ -0,0 +1,28 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<projectDescription>
+       <name>org.argeo.slc.rpmfactory</name>
+       <comment></comment>
+       <projects>
+       </projects>
+       <buildSpec>
+               <buildCommand>
+                       <name>org.eclipse.jdt.core.javabuilder</name>
+                       <arguments>
+                       </arguments>
+               </buildCommand>
+               <buildCommand>
+                       <name>org.eclipse.pde.ManifestBuilder</name>
+                       <arguments>
+                       </arguments>
+               </buildCommand>
+               <buildCommand>
+                       <name>org.eclipse.pde.SchemaBuilder</name>
+                       <arguments>
+                       </arguments>
+               </buildCommand>
+       </buildSpec>
+       <natures>
+               <nature>org.eclipse.pde.PluginNature</nature>
+               <nature>org.eclipse.jdt.core.javanature</nature>
+       </natures>
+</projectDescription>
diff --git a/runtime/org.argeo.slc.rpmfactory/.settings/org.eclipse.jdt.core.prefs b/runtime/org.argeo.slc.rpmfactory/.settings/org.eclipse.jdt.core.prefs
new file mode 100644 (file)
index 0000000..c537b63
--- /dev/null
@@ -0,0 +1,7 @@
+eclipse.preferences.version=1
+org.eclipse.jdt.core.compiler.codegen.inlineJsrBytecode=enabled
+org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.6
+org.eclipse.jdt.core.compiler.compliance=1.6
+org.eclipse.jdt.core.compiler.problem.assertIdentifier=error
+org.eclipse.jdt.core.compiler.problem.enumIdentifier=error
+org.eclipse.jdt.core.compiler.source=1.6
diff --git a/runtime/org.argeo.slc.rpmfactory/.settings/org.eclipse.pde.core.prefs b/runtime/org.argeo.slc.rpmfactory/.settings/org.eclipse.pde.core.prefs
new file mode 100644 (file)
index 0000000..f29e940
--- /dev/null
@@ -0,0 +1,3 @@
+eclipse.preferences.version=1
+pluginProject.extensions=false
+resolve.requirebundle=false
diff --git a/runtime/org.argeo.slc.rpmfactory/build.properties b/runtime/org.argeo.slc.rpmfactory/build.properties
new file mode 100644 (file)
index 0000000..5fc538b
--- /dev/null
@@ -0,0 +1,4 @@
+source.. = src/main/java/
+output.. = target/classes/
+bin.includes = META-INF/,\
+               .
diff --git a/runtime/org.argeo.slc.rpmfactory/pom.xml b/runtime/org.argeo.slc.rpmfactory/pom.xml
new file mode 100644 (file)
index 0000000..bb8b161
--- /dev/null
@@ -0,0 +1,55 @@
+<?xml version="1.0" encoding="UTF-8" standalone="no"?>
+<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+       xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
+       <modelVersion>4.0.0</modelVersion>
+       <parent>
+               <groupId>org.argeo.slc</groupId>
+               <artifactId>runtime</artifactId>
+               <version>1.1.13-SNAPSHOT</version>
+               <relativePath>..</relativePath>
+       </parent>
+       <artifactId>org.argeo.slc.rpmfactory</artifactId>
+       <name>SLC RPM Factory</name>
+       <build>
+               <plugins>
+                       <plugin>
+                               <groupId>org.apache.felix</groupId>
+                               <artifactId>maven-bundle-plugin</artifactId>
+
+                               <configuration>
+                                       <instructions>
+                                               <Export-Package>
+                                                       org.argeo.slc.rpmfactory.*
+                                               </Export-Package>
+                                               <Import-Package>
+                                                       *
+                                               </Import-Package>
+                                       </instructions>
+                               </configuration>
+                       </plugin>
+               </plugins>
+       </build>
+       <dependencies>
+               <!-- SLC Runtime -->
+               <dependency>
+                       <groupId>org.argeo.slc</groupId>
+                       <artifactId>org.argeo.slc.repo</artifactId>
+                       <version>1.1.13-SNAPSHOT</version>
+               </dependency>
+               <dependency>
+                       <groupId>org.argeo.slc</groupId>
+                       <artifactId>org.argeo.slc.support.jcr</artifactId>
+                       <version>1.1.13-SNAPSHOT</version>
+               </dependency>
+
+               <!-- Third party -->
+               <dependency>
+                       <groupId>org.argeo.tp</groupId>
+                       <artifactId>org.apache.commons.io</artifactId>
+               </dependency>
+               <dependency>
+                       <groupId>org.argeo.tp</groupId>
+                       <artifactId>slf4j.org.apache.commons.logging</artifactId>
+               </dependency>
+       </dependencies>
+</project>
\ No newline at end of file
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
new file mode 100644 (file)
index 0000000..d2469f8
--- /dev/null
@@ -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 MavenProxyService extends ResourceProxy {
+}
diff --git a/runtime/org.argeo.slc.rpmfactory/src/main/java/org/argeo/slc/rpmfactory/RpmRepository.java b/runtime/org.argeo.slc.rpmfactory/src/main/java/org/argeo/slc/rpmfactory/RpmRepository.java
new file mode 100644 (file)
index 0000000..d15940b
--- /dev/null
@@ -0,0 +1,8 @@
+package org.argeo.slc.rpmfactory;
+
+public interface RpmRepository {
+       public String getId();
+
+       public String getUrl();
+
+}
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
new file mode 100644 (file)
index 0000000..4f8a022
--- /dev/null
@@ -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.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<RpmRepository> defaultRepositories = new ArrayList<RpmRepository>();
+
+       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<Node> getBaseUrls(Session session)
+                       throws RepositoryException {
+               List<Node> baseUrls = new ArrayList<Node>();
+               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<RpmRepository> defaultRepositories) {
+               this.defaultRepositories = defaultRepositories;
+       }
+
+       public void setArtifactsBasePath(String artifactsBasePath) {
+               this.artifactsBasePath = artifactsBasePath;
+       }
+
+}
index d89cfcd87c1a939c5c30822af9386e5b17f999c0..7320304bc99e32476973bbb1173a317f0646227a 100644 (file)
@@ -27,5 +27,6 @@
                <module>org.argeo.slc.launcher</module>
                <module>org.argeo.slc.lib.detached</module>
                <module>org.argeo.slc.repo</module>
+               <module>org.argeo.slc.rpmfactory</module>
        </modules>
 </project>