You are viewing a plain text version of this content. The canonical link for it is here.
Posted to scm@geronimo.apache.org by ga...@apache.org on 2010/06/23 19:26:32 UTC
svn commit: r957276 - in /geronimo/server/trunk/framework:
configs/j2ee-system/src/main/plan/
modules/geronimo-obr/src/main/java/org/apache/geronimo/obr/
modules/geronimo-shell-base/
modules/geronimo-shell-base/src/main/java/org/apache/geronimo/shell/o...
Author: gawor
Date: Wed Jun 23 17:26:31 2010
New Revision: 957276
URL: http://svn.apache.org/viewvc?rev=957276&view=rev
Log:
Improved Geronimo OBR support. Contains fix for GERONIMO-5392 as well as support for excludes and a shell command for refreshing the repository
Added:
geronimo/server/trunk/framework/modules/geronimo-shell-base/src/main/java/org/apache/geronimo/shell/obr/
geronimo/server/trunk/framework/modules/geronimo-shell-base/src/main/java/org/apache/geronimo/shell/obr/RefreshCommand.java (with props)
geronimo/server/trunk/framework/modules/geronimo-shell-base/src/main/resources/OSGI-INF/blueprint/shell-obr.xml (with props)
Modified:
geronimo/server/trunk/framework/configs/j2ee-system/src/main/plan/plan.xml
geronimo/server/trunk/framework/modules/geronimo-obr/src/main/java/org/apache/geronimo/obr/GeronimoOBRGBean.java
geronimo/server/trunk/framework/modules/geronimo-shell-base/pom.xml
Modified: geronimo/server/trunk/framework/configs/j2ee-system/src/main/plan/plan.xml
URL: http://svn.apache.org/viewvc/geronimo/server/trunk/framework/configs/j2ee-system/src/main/plan/plan.xml?rev=957276&r1=957275&r2=957276&view=diff
==============================================================================
--- geronimo/server/trunk/framework/configs/j2ee-system/src/main/plan/plan.xml (original)
+++ geronimo/server/trunk/framework/configs/j2ee-system/src/main/plan/plan.xml Wed Jun 23 17:26:31 2010
@@ -125,6 +125,10 @@ specific services - those should be prov
<reference name="ServerInfo">
<name>ServerInfo</name>
</reference>
+ <attribute name="exclusions">
+ org.apache.felix/org.apache.felix.framework//,
+ org.eclipse/osgi//
+ </attribute>
</gbean>
<gbean name="EmbeddedDaemon" class="org.apache.geronimo.system.main.EmbeddedDaemon"/>
Modified: geronimo/server/trunk/framework/modules/geronimo-obr/src/main/java/org/apache/geronimo/obr/GeronimoOBRGBean.java
URL: http://svn.apache.org/viewvc/geronimo/server/trunk/framework/modules/geronimo-obr/src/main/java/org/apache/geronimo/obr/GeronimoOBRGBean.java?rev=957276&r1=957275&r2=957276&view=diff
==============================================================================
--- geronimo/server/trunk/framework/modules/geronimo-obr/src/main/java/org/apache/geronimo/obr/GeronimoOBRGBean.java (original)
+++ geronimo/server/trunk/framework/modules/geronimo-obr/src/main/java/org/apache/geronimo/obr/GeronimoOBRGBean.java Wed Jun 23 17:26:31 2010
@@ -23,6 +23,8 @@ import java.io.IOException;
import java.net.MalformedURLException;
import java.net.URL;
import java.util.ArrayList;
+import java.util.HashSet;
+import java.util.Iterator;
import java.util.List;
import java.util.Set;
import java.util.StringTokenizer;
@@ -36,6 +38,7 @@ import javax.xml.bind.Marshaller;
import org.apache.felix.bundlerepository.RepositoryAdmin;
import org.apache.geronimo.gbean.GBeanLifecycle;
import org.apache.geronimo.gbean.annotation.GBean;
+import org.apache.geronimo.gbean.annotation.OsgiService;
import org.apache.geronimo.gbean.annotation.ParamAttribute;
import org.apache.geronimo.gbean.annotation.ParamReference;
import org.apache.geronimo.gbean.annotation.ParamSpecial;
@@ -52,6 +55,7 @@ import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
@GBean
+@OsgiService
public class GeronimoOBRGBean implements GBeanLifecycle {
private static final Logger LOG = LoggerFactory.getLogger(GeronimoOBRGBean.class);
@@ -60,15 +64,18 @@ public class GeronimoOBRGBean implements
private ListableRepository repository;
private File obrFile;
private List<URL> repositories;
+ private Set<Artifact> exclusions;
public GeronimoOBRGBean(@ParamReference(name = "Repository", namingType = "Repository") ListableRepository repository,
@ParamReference(name = "ServerInfo") ServerInfo serverInfo,
@ParamSpecial(type = SpecialAttributeType.bundleContext) BundleContext bundleContext,
- @ParamAttribute(name = "repositoryList") String repositoryList) throws Exception {
+ @ParamAttribute(name = "repositoryList") String repositoryList,
+ @ParamAttribute(name = "exclusions") String exclusions) throws Exception {
this.repository = repository;
this.bundleContext = bundleContext;
this.obrFile = serverInfo.resolveServer("var/obr.xml");
this.repositories = parseRepositories(repositoryList);
+ this.exclusions = parseExclusions(exclusions);
}
private static List<URL> parseRepositories(String repositoryList) throws MalformedURLException {
@@ -83,12 +90,50 @@ public class GeronimoOBRGBean implements
return list;
}
- private void generateOBR() throws Exception {
+ private static Set<Artifact> parseExclusions(String exclusions) throws MalformedURLException {
+ Set<Artifact> set = new HashSet<Artifact>();
+ if (exclusions != null) {
+ StringTokenizer tokenizer = new StringTokenizer(exclusions, ",");
+ while (tokenizer.hasMoreElements()) {
+ String token = (String) tokenizer.nextElement();
+ set.add(Artifact.create(token.trim()));
+ }
+ }
+ return set;
+ }
+
+ public void refresh() throws Exception {
+ generateRepository();
+
+ ServiceReference ref = bundleContext.getServiceReference(RepositoryAdmin.class.getName());
+ RepositoryAdmin repositoryAdmin = (RepositoryAdmin) bundleContext.getService(ref);
+ try {
+ repositoryAdmin.removeRepository(obrFile.toURI().toURL().toExternalForm());
+ repositoryAdmin.addRepository(obrFile.toURI().toURL());
+ } finally {
+ bundleContext.ungetService(ref);
+ }
+ }
+
+ private void generateRepository() throws Exception {
String obrName = "Geronimo OBR Repository";
org.apache.geronimo.kernel.repository.Repository geronimoRepository = repository;
Set<Artifact> artifacts = repository.list();
+
+ // prune excluded artifacts
+ for (Artifact excluded : exclusions) {
+ Iterator<Artifact> iterator = artifacts.iterator();
+ while (iterator.hasNext()) {
+ Artifact artifact = iterator.next();
+ if (excluded.matches(artifact)) {
+ LOG.debug("Exluded {} artifact from OBR", artifact);
+ iterator.remove();
+ }
+ }
+ }
+
generateOBR(obrName, artifacts, geronimoRepository, obrFile);
}
@@ -96,7 +141,7 @@ public class GeronimoOBRGBean implements
Repository repo = generateOBRModel(obrName, geronimoRepository, artifacts);
marshallOBRModel(repo, obrFile);
}
-
+
public static void marshallOBRModel(Repository repo, File obrFile) throws JAXBException {
JAXBContext context = JAXBContext.newInstance(Repository.class);
Marshaller marshaller = context.createMarshaller();
@@ -136,8 +181,15 @@ public class GeronimoOBRGBean implements
BundleDescription desc = new BundleDescription(mf);
ResourceBuilder builder = new ResourceBuilder(desc);
-
- Resource resource = builder.createResource();
+
+ Resource resource = null;
+ try {
+ resource = builder.createResource();
+ } catch (RuntimeException e) {
+ LOG.debug("Failed to generate OBR information for " + artifact + " artifact", e);
+ continue;
+ }
+
if (resource != null) {
resource.setUri(getURL(artifact));
if (location.isFile()) {
@@ -145,7 +197,7 @@ public class GeronimoOBRGBean implements
}
repo.getResource().add(resource);
} else {
- LOG.debug("Artifact {} is not a bundle.", artifact);
+ LOG.debug("Did not generate OBR information for {} artifact. It is not a bundle.", artifact);
}
}
return repo;
@@ -155,25 +207,39 @@ public class GeronimoOBRGBean implements
return "mvn:" + artifact.getGroupId() + "/" + artifact.getArtifactId() + "/" + artifact.getVersion() + ("jar".equals(artifact.getType())? "": "/" + artifact.getType());
}
- private void registerOBR() throws Exception {
+ private void registerRepositories() throws Exception {
ServiceReference ref = bundleContext.getServiceReference(RepositoryAdmin.class.getName());
- RepositoryAdmin repositoryAdmin = (RepositoryAdmin) bundleContext.getService(ref);
-
- repositoryAdmin.addRepository(obrFile.toURI().toURL());
-
- for (URL repository : repositories) {
- repositoryAdmin.addRepository(repository);
+ RepositoryAdmin repositoryAdmin = (RepositoryAdmin) bundleContext.getService(ref);
+ try {
+ repositoryAdmin.addRepository(obrFile.toURI().toURL());
+ for (URL repository : repositories) {
+ repositoryAdmin.addRepository(repository);
+ }
+ } finally {
+ bundleContext.ungetService(ref);
+ }
+ }
+
+ private void unregisterRepositories() throws Exception {
+ ServiceReference ref = bundleContext.getServiceReference(RepositoryAdmin.class.getName());
+ RepositoryAdmin repositoryAdmin = (RepositoryAdmin) bundleContext.getService(ref);
+ try {
+ repositoryAdmin.removeRepository(obrFile.toURI().toURL().toExternalForm());
+ for (URL repository : repositories) {
+ repositoryAdmin.removeRepository(repository.toExternalForm());
+ }
+ } finally {
+ bundleContext.ungetService(ref);
}
-
- bundleContext.ungetService(ref);
}
public void doStart() throws Exception {
- generateOBR();
- registerOBR();
+ generateRepository();
+ registerRepositories();
}
public void doStop() throws Exception {
+ unregisterRepositories();
}
public void doFail() {
Modified: geronimo/server/trunk/framework/modules/geronimo-shell-base/pom.xml
URL: http://svn.apache.org/viewvc/geronimo/server/trunk/framework/modules/geronimo-shell-base/pom.xml?rev=957276&r1=957275&r2=957276&view=diff
==============================================================================
--- geronimo/server/trunk/framework/modules/geronimo-shell-base/pom.xml (original)
+++ geronimo/server/trunk/framework/modules/geronimo-shell-base/pom.xml Wed Jun 23 17:26:31 2010
@@ -52,9 +52,19 @@
</dependency>
<dependency>
+ <groupId>org.apache.geronimo.framework</groupId>
+ <artifactId>geronimo-obr</artifactId>
+ <version>${project.version}</version>
+ </dependency>
+
+ <dependency>
<groupId>org.apache.felix.karaf.shell</groupId>
<artifactId>org.apache.felix.karaf.shell.console</artifactId>
</dependency>
+ <dependency>
+ <groupId>org.apache.aries.blueprint</groupId>
+ <artifactId>org.apache.aries.blueprint</artifactId>
+ </dependency>
</dependencies>
</project>
Added: geronimo/server/trunk/framework/modules/geronimo-shell-base/src/main/java/org/apache/geronimo/shell/obr/RefreshCommand.java
URL: http://svn.apache.org/viewvc/geronimo/server/trunk/framework/modules/geronimo-shell-base/src/main/java/org/apache/geronimo/shell/obr/RefreshCommand.java?rev=957276&view=auto
==============================================================================
--- geronimo/server/trunk/framework/modules/geronimo-shell-base/src/main/java/org/apache/geronimo/shell/obr/RefreshCommand.java (added)
+++ geronimo/server/trunk/framework/modules/geronimo-shell-base/src/main/java/org/apache/geronimo/shell/obr/RefreshCommand.java Wed Jun 23 17:26:31 2010
@@ -0,0 +1,37 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You 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.apache.geronimo.shell.obr;
+
+import org.apache.felix.gogo.commands.Command;
+import org.apache.felix.karaf.shell.console.OsgiCommandSupport;
+import org.apache.geronimo.obr.GeronimoOBRGBean;
+import org.osgi.framework.ServiceReference;
+
+@Command(scope = "obr", name = "geronimo-refresh", description = "Refresh Geronimo OBR repository")
+public class RefreshCommand extends OsgiCommandSupport {
+
+ protected Object doExecute() throws Exception {
+ ServiceReference ref = bundleContext.getServiceReference(GeronimoOBRGBean.class.getName());
+ GeronimoOBRGBean service = (GeronimoOBRGBean) getService(GeronimoOBRGBean.class, ref);
+
+ service.refresh();
+
+ return null;
+ }
+
+}
Propchange: geronimo/server/trunk/framework/modules/geronimo-shell-base/src/main/java/org/apache/geronimo/shell/obr/RefreshCommand.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: geronimo/server/trunk/framework/modules/geronimo-shell-base/src/main/java/org/apache/geronimo/shell/obr/RefreshCommand.java
------------------------------------------------------------------------------
svn:keywords = Date Revision
Propchange: geronimo/server/trunk/framework/modules/geronimo-shell-base/src/main/java/org/apache/geronimo/shell/obr/RefreshCommand.java
------------------------------------------------------------------------------
svn:mime-type = text/plain
Added: geronimo/server/trunk/framework/modules/geronimo-shell-base/src/main/resources/OSGI-INF/blueprint/shell-obr.xml
URL: http://svn.apache.org/viewvc/geronimo/server/trunk/framework/modules/geronimo-shell-base/src/main/resources/OSGI-INF/blueprint/shell-obr.xml?rev=957276&view=auto
==============================================================================
--- geronimo/server/trunk/framework/modules/geronimo-shell-base/src/main/resources/OSGI-INF/blueprint/shell-obr.xml (added)
+++ geronimo/server/trunk/framework/modules/geronimo-shell-base/src/main/resources/OSGI-INF/blueprint/shell-obr.xml Wed Jun 23 17:26:31 2010
@@ -0,0 +1,29 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+
+ Licensed to the Apache Software Foundation (ASF) under one or more
+ contributor license agreements. See the NOTICE file distributed with
+ this work for additional information regarding copyright ownership.
+ The ASF licenses this file to You 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.
+
+-->
+<blueprint xmlns="http://www.osgi.org/xmlns/blueprint/v1.0.0"
+ default-activation="lazy">
+
+ <command-bundle xmlns="http://felix.apache.org/karaf/xmlns/shell/v1.0.0">
+ <command name="obr/geronimo-refresh">
+ <action class="org.apache.geronimo.shell.obr.RefreshCommand"></action>
+ </command>
+ </command-bundle>
+
+</blueprint>
Propchange: geronimo/server/trunk/framework/modules/geronimo-shell-base/src/main/resources/OSGI-INF/blueprint/shell-obr.xml
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: geronimo/server/trunk/framework/modules/geronimo-shell-base/src/main/resources/OSGI-INF/blueprint/shell-obr.xml
------------------------------------------------------------------------------
svn:keywords = Date Revision
Propchange: geronimo/server/trunk/framework/modules/geronimo-shell-base/src/main/resources/OSGI-INF/blueprint/shell-obr.xml
------------------------------------------------------------------------------
svn:mime-type = text/xml