</service-properties>\r
</service>\r
\r
+ <service ref="slcRepoManager" interface="org.argeo.slc.repo.SlcRepoManager" />\r
+\r
<service ref="mavenProxyService" interface="org.argeo.slc.repo.MavenProxyService" />\r
<service ref="rpmProxyService" interface="org.argeo.slc.rpmfactory.RpmProxyService" />\r
\r
</property>
</bean>
- <!-- Maven Proxy -->
- <bean id="mavenProxyService" class="org.argeo.slc.repo.maven.MavenProxyServiceImpl"
- init-method="init" destroy-method="destroy" depends-on="ROLE_SLC">
- <property name="jcrRepository" ref="javaRepository" />
- <property name="proxyWorkspace" value="${slc.repo.jcr.proxyWorkspace}" />
- <property name="defaultRepositories" ref="defaultMavenRepositories" />
+ <bean id="slcRepoManager" class="org.argeo.slc.repo.core.SlcRepoManagerImpl"
+ init-method="init" destroy-method="destroy">
+ <property name="javaRepoManager" ref="javaRepoManager" />
</bean>
- <bean id="mavenProxyIndexer" class="org.argeo.slc.repo.RepoIndexer"
- init-method="init" destroy-method="destroy">
- <property name="jcrRepository" ref="javaRepository" />
- <property name="workspace" value="${slc.repo.jcr.proxyWorkspace}" />
+ <!-- Java -->
+ <bean id="javaRepoManager" class="org.argeo.slc.repo.core.JavaRepoManagerImpl"
+ init-method="init" destroy-method="destroy" depends-on="ROLE_SLC">
<property name="nodeIndexers">
<list>
<bean class="org.argeo.slc.repo.ArtifactIndexer" />
<bean class="org.argeo.slc.repo.JarFileIndexer" />
</list>
</property>
+ <property name="jcrRepository" ref="javaRepository" />
</bean>
- <!-- RPM Proxy -->
- <bean id="rpmProxyService" class="org.argeo.slc.rpmfactory.core.RpmProxyServiceImpl"
+ <bean id="mavenProxyService" class="org.argeo.slc.repo.maven.MavenProxyServiceImpl"
init-method="init" destroy-method="destroy" depends-on="ROLE_SLC">
- <property name="jcrRepository" ref="rpmRepository" />
+ <property name="jcrRepository" ref="javaRepository" />
<property name="proxyWorkspace" value="${slc.repo.jcr.proxyWorkspace}" />
- <property name="defaultRepositories" ref="defaultRpmRepositories" />
+ <property name="defaultRepositories" ref="defaultMavenRepositories" />
</bean>
- <bean id="rpmProxyIndexer" class="org.argeo.slc.repo.RepoIndexer"
- init-method="init" destroy-method="destroy">
- <property name="jcrRepository" ref="rpmRepository" />
- <property name="workspace" value="${slc.repo.jcr.proxyWorkspace}" />
+ <!-- RPM -->
+ <bean id="rpmRepoManager" class="org.argeo.slc.repo.core.RpmRepoManagerImpl"
+ init-method="init" destroy-method="destroy" depends-on="ROLE_SLC">
<property name="nodeIndexers">
<list>
<bean class="org.argeo.slc.repo.RpmIndexer" />
</list>
</property>
+ <property name="jcrRepository" ref="rpmRepository" />
+ </bean>
+
+ <bean id="rpmProxyService" class="org.argeo.slc.rpmfactory.core.RpmProxyServiceImpl"
+ init-method="init" destroy-method="destroy" depends-on="ROLE_SLC">
+ <property name="jcrRepository" ref="rpmRepository" />
+ <property name="proxyWorkspace" value="${slc.repo.jcr.proxyWorkspace}" />
+ <property name="defaultRepositories" ref="defaultRpmRepositories" />
</bean>
</beans>
\ No newline at end of file
*/
public class ArtifactIndexer implements NodeIndexer {
private Log log = LogFactory.getLog(ArtifactIndexer.class);
+ private Boolean force = false;
public Boolean support(String path) {
String relativePath = getRelativePath(path);
public void index(Node fileNode) {
Artifact artifact = null;
try {
- if(!support(fileNode.getPath()))
+ if (!support(fileNode.getPath()))
return;
-
+
+ // Already indexed
+ if (!force && fileNode.isNodeType(SlcTypes.SLC_ARTIFACT))
+ return;
+
if (!fileNode.isNodeType(NodeType.NT_FILE))
return;
String relativePath = nodePath.substring(basePath.length());
return relativePath;
}
+
+ public void setForce(Boolean force) {
+ this.force = force;
+ }
+
}
*/
public class JarFileIndexer implements NodeIndexer, SlcNames {
private final static Log log = LogFactory.getLog(JarFileIndexer.class);
+ private Boolean force = false;
public Boolean support(String path) {
return FilenameUtils.getExtension(path).equals("jar");
ByteArrayInputStream bi = null;
Binary manifestBinary = null;
try {
- if(!support(fileNode.getPath()))
+ if (!support(fileNode.getPath()))
return;
-
+
+ // Already indexed
+ if (!force && fileNode.isNodeType(SlcTypes.SLC_JAR_FILE))
+ return;
+
if (!fileNode.isNodeType(NodeType.NT_FILE))
return;
version.getQualifier());
}
+ public void setForce(Boolean force) {
+ this.force = force;
+ }
+
}
--- /dev/null
+package org.argeo.slc.repo;
+
+/** Java-specific operations */
+public interface JavaRepoManager {
+ public void createWorkspace(String workspaceName);
+
+}
+++ /dev/null
-/*
- * 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.repo;
-
-import java.util.ArrayList;
-import java.util.List;
-
-import javax.jcr.Node;
-import javax.jcr.Repository;
-import javax.jcr.RepositoryException;
-import javax.jcr.Session;
-import javax.jcr.observation.Event;
-import javax.jcr.observation.EventIterator;
-import javax.jcr.observation.EventListener;
-
-import org.argeo.jcr.JcrUtils;
-import org.argeo.slc.SlcException;
-
-/** Repository backend, maintain the JCR repository, mainly through listeners */
-public class RepoIndexer {
-
- private Repository jcrRepository;
- private String workspace = null;
-
- // Internal
- private Session adminSession;
- private FilesListener artifactListener;
-
- /** order may be important */
- private List<NodeIndexer> nodeIndexers = new ArrayList<NodeIndexer>();
-
- public void init() {
- try {
- adminSession = jcrRepository.login(workspace);
- artifactListener = new FilesListener();
- adminSession
- .getWorkspace()
- .getObservationManager()
- .addEventListener(artifactListener, Event.NODE_ADDED, "/",
- true, null, null, true);
- } catch (RepositoryException e) {
- throw new SlcException("Cannot initialize repository backend", e);
- }
- }
-
- public void destroy() {
- JcrUtils.logoutQuietly(adminSession);
- }
-
- public void setJcrRepository(Repository jcrRepository) {
- this.jcrRepository = jcrRepository;
- }
-
- public void setNodeIndexers(List<NodeIndexer> nodeIndexers) {
- this.nodeIndexers = nodeIndexers;
- }
-
- public void setWorkspace(String workspace) {
- this.workspace = workspace;
- }
-
- class FilesListener implements EventListener {
-
- public void onEvent(EventIterator events) {
- while (events.hasNext()) {
- Event event = events.nextEvent();
- try {
- String newNodePath = event.getPath();
- Node newNode = null;
- for (NodeIndexer nodeIndexer : nodeIndexers) {
- try {
- if (nodeIndexer.support(newNodePath)) {
- if (newNode == null)
- newNode = adminSession.getNode(newNodePath);
- nodeIndexer.index(newNode);
- }
- } catch (RuntimeException e) {
- e.printStackTrace();
- throw e;
- }
- }
- if (newNode != null)
- adminSession.save();
- } catch (RepositoryException e) {
- throw new SlcException("Cannot process event " + event, e);
- } finally {
- JcrUtils.discardQuietly(adminSession);
- }
- }
-
- }
-
- }
-
-}
+++ /dev/null
-/*
- * 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.repo;
-
-import org.argeo.slc.jcr.SlcNames;
-
-/**
- * Names used for items (nodes and properties).
- *
- * @deprecated use {@link SlcNames} instead
- */
-public interface RepoNames extends SlcNames {
-}
+++ /dev/null
-/*
- * 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.repo;
-
-import org.argeo.slc.jcr.SlcTypes;
-
-/**
- * Node types used programatically.
- *
- * @deprecated use {@link SlcTypes} instead
- */
-public interface RepoTypes extends SlcTypes {
-}
import javax.jcr.Node;
import javax.jcr.Property;
+import javax.jcr.nodetype.NodeType;
import org.apache.commons.io.FilenameUtils;
import org.argeo.slc.SlcException;
/** Indexes an RPM file. */
public class RpmIndexer implements NodeIndexer, SlcNames {
+ private Boolean force = false;
@Override
public Boolean support(String path) {
@Override
public void index(Node node) {
try {
+ if (!support(node.getPath()))
+ return;
+
+ // Already indexed
+ if (!force && node.isNodeType(SlcTypes.SLC_RPM))
+ return;
+
+ if (!node.isNodeType(NodeType.NT_FILE))
+ return;
+
InputStream in = node.getNode(Node.JCR_CONTENT)
.getProperty(Property.JCR_DATA).getBinary().getStream();
ReadableChannelWrapper channel = new ReadableChannelWrapper(
--- /dev/null
+package org.argeo.slc.repo;
+
+public interface RpmRepoManager {
+
+}
--- /dev/null
+package org.argeo.slc.repo;
+
+/** Coordinator of the various type of repository (Java, RPM, etc.) */
+public interface SlcRepoManager {
+ /** @return null if Java not supported. */
+ public JavaRepoManager getJavaRepoManager();
+
+ /** @return null if RPM not supported. */
+ public RpmRepoManager getRpmRepoManager();
+}
--- /dev/null
+package org.argeo.slc.repo.core;
+
+import java.util.List;
+import java.util.Map;
+import java.util.TreeMap;
+
+import javax.jcr.NoSuchWorkspaceException;
+import javax.jcr.Repository;
+import javax.jcr.RepositoryException;
+import javax.jcr.Session;
+
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+import org.argeo.jcr.JcrUtils;
+import org.argeo.slc.SlcConstants;
+import org.argeo.slc.SlcException;
+import org.argeo.slc.repo.NodeIndexer;
+
+/** Generic operations on a JCR-based repo. */
+abstract class AbstractJcrRepoManager {
+ private final static Log log = LogFactory
+ .getLog(AbstractJcrRepoManager.class);
+ private String securityWorkspace = "security";
+
+ private Repository jcrRepository;
+ private Session adminSession;
+ private List<NodeIndexer> nodeIndexers;
+
+ // registries
+ private Map<String, Session> workspaceSessions = new TreeMap<String, Session>();
+ private Map<String, WorkspaceIndexer> workspaceIndexers = new TreeMap<String, WorkspaceIndexer>();
+
+ public void init() {
+ try {
+ adminSession = jcrRepository.login();
+ String[] workspaceNames = adminSession.getWorkspace()
+ .getAccessibleWorkspaceNames();
+ for (String workspaceName : workspaceNames) {
+ if (workspaceName.equals(securityWorkspace))
+ continue;
+ if (workspaceName.equals(adminSession.getWorkspace().getName()))
+ continue;
+ workspaceInit(workspaceName);
+ }
+ } catch (RepositoryException e) {
+ throw new SlcException("Cannot initialize repo manager", e);
+ }
+ }
+
+ public void destroy() {
+ for (String key : workspaceIndexers.keySet()) {
+ workspaceIndexers.get(key).close();
+ }
+
+ for (String key : workspaceSessions.keySet()) {
+ JcrUtils.logoutQuietly(workspaceSessions.get(key));
+ }
+ JcrUtils.logoutQuietly(adminSession);
+ }
+
+ public void createWorkspace(String workspaceName) {
+ try {
+ try {
+ jcrRepository.login(workspaceName);
+ throw new SlcException("Workspace " + workspaceName
+ + " exists already.");
+ } catch (NoSuchWorkspaceException e) {
+ // try to create workspace
+ adminSession.getWorkspace().createWorkspace(workspaceName);
+ workspaceInit(workspaceName);
+ }
+ } catch (RepositoryException e) {
+ throw new SlcException("Cannot create workspace " + workspaceName,
+ e);
+ }
+ }
+
+ protected void workspaceInit(String workspaceName) {
+ try {
+ Session workspaceAdminSession = jcrRepository.login(workspaceName);
+ workspaceSessions.put(workspaceName, adminSession);
+ JcrUtils.addPrivilege(workspaceAdminSession, "/",
+ SlcConstants.ROLE_SLC, "jcr:all");
+ WorkspaceIndexer workspaceIndexer = new WorkspaceIndexer(
+ workspaceAdminSession, nodeIndexers);
+ workspaceIndexers.put(workspaceName, workspaceIndexer);
+ } catch (RepositoryException e) {
+ log.error("Cannot initialize workspace " + workspaceName, e);
+ }
+ }
+
+ public void setJcrRepository(Repository jcrRepository) {
+ this.jcrRepository = jcrRepository;
+ }
+
+ public void setNodeIndexers(List<NodeIndexer> nodeIndexers) {
+ this.nodeIndexers = nodeIndexers;
+ }
+
+ public void setSecurityWorkspace(String securityWorkspace) {
+ this.securityWorkspace = securityWorkspace;
+ }
+
+}
--- /dev/null
+package org.argeo.slc.repo.core;
+
+import org.argeo.slc.repo.JavaRepoManager;
+
+/** Java-specific operations */
+public class JavaRepoManagerImpl extends AbstractJcrRepoManager implements
+ JavaRepoManager {
+}
--- /dev/null
+package org.argeo.slc.repo.core;
+
+import org.argeo.slc.repo.RpmRepoManager;
+
+/** RPM-specific operations */
+public class RpmRepoManagerImpl extends AbstractJcrRepoManager implements
+ RpmRepoManager {
+}
--- /dev/null
+package org.argeo.slc.repo.core;
+
+import org.argeo.slc.repo.JavaRepoManager;
+import org.argeo.slc.repo.RpmRepoManager;
+import org.argeo.slc.repo.SlcRepoManager;
+
+/** Coordinator of the various repositories. */
+public class SlcRepoManagerImpl implements SlcRepoManager {
+ private JavaRepoManager javaRepoManager;
+ private RpmRepoManager rpmRepoManager;
+
+ public void init() {
+
+ }
+
+ public void destroy() {
+
+ }
+
+ @Override
+ public JavaRepoManager getJavaRepoManager() {
+ return javaRepoManager;
+ }
+
+ public void setJavaRepoManager(JavaRepoManager javaRepoManager) {
+ this.javaRepoManager = javaRepoManager;
+ }
+
+ @Override
+ public RpmRepoManager getRpmRepoManager() {
+ return rpmRepoManager;
+ }
+
+ public void setRpmRepoManager(RpmRepoManager rpmRepoManager) {
+ this.rpmRepoManager = rpmRepoManager;
+ }
+
+}
--- /dev/null
+/*
+ * 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.repo.core;
+
+import java.util.List;
+
+import javax.jcr.Node;
+import javax.jcr.RepositoryException;
+import javax.jcr.Session;
+import javax.jcr.observation.Event;
+import javax.jcr.observation.EventIterator;
+import javax.jcr.observation.EventListener;
+
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+import org.argeo.jcr.JcrUtils;
+import org.argeo.slc.SlcException;
+import org.argeo.slc.repo.NodeIndexer;
+
+/** Maintains the metadata of a workspace, using listeners */
+public class WorkspaceIndexer {
+ private final static Log log = LogFactory.getLog(WorkspaceIndexer.class);
+
+ private final Session adminSession;
+ private IndexingListener artifactListener;
+ /** order may be important */
+ private final List<NodeIndexer> nodeIndexers;
+
+ public WorkspaceIndexer(Session adminSession, List<NodeIndexer> nodeIndexers) {
+ this.adminSession = adminSession;
+ this.nodeIndexers = nodeIndexers;
+ try {
+ artifactListener = new IndexingListener();
+ adminSession
+ .getWorkspace()
+ .getObservationManager()
+ .addEventListener(artifactListener, Event.NODE_ADDED, "/",
+ true, null, null, true);
+ } catch (RepositoryException e) {
+ throw new SlcException("Cannot initialize repository backend", e);
+ }
+ }
+
+ public void close() {
+ try {
+ adminSession.getWorkspace().getObservationManager()
+ .removeEventListener(artifactListener);
+ } catch (RepositoryException e) {
+ log.error("Cannot close workspace indexer "
+ + adminSession.getWorkspace().getName(), e);
+ }
+ }
+
+ class IndexingListener implements EventListener {
+
+ public void onEvent(EventIterator events) {
+ while (events.hasNext()) {
+ Event event = events.nextEvent();
+ try {
+ String newNodePath = event.getPath();
+ Node newNode = null;
+ for (NodeIndexer nodeIndexer : nodeIndexers) {
+ try {
+ if (nodeIndexer.support(newNodePath)) {
+ if (newNode == null)
+ newNode = adminSession.getNode(newNodePath);
+ nodeIndexer.index(newNode);
+ }
+ } catch (RuntimeException e) {
+ e.printStackTrace();
+ throw e;
+ }
+ }
+ if (newNode != null)
+ adminSession.save();
+ } catch (RepositoryException e) {
+ throw new SlcException("Cannot process event " + event, e);
+ } finally {
+ JcrUtils.discardQuietly(adminSession);
+ }
+ }
+ }
+ }
+}