<version>1.1.13-SNAPSHOT</version>
</dependency>
<dependency>
- <groupId>org.argeo.slc.rpmfactory</groupId>
- <artifactId>org.argeo.slc.repo</artifactId>
+ <groupId>org.argeo.slc</groupId>
+ <artifactId>org.argeo.slc.rpmfactory</artifactId>
<version>1.1.13-SNAPSHOT</version>
</dependency>
<dependency>
<!-- ROLES -->\r
<reference id="userAdminService" interface="org.argeo.security.UserAdminService" />\r
\r
- <beans:bean class="org.argeo.security.core.SimpleRoleRegistration"\r
- init-method="run">\r
+ <beans:bean id="ROLE_SLC"\r
+ class="org.argeo.security.core.SimpleRoleRegistration" init-method="run">\r
<beans:property name="role" value="ROLE_SLC" />\r
<beans:property name="userAdminService" ref="userAdminService" />\r
</beans:bean>\r
</property>
</bean>
- <bean id="repo" class="org.argeo.slc.repo.RepoImpl" init-method="init"
- destroy-method="destroy">
+ <!-- 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>
+
+ <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}" />
<property name="nodeIndexers">
<list>
<bean class="org.argeo.slc.repo.ArtifactIndexer" />
</property>
</bean>
- <!--Caching Proxy Services -->
- <bean id="mavenProxyService" class="org.argeo.slc.repo.maven.MavenProxyServiceImpl"
- init-method="init" destroy-method="destroy">
- <property name="jcrRepository" ref="javaRepository" />
- <property name="defaultRepositories" ref="defaultMavenRepositories" />
- </bean>
-
+ <!-- RPM Proxy -->
<bean id="rpmProxyService" class="org.argeo.slc.rpmfactory.core.RpmProxyServiceImpl"
- init-method="init" destroy-method="destroy">
+ 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>
+ <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}" />
+ <property name="nodeIndexers">
+ <list>
+ <bean class="org.argeo.slc.rpmfactory.core.RpmIndexer" />
+ </list>
+ </property>
+ </bean>
</beans>
\ No newline at end of file
slc.repo.jcr.reposBase=${osgi.instance.area}/repos
slc.repo.jcr.forceCndImport=true
+slc.repo.jcr.proxyWorkspace=proxy
slc.repo.jcr.configuration.java=osgibundle:repository-h2.xml
slc.repo.jcr.configuration.dist=osgibundle:repository-h2.xml
--- /dev/null
+package org.argeo.slc.repo;
+
+import java.util.ArrayList;
+import java.util.List;
+
+import javax.jcr.ItemVisitor;
+import javax.jcr.Node;
+import javax.jcr.NodeIterator;
+import javax.jcr.Property;
+import javax.jcr.RepositoryException;
+
+/**
+ * Recursively visit a sub tree and apply the list of node indexer on supported
+ * nodes.
+ */
+public class NodeIndexerVisitor implements ItemVisitor {
+ /** order may be important */
+ private List<NodeIndexer> nodeIndexers = new ArrayList<NodeIndexer>();
+
+ public NodeIndexerVisitor() {
+ }
+
+ /** Convenience constructor */
+ public NodeIndexerVisitor(NodeIndexer nodeIndexer) {
+ nodeIndexers.add(nodeIndexer);
+ }
+
+ public NodeIndexerVisitor(List<NodeIndexer> nodeIndexers) {
+ this.nodeIndexers = nodeIndexers;
+ }
+
+ public void visit(Node node) throws RepositoryException {
+ for (NodeIndexer nodeIndexer : nodeIndexers)
+ if (nodeIndexer.support(node.getPath()))
+ nodeIndexer.index(node);
+
+ for (NodeIterator it = node.getNodes(); it.hasNext();)
+ visit(it.nextNode());
+ }
+
+ public void visit(Property property) throws RepositoryException {
+ }
+
+ public void setNodeIndexers(List<NodeIndexer> nodeIndexers) {
+ this.nodeIndexers = nodeIndexers;
+ }
+
+}
+++ /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.Arrays;
-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 RepoImpl {
-
- private Repository jcrRepository;
- private Session adminSession;
-
- private ArtifactListener artifactListener;
-
- /** order may be important */
- private List<NodeIndexer> nodeIndexers = new ArrayList<NodeIndexer>();
-
- public void init() {
- try {
- adminSession = jcrRepository.login();
- artifactListener = new ArtifactListener();
- adminSession
- .getWorkspace()
- .getObservationManager()
- .addEventListener(artifactListener, Event.NODE_ADDED,
- RepoConstants.DEFAULT_ARTIFACTS_BASE_PATH, true, null,
- null, true);
- // localrepo
- String localrepoWorkspace = "localrepo";
- if (!Arrays.asList(
- adminSession.getWorkspace().getAccessibleWorkspaceNames())
- .contains(localrepoWorkspace))
- adminSession.getWorkspace().createWorkspace(localrepoWorkspace);
- } 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;
- }
-
- class ArtifactListener 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 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);
+ }
+ }
+
+ }
+
+ }
+
+}
import javax.jcr.RepositoryException;
import javax.jcr.Session;
import javax.jcr.nodetype.NodeType;
+import javax.jcr.security.AccessControlException;
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.SlcConstants;
import org.argeo.slc.SlcException;
import org.argeo.slc.jcr.SlcNames;
import org.argeo.slc.jcr.SlcTypes;
@Override
protected void beforeInitSessionSave(Session session)
throws RepositoryException {
+ JcrUtils.addPrivilege(session, "/", "anonymous", "jcr:read");
+ try {
+ JcrUtils.addPrivilege(session, "/", SlcConstants.ROLE_SLC,
+ "jcr:all");
+ } catch (AccessControlException e) {
+ if (log.isTraceEnabled())
+ log.trace("Cannot give jcr:all privileges to ROLE_SLC");
+ }
+
JcrUtils.mkdirsSafe(session, RepoConstants.DEFAULT_ARTIFACTS_BASE_PATH);
Node proxiedRepositories = JcrUtils.mkdirsSafe(session,
RepoConstants.PROXIED_REPOSITORIES);
[slc:bundleArtifact] > slc:artifact,slc:jarFile,slc:bundle
mixin
+
+// RPM
+[slc:rpm] > mix:referenceable, mix:created, mix:lastModified, mix:title
+mixin
+- slc:name (STRING)
+- slc:version (STRING)
+- slc:rpmVersion (STRING)
+- slc:rpmRelease (STRING)
+- slc:rpmArch (STRING)
+- slc:rpmArchivaeSize (STRING)
<groupId>org.argeo.tp</groupId>
<artifactId>slf4j.org.apache.commons.logging</artifactId>
</dependency>
+ <dependency>
+ <groupId>org.argeo.tp</groupId>
+ <artifactId>org.redline_rpm</artifactId>
+ </dependency>
+
</dependencies>
</project>
\ No newline at end of file
private final static String NOARCH = "noarch";
private String rpmPackage = null;
+ private String branch = null;
private String arch = NOARCH;
- private RpmBuildEnvironment buildEnvironment;
+ private RpmFactory factory;
private Executor executor;
private String debuginfoDirName = "debuginfo";
public void run() {
- String mockCfg = buildEnvironment.getMockConfig(arch);
- File mockConfigFile = buildEnvironment.getMockConfigFile(arch);
+ String mockCfg = factory.getMockConfig(arch);
+ File mockConfigFile = factory.getMockConfigFile(arch, branch);
// prepare mock call
SystemCall mock = new SystemCall();
mock.arg("--arch=" + arch);
mock.arg("-r").arg(mockCfg);
mock.arg("--scm-enable");
+ // mock.arg("--scm-option");
+ // mock.arg("git_get='git clone " + (branch != null ? "-b " + branch :
+ // "")
+ // + " " + factory.getGitBaseUrl() + "/SCM_PKG SCM_PKG'");
mock.arg("--scm-option").arg("package=" + rpmPackage);
mock.setLogCommand(true);
mock.run();
//
- File stagingDir = buildEnvironment.getStagingDir();
+ File stagingDir = factory
+ .getWorkspaceDir(factory.getStagingWorkspace());
File srpmDir = new File(stagingDir, "SRPMS");
srpmDir.mkdirs();
File archDir = null;
// copy RPMs
Set<File> reposToRecreate = new HashSet<File>();
- File resultDir = buildEnvironment.getResultDir(arch);
+ File resultDir = factory.getResultDir(arch);
rpms: for (File file : resultDir.listFiles()) {
if (file.isDirectory())
continue rpms;
targetDirs = new File[] { archDir };
else if (file.getName().contains(".noarch.rpm")) {
List<File> dirs = new ArrayList<File>();
- for (String arch : buildEnvironment.getArchs())
+ for (String arch : factory.getArchs())
dirs.add(new File(stagingDir, arch));
targetDirs = dirs.toArray(new File[dirs.size()]);
} else if (file.getName().contains(".rpm"))
createrepo.run();
log.info("Updated repo " + repoToRecreate);
}
+
+ // index staging workspace
+ factory.indexWorkspace(factory.getStagingWorkspace());
}
protected void copyToDirs(File file, File[] dirs) {
this.rpmPackage = rpmPackage;
}
- public void setBuildEnvironment(RpmBuildEnvironment buildEnvironment) {
- this.buildEnvironment = buildEnvironment;
+ public void setBranch(String branch) {
+ this.branch = branch;
+ }
+
+ public void setFactory(RpmFactory env) {
+ this.factory = env;
}
public void setExecutor(Executor executor) {
* consistent distributable set (typically to be used to generate an ISO).
*/
public class CreateRpmDistribution implements Runnable {
-
+ // private RpmDistribution rpmDistribution;
@Override
public void run() {
- // TODO Auto-generated method stub
}
-
}
+++ /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.rpmfactory.core;
-
-import java.io.File;
-import java.io.IOException;
-import java.util.ArrayList;
-import java.util.HashMap;
-import java.util.List;
-import java.util.Map;
-
-import javax.jcr.Node;
-import javax.jcr.Repository;
-import javax.jcr.RepositoryException;
-import javax.jcr.Session;
-
-import org.apache.commons.io.FileUtils;
-import org.argeo.jcr.JcrUtils;
-import org.argeo.slc.SlcException;
-import org.argeo.slc.core.execution.tasks.SystemCall;
-import org.argeo.slc.rpmfactory.RpmRepository;
-
-/**
- * Defines a build environment. This information is typically used by other
- * components performing the various actions related to RPM build.
- */
-public class RpmBuildEnvironment {
-
- private Repository rpmRepository;
- private Repository distRepository;
-
- private String id;
- private String stagingBase = "/mnt/slc/repos/rpm";
- private String mockVar = "/var/lib/mock";
- private String mockEtc = "/etc/mock";
- private List<String> archs = new ArrayList<String>();
-
- private String localUrlBase = "http://localhost:7070/";
-
- private String yumConfigMainSection = "cachedir=/var/cache/yum\n"
- + "debuglevel=1\n" + "reposdir=/dev/null\n"
- + "logfile=/var/log/yum.log\n" + "retries=20\n" + "obsoletes=1\n"
- + "gpgcheck=0\n" + "assumeyes=1\n" + "syslog_ident=mock\n"
- + "syslog_device=\n";
- private List<RpmRepository> repositories = new ArrayList<RpmRepository>();
-
- private String defaultMacroFiles = "/usr/lib/rpm/macros:"
- + "/usr/lib/rpm/ia32e-linux/macros:"
- + "/usr/lib/rpm/redhat/macros:" + "/etc/rpm/macros.*:"
- + "/etc/rpm/macros:" + "/etc/rpm/ia32e-linux/macros:"
- + "~/.rpmmacros";
- private Map<String, String> rpmmacros = new HashMap<String, String>();
-
- // set by init
- private String proxiedReposBase;
- private String managedReposBase;
-
- private String stagingWorkspace;
- private String testingWorkspace;
- private String stableWorkspace;
-
- private File rpmFactoryBaseDir;
- private File mockConfDir;
- private File yumConfDir;
-
- public void init() {
- proxiedReposBase = localUrlBase + "repo/rpm/";
- managedReposBase = localUrlBase + "data/public/rpm/";
-
- stagingWorkspace = id + "-staging";
- testingWorkspace = id + "-testing";
- stableWorkspace = id;
-
- // rpmFactoryBaseDir = new File(System.getProperty("osgi.instance.area")
- // .substring("file://".length()) + "/rpmfactory");
- rpmFactoryBaseDir.mkdirs();
- mockConfDir = new File(rpmFactoryBaseDir.getPath() + "/conf/mock");
- mockConfDir.mkdirs();
- yumConfDir = new File(rpmFactoryBaseDir.getPath() + "/conf/yum");
- yumConfDir.mkdirs();
-
- initDistWorkspace(stagingWorkspace);
- initRpmWorkspace(stagingWorkspace);
- initRpmWorkspace(testingWorkspace);
- initRpmWorkspace(stableWorkspace);
- }
-
- protected void initRpmWorkspace(String workspace) {
- Session session = null;
- try {
- session = JcrUtils.loginOrCreateWorkspace(rpmRepository, workspace);
- JcrUtils.addPrivilege(session, "/", "anonymous", "jcr:read");
-
- for (String arch : archs) {
- Node archFolder = JcrUtils.mkfolders(session, "/" + arch);
- if (!archFolder.hasNode("repodata")) {
- SystemCall createrepo = new SystemCall();
- createrepo.arg("createrepo");
- createrepo.arg("-q");
- File archDir = new File(getStagingDir(), arch);
- createrepo.arg(archDir.getAbsolutePath());
- }
- }
- } catch (RepositoryException e) {
- throw new SlcException("Cannot initialize workspace " + workspace,
- e);
- } finally {
- JcrUtils.logoutQuietly(session);
- }
- }
-
- protected void initDistWorkspace(String workspace) {
- Session session = null;
- try {
- session = JcrUtils
- .loginOrCreateWorkspace(distRepository, workspace);
- JcrUtils.addPrivilege(session, "/", "anonymous", "jcr:read");
- } catch (RepositoryException e) {
- throw new SlcException("Cannot initialize workspace " + workspace,
- e);
- } finally {
- JcrUtils.logoutQuietly(session);
- }
- }
-
- public void destroy() {
-
- }
-
- public String generateMockConfigFile(String arch) {
- StringBuffer buf = new StringBuffer();
-
- buf.append("config_opts['root'] = '" + getIdWithArch(arch) + "'\n");
- buf.append("config_opts['target_arch'] = '" + arch + "'\n");
- buf.append("config_opts['legal_host_arches'] = ('" + arch + "',)\n");
- buf.append("config_opts['chroot_setup_cmd'] = 'groupinstall buildsys-build'\n");
- // buf.append("config_opts['dist'] = 'el6'\n");
-
- buf.append("config_opts['scm'] = False\n");
- buf.append("config_opts['scm_opts']['method'] = 'git'\n");
- buf.append("config_opts['scm_opts']['git_get'] = 'git clone -b elgis6 /home/mbaudier/dev/git/elgis.argeo.org/SCM_PKG SCM_PKG'\n");
- buf.append("config_opts['scm_opts']['spec'] = 'SCM_PKG.spec'\n");
- buf.append("config_opts['scm_opts']['ext_src_dir'] = '/home/mbaudier/dev/git/elgis.argeo.org/sources'\n");
- buf.append("config_opts['scm_opts']['git_timestamps'] = True\n");
-
- buf.append("config_opts['yum.conf'] = \"\"\"\n");
- buf.append(generateYumConfigFile(arch)).append('\n');
- buf.append("\"\"\"\n");
- return buf.toString();
- }
-
- public String generateYumConfigFile(String arch) {
- StringBuffer buf = new StringBuffer();
- buf.append("[main]\n");
- buf.append(yumConfigMainSection).append('\n');
-
- for (RpmRepository repository : repositories) {
- buf.append('[').append(repository.getId()).append("]\n");
- if (repository instanceof ThirdPartyRpmRepository) {
- buf.append("#baseurl=").append(repository.getUrl())
- .append(arch).append('/').append("\n");
- buf.append("baseurl=").append(proxiedReposBase)
- .append(repository.getId()).append('/').append(arch)
- .append('/').append("\n");
- }
- }
-
- // managed repos
- buf.append('[').append(stagingWorkspace).append("]\n");
- buf.append("baseurl=").append(managedReposBase)
- .append(stagingWorkspace).append('/').append(arch).append('/')
- .append("\n");
-
- buf.append('[').append(testingWorkspace).append("]\n");
- buf.append("baseurl=").append(managedReposBase)
- .append(testingWorkspace).append('/').append(arch).append('/')
- .append("\n");
-
- buf.append('[').append(stableWorkspace).append("]\n");
- buf.append("baseurl=").append(managedReposBase).append(stableWorkspace)
- .append('/').append(arch).append('/').append("\n");
- return buf.toString();
- }
-
- /** Creates a mock config file. */
- public File getMockConfigFile(String arch) {
- File mockSiteDefaultsFile = new File(mockConfDir, "site-defaults.cfg");
- File mockLoggingFile = new File(mockConfDir, "logging.ini");
- File mockConfigFile = new File(mockConfDir, getIdWithArch(arch)
- + ".cfg");
- try {
- if (!mockSiteDefaultsFile.exists())
- mockSiteDefaultsFile.createNewFile();
- if (!mockLoggingFile.exists())
- FileUtils.copyFile(new File(mockEtc + "/logging.ini"),
- mockLoggingFile);
-
- FileUtils.writeStringToFile(mockConfigFile,
- generateMockConfigFile(arch));
- return mockConfigFile;
- } catch (IOException e) {
- throw new SlcException("Cannot write mock config file to "
- + mockConfigFile, e);
- }
- }
-
- /** Creates a yum config file. */
- public File getYumConfigFile(String arch) {
- File yumConfigFile = new File(yumConfDir, getIdWithArch(arch) + ".conf");
- try {
- FileUtils.writeStringToFile(yumConfigFile,
- generateYumConfigFile(arch));
- return yumConfigFile;
- } catch (IOException e) {
- throw new SlcException("Cannot write yum config file to "
- + yumConfigFile, e);
- }
- }
-
- public File getResultDir(String arch) {
- return new File(mockVar + "/" + getIdWithArch(arch) + "/result");
- }
-
- public File getStagingDir() {
- return new File(stagingBase + "/" + stagingWorkspace);
- }
-
- public String getMockConfig(String arch) {
- return getIdWithArch(arch);
- }
-
- public String getIdWithArch(String arch) {
- return id + "-" + arch;
- }
-
- /** Write (topdir)/rpmmacros and (topdir)/rpmrc */
- public void writeRpmbuildConfigFiles(File topdir) {
- writeRpmbuildConfigFiles(topdir, new File(topdir, "rpmmacros"),
- new File(topdir, "rpmrc"));
- }
-
- public void writeRpmbuildConfigFiles(File topdir, File rpmmacroFile,
- File rpmrcFile) {
- try {
- List<String> macroLines = new ArrayList<String>();
- macroLines.add("%_topdir " + topdir.getCanonicalPath());
- for (String macroKey : rpmmacros.keySet()) {
- macroLines.add(macroKey + " " + rpmmacros.get(macroKey));
- }
- FileUtils.writeLines(rpmmacroFile, macroLines);
-
- List<String> rpmrcLines = new ArrayList<String>();
- rpmrcLines.add("include: /usr/lib/rpm/rpmrc");
- rpmrcLines.add("macrofiles: " + defaultMacroFiles + ":"
- + rpmmacroFile.getCanonicalPath());
- FileUtils.writeLines(rpmrcFile, rpmrcLines);
- } catch (IOException e) {
- throw new SlcException("Cannot write rpmbuild config files", e);
- }
-
- }
-
- public Map<String, String> getRpmmacros() {
- return rpmmacros;
- }
-
- public void setRpmmacros(Map<String, String> rpmmacros) {
- this.rpmmacros = rpmmacros;
- }
-
- public String getDefaultMacroFiles() {
- return defaultMacroFiles;
- }
-
- public void setDefaultMacroFiles(String defaultMacroFiles) {
- this.defaultMacroFiles = defaultMacroFiles;
- }
-
- public void setArchs(List<String> archs) {
- this.archs = archs;
- }
-
- public List<String> getArchs() {
- return archs;
- }
-
- public String getStagingBase() {
- return stagingBase;
- }
-
- public void setStagingBase(String stagingBase) {
- this.stagingBase = stagingBase;
- }
-
- public void setId(String id) {
- this.id = id;
- }
-
- public void setMockVar(String mockVar) {
- this.mockVar = mockVar;
- }
-
- public void setRpmRepository(Repository rpmRepository) {
- this.rpmRepository = rpmRepository;
- }
-
- public void setDistRepository(Repository distRepository) {
- this.distRepository = distRepository;
- }
-
- public void setLocalUrlBase(String localUrlBase) {
- this.localUrlBase = localUrlBase;
- }
-
- public void setYumConfigMainSection(String yumConfigMainSection) {
- this.yumConfigMainSection = yumConfigMainSection;
- }
-
- public void setRepositories(List<RpmRepository> repositories) {
- this.repositories = repositories;
- }
-
- public void setRpmFactoryBaseDir(File rpmFactoryBaseDir) {
- this.rpmFactoryBaseDir = rpmFactoryBaseDir;
- }
-
-}
package org.argeo.slc.rpmfactory.core;
+import java.util.List;
+
/** A consistent distributable set of RPM. */
public class RpmDistribution {
+ private List<String> packages;
+
+ public List<String> getPackages() {
+ return packages;
+ }
+ public void setPackages(List<String> packages) {
+ this.packages = packages;
+ }
}
--- /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.rpmfactory.core;
+
+import java.io.File;
+import java.io.IOException;
+import java.util.ArrayList;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+
+import javax.jcr.Node;
+import javax.jcr.Repository;
+import javax.jcr.RepositoryException;
+import javax.jcr.Session;
+
+import org.apache.commons.io.FileUtils;
+import org.argeo.jcr.JcrUtils;
+import org.argeo.slc.SlcConstants;
+import org.argeo.slc.SlcException;
+import org.argeo.slc.core.execution.tasks.SystemCall;
+import org.argeo.slc.repo.NodeIndexerVisitor;
+import org.argeo.slc.rpmfactory.RpmRepository;
+
+/**
+ * Defines a build environment. This information is typically used by other
+ * components performing the various actions related to RPM build.
+ */
+public class RpmFactory {
+ private Repository rpmRepository;
+ private Repository distRepository;
+
+ private String id;
+ private List<RpmRepository> repositories = new ArrayList<RpmRepository>();
+ private List<String> archs = new ArrayList<String>();
+
+ private String rpmBase = "/mnt/slc/repos/rpm";
+ private String distBase = "/mnt/slc/repos/dist";
+ private String mockVar = "/var/lib/mock";
+ private String mockEtc = "/etc/mock";
+
+ private String gitWorkspace = "git";
+
+ private String localUrlBase = "http://localhost:7070/";
+
+ private Boolean withTestingRepository = false;
+
+ private String yumConfigMainSection = "cachedir=/var/cache/yum\n"
+ + "debuglevel=1\n" + "reposdir=/dev/null\n"
+ + "logfile=/var/log/yum.log\n" + "retries=20\n" + "obsoletes=1\n"
+ + "gpgcheck=0\n" + "assumeyes=1\n" + "syslog_ident=mock\n"
+ + "syslog_device=\n" + "http_caching=none\n";
+
+ private String defaultMacroFiles = "/usr/lib/rpm/macros:"
+ + "/usr/lib/rpm/ia32e-linux/macros:"
+ + "/usr/lib/rpm/redhat/macros:" + "/etc/rpm/macros.*:"
+ + "/etc/rpm/macros:" + "/etc/rpm/ia32e-linux/macros:"
+ + "~/.rpmmacros";
+ private Map<String, String> rpmmacros = new HashMap<String, String>();
+
+ // set by init
+ private String proxiedReposBase;
+ private String managedReposBase;
+
+ private String stagingWorkspace;
+ private String testingWorkspace;
+ private String stableWorkspace;
+
+ private File rpmFactoryBaseDir;
+ private File mockConfDir;
+ private File yumConfDir;
+
+ public void init() {
+ // local URL bases
+ proxiedReposBase = localUrlBase + "repo/rpm/";
+ managedReposBase = localUrlBase + "data/public/rpm/";
+
+ // local directories
+ rpmFactoryBaseDir.mkdirs();
+ mockConfDir = new File(rpmFactoryBaseDir.getPath() + "/conf/mock");
+ mockConfDir.mkdirs();
+ yumConfDir = new File(rpmFactoryBaseDir.getPath() + "/conf/yum");
+ yumConfDir.mkdirs();
+
+ // managed repositories
+ stagingWorkspace = id + "-staging";
+ if (withTestingRepository)
+ testingWorkspace = id + "-testing";
+ stableWorkspace = id;
+
+ initDistWorkspace(stableWorkspace);
+ initGitWorkspace();
+ initRpmWorkspace(stagingWorkspace);
+ if (withTestingRepository)
+ initRpmWorkspace(testingWorkspace);
+ initRpmWorkspace(stableWorkspace);
+ }
+
+ protected void initRpmWorkspace(String workspace) {
+ Session session = null;
+ try {
+ session = JcrUtils.loginOrCreateWorkspace(rpmRepository, workspace);
+ JcrUtils.addPrivilege(session, "/", "anonymous", "jcr:read");
+ JcrUtils.addPrivilege(session, "/", SlcConstants.ROLE_SLC,
+ "jcr:all");
+
+ for (String arch : archs) {
+ Node archFolder = JcrUtils.mkfolders(session, "/" + arch);
+ session.save();
+ if (!archFolder.hasNode("repodata")) {
+ File workspaceDir = getWorkspaceDir(workspace);
+ // touch a file in order to make sue this is properly
+ // mounted.
+ File touch = new File(workspaceDir, ".touch");
+ touch.createNewFile();
+ touch.delete();
+
+ SystemCall createrepo = new SystemCall();
+ createrepo.arg("createrepo");
+ createrepo.arg("-q");
+ File archDir = new File(workspaceDir, arch);
+ createrepo.arg(archDir.getAbsolutePath());
+ createrepo.run();
+ }
+ }
+ } catch (Exception e) {
+ throw new SlcException("Cannot initialize workspace " + workspace,
+ e);
+ } finally {
+ JcrUtils.logoutQuietly(session);
+ }
+ }
+
+ protected void initGitWorkspace() {
+ Session session = null;
+ try {
+ session = JcrUtils.loginOrCreateWorkspace(rpmRepository,
+ gitWorkspace);
+ JcrUtils.addPrivilege(session, "/", "anonymous", "jcr:read");
+ JcrUtils.addPrivilege(session, "/", SlcConstants.ROLE_SLC,
+ "jcr:all");
+ } catch (Exception e) {
+ throw new SlcException("Cannot initialize workspace "
+ + gitWorkspace, e);
+ } finally {
+ JcrUtils.logoutQuietly(session);
+ }
+ }
+
+ protected void initDistWorkspace(String workspace) {
+ Session session = null;
+ try {
+ session = JcrUtils
+ .loginOrCreateWorkspace(distRepository, workspace);
+ JcrUtils.addPrivilege(session, "/", "anonymous", "jcr:read");
+ } catch (RepositoryException e) {
+ throw new SlcException("Cannot initialize workspace " + workspace,
+ e);
+ } finally {
+ JcrUtils.logoutQuietly(session);
+ }
+ }
+
+ public void destroy() {
+
+ }
+
+ public String generateMockConfigFile(String arch, String branch) {
+ StringBuffer buf = new StringBuffer();
+
+ buf.append("config_opts['root'] = '" + getIdWithArch(arch) + "'\n");
+ buf.append("config_opts['target_arch'] = '" + arch + "'\n");
+ buf.append("config_opts['legal_host_arches'] = ('" + arch + "',)\n");
+ buf.append("config_opts['chroot_setup_cmd'] = 'groupinstall buildsys-build'\n");
+ // buf.append("config_opts['dist'] = 'el6'\n");
+ buf.append("config_opts['plugin_conf']['yum_cache_enable'] = False\n");
+
+ buf.append("config_opts['scm'] = False\n");
+ buf.append("config_opts['scm_opts']['method'] = 'git'\n");
+ buf.append("config_opts['scm_opts']['spec'] = 'SCM_PKG.spec'\n");
+ buf.append("config_opts['scm_opts']['ext_src_dir'] = '"
+ + getSourcesDir().getAbsolutePath() + "'\n");
+ buf.append("config_opts['scm_opts']['git_timestamps'] = True\n");
+ buf.append("config_opts['scm_opts']['git_get'] = 'git clone "
+ + (branch != null ? "-b " + branch : "") + " "
+ + getGitBaseUrl() + "/SCM_PKG.git SCM_PKG'\n");
+
+ buf.append("\nconfig_opts['yum.conf'] = \"\"\"\n");
+ buf.append(generateYumConfigFile(arch)).append('\n');
+ buf.append("\"\"\"\n");
+ return buf.toString();
+ }
+
+ public String generateYumConfigFile(String arch) {
+ StringBuffer buf = new StringBuffer();
+ buf.append("[main]\n");
+ buf.append(yumConfigMainSection).append('\n');
+
+ for (RpmRepository repository : repositories) {
+ buf.append('[').append(repository.getId()).append("]\n");
+ if (repository instanceof ThirdPartyRpmRepository) {
+ buf.append("#baseurl=").append(repository.getUrl())
+ .append(arch).append('/').append("\n");
+ buf.append("baseurl=").append(proxiedReposBase)
+ .append(repository.getId()).append('/').append(arch)
+ .append('/').append("\n");
+ }
+ }
+
+ // managed repos
+ addManagedRepository(buf, stagingWorkspace, arch);
+ if (withTestingRepository)
+ addManagedRepository(buf, testingWorkspace, arch);
+ addManagedRepository(buf, stableWorkspace, arch);
+ return buf.toString();
+ }
+
+ protected void addManagedRepository(StringBuffer buf, String workspace,
+ String arch) {
+ buf.append('[').append(workspace).append("]\n");
+ buf.append("baseurl=").append(managedReposBase).append(workspace)
+ .append('/').append(arch).append('/').append("\n");
+ }
+
+ /** Creates a mock config file. */
+ public File getMockConfigFile(String arch, String branch) {
+ File mockSiteDefaultsFile = new File(mockConfDir, "site-defaults.cfg");
+ File mockLoggingFile = new File(mockConfDir, "logging.ini");
+ File mockConfigFile = new File(mockConfDir, getIdWithArch(arch)
+ + ".cfg");
+ try {
+ if (!mockSiteDefaultsFile.exists())
+ mockSiteDefaultsFile.createNewFile();
+ if (!mockLoggingFile.exists())
+ FileUtils.copyFile(new File(mockEtc + "/logging.ini"),
+ mockLoggingFile);
+
+ FileUtils.writeStringToFile(mockConfigFile,
+ generateMockConfigFile(arch, branch));
+ return mockConfigFile;
+ } catch (IOException e) {
+ throw new SlcException("Cannot write mock config file to "
+ + mockConfigFile, e);
+ }
+ }
+
+ /** Creates a yum config file. */
+ public File getYumConfigFile(String arch) {
+ File yumConfigFile = new File(yumConfDir, getIdWithArch(arch) + ".conf");
+ try {
+ FileUtils.writeStringToFile(yumConfigFile,
+ generateYumConfigFile(arch));
+ return yumConfigFile;
+ } catch (IOException e) {
+ throw new SlcException("Cannot write yum config file to "
+ + yumConfigFile, e);
+ }
+ }
+
+ public File getResultDir(String arch) {
+ return new File(mockVar + "/" + getIdWithArch(arch) + "/result");
+ }
+
+ public File getWorkspaceDir(String workspace) {
+ return new File(rpmBase + "/" + workspace);
+ }
+
+ public File getSourcesDir() {
+ return new File(distBase + "/" + stagingWorkspace);
+ }
+
+ public String getMockConfig(String arch) {
+ return getIdWithArch(arch);
+ }
+
+ public String getIdWithArch(String arch) {
+ return id + "-" + arch;
+ }
+
+ public String getGitBaseUrl() {
+ return managedReposBase + gitWorkspace;
+ }
+
+ public void indexWorkspace(String workspace) {
+ Session session = null;
+ try {
+ session = rpmRepository.login(workspace);
+ session.getRootNode().accept(
+ new NodeIndexerVisitor(new RpmIndexer()));
+ } catch (RepositoryException e) {
+ throw new SlcException("Cannot index workspace " + workspace, e);
+ } finally {
+ JcrUtils.logoutQuietly(session);
+ }
+ }
+
+ /** Write (topdir)/rpmmacros and (topdir)/rpmrc */
+ public void writeRpmbuildConfigFiles(File topdir) {
+ writeRpmbuildConfigFiles(topdir, new File(topdir, "rpmmacros"),
+ new File(topdir, "rpmrc"));
+ }
+
+ public void writeRpmbuildConfigFiles(File topdir, File rpmmacroFile,
+ File rpmrcFile) {
+ try {
+ List<String> macroLines = new ArrayList<String>();
+ macroLines.add("%_topdir " + topdir.getCanonicalPath());
+ for (String macroKey : rpmmacros.keySet()) {
+ macroLines.add(macroKey + " " + rpmmacros.get(macroKey));
+ }
+ FileUtils.writeLines(rpmmacroFile, macroLines);
+
+ List<String> rpmrcLines = new ArrayList<String>();
+ rpmrcLines.add("include: /usr/lib/rpm/rpmrc");
+ rpmrcLines.add("macrofiles: " + defaultMacroFiles + ":"
+ + rpmmacroFile.getCanonicalPath());
+ FileUtils.writeLines(rpmrcFile, rpmrcLines);
+ } catch (IOException e) {
+ throw new SlcException("Cannot write rpmbuild config files", e);
+ }
+
+ }
+
+ public Map<String, String> getRpmmacros() {
+ return rpmmacros;
+ }
+
+ public void setRpmmacros(Map<String, String> rpmmacros) {
+ this.rpmmacros = rpmmacros;
+ }
+
+ public String getDefaultMacroFiles() {
+ return defaultMacroFiles;
+ }
+
+ public void setDefaultMacroFiles(String defaultMacroFiles) {
+ this.defaultMacroFiles = defaultMacroFiles;
+ }
+
+ public void setArchs(List<String> archs) {
+ this.archs = archs;
+ }
+
+ public List<String> getArchs() {
+ return archs;
+ }
+
+ public void setRpmBase(String stagingBase) {
+ this.rpmBase = stagingBase;
+ }
+
+ public void setId(String id) {
+ this.id = id;
+ }
+
+ public void setMockVar(String mockVar) {
+ this.mockVar = mockVar;
+ }
+
+ public void setRpmRepository(Repository rpmRepository) {
+ this.rpmRepository = rpmRepository;
+ }
+
+ public void setDistRepository(Repository distRepository) {
+ this.distRepository = distRepository;
+ }
+
+ public void setLocalUrlBase(String localUrlBase) {
+ this.localUrlBase = localUrlBase;
+ }
+
+ public void setYumConfigMainSection(String yumConfigMainSection) {
+ this.yumConfigMainSection = yumConfigMainSection;
+ }
+
+ public void setRepositories(List<RpmRepository> repositories) {
+ this.repositories = repositories;
+ }
+
+ public void setRpmFactoryBaseDir(File rpmFactoryBaseDir) {
+ this.rpmFactoryBaseDir = rpmFactoryBaseDir;
+ }
+
+ public String getStagingWorkspace() {
+ return stagingWorkspace;
+ }
+
+ public String getTestingWorkspace() {
+ return testingWorkspace;
+ }
+
+ public String getStableWorkspace() {
+ return stableWorkspace;
+ }
+
+ public void setWithTestingRepository(Boolean withTestingRepository) {
+ this.withTestingRepository = withTestingRepository;
+ }
+
+}
--- /dev/null
+package org.argeo.slc.rpmfactory.core;
+
+import static org.freecompany.redline.header.Header.HeaderTag.HEADERIMMUTABLE;
+import static org.freecompany.redline.header.Signature.SignatureTag.SIGNATURES;
+
+import java.io.InputStream;
+import java.nio.ByteBuffer;
+import java.nio.channels.Channels;
+
+import javax.jcr.Node;
+import javax.jcr.Property;
+
+import org.apache.commons.io.FilenameUtils;
+import org.argeo.slc.SlcException;
+import org.argeo.slc.jcr.SlcNames;
+import org.argeo.slc.jcr.SlcTypes;
+import org.argeo.slc.repo.NodeIndexer;
+import org.freecompany.redline.ChannelWrapper.Key;
+import org.freecompany.redline.ReadableChannelWrapper;
+import org.freecompany.redline.header.AbstractHeader;
+import org.freecompany.redline.header.Format;
+import org.freecompany.redline.header.Header;
+
+/** Indexes an RPM file. */
+public class RpmIndexer implements NodeIndexer, SlcNames {
+
+ @Override
+ public Boolean support(String path) {
+ return FilenameUtils.getExtension(path).equals("rpm");
+ }
+
+ @Override
+ public void index(Node node) {
+ try {
+ InputStream in = node.getNode(Node.JCR_CONTENT)
+ .getProperty(Property.JCR_DATA).getBinary().getStream();
+ ReadableChannelWrapper channel = new ReadableChannelWrapper(
+ Channels.newChannel(in));
+ Format format = readRpmInfo(channel);
+
+ node.addMixin(SlcTypes.SLC_RPM);
+ node.setProperty(SLC_NAME, readTag(format, Header.HeaderTag.NAME));
+ String rpmVersion = readTag(format, Header.HeaderTag.VERSION);
+ String rpmRelease = readTag(format, Header.HeaderTag.RELEASE);
+ node.setProperty(SLC_RPM_VERSION, rpmVersion);
+ node.setProperty(SLC_RPM_RELEASE, rpmRelease);
+ node.setProperty(SLC_VERSION, rpmVersion + "-" + rpmRelease);
+
+ String arch = readTag(format, Header.HeaderTag.ARCH);
+ if (arch != null)
+ node.setProperty(SLC_RPM_ARCH, arch);
+
+ String archiveSize = readTag(format, Header.HeaderTag.ARCHIVESIZE);
+ if (archiveSize != null)
+ node.setProperty(SLC_RPM_ARCHIVE_SIZE,
+ Long.parseLong(archiveSize));
+
+ node.getSession().save();
+ } catch (Exception e) {
+ throw new SlcException("Cannot index " + node, e);
+ }
+
+ }
+
+ @SuppressWarnings("unused")
+ public Format readRpmInfo(ReadableChannelWrapper channel) throws Exception {
+ Format format = new Format();
+
+ Key<Integer> lead = channel.start();
+ format.getLead().read(channel);
+ // System.out.println( "Lead ended at '" + in.finish( lead) + "'.");
+
+ Key<Integer> signature = channel.start();
+ int count = format.getSignature().read(channel);
+ int expected = ByteBuffer
+ .wrap((byte[]) format.getSignature().getEntry(SIGNATURES)
+ .getValues(), 8, 4).getInt()
+ / -16;
+ // System.out.println( "Signature ended at '" + in.finish( signature) +
+ // "' and contained '" + count + "' headers (expected '" + expected +
+ // "').");
+
+ Key<Integer> header = channel.start();
+ count = format.getHeader().read(channel);
+ expected = ByteBuffer.wrap(
+ (byte[]) format.getHeader().getEntry(HEADERIMMUTABLE)
+ .getValues(), 8, 4).getInt()
+ / -16;
+ // System.out.println( "Header ended at '" + in.finish( header) +
+ // " and contained '" + count + "' headers (expected '" + expected +
+ // "').");
+
+ return format;
+ }
+
+ private String readTag(Format format, Header.HeaderTag tag) {
+ AbstractHeader.Entry<?> entry = format.getHeader().getEntry(tag);
+ if (entry == null)
+ return null;
+ if (entry.getValues() == null)
+ return null;
+ Object[] values = (Object[]) entry.getValues();
+ return values[0].toString().trim();
+ }
+}
import java.util.Set;
import javax.jcr.Node;
+import javax.jcr.RepositoryException;
import javax.jcr.Session;
+import javax.jcr.nodetype.NodeType;
+import javax.jcr.security.AccessControlException;
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.SlcConstants;
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;
private Set<RpmRepository> defaultRepositories = new HashSet<RpmRepository>();
+ @Override
+ protected void beforeInitSessionSave(Session session)
+ throws RepositoryException {
+ JcrUtils.addPrivilege(session, "/", "anonymous", "jcr:read");
+ try {
+ JcrUtils.addPrivilege(session, "/", SlcConstants.ROLE_SLC,
+ "jcr:all");
+ } catch (AccessControlException e) {
+ if (log.isTraceEnabled())
+ log.trace("Cannot give jcr:all privileges to ROLE_SLC");
+ }
+
+ JcrUtils.mkdirsSafe(session, RepoConstants.PROXIED_REPOSITORIES);
+ }
+
/**
* Retrieve and add this file to the repository
*/
protected Node retrieve(Session session, String path) {
StringBuilder relativePathBuilder = new StringBuilder();
String repoId = extractRepoId(path, relativePathBuilder);
- String relativePath = relativePathBuilder.toString();
+ // remove starting '/'
+ String relativePath = relativePathBuilder.toString().substring(1);
RpmRepository sourceRepo = null;
for (Iterator<RpmRepository> reposIt = defaultRepositories.iterator(); reposIt
throw new SlcException("No RPM repository found for " + path);
try {
- // if (session.hasPendingChanges())
- // throw new SlcException("Session has pending changed");
String baseUrl = sourceRepo.getUrl();
String remoteUrl = baseUrl + relativePath;
Node node = proxyUrl(session, remoteUrl, path);
if (node != null) {
- // node.addMixin(SlcTypes.SLC_KNOWN_ORIGIN);
- // Node origin;
- // if (!node.hasNode(SLC_ORIGIN))
- // origin = node.addNode(SLC_ORIGIN, SlcTypes.SLC_PROXIED);
- // else
- // origin = node.getNode(SLC_ORIGIN);
- // // origin.setProperty(SLC_PROXY, sourceRepo.getId());
- // JcrUtils.urlToAddressProperties(origin, remoteUrl);
-
+ registerSource(sourceRepo, node, remoteUrl);
if (log.isDebugEnabled())
log.debug("Imported " + remoteUrl + " to " + node);
return node;
throw new SlcException("No proxy found for " + path);
}
+ protected void registerSource(RpmRepository sourceRepo, Node node,
+ String remoteUrl) throws RepositoryException {
+ node.addMixin(SlcTypes.SLC_KNOWN_ORIGIN);
+ Node origin;
+ if (!node.hasNode(SLC_ORIGIN))
+ origin = node.addNode(SLC_ORIGIN, SlcTypes.SLC_PROXIED);
+ else
+ origin = node.getNode(SLC_ORIGIN);
+
+ // proxied repository
+ Node proxiedRepository;
+ String proxiedRepositoryPath = RepoConstants.PROXIED_REPOSITORIES + '/'
+ + sourceRepo.getId();
+ Session session = node.getSession();
+ if (session.itemExists(proxiedRepositoryPath)) {
+ proxiedRepository = session.getNode(proxiedRepositoryPath);
+ } else {
+ proxiedRepository = session.getNode(
+ RepoConstants.PROXIED_REPOSITORIES).addNode(
+ sourceRepo.getId());
+ proxiedRepository.addMixin(NodeType.MIX_REFERENCEABLE);
+ JcrUtils.urlToAddressProperties(proxiedRepository,
+ sourceRepo.getUrl());
+ proxiedRepository.setProperty(SLC_URL, sourceRepo.getUrl());
+ }
+
+ origin.setProperty(SLC_PROXY, proxiedRepository);
+ JcrUtils.urlToAddressProperties(origin, remoteUrl);
+ }
+
/** Returns the first token of the path */
protected String extractRepoId(String path, StringBuilder relativePath) {
StringBuilder workspace = new StringBuilder();
@Override
protected Boolean shouldUpdate(Session clientSession, String nodePath) {
- if (nodePath.contains("/repodata/"))
- return true;
+ // if (nodePath.contains("/repodata/"))
+ // return true;
return super.shouldUpdate(clientSession, nodePath);
}
--- /dev/null
+package org.argeo.slc;
+
+/** Constants useful across all SLC components */
+public interface SlcConstants {
+ /** Read-write role. */
+ public final static String ROLE_SLC = "ROLE_SLC";
+}
// slc:exportedPackage
public final static String SLC_USES = "slc:uses";
+ // RPM
+ // slc:rpm
+ public final static String SLC_RPM_VERSION = "slc:rpmVersion";
+ public final static String SLC_RPM_RELEASE = "slc:rpmRelease";
+ public final static String SLC_RPM_ARCH = "slc:rpmArch";
+ public final static String SLC_RPM_ARCHIVE_SIZE = "slc:rpmArchiveSize";
}
public final static String SLC_CHECK = "slc:check";
public final static String SLC_PROPERTY = "slc:property";
public final static String SLC_DIFF_RESULT = "slc:diffResult";
-
+
// Node types used for user defined and managed result UI tree
public final static String SLC_MY_RESULT_ROOT_FOLDER = "slc:myResultRootFolder";
public final static String SLC_RESULT_FOLDER = "slc:resultFolder";
public final static String SLC_KNOWN_ORIGIN = "slc:knownOrigin";
public final static String SLC_PROXIED = "slc:proxied";
+ // rpm
+ public final static String SLC_RPM = "slc:rpm";
}
<artifactId>org.apache.commons.exec</artifactId>
</dependency>
- <dependency>
- <groupId>org.argeo.tp</groupId>
- <artifactId>org.redline_rpm</artifactId>
- </dependency>
-
<!-- TODO: check if necessary here -->
<dependency>
<groupId>org.argeo.tp</groupId>