From 91bba941484fdf89d8f884347c307b1efc2c34a3 Mon Sep 17 00:00:00 2001 From: Mathieu Baudier Date: Sun, 2 Jun 2013 20:47:50 +0000 Subject: [PATCH] Working RPM Factory with proxy. git-svn-id: https://svn.argeo.org/slc/trunk@6325 4cfe0d0a-d680-48aa-b62c-e0a02a3f76cc --- demo/log4j.properties | 6 +- demo/slc_demo_rcp.properties | 2 +- doc/site/site.xml | 4 +- .../WEB-INF/maven-servlet.xml | 6 - .../WEB-INF/osgi.xml | 5 +- .../WEB-INF/rpm-servlet.xml | 28 +++ .../WEB-INF/web.xml | 47 ++-- .../org.argeo.slc.server.repo.webapp/pom.xml | 6 +- .../META-INF/spring/repo-osgi.xml | 6 +- .../META-INF/spring/services.xml | 9 +- .../{maven/proxy => }/MavenProxyService.java | 2 +- .../{proxy => }/MavenProxyServiceImpl.java | 22 +- .../argeo/slc/rpmfactory/RpmProxyService.java | 2 +- .../argeo/slc/rpmfactory/RpmRepository.java | 1 + .../core/AbstractRpmRepository.java | 28 +++ .../slc/rpmfactory/core/BuildInMock.java | 213 ++++++++++++++++++ .../rpmfactory/core/RpmBuildEnvironment.java | 99 ++++++++ .../rpmfactory/core/RpmProxyServiceImpl.java | 133 +++++------ .../slc/rpmfactory/core/RpmSpecFile.java | 128 +++++++++++ .../core/ThirdPartyRpmRepository.java | 9 + .../slc/lib/linux/rpmfactory/RpmBuilder.java | 25 -- .../slc/lib/linux/rpmfactory/RpmRepoInit.java | 26 --- 22 files changed, 629 insertions(+), 178 deletions(-) create mode 100644 modules/org.argeo.slc.server.repo.webapp/WEB-INF/rpm-servlet.xml rename runtime/org.argeo.slc.repo/src/main/java/org/argeo/slc/repo/{maven/proxy => }/MavenProxyService.java (95%) rename runtime/org.argeo.slc.repo/src/main/java/org/argeo/slc/repo/maven/{proxy => }/MavenProxyServiceImpl.java (86%) create mode 100644 runtime/org.argeo.slc.rpmfactory/src/main/java/org/argeo/slc/rpmfactory/core/AbstractRpmRepository.java create mode 100644 runtime/org.argeo.slc.rpmfactory/src/main/java/org/argeo/slc/rpmfactory/core/BuildInMock.java create mode 100644 runtime/org.argeo.slc.rpmfactory/src/main/java/org/argeo/slc/rpmfactory/core/RpmBuildEnvironment.java create mode 100644 runtime/org.argeo.slc.rpmfactory/src/main/java/org/argeo/slc/rpmfactory/core/RpmSpecFile.java create mode 100644 runtime/org.argeo.slc.rpmfactory/src/main/java/org/argeo/slc/rpmfactory/core/ThirdPartyRpmRepository.java delete mode 100644 runtime/org.argeo.slc.support.simple/src/main/java/org/argeo/slc/lib/linux/rpmfactory/RpmBuilder.java delete mode 100644 runtime/org.argeo.slc.support.simple/src/main/java/org/argeo/slc/lib/linux/rpmfactory/RpmRepoInit.java diff --git a/demo/log4j.properties b/demo/log4j.properties index d89c95797..e062f7421 100644 --- a/demo/log4j.properties +++ b/demo/log4j.properties @@ -11,7 +11,7 @@ log4j.logger.org.argeo.server.webextender.TomcatDeployer=WARN #log4j.logger.org.springframework.security=DEBUG #log4j.logger.org.apache.jackrabbit=DEBUG #log4j.logger.org.apache.jackrabbit.spi2dav=DEBUG -log4j.logger.org.apache.jackrabbit.core.query.QueryImpl=DEBUG +#log4j.logger.org.apache.jackrabbit.core.query.QueryImpl=DEBUG log4j.logger.org.apache.coyote=INFO log4j.logger.org.apache.catalina.core.ContainerBase=INFO @@ -29,5 +29,5 @@ log4j.appender.console.layout.ConversionPattern=%d{yyyyMMdd HH:mm:ss} %-5p %m [% # development appender log4j.appender.development=org.apache.log4j.ConsoleAppender log4j.appender.development.layout=org.apache.log4j.PatternLayout -#log4j.appender.development.layout.ConversionPattern=%d{HH:mm:ss,SSS} [%16.16t] %5p %m (%F:%L) %c%n -log4j.appender.development.layout.ConversionPattern=%d{HH:mm:ss,SSS} %5p %m [%16.16t] %c%n +log4j.appender.development.layout.ConversionPattern=%d{HH:mm:ss,SSS} [%16.16t] %5p %m (%F:%L) %c%n +#log4j.appender.development.layout.ConversionPattern=%d{HH:mm:ss,SSS} %5p %m [%16.16t] %c%n diff --git a/demo/slc_demo_rcp.properties b/demo/slc_demo_rcp.properties index 4cc6ad222..808f43ffe 100644 --- a/demo/slc_demo_rcp.properties +++ b/demo/slc_demo_rcp.properties @@ -11,6 +11,7 @@ org.argeo.slc.server.repo,\ argeo.osgi.start.5=org.argeo.server.catalina.start,\ org.springframework.osgi.web.extender,\ org.argeo.jackrabbit.webapp,\ +org.argeo.slc.server.repo.webapp,\ slc.executionModules=org.argeo.slc.demo.ant,\ org.argeo.slc.demo.basic,\ @@ -18,7 +19,6 @@ org.argeo.slc.demo.minimal,\ eclipse.application=org.argeo.slc.client.rcp.application org.argeo.security.ui.initialPerspective=org.argeo.slc.client.ui.slcExecutionPerspective -#org.argeo.security.ui.initialPerspective=org.argeo.slc.client.ui.dist.distributionPerspective log4j.configuration=file:../../log4j.properties diff --git a/doc/site/site.xml b/doc/site/site.xml index ec2bd28db..aa8ebfd0f 100644 --- a/doc/site/site.xml +++ b/doc/site/site.xml @@ -26,8 +26,8 @@ - - + + + @@ -18,6 +18,7 @@ filter="(argeo.jcr.repository.alias=java)" /> - + + \ No newline at end of file diff --git a/modules/org.argeo.slc.server.repo.webapp/WEB-INF/rpm-servlet.xml b/modules/org.argeo.slc.server.repo.webapp/WEB-INF/rpm-servlet.xml new file mode 100644 index 000000000..adb909acb --- /dev/null +++ b/modules/org.argeo.slc.server.repo.webapp/WEB-INF/rpm-servlet.xml @@ -0,0 +1,28 @@ + + + + + + + + + + + rpmProxyServlet + + + + + + + + \ No newline at end of file diff --git a/modules/org.argeo.slc.server.repo.webapp/WEB-INF/web.xml b/modules/org.argeo.slc.server.repo.webapp/WEB-INF/web.xml index 3899789d6..3f58e7dde 100644 --- a/modules/org.argeo.slc.server.repo.webapp/WEB-INF/web.xml +++ b/modules/org.argeo.slc.server.repo.webapp/WEB-INF/web.xml @@ -2,9 +2,9 @@ - - index.jsp - + + index.jsp + Argeo SLC Repo Webapp @@ -23,20 +23,35 @@ org.springframework.osgi.web.context.support.OsgiBundleXmlWebApplicationContext + + + rpm + org.springframework.web.servlet.DispatcherServlet + + contextClass + org.springframework.osgi.web.context.support.OsgiBundleXmlWebApplicationContext + + 1 + + + rpm + /rpm/* + + - - - - - - - - - - - - - + + + + + + + + + + + + + diff --git a/modules/org.argeo.slc.server.repo.webapp/pom.xml b/modules/org.argeo.slc.server.repo.webapp/pom.xml index 86f5ffbd7..18e399100 100644 --- a/modules/org.argeo.slc.server.repo.webapp/pom.xml +++ b/modules/org.argeo.slc.server.repo.webapp/pom.xml @@ -1,4 +1,5 @@ - + 4.0.0 org.argeo.slc @@ -27,7 +28,8 @@ org.argeo.security.core, org.argeo.security.jcr, org.argeo.slc.aether.spring, - org.argeo.slc.repo.maven.proxy, + org.argeo.slc.repo, + org.argeo.slc.rpmfactory, org.springframework.osgi.web.context.support, org.springframework.security, org.springframework.security.context, diff --git a/modules/org.argeo.slc.server.repo/META-INF/spring/repo-osgi.xml b/modules/org.argeo.slc.server.repo/META-INF/spring/repo-osgi.xml index fc2362c89..71f7a5d44 100644 --- a/modules/org.argeo.slc.server.repo/META-INF/spring/repo-osgi.xml +++ b/modules/org.argeo.slc.server.repo/META-INF/spring/repo-osgi.xml @@ -12,6 +12,9 @@ + + @@ -34,7 +37,8 @@ - + + diff --git a/modules/org.argeo.slc.server.repo/META-INF/spring/services.xml b/modules/org.argeo.slc.server.repo/META-INF/spring/services.xml index 71c2f2a3e..06560aebc 100644 --- a/modules/org.argeo.slc.server.repo/META-INF/spring/services.xml +++ b/modules/org.argeo.slc.server.repo/META-INF/spring/services.xml @@ -26,10 +26,17 @@ - + + + + + + \ No newline at end of file diff --git a/runtime/org.argeo.slc.repo/src/main/java/org/argeo/slc/repo/maven/proxy/MavenProxyService.java b/runtime/org.argeo.slc.repo/src/main/java/org/argeo/slc/repo/MavenProxyService.java similarity index 95% rename from runtime/org.argeo.slc.repo/src/main/java/org/argeo/slc/repo/maven/proxy/MavenProxyService.java rename to runtime/org.argeo.slc.repo/src/main/java/org/argeo/slc/repo/MavenProxyService.java index c5f179e8c..8df4a5383 100644 --- a/runtime/org.argeo.slc.repo/src/main/java/org/argeo/slc/repo/maven/proxy/MavenProxyService.java +++ b/runtime/org.argeo.slc.repo/src/main/java/org/argeo/slc/repo/MavenProxyService.java @@ -13,7 +13,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package org.argeo.slc.repo.maven.proxy; +package org.argeo.slc.repo; import org.argeo.jcr.proxy.ResourceProxy; diff --git a/runtime/org.argeo.slc.repo/src/main/java/org/argeo/slc/repo/maven/proxy/MavenProxyServiceImpl.java b/runtime/org.argeo.slc.repo/src/main/java/org/argeo/slc/repo/maven/MavenProxyServiceImpl.java similarity index 86% rename from runtime/org.argeo.slc.repo/src/main/java/org/argeo/slc/repo/maven/proxy/MavenProxyServiceImpl.java rename to runtime/org.argeo.slc.repo/src/main/java/org/argeo/slc/repo/maven/MavenProxyServiceImpl.java index 5f87f24ac..87ee867b7 100644 --- a/runtime/org.argeo.slc.repo/src/main/java/org/argeo/slc/repo/maven/proxy/MavenProxyServiceImpl.java +++ b/runtime/org.argeo.slc.repo/src/main/java/org/argeo/slc/repo/maven/MavenProxyServiceImpl.java @@ -13,7 +13,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package org.argeo.slc.repo.maven.proxy; +package org.argeo.slc.repo.maven; import java.util.ArrayList; import java.util.List; @@ -32,10 +32,11 @@ 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.MavenProxyService; import org.argeo.slc.repo.RepoConstants; import org.sonatype.aether.repository.RemoteRepository; -/** Synchronizes the node repository with remote Maven repositories */ +/** Synchronises the node repository with remote Maven repositories */ public class MavenProxyServiceImpl extends AbstractUrlProxy implements MavenProxyService, ArgeoNames, SlcNames { private final static Log log = LogFactory @@ -43,9 +44,7 @@ public class MavenProxyServiceImpl extends AbstractUrlProxy implements private List defaultRepositories = new ArrayList(); - private String artifactsBasePath = RepoConstants.DEFAULT_ARTIFACTS_BASE_PATH; - - /** Inititalizes the artifacts area. */ + /** Initialises the artifacts area. */ @Override protected void beforeInitSessionSave(Session session) throws RepositoryException { @@ -109,21 +108,8 @@ public class MavenProxyServiceImpl extends AbstractUrlProxy implements 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/RpmProxyService.java b/runtime/org.argeo.slc.rpmfactory/src/main/java/org/argeo/slc/rpmfactory/RpmProxyService.java index bd59838ee..8f86253b6 100644 --- 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 @@ -17,6 +17,6 @@ package org.argeo.slc.rpmfactory; import org.argeo.jcr.proxy.ResourceProxy; -/** Marker interface (useful for OSGi servcies references), maybe extended later */ +/** Marker interface (useful for OSGi services references), may be extended later */ public interface RpmProxyService 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 index d15940bcc..24d7c727c 100644 --- 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 @@ -1,5 +1,6 @@ package org.argeo.slc.rpmfactory; +/** A YUM compatible repository of RPM packages. */ public interface RpmRepository { public String getId(); diff --git a/runtime/org.argeo.slc.rpmfactory/src/main/java/org/argeo/slc/rpmfactory/core/AbstractRpmRepository.java b/runtime/org.argeo.slc.rpmfactory/src/main/java/org/argeo/slc/rpmfactory/core/AbstractRpmRepository.java new file mode 100644 index 000000000..19418b61d --- /dev/null +++ b/runtime/org.argeo.slc.rpmfactory/src/main/java/org/argeo/slc/rpmfactory/core/AbstractRpmRepository.java @@ -0,0 +1,28 @@ +package org.argeo.slc.rpmfactory.core; + +import org.argeo.slc.rpmfactory.RpmRepository; + +/** Common method to RPM repositories. */ +public abstract class AbstractRpmRepository implements RpmRepository { + private String id; + private String url; + + @Override + public String getId() { + return id; + } + + @Override + public String getUrl() { + return url; + } + + public void setId(String id) { + this.id = id; + } + + public void setUrl(String url) { + this.url = url; + } + +} diff --git a/runtime/org.argeo.slc.rpmfactory/src/main/java/org/argeo/slc/rpmfactory/core/BuildInMock.java b/runtime/org.argeo.slc.rpmfactory/src/main/java/org/argeo/slc/rpmfactory/core/BuildInMock.java new file mode 100644 index 000000000..a085a9d08 --- /dev/null +++ b/runtime/org.argeo.slc.rpmfactory/src/main/java/org/argeo/slc/rpmfactory/core/BuildInMock.java @@ -0,0 +1,213 @@ +/* + * 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.Arrays; +import java.util.HashSet; +import java.util.List; +import java.util.Set; + +import org.apache.commons.exec.Executor; +import org.apache.commons.io.FileUtils; +import org.apache.commons.logging.Log; +import org.apache.commons.logging.LogFactory; +import org.argeo.slc.SlcException; +import org.argeo.slc.core.execution.tasks.SystemCall; + +/** Rebuild an SRPM in mock. (Historical) Replaces the build-mock.sh script. */ +public class BuildInMock implements Runnable { + private final static Log log = LogFactory.getLog(BuildInMock.class); + + /** Mock flavour provided by the EPEL repository */ + public final static String EPEL = "EPEL"; + /** Mock flavour provided by CentOS until v5 */ + public final static String CENTOS = "CENTOS"; + + public final static String NOARCH = "noarch"; + + private String mockVar = "/var/lib/mock"; + + private String mockFlavour = EPEL; + private String mockConfig = null; + + private String repository; + private String release = null; + private String level = null; + private String arch = NOARCH; + + private String rpmPackage = null; + + private Boolean mkdirs = true; + + private RpmBuildEnvironment buildEnvironment; + private Executor executor; + + private String debuginfoDirName = "debuginfo"; + + public void run() { + // TODO check if caller is in mock group + + String cfgId = repository + "-" + release + "-" + arch; + String cfg = mockConfig != null ? mockConfig : "slc/" + cfgId; + + // prepare mock call + SystemCall mock = new SystemCall(); + if (arch != null) + mock.arg("setarch").arg(arch); + mock.arg("mock"); + if (mockFlavour.equals(EPEL)) + mock.arg("-v"); + else if (mockFlavour.equals(CENTOS)) + mock.arg("--debug"); + if (arch != null) + mock.arg("--arch=" + arch); + mock.arg("-r").arg(cfg); + + mock.arg("--scm-enable"); + mock.arg("--scm-option").arg("package=" + rpmPackage); + + mock.setLogCommand(true); + + // mock command execution + mock.setExecutor(executor); + mock.run(); + + // File repoDir = new File(buildEnvironment.getStagingBase() + "/" + // + repository + "/" + level + "/" + release); + File repoDir = new File(buildEnvironment.getStagingBase() + "/" + + repository + "-" + release + "-staging"); + File srpmDir = new File(repoDir, "SRPMS"); + if (mkdirs) + srpmDir.mkdirs(); + File archDir = null; + File debuginfoDir = null; + if (!arch.equals(NOARCH)) { + archDir = new File(repoDir, arch); + debuginfoDir = new File(archDir, debuginfoDirName); + debuginfoDir.mkdirs(); + } + + // copy RPMs + Set reposToRecreate = new HashSet(); + File resultDir = new File(mockVar + "/" + cfgId + "/result"); + rpms: for (File file : resultDir.listFiles()) { + if (file.isDirectory()) + continue rpms; + + File[] targetDirs; + if (file.getName().contains(".src.rpm")) + targetDirs = new File[] { srpmDir }; + else if (file.getName().contains("-debuginfo-")) + targetDirs = new File[] { debuginfoDir }; + else if (!arch.equals(NOARCH) + && file.getName().contains("." + arch + ".rpm")) + targetDirs = new File[] { archDir }; + else if (file.getName().contains(".noarch.rpm")) { + List dirs = new ArrayList(); + for (String arch : buildEnvironment.getArchs()) + dirs.add(new File(repoDir, arch)); + targetDirs = dirs.toArray(new File[dirs.size()]); + } else if (file.getName().contains(".rpm")) + throw new SlcException("Don't know where to copy " + file); + else { + if (log.isTraceEnabled()) + log.trace("Skip " + file); + continue rpms; + } + + reposToRecreate.addAll(Arrays.asList(targetDirs)); + copyToDirs(file, targetDirs); + } + + // recreate changed repos + for (File repoToRecreate : reposToRecreate) { + SystemCall createrepo = new SystemCall(); + createrepo.arg("createrepo"); + // sqllite db + createrepo.arg("-d"); + // debuginfo + if (!repoToRecreate.getName().equals(debuginfoDirName)) + createrepo.arg("-x").arg(debuginfoDirName + "/*"); + // quiet + createrepo.arg("-q"); + createrepo.arg(repoToRecreate.getAbsolutePath()); + + createrepo.setExecutor(executor); + createrepo.run(); + log.info("Updated repo " + repoToRecreate); + } + } + + protected void copyToDirs(File file, File[] dirs) { + for (File dir : dirs) { + try { + FileUtils.copyFileToDirectory(file, dir); + if (log.isDebugEnabled()) + log.debug(file + " => " + dir); + } catch (IOException e) { + throw new SlcException("Cannot copy " + file + " to " + dir, e); + } + } + } + + public void setMockFlavour(String mockFlavour) { + this.mockFlavour = mockFlavour; + } + + public void setMockConfig(String mockConfig) { + this.mockConfig = mockConfig; + } + + public void setRepository(String repo) { + this.repository = repo; + } + + public void setRelease(String release) { + this.release = release; + } + + public void setLevel(String level) { + this.level = level; + } + + public void setArch(String arch) { + this.arch = arch; + } + + public void setRpmPackage(String rpmPackage) { + this.rpmPackage = rpmPackage; + } + + public void setMockVar(String mockVar) { + this.mockVar = mockVar; + } + + public void setMkdirs(Boolean mkdirs) { + this.mkdirs = mkdirs; + } + + public void setBuildEnvironment(RpmBuildEnvironment buildEnvironment) { + this.buildEnvironment = buildEnvironment; + } + + public void setExecutor(Executor executor) { + this.executor = executor; + } + +} diff --git a/runtime/org.argeo.slc.rpmfactory/src/main/java/org/argeo/slc/rpmfactory/core/RpmBuildEnvironment.java b/runtime/org.argeo.slc.rpmfactory/src/main/java/org/argeo/slc/rpmfactory/core/RpmBuildEnvironment.java new file mode 100644 index 000000000..ebdf1de2b --- /dev/null +++ b/runtime/org.argeo.slc.rpmfactory/src/main/java/org/argeo/slc/rpmfactory/core/RpmBuildEnvironment.java @@ -0,0 +1,99 @@ +/* + * 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 org.apache.commons.io.FileUtils; +import org.argeo.slc.SlcException; + +/** + * Defines a build environment. This information is typically used by other + * components performing the various actions related to RPM build. + */ +public class RpmBuildEnvironment { + static 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 rpmmacros = new HashMap(); + + private List archs = new ArrayList(); + + private String stagingBase = "/mnt/slc/repos/rpm"; + + /** 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 macroLines = new ArrayList(); + macroLines.add("%_topdir " + topdir.getCanonicalPath()); + for (String macroKey : rpmmacros.keySet()) { + macroLines.add(macroKey + " " + rpmmacros.get(macroKey)); + } + FileUtils.writeLines(rpmmacroFile, macroLines); + + List rpmrcLines = new ArrayList(); + 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 getRpmmacros() { + return rpmmacros; + } + + public void setRpmmacros(Map rpmmacros) { + this.rpmmacros = rpmmacros; + } + + public String getDefaultMacroFiles() { + return defaultMacroFiles; + } + + public void setDefaultMacroFiles(String defaultMacroFiles) { + this.defaultMacroFiles = defaultMacroFiles; + } + + public void setArchs(List archs) { + this.archs = archs; + } + + public List getArchs() { + return archs; + } + + public String getStagingBase() { + return stagingBase; + } + + public void setStagingBase(String stagingBase) { + this.stagingBase = stagingBase; + } +} 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 index 72958ba0a..14d399c27 100644 --- 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 @@ -15,14 +15,12 @@ */ package org.argeo.slc.rpmfactory.core; -import java.util.ArrayList; -import java.util.List; +import java.util.HashSet; +import java.util.Iterator; +import java.util.Set; 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; @@ -32,98 +30,87 @@ 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 */ +/** Synchronises 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 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()); - } - } - } + private Set defaultRepositories = new HashSet(); /** * Retrieve and add this file to the repository */ @Override protected Node retrieve(Session session, String path) { + StringBuilder relativePathBuilder = new StringBuilder(); + String repoId = extractRepoId(path, relativePathBuilder); + String relativePath = relativePathBuilder.toString(); + + RpmRepository sourceRepo = null; + for (Iterator reposIt = defaultRepositories.iterator(); reposIt + .hasNext();) { + RpmRepository rpmRepo = reposIt.next(); + if (rpmRepo.getId().equals(repoId)) { + sourceRepo = rpmRepo; + break; + } + } + + if (sourceRepo == null) + throw new SlcException("No RPM repository found for " + 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 (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); + + if (log.isDebugEnabled()) + log.debug("Imported " + remoteUrl + " 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); } + JcrUtils.discardQuietly(session); + throw new SlcException("No proxy found for " + path); } - 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); + /** Returns the first token of the path */ + protected String extractRepoId(String path, StringBuilder relativePath) { + StringBuilder workspace = new StringBuilder(); + StringBuilder buf = workspace; + for (int i = 1; i < path.length(); i++) { + char c = path.charAt(i); + if (c == '/') { + buf = relativePath; + } + buf.append(c); } - return baseUrls; + return workspace.toString(); } - /** 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; + @Override + protected Boolean shouldUpdate(Session clientSession, String nodePath) { + if (nodePath.contains("/repodata/")) + return true; + return super.shouldUpdate(clientSession, nodePath); } - public void setDefaultRepositories(List defaultRepositories) { + public void setDefaultRepositories(Set 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/RpmSpecFile.java b/runtime/org.argeo.slc.rpmfactory/src/main/java/org/argeo/slc/rpmfactory/core/RpmSpecFile.java new file mode 100644 index 000000000..4b4db3b2e --- /dev/null +++ b/runtime/org.argeo.slc.rpmfactory/src/main/java/org/argeo/slc/rpmfactory/core/RpmSpecFile.java @@ -0,0 +1,128 @@ +/* + * 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.IOException; +import java.util.HashMap; +import java.util.List; +import java.util.Map; + +import org.apache.commons.io.IOUtils; +import org.springframework.core.io.Resource; + +public class RpmSpecFile { + private Resource specFile; + + private String name; + private String version; + private String release; + private Map sources = new HashMap(); + private Map patches = new HashMap(); + + public RpmSpecFile(Resource specFile) { + this.specFile = specFile; + parseSpecFile(); + } + + public void init() { + parseSpecFile(); + } + + @SuppressWarnings("unchecked") + protected void parseSpecFile() { + try { + List lines = (List) IOUtils.readLines(specFile + .getInputStream()); + + lines: for (String line : lines) { + int indexSemiColon = line.indexOf(':'); + if (indexSemiColon <= 0) + continue lines; + String directive = line.substring(0, indexSemiColon).trim(); + String value = line.substring(indexSemiColon + 1).trim(); + if ("name".equals(directive.toLowerCase())) + name = value; + else if ("version".equals(directive.toLowerCase())) + version = value; + else if ("release".equals(directive.toLowerCase())) + release = value; + else if (directive.toLowerCase().startsWith("source")) + sources.put(directive, interpret(value)); + else if (directive.toLowerCase().startsWith("patch")) + patches.put(directive, interpret(value)); + } + + } catch (IOException e) { + throw new RuntimeException("Cannot parse spec file " + specFile, e); + } + } + + protected String interpret(String value) { + StringBuffer buf = new StringBuffer(value.length()); + StringBuffer currKey = null; + boolean mayBeKey = false; + chars: for (char c : value.toCharArray()) { + if (c == '%') + mayBeKey = true; + else if (c == '{') { + if (mayBeKey) + currKey = new StringBuffer(); + } else if (c == '}') { + if (currKey == null) + continue chars; + String key = currKey.toString(); + if ("name".equals(key.toLowerCase())) + buf.append(name); + else if ("version".equals(key.toLowerCase())) + buf.append(version); + else + buf.append("%{").append(key).append('}'); + currKey = null; + } else { + if (currKey != null) + currKey.append(c); + else + buf.append(c); + } + } + return buf.toString(); + } + + public Resource getSpecFile() { + return specFile; + } + + public String getName() { + return name; + } + + public String getVersion() { + return version; + } + + public String getRelease() { + return release; + } + + public Map getSources() { + return sources; + } + + public Map getPatches() { + return patches; + } + +} diff --git a/runtime/org.argeo.slc.rpmfactory/src/main/java/org/argeo/slc/rpmfactory/core/ThirdPartyRpmRepository.java b/runtime/org.argeo.slc.rpmfactory/src/main/java/org/argeo/slc/rpmfactory/core/ThirdPartyRpmRepository.java new file mode 100644 index 000000000..3e366e28b --- /dev/null +++ b/runtime/org.argeo.slc.rpmfactory/src/main/java/org/argeo/slc/rpmfactory/core/ThirdPartyRpmRepository.java @@ -0,0 +1,9 @@ +package org.argeo.slc.rpmfactory.core; + +/** + * A repository of third party RPMs used for the build. RPM used by the builds + * will be cached within the system. + */ +public class ThirdPartyRpmRepository extends AbstractRpmRepository { + +} diff --git a/runtime/org.argeo.slc.support.simple/src/main/java/org/argeo/slc/lib/linux/rpmfactory/RpmBuilder.java b/runtime/org.argeo.slc.support.simple/src/main/java/org/argeo/slc/lib/linux/rpmfactory/RpmBuilder.java deleted file mode 100644 index 613a8c4f1..000000000 --- a/runtime/org.argeo.slc.support.simple/src/main/java/org/argeo/slc/lib/linux/rpmfactory/RpmBuilder.java +++ /dev/null @@ -1,25 +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.lib.linux.rpmfactory; - -import org.freecompany.redline.Builder; - -public class RpmBuilder { - private Builder builder; - - public void run() { - } -} diff --git a/runtime/org.argeo.slc.support.simple/src/main/java/org/argeo/slc/lib/linux/rpmfactory/RpmRepoInit.java b/runtime/org.argeo.slc.support.simple/src/main/java/org/argeo/slc/lib/linux/rpmfactory/RpmRepoInit.java deleted file mode 100644 index c92035466..000000000 --- a/runtime/org.argeo.slc.support.simple/src/main/java/org/argeo/slc/lib/linux/rpmfactory/RpmRepoInit.java +++ /dev/null @@ -1,26 +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.lib.linux.rpmfactory; - -/** Initialize a repository factory. */ -public class RpmRepoInit implements Runnable { - - public void run() { - // TODO Auto-generated method stub - - } - -} -- 2.39.2